ELF Binary takes user input and stores it in
0x4020e8. Further, the registers going into the instruction set are
|length of user input (min length is 3)||0||0x4020e8||0x539||0x4020e8|
;-- __: 0x0040108a 678a5901 mov bl, byte [ecx + 1] 0x0040108e 01da add edx, ebx 0x00401090 ffc1 inc ecx 0x00401092 ffc8 dec eax 0x00401094 75f4 jne loc.__ 0x00401096 01d2 add edx, edx 0x00401098 89d0 mov eax, edx 0x0040109a 31d2 xor edx, edx 0x0040109c b911000000 mov ecx, 0x11 ; 17 0x004010a1 f7f1 div ecx 0x004010a3 80c230 add dl, 0x30 ; 48 0x004010a6 678a06 mov al, byte [esi] 0x004010a9 28c2 sub dl, al 0x004010ab 84d2 test dl, dl 0x004010ad 7405 je loc.go_on
The instruction set is basically adding the ord value of each character to the decimal 1337 then doubling it and mod dividing it by 17. That's not exactly correct but it's a close enough synopsis for what I'm trying to say.
I can script out a solution for it in python easily enough.
test = 100 while True: pin = str(test) var = 1337 var += sum([ord(c) for c in pin[1:]]) + 10 var *= 2 var %= 17 var += 48 if var == ord(pin): print(test) break test += 1
Looking at the python, you can see the little distinctions between my synopsis and the actual algorithm.
What I am hoping to find out is how to actually turn the instruction set into a best approximation of the original source code. If I were using IDA pro (just for example) it would de-compile those instructions into an actual formula. How can I reproduce that effort manually?
I'm a self learner so books or other resources on tips and tricks for decompilation would be most helpful.
EDIT 1-1-2023 The answers I've gotten thus far make me think that I am not explaining my question well. I apologize for that.
I'm trying to go from the low level assembly to the highest level, completely human-readable format of the formula.
After some thought, I came to realize that the original formula must have been very similar to
y - 48 = ((1337 + x + 10) * 2) mod 17
y=ordinal value of first string character
x=the sum of the ordinal values of the remaining string charaters.
That high level formula is what I am trying to get to.