flat assembler
Message board for the users of flat assembler.

Index > Linux > Minor Self Modifying Code linker (maybe) bug

Author
Thread Post new topic Reply to topic
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 21 Jul 2004, 04:11
I don't know why and why not, but when i specify "format elf executable" my smc code cannot run without a segfault. But when i specify "format elf" and link with ld, my smc code does fine.

Here is my code (linux2.6 debian fasm 1.53)

Code:
format ELF
public start

section ".data" align 0x1000
modified_code rb 0x8000

sys.write = 4
sys.mprotect = 125

macro sys.write fd, buf, count{
        mov eax, 4
        mov ebx, fd
        mov ecx, buf
        mov edx, count
        int 80h
}
read = 1
write = 2
exec = 4

stdout = 1

section ".data"string db "Hello World!", 0xA
sizeof.string = $-string

section ".text"
start:
        mov ebp, modified_code

        mov eax, sys.mprotect
        mov ebx, ebp
        mov ecx, 0x8000
        mov edx, read+write+exec
        int 80h

        test eax, eax
        js .error
.tocopy:
        sys.write stdout, string, sizeof.string

        sizeof.start.tocopy= $-.tocopy

        mov ebx, 90
        mov edi, modified_code
.loop:
        mov esi, .tocopy
        mov ecx, sizeof.start.tocopy
        rep movsb
        dec ebx
        jnz .loop

        mov al, 0xc3
        stosb
        jmp .blah
.blah:

        call ebp
 .error:
        mov eax, 1
        mov ebx, 0
        int 80h     


Sorry for the lack of comments. Anyway, when i change it to executable, and then change all the segments to either (writeable readable) or (executeable) it just wont work.

The changes look like this:
from
Code:
section ".data" align 0x1000
    


to
Code:
section readable writeable
align 0x1000
    


if it has to do with anything. And this is applied to all section headers thoughout the source.

Linking with LD works fine however , so i think this is a linker error. No clue though Smile

This should print 91 "Hello World!", 0xa
out
Post 21 Jul 2004, 04:11
View user's profile Send private message Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 21 Jul 2004, 05:01
And just incase the above isn't a bug, but something wrong on my part...
I'll post the well known fasm linux "bug" that sets default permisions to read/write on executables, instead of read/write/exec
Post 21 Jul 2004, 05:01
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 21 Jul 2004, 07:52
Your first problem has just been fixed, please read the http://board.flatassembler.net/topic.php?t=1877 thread.

As for the second one, it's just because fasm's interface doesn't know whether the file generated by core is an executable or not. Even in case when it could know it (as with "format ELF executable" directive, in the same way as FASMW's extension guessing) it might not be sure, so it leaves it to the user to give the right permissions to that file (and of course he needs to know what is he doing).
Post 21 Jul 2004, 07:52
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.