flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > fasm as DLL

Goto page Previous  1, 2, 3, 4, 5, 6
Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 06 Dec 2023, 11:51
Ben321 wrote:
To tell it that a number is hexadecimal, you can either prepend "0x" or append "h" to the number. I found this doesn't work though if the first digit of the number is a hexadecimal letter. For example, 0xF00000 works, but F00000h generates an error. It's fine if the letter is elsewhere in the hex number. This means a temporary work around hers is to prepend a zero before the first letter, like 0F00000h will work. But it's not ideal. I hope this is a bug that you can fix.
This has been discussed already: https://board.flatassembler.net/topic.php?t=20762
Post 06 Dec 2023, 11:51
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 06 Dec 2023, 11:52
All numbers must begin with a digit 0-9. The only exception is the $.
Code:
db 0xf0
db $f0
db f0 ; this is a label name 'f0'.    
Post 06 Dec 2023, 11:52
View user's profile Send private message Visit poster's website Reply with quote
Ben321



Joined: 07 Dec 2017
Posts: 70
Ben321 29 Jul 2024, 20:46
The FASM DLL outputs code that is in raw binary format, this means that then when running that code, it may not work properly if it's not loaded at the correct address. For example, lets say I made launcher in Windows (using something like C or C++ to write the launcher) that used FASM DLL to assemble code and then run it. There's no guarenty what address in memory the assembled code will be at. Therefore the fasm_Assemble function should in addition to outputting a byte array for the assembled code, it should also output relocation information, so that the launcher program that ran the fasm_Assemble function could then proceed to use this info to perform relocation fixes on the code prior to running the code.

If you don't want to add this feature to the fasm_Assemble function, maybe have the FASM DLL store this relocation info internally after running fasm_Assemble and then make a new function for the calling code to get that relocation info (maybe call it fasm_GetRelocs).

This relocation information would consist of a doubleword value stating the number of relocation entries, followed by the array of relocation entries. Each relocation entry would contain the offset to where the relocation needed to be performed, and the size of the relocation (whether it's 2, 4, or 8 bytes).

Since the launcher program for the assembled code would already know where the assembled code is in memory, it could use this relocation information to fix the absolute addresses that appear in the code.

While a simple ORG statement in the will work if the location the code will be executed from is known before assembling it, in many cases the exact location where the code will be executed from is not known before assembling the code. And leaving out the ORG statement of course is just equivalent to starting the code with an address of 0 (in other words, equivalent to "ORG 0"). So making the code that is generated by the FASM DLL, actually work properly in the launcher program (which is responsible for both assembling and running the code), will require that this launcher program have access to the relocation information.

Is this a feature you intend to add to future versions of the FASM DLL?
Post 29 Jul 2024, 20:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 29 Jul 2024, 21:05
You can write position independent code if it is important that it executes from all offsets. Code can also relocate itself if you want it to.

64-bit code is easier to make position independent than 32-bit code. But it can be done in both.
Post 29 Jul 2024, 21:05
View user's profile Send private message Visit poster's website Reply with quote
Ben321



Joined: 07 Dec 2017
Posts: 70
Ben321 30 Jul 2024, 01:07
revolution wrote:
You can write position independent code if it is important that it executes from all offsets. Code can also relocate itself if you want it to.

64-bit code is easier to make position independent than 32-bit code. But it can be done in both.

Maybe so, but I think it would expand the usefulness of the FASM DLL if it could output a list of relocations.
Post 30 Jul 2024, 01:07
View user's profile Send private message Reply with quote
Ben321



Joined: 07 Dec 2017
Posts: 70
Ben321 30 Jul 2024, 01:13
revolution wrote:
If you use PE format and include a relocs table then you will get a fully relocatable exe.


Can you use PE format in the FASM DLL? I thought the DLL version exclusively output only raw binary format.
Post 30 Jul 2024, 01:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 30 Jul 2024, 02:00
Ben321 wrote:
Can you use PE format in the FASM DLL? I thought the DLL version exclusively output only raw binary format.
Try it and see what happens.
Post 30 Jul 2024, 02:00
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5, 6

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.