A complex Delphi event handler in DE Decompiler, IDR and IDA

In the Win32 AntiCrack.exe, we selected TfrmMain.cmdProtectClick at VA 0x007BDA5C. The portion shown here clears UI controls, checks a path and starts reading a text file. Each listing shows the same handler. The ToDoList case lets you repeat the comparison on a second executable with two conditions, a VCL property write and a constructed file path.

Reproduce the comparison with ToDoList

DE Decompiler 26.7

The code tree identifies Main, TfrmMain and cmdProtectClick. In the Pascal-like listing, the condition at 0x007BDAD9 is shown as FileExists(var_39C, True). The successful branch reaches AssignFile, followed by while not Eof(...), Read and ReadLn. The listing also contains generated variable and call names. Use the instruction addresses to match it to the other tools.

The AntiCrack handler in DE Decompiler, with the file check and read loop in view.
The AntiCrack handler in DE Decompiler, with the file check and read loop in view.

IDR 2.6.3.14

The CodeViewer identifies the procedure as _Unit115.TfrmMain.cmdProtectClick. It annotates several operands and calls, including TfrmMain.txtFile:TsEdit and TControl.GetText. The file check still appears in assembly. At 0x007BDAD2 it calls 0x00428DFC, tests AL and branches at 0x007BDAD9.

IDR also has a Src command. Running it on this handler produced the message below. Source generation stopped at an incomplete prototype for the same call at 0x00428DFC. The annotated disassembly remained available. Testing whether function length affects Src would require separate runs.

IDR CodeViewer, with the handler address, named VCL references and the call at 0x007BDAD2.
IDR CodeViewer, with the handler address, named VCL references and the call at 0x007BDAD2.
IDR stops generating source for this handler at the incomplete prototype of sub_00428DFC.
IDR stops generating source for this handler at the incomplete prototype of sub_00428DFC.

Decompile->Try->Prototype of sub_00428DFC is not completed.

IDA 9.0 with Hex-Rays

Hex-Rays produced C-like pseudocode for the handler. At the corresponding branch, it emitted if ((unsigned __int8)sub_428DFC()). Its view of the surrounding code includes the Windows exception-registration setup and indirect calls expressed as pointer dereferences. The branch and the following + Load string line up with the same region in the other two listings.

The corresponding section in Hex-Rays pseudocode. The file check remains a call to sub_428DFC.
The corresponding section in Hex-Rays pseudocode. The file check remains a call to sub_428DFC.

Reproduce the comparison with ToDoList

Download ToDoList.exe and its SHA-256 manifest (ZIP)

Use the PE32 executable with the preferred image base 0x00400000. The handler is at VA 0x006A5894 (RVA 0x002A5894). The binary DFM resource TFRMMAIN binds OnClick to cmdConnectClick. In DE Decompiler, open Code → Main → TfrmMain → cmdConnectClick_6A5894. In IDA, jump to the VA and open Pseudocode with F5. In IDR, open _Unit86.TfrmMain.cmdConnectClick and try Src.

SHA-256 of ToDoList.exe
0beb09e9d3c84db81dcaa96a8c1582c87266d24339d1e12437721d2187ff4e7d

DE Decompiler 26.7

The first branch checks the value read from Self.txtName and shows “Enter the program name” when it is empty. The other branch reads Self.txtPass and compares the local value with zero. The path through 0x006A58F3 sets Self.lblStatus.Caption to “Connecting to the database”. The listing then shows how the code appends \ToDoList.dat and passes the resulting path to Proc_6A5130. Some routine names remain address-based.

The ToDoList handler in DE Decompiler, with named controls, branches and path construction.
The ToDoList handler in DE Decompiler, with named controls, branches and path construction.

IDA 9.0 with Hex-Rays

The assembly view shows what the first call receives. At 0x006A58AE the routine loads the address of a local into EDX, loads the form field at offset 0x478 into EAX and calls 0x0054B0C8. At 0x006A58BC it compares that local with zero. The following instructions also show the message literal passed to 0x005ABAAC.

Hex-Rays displays both branches in C-like pseudocode. At the first call, the inferred argument list includes the exception-chain setup values, including ExceptionList. The preceding machine instructions instead load the two values shown below. Compare the assembly with the inferred call signature before using the pseudocode to describe the call.

006A58AE  lea edx, [ebp-8]
006A58B1  mov eax, [ebx+478h]
006A58B7  call 0054B0C8h
006A58BC  cmp dword ptr [ebp-8], 0
006A58C0  jne 006A58D4h
...
006A58FD  call 00407094h
...
006A5915  call 006A5130h
Hex-Rays pseudocode with the inferred arguments to sub_54B0C8.
Hex-Rays pseudocode with the inferred arguments to sub_54B0C8.
The corresponding x86 instructions in IDA, including the field load, the call and the first branch.
The corresponding x86 instructions in IDA, including the field load, the call and the first branch.

IDR 2.6.3.14

The disassembly identifies TfrmMain.txtName at offset 0x478 and labels both calls to TControl.GetText. It also shows TLabel.SetCaption and the string-concatenation helper @UStrCat3. This makes it possible to trace the status text and the file suffix in the assembly listing.

On this sample, Src stops at an incomplete prototype for sub_00407094, called from 0x006A58FD. The AntiCrack run named a different callee. Both diagnostics identify a concrete prototype at which source generation stopped.

IDR disassembly with VCL names, the status string and the file suffix.
IDR disassembly with VCL names, the status string and the file suffix.
IDR Src stops at the incomplete prototype of sub_00407094 in the ToDoList handler.
IDR Src stops at the incomplete prototype of sub_00407094 in the ToDoList handler.

Decompile->Try->Prototype of sub_00407094 is not completed.

Read the separate VCL walkthrough with Delphi source