The task is to add the code to the working state.
some_var dd ? ... // код // здесь мы имеем в регистре eax, к примеру, адрес переменной some_var
The solution is obvious - lea eax, [some_var]
, but it does not suit me for the reason that it is not position-independent (I tried to translate it into Russian in the title of the question). In other words, I need a code that can be copied together with the data at any address and get it in working order. Variables must have been global.
My decision is based on the fact that the difference between tag addresses does not depend on the position of the code. During compilation, you can find out the addresses of labels for a fixed address for placing a code, and its real position after the transfer - with the help of call $+5
, pop eax
. Now I get out, but the resulting code is too cumbersome. On the other hand, it is not reflected in the source code, as it is wrapped in a macro.
The question is - is there a simpler solution? I use fasm, maybe its preprocessor is capable of that.
My version
call $+5 label: lea eax, [label] sub [esp], eax lea eax, [var] add [esp], eax pop eax