flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Pelles C vs FASM executable

Thread Post new topic Reply to topic

Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY 12 Sep 2005, 14:45
I did some tests on the .exes outputed by both FASM and Pelles C:

C code:
#include <stdio.h>
#include <windows.h>
void mymain() {
__asm {
jmp @skip
db 0xC3
BYTE c=0;
int i=0;
FILE *fp=fopen("test.exe","rb");
if(c==0xC3) goto found;
goto lop;
printf("%x %x",i, c);

FASM code:
format PE console
include '%fasminc%\win32ax.inc'
jmp skip
retop: db 0c3h
invoke fopen,fname,crb
mov [hfile],eax
xor ecx,ecx
invoke fgetc,[hfile]
inc ecx
cmp eax,0c3h
je found
jmp lop
invoke printf,pcd,ecx,eax
invoke fclose,[hfile]
invoke system,ppause
invoke ExitProcess,0
pcd db '%x %x',0
hfile dd 0
fname db 'test.exe',0
crb db 'rb',0
ppause db 'pause>nul',0
data import
library crt,'msvcrt.dll',\
import crt,printf,'printf',\
import kernel32,ExitProcess,'ExitProcess'
end data

to build:

@echo off
call povars32
cc /Ze /c /Os test.c
polink test.obj msvcrt.lib kernel32.lib /entry:mymain /nodefaultlib /merge:.data=.flat /merge:.text=.flat /merge:.rdata=.flat /section:.flat,erw

fasm test2.asm

And also outputed binary are a little different:

MZ€    ÿÿ @ @ € º ´ Í!¸LÍ!This program cannot be run in DOS mode.
$ PE L j•%C à  @  @    
 ±x      } Í .flat J    ` à ëÃhp@ hf@ ÿí@ £b@ 1Éÿ5b@ ÿõ@ A=à tëêPQh\@ ÿé@ ÿ5b@ ÿñ@ hs@ ÿù@ j ÿ4@ %x %x test2.exe rb pause>nul Ñ ¹ é , Ä 4 msvcrt.dll kernel32.dll 
   # printf fopen fclose fgetc system < < ExitProcess

Pelles C:

MZ   ÿÿ ¸ @ € º ´ Í!¸LÍ!This program cannot be run in DOS mode.

$ PE L >“%C à  2    @            ¬ <  .flat ~    à U‰åƒì ëÃÆEÿ ƒeø h @ h£@ èR YY‰Eô€}ÿÃtÿuôèE YˆEÿÿEøëé¶EÿPÿuøhš@ è0 ƒÄ ÿuôè+ Yh@ è& Yj ÿ @ ‰ì]ÃÌÿ%@ ÿ% @ ÿ%@ ÿ%@ ÿ%@ pause>nul %x %x rb test.exe è V   p  ( 0 8 B L b ( 0 8 B L b Wfopen Pfgetc žprintf Lfclose Ísystem MSVCRT.dll
ExitProcess KERNEL32.dll

One question: Is it possible to make my variable be compiled at the place I want like I do in FASM with db? Is it only FASM can do it? Cause I think other assembler that use linkers will be like C compiled codes. So FASM is more powerful, cause it do what i tell...
2º question: is it possible to write self-modifying-code in C (maybe with inline asm?)?
Both work fine as expected. They output the size from first byte of the EXE until it finds 0C3h (ret) and outputs it correcty. But why the first value are diferente? is the size of the PE header entry point different? How to get the size of the PE header?

I'm testing this to learn more about PE files.

Post 12 Sep 2005, 14:45
View user's profile Send private message Reply with quote

Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 13 Sep 2005, 15:02
Code getting size of PE header:
        mov     eax, [hinstance]
        mov     ecx, [eax+IMAGE_DOS_HEADER.e_lfanew]
        movzx   eax, [eax+ecx+IMAGE_NT_HEADERS.FileHeader.SizeOfOptionalHeader]
        lea     eax, [eax+ecx+sizeof.IMAGE_FILE_HEADER+4]
Post 13 Sep 2005, 15:02
View user's profile Send private message Visit poster's website Reply with quote

Joined: 17 Sep 2005
Posts: 16
dxl 17 Sep 2005, 08:03
you can put your variable in the msdos stub.
if your program has only one section and the headers are 512 bytes long,
you have something lilke 160 bytes left to add you variable (reading only)
pelles-c allow user defined msdos stub
Post 17 Sep 2005, 08:03
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.