Message board for the users of flat assembler.
> Main > Write code that can be runs in any memory address?
ivan_tux 14 Jun 2016, 11:36
I've been wrote a executable injector and the tested injected code can running perfectly by now.
I place code and data in one section. These part will be loaded to memory, depends on the exe configuration, so the code must can be run in any addresses of memory. But I have a problem when accessing data.
data1 db 1
data2 db 2
mov eax, [data1] ;???
Can I access data1 relative from instruction "mov eax, [data1]"? Or is there a way to access data in such problem?
|14 Jun 2016, 11:36||
revolution 14 Jun 2016, 12:07
In 32-bit code there are no EIP relative memory instructions. So you have to load a GP register with the current EIP and use that to access memory:
But this won't work if the offset from data1 to my_eip is not fixed. In that case you would need to relocate in some way.
data1 db 1 call my_eip my_eip: pop ebx ;get current EIP mov al,[ebx+data1-my_eip]
|14 Jun 2016, 12:07||
DOS386 06 Jul 2016, 09:41
> so the code must can be run in any addresses of memory
Bisa PIC (position independent code) http://board.flatassembler.net/topic.php?t=11170
Bug Nr.: 12345
Title: Hello World program compiles to 100 KB !!!
Status: Closed: NOT a Bug
|06 Jul 2016, 09:41||
< Last Thread | Next Thread >
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.