OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:25 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Can anyone help me hack command.com's reentry point?
PostPosted: Wed Oct 07, 2020 2:53 am 
Offline

Joined: Sat Oct 03, 2020 6:51 am
Posts: 2
OK, so that's the best way I could think of saying it.

I am modifying MS-DOS to better suit my needs. I have a .com file that I wrote that changes the layout a bit, text mode, colors, box cursor. I have this in my autoexec.bat. The problem is when I run a program and quit, it returns back to command.com in the original mode, so I have to run my .com file each time.

So I need to find the part in command.com (I assume it's in there) where the reentry point is so I can inject some code to execute my .com file. Can anyone help me with this?

I would REALLY appreciate it cause I love the way my program makes DOS look and I want to make it seamless so I don't have to keep typing it. Maybe there's a way to do this without hacking the file?


Top
 Profile  
 
 Post subject: Re: Can anyone help me hack command.com's reentry point?
PostPosted: Wed Oct 07, 2020 7:09 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
OgreVorbis wrote:
changes the layout a bit, text mode, colors, box cursor.
Just load the already existing ANSI.SYS, all of these can be set with it.
OgreVorbis wrote:
Maybe there's a way to do this without hacking the file?
You can write your own driver (.SYS) and load it from CONFIG.SYS.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Can anyone help me hack command.com's reentry point?
PostPosted: Wed Oct 07, 2020 12:52 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
There used to be a number of TSR (Terminate and Stay Resident) programs that allowed one to reprogram the fonts (on EGA and VGA cards) and change the keyboard layout to support various national languages. They hooked several ISRs: to intercept keyboard input (IRQ 1 / INT 9) and video mode switches (INT 10H) and to check for presence (INT 2FH) before uninstallation.

You can do something similar as well.


Top
 Profile  
 
 Post subject: Re: Can anyone help me hack command.com's reentry point?
PostPosted: Wed Oct 07, 2020 1:52 pm 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 852
In version 6.22, offset 108dh is where the main loop starts. It ends up back here after executing a program, after pressing control break, or after a critical error.

The transient portion of command.com begins at offset 26e0h in the file, and at offset 100h from the segment base. It is 0af95h bytes long. The main loop starts at 12ch.

Expanding either portion requires changing all of the places where their length appears.


Top
 Profile  
 
 Post subject: Re: Can anyone help me hack command.com's reentry point?
PostPosted: Wed Oct 07, 2020 3:30 pm 
Offline
Member
Member

Joined: Sun Aug 23, 2020 4:35 pm
Posts: 148
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

_________________
My OS: TritiumOS
https://github.com/foliagecanine/tritium-os
void warranty(laptop_t laptop) { if (laptop.broken) return laptop; }
I don't get it: Why's the warranty void?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 38 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group