diff options
author | Ron Yorston <rmy@pobox.com> | 2019-01-08 15:51:04 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-01-08 15:51:04 +0000 |
commit | bade8b3460ea3cf1182cd1bda9faf8b6ccee6a25 (patch) | |
tree | 6b0c855e3d0688e07f512e61d17d76d09c64c6cb /win32 | |
parent | 59701e7f6a483d4aad4dc7088c673cd69fe294c8 (diff) | |
download | busybox-w32-bade8b3460ea3cf1182cd1bda9faf8b6ccee6a25.tar.gz busybox-w32-bade8b3460ea3cf1182cd1bda9faf8b6ccee6a25.tar.bz2 busybox-w32-bade8b3460ea3cf1182cd1bda9faf8b6ccee6a25.zip |
ps: add support for the args column
Implement read_cmdline() for WIN32 by storing the command line in
the same way as the applet name.
The applet name is actually used for the comm column which is
truncated to COMM_LEN. Using this as the size of the bb_comm
array avoids the need to calculate MAX_APPLET_NAME_LEN.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/process.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/win32/process.c b/win32/process.c index b29780be8..49dddf864 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -377,11 +377,11 @@ static inline long long filetime_to_ticks(const FILETIME *ft) | |||
377 | } | 377 | } |
378 | 378 | ||
379 | /* | 379 | /* |
380 | * Attempt to get the applet name from another instance of busybox.exe. | 380 | * Attempt to get a string from another instance of busybox.exe. |
381 | * This will only work if the other process is using the same binary | 381 | * This will only work if the other process is using the same binary |
382 | * as the current process. If anything goes wrong just give up. | 382 | * as the current process. If anything goes wrong just give up. |
383 | */ | 383 | */ |
384 | static char *get_applet_name(DWORD pid, char *exe) | 384 | static char *get_bb_string(DWORD pid, const char *exe, char *string) |
385 | { | 385 | { |
386 | HANDLE proc; | 386 | HANDLE proc; |
387 | HMODULE mlist[32]; | 387 | HMODULE mlist[32]; |
@@ -389,6 +389,7 @@ static char *get_applet_name(DWORD pid, char *exe) | |||
389 | void *address; | 389 | void *address; |
390 | char *my_base; | 390 | char *my_base; |
391 | char buffer[128]; | 391 | char buffer[128]; |
392 | char exepath[PATH_MAX]; | ||
392 | char *name = NULL; | 393 | char *name = NULL; |
393 | int i; | 394 | int i; |
394 | 395 | ||
@@ -397,6 +398,12 @@ static char *get_applet_name(DWORD pid, char *exe) | |||
397 | return NULL; | 398 | return NULL; |
398 | } | 399 | } |
399 | 400 | ||
401 | if (exe == NULL) { | ||
402 | if (GetProcessImageFileName(proc, exepath, PATH_MAX) != 0) { | ||
403 | exe = bb_basename(exepath); | ||
404 | } | ||
405 | } | ||
406 | |||
400 | /* | 407 | /* |
401 | * Search for the module that matches the name of the executable. | 408 | * Search for the module that matches the name of the executable. |
402 | * The values returned in mlist are actually the base address of | 409 | * The values returned in mlist are actually the base address of |
@@ -407,7 +414,7 @@ static char *get_applet_name(DWORD pid, char *exe) | |||
407 | goto finish; | 414 | goto finish; |
408 | } | 415 | } |
409 | 416 | ||
410 | for (i=0; i<needed/sizeof(HMODULE); ++i) { | 417 | for (i=0; exe != NULL && i<needed/sizeof(HMODULE); ++i) { |
411 | char modname[MAX_PATH]; | 418 | char modname[MAX_PATH]; |
412 | if (GetModuleFileNameEx(proc, mlist[i], modname, sizeof(modname))) { | 419 | if (GetModuleFileNameEx(proc, mlist[i], modname, sizeof(modname))) { |
413 | if (strcasecmp(bb_basename(modname), exe) == 0) { | 420 | if (strcasecmp(bb_basename(modname), exe) == 0) { |
@@ -432,17 +439,14 @@ static char *get_applet_name(DWORD pid, char *exe) | |||
432 | goto finish; | 439 | goto finish; |
433 | } | 440 | } |
434 | 441 | ||
435 | /* attempt to read the applet name */ | 442 | /* attempt to read the required string */ |
436 | address = (char *)mlist[i] + ((char *)bb_applet_name - my_base); | 443 | address = (char *)mlist[i] + ((char *)string - my_base); |
437 | if (!ReadProcessMemory(proc, address, buffer, 128, NULL)) { | 444 | if (!ReadProcessMemory(proc, address, buffer, 128, NULL)) { |
438 | goto finish; | 445 | goto finish; |
439 | } | 446 | } |
440 | 447 | ||
441 | /* check that the string really is an applet name */ | 448 | buffer[127] = '\0'; |
442 | buffer[31] = '\0'; | 449 | name = auto_string(xstrdup(buffer)); |
443 | if (find_applet_by_name(buffer) >= 0 || !strcmp(buffer, "[sh]")) { | ||
444 | name = auto_string(xstrdup(buffer)); | ||
445 | } | ||
446 | 450 | ||
447 | finish: | 451 | finish: |
448 | CloseHandle(proc); | 452 | CloseHandle(proc); |
@@ -522,7 +526,7 @@ UNUSED_PARAM | |||
522 | if (sp->pid == GetProcessId(GetCurrentProcess())) { | 526 | if (sp->pid == GetProcessId(GetCurrentProcess())) { |
523 | comm = applet_name; | 527 | comm = applet_name; |
524 | } | 528 | } |
525 | else if ((name=get_applet_name(pe.th32ProcessID, pe.szExeFile)) != NULL) { | 529 | else if ((name=get_bb_string(sp->pid, pe.szExeFile, bb_comm)) != NULL) { |
526 | comm = name; | 530 | comm = name; |
527 | } | 531 | } |
528 | else { | 532 | else { |
@@ -533,6 +537,20 @@ UNUSED_PARAM | |||
533 | return sp; | 537 | return sp; |
534 | } | 538 | } |
535 | 539 | ||
540 | void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) | ||
541 | { | ||
542 | const char *str, *cmdline; | ||
543 | |||
544 | *buf = '\0'; | ||
545 | if (pid == GetProcessId(GetCurrentProcess())) | ||
546 | cmdline = bb_command_line; | ||
547 | else if ((str=get_bb_string(pid, NULL, bb_command_line)) != NULL) | ||
548 | cmdline = str; | ||
549 | else | ||
550 | cmdline = comm; | ||
551 | safe_strncpy(buf, cmdline, col); | ||
552 | } | ||
553 | |||
536 | /** | 554 | /** |
537 | * If the process ID is positive invoke the callback for that process | 555 | * If the process ID is positive invoke the callback for that process |
538 | * only. If negative or zero invoke the callback for all descendants | 556 | * only. If negative or zero invoke the callback for all descendants |