THTD
September 9th, 2005, 13:24
Hi to everyone...
I am learning the difficult art of RCE, but I am already encountering difficulties
I am currently looking at crackme #2 from deroko (http://www.crackmes.de/users/deroko/derokos_crackme_2/) and I can't understand what happens when the programs tries to check the serial.
As soon as GetDlgItemTextA returns, the EAX register holds the length of the string coming as input. This value is used to perform a simple check on the length of the key (Serial_Length=0xE).
Now, as soon as I enter check key, problems start coming out. The code is the following:
Now my questions:
In order to install another Exception Handler, shouldn't I do something like:
mov large fs:[0], offset Exception_Handler ??
What this three instruction do? they seems to copy the wrong value into fs:[0]:
Also, when debugging, as soon as the popf instruction is executed, I get the value of 0x202 in the EFLAGS register.... Why? Shouldn't I find 0x100?
Intel reference manual says that (IDA Tells that operandsize attribute is 32bit):
The solution of the crackme just says that the program is setting the singlestep flag...
Also, could anybody point me to a __complete__ tutorial on SEH inner workings?? I seem to find noone...
Best regards,
THTD
I am learning the difficult art of RCE, but I am already encountering difficulties

I am currently looking at crackme #2 from deroko (http://www.crackmes.de/users/deroko/derokos_crackme_2/) and I can't understand what happens when the programs tries to check the serial.
Code:
CODE:004011BD push 100h ; nMaxCount
CODE:004011C2 push offset String ; lpString
CODE:004011C7 push 0 ; nIDDlgItem
CODE:004011C9 push [ebp+hWnd] ; hDlg
CODE:004011CC call GetDlgItemTextA
CODE:004011CC
CODE:004011CC // Reads the string from the form!
CODE:004011CC
CODE:004011CC GetDlgItemTextA(hWnd,0,&String,100);
CODE:004011CC
CODE:004011D1 cmp eax, Serial_Length
CODE:004011D4 jnz short @@wrong_serial
CODE:004011D4
CODE:004011D6 call check_key
As soon as GetDlgItemTextA returns, the EAX register holds the length of the string coming as input. This value is used to perform a simple check on the length of the key (Serial_Length=0xE).
Now, as soon as I enter check key, problems start coming out. The code is the following:
Code:
CODE:004012CA xor edx, edx ; EDX is zeroed
CODE:004012CC push offset Exception_Handler ; Put on the stack the pointer to the exception handler
CODE:004012D1 push dword ptr fs:[edx] ; Puts on the stack the current value at fs:[0]
CODE:004012D4 mov fs:[edx], esp ; Install as new Exception Handler the value in ESP
CODE:004012D7 xor eax, eax ; EAX is zeroed
CODE:004012D9 or eax, 100h ; EAX = EAX | 100h --> EAX = 100h
CODE:004012DE push eax ; Put on the stack 100h
CODE:004012DF popf ; Pop into EFLAGS what is on the stack
CODE:004012E0 jmp short loc_4012E8 ; Proceed
CODE:004012E0
Now my questions:
In order to install another Exception Handler, shouldn't I do something like:
mov large fs:[0], offset Exception_Handler ??
What this three instruction do? they seems to copy the wrong value into fs:[0]:
Code:
CODE:004012CC push offset Exception_Handler
CODE:004012D1 push dword ptr fs:[edx]
CODE:004012D4 mov fs:[edx], esp <-- this puts a wrong value??
Also, when debugging, as soon as the popf instruction is executed, I get the value of 0x202 in the EFLAGS register.... Why? Shouldn't I find 0x100?
Intel reference manual says that (IDA Tells that operandsize attribute is 32bit):
Quote:
These instructions pop a doubleword (POPFD) from the top of the stack (if the current operandsize attribute is 32) and stores the value in the EFLAGS register, or pops a word from the top of the stack (if the operand-size attribute is 16) and stores it in the lower 16 bits of the EFLAGS register (that is, the FLAGS register). |
The solution of the crackme just says that the program is setting the singlestep flag...
Also, could anybody point me to a __complete__ tutorial on SEH inner workings?? I seem to find noone...

Best regards,
THTD