change proc_args to use CommandLineToArgvW parser

This commit is contained in:
Doug MacEachern 2004-08-03 03:06:25 +00:00
parent 042c38ae95
commit bb02117ef4
3 changed files with 24 additions and 16 deletions

View File

@ -7,6 +7,7 @@
#include "sigar.h"
#include "sigar_private.h"
#include "sigar_os.h"
#include <shellapi.h>
#define PAGE_START 0x00020000
#define CWD_OFFSET PAGE_START + 0x0290
@ -79,12 +80,16 @@ int sigar_proc_exe_peb_get(sigar_t *sigar, HANDLE proc,
return SIGAR_OK;
}
int sigar_proc_cmdline_get(sigar_t *sigar, HANDLE proc, char *cmdline)
int sigar_proc_args_peb_get(sigar_t *sigar, HANDLE proc,
sigar_proc_args_t *procargs)
{
int status;
LPBYTE scratch;
DWORD base;
WCHAR buf[SIGAR_CMDLINE_MAX];
char arg[SIGAR_CMDLINE_MAX];
LPWSTR *args;
int num, i;
if ((status = sigar_peb_get(sigar, proc, &base)) != SIGAR_OK) {
return status;
@ -99,7 +104,20 @@ int sigar_proc_cmdline_get(sigar_t *sigar, HANDLE proc, char *cmdline)
wcsncpy(buf, (LPWSTR)scratch, SIGAR_CMDLINE_MAX);
buf[SIGAR_CMDLINE_MAX-1] = L'\0';
SIGAR_W2A(buf, cmdline, SIGAR_CMDLINE_MAX);
args = CommandLineToArgvW(buf, &num);
sigar_proc_args_create(procargs);
for (i=0; i<=num; i++) {
if (!iswprint(*args[i])) {
continue; /* seen trailing garbage */
}
SIGAR_PROC_ARGS_GROW(procargs);
SIGAR_W2A(args[i], arg, SIGAR_CMDLINE_MAX);
procargs->data[procargs->number++] = strdup(arg);
}
GlobalFree(args);
return SIGAR_OK;
}

View File

@ -124,7 +124,8 @@ int sigar_wsa_init(sigar_t *sigar);
int sigar_proc_exe_peb_get(sigar_t *sigar, HANDLE proc,
sigar_proc_exe_t *procexe);
int sigar_proc_cmdline_get(sigar_t *sigar, HANDLE proc, char *cmdline);
int sigar_proc_args_peb_get(sigar_t *sigar, HANDLE proc,
sigar_proc_args_t *procargs);
unsigned int sigar_cpu_count(sigar_t *sigar);

View File

@ -820,22 +820,11 @@ static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
return GetLastError();
}
status = sigar_proc_cmdline_get(sigar, proc, cmdline);
status = sigar_proc_args_peb_get(sigar, proc, procargs);
CloseHandle(proc);
if (status != SIGAR_OK) {
return status;
}
sigar_proc_args_create(procargs);
while (*ptr && (arg = getarg(&ptr))) {
SIGAR_PROC_ARGS_GROW(procargs);
procargs->data[procargs->number++] = strdup(arg);
}
return SIGAR_OK;
return status;
}
static int sigar_local_proc_args_get(sigar_t *sigar, sigar_pid_t pid,