NO

Author Topic: example of use of exe headers to put initialized datas  (Read 3499 times)

Anonymous

  • Guest
example of use of exe headers to put initialized datas
« on: November 30, 2004, 01:18:05 AM »
if your program has only one section you have 160 bytes available
to put initialized datas

example:

the program following , will print on screen 159 times X
the "XXXXXXX......X" string is contained in the exe header

you need to rebuild the dos stub using fasm, an open source compiler:

here is one adapted from one found on fasm forum:

;file=dos-exe.asm--cut here------


;-- a program for learning PE format
;note: the code below is not flexible enough
;you can try to improve it if you like
;Liu Junfeng

DOS_Header:
   .e_magic     dw "MZ"      ;IMAGE_DOS_SIGNATURE
   .e_cblp      dw 0x0080
   .e_cp        dw 0x0001
   .e_crlc      dw 0x0000
   .e_cparhdr   dw 0x0004
   .e_minalloc  dw 0x0010
   .e_maxalloc  dw 0xFFFF
   .e_ss        dw 0x0000
   .e_sp        dw 0x0140
   .e_csum      dw 0x0000
   .e_ip        dw 0x0000
   .e_cs        dw 0x0000
   .e_lfarlc    dw 0x0040
   .e_ovno      dw 0x0000
   .e_res       rw 4
   .e_oemid     dw 0x0000
   .e_oeminfo   dw 0x0000
   .e_res2      rw 10
   .e_lfanew    dd PE_header  ;PE header Offset

DOS_Stub:
 org $+DOS_Stub

times 159 db 'X'
db 0
PE_header:


;end of dos-exe.asm


//file=text.asm---cut here----

#include <stdio.h>

void main()
{
char* ptr;
ptr=(char*) 0x400040;
printf("%s",ptr);
}

//end of text.c -----cut here-----


rem file=makebin.bat----cut here----
fasm dos-exe.asm dosstub.exe
cc.exe -c  -W1 -Gd -Zl -Os -Ze -Tx86-coff  %1.c
polink  /STUB:dosstub.exe /ENTRY:main  /SUBSYSTEM:CONSOLE  /NODEFAULTLIB  /MERGE:.rdata=.text /MERGE:.data=.text /OUT: %1.exe msvcrt.lib %1.obj

rem end of makebin.bat---cut here---