J'essaie d'ouvrir un processus avec mon débogueur en utilisant CreateProcess
avec les drapeaux DEBUG_PROCESS
et DEBUG_ONLY_THIS_PROCESS
et le processus est ouvert, mais quand j'essaie d'appeler SymInitialize
avec le handle que je reçois , il échoue.Problèmes avec l'ouverture d'un processus avec des drapeaux DEBUG
Ceci est mon code:
#include <windows.h>
#include <stdio.h>
#include <dbghelp.h>
#pragma (lib, "dbghelp.lib");
bool EnablePrivilege(LPCTSTR lpszPrivilegeName, BOOL bEnable)
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
bool ret;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_READ, &hToken))
return FALSE;
if (!LookupPrivilegeValue(NULL, lpszPrivilegeName, &luid))
return FALSE;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0;
ret = AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
CloseHandle(hToken);
return ret;
}
void main()
{
EnablePrivilege(SE_DEBUG_NAME, TRUE);
STARTUPINFOA startInfo;
PROCESS_INFORMATION processInfo;
ZeroMemory(&startInfo, sizeof(startInfo));
startInfo.cb = sizeof(startInfo);
ZeroMemory(&processInfo, sizeof(processInfo));
DWORD creationFlags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS | PROCESS_VM_READ | PROCESS_QUERY_INFORMATION;
const char* comLine = "Some process path and name";
// Start the child process.
if(CreateProcessA(NULL, // No module name (use command line)
(LPSTR)comLine, //argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
creationFlags, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&startInfo, // Pointer to STARTUPINFO structure
&processInfo) // Pointer to PROCESS_INFORMATION structure
== false)
{
printf("FAIL!");
return;
}
SetLastError(0);
bool ok = SymInitialize(processInfo.hProcess, NULL, true);
int err = GetLastError();
}
Si j'appelle CreateProcess sans drapeaux de création, réussir SymInitialize.
Qu'est-ce que je fais de mal?
J'ai également essayé de supprimer les indicateurs: PROCESS_VM_READ et PROCESS_QUERY_INFORMATION mais cela n'a pas aidé. – Idov
Lorsque l'appel à SymInitialize échoue, que GetLastError() renvoie-t-il? –
Il renvoie une valeur négative de la poubelle:/ – Idov