Suppose you have code like this (and you don't want to shell out the amount for the HexRays decompiler plugin):

loc_4BEEEF:                             ; CODE XREF: DriverEntry+28j
                push    50505050h       ; Tag
                push    1234h           ; NumberOfBytes
                push    ebx             ; PoolType
                call    ds:ExAllocatePoolWithTag
                cmp     eax, ebx
                jz      short loc_4BEEFF

Now for these cases I tend to write IDC scripts that collapse the push, push, push, call into a single hidden area.

However, since the hidden areas in IDA seem to be based on the address and the first push is a "named location", the indication that this is a label gets lost when I "name" my hidden area with descriptive pseudo-code, like this:

; eax := ExAllocatePoolWithTag(ebx, 1234h, 'PPPP')
                cmp     eax, ebx
                jz      short loc_4BEEFF

and if I can deduce the value of ebx, as would be possible here, I'd even convert that into:

; eax := ExAllocatePoolWithTag(NonpagedPool, 1234h, 'PPPP')
                cmp     eax, ebx
                jz      short loc_4BEEFF

Is there any way, short of starting my hidden area after the first push, that would allow me to hide the instructions and replace them with more descriptive pseudo-code, while at the same time retaining the label/name that coincides with the passing of the (last) argument?!

That is, my goal is to have it something like:

loc_4BEEEF:                             ; CODE XREF: DriverEntry+28j
                cmp     eax, ebx
                jz      short loc_4BEEFF

(the comment behind the loc_4BEEEF label is not important to me, though)

Of course allocation is but one of the cases where this applies and where the first pushed (i.e. last) argument ends up at a named location.


Yes, you can use manual instructions.

From https://www.hex-rays.com/products/ida/support/idadoc/651.shtml:


// Specify instruction represenation manually.
//      ea   - linear address
//      insn - a string represenation of the operand
// IDA will not check the specified instruction, it will simply display
// it instead of the orginal representation.

void   SetManualInsn   (long ea, string insn);

You can test it through the UI via Edit → Other → Manual instruction... or by pressing Alt+F2.

You would set the manual instruction for address 0x4BEEEF to eax := ExAllocatePoolWithTag(NonpagedPool, 1234h, 'PPPP'). You could then put the remaining pushes and call into a hidden area, or alternatively, set manual instructions for those push and call instructions with (blank space) as the manual instruction value.

  • Thanks, didn't think these would work for the purpose. Brilliant solution.
    – 0xC0000022L
    Apr 16 '16 at 18:25

Your Answer

