flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Accessing reserved data without ORG in a flat binary proc

Author
Thread Post new topic Reply to topic
Beege



Joined: 24 Nov 2018
Posts: 8
Location: USA Indiana
Beege
Hi, Quick back story, I was introduced to assembly/fasm years ago via AutoIt scripting langauge for windows by a member who created a library for using fasm.dll. Autoit is great for a lot of things but it is an interpreting language so can get kinda slow in certain situations (mainly functions with tons of loops) and thats where fasm came in great. Using the dll, I generate flat binary procedures (correct term?), load the opcode output from dll into memory and then execute that memory location like any other function in the script.

Recently I added a package for fasmg (Link below) and would love to confirm if I am correct about accessing reserved data when generating code like this (single procedure only) and not using the ORG statement to specify the memory location the code is going to be executed at. I like using ORG for quickly writing and testing code but also like to write the code not using ORG so it can be saved as binary string in script and later execute without requiring the fasmg.dll and includes files. I know I can pass the function the current address as a parameter and then access the data that way, but mainly just want to be sure thats my only option if I dont use ORG.

Below is a sample inline fasmg fuction I would put in my script. This first code below out fine when passing the current address as pCurrentMemAddr and I have told myself thats the only way I can do it, but I want to be sure.

Code:
;"force" is just a macro that creates an annoynomous label to ensure _TestDataAccess is generated (since nothing calls this function within fasmg).
force _TestDataAccess ;
proc _TestDataAccess uses ebx, pCurrentMemAddr, iParm2
        mov ebx, [pCurrentMemAddr]
        mov eax, [ebx+iTest]
        add eax, [iParm2]
        ret
        iTest dd 0xAABBCCDD
endp    


Here pCurrentMemAddr is taken out of the function. Is there any other way reach that data? Possibly something with LOAD/STORE?
Code:
force _TestDataAccess ;
proc _TestDataAccess, iParm2
        ;
                Anything I can put here to reach iTest? 
        ;
        add eax, [iParm2]
        ret
        iTest dd 0xAABBCCDD
endp    


Any feedback is appreciated. Thanks

https://www.autoitscript.com/forum/topic/199758-flat-assembler-g-udf
https://www.autoitscript.com/forum/topic/197423-a-new-way-to-write-fasm-assembly-code-with-extended-headers
Post 02 Sep 2019, 18:55
View user's profile Send private message Reply with quote
st



Joined: 12 Jul 2019
Posts: 34
Location: Russia
st
In 32 bit mode the current address (instruction pointer register) can be obtained with the following code snippet
Code:
        call delta
delta:  pop ebx    

I think there should be some topics about Position Independent Code (PIC) here. For example https://board.flatassembler.net/topic.php?p=66010
Post 03 Sep 2019, 08:03
View user's profile Send private message Visit poster's website Reply with quote
Beege



Joined: 24 Nov 2018
Posts: 8
Location: USA Indiana
Beege
Wow that's an awesome trick! thank you!
Post 03 Sep 2019, 14:53
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-2019, Tomasz Grysztar.

Powered by rwasa.