elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


  Mostrar Mensajes
Páginas: 1 2 3 4 [5] 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
41  Programación / Programación C/C++ / Re: Interceptar Opengl32 con Detours y obtener un WH en: 10 Abril 2013, 03:06 am
Si eso estaba en el código original de SharkBoy999, no lo quité pero eso no funciona así, es decir vos comprobás si GetAsyncKeyState es diferente de 0, ya que la especificación de la MSDN dice que si el bit más significativo es 1 es que la llave está presionada, y dice que no se tome en cuenta otros comportamientos, por lo tanto no hace falta usar máscara de bits, sólamente comprobando que no sea 0 es suficiente.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx


EDIT: XD aparte la función 'toggle' es cualquier cosa , es decir no le des bola al resto del código porque pertenece a la base de SharkBoy999, es un man que hizo un par de hacks en el pasado y siempre que publicaba códigos lo hacía poniendo errores para que no los compile cualquiera o para que no funcionen. Lo mismo hacían muchos otros.

Es decir, concentráte en el método del HOOK

Saludos
42  Programación / Programación C/C++ / Re: Interceptar con Detours el Opengl nativo por TIB en: 10 Abril 2013, 02:47 am
Dejo un par de links más
http://www.codeproject.com/Articles/29174/Win32-TIB
http://www.microsoft.com/msj/archive/s2ce.aspx

http://www.gamedeception.net/threads/8866-TIB-Opengl-hooking
Y esto lo saqué de gamedeception (2ci- y Organner), es otro intento.. aunque sino no da los resultados que se esperan, mejor obtener un puntero al selector FS del hilo creador de la ventana, y después hacer [eax+OFFSET] tal como en Opengl32.dll. No hay TIB específico para Opengl32, sino más bien es el TIB del hilo en el que se llama a Opengl32.

