WaxfordSqueers
January 25th, 2005, 20:23
Howdy,
The code below comes from an Asprotect packed file. Values to the right of the <<<< signs was added by me based on the value in each register. It seems to be a check of some kind involving the CPUID instruction. I can follow it to a certain extent, but the following questions arise:
1)what is this piece of code doing? Upon return from the CPUID instruction, the AH, AL reg is manipulated to get 0F. That value is compared to 03 at 408B08, after the return. The return code is right below the main body. There's a branch there that I suspect is a good guy/bad guy thing.
2) Is there a way in softice to see the entire flag register?
It seems to me bit 21 on the flags reg is checked by way of an XOR to see if CPUID is supported. Also, bit 18 is checked for alignment. It's possible other flags are being manipulated that I can't see out of inexperience. It would be nice to watch them as it happened.
BTW...I have Iceext loaded (XP with SP2 and Ice 4.3.1) with full protection on. It does such a good job that even symbol loader can't find softice. :-) Setting byte one of the unhandledexceptionfilter code to 90, dynamically in memory, before Iceext loads, allows all the hiding features of Iceext to come on. It replaces the NOP with 68, but it doesn't seem to want to load that protection otherwise if Softice grabs it with a CC first.
3)there's a POPFD instruction at 408AC3 that adds the value in the stack to the value in the EAX register. How does that work? Before the POPFD, the EAX was 0x00000003. After the POPFD, it was 40206, and the POPFD value was 40202. Can POPFD add to a value in a register? I don't see that in any Intel literature. I can't see anything that would have altered the flags from the time they were pushed and re-popped, unless the XOR at 408ABA altered the parity and auxiliary flag, or something.
00408AA4 53 push ebx
00408AA5 51 push ecx
00408AA6 52 push edx
00408AA7 89 E3 mov ebx, esp
00408AA9 83 E4 FC and esp, 0FFFFFFFCh
00408AAC 9C pushfd <<<<<<<<00000202
00408AAD 9C pushfd <<<<<<<<00000202
00408AAE 58 pop eax <<<<<00000202
00408AAF 89 C1 mov ecx, eax <<<<ECX= 00000202
00408AB1 35 00 00 04 00 xor eax, 40000h <<<0040202
00408AB6 50 push eax <<<<0040202
00408AB7 9D popfd
00408AB8 9C pushfd
00408AB9 58 pop eax <<<<40202
00408ABA 31 C8 xor eax, ecx <<<EAX=40000 after the XOR
00408ABC B8 03 00 00 00 mov eax, 3 <<<EAX = 00000003
00408AC1 74 24 jz short loc_408AE7
00408AC3 9C pushfd
00408AC4 58 pop eax <<<<0040206
00408AC5 89 C1 mov ecx, eax
00408AC7 35 00 00 20 00 xor eax, 200000 <<<<240206h
00408ACC 50 push eax <<<<240206
00408ACD 9D popfd
00408ACE 9C pushfd
00408ACF 58 pop eax <<<<204026
00408AD0 31 C8 xor eax, ecx <<<EAX=200000 (ECX was 40206)
00408AD2 B8 04 00 00 00 mov eax, 4 <<<EAX=4
00408AD7 74 0E jz short loc_408AE7
00408AD9 53 push ebx <<<<12FF68
00408ADA B8 01 00 00 00 mov eax, 1
00408ADF 0F A2 cpuid <<<<ret EAX=F27; EBX=1080A;
ECX=4400;EDX=BFEBFBFF
00408AE1 88 E0 mov al, ah <<<eax=0000000F
00408AE3 83 E0 0F and eax, 0Fh
00408AE6 5B pop ebx
00408AE7
00408AE7 loc_408AE7:
00408AE7 ; sub_408AA4+33j
00408AE7 9D popfd
00408AE8 89 DC mov esp, ebx
00408AEA 5A pop edx
00408AEB 59 pop ecx
00408AEC 5B pop ebx
00408AED C3 retn to 408B03
00408B03 mov ds:dword_413098, eax
00408B08 cmp ds:dword_413098, 3 <<<<<cmp F to 3.
00408B0F jle short loc_408B26
00408B11 mov ds:dword_413090, offset loc_4046B8
00408B1B mov ds:dword_413094, offset loc_4046D8
00408B25 C3 retn
The code below comes from an Asprotect packed file. Values to the right of the <<<< signs was added by me based on the value in each register. It seems to be a check of some kind involving the CPUID instruction. I can follow it to a certain extent, but the following questions arise:
1)what is this piece of code doing? Upon return from the CPUID instruction, the AH, AL reg is manipulated to get 0F. That value is compared to 03 at 408B08, after the return. The return code is right below the main body. There's a branch there that I suspect is a good guy/bad guy thing.
2) Is there a way in softice to see the entire flag register?
It seems to me bit 21 on the flags reg is checked by way of an XOR to see if CPUID is supported. Also, bit 18 is checked for alignment. It's possible other flags are being manipulated that I can't see out of inexperience. It would be nice to watch them as it happened.
BTW...I have Iceext loaded (XP with SP2 and Ice 4.3.1) with full protection on. It does such a good job that even symbol loader can't find softice. :-) Setting byte one of the unhandledexceptionfilter code to 90, dynamically in memory, before Iceext loads, allows all the hiding features of Iceext to come on. It replaces the NOP with 68, but it doesn't seem to want to load that protection otherwise if Softice grabs it with a CC first.
3)there's a POPFD instruction at 408AC3 that adds the value in the stack to the value in the EAX register. How does that work? Before the POPFD, the EAX was 0x00000003. After the POPFD, it was 40206, and the POPFD value was 40202. Can POPFD add to a value in a register? I don't see that in any Intel literature. I can't see anything that would have altered the flags from the time they were pushed and re-popped, unless the XOR at 408ABA altered the parity and auxiliary flag, or something.
00408AA4 53 push ebx
00408AA5 51 push ecx
00408AA6 52 push edx
00408AA7 89 E3 mov ebx, esp
00408AA9 83 E4 FC and esp, 0FFFFFFFCh
00408AAC 9C pushfd <<<<<<<<00000202
00408AAD 9C pushfd <<<<<<<<00000202
00408AAE 58 pop eax <<<<<00000202
00408AAF 89 C1 mov ecx, eax <<<<ECX= 00000202
00408AB1 35 00 00 04 00 xor eax, 40000h <<<0040202
00408AB6 50 push eax <<<<0040202
00408AB7 9D popfd
00408AB8 9C pushfd
00408AB9 58 pop eax <<<<40202
00408ABA 31 C8 xor eax, ecx <<<EAX=40000 after the XOR
00408ABC B8 03 00 00 00 mov eax, 3 <<<EAX = 00000003
00408AC1 74 24 jz short loc_408AE7
00408AC3 9C pushfd
00408AC4 58 pop eax <<<<0040206
00408AC5 89 C1 mov ecx, eax
00408AC7 35 00 00 20 00 xor eax, 200000 <<<<240206h
00408ACC 50 push eax <<<<240206
00408ACD 9D popfd
00408ACE 9C pushfd
00408ACF 58 pop eax <<<<204026
00408AD0 31 C8 xor eax, ecx <<<EAX=200000 (ECX was 40206)
00408AD2 B8 04 00 00 00 mov eax, 4 <<<EAX=4
00408AD7 74 0E jz short loc_408AE7
00408AD9 53 push ebx <<<<12FF68
00408ADA B8 01 00 00 00 mov eax, 1
00408ADF 0F A2 cpuid <<<<ret EAX=F27; EBX=1080A;
ECX=4400;EDX=BFEBFBFF
00408AE1 88 E0 mov al, ah <<<eax=0000000F
00408AE3 83 E0 0F and eax, 0Fh
00408AE6 5B pop ebx
00408AE7
00408AE7 loc_408AE7:
00408AE7 ; sub_408AA4+33j
00408AE7 9D popfd
00408AE8 89 DC mov esp, ebx
00408AEA 5A pop edx
00408AEB 59 pop ecx
00408AEC 5B pop ebx
00408AED C3 retn to 408B03
00408B03 mov ds:dword_413098, eax
00408B08 cmp ds:dword_413098, 3 <<<<<cmp F to 3.
00408B0F jle short loc_408B26
00408B11 mov ds:dword_413090, offset loc_4046B8
00408B1B mov ds:dword_413094, offset loc_4046D8
00408B25 C3 retn