Skip to content

How to properly reference data added using the CodeAssembler .db function in 32-bit mode? #279

Answered by wtfsck
netadr asked this question in Q&A
Discussion options

You must be logged in to vote

That example is from the README and uses 64-bit mode and will fail in 16/32-bit mode.

One workaround is to get the address of the label after assembling it (see assemble_options()?.label_ip() and then patching an instruction, eg. a 'mov eax,imm32' instruction. You can get the offset of the imm32 by passing in BlockEncoderOptions::RETURN_CONSTANT_OFFSETS | BlockEncoderOptions::RETURN_NEW_INSTRUCTION_OFFSETS to assemble_options().

Another one is to do something like:

call there
my_data:
db 1,2,3,4
there:
pop eax

eax now has the address of my_data.

I created an issue: #281

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by netadr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants