masm 32bit and binary files

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

masm 32bit and binary files

Post by xyjamepa »

Hi guys ...
dose any body know how can we creat a binary file like file1.bin
using masm32 and link or any other linker.
Thanx.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

You can tell LD to output binary with --oformat=binary or a linker script, you can tell nasm to output binary with -f binary. Most others probably can too, but if they can't there's a trick. You can use objcopy to convert any type of file to binary.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

MASM != NASM :?

Microsoft Assembler reference: http://msdn2.microsoft.com/en-us/librar ... S.80).aspx (copy+paste, phpbb doesnt like to [url] this)
I couldnt find a binary output format in ml or link though - you should probably use binutils for that, as Candy suggested
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

Combuster wrote:MASM != NASM :?
I am aware that Microsoft's assembler is not equal to the Netwide assembler, but since I don't know of any switch for Microsoft's assembler I thought giving the Netwide assembler syntax might help.
bontanu
Member
Member
Posts: 134
Joined: Thu Aug 18, 2005 11:00 pm
Location: Sol. Earth. Europe. Romania. Bucuresti
Contact:

Post by bontanu »

You can use a special linker, as I use JLOC for Solar OS.
Solar OS is written in TASM and TASM is pretty close to MASM.
JLOC can generate binary files from OBJ's created by TASM/MASM ;)
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

would you please give me a simple example how i do that.
after getting the object file from masm.
Thanx.
bontanu
Member
Member
Posts: 134
Joined: Thu Aug 18, 2005 11:00 pm
Location: Sol. Earth. Europe. Romania. Bucuresti
Contact:

Post by bontanu »

JLOC has a help file... is not simple ... please read it.
You can also find a sample linker control file in SolarOS.

For your conveninece I post a sample here... however it must be adapted to suit your specific needs... this example is from SOL:

Code: Select all

ALL:
	SYSTEM32.obj

SYS32: 0,0B000,0
	*,*,*,code32,system32.obj
*
This statements will link sytem32.obj (compiled with TASM) to run at absolute memory location 0xB000
PyroMathic
Member
Member
Posts: 33
Joined: Wed Apr 26, 2006 11:00 pm

Re: masm 32bit and binary files

Post by PyroMathic »

abuashraf wrote:Hi guys ...
dose any body know how can we creat a binary file like file1.bin
using masm32 and link or any other linker.
Thanx.
You cant, i also had this problem since my os is also completely written in masm32... but you can simply compile the exe-file, then open the exe-file and look up where in the file your code seg is located, and then copy that binairy code to another file, or do whit it what you like to do whit it.

you could use something like this, to find the base of your code:

Code: Select all


mov bx,offset PE_EXE_FILE             ; base in mem of the PE-EXE file
add bx,dword [ds:bx+3ch]

; now at "PE" base
add bx,0F8h                                 ; Go to table for segments, so 
                                                   ;  .DATA/.CODE
looping:
     test dword [ds:bx+36],020000000h ; should be Flag for code segment
     jnz GotIt

     add bx,40
jmp looping


GotIt:
     mov dx,offset PE_EXE_FILE 
     add  dx,dword [bx+20]               ; DX + Base in file, for the code seg.


; now DX points to the base in mem, of your code..
if you only use the .Code seg. this should also work:
offset PE_EXE_FILE + 200h. since that should always be the base of
your code, but depens on the linker.. the above code is cleaner.
(look it up whit a hex edit).


if you also would like to be able to use .Data and .Data? seg's you need to expend the code above a bit, look on the internet for the "PE-header file format".

http://www.madchat.org/vxdevl/papers/wi ... pefile.htm that should cover most of it.

Regards
PyroMathic
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Thank you guys that was helpful. :)
Post Reply