0

I wrote a very basic crackme to learn how assembly works.

Even though I wrote it myself, I am having some trouble understanding a few pieces of the assembly:

enter image description here

What I know up to now is: [rbp+rax+input_buffer] is basically input_buffer[rax], xor'ing two of the same registers resets them and that's about it (apart from the very basic stuff like add, mov, inc).

I specifically don't understand what movsx .. and add ecx, 0FFF.. is doing.

The input_buffer is filled with _fgets. I'm intentionally not saying a working input to see if you can figure it out (it shouldn't be hard anyways).

A proper input would be 0123456789\n, note that I discard the newline via strcspn.

0

1 Answer 1

3

I guess the original code is something like:

char input_buffer[...];
// ...
int c = input_buffer[i];

Since the variable c is a int and input_buffer is a char[], your compiler has to promote the read char as a int. That's why you have the movsx instruction. It will read the current character and sign extend it, so it'll fit to a int.

About the add, it's common for a compiler to encode a sub dst, imm as add dst, -imm, if you negate 0xffffffd0 (SHIFT - in IDA), you'll obtain -0x30. This is how you convert the ASCII digit into a integer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.