flat assembler
Message board for the users of flat assembler.

Index > Main > fasm silently overwrites output file with debug info

Author
Thread Post new topic Reply to topic
dunkaist



Joined: 31 Jul 2015
Posts: 19
dunkaist
Hi Tomasz,

Due to a mistake in my makefile I got the following listing:
Code:
$ cat main.asm 
use32
xor eax, eax
ret

$ fasm main.asm main.bin -s main.fas
flat assembler  version 1.73.16  (16384 kilobytes memory, x64)
1 passes, 3 bytes.

$ fasm main.asm main.fas -s main.fas
flat assembler  version 1.73.16  (16384 kilobytes memory, x64)
1 passes, 3 bytes.

$ listing main.fas main.lst

$ ls
main.asm  main.bin  main.fas  main.lst

$ cat main.lst 
                                                                use32
00000000: 66 61                                                 xor eax, eax
00000002: 73                                                    ret    

Imagine how I was surprised to see these 66 61 73 Shocked

Please, consider adding a check for this case to fasm.
Thank you.
Post 08 Nov 2019, 23:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16840
Location: In your JS exploiting you and your system
revolution
You can also try this:
Code:
fasm main.asm main.asm -s main.asm    
Razz
Post 09 Nov 2019, 07:38
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7404
Location: Kraków, Poland
Tomasz Grysztar
This has the same problems that we discussed with "includeonce". The OS abstraction layer that fasm uses has no ability to deal with them in a reliable way. In fact, fasm is not even aware whether the file system uses case-sensitive or case-insensitive names.

A practical solution could be to write some shell script around fasm, handling things in a way appropriate for a given OS.
Post 09 Nov 2019, 08:58
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: 16840
Location: In your JS exploiting you and your system
revolution
dunkaist:

One way to detect this problem would be to temporarily mark each file as read-only.

Fasm could do this itself. Once the input has been read, mark it read-only. Once the binary has been written, mark it as read-only. Then before exiting restore the permissions to the original. If you get a permission error when writing then you know something is wrong. You would have to modify your own copy of fasm to support it.

But that wouldn't protect against output redirection:
Code:
fasm main.asm > main.asm    


Last edited by revolution on 09 Nov 2019, 16:28; edited 1 time in total
Post 09 Nov 2019, 14:27
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7404
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
Once the input has been, read mark it read-only.
Note that there are legitimate use cases when one might want to actually replace the source file with its output. I do it frequently with generated test sources, for example - but you could also have something like self-patching, etc.

Things like the attributes may also be highly OS-dependent. Good news is that you can implement such tricks entirely within the OS abstraction layer (fasm's "interface") without having to touch the fasm's core. You can make even a highly customized interface which should be able to be assembled with various versions of fasm's core with no problems.
Post 09 Nov 2019, 16:23
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: 16840
Location: In your JS exploiting you and your system
revolution
Another possibility is to write the output to a temporary filename and then rename it when it is closed.

All OSes that I have encountered will fail the rename if another file of the same name already exists.
Post 09 Nov 2019, 16:34
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7404
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
Another possibility is to write the output to a temporary filename and then rename it when it is closed.

All OSes that I have encountered will fail the rename if another file of the same name already exists.
Then you would not be able to re-assemble the same thing without deleting it first.
Post 09 Nov 2019, 16:39
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:  


< 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.