I am working on a shell that would replace COMMAND.COM and I wonder: is
there any way I can figure out where my shell is, once it is executed
by the MS-DOS kernel?
By default MS-DOS launches whatever it finds at [BOOTDRV]:\COMMAND.COM.
This situation is easy, but there is also the possibility that the shell
was configured through a "SHELL" or "SHELLHIGH" CONFIG.SYS directive: SHELL=X:\EXOTIC\PATH\CUSTOM.COM
I am unable to find a way to discover the above path. Any ideas if this
is feasible at all? I went through RBIL but with no luck so far.
The environment contains the full path/name of the executed program,
but this does not apply to process 0, as the MS-DOS kernel does not
allocate any environment for it (env segment in PSP = 0x0000).
Mateusz Viste wrote:
I am working on a shell that would replace COMMAND.COM and I
wonder: is there any way I can figure out where my shell is, once
it is executed by the MS-DOS kernel?
By default MS-DOS launches whatever it finds at
[BOOTDRV]:\COMMAND.COM. This situation is easy, but there is also
the possibility that the shell was configured through a "SHELL" or "SHELLHIGH" CONFIG.SYS directive: SHELL=X:\EXOTIC\PATH\CUSTOM.COM
I am unable to find a way to discover the above path. Any ideas if
this is feasible at all? I went through RBIL but with no luck so
far.
The environment contains the full path/name of the executed program,
but this does not apply to process 0, as the MS-DOS kernel does not allocate any environment for it (env segment in PSP = 0x0000).
Just throwing out the obvious here... have you considered just
looking through config.sys for the shell?
2021-11-16 at 16:54 -0000, Auric__ wrote:
Mateusz Viste wrote:
I am working on a shell that would replace COMMAND.COM and I
wonder: is there any way I can figure out where my shell is, once
it is executed by the MS-DOS kernel?
By default MS-DOS launches whatever it finds at
[BOOTDRV]:\COMMAND.COM. This situation is easy, but there is also
the possibility that the shell was configured through a "SHELL" or
"SHELLHIGH" CONFIG.SYS directive: SHELL=X:\EXOTIC\PATH\CUSTOM.COM
I am unable to find a way to discover the above path. Any ideas if
this is feasible at all? I went through RBIL but with no luck so
far.
The environment contains the full path/name of the executed program,
but this does not apply to process 0, as the MS-DOS kernel does not
allocate any environment for it (env segment in PSP = 0x0000).
Just throwing out the obvious here... have you considered just
looking through config.sys for the shell?
Yes, of course, but this seemingly obvious solution is extremely complex
and unreliable.
Such parser would have not only to look for SHELL or SHELLHIGH
directives in CONFIG.SYS, but also understand the logic behind
conditional instructions (config menus), with possible dialect
variations between DOS versions. There are also DOSes that use a file
named differently than "CONFIG.SYS". And then, there's also the
possibility that the user simply skipped the SHELL directive (F5/F8) or
that the shell has been entered by hand at boot time (some DOSes ask
for the command interpreter path if the default file cannot be found).
The MS-DOS 2.0 source code is on Github, where you might look into
the file SYSINIT.ASM, available here:
https://github.com/microsoft/MS-DOS/blob/master/v2.0/source/SYSINIT.ASM
HACK: when 4DOS.COM is the shell and it doesn't have an environment
from which to obtain its original program name, it grovels through
all of memory to find the filename that was used to exec it; it
wants to find the SHELL= line in the in-memory copy of CONFIG.SYS,
and it knows that sysinit converts the SHELL= keyword to an 'S', so
it expects to find an 'S' immediately before the filename, but since
we are now storing line # info in the config.sys memory image, 4DOS
fails to find the 'S' in the right spot.
So, on the final pass of CONFIG.SYS, copy the command code (eg, 'S')
over the line number info, since we no longer need that info anyway.
This relies on the fact that getchr leaves ES:SI pointing to the
last byte retrieved.
As for other flavors of DOS, most of them are open source, so I think
it would be worth it to download some source code and search for
"shell".
Hello,
I am working on a shell that would replace COMMAND.COM and I wonder: is
there any way I can figure out where my shell is, once it is executed
by the MS-DOS kernel?
By default MS-DOS launches whatever it finds at [BOOTDRV]:\COMMAND.COM.
This situation is easy, but there is also the possibility that the shell
was configured through a "SHELL" or "SHELLHIGH" CONFIG.SYS directive: SHELL=X:\EXOTIC\PATH\CUSTOM.COM
I am unable to find a way to discover the above path. Any ideas if this
is feasible at all? I went through RBIL but with no luck so far.
The environment contains the full path/name of the executed program,
but this does not apply to process 0, as the MS-DOS kernel does not
allocate any environment for it (env segment in PSP = 0x0000).
Mateusz
On Tue, 16 Nov 2021 10:44:16 +0100, Mateusz Viste wrote:
Hello,
I am working on a shell that would replace COMMAND.COM and I
wonder: is there any way I can figure out where my shell is, once
it is executed by the MS-DOS kernel?
By default MS-DOS launches whatever it finds at
[BOOTDRV]:\COMMAND.COM. This situation is easy, but there is also
the possibility that the shell was configured through a "SHELL" or "SHELLHIGH" CONFIG.SYS directive: SHELL=X:\EXOTIC\PATH\CUSTOM.COM
I am unable to find a way to discover the above path. Any ideas if
this is feasible at all? I went through RBIL but with no luck so
far.
The environment contains the full path/name of the executed program,
but this does not apply to process 0, as the MS-DOS kernel does not allocate any environment for it (env segment in PSP = 0x0000).
Mateusz
You may want to walk the MCB chain to find the master environment
block.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 415 |
Nodes: | 16 (2 / 14) |
Uptime: | 114:59:55 |
Calls: | 8,695 |
Calls today: | 4 |
Files: | 13,259 |
Messages: | 5,949,062 |