So I was messing with an interesting keygenme, written in C++, which derives the key based on the values of the OSINFO structure. Now, when checking for a valid key it uses the following instruction:


My question is: why isn't the key stored in a local variable or something like:[EBP-X]?

How would I translate it back into C++ so that it stores the key in DS:[key] rather than in the stack?

1 Answer 1


Use a global or static variable.


EBP (base pointer) typically holds the address of the current stack frame, in that case it's used to get the address to local variable. (reference) Global or static variables don't need such pointer, as their address is fixed on program load.

By the way: I didn't test compiling a simple program on a 32-bit compiler. 64-bit mode doesn't use segment registers.

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.