Floris Bruynooghe avatar Floris Bruynooghe committed d25182c

Add .commmand and .cwd

Comments (0)

Files changed (1)

      process_sources.append('src/arch/procfs_processtable.c')
 +if PLATFORM == 'win32':
 +    process_sources.append('src/arch/win32_processtable.c')
-+    process_libraries.extend(['Psapi', 'ole32', 'oleaut32', 'Shell32'])
++    process_libraries.extend(['Psapi', 'Shell32'])
  
  _psi = Extension('psi._psi',
                   define_macros = MACROS,
 new file mode 100644
 --- /dev/null
 +++ b/src/arch/win32_process.c
-@@ -0,0 +1,680 @@
+@@ -0,0 +1,741 @@
 +/* The MIT License
 + *
 + * Copyright (C) 2009-2010 Floris Bruynooghe
 +
 +/***** Local declarations *****/
 +
++/** We prefer to use the C standard libary, not Microsoft extensions
++ *
++ * Problem is that Visual Studio thinks that is unsafe, so we disable
++ * the warnings using this declaration.
++ */
++#define _CRT_SECURE_NO_WARNINGS
++
 +/** Define NT_SUCCESS macro if it doesn't exist
 + *
 + * These values are lifed from
 +                    const HANDLE proch, const PVOID rtl_addr);
 +static int set_env(psi_process_t *proci,
 +                   const HANDLE proch, const PVOID rtl_addr);
++static int set_cwd(psi_process_t *proci,
++                   const HANDLE proch, const PVOID rtl_addr);
 +static int set_ppid(psi_process_t *proci, const HANDLE proch);
 +
 +/* Helpers */
 +        goto error;
 +    if (set_env(proci, proch, rtl_userinfo_addr) < 0)
 +        goto error;
++    if (set_cwd(proci, proch, rtl_userinfo_addr) < 0)
++	goto error;
 +    if (set_ppid(proci, proch) < 0)
 +        goto error;
 +    if (set_toolsnapshot(proci, pid) < 0) /* XXX */
 +    proci->name = psi_malloc(len);
 +    strncpy(proci->name, name, len);
 +    proci->name_status = PSI_STATUS_OK;
++    proci->command = psi_malloc(sizeof(char));
++    if (proci->command == NULL)
++      return -1;
++    *(proci->command) = '\0';
++    proci->command_status = PSI_STATUS_OK;
 +    return 0;
 +}
 +
 +                              sizeof(PROCESS_MEMORY_COUNTERS)))
 +        if (GetLastError() == ERROR_ACCESS_DENIED) {
 +            proci->rss_status = PSI_STATUS_PRIVS;
-+            proci->vsz_status = PSI_STATUS_PRIVS;
++            proci->pagefile_status = PSI_STATUS_PRIVS;
 +            return 0;
 +        } else {
 +            PyErr_SetFromWindowsErr(0);
 +
 +
 +static int
++set_cwd(psi_process_t *proci, const HANDLE proch, const PVOID rtl_addr)
++{
++    UNICODE_STRING uscwd;
++    LONG cwd_offset;
++    WCHAR* wcwd;
++    size_t len;
++    int r;
++
++    cwd_offset = FIELD_OFFSET(RTL_USER_PROCESS_PARAMETERS,
++                              CurrentDirectoryPath);
++    if (!ReadProcessMemory(proch, (PCHAR)rtl_addr + cwd_offset,
++                           &uscwd, sizeof(UNICODE_STRING), NULL)) {
++        PyErr_SetFromWindowsErr(0);
++        return -1;
++    }
++    wcwd = (WCHAR*) psi_malloc(uscwd.Length + sizeof(WCHAR));
++    if (wcwd == NULL)
++        return -1;
++    if (!ReadProcessMemory(proch, uscwd.Buffer, wcwd,
++                           uscwd.Length + sizeof(WCHAR), NULL)) {
++        psi_free(wcwd);
++        PyErr_SetFromWindowsErr(0);
++        return -1;
++    }
++    len = wcslen(wcwd) + 1;
++    proci->cwd = psi_malloc(len);
++    if (proci->cwd == NULL) {
++        psi_free(wcwd);
++        return -1;
++    }
++    r = WideCharToMultiByte(20127, 0, wcwd, -1,
++                            proci->cwd, (int)len, NULL, NULL);
++    psi_free(wcwd);
++    if (r == 0) {
++        PyErr_SetFromWindowsErr(0);
++        return -1;
++    }
++    proci->cwd_status = PSI_STATUS_OK;
++    return 0;
++}
++
++
++static int
 +set_ppid(psi_process_t *proci, const HANDLE proch)
 +{
 +    struct ProcessBasicInformation pbi;
 +                psi_free(argv[j]);
 +            psi_free(argv);
 +            LocalFree(wargv);
++            PyErr_SetFromWindowsErr(0);
 +            return NULL;
 +        }
 +    }
 +            for (j = 0; j < i; j++)
 +                psi_free(envv[i]);
 +            psi_free(envv);
++            PyErr_SetFromWindowsErr(0);
 +            return NULL;
 +        }
 +    }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.