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

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 21-05-2020
Avatar de aguml
aguml aguml is offline
Miembro
 
Registrado: may 2013
Posts: 885
Poder: 11
aguml Va por buen camino
Obtener el TEB de un proceso en x64

Buenas amigos, ya estoy depurando mi clase TDebugger y el primer pero que tengo es algo que uso para los métodos antidebug para lo cual necesito obtener el TEB. He modificado la función que tenia en x86 para adaptarla en x64 y quedó así:
Código PHP:
DWORD64 __fastcall THiloDebugger::GetTEBHANDLE hThreadHANDLE hProcess )
{
        
LDT_ENTRY Selector;
        
DWORD64 nTEBAddr;
        
CONTEXT Context = {0};

        
Context.ContextFlagsCONTEXT_FULL CONTEXT_FLOATING_POINT CONTEXT_DEBUG_REGISTERS;

        if(!
GetThreadContext(hThread, &Context))
        {
                return 
0;
        }

        if(!
GetThreadSelectorEntry(hThreadContext.SegFs, &Selector))
        {
                return 
0;
        }

        
nTEBAddr = ((Selector.HighWord.Bits.BaseHi << 24) + (Selector.HighWord.Bits.BaseMid << 16) + Selector.BaseLow);

        return 
nTEBAddr;

El problema es que GetThreadSelectorEntry solo sirve para x86 (lo miré en la msdn). ¿No existe el TEB en x64?¿como lo obtengo?

Última edición por aguml fecha: 21-05-2020 a las 10:39:44. Razón: El titulo estaba mal
Responder Con Cita
  #2  
Antiguo 21-05-2020
Avatar de aguml
aguml aguml is offline
Miembro
 
Registrado: may 2013
Posts: 885
Poder: 11
aguml Va por buen camino
He probado esto:
Código PHP:
DWORD64 __fastcall THiloDebugger::GetTEBHANDLE hThread)
{
        
#ifndef THREAD_BASIC_INFORMATION
            #define SIZE_NTSTATUS 4
            #define SIZE_PADDING 4
            #define SIZE_CLIENT_ID 16
            #define SIZE_KAFFINITY 8
            #define SIZE_KPRIORITY 4

            
typedef DWORD NTSTATUS;
            
typedef __int128 CLIENT_ID;
            
typedef DWORD KPRIORITY;

            
typedef struct _THREAD_BASIC_INFORMATION
            
{
                
NTSTATUS                ExitStatus;
                
PVOID                   TebBaseAddress;
                
CLIENT_ID               ClientId;
                
KAFFINITY               AffinityMask;
                
KPRIORITY               Priority;
                
KPRIORITY               BasePriority;
            } 
THREAD_BASIC_INFORMATION, *PTHREAD_BASIC_INFORMATION;
        
#endif

        
typedef NTSTATUS (WINAPI *PNTQIT)(HANDLETHREADINFOCLASSPVOIDULONGPULONG);
        
PNTQIT pNtQueryInformationThread;

        
THREAD_BASIC_INFORMATION infoBuff={0};
        
HMODULE hMod LoadLibrary(L"Ntdll.dll");
        
pNtQueryInformationThread = (PNTQITGetProcAddress(hMod,"NtQueryInformationThread");
        
NTSTATUS stat pNtQueryInformationThread(hThread, (THREADINFOCLASS0, &infoBuffsizeof(THREAD_BASIC_INFORMATION), NULL);
        if (!
NT_SUCCESS(stat)) {
            
ShowMessage(WideString().sprintf(L"ERROR (code 0x%8x): No se pudo obtener la informacion del TEB del proceso. \n"stat));
            return 
0;
        }
        return (
DWORD64)infoBuff.TebBaseAddress;

Aparentemente funciona pero no se si lo que obtengo es lo que busco o está obteniendo otra cosa:
Código:
infoBuff		{ 0x00000103, :0000000000336000, 168750814786294978186064, 0x000000000000000f, 0x00000009, 0x00000000 }
	infoBuff.ExitStatus	259 (0x00000103)
	infoBuff.TebBaseAddress	:0000000000336000
	infoBuff.ClientId	168750814786294978186064
	infoBuff.AffinityMask	15 (0x000000000000000f)
	infoBuff.Priority	9 (0x00000009)
	infoBuff.BasePriority	0 (0x00000000)
Lo que me extraña es la TebBaseAddress ¿no tendria que estar dentro del header del programa? Ademas en cada ejecucion me da un valor diferente
Pienso que esto no vale
Responder Con Cita
Respuesta



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
obtener peb de mi proceso aguml C++ Builder 5 18-06-2014 08:47:47
Obtener proceso bloqueado kasper API de Windows 4 11-03-2008 14:40:30
Obtener el handle de un proceso TEO127 API de Windows 4 10-01-2008 22:14:07
Obtener proceso de una ventana. Thor API de Windows 2 02-05-2006 18:46:55
Obtener el username de un proceso Alex_Ramiro API de Windows 1 08-02-2005 19:34:23


La franja horaria es GMT +2. Ahora son las 07:32:11.


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