flat assembler
Message board for the users of flat assembler.

Index > Main > Change output data (modify MZ stub of PE from source code)

Author
Thread Post new topic Reply to topic
Leo_yz



Joined: 05 Feb 2010
Posts: 2
Location: Russia
Leo_yz 09 May 2010, 14:11
How can I change the output data at compile stage?
I need to write addr of label to MZ-header.(STUB or somewhere)
For example:
Code:
format PE GUI 4.0
entry start
section '' code readable writeable
somedata db 'data',0

start:
ret
    

I need to write addr of label to "somedata" after MZ-signature - at offset 0x2 of EXE file. How can it be done?
Help me please Embarassed

EDIT by DOS386 : enhanced subject
Post 09 May 2010, 14:11
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko 09 May 2010, 14:56
store dword 'leo:' at $xxxxxxxx

edit: weird i cannot store to $400'000
Post 09 May 2010, 14:56
View user's profile Send private message Reply with quote
Leo_yz



Joined: 05 Feb 2010
Posts: 2
Location: Russia
Leo_yz 09 May 2010, 15:50
Quote:
Both load and store directives are limited to operate on places in current addressing space. The $$ symbol is always equal to the base address of current addressing space, and the $ symbol is the address of current position in that addressing space, therefore these two values define limits of the area, where load and store can operate.
Post 09 May 2010, 15:50
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko 09 May 2010, 19:32
edit
Hope Tomasz will ever fix that.
Number display macros you can use to see addresses etc:
http://board.flatassembler.net/topic.php?t=11516


Last edited by edemko on 17 May 2010, 12:29; edited 1 time in total
Post 09 May 2010, 19:32
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 09 May 2010, 19:57
You can't do that*. Also, are you sure you want it at that offset?? Note those are not unused bytes: http://www.delorie.com/djgpp/doc/exe/

*Well you could by using "format binary as 'exe'" and then defining all the MZ and PE structures yourself instead of letting fasm do that for you. Some people posted examples in this forum but I can't find them now... Also, you could use the debugging information and an external tool that search for your label in the .fas file and then patches the executable with the address the file says the label is located at.
Post 09 May 2010, 19:57
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko 09 May 2010, 20:07
...or you are just approaching masm Sad
fasm must go forward Smile
he might wants some file stamping or
needS to write addr of label to MZ-header.(STUB or somewhere)

masm: no provocation - facts
Post 09 May 2010, 20:07
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 10 May 2010, 08:09
Quote:
I need to write addr of label to "somedata" after MZ-signature - at offset 0x2 of EXE file. How can it be done? Help me please Embarassed


Bad idea.

Quote:
Some people posted examples in this forum but I can't find them now


Can't find the forest anymore because of all the trees Laughing

http://board.flatassembler.net/topic.php?t=10874

Code:
; *** MZ-Header, stub (0,$60) ***

ccstacktop = $1040 ; MZ header $20 ; Program $0040 ; Heap 0 ; Stack $1000

  db "MZ"          ; Mark's Sigi
  dw $60           ; Bytes in last block (0 is full, includes header size)
  dw 1             ; Blocks per 512 Bytes (includes header size)
  db 0,0           ; No relocs
  db 2,0           ; Header size
  dw $1000         ; Min (Heap + Stack) 4 KiB
  dw $1000         ; Max (Heap + Stack) 4 KiB
  dw 0             ; Stack segment: SS=CS !!!
  dw ccstacktop    ; Stack size (almost 4 KiB) / pointer in bytes !!!
  db 0,0,0,0,0,0   ; CHK, IP, CS
  dw $1C           ; Useless reloc offset
  db 0,0           ; Useless "overlay"
  db 0,0,0,0       ; Padding / empty reloc

; org = $20 , should be 0 but irrelevant Very Happy

  db $0E,$1F         ; PUSH CS   | POPE DS
  db $B4,9,$BA,$20,0 ; MOV AH, 9 | MOV DX, $0020
  db $CD,$21         ; INT $21
  db $B8,1,$4C       ; MOV AX, $4C01
  db $CD,$21         ; INT $21
  db 0,0             ; Wasting 2 bytes

; org = $30

  db 0,0,0,0,0,0,0,0,0,0,0,0   ; Wasting 12 bytes
  db $60,0,0,0                 ; PE begins here

; org = $40, should be $20

  db "Need HX-DOS Extender to run !",$0D,$0A,$24 ; 29 chars + 3 special

; org = $60, content moved by +$20 bytes

; *** PE-Header ($60,$1Cool ***

db "PE", 0, 0 ; Signature
    


Put it somewhere where I wrote "padding" or "wasting" Wink

Quote:
edit: weird i cannot store to $400'000


better: $0040'0000 AKA 4 MiB
Post 10 May 2010, 08:09
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.