Gigasoft wrote:
Expanding either portion requires changing all of the places where their length appears.
Do you mean you would have to change the header to accommodate the larger amount of code, or the addresses of everything past the point changed? I don't think COM files have a header.
In theory, wouldn't you be able to do something like this:
Code:
CODE
{main_loop starts here}
CODE
SOMECODE -> replace with jmp MY_CODE. Surround with NOPs if necessary.
GO_BACK:
CODE...
{at the end of the binary}
MY_CODE:
SOMECODE
CUSTOM_CODE
jmp GO_BACK
or even just find any references to address 0x108D and update it with the address of MY_CODE. Then add a jmp to main_loop:
Code:
CODE
call 0x108D -> call MY_CODE
main_loop:
MAINLOOPCODE
CODE...
call main_loop -> call MY_CODE
CODE...
{at the end of the binary}
MY_CODE:
CUSTOM_CODE
jmp main_loop
This second one would probably be harder because of segments though.
I don't know. Just throwing out random ideas.
EDIT: I just hexdumped the FreeDOS command.com and it starts with "MZ." Maybe it is just an EXE in disguise and does actually have a header.
EDIT: ... But the MSDOS 6.22 COMMAND.COM is a .COM. No header