Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 10-05-2020
Avatar de aguml
aguml aguml is offline
Miembro
 
Registrado: may 2013
Posts: 885
Poder: 11
aguml Va por buen camino
Problemas al asignar privilegios a mi proceso

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(hProcessTOKEN_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_PRIVILEGESNULL
           (
PDWORDNULL) ){ 
        
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;
    }
    
CloseHandlehToken );
    return 
TRUE;

y la llamo así:
Código PHP:
if(!SetPrivilege(GetCurrentProcess(), SE_DEBUG_NAMETRUE)) {
            
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_QUERYFALSE, &hToken))
    {
        if (!
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
            return 
false;
    }

    
// Get the token privilege information.
    
DWORD dwNeeded 0;
    
GetTokenInformation(hTokenTokenPrivilegesNULL0, &dwNeeded);
    
LPBYTE pBuffer = new BYTE[dwNeeded 1];
    
GetTokenInformation(hTokenTokenPrivilegespBufferdwNeeded, &dwNeeded);

    
// Cast to the proper type.
    
PTOKEN_PRIVILEGES pTokenPrivileges reinterpret_cast<PTOKEN_PRIVILEGES>(pBuffer);

    
// Iterate the privileges.
    
for (DWORD i 0pTokenPrivileges->PrivilegeCount; ++i)
    {
        
// Get and display the privilege name.
        
DWORD dwSize 0;
        
LookupPrivilegeName(NULL, &pTokenPrivileges->Privileges[i].LuidNULL, &dwSize);
        
LPSTR szName = new CHAR[dwSize 1];
        
LookupPrivilegeName(NULL, &pTokenPrivileges->Privileges[i].LuidszName, &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
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Problemas con CloseHandle y atacheo de proceso aguml C++ Builder 3 07-05-2020 15:04:01
Crear, modificar, borrar usuarios y asignar privilegios en Firebird anubis Trucos 2 17-10-2014 18:38:15
Problemas de Privilegios en Delphi gersojn Varios 10 03-08-2011 19:30:06
Problema para asignar privilegios PaFernan99 MySQL 2 19-11-2006 20:32:50
Problemas al crear TXT y asignar un String lucasarts_18 Varios 7 30-09-2005 22:42:43


La franja horaria es GMT +2. Ahora son las 19:56:05.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi