can i create a 32bit com file (no header just code) with
the masm linker? i wrote a prog that just grabs the code
section of an executable but thats like breaking a fly on
the wheel... the linker output doesn't have to be executable
i just need the raw code... that means no alignment, no
mz header, no pe header, no import directory... just plain
Posted on 2002-01-23 04:06:24 by mob
As far as I know .com files are only 16 bits, but I think it was an example of what you want to do...

I don't know if MASM is able to do it (.obj, but it is not what you want, I suppose), but if you want the compiled code, maybe you can dump the .code section "manually" from the compiled file using an external program ?

I remember to have seen some tools that dump sections from an exe and put them into seperate files...
Posted on 2002-01-23 05:00:52 by JCP
yeah there is a load of tools outthere... but i've already
done this myself... now i wanted to know if there is an
easier way... like i said the .com doesn't have to be
executable... isn't there a compiler option that let's me
copy the whole stuff into a file?
Posted on 2002-01-23 05:18:20 by mob
Don't think you can do it directly. Either use nasm, or find a version
of the GNU linker that reads ms-coff input files and produces binary
output (mingw32?)
Posted on 2002-01-23 09:20:39 by f0dder
hm, I thought there was some compiler
option... anyway i just rip the .text sec

thank you
Posted on 2002-01-23 09:31:21 by mob
If you only want executable code, be careful though...

Remember of this old szText macro ? It puts strings in the .text/.code section with a jump before it, that points after the string to avoid it to be executed... (bleh !)
Also, some executables has their datas before the entrypoint (like you declare variables in .code but before the start: label).

You can see this sometimes (heh, I use it sometimes myself) as it avoids the creation of a .data section in the exe (make the exe file size go down a bit... an alignment boundary, typically).

If you dump all the .text section you may have some variables in it that are not executable code... I don't see any easy way to avoid dumping these variables, though...
Posted on 2002-01-24 16:59:24 by JCP
You can create .com files with masm (probably MASM32), but after you link them, you have to run an Exe2Bin utility. Currently there is no such thing as 32 .com files simply because .com files run in v86. But in MS-DOS mode, your .com file is free to switch the cpu to real mode. On Win32, you would have to make a custom loader (maybe take advantage of the *.com, and have windows launch you loader).

If usefull, here is something that assembles under FAsm:
Posted on 2002-01-25 02:35:31 by eet_1024
Don't forget that if you extract code from an exe that you have to fixup the pointers.

FAsm will spit out binaries that are greater that 64k.

Is it possible to execute data that is file mapped or loaded into a heap?
Posted on 2002-01-25 02:48:14 by eet_1024
thank you eet and readiosys for your replys...
i already know about relocation and data storage.
i wrote a little process-patcher that let's me enter
some code which i can insert in other progs later.
my app takes the typed code and compiles it to
an executable... another tool i wrote will then rip
the .text section in a dummy-file (ok, maybe .com
is the wrong word for that...). later i can choose
the target, and this ripped code will be inserted
into a new section... ep will point to the start of
my code... it's still very raw and uncomfortable...
next thing to do is creating some flexible api-system
so that the user can use them without fighting
with kernel to get the module-base... if masm could
rip sections it would be much cleaner but it's not
necessary... i will Look over your example eet...

so thank you again :)

your prog is exactly what i need, if i could do this
with masm i could merge the whole process into
one single command... that would be great...
Posted on 2002-01-25 03:32:30 by mob