public inbox for linux-msdos@vger.kernel.org
 help / color / mirror / Atom feed
* DOS program recording it's parameters and environment?
@ 2012-01-18  5:20 Frantisek Hanzlik
       [not found] ` <4F16E21B.9030804@gmail.com>
  2012-01-27 12:01 ` Paul Crawford
  0 siblings, 2 replies; 11+ messages in thread
From: Frantisek Hanzlik @ 2012-01-18  5:20 UTC (permalink / raw)
  To: DOSEMU/FreeDOS

Excuse me for slightly OT question. Know anyone DOS program, which is
able record infos with what parameters was started and eventually
other informations about calling environment (e.g. environment
variables, available memory etc.)?

I've DOS program, which is optimized for run under windows, and this
program is launching other its supplement programs, which are written
for windows (e.g. search for updates and other access to internet,
print to windows printers etc.). I'm running this program successfuly
under DOSEMU and now I want run some its extension. Thus my questions:

1) Has someone any experience with this matters?

2) Program authors give me no iformations (except that they not support
run program under Linux ;). My idea is uncover how are these external
programs called and then run my own Linux equivalents. Then in first
step i want small program which i can substitute instead of this
windows one and see how is called from DOS program.
I was searching on internet, but found none - maybe i do not know
construct right question.

Thanks in advance, Franta Hanzlik

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
       [not found] ` <4F16E21B.9030804@gmail.com>
@ 2012-01-18 17:46   ` Frantisek Hanzlik
  2012-01-18 17:55     ` Frank Cox
  0 siblings, 1 reply; 11+ messages in thread
From: Frantisek Hanzlik @ 2012-01-18 17:46 UTC (permalink / raw)
  To: Robert Supansic; +Cc: DOSEMU/FreeDOS

Robert Supansic napsal(a):
> Frantisek Hanzlik wrote:
>> Excuse me for slightly OT question. Know anyone DOS program, which is
>> able record infos with what parameters was started and eventually
>> other informations about calling environment (e.g. environment
>> variables, available memory etc.)?
>>   
> 
> I do not know if I am understanding your question correctly, but there are two DOS commands that may help:
> Both are run from the command line.
> 
> MEM /C /P will list available memory by type.
> SET will list environmental variables.

Sorry for my bad english. I want program, which I arrange instead of
windows program - which is started by my DOS program but I not know
with what parameters.

For example: closed-source DOS program which i'm using start windows
program WINPROG.EXE with parameters "C:\path\file /A delay=5".
I not know these parameters, but when I take "spying" program, rename
it to "WINPROG.EXE" and replace original program with him, then DOS
program will run my "spying" program - and it can somewhere (e.g. to
file) write info how was started (me interest mainly its parameters,
but other informations, as available memory when was started,
inherited environment variables, etc. would be welcomed).

Such "spying" program should be IMO very simple (sort of any copybook
example) and perhaps already had someone this needs and realize it -
but I cannot find it ;)

Or there is second way - write this itself. But I not know intel
assembler, and use DJGPP C seems for me as "cannon onto sparrow".
Or is there other publicly available programming language for DOS,
which wil produce small code?

Thanks, Franta Hanzlik

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
  2012-01-18 17:46   ` Frantisek Hanzlik
@ 2012-01-18 17:55     ` Frank Cox
  2012-01-18 18:36       ` Frantisek Hanzlik
  0 siblings, 1 reply; 11+ messages in thread
From: Frank Cox @ 2012-01-18 17:55 UTC (permalink / raw)
  To: Frantisek Hanzlik; +Cc: linux-msdos

On Wed, 18 Jan 2012 18:46:25 +0100
Frantisek Hanzlik wrote:

> For example: closed-source DOS program which i'm using start windows
> program WINPROG.EXE with parameters "C:\path\file /A delay=5".

Have you considered using "strings progname.exe" and see what you can find that
way?  If the program isn't encrypted or compressed (with lzexe or whatever) you
might find interesting things.  And if it is compressed, you may discover how
and be able to uncompress it.

