flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Write code that can be runs in any memory address?

Author
Thread Post new topic Reply to topic
ivan_tux



Joined: 23 Jun 2012
Posts: 27
Location: Indonesia
Hi all..
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
entry:
mov eax, [data1] ;???

Can I access data1 relative from instruction "mov eax, [data1]"? Or is there a way to access data in such problem?
Thanks before..
Post 14 Jun 2016, 11:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15975
Location: Qo'noS
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:
Code:
data1 db 1
call my_eip
my_eip:
pop ebx  ;get current EIP
mov al,[ebx+data1-my_eip]    
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.
Post 14 Jun 2016, 12:07
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1904
> so the code must can be run in any addresses of memory

Bisa Smile 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
Post 06 Jul 2016, 09:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.