Disclaimer: I'm not asking for the solution to this problem, but for you to point out the particular areas or techniques of reverse engineering that I need to improve at in order to solve this problem myself.
The code in question comes from the game "Sourcery," it's basically a CTF inside a game. The game doesn't give you the ability to debug or modify the code whatsoever, so the problem to solve here is to find an input that will make verify_code return 1.
So far I had the idea of trying to brute force the solution, i.e. trying all possible codes until I find one that works. The range of acceptable characters for the code is all printable ascii chars, and we need to figure out 16 chars, which seems like it would take too much time to brute force unless you were able to reduce the character range.
The thing that is making this hard for me to mentally analyze is that it seems like if you change one character, it can change the effect that successive characters have on the execution path.
Any ideas how to approach this?
; int verify_code(char *code)
verify_code:
push esi
push ebp
mov ebp, esp
sub esp, 8
push dword [ebp + 12]
call strlen
cmp eax, 16
; the code must be 16 characters long.
jne .bad
mov esi, [ebp + 12]
mov edx, 0xfa
mov al, [esi]
rol edx, 5
xor dl, al
add dl, 0xab
mov al, [esi+1]
rol edx, 3
xor dl, al
add dl, 0x45
mov al, [esi+2]
rol edx, 1
xor dl, al
add dl, 0x12
mov al, [esi+3]
rol edx, 9
xor dl, al
add dl, 0xcd
mov cl, dl
and cl, 15
add cl, 'a'
cmp [esi+4], cl
jne .bad
rol edx, 12
xor dl, cl
add dl, 0x87
mov cl, dl
and cl, 15
add cl, 'a'
cmp [esi+5], cl
jne .bad
rol edx, 3
xor dl, cl
add dl, 0xef
mov cl, dl
and cl, 15
add cl, 'C'
cmp [esi+6], cl
jne .bad
rol edx, 1
xor dl, cl
add dl, 0x10
mov cl, dl
and cl, 15
add cl, 'f'
cmp [esi+7], cl
jne .bad
rol edx, 13
xor dl, cl
add dl, 0x9a
mov cl, dl
and cl, 15
add cl, 'e'
cmp [esi+8], cl
jne .bad
rol edx, 9
xor dl, cl
add dl, 0xa8
mov cl, dl
and cl, 15
add cl, 'D'
cmp [esi+9], cl
jne .bad
rol edx, 7
xor dl, cl
add dl, 0xca
mov cl, dl
and cl, 15
add cl, 'D'
cmp [esi+10], cl
jne .bad
rol edx, 2
xor dl, cl
add dl, 0x91
mov cl, dl
and cl, 15
add cl, 'c'
cmp [esi+11], cl
jne .bad
rol edx, 5
xor dl, cl
add dl, 0x86
mov cl, dl
and cl, 15
add cl, 'A'
cmp [esi+12], cl
jne .bad
rol edx, 6
xor dl, cl
add dl, 0xf1
mov cl, dl
and cl, 15
add cl, 'e'
cmp [esi+13], cl
jne .bad
rol edx, 3
xor dl, cl
add dl, 0x1f
mov cl, dl
and cl, 15
add cl, 'B'
cmp [esi+14], cl
jne .bad
rol edx, 4
xor dl, cl
add dl, 0x90
mov cl, dl
and cl, 15
add cl, 'f'
cmp [esi+15], cl
jne .bad
mov al, 1
mov esp, ebp
pop ebp
pop esi
ret 4
.bad:
xor al, al
mov esp, ebp
pop ebp
pop esi
ret 4