Código
  1. typedef void(__stdcall* t_glBegin)(GLenum);
  2. t_glBegin pOrig_glBegin = NULL;
  3.  
  4. /////////////////////////////////////////////////////////////////////////////////////////////////
  5.  
  6. void __stdcall HOOK_glBegin(GLenum mode)
  7. {
  8. static bool once=false;
  9. if(!once){
  10.  
  11. printf("\n");
  12. printf("DLL -> HOOK_glBegin!\n");
  13. system("pause");
  14. once=true;
  15. }
  16.  
  17. (*pOrig_glBegin)(mode);
  18. }
  19.  
  20. /////////////////////////////////////////////////////////////////////////////////////////////////
  21.  
  22. DWORD* OGL_GetFuncForOffset( DWORD dwTIBOffset )
  23. {
  24. DWORD* retval=0;
  25. __asm {
  26. mov eax, fs:[0x18]; // TIB
  27. add eax, dwTIBOffset;
  28. mov eax, [eax]
  29. mov retval, eax
  30. }
  31. return retval;
  32. }
  33.  
  34. /////////////////////////////////////////////////////////////////////////////////////////////////
  35.  
  36. bool OGL_IsOffsetHooked( DWORD dwTIBOffset, DWORD* dwOriginal, DWORD* dwHook )
  37. {
  38. return( OGL_GetFuncForOffset( dwTIBOffset ) == dwHook );
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////////////////////////
  42.  
  43. void OGL_HookTIB( DWORD dwTIBOffset, DWORD* dwOriginal, DWORD* dwHook )
  44. {
  45. if( OGL_IsOffsetHooked( dwTIBOffset, dwOriginal, dwHook ) ){
  46. return;
  47. }
  48.  
  49. __asm {
  50. mov eax, dword ptr fs:[0x18]; // TIB
  51. add eax, dwTIBOffset; // add offset needed
  52. mov ecx, [eax] // get the function offset
  53. mov ebx, [dwOriginal] // grab addr of original
  54. mov [ebx], ecx; // move it into our pointer
  55. mov ecx, dwHook; // move offset of our hook into ecx
  56. mov [eax], ecx; // move ecx into opengl's info space
  57. }
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////////////////////////
  61.  
  62. #define ofs_glBegin     0x7CC
  63. #define ofs_glVertext3f 0x94C
  64. #define ofs_glPopMatrix 0x9E4
  65.  
  66. /////////////////////////////////////////////////////////////////////////////////////////////////
  67.  
  68. DWORD dwReplaceDriverAddress(DWORD dwIndex, DWORD dwNewFunction)
  69. {
  70.    DWORD* dwTIB = NULL;
  71. DWORD teb=0;
  72. PTEB myTEB;
  73.  
  74.       __asm
  75.       {
  76.            mov eax, dword ptr fs:[18h]
  77.            add eax, dwIndex
  78.            mov dwTIB, eax
  79.            mov myTEB,eax
  80.       }
  81.  
  82. printf("myTEB 0x%X\n",myTEB);
  83. printf("dwIndex 0x%X\n",dwIndex);
  84. printf("dwTIB 0x%X\n",dwTIB);
  85. printf("*dwTIB 0x%X\n",*dwTIB);
  86. printf("dwNewFunction 0x%X\n",dwNewFunction);
  87. system("pause");
  88.  
  89.        DWORD g_dwReturnValue = *dwTIB;
  90.        //*dwTIB = dwNewFunction;
  91.        //printf("*dwTIB 0x%X\n",*dwTIB);
  92.        return g_dwReturnValue;
  93. }
  94.  
  95. /////////////////////////////////////////////////////////////////////////////////////////////////
  96.  
  97. void thread(){
  98.  
  99. while(1){
  100.  
  101. if(GetModuleHandle("opengl32.dll")){
  102.  
  103. pOrig_glBegin = (t_glBegin)dwReplaceDriverAddress(ofs_glBegin,(DWORD)HOOK_glBegin);
  104.  
  105. if(pOrig_glBegin){
  106.  
  107.    printf("pOrig_glBegin 0x%X\n",pOrig_glBegin);
  108.    system("pause");
  109. }
  110. break;
  111. }
  112.  
  113. Sleep(300);
  114. }
  115. }
  116.  
  117. /////////////////////////////////////////////////////////////////////////////////////////////////
  118.  
  119. BOOL APIENTRY DllMain(HINSTANCE i, DWORD reason, LPVOID res){
  120.  
  121. if(reason == DLL_PROCESS_ATTACH){
  122.  
  123. if(GetModuleHandle("opengl32.dll")){
  124.  
  125. pOrig_glBegin = (t_glBegin)dwReplaceDriverAddress(ofs_glBegin,(DWORD)HOOK_glBegin);
  126.  
  127. if(pOrig_glBegin){
  128.    printf("pOrig_glBegin 0x%X\n",pOrig_glBegin);
  129.    system("pause");
  130. }
  131. }
  132.  
  133. //CreateThread(0,0,(unsigned long (__stdcall *)(void *))thread,0,0,0);
  134. }
  135. return (true);
  136. }
  137.  

PS: Ese código la sarpa, parece un multihack XD.. y tiene la librería de karman IntelliAPIHooking, nice  >:D
43  Programación / Programación C/C++ / Re: Codigo Fuente, Cheat Cs 1.6 en: 9 Abril 2013, 21:29 pm
aah, claro voy a tratar de ir escalando por metodo

La verdad, esto que hiciste se puede considerar parchear el juego, pero en realidad se aplica a cuando cambiás bytes en la memoria del proceso en la parte del código, los punteros son datos aunque podemos considerarlo un parche el hecho de reemplazar un valor por otro.

Los 'Detours' también es "parchear el juego".

Los hooks del tipo EAT y IAT también se trata de parchear, lo mismo, osea punteros.

Pero eso te dije que son métodos instrusivos.

Son fáciles de detectar y de restaurar.
Por eso cuando uno parchea algo que tiene comprobaciones de seguridad, lo que se debe hacer también es parchear esas comprobaciones XD, para que no te detecten

44  Programación / Programación C/C++ / Interceptar con Detours el Opengl nativo por TEB en: 9 Abril 2013, 20:50 pm
Primero que nada quiero decir que voy a postear el código fuente público de un hack de karman, llamado Inexinferis FX de finales del 2010.
Es un código ya publicado sólo que no se observa demasiado por internet XD

Lo posteo porque es parte de los métodos que se estaban comentando en el foro últimamente, y se trata de utilizar 'detours' pero a un nivel más profundo que el que ofrece Openg32.dll, siendo Opengl32.dll el nivel más alto y el driver de la tarjeta gráfica lo más bajo. Intermediamente se tiene otra DLL de relacionada con Opengl32 pero perteneciente a la firma de la tarjeta gráfica, pero el tema es que hay muchas marcas de tarjetas gráficas y por lo tanto muchos drivers. Por lo que cada uno sabe lo que tiene XD

Esta es la información que se necesita manejar para poder entender como se determinan las direcciones de bajo nivel para Opengl por medio de lo que se llama TEB (Thread Environment Block), también conocido como TIB (Thread Information Block) por algunos, aunque otros insisten en que el TIB es miembro del TEB (Ver link de undocumented.ntinternals.net).
http://es.wikipedia.org/wiki/Win32_Thread_Information_Block
http://en.wikipedia.org/wiki/Win32_Thread_Information_Block
http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/Thread/TEB.html

Otros links
http://www.snoxd.net/index.php/topic/377-finding-the-thread-id-from-the-executable-name/
http://www.alex-ionescu.com/part1.pdf
http://www.ciphermonk.net/teb.php
http://nasutechtips.blogspot.com.ar/2011/01/thread-information-block-tib-and-fs.html
http://skypher.com/wiki/index.php/Hacking/Windows_internals/Process/Memory/TEB
http://stackoverflow.com/questions/9964236/tib-access-in-win32
http://software.intel.com/sites/products/documentation/doclib/stdxe/2013composerxe/compiler/cpp-win/GUID-F90BD123-AE25-4DC2-ADFB-B59067E77728.htm

Otros links que se pueden tomar en cuenta
http://www.nynaeve.net/?p=180
http://msdn.microsoft.com/es-ar/library/6yh4a9k1.aspx
http://msdn.microsoft.com/en-us/library/6yh4a9k1.aspx
http://msdn.microsoft.com/es-ar/library/y6h8hye8.aspx
http://msdn.microsoft.com/es-ar/library/2s9wt68x.aspx


En Opengl32.DLL básicamente se encuentran funciones que sólo hacen saltos hacia el nivel más bajo de Opengl, y para obtener las direcciones correctas del driver, se hace con este método del TEB.

Este es el ejemplo de glBegin

Citar
Pos: FS:[0x18]      Len: 4   Ver: Win9x y NT   -> Dirección lineal del TIB

con esos parámetros se consigue hacer un salto hacia el nivel bajo del que hablábamos (nvoglnt.dll en mi caso que tengo una tarjeta NVIDIA)


Luego hace otro salto hacia la función en sí.
Con OllyDBG se puede observar el estado de los registros para tener una mejor idea de como se obtienen las direcciones.
Mejor aún, para aquellos que prefieren leer una buena explicación les dejo este manual al respecto:
http://www.mediafire.com/?kmru385gmmcik46

Código
  1. //
  2.  
  3. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4.  
  5. #pragma comment(lib,"OpenGL32.lib")
  6. #pragma comment(lib, "Version.lib")
  7. #define _WIN32_WINNT 0x0500
  8. #undef UNICODE
  9. #include <windows.h>
  10. #include <gl/gl.h>
  11. #include <gl/glu.h>
  12. #include <shlwapi.h>
  13. #include <stdio.h>
  14.  
  15. #include "nt.h"
  16.  
  17. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  18.  
  19. HANDLE hThread=NULL;
  20. PBYTE dwFSBase,dwFSBase2;
  21.  
  22. HWND hdHalfLife;
  23.  
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25.  
  26. typedef void (APIENTRY* glBlendFunc_t)(GLenum,GLenum);
  27. typedef void (APIENTRY* glClear_t)(GLbitfield);
  28. typedef void (APIENTRY* glVertex2f_t)(GLfloat,GLfloat);
  29. typedef void (APIENTRY* glVertex3f_t)(GLfloat,GLfloat,GLfloat);
  30. typedef void (APIENTRY* glVertex3fv_t)(const GLfloat*);
  31. typedef void (APIENTRY* glBegin_t)(GLenum);
  32. glBlendFunc_t pglBlendFunc=0;
  33. glClear_t pglClear=0;
  34. glVertex2f_t pglVertex2f=0;
  35. glVertex3f_t pglVertex3f=0;
  36. glVertex3fv_t pglVertex3fv=0;
  37. glBegin_t pglBegin=0;
  38.  
  39. BOOL bFlash=FALSE;
  40. BOOL bSky=FALSE;
  41.  
  42. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  43.  
  44. void APIENTRY New_glBegin(GLenum mode){
  45.  
  46. if(mode==GL_TRIANGLE_STRIP||mode==GL_TRIANGLE_FAN)
  47. glDisable(GL_DEPTH_TEST);
  48. else if(mode!=GL_QUADS&&mode!=GL_LINES)
  49. glEnable(GL_DEPTH_TEST);
  50.  
  51. if(mode==GL_QUADS){
  52. float col[4];
  53.        glGetFloatv(GL_CURRENT_COLOR, col);
  54.        bFlash=(col[0]==1.0&&col[1]==1.0&&col[2]==1.0&&col[3]>0.2);
  55. bSky=TRUE;
  56.    }
  57. else
  58. bSky=FALSE;
  59. pglBegin(mode);
  60. }
  61.  
  62. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  63.  
  64. void APIENTRY New_glClear(GLbitfield mask){
  65.  
  66. if(mask==GL_DEPTH_BUFFER_BIT){
  67. mask+=GL_COLOR_BUFFER_BIT;
  68. glClearColor(0.0f,0.0f,0.0f,0.0f);
  69. }
  70. pglClear(mask);
  71. }
  72.  
  73. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74.  
  75. void APIENTRY New_glVertex3fv(const GLfloat* v){
  76.  
  77. if(bSky) return;
  78. pglVertex3fv(v);
  79. }
  80.  
  81. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  82.  
  83. void APIENTRY New_glVertex2f(GLfloat x, GLfloat y){
  84.  
  85. if(bFlash&&x==0.0&&y==0.0) glColor4f(1.0f,1.0f,1.0f,0.2f);
  86.    pglVertex2f(x,y);
  87. }
  88.  
  89. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  90.  
  91. void APIENTRY New_glVertex3f(GLfloat x, GLfloat y, GLfloat z){
  92.  
  93. glColor3f(1.0f,1.0f,1.0f);
  94. pglVertex3f(x,y,z);
  95. }
  96.  
  97. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  98.  
  99. BOOL GetDllVersion(HMODULE hLibModule, DLLVERSIONINFO* aVersion){
  100.  
  101.    CHAR fileName[MAX_PATH];
  102.    UINT len=0;
  103.    VS_FIXEDFILEINFO* vsfi=NULL;
  104.    DWORD handle=0;
  105.    DWORD size=GetModuleFileName(hLibModule,fileName,MAX_PATH);
  106.    fileName[size]=0;
  107.    size=GetFileVersionInfoSize(fileName, &handle);
  108.    BYTE* versionInfo=new BYTE[size];
  109.    if(!GetFileVersionInfo(fileName,handle,size,versionInfo)){
  110. delete[] versionInfo;
  111.        return FALSE;
  112.    }
  113.    VerQueryValue(versionInfo,"\\",(PVOID*)&vsfi,&len);
  114.    aVersion->dwMajorVersion=HIWORD(vsfi->dwFileVersionMS);
  115.    aVersion->dwMinorVersion=LOWORD(vsfi->dwFileVersionMS);
  116.    aVersion->dwBuildNumber=HIWORD(vsfi->dwFileVersionLS);
  117.    aVersion->dwPlatformID=LOWORD(vsfi->dwFileVersionLS);
  118.    delete[] versionInfo;
  119.    return TRUE;
  120. }
  121.  
  122. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  123.  
  124. void* Detour1(BYTE* src, const BYTE* dst, const int len){
  125. BYTE* jmp = (BYTE*)malloc(len+5);
  126. DWORD dwback;
  127. while(!VirtualProtect(src, len, PAGE_READWRITE, &dwback));
  128. memcpy(jmp, src, len);jmp+=len;
  129. jmp[0] = 0xE9;
  130. *(DWORD*)(jmp+1)=(DWORD)(src+len-jmp)-5;
  131. src[0] = 0xE9;
  132. *(DWORD*)(src+1)=(DWORD)(dst-src)-5;
  133. while(!VirtualProtect(src, len, dwback, &dwback));
  134. return (jmp-len);
  135. }
  136.  
  137. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  138.  
  139. /*
  140. DWORD GetProcessThreadId(unsigned long ProcessId)
  141. {
  142.     HANDLE hSnapThread = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, ProcessId);
  143.     if(hSnapThread == INVALID_HANDLE_VALUE) return NULL;
  144.     THREADENTRY32 te;
  145.     te.dwSize = sizeof(THREADENTRY32);
  146.     if(Thread32First(hSnapThread, &te))
  147.     {
  148.        do
  149.        {
  150.             if(te.th32OwnerProcessID == ProcessId) {
  151.                 CloseHandle(hSnapThread);
  152.                 return te.th32ThreadID;
  153.             }
  154.  
  155.        } while(Thread32Next(hSnapThread, &te));
  156.     }
  157.     CloseHandle(hSnapThread);
  158.     return 0;
  159. }*/
  160.  
  161. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  162.  
  163. DWORD WINAPI Thread(LPVOID lpParam){
  164.  
  165.    DWORD dwThreadId,dwProcessId,dwOGLOffset;
  166.    CONTEXT Context;
  167.    LDT_ENTRY SelEntry;
  168.    HMODULE hModule;
  169.    Context.ContextFlags=CONTEXT_FULL|CONTEXT_DEBUG_REGISTERS;
  170.    DWORD dwTLSIndex=0;
  171.    DLLVERSIONINFO oglVersion;
  172.  
  173.    while(((hdHalfLife=FindWindow("Valve001",NULL))==NULL)
  174.              &&((hdHalfLife=FindWindow(NULL,"Counter-Strike"))==NULL))
  175.                      Sleep(100);
  176.  
  177.    while((hModule=GetModuleHandle("Opengl32.dll"))==NULL)
  178.              Sleep(100);
  179.  
  180.    if(GetDllVersion(hModule,&oglVersion)){
  181.  
  182.        if(oglVersion.dwMajorVersion==5&&oglVersion.dwMinorVersion==1){
  183.            dwTLSIndex=0xAC80C;
  184. }
  185. else if(oglVersion.dwMajorVersion==6&&oglVersion.dwMinorVersion==0){
  186.            dwTLSIndex=0xAB958;
  187. }
  188. else if(oglVersion.dwMajorVersion==6&&oglVersion.dwMinorVersion==1){
  189.            dwTLSIndex=0xA100C;
  190. }
  191.        else
  192.        {
  193.             //MessageBox(hdHalfLife,"Incompatible OpenGL Version...\n\nSorry man...","Inexinferis FX Series - Karman",0);
  194.            ExitThread(0);
  195.            return 0;
  196.        }
  197.    }
  198.    else
  199.    {
  200.        //MessageBox(hdHalfLife,"Can't Get OpenGL Version...\n\nWrong OpenGL???","Inexinferis FX Series - Karman",0);
  201. ExitThread(0);
  202.        return 0;
  203.    }
  204.  
  205.    //DWORD ProcessId = GetCurrentProcessId();
  206.    //DWORD ProcessThreadId = GetProcessThreadId(ProcessId);
  207.    dwThreadId=GetWindowThreadProcessId(hdHalfLife,&dwProcessId);
  208.    HANDLE hThread=OpenThread(THREAD_GET_CONTEXT|THREAD_SUSPEND_RESUME|THREAD_QUERY_INFORMATION,FALSE,dwThreadId);
  209.  
  210.    if(!hThread){
  211.        //MessageBox(hdHalfLife,"Couldn't Get Proccess Info...\n\nAntivirus???","Inexinferis FX Series - Karman",0);
  212.        CloseHandle(hThread);
  213.        ExitThread(0);
  214.        return 0;
  215.    }
  216.  
  217.    GetThreadContext(hThread,&Context);
  218.    GetThreadSelectorEntry(hThread, Context.SegFs, &SelEntry);
  219.    dwFSBase = (PBYTE)((SelEntry.HighWord.Bits.BaseHi<<24)|(SelEntry.HighWord.Bits.BaseMid<<16)|SelEntry.BaseLow);
  220.  
  221.    if(!dwFSBase||IsBadReadPtr((PVOID)dwFSBase,sizeof(DWORD))){
  222.        //MessageBox(hdHalfLife,"Couldn't Get TEB From Opengl32.dll\n\nMake Sure that you are Running the Game in OpenGl Mode...","Inexinferis FX Series - Karman",0);
  223.        CloseHandle(hThread);
  224.        ExitThread(0);
  225.        return 0;
  226.    }
  227.  
  228.    dwOGLOffset=((DWORD)hModule)+dwTLSIndex;
  229.    if(!dwTLSIndex||IsBadReadPtr((PVOID)dwOGLOffset,sizeof(DWORD))){
  230.        //MessageBox(hdHalfLife,"Couldn't Read From Opengl32.dll Address\n\nMaybe your OpenGL driver is not compatible...","Inexinferis FX Series - Karman",0);
  231.       CloseHandle(hThread);
  232.       ExitThread(0);
  233.       return 0;
  234.    }
  235.    //multiple redirect...
  236.    do{
  237.           Sleep(10);
  238.           dwFSBase2=(PBYTE)(*(PDWORD)((DWORD)dwFSBase+(*(PDWORD)dwOGLOffset)));
  239.    }while(dwFSBase2==NULL);
  240.  
  241. /*
  242.    dwFSBase2=(PBYTE)(*(PDWORD)((DWORD)dwFSBase+(*(PDWORD)0x5F1CC80C)));
  243.    if(!dwFSBase2){
  244.        CloseHandle(hThread);
  245.        ExitThread(0);
  246.        return 0;
  247.    }*/
  248.  
  249.  
  250.  
  251.  
  252.   //MessageBox(hdHalfLife,"http://www.inexinferis.com.ar/foro","Inexinferis FX Series - Karman",0);
  253.   SuspendThread(hThread);
  254.  
  255.   ////////
  256.   // Hooks
  257.  
  258.   // 0x01D46862  opengl32.glClear [EAX+32C] -> 0x69609A20 [12]
  259.   pglClear= (glClear_t)Detour1((PBYTE)(*(PDWORD)(dwFSBase2+0x32C)),(PBYTE)New_glClear,12);
  260.  
  261.   // 0x01D3CF1D  opengl32.glVertex2f [EAX+92C] -> 0x69606320 [12]
  262.   pglVertex2f= (glVertex2f_t)Detour1((PBYTE)(*(PDWORD)(dwFSBase+0x92C)),(PBYTE)New_glVertex2f,12);
  263.  
  264.   pglVertex3f= (glVertex3f_t)Detour1((PBYTE)(*(PDWORD)(dwFSBase+0x94C)),(PBYTE)New_glVertex3f,12);
  265.  
  266.   // 0x01D936C5 opengl32.glVertex3fv [EAX+950] -> 0x696073F0 [12]
  267.   pglVertex3fv= (glVertex3fv_t)Detour1((PBYTE)(*(PDWORD)(dwFSBase+0x950)),(PBYTE)New_glVertex3fv,12);
  268.  
  269.   // 0x01D93681 opengl32.glBegin [EAX+7CC] -> 0x695FD250 [8]
  270.   pglBegin= (glBegin_t)Detour1((PBYTE)(*(PDWORD)(dwFSBase+0x7CC)),(PBYTE)New_glBegin, 8);
  271.  
  272.    ////////
  273.  
  274.    ResumeThread(hThread);
  275.    CloseHandle(hThread);
  276.  
  277.    ExitThread(0);
  278.    return 0;
  279. }
  280.  
  281. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  282.  
  283. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved){
  284.  
  285. if(fdwReason==DLL_PROCESS_ATTACH){
  286.  
  287. DisableThreadLibraryCalls(hInstance);
  288. hThread=CreateThread(NULL,0,Thread,NULL,0,NULL);
  289. }
  290. return (TRUE);
  291. }
  292.  
  293. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  294.  
  295.  

PROYECTO MS Visual C++ 2010 Express
http://www.mediafire.com/?yttdt8712ymvj2r
45  Programación / Programación C/C++ / Interceptar Opengl32 con Detours y obtener un WH en: 9 Abril 2013, 19:29 pm
Para terminar de redondear el tema de interceptar Opengl32 usando detours, muestro una pequeña base para crear un WH, utiliza una función personalizada para instalar un hook del tipo DETOUR.
Habíamos visto en otros tutoriales como se hace, y que se trata de una técnica intrusiva porque requiere parchear la memoria (código) del proceso víctima.
http://foro.elhacker.net/programacion_cc/detours-t168884.0.html
No tiene nada que ver con otros tutoriales que muestran como se modifican los valores de algunos punteros que corresponden a datos en el proceso.
Ej: http://foro.elhacker.net/programacion_cc/codigo_fuente_cheat_cs_16-t387341.0.html

Dejo el código funcional y el proyecto para descargar como siempre, dejo unas imágenes..

En este caso para diferenciarnos de otros tutoriales, explico la forma en que se puede cargar esta DLL en el proceso "hl.exe" que corresponde al juego Counter-Strike.

Se trata de ir a la carpeta del juego, y buscar una DLL de las que sabemos que no son necesarias en el juego pero de todas formas son cargadas al proceso.
Hay otras DLLs que son cargadas y algunas de sus funciones o todas, son utilizadas en el proceso, por lo que no se puede quitarlas, sino más bien hacer un 'wrapper' de ellas. Pero no quitarlas.

Vamos a ver una DLL que si la podemos quitar que se llama "DemoPlayer.dll". Vamos a quitarla y poner nuestra DLL con el WH en su lugar. Obviamente la tenemos que renombrar a "demoplayer.DLL" si es que no tiene ese nombre toda via.





Al final quiero decir que los sistemas de seguridad suelen escanear en la memoria, por ejemplo los primeros 5 bytes de algunas funciones para determinar si tienen 'detours'.
Pero a veces hacen otras comprobaciones como CRC32 de toda una función, o quien sabe que otras comprobaciones.. el tema es que este es un método intrusivo.

Código
  1.  
  2. //
  3. // Modifications: By 85
  4. // Credits: gamedeception (detour function), SharkBoy999 base
  5. // elhacker.net
  6. // etalking.com.ar
  7. // david_bs@live.com
  8. // 2013
  9. //
  10.  
  11. ///////////////////////////////////////////////////////////////////////////////////////
  12.  
  13. #pragma comment(lib,"OpenGL32.lib")
  14. #include <windows.h>
  15. #include <gl/gl.h>
  16. #include <tlhelp32.h>
  17. #include<stdio.h>
  18.  
  19. ///////////////////////////////////////////////////////////////////////////////////////
  20.  
  21. #define wallhack_key     GetAsyncKeyState(VK_NUMPAD1) &1
  22. #define lambert_key GetAsyncKeyState(VK_NUMPAD2) &1
  23. #define nosmoke_key GetAsyncKeyState(VK_NUMPAD3) &1
  24. #define noflash_key GetAsyncKeyState(VK_NUMPAD4) &1
  25.  
  26. bool wallhack = true;
  27. bool lambert = true;
  28. bool nosmoke = true;
  29. bool noflash = true;
  30.  
  31. bool bDrawingSmoke = false;
  32. bool bDrawingFlash = false;
  33.  
  34. ///////////////////////////////////////////////////////////////////////////////////////
  35.  
  36. typedef FARPROC (APIENTRY* GetProcAddress_t)(HMODULE, LPCSTR);
  37. typedef void (APIENTRY* glBegin_t)(GLenum mode);
  38. typedef void (APIENTRY* glViewport_t)(GLint x, GLint y, GLsizei width, GLsizei height);
  39. typedef void (APIENTRY* glVertex3fv_t)(const GLfloat* v);
  40. typedef void (APIENTRY* glVertex2f_t)(GLfloat,GLfloat);
  41.  
  42. ///////////////////////////////////////////////////////////////////////////////////////
  43.  
  44. GetProcAddress_t pGetProcAddress = 0;
  45. glBegin_t pglBegin;
  46. glViewport_t pglViewport;
  47. glVertex3fv_t pglVertex3fv;
  48. glVertex2f_t pglVertex2f;
  49.  
  50. ///////////////////////////////////////////////////////////////////////////////////////
  51.  
  52. void toggle(bool var)
  53. {
  54.    var = !var;
  55. }
  56.  
  57. ///////////////////////////////////////////////////////////////////////////////////////
  58.  
  59. void* Detour1(BYTE* src, const BYTE* dst, const int len)
  60. {
  61. BYTE* jmp = (BYTE*)malloc(len+5);
  62. DWORD dwback;
  63. while(!VirtualProtect(src, len, PAGE_READWRITE, &dwback));
  64. memcpy(jmp, src, len);jmp+=len;
  65. jmp[0] = 0xE9;
  66. *(DWORD*)(jmp+1)=(DWORD)(src+len-jmp)-5;
  67. src[0] = 0xE9;
  68. *(DWORD*)(src+1)=(DWORD)(dst-src)-5;
  69. while(!VirtualProtect(src, len, dwback, &dwback));
  70. return (jmp-len);
  71. }
  72.  
  73. ///////////////////////////////////////////////////////////////////////////////////////
  74.  
  75. FARPROC APIENTRY new_GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
  76. {
  77. //FARPROC fpResult = (*pGetProcAddress)(hModule, lpProcName);
  78. FARPROC fpResult = pGetProcAddress(hModule, lpProcName);
  79. if(HIWORD(lpProcName))
  80. {
  81. if(!lstrcmp(lpProcName,"GetProcAddress"))
  82. return((FARPROC)&new_GetProcAddress);
  83. }
  84. return fpResult;
  85. }
  86.  
  87. ///////////////////////////////////////////////////////////////////////////////////////
  88.  
  89. void APIENTRY new_glBegin(GLenum mode)
  90. {
  91. if(wallhack)
  92. {
  93. if(mode == GL_TRIANGLE_STRIP || mode == GL_TRIANGLE_FAN)
  94. glDepthRange( 0, 0.5 );
  95. else
  96. glDepthRange( 0.5, 1 );
  97. }
  98.  
  99. if(lambert)
  100. {
  101. if(mode == GL_TRIANGLE_STRIP || mode == GL_TRIANGLE_FAN)
  102. glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
  103. }
  104.  
  105. if(nosmoke)
  106. {
  107. if(mode==GL_QUADS)
  108. {
  109. GLfloat curcol[4];
  110. glGetFloatv(GL_CURRENT_COLOR, curcol);
  111. if(mode==GL_QUADS
  112. && (curcol[0]==curcol[1])
  113. && (curcol[0]==curcol[2])
  114. && (curcol[0]!=0.0)
  115. && (curcol[0]!=1.0))
  116. {
  117. bDrawingSmoke = true;
  118. }
  119. else
  120. bDrawingSmoke = false;
  121. }
  122. }
  123.  
  124. if(noflash)
  125. {
  126. GLfloat color[4];
  127. glGetFloatv(GL_CURRENT_COLOR, color);
  128. if(mode == GL_QUADS && (color[0]==1 && color[1]==1 && color[2]==1) )
  129. {
  130. bDrawingFlash = true;
  131. }
  132. else
  133. bDrawingFlash = false;
  134. }
  135. pglBegin(mode);
  136. }
  137.  
  138. ///////////////////////////////////////////////////////////////////////////////////////
  139.  
  140. void APIENTRY new_glViewport(GLint x, GLint y, GLsizei w, GLsizei h)
  141. {
  142. if(wallhack_key)
  143. toggle(wallhack);
  144. if(lambert_key)
  145. toggle(lambert);
  146. if(nosmoke_key)
  147. toggle(nosmoke);
  148. if(noflash_key)
  149. toggle(noflash);
  150. pglViewport(x,y,w,h);
  151. }
  152.  
  153. ///////////////////////////////////////////////////////////////////////////////////////
  154.  
  155. void APIENTRY new_glVertex3fv(const GLfloat* v)
  156. {
  157. if(bDrawingSmoke)
  158. return;
  159.  
  160. pglVertex3fv(v);
  161. }
  162.  
  163. ///////////////////////////////////////////////////////////////////////////////////////
  164.  
  165. void APIENTRY new_glVertex2f(GLfloat x,GLfloat y)
  166. {
  167. /* if (bDrawingFlash)
  168. {
  169. GLfloat color[4];
  170. glGetFloatv(GL_CURRENT_COLOR, color);
  171. //color[0]=0, color[1]=0, color[2]=0;
  172. glDisable(GL_TEXTURE_2D);
  173. glColor4f(color[0], color[1], color[2], 0.01f);
  174. }*/
  175. pglVertex2f(x,y);
  176. }
  177.  
  178. ///////////////////////////////////////////////////////////////////////////////////////
  179.  
  180. void Hook(void)
  181. {
  182. pglBegin =        (glBegin_t)       Detour1((LPBYTE)glBegin,       (LPBYTE)new_glBegin, 6);
  183. pglViewport =     (glViewport_t)    Detour1((LPBYTE)glViewport,    (LPBYTE)new_glViewport, 7);
  184. pglVertex3fv =    (glVertex3fv_t)   Detour1((LPBYTE)glVertex3fv,   (LPBYTE)new_glVertex3fv, 6);
  185. pglVertex2f =     (glVertex2f_t)    Detour1((LPBYTE)glVertex2f,    (LPBYTE)new_glVertex2f, 6);
  186. }
  187.  
  188. ///////////////////////////////////////////////////////////////////////////////////////
  189.  
  190. bool APIENTRY DllMain(HANDLE hModule, DWORD  dwReason, LPVOID lpReserved)
  191. {
  192. if(dwReason == DLL_PROCESS_ATTACH)
  193. {
  194. // No es necesario este Detour para la demostración..
  195. pGetProcAddress = (GetProcAddress_t)Detour1((LPBYTE)GetProcAddress,
  196. (LPBYTE)new_GetProcAddress, 5);
  197.  
  198. if(GetModuleHandle("Opengl32.dll"))
  199. Hook();
  200. }
  201. else if(dwReason == DLL_PROCESS_DETACH)
  202. {
  203. // Restaurar bytes en GPA
  204.  
  205. // (no hace falta suspender el mismo hilo! no sirve para nada XD)
  206.  
  207. // Salida con retardo.
  208. // Permite que se ejecuten los últimos llamados a GPA
  209. // (Y no hace falta restaurar los bytes parcheados XD)
  210. ExitProcess(100);
  211. }
  212. return (true);
  213. }
  214.  
  215. ///////////////////////////////////////////////////////////////////////////////////////
  216.  
  217.  

otra cosa que quiero agregar, es que el 'hook' a GetProcAddress no es necesario, pero está hecho y sirve para demostrar algo importante.

cuando salimos del juego, osea del proceso, antes se descargan las DLLs entre otras cosas, pero cuando se descarga nuestra DLL la memoria del proceso continua parcheada (los hooks que instalamos), y las referencias a los hooks son inválidas ya que la DLL se ha descargado.

Esto no importa para Opengl32 porque nadie va a utilizar Opengl32 al salir, pero con GetProcAddress si pasa esto. Por eso se debería considerar restaurar los bytes parcheados en GetProcAddress, o más fácil es hacer que la DLL se descargue cuando ya no sea necesaria (cuando no se haga más referencia a los hooks). Con un ExitProcess(100) queda resuelto, en realidad no investigué acerca de este tema, sólo traté de arreglarlo de alguna forma. Pero es un detalle a considerar.

PROYECTO
http://www.mediafire.com/?qfb65fsfgaf5doa

46  Programación / Desarrollo Web / Detener registraciones spam en vBulletin en: 9 Abril 2013, 17:34 pm
By: Shabbir (Go4Expert)
http://www.go4expert.com/articles/st...ration-t29601/

Captcha, reCaptcha as well as Question and Answer does not stop vBulletin Spam registrations and so I have come up with yet another solution to stop vBulletin Spam for Registration. This works with any kind of site and is based on Cookies for Comments Wordpress Plugin.

The idea and implementation is completely based on the plugin and so the credit completely goes to the Authors of the above plugin. I have just used it for vBulletin and shared it here so you can apply the same for your forums. It is very simple and yet so effective that it can be applied to almost any website.

Step 1
Download the above plugin and extract into a folder. Upload css.php file to your forum root directory. Browse to the css.php file in your browser and copy the link to the css.php file.

Step 2
Now add the following lines to your headinclude template in each of your vBulletin style.

Código:
<link rel="stylesheet" type="text/css" href="LINK_TO_FILE UPLOADED_IN_STEP1?k=SOME_RANDOM_STRING_OF_YOUR_CHOICE" />

Replace the SOME_RANDOM_STRING_OF_YOUR_CHOICE with anything of your choice.

If you don't want to add stylesheet declaration in your template, you can also opt for blank image. For this you have to upload the blank.gif image from the above plugin to your site and then add the following blank image code in header or footer template of each of your vBulletin style.

Código:
<img src="LINK_TO_FILE UPLOADED_IN_STEP1?k=SOME_RANDOM_STRING_OF_YOUR_CHOICE&o=img" width="0" height="0" border="0" style="display:none;" />

Step 3
Now Add the following into your .htaccess file.

Código:
RewriteCond %{HTTP_COOKIE} !^.*SOME_RANDOM_STRING_OF_YOUR_CHOICE.*$
RewriteRule ^register.php - [F,L]

Remember the above rules goes right at the top. Even above the vBSEO Rules if any.

Now any user visiting your register.php file without visiting any of your pages on your forum will get a 403 forbidden error message.

There can be issues if you have multiple CMSes like may be Wordpress and vBulletin or any other static pages and genuine users can click on registration link from those pages. The solution is to make the call to the above CSS/image file from every page of your site.

I hope it helps reduce the spam registration considerably.

The above solution can even be applied to any other custom CMS of your choice as well. You have to just block your registration pages with the needed cookie and set the cookies in header or footer of your site for genuine users who visit your site.

Further Spam Prevention Options for vBulletin
You can also opt for some more spam prevention options that I have mentioned on my blog here as well as opt for a Block vBulletin Spam Posts Plugin to stop spam posts in forums.

NOTA: Si está en inglés, pueden usar el traductor de google XD
http://translate.google.com.ar/

Pero si esto funciona como dice, es super importante para los que tienen vBulletin por el gran problema de los bots :/
Supuestamente sirve para cualquier sitio.
47  Programación / Programación C/C++ / Re: ¿alguien podria hecharme una mano? en: 8 Abril 2013, 01:21 am
Aunque no entiendas nada tendrías que leer un manual de los básicos, siempre traen ejemplos de código.
Se aprende entrenando, nunk dejes de codificar, aunque sea con ejemplos que te pasen otros o lo que sea..

Estos 2 temas fijate a mi criterio parecen básicos, es decir nada complicado y indicado para un beginner.
http://foro.elhacker.net/programacion_cc/descomponer_en_unidades-t386770.0.html
http://foro.elhacker.net/programacion_cc/clases_de_almacenamiento-t386497.0.html

bucles
FOR = ciclo exacto, osea se conocen la cantidad de ciclos
WHILE = ciclo inexacto, no se conocen la cantidad de ciclos

bloques condicionales
IF
ELSE-IF
ELSE

tipos de datos del lenguaje
tipos de datos personalizados

funciones

me imagino que sabés acerca de la función MAIN, también conocida como punto de entrada del programa.

El manual es necesario, no conozco a nadie que no haya agarrado un manual de C para aprender, ya que del manual no sólo se aprende el lenguaje en sí, sino acerca de las especificaciones técnicas (Se conoce como standard).

48  Programación / Programación C/C++ / Re: Codigo Fuente, Cheat Cs 1.6 en: 8 Abril 2013, 01:04 am
Nop, Ring0 ak no tiene nada que ver. Vos sabés que para ejecutar código en modo Ring0 se requiere un driver, y las librerías son otras que las de modo Ring3 (usuario). Es decir es otro tema XD, se requiere una DDK para compilar drivers, es otro tema

Todo esto es desde Ring3. Pero si te interesa saber si se puede hacer desde Ring0, la respuesta es si, todo o casi todo se puede hacer desde ese nivel.
Sólo que es otra programación (otras librerías).

Andá escalando XD, ya sabés lo que es parchear el juego, sabés lo que es un 'wrapper' de DLL, sabés acerca de usar 'Detours' que también es parchear.
Y también deberías saber acerca de EAT y IAT debido a los múltiples temas que se han publicado al respecto. Por ejemplo el link de mr.blood
49  Programación / Programación C/C++ / MS Detours 2.1 para interceptar Opengl32 en: 8 Abril 2013, 00:34 am
http://research.microsoft.com/en-us/projects/detours/
Citar
Overview
Innovative systems research hinges on the ability to easily instrument and extend existing operating system and application functionality. With access to appropriate source code, it is often trivial to insert new instrumentation or extensions by rebuilding the OS or application. However, in today's world systems researchers seldom have access to all relevant source code.

Detours is a library for instrumenting arbitrary Win32 functions Windows-compatible processors. Detours intercepts Win32 functions by re-writing the in-memory code for target functions. The Detours package also contains utilities to attach arbitrary DLLs and data segments (called payloads) to any Win32 binary.

Detours preserves the un-instrumented target function (callable through a trampoline) as a subroutine for use by the instrumentation. Our trampoline design enables a large class of innovative extensions to existing binary software.

We have used Detours to create an automatic distributed partitioning system, to instrument and analyze the DCOM protocol stack, and to create a thunking layer for a COM-based OS API. Detours is used widely within Microsoft and within the industry.

Bueno, la intención no es contar toda la historia sino publicar un código fuente XD.

En síntesis, con esta librería se pueden interceptar funciones. Es una librería de MS que no es pública en su versión completa, pero si tiene una versión de prueba para el público.
Se usaba desde hace años para construir los hacks de distintos juegos, por ejemplo para el Counter-Strike.
En este enlace se puede encontrar una base para un hook de Opengl32 que fue muy conocida cuando salió.
http://board.cheat-project.com/showthread.php?t=9232

Algunas de estas bases se hicieron primero con Detours 1.5 y después se actualizaron a Detours 2.1. Ahora está disponible la versión pública de Detours 3.0.

Lo que hice yo, fue organizar la base publicada en ese enlace que he mostrado. originalmente no compilaba, tenía errores, faltaban archivos, y tenía mucho código que no era necesario para una simple demostración.
Por eso el código fue organizado y arreglado para que funcione, el proyecto es de una librería de vínculos dinámicos (DLL), que debe ser cargada en el juego Counter-Strike (En modo Opengl32).
Al cargarse la DLL se instalan los hooks ('detours'), y se obtiene un "Wallhack" funcionando.

El creador de esta base es un tal Xantrax, el link ya lo he mostrado.
Esto se trata de ver como se implementa esta librería.
Dejo el código completo y al final un enlace de descarga.
La descarga fue preparada especialmente, porque incluye los archivos de instalación de Detours 2.1, el .h y la librería estática .lib.
Y se incluye también el .h y la librería estática .lib correspondiente a Detours 1.5.
El tema es que estos archivos no se consiguen fácilmente porque son versiones anteriores de 'Detours'.
Otra cosa es que para obtener la librería estática .lib se tiene que compilar 'Detours' para que la produzca.

Código
  1.  
  2. //
  3. // Modifications: By 85
  4. // Credits: Xantrax, MS Detours 2.1
  5. // elhacker.net
  6. // etalking.com.ar
  7. // david_bs@live.com
  8. // 2013
  9. //
  10.  
  11. ///////////////////////////////////////////////////////////////////////////////////////
  12.  
  13. #pragma comment(lib,"detours.lib")// 1.5
  14. #pragma comment(lib,"OpenGL32.lib")
  15. #include <windows.h>
  16. #include <gl/gl.h>
  17. #include<stdio.h>
  18.  
  19. #include "detours.h"
  20.  
  21. ///////////////////////////////////////////////////////////////////////////////////////
  22.  
  23. bool bOGLSubtractive = false;
  24. bool g_bSky = false;
  25.  
  26. ///////////////////////////////////////////////////////////////////////////////////////
  27.  
  28. class CDraw {
  29. public:
  30. CDraw();
  31. int m_iVpCounter;
  32. bool m_bDrawing;
  33. void DrawPanel();
  34. };
  35.  
  36. CDraw::CDraw( ){
  37. m_iVpCounter = 0;
  38. m_bDrawing = false;
  39. }
  40.  
  41. void CDraw::DrawPanel( ) {
  42.  
  43. //Drawing Every 5th here
  44. }
  45.  
  46. CDraw* pDraw = new CDraw();
  47.  
  48. ///////////////////////////////////////////////////////////////////////////////////////
  49.  
  50. /* function prototype and original target */
  51.  
  52. DETOUR_TRAMPOLINE( VOID WINAPI Trampoline_glBegin( GLenum mode ), glBegin );
  53. DETOUR_TRAMPOLINE( VOID WINAPI Trampoline_glViewport( GLint x,  GLint y,  GLsizei width,  GLsizei height ), glViewport );
  54. DETOUR_TRAMPOLINE( VOID WINAPI Trampoline_glVertex3fv( const GLfloat *v ), glVertex3fv  );
  55. DETOUR_TRAMPOLINE( VOID WINAPI Trampoline_glVertex3f( GLfloat x, GLfloat y, GLfloat z ), glVertex3f );
  56. DETOUR_TRAMPOLINE( VOID WINAPI Trampoline_glShadeModel( GLenum mode ), glShadeModel );
  57. DETOUR_TRAMPOLINE( VOID WINAPI Trampoline_glClear( GLbitfield mask ), glClear );
  58. DETOUR_TRAMPOLINE( VOID WINAPI Trampoline_glColor3f( GLfloat red, GLfloat green, GLfloat blue ), glColor3f );
  59. typedef void (WINAPI* wglSwapBuffers_t)(HDC);
  60.  
  61. ///////////////////////////////////////////////////////////////////////////////////////
  62.  
  63. //#define HIWORD(l)           ((WORD)((DWORD_PTR)(l) >> 16))
  64.  
  65. DETOUR_TRAMPOLINE(FARPROC WINAPI Trampoline_GetProcAddress(HMODULE hModule,
  66.  LPCSTR lpProcName), GetProcAddress);
  67.  
  68. ///////////////////////////////////////////////////////////////////////////////////////
  69.  
  70. VOID WINAPI glBeginDetour(GLenum mode)
  71. {
  72. if(mode == GL_TRIANGLE_STRIP || mode == GL_TRIANGLE_FAN)
  73. glDepthRange( 0, 0.5 );
  74. else
  75. glDepthRange( 0.5, 1 );
  76.  
  77. if(mode == GL_TRIANGLE_STRIP || mode == GL_TRIANGLE_FAN)
  78. glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
  79.  
  80. if( mode == GL_QUADS )
  81. g_bSky = true;
  82. else
  83. g_bSky = false;
  84.  
  85. Trampoline_glBegin(mode);
  86. }
  87.  
  88. ///////////////////////////////////////////////////////////////////////////////////////
  89.  
  90. VOID WINAPI glClearDetour(GLbitfield mask)
  91. {
  92. if(mask==GL_DEPTH_BUFFER_BIT)
  93. {
  94. mask+=GL_COLOR_BUFFER_BIT;
  95. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  96.  
  97. Trampoline_glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
  98. return;
  99. }
  100.  
  101. Trampoline_glClear(mask);
  102. }
  103.  
  104. ///////////////////////////////////////////////////////////////////////////////////////
  105.  
  106. VOID WINAPI glShadeModelDetour(GLenum mode)
  107. {
  108. //XQZ2 wallhack
  109. if( mode == GL_SMOOTH ){
  110. __asm {
  111. push 0x00000100 //GL_DEPTH_BUFFER_BIT
  112. call dword ptr[ Trampoline_glClear ]
  113. }
  114. }
  115.  
  116. Trampoline_glShadeModel(mode);
  117. }
  118.  
  119. ///////////////////////////////////////////////////////////////////////////////////////
  120.  
  121. VOID WINAPI glViewportDetour(GLint x, GLint y, GLsizei width, GLsizei height)
  122. {
  123. pDraw->m_iVpCounter++;
  124. if( pDraw->m_iVpCounter >= 5 ){
  125. pDraw->m_bDrawing = true;
  126. }
  127. Trampoline_glViewport(x, y, width, height);
  128. }
  129.  
  130. ///////////////////////////////////////////////////////////////////////////////////////
  131.  
  132. VOID WINAPI glColor3fDetour(GLfloat red, GLfloat green, GLfloat blue)
  133. {
  134. Trampoline_glColor3f(red, green, blue);
  135. }
  136.  
  137. ///////////////////////////////////////////////////////////////////////////////////////
  138.  
  139. VOID WINAPI glVertex3fvDetour(const GLfloat* v)
  140. {
  141. if(g_bSky && v[2]>300){
  142.  
  143. return;
  144. /*float flZero = 0.0f;
  145. __asm {
  146. push flZero
  147. push flZero
  148. push flZero
  149. call dword ptr[ Trampoline_glColor3f ]
  150. }*/
  151. }
  152. Trampoline_glVertex3fv(v);
  153. }
  154.  
  155. ///////////////////////////////////////////////////////////////////////////////////////
  156.  
  157. VOID WINAPI glVertex3fDetour(GLfloat x, GLfloat y, GLfloat z)
  158. {
  159. Trampoline_glVertex3f(x, y, z);
  160. }
  161.  
  162. ///////////////////////////////////////////////////////////////////////////////////////
  163.  
  164. wglSwapBuffers_t pwglSwapBuffers = NULL;
  165. // DETOUR_TRAMPOLINE(void WINAPI _wglSwapBuffers(HDC hDC), wglSwapBuffers);
  166. // since wglSwapBuffers is undefined, the macro wont work. this is, what it basically does:
  167. static PVOID __fastcall _Detours_GetVA_wglSwapBuffers(VOID)
  168. {
  169.    return pwglSwapBuffers;
  170. }
  171.  
  172. ///////////////////////////////////////////////////////////////////////////////////////
  173.  
  174. __declspec(naked) void WINAPI _Trampoline_wglSwapBuffers(HDC hDC)
  175. {
  176.    __asm { nop };
  177.    __asm { nop };
  178.    __asm { call _Detours_GetVA_wglSwapBuffers };
  179.    __asm { jmp eax };
  180.    __asm { ret };
  181.    __asm { nop };
  182.    __asm { nop };
  183.    __asm { nop };
  184.    __asm { nop };
  185.    __asm { nop };
  186.    __asm { nop };
  187.    __asm { nop };
  188.    __asm { nop };
  189.    __asm { nop };
  190.    __asm { nop };
  191.    __asm { nop };
  192.    __asm { nop };
  193.    __asm { nop };
  194.    __asm { nop };
  195.    __asm { nop };
  196.    __asm { nop };
  197.    __asm { nop };
  198.    __asm { nop };
  199.    __asm { nop };
  200.    __asm { nop };
  201.    __asm { nop };
  202.    __asm { nop };
  203. }
  204.  
  205. ///////////////////////////////////////////////////////////////////////////////////////
  206.  
  207. VOID WINAPI _wglSwapBuffers(HDC hDC)
  208. {
  209. pDraw->m_iVpCounter = 0;
  210. _Trampoline_wglSwapBuffers( hDC );
  211. }
  212.  
  213. ///////////////////////////////////////////////////////////////////////////////////////
  214.  
  215. void DetourOpenGL()
  216. {
  217. #define Detour( pbTrampFunc, pbDetourFunc )\
  218. DetourFunctionWithTrampoline( (PBYTE)##pbTrampFunc,( PBYTE )##pbDetourFunc )
  219.  
  220. Detour( Trampoline_glBegin, glBeginDetour );
  221. Detour( Trampoline_glVertex3fv, glVertex3fvDetour );
  222. Detour( Trampoline_glClear, glClearDetour );
  223. /*
  224. Detour( Trampoline_glShadeModel, glShadeModelDetour );
  225. Detour( Trampoline_glViewport, glViewportDetour );
  226. Detour( Trampoline_glVertex3f, glVertex3fDetour );
  227.  
  228. // Because wglSwapBuffers isnt declared in GL\GL.h...
  229. pwglSwapBuffers = (wglSwapBuffers_t)GetProcAddress(LoadLibrary("opengl32.dll"),
  230. "wglSwapBuffers");
  231. Detour( _Trampoline_wglSwapBuffers, _wglSwapBuffers);
  232.  
  233. Detour( Trampoline_glColor3f, glColor3fDetour );*/
  234. }
  235.  
  236. ///////////////////////////////////////////////////////////////////////////////////////
  237.  
  238. void RemoveOpenGLDetour()
  239. {
  240. #define Destroy( pbTrampFunc, pbDetourFunc )\
  241. DetourRemove( (PBYTE)##pbTrampFunc,( PBYTE )##pbDetourFunc )
  242.  
  243. Destroy( Trampoline_glBegin, glBeginDetour );
  244. Destroy( Trampoline_glVertex3fv, glVertex3fvDetour );
  245. Destroy( Trampoline_glClear, glClearDetour );
  246. /*
  247. Destroy( Trampoline_glShadeModel, glShadeModelDetour );
  248. Destroy( Trampoline_glViewport, glViewportDetour );
  249. Destroy( Trampoline_glVertex3f, glVertex3fDetour );
  250.  
  251. Destroy( Trampoline_glColor3f, glColor3fDetour );*/
  252. }
  253.  
  254. ///////////////////////////////////////////////////////////////////////////////////////
  255.  
  256. FARPROC WINAPI GetProcAddressDetour(HMODULE hModule, LPCSTR lpProcName)
  257. {
  258. FARPROC retval = Trampoline_GetProcAddress(hModule, lpProcName);
  259. return retval;
  260. }
  261.  
  262. ///////////////////////////////////////////////////////////////////////////////////////
  263.  
  264. BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  265. {
  266. switch(ul_reason_for_call)
  267. {
  268. case DLL_PROCESS_ATTACH://Let the magic happen...:->
  269. DetourOpenGL();
  270. //Extras
  271. /* DetourFunctionWithTrampoline((PBYTE)Trampoline_GetProcAddress,
  272. (PBYTE)GetProcAddressDetour);*/
  273. break;
  274. case DLL_PROCESS_DETACH:
  275. RemoveOpenGLDetour();
  276. break;
  277. }
  278.    return TRUE;
  279. }
  280.  
  281. ///////////////////////////////////////////////////////////////////////////////////////
  282.  

PROJECT VCPP6
http://www.mediafire.com/?tl9qprjaytk77v7

50  Programación / Programación C/C++ / Re: AYUDA Hookear Función en: 7 Abril 2013, 23:55 pm
para trabajar directamente con la memoria son necesarios, a menos que te manejes con las direcciones de las variables o de las funciones directamente, o utilices "pseudopunteros" o typecasting de variables de tipo DWORD por ejemplo que guarden direcciones de memoria. Es decir, la idea es usar punteros si.
Claro en un sistema x32 con JMP+ADDRESS son 5 bytes, 1 del JMP y 4 de la ADDRESS.

Te recomiendo que desensambles algunos programas muy simples en C para examinar el código ASM, al menos para ver de que se trata. No es necesario saber programar en ASM para observar algunos conceptos.

Bajate algún desensamblador o sino utilizando un depurador, El tema es que veas los bytes en la memoria, que corresponden a tu programa.
Páginas: 1 2 3 4 [5] 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines