Page 1 of 1
masm 32bit and binary files
Posted: Fri Nov 10, 2006 11:48 pm
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.
Posted: Sat Nov 11, 2006 1:47 am
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.
Posted: Sat Nov 11, 2006 4:08 am
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
Posted: Sat Nov 11, 2006 4:35 am
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.
Posted: Sat Nov 11, 2006 10:07 am
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
Posted: Sat Nov 11, 2006 10:43 am
by xyjamepa
would you please give me a simple example how i do that.
after getting the object file from masm.
Thanx.
Posted: Sat Nov 11, 2006 12:55 pm
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
Re: masm 32bit and binary files
Posted: Sun Nov 12, 2006 3:46 am
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
Posted: Mon Nov 13, 2006 1:46 am
by xyjamepa
Thank you guys that was helpful.