ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu n' Flavors, ReactOS, MINIX3, FreeDOS, Arch
Posts: 339
Rep:
C++ make a .com
How would I make a .com in c++, not the domain the old dos executable, I have open watcom and can make the compiler wise but what code should I use? Normal code brings up a ton of errors...
Click here to see the post LQ members have rated as the most helpful post in this thread.
You have a C++ compiler that generates 16 bit x86 machine code? (Sorry I don't know what watcom is).
If you have compiled into 16 bit .obj files, it shouldn't be too hard to link the result into a .com as long as the whole program is small enough (including all the 16 bit C++ startup code and C++ library code).
How would I make a .com in c++, not the domain the old dos executable, I have open watcom and can make the compiler wise but what code should I use? Normal code brings up a ton of errors...
The COM file format used in historical DOS versions is taylored to applications that run on as little as 64kB of memory. Actually, the file format was developed for CP/M and slightly adapted for the first DOS incarnation. A DOS application using the old COM file format is restricted to 64kB (actually it's 64kB minus 256 bytes, since the 64k segment begins with the PSP and code starts at 0100h) for code, data and stack together.
In the end, I suppose you don't want to build an old style COM executable. Instead, you want to compile and run your program. So let's face the "ton of errors" you get and think about their reason - and how to get rid of them.
If you still insist on building a 64k DOS executable: Choose the "tiny" memory model, compile your program to a standard DOS EXE file, and convert it to the COM format using the DOS tool exe2bin. Though I still wonder why someone would want to build a DOS application nowadays, instead of a Windows console application ...
[X] Doc CPU
Last edited by Doc CPU; 12-14-2011 at 03:39 PM.
Reason: Digits were swapped: It's 256 bytes, not 265
Though I still wonder why someone would want to build a DOS application nowadays, instead of a Windows console application ...
There's a trick that allows packing executables into something as small as 4kB. The trick involves *.COM file format - apparently it is possible to compress *.exe into simple compressed format, attach it to *.COM unpacker (*.com has no overhead, unlike PE *.exe that has minimal size of roughly 8kB) - and make unpacker decompress and launch the program. Apparently it is possible because real-mode *.com executable can launch protected mode windows executable. It's been a while since I heard about this trick and I no longer can find relevant articles (there was an entire tutorial with asm listings), but if you search for "4kb demo" or "4kb demoscene", I'm sure you'll find something on the subject. Also, I don't think they will work on windows 7 - only on XP.
It's been a while since I heard about this trick and I no longer can find relevant articles (there was an entire tutorial with asm listings), but if you search for "4kb demo" or "4kb demoscene", I'm sure you'll find something on the subject. Also, I don't think they will work on windows 7 - only on XP.
So far as I recall, I haven't seen that used since Windows 95. Does it really work on XP (which was derived from Windows NT, not from 95)?
It shouldn't be possible on any 64 bit Windows (even for 32 bit applications) even 64bit XP. Since I don't know why it would work even in 32bit XP, I'm not qualified to guess why it might or might not work in 32 bit Windows 7.
There's a trick that allows packing executables into something as small as 4kB. The trick involves *.COM file format - apparently it is possible to compress *.exe into simple compressed format, attach it to *.COM unpacker (*.com has no overhead, unlike PE *.exe that has minimal size of roughly 8kB) - and make unpacker decompress and launch the program. Apparently it is possible because real-mode *.com executable can launch protected mode windows executable.
yea, sure you can append a compressed PE file to a COM decompressor stub, and I guess that might even work with recent Windows versions. But what's the point? Disk space is cheap, at least when we're talking about saving a few kB. It hardly matters whether I have a 100kB EXE file on my disk, or a 60kB COM file including the compressed payload.
Besides, what's the significance of those 4kB you mention? That's probably the size of the decompressor stub, is it?
Quote:
Originally Posted by SigTerm
Also, I don't think they will work on windows 7 - only on XP.
I'm sure it'll also work with Seven - because injecting a new process into memory is a task that every debugger does.
So far as I recall, I haven't seen that used since Windows 95. Does it really work on XP (which was derived from Windows NT, not from 95)?
Now that you say it, I'm not entirely certain. I'm not entirely sure whether I saw it last time on windows 98 or windows xp, but it definitely wasn't win95. I also remember playing around with the technique, but again - I don't remember where any of those programs are now and can't find any of them to check.
Quote:
Originally Posted by Doc CPU
But what's the point?
The only point I know of is demoscene contests. They have size limits - 4k, 64k, etc. A programming exercise. See .kkrieger(youtube video) for example (100kb 3d first person shooter prototype).
Quote:
Originally Posted by Doc CPU
I'm sure it'll also work with Seven - because injecting a new process into memory is a task that every debugger does.
*IF* I remember correctly, it didn't work this way - *.com file have been unpacking PE onto disk and starting new process using dos interrupts. The problem is that I don't remember how exactly it was done - I think it called some kind of equivalent of exec() or system() using an interrupt. So if you'll tweak ntvdm equivalent on win7, it'll stop working - assuming it actually worked the way I think it did.
Anyway, I can't find any program that uses this technique on WinXP in my backups and can't verify if I'm correct (that it'll work on winxp). It is possible that I was mistaken somewhere.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.