-- 
MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com
www.creekfm.com - FIFTY THOUSAND WATTS of POW WOW POWER!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
  2012-01-18 17:55     ` Frank Cox
@ 2012-01-18 18:36       ` Frantisek Hanzlik
  2012-01-18 19:17         ` Scott
  0 siblings, 1 reply; 11+ messages in thread
From: Frantisek Hanzlik @ 2012-01-18 18:36 UTC (permalink / raw)
  To: Frank Cox; +Cc: linux-msdos

Frank Cox wrote:
> On Wed, 18 Jan 2012 18:46:25 +0100
> Frantisek Hanzlik wrote:
> 
>> For example: closed-source DOS program which i'm using start windows
>> program WINPROG.EXE with parameters "C:\path\file /A delay=5".
> 
> Have you considered using "strings progname.exe" and see what you can find that
> way?  If the program isn't encrypted or compressed (with lzexe or whatever) you
> might find interesting things.  And if it is compressed, you may discover how
> and be able to uncompress it.

There is violent that DOS program assemble parameters ("command line") for
program which will execute dynamically, "strings" in this case will not be
very usefull.

Help will be, when DOSEMU debug made this, but such details IMO there are not.

Franta

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
  2012-01-18 18:36       ` Frantisek Hanzlik
@ 2012-01-18 19:17         ` Scott
  0 siblings, 0 replies; 11+ messages in thread
From: Scott @ 2012-01-18 19:17 UTC (permalink / raw)
  To: Frantisek Hanzlik; +Cc: linux-msdos

On Wed, Jan 18, 2012 at 07:36:26PM +0100, Frantisek Hanzlik wrote:
> Frank Cox wrote:
> > On Wed, 18 Jan 2012 18:46:25 +0100
> > Frantisek Hanzlik wrote:
> > 
> >> For example: closed-source DOS program which i'm using start windows
> >> program WINPROG.EXE with parameters "C:\path\file /A delay=5".
> > 
> > Have you considered using "strings progname.exe" and see what you can find that
> > way?  

> 
> There is violent that DOS program assemble parameters ("command line") for
> program which will execute dynamically, "strings" in this case will not be
> very usefull.

Franta,

I think that Frank is suggesting to use the "strings" not on
WINPROG.EXE but on the closed-source DOS program that calls
it. Wouldn't "strings" then show the command-lines which it is using?
Maybe I'm way off base here....

Scott.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
  2012-01-18  5:20 DOS program recording it's parameters and environment? Frantisek Hanzlik
       [not found] ` <4F16E21B.9030804@gmail.com>
@ 2012-01-27 12:01 ` Paul Crawford
  2012-02-16 18:54   ` Frantisek Hanzlik
  1 sibling, 1 reply; 11+ messages in thread
From: Paul Crawford @ 2012-01-27 12:01 UTC (permalink / raw)
  To: Frantisek Hanzlik; +Cc: DOSEMU/FreeDOS

