OK, now I'm flummoxed. I finally rebuilt a logical PE file out of this s***, and suddenly I get the Congratulations message (but only if I don't set certain breakpoints, some are OK, some aren't). My hat's off to you Code_Inside, you turned this PE file inside out, chewed it up, and spat out... something.
I started by trying to answer Clandestiny's question about IIDKing. The *reason* it can't insert another section in the PE Header is because there's not enough empty bytes after the Section header, either because of the original code, or because of the advert crap PEditor 1.7 puts in there if you used it. If you made a raw image dump, then the real code begins at 1000h, so you can fill that whole section from the end of the Section header around 1B8h to 1000h with 0's. IIDKing will now be able to insert a new section.
I found a problem with this anyway because the image file extends to 4F1000, and IIDKing wipes out most of it because I guess it doesn't really recognize the still screwed up PE header. Well, I could see that all of the code was between 1000h and 1430h, and I was getting fed up with this F1000h file size (964KB), so I decided to create a "proper" PE file.
I deleted everything from 2000h onwards, this left me with just a .text section from 1000h to 2000h. Then I rebuilt my own .idata section of the 3 API's at 2000h. I used the existing one as a template, and just changed the IMAGE_IMPORT_DESCRIPTOR pointers and the IAT pointers. While messing with getting the file to run, I finally realized what that 3rd section, the one I called .wtf, really is! This is the one in the original file that has a Raw and Virtual Offset of 0000000. Very peculiar this. Turns out this is actually the PE header, beginning at the ImageBase Virtual Address of 400000. This section seems necessary to map the PE header into memory so part of it can be overwritten at:
:00401107 BE20114000 mov esi, 00401120
:0040110C BF00004000 mov edi, 00400000
:00401111 F3 repz
:00401112 A4 movsb
and elsewhere. If the 400000 address is not mapped properly, the repz/movsb code crashes. Anyway, that was interesting, I kept wondering why I couldn't delete that .wtf section. (Which is why I called it .wtf
To continue, I realized that the original Import Table, at F0000, is **required** to be mapped there, because the SMC code at 4011A0 at one point calls GetTickCount, and it's looking for it in this memory range. But, I didn't want a raw file this big, so I discarded my rebuilt IT and copied the original Import table, including the IAT, (i.e. from F0000h to F0090h in the dumped file, or 200h to 290h in the original file) and inserted it in a new .idata section at 2000h. Then I set the Virtual Offset to be F0000 so it would be mapped where it was expected to be.
So my final Section header looks like:
.text VSize=2000, VOff=1000, RSize=1000, ROff=1000, Char=E0000020
.idata VSize=1000, VOff=F0000, RSize=1000, ROff=2000, Char=C0000040
.wtf VSize=400, VOff=0000, RSize=400, ROff=0000, Char=C0000040
SizeOfImage=F1000
OEP=401100
*note- raw size of .text can be 1000h (minimum 430h), but virtual size *must* be 2000 (or somewhere in there) because this memory, even though it only contains 0's, is read/written to at some point and must be mapped to prevent a crash.
Not sure where the checks are, but this rebuilt file seems to call the Goodboy message box. IIDKing also seems to be able to insert API's properly now. I inserted 10 new API's:
CreateFileA, ReadFile, WriteFile if I wanted to read JimmyClif's encrypted file into memory to decrypt it.
CreateFileA, CreateFileMapping, MapViewOfFile, UnmapViewOfFile, CloseHandle if I wanted to map it into memory.
LoadLibraryA, GetProcAddress, FreeLibraryA if I wanted to call my own dll to do the dirty work.
Kayaker