[CKPT SPAM] RE: Retriving Command-Line

Gets my vote.

I sometimes ponder submitting questions to this forum, but they nearly
always fall into the “insane requirements” bucket, and rather than have to
justify my world and get the blood presure of the “more mature” forum
members rising, I tend to hit delete and blunder on in silence.

Here’s to all of you with “insane” requirements.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: 28 July 2009 14:05
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Retriving Command-Line

I’m considering making that the NTDEV motto.

Peter
OSR


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4285 (20090728) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4285 (20090728) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Crispin Wright wrote:

http://msdn.microsoft.com/en-us/library/aa813706(VS.85).aspx

Using the PEB as a reference for anything in production code can be flaky
(unless your os version is guaranteed…, or you implement every single
variant) because of its changes between OS’s, although having said that, I
did really like the quote that I think it was Pavel made the other day, “One
just can’t come with a sane and clean solution when requirements are insane”

crispin.

Thanks. But getting a command line of another process IMHO does
not qualify as insane requirement. Process explorer can do this.
Task manager in Vista+ does this too.

-pa

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.com
Sent: 28 July 2009 11:44
To: Windows System Software Devs Interest List
Subject: [ntdev] Retriving Command-Line

Hi All,

I want to get arguments that are passed to another process. For that I am
using
NtQueryInformationProcess API and PEB structure. The code works well for all
32 bit OS (2K Onwords), But it does not work for 64 bit OS. I think this
problem
is due to change of PEB structure.

Currently I am using structure as…
typedef struct _MYPEB
{
//
// Undoc
//
UCHAR
Reserved1[4];
PVOID Reserved2;
PVOID
ImageBaseAddress;
PPEB_LDR_DATA LoaderData;
PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
BYTE
Reserved3[312];
/*PPS_POST_PROCESS_INIT_ROUTINE*/
void *
PostProcessInitRoutine;
BYTE
Reserved4[132];
ULONG SessionId;

} MYPEB, *PMYPEB;

What changes I have to do sothat it will work on 64 bit OS?

Thanks & Regards,
Amit.

> Yes I want it in ser mode.

Can PSAPI.DLL help you?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

> Can PSAPI.DLL help you?
It does not [to my big surprise, I would add.]

Here is what works, OP, here is the link I had in mind:

http://msdn.microsoft.com/en-us/magazine/bb985842.aspx

The code is not very good, but quite fixable.

Search for GetRemoteCmdLine in the code.

The author’s idea is to inject his DLL a la Jeffrey
Richter and grab the [remote] cmd line from
within the process itself, which is trivial.

Again, Richter’s code from the book is bad, and
that Nasarre guy also has a couple of bugs (leaks,
actually - I notified him, but it was too late), so
pay attention.

Then goes the usual round-about with inverted call,
I assume this part does not require comments.

----- Original Message -----
From: “Maxim S. Shatskih”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Tuesday, July 28, 2009 2:22 PM
Subject: Re:[ntdev] Retriving Command-Line

> Yes I want it in ser mode.

Can PSAPI.DLL help you?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I did not read this article, but based on your suggestion this can be done
through another way as well.

the OP can check for Detours API from MS Research, it has some great
features exactly for this kind of scenario. It allows you to write a DLL
that can “hook” (don’t know if that’s the right word) system or other
function and run your code through the target app. This way you can easily
get the command line from the thirdparty exe. Just a possible way to try :slight_smile:

-rtshiva

On Wed, Jul 29, 2009 at 1:15 AM, Alex Shvedov wrote:

> Can PSAPI.DLL help you?
>>
> It does not [to my big surprise, I would add.]
>
> Here is what works, OP, here is the link I had in mind:
>
> http://msdn.microsoft.com/en-us/magazine/bb985842.aspx
>
> The code is not very good, but quite fixable.
>
> Search for GetRemoteCmdLine in the code.
>
> The author’s idea is to inject his DLL a la Jeffrey
> Richter and grab the [remote] cmd line from
> within the process itself, which is trivial.
>
> Again, Richter’s code from the book is bad, and
> that Nasarre guy also has a couple of bugs (leaks,
> actually - I notified him, but it was too late), so
> pay attention.
>
> Then goes the usual round-about with inverted call,
> I assume this part does not require comments.
>
>
>
>
>
> ----- Original Message ----- From: “Maxim S. Shatskih” <
> xxxxx@storagecraft.com>
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Tuesday, July 28, 2009 2:22 PM
> Subject: Re:[ntdev] Retriving Command-Line
>
>
>
> Yes I want it in ser mode.
>>
>
> Can PSAPI.DLL help you?
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Detours is 32-bit only.

mm

k just checked the free 32bit is for non production and non commercial use
only .

but the 64 bit version is available with professional edition :slight_smile:

-rtshiva

On Wed, Jul 29, 2009 at 10:28 AM, wrote:

> Detours is 32-bit only.
>
>
> mm
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

just checked the licensing fee for the professional edition :slight_smile: dont think
he would want it for the current scenario


Licensing Terms
Standard Terms & Conditions
Fee
Distribution License
Non-exclusive
Redistribution in binary form tied to one software product only
Right to create derivative works of the API, user guide documentation
One time licensing fee: $10,000
License is for this package release only and not for updated or future
releases

On Wed, Jul 29, 2009 at 10:34 AM, sivakumar thulasimani
wrote:

> k just checked the free 32bit is for non production and non commercial use
> only .
>
> but the 64 bit version is available with professional edition :slight_smile:
>
> -rtshiva
>
>
>
> On Wed, Jul 29, 2009 at 10:28 AM, wrote:
>
>> Detours is 32-bit only.
>>
>>
>> mm
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
>

Yeah fairly tame example I know, hardly rocket science…I’ll pick a better
one next time :slight_smile: (does this merit an “insane requirement” of the week poll
perhaps?) I was thinking (probably more to myself than anyone else) about
the concept and the quote in general really.

crispin.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Pavel A.
Sent: 28 July 2009 17:53
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Retriving Command-Line

Crispin Wright wrote:

http://msdn.microsoft.com/en-us/library/aa813706(VS.85).aspx

Using the PEB as a reference for anything in production code can be flaky
(unless your os version is guaranteed…, or you implement every single
variant) because of its changes between OS’s, although having said that, I
did really like the quote that I think it was Pavel made the other day,
“One
just can’t come with a sane and clean solution when requirements are
insane”

crispin.

Thanks. But getting a command line of another process IMHO does
not qualify as insane requirement. Process explorer can do this.
Task manager in Vista+ does this too.

-pa

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.com
Sent: 28 July 2009 11:44
To: Windows System Software Devs Interest List
Subject: [ntdev] Retriving Command-Line

Hi All,

I want to get arguments that are passed to another process. For that I am
using
NtQueryInformationProcess API and PEB structure. The code works well for
all
32 bit OS (2K Onwords), But it does not work for 64 bit OS. I think this
problem
is due to change of PEB structure.

Currently I am using structure as…
typedef struct _MYPEB
{
//
// Undoc
//
UCHAR
Reserved1[4];
PVOID Reserved2;
PVOID
ImageBaseAddress;
PPEB_LDR_DATA LoaderData;
PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
BYTE
Reserved3[312];
/*PPS_POST_PROCESS_INIT_ROUTINE*/
void *
PostProcessInitRoutine;
BYTE
Reserved4[132];
ULONG SessionId;

} MYPEB, *PMYPEB;

What changes I have to do sothat it will work on 64 bit OS?

Thanks & Regards,
Amit.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4286 (20090728) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4286 (20090728) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

> this can be done through another way as well.
Well, now you know why I did not mention detours
as a solution ($10K for 64 bit, research etc.)

Note however, that detouring as described in detours
1.5 (previous) and/or 2.0 (current, IIRC) - btw, 1.5 and 2.0
are very different - is not the only way to hook, there are
a couple of open source projects that do the job as well,
so a free detouring solution does exist.

I pointed to Richter’s injection scheme b/c it is a ready-made
piece of code that starts working immediately. As I noted,
it does need polishing, but you know whether it is a fit or not in
one day.

[Why on earth it cannot be done through API, without
standing on your head, beats me. When I needed that
back in 2000, I naively thought that hey, I will OpenProcess
and then some API will give me everything I need about
a process of interest. Turns out the answer is no.
Go ahead and dance this strange dance with PEB or
hooking or code injection. Why??? ]

----- Original Message -----
From: sivakumar thulasimani
To: Windows System Software Devs Interest List
Sent: Wednesday, July 29, 2009 12:48 AM
Subject: Re: Re:[ntdev] Retriving Command-Line

I did not read this article, but based on your suggestion this can be done through another way as well.

the OP can check for Detours API from MS Research, it has some great features exactly for this kind of scenario. It allows you to write a DLL that can “hook” (don’t know if that’s the right word) system or other function and run your code through the target app. This way you can easily get the command line from the thirdparty exe. Just a possible way to try :slight_smile:

-rtshiva

On Wed, Jul 29, 2009 at 1:15 AM, Alex Shvedov wrote:

Can PSAPI.DLL help you?

It does not [to my big surprise, I would add.]

Here is what works, OP, here is the link I had in mind:

http://msdn.microsoft.com/en-us/magazine/bb985842.aspx

The code is not very good, but quite fixable.

Search for GetRemoteCmdLine in the code.

The author’s idea is to inject his DLL a la Jeffrey
Richter and grab the [remote] cmd line from
within the process itself, which is trivial.

Again, Richter’s code from the book is bad, and
that Nasarre guy also has a couple of bugs (leaks,
actually - I notified him, but it was too late), so
pay attention.

Then goes the usual round-about with inverted call,
I assume this part does not require comments.

----- Original Message ----- From: “Maxim S. Shatskih”
Newsgroups: ntdev

To: “Windows System Software Devs Interest List”

Sent: Tuesday, July 28, 2009 2:22 PM
Subject: Re:[ntdev] Retriving Command-Line

Yes I want it in ser mode.

Can PSAPI.DLL help you?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hi All,

I have done it. There is change in RTL_USER_PROCESS_PARAMETERS strecture.

Thanks & Regards,
Amit.