[-- Attachment #1: Type: text/plain, Size: 1118 bytes --]

Dear Frantisek,
> Excuse me for slightly OT question. Know anyone DOS program, which is
> able record infos with what parameters was started and eventually
> other informations about calling environment (e.g. environment
> variables, available memory etc.)?

Attacked is a gzip'd tar file with a simple program to do this, but 
re-named .dat instead of .tgz as we use Google mail and it is too stupid 
to allow compressed executables to be emailed.

Save to a Linux box and then re-name, then the usual arcive manager or 
tar can extract the files.

It creates a file dosenv.txt in the working directory and prints out the 
calling arguments and the environment to that file. If you have a C 
compiler (I used Microsoft's C6.0 DOS compiler from around 1988) you 
could modify this program to do other things (e.g. date/time based file 
names if they fit the 8.3 limit of DOS, etc)

Regards,
Paul
-- 
Dr. Paul S. Crawford
Satellite Station
Dundee University
Small's Wynd, Dundee,
DD1 4HN, U.K.
Tel: +44 (0)1382 38 4687
Email: psc@sat.dundee.ac.uk
The University of Dundee is a Scottish Registered Charity, No. SC015096

[-- Attachment #2: dosenv.dat --]
[-- Type: application/x-ns-proxy-autoconfig, Size: 6377 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
  2012-01-27 12:01 ` Paul Crawford
@ 2012-02-16 18:54   ` Frantisek Hanzlik
  2012-02-16 21:01     ` Paul Crawford
  0 siblings, 1 reply; 11+ messages in thread
From: Frantisek Hanzlik @ 2012-02-16 18:54 UTC (permalink / raw)
  To: Paul Crawford; +Cc: DOSEMU/FreeDOS, Freedos user list

Paul Crawford napsal(a):
> Dear Frantisek,
>> Excuse me for slightly OT question. Know anyone DOS program, which is
>> able record infos with what parameters was started and eventually
>> other informations about calling environment (e.g. environment
>> variables, available memory etc.)?
> 
> Attacked is a gzip'd tar file with a simple program to do this, but
> re-named .dat instead of .tgz as we use Google mail and it is too stupid
> to allow compressed executables to be emailed.
> 
> Save to a Linux box and then re-name, then the usual arcive manager or
> tar can extract the files.
> 
> It creates a file dosenv.txt in the working directory and prints out the
> calling arguments and the environment to that file. If you have a C
> compiler (I used Microsoft's C6.0 DOS compiler from around 1988) you
> could modify this program to do other things (e.g. date/time based file
> names if they fit the 8.3 limit of DOS, etc)
> 
> Regards,
> Paul

Hello Paul,

many thanks for Your help. I have not bigger piece of time for playing
with until yesterday. And I must say You program work well, is quite
tiny and when I have seen how it is simple, I was ashamed for being so
powerless for writing similar code.

I was trying slightly modify You code (nothing much, only write result
to not fixed name file, but to filename basename(argv[0]) and open it
for append and write there timestamp when program run). Because I have
not had any C compiler before, I was downloading and using OpenWatcom C
compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock
to problem - it seems as this compiler not support construction:

int main(int argc, char *argv[], char *envp[])

in the concrete, pointer to environment vector perhaps isn't possible or
valid. Program compiles and links fine, run without problems, printed
args are OK, but instead of environment variables it output only several
weird characters. Thus, when I can still ask, know You or someone in
DOSEMU or FreeDOS forum:

- when is possible walk through environment values in Watcom C?
I think it may be possible with some undocumented functions, with some
included assembler code etc. Or there may be problem e.g. in incorrect
variable alignment in memory...? ;)

- or when there is other free DOS C compiler which would be possible use?

Thanks in advance, Franta Hanzlik

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
  2012-02-16 18:54   ` Frantisek Hanzlik
@ 2012-02-16 21:01     ` Paul Crawford
  2012-02-16 21:34       ` Frantisek Hanzlik
  2012-02-17  1:57       ` Samuel Bronson
  0 siblings, 2 replies; 11+ messages in thread
From: Paul Crawford @ 2012-02-16 21:01 UTC (permalink / raw)
  To: Frantisek Hanzlik; +Cc: DOSEMU/FreeDOS, Freedos user list

[-- Attachment #1: Type: text/plain, Size: 583 bytes --]

Dear Frantisek,
> compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock
> to problem - it seems as this compiler not support construction:
>
> int main(int argc, char *argv[], char *envp[])

I think this 3rd argument may be a MS-specific extension, as most C 
programs just have argc & argv in the call to main();

If you change to use the 'environ' variable, that should be pre-defined 
(probably in stdlib.h) and should do the same job. Attached is an 
example that seems to compile & work under C6 DOS compiler and with gcc 
on my Ubuntu 10.04 box.

Regards,
Paul

[-- Attachment #2: dosenv.c --]
[-- Type: text/x-csrc, Size: 470 bytes --]



#include <stdio.h>
#include <stdlib.h>

extern char **environ;

int main(int argc, char *argv[])
{
int ii;
FILE *fp;
char **envp = environ;


	fp=fopen("dosenv.txt", "wb");
	if(fp != NULL)
		{
		fprintf(fp, "argc = %d\n", argc);

		for(ii=0; ii<argc; ii++)
			{
			fprintf(fp, "argv[%d] = %s\n", ii, argv[ii]);
			}

		ii=0;
		while(envp != NULL && envp[ii] != NULL)
			{
			fprintf(fp, "envp[%d] = %s\n", ii, envp[ii]);
			ii++;
			}

		fclose(fp);
		}


return 0;
}

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
  2012-02-16 21:01     ` Paul Crawford
@ 2012-02-16 21:34       ` Frantisek Hanzlik
  2012-02-17  1:57       ` Samuel Bronson
  1 sibling, 0 replies; 11+ messages in thread
From: Frantisek Hanzlik @ 2012-02-16 21:34 UTC (permalink / raw)
  To: Paul Crawford; +Cc: DOSEMU/FreeDOS, Freedos user list

Dear Paul,

You are right, it works with Watcom C fine. And now I found in "Watcom C
Library Reference" manual paragraph:

environ
Prototype in <stdlib.h>.
This char ** __near data item is a pointer to an array of character
pointers to the environment strings.

which I not noticed before. Eeh, I still must learn to much!

Many thanks once again,
Franta

Paul Crawford napsal(a):
> Dear Frantisek,
>> compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock
>> to problem - it seems as this compiler not support construction:
>>
>> int main(int argc, char *argv[], char *envp[])
> 
> I think this 3rd argument may be a MS-specific extension, as most C
> programs just have argc & argv in the call to main();
> 
> If you change to use the 'environ' variable, that should be pre-defined
> (probably in stdlib.h) and should do the same job. Attached is an
> example that seems to compile & work under C6 DOS compiler and with gcc
> on my Ubuntu 10.04 box.
> 
> Regards,
> Paul
> 
> 
> dosenv.c
> 
> 
> 
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> extern char **environ;
> 
> int main(int argc, char *argv[])
> {
> int ii;
> FILE *fp;
> char **envp = environ;
> 
> 
> 	fp=fopen("dosenv.txt", "wb");
> 	if(fp != NULL)
> 		{
> 		fprintf(fp, "argc = %d\n", argc);
> 
> 		for(ii=0; ii<argc; ii++)
> 			{
> 			fprintf(fp, "argv[%d] = %s\n", ii, argv[ii]);
> 			}
> 
> 		ii=0;
> 		while(envp != NULL && envp[ii] != NULL)
> 			{
> 			fprintf(fp, "envp[%d] = %s\n", ii, envp[ii]);
> 			ii++;
> 			}
> 
> 		fclose(fp);
> 		}
> 
> 
> return 0;
> }

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
  2012-02-16 21:01     ` Paul Crawford
  2012-02-16 21:34       ` Frantisek Hanzlik
@ 2012-02-17  1:57       ` Samuel Bronson
  2012-02-17 22:29         ` Scott
  1 sibling, 1 reply; 11+ messages in thread
From: Samuel Bronson @ 2012-02-17  1:57 UTC (permalink / raw)
  To: Paul Crawford; +Cc: Frantisek Hanzlik, DOSEMU/FreeDOS, Freedos user list

On Thu, Feb 16, 2012 at 4:01 PM, Paul Crawford <psc@sat.dundee.ac.uk> wrote:
> Dear Frantisek,
>
>> compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock
>> to problem - it seems as this compiler not support construction:
>>
>> int main(int argc, char *argv[], char *envp[])
>
> I think this 3rd argument may be a MS-specific extension, as most C programs
> just have argc & argv in the call to main();

This is not actually MS-specific; I see it in my execve(2) manpage
here on Linux, and
<http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B> says "Unix
(though not POSIX.1) and Microsoft Windows have a third argument
giving the program's environment". (I was actually a little surprised
to see that it wasn't POSIX.)

GNU's libc.info says so, too:

>    In Unix systems you can define `main' a third way, using three
> arguments:
>
>      int main (int ARGC, char *ARGV[], char *ENVP[])
>
>    The first two arguments are just the same.  The third argument ENVP
> gives the program's environment; it is the same as the value of
> `environ'.  See Environment Variables.  POSIX.1 does not allow this
> three-argument form, so to be portable it is best to write `main' to
> take two arguments, and use the value of `environ'.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: DOS program recording it's parameters and environment?
  2012-02-17  1:57       ` Samuel Bronson
@ 2012-02-17 22:29         ` Scott
  0 siblings, 0 replies; 11+ messages in thread
From: Scott @ 2012-02-17 22:29 UTC (permalink / raw)
  To: Samuel Bronson; +Cc: franta, linux-msdos, freedos-user

On Thu, Feb 16, 2012 at 08:57:46PM -0500, Samuel Bronson wrote:
> On Thu, Feb 16, 2012 at 4:01 PM, Paul Crawford <psc@sat.dundee.ac.uk> wrote:
> > Dear Frantisek,
> >
> >> compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock
> >> to problem - it seems as this compiler not support construction:
> >>
> >> int main(int argc, char *argv[], char *envp[])
> >
> > I think this 3rd argument may be a MS-specific extension, as most C programs
> > just have argc & argv in the call to main();
> 
> This is not actually MS-specific; I see it in my execve(2) manpage
> here on Linux, and

Got curious and pulled down my "Let's C" (Mark Williams Company)
manual from 1987.

 envp - Argument passed to main
        char *envp[];

 ... and is by convention the third argument passed to main.

 ... Note that Let's C calls main(argc, argv, NULL); however, envp is
 significant under some other operating systems, including TOS, UNIX
 and COHERENT.

If of any interest.

Scott Swanson

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-02-17 22:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-18  5:20 DOS program recording it's parameters and environment? Frantisek Hanzlik
     [not found] ` <4F16E21B.9030804@gmail.com>
2012-01-18 17:46   ` Frantisek Hanzlik
2012-01-18 17:55     ` Frank Cox
2012-01-18 18:36       ` Frantisek Hanzlik
2012-01-18 19:17         ` Scott
2012-01-27 12:01 ` Paul Crawford
2012-02-16 18:54   ` Frantisek Hanzlik
2012-02-16 21:01     ` Paul Crawford
2012-02-16 21:34       ` Frantisek Hanzlik
2012-02-17  1:57       ` Samuel Bronson
2012-02-17 22:29         ` Scott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox