flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [bug] crash while compiling sample (fasm v1.73.30)

Author
Thread Post new topic Reply to topic
vityacv



Joined: 27 Oct 2012
Posts: 7
vityacv 12 Jul 2023, 06:41
stub64.asm:
Code:
format binary 
use64 
struct IMAGE_DOS_HEADER
e_magic rw 1 
e_cblp rw 1
e_cp rw 1
e_crlc rw 1
e_cparhdr rw 1 
e_minalloc rw 1
e_maxalloc rw 1
e_ss rw 1
e_sp rw 1
e_csum rw 1
e_ip rw 1
e_cs rw 1
e_lfarlc rw 1
e_ovno rw 1
e_res rw 4 
e_oemid rw 1 
e_oeminfo rw 1 
e_res2 rw 10 
e_lfanew rd 1
ends 

teste IMAGE_DOS_HEADER 'MZ',testq.size,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,testq.size 

testq:
mov rax,1 
align 4 
testq.size = $-teste
    

test64.asm:
Code:
format pe64 on 'stub64.bin' 
entry Main
Main: 
ret 
    

results in
Code:
---------------------------                                                                                                             
fasm.exe - Application Error                                                                                                            
---------------------------                                                                                                             
The instruction at 0x0000000000419994 referenced memory at 0x0000000040B10000. The memory could not be written.                         
                                                                                                                                        
                                                                                                                                        
Click on OK to terminate the program                                                                                                    
---------------------------                                                                                                             
OK                                                                                                                                      
---------------------------     
Post 12 Jul 2023, 06:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20513
Location: In your JS exploiting you and your system
revolution 12 Jul 2023, 07:58
Your stub.asm does not assemble.
Code:
flat assembler  version 1.73.30  (16384 kilobytes memory)memory)
stub64.asm [3]:
struct IMAGE_DOS_HEADER
processed: struct IMAGE_DOS_HEADER
error: illegal instruction.    
Post 12 Jul 2023, 07: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: 20513
Location: In your JS exploiting you and your system
revolution 12 Jul 2023, 08:07
I changed stub64.asm to this:
Code:
format binary
use64
teste:  e_magic         db      'MZ'
        e_cblp          dw      testq.size
        e_cp            rw      1
        e_crlc          rw      1
        e_cparhdr       rw      1
        e_minalloc      rw      1
        e_maxalloc      rw      1
        e_ss            rw      1
        e_sp            rw      1
        e_csum          rw      1
        e_ip            rw      1
        e_cs            rw      1
        e_lfarlc        rw      1
        e_ovno          rw      1
        e_res           rw      1
        e_oemid         rw      1
        e_oeminfo       rw      1
        e_res2          rw      10
        e_lfanew        dd      testq.size

testq:
mov rax,1
align 4
testq.size = $-teste    
Now I can reproduce your resutl:
Code:
flat assembler  version 1.73.30  (16384 kilobytes memory)
Segmentation fault (core dumped)    
Post 12 Jul 2023, 08:07
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: 20513
Location: In your JS exploiting you and your system
revolution 12 Jul 2023, 08:24
In formats.inc around line 742 we can add one line:
Code:
;...
        call    lseek
        movzx   ecx,word [esi+4]
        dec     ecx
js out_of_memory  ; <--- add this line
        shl     ecx,9
        movzx   edx,word [esi+2]
        test    edx,edx
        jnz     stub_header_size_ok
;...    
Jumping to out_of_memory isn't really correct, but there is no dedicated error message to indicate a malformed stub file. At least it won't crash, it prints out of memory instead.
Post 12 Jul 2023, 08:24
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: 20513
Location: In your JS exploiting you and your system
revolution 12 Jul 2023, 16:17
No crash in 1.73.31
Code:
flat assembler  version 1.73.31  (16384 kilobytes memory)
error: out of memory.    
Post 12 Jul 2023, 16:17
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.