Buenas amigos, sigo con mi proyecto del debugger y alguien me dijo que podria ser problema de que el proceso que hace de debugger no puede tener los mismos privilegios que el proceso depurado y por eso no me deja poner bps y la funcion WriteProcessMemory falla.
Me dijo que para darle privilegios podria hacer algo asi:
Código PHP:
BOOL SetPrivilege(
HANDLE hProcess, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
){
HANDLE hToken = NULL;
TOKEN_PRIVILEGES tp;
LUID luid;
//The OpenProcessToken function opens the access token associated with a process.
/* An access token contains the security information for a logon session.
The system creates an access token when a user logs on, and every process executed
on behalf of the user has a copy of the token. The token identifies the user,
the user's groups, and the user's privileges. The system uses the token to control
access to securable objects and to control the ability of the user to perform various
system-related operations on the local computer. There are two kinds of access token,
primary and impersonation.
*/
if(!OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken)){
ShowMessage(AnsiString().sprintf("OpenProcessToken() failed, error %u\n", GetLastError()));
return FALSE;
}
if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid ) ) // receives LUID of privilege
{
ShowMessage(AnsiString().sprintf("LookupPrivilegeValue error: %u\n", GetLastError()));
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if ( !AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL) ){
ShowMessage(AnsiString().sprintf("AdjustTokenPrivileges error: %u\n", GetLastError()));
return FALSE;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED){
ShowMessage(AnsiString().sprintf("The token does not have the specified privilege."));
return FALSE;
}
CloseHandle( hToken );
return TRUE;
}
y la llamo así:
Código PHP:
if(!SetPrivilege(GetCurrentProcess(), SE_DEBUG_NAME, TRUE)) {
ShowMessage(AnsiString().sprintf("Failed to enable privilege, error %u\n",GetLastError()));
return false;
}
La funcion parece funcionar puesto que no me muestra ningun mensaje pero sigue pasandome lo mismo y WriteProcessMemory sigue sin poder escribir en el proceso depurado.
Me gustaria asegurarme de que se le ha dado los privilegios a mi aplicacion pero no se como hacerlo y no veo nada por la red. Lo unico que he encontrado es esta funcion y la verdad es que no se bien lo que hace y me muestra muchos mensajes con varios tipos de privilegios:
Código PHP:
bool ShowPrivileges()
{
// Get a token handle.
HANDLE hToken;
if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &hToken))
{
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
return false;
}
// Get the token privilege information.
DWORD dwNeeded = 0;
GetTokenInformation(hToken, TokenPrivileges, NULL, 0, &dwNeeded);
LPBYTE pBuffer = new BYTE[dwNeeded + 1];
GetTokenInformation(hToken, TokenPrivileges, pBuffer, dwNeeded, &dwNeeded);
// Cast to the proper type.
PTOKEN_PRIVILEGES pTokenPrivileges = reinterpret_cast<PTOKEN_PRIVILEGES>(pBuffer);
// Iterate the privileges.
for (DWORD i = 0; i < pTokenPrivileges->PrivilegeCount; ++i)
{
// Get and display the privilege name.
DWORD dwSize = 0;
LookupPrivilegeName(NULL, &pTokenPrivileges->Privileges[i].Luid, NULL, &dwSize);
LPSTR szName = new CHAR[dwSize + 1];
LookupPrivilegeName(NULL, &pTokenPrivileges->Privileges[i].Luid, szName, &dwSize);
ShowMessage(szName);
delete[] szName;
}
delete[] pBuffer;
CloseHandle(hToken);
return true;
}
¿Me podeis ayudar a ver si puedo ver si tiene privilegios de debug o no?
Gracias por adelantado