Kayaker
April 27th, 2001, 23:36
Hi All,
Madmax!'s post made me dig up some old notes that I'll pass on if it can help anyone. You're right, Revirgin doesn't seem to handle what Pex does. But that's not why I'm writing. Pex .99 is actually a very interesting packer to study for anyone wanting to see an example of wtf a "redirected API" is, what with all this talk of it with Asprotect and such (you listening Clandestiny
I'll use the example of packing Win98SE Notepad with Pex 0.99 with the Import encryption option. The IAT start RVA is 4062e0 in the regular file, same in the packed file.
I'll actually be discussing what's happening in the packed file, but if you want to unpack it, what I did was to break into the Import encryption routine by setting BP's on pops and popads until I found it. There's probably a better way to do it using an API, I just kind of winged it through the code as I went along. I've found that *sometimes* pops and popads are like little stable islands in Self Modifying Code (SMC) that you can set breakpoints on. Actually, a quick way to get close to the OEP and bypass even the Import encryption routine is to break on VirtualFree. A few SMC runs with RET's after this is the jump to the OEP, where you can dump an unpacked file, albeit with corrupted IT, as usual.
:0040D03C 50 PUSH EAX ;4010CC for Notepad
:0040D03D C3 RET
Now comes the interesting part. Continue into notepad after unpacking. The 1st Call is at
4010d3 Call [4063e0]
If you display the contents of 4063e0, which is an address within the IAT, you see it points to 40d6d7. This is actually the concept of a "redirected" API. Normally this should point to the ASCII API name, but, well, it's redirected.
Go to 40d6d7 and there's an immediate jump to GetCommandLineA:
:0040D6D7 E9FEEEB7BF JMP KERNEL32!GetCommandLineA
This is the simplest situation, a direct jump. Now how do we know that the bytes E9FEEEB7BF jump to that API? If you add the effective RVA at the end of the 40d6d7 line, where the jump actually takes place from, with the offset in the bytes, you get the API address. i.e.
40d6d7 + 5 bytes = 40d6dc.
Add 40d6dc + BF B7 EE FE (reverse order) = BFFBC5DA = Address GetCommandLineA
E9 is just the opcode for far jump.
You can use Exescope for example on Kernel32.dll to confirm that BFFBC5DA is the start of the GetCommandLineA function.
...continued...
Madmax!'s post made me dig up some old notes that I'll pass on if it can help anyone. You're right, Revirgin doesn't seem to handle what Pex does. But that's not why I'm writing. Pex .99 is actually a very interesting packer to study for anyone wanting to see an example of wtf a "redirected API" is, what with all this talk of it with Asprotect and such (you listening Clandestiny

I'll use the example of packing Win98SE Notepad with Pex 0.99 with the Import encryption option. The IAT start RVA is 4062e0 in the regular file, same in the packed file.
I'll actually be discussing what's happening in the packed file, but if you want to unpack it, what I did was to break into the Import encryption routine by setting BP's on pops and popads until I found it. There's probably a better way to do it using an API, I just kind of winged it through the code as I went along. I've found that *sometimes* pops and popads are like little stable islands in Self Modifying Code (SMC) that you can set breakpoints on. Actually, a quick way to get close to the OEP and bypass even the Import encryption routine is to break on VirtualFree. A few SMC runs with RET's after this is the jump to the OEP, where you can dump an unpacked file, albeit with corrupted IT, as usual.
:0040D03C 50 PUSH EAX ;4010CC for Notepad
:0040D03D C3 RET
Now comes the interesting part. Continue into notepad after unpacking. The 1st Call is at
4010d3 Call [4063e0]
If you display the contents of 4063e0, which is an address within the IAT, you see it points to 40d6d7. This is actually the concept of a "redirected" API. Normally this should point to the ASCII API name, but, well, it's redirected.
Go to 40d6d7 and there's an immediate jump to GetCommandLineA:
:0040D6D7 E9FEEEB7BF JMP KERNEL32!GetCommandLineA
This is the simplest situation, a direct jump. Now how do we know that the bytes E9FEEEB7BF jump to that API? If you add the effective RVA at the end of the 40d6d7 line, where the jump actually takes place from, with the offset in the bytes, you get the API address. i.e.
40d6d7 + 5 bytes = 40d6dc.
Add 40d6dc + BF B7 EE FE (reverse order) = BFFBC5DA = Address GetCommandLineA
E9 is just the opcode for far jump.
You can use Exescope for example on Kernel32.dll to confirm that BFFBC5DA is the start of the GetCommandLineA function.
...continued...