Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Borito30 en 14 Marzo 2017, 14:21 pm



Título: Como resolver estos errores?
Publicado por: Borito30 en 14 Marzo 2017, 14:21 pm
Estoy intentando compilar ejemplos de esta libreria:
Código:
https://www.codeproject.com/KB/winsdk/LibMinHook/MinHook_133_src.zip

El tio compila ejemplos de todos pero cuando yo lo intento me devuelve:
Código:
C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h:141:
22: note:   candidate expects 5 arguments, 4 provided
DynamicLinkSample.cpp:12:18: note: template<class T> MH_STATUS MH_CreateHookApiE
x(LPCWSTR, LPCSTR, LPVOID, T**)
 inline MH_STATUS MH_CreateHookApiEx(LPCWSTR pszModule, LPCSTR pszProcName, LPVO
ID pDetour, T** ppOriginal)
                  ^
DynamicLinkSample.cpp:12:18: note:   template argument deduction/substitution fa
iled:
DynamicLinkSample.cpp:37:88: note:   cannot convert 'DetourMessageBoxW' (type 'i
nt (__attribute__((__stdcall__)) *)(HWND, LPCWSTR, LPCWSTR, UINT) {aka int (__at
tribute__((__stdcall__)) *)(HWND__*, const wchar_t*, const wchar_t*, unsigned in
t)}') to type 'LPVOID {aka void*}'
     if (MH_CreateHookApiEx(L"user32", "MessageBoxW", &DetourMessageBoxW, &fpMes
sageBoxW) != MH_OK)

        ^
DynamicLinkSample.cpp:43:35: error: invalid conversion from 'int (__attribute__(
(__stdcall__)) *)(HWND, LPCWSTR, LPCWSTR, UINT) {aka int (__attribute__((__stdca
ll__)) *)(HWND__*, const wchar_t*, const wchar_t*, unsigned int)}' to 'LPVOID {a
ka void*}' [-fpermissive]
     if (MH_EnableHook(&MessageBoxW) != MH_OK)
                                   ^
In file included from DynamicLinkSample.cpp:2:0:
C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h:154:
22: note: initializing argument 1 of 'MH_STATUS MH_EnableHook(LPVOID)'
     MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget);
                      ^
DynamicLinkSample.cpp:52:36: error: invalid conversion from 'int (__attribute__(
(__stdcall__)) *)(HWND, LPCWSTR, LPCWSTR, UINT) {aka int (__attribute__((__stdca
ll__)) *)(HWND__*, const wchar_t*, const wchar_t*, unsigned int)}' to 'LPVOID {a
ka void*}' [-fpermissive]
     if (MH_DisableHook(&MessageBoxW) != MH_OK)
                                    ^
In file included from DynamicLinkSample.cpp:2:0:
C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h:161:
22: note: initializing argument 1 of 'MH_STATUS MH_DisableHook(LPVOID)'
     MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget);
                      ^

Supongo algo estare haciendo mal. En este caso estoy intentando desde consola con g++, que el compilador sería mingw.


Título: Re: Como resolver estos errores?
Publicado por: ivancea96 en 14 Marzo 2017, 14:58 pm
Esa librería sera de C (los errores son errores de conversión de un puntero a función a un void*, cosa que en C se podía hacer de forma implícita). O modificas las funciones añadiendo casts a void*, o:
https://www.codeproject.com/Articles/44326/MinHook-The-Minimalistic-x-x-API-Hooking-Libra (https://www.codeproject.com/Articles/44326/MinHook-The-Minimalistic-x-x-API-Hooking-Libra)
Hay una parte que pone: If you are a C++ user, ...


Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 14 Marzo 2017, 15:07 pm
Esa librería sera de C (los errores son errores de conversión de un puntero a función a un void*, cosa que en C se podía hacer de forma implícita). O modificas las funciones añadiendo casts a void*, o:
https://www.codeproject.com/Articles/44326/MinHook-The-Minimalistic-x-x-API-Hooking-Libra (https://www.codeproject.com/Articles/44326/MinHook-The-Minimalistic-x-x-API-Hooking-Libra)
Hay una parte que pone: If you are a C++ user, ...
Primero tengo unas dudas cuando dices librería te refieres a cabecera? también se le puede llamar libreria a un .h por ejemplo? Segundo :
Citar
los errores son errores de conversión de un puntero a función a un void*, cosa que en C se podía hacer de forma implícita). O modificas las funciones añadiendo casts a void*

Cuando dices añadir casts a void* te refieres que en la libreria/cabecera minhook.h debó incluirle el * de puntero?

En cuanto a esto:
Citar
If you are a C++ user, ...

Lo intente cambiando la parte de arriba y de abajo y dejando el main tal como estaba pero al compilarlo seguia devolviendo error.



Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 14 Marzo 2017, 15:14 pm
La librería es la siguiente:
Código
  1. #pragma once
  2.  
  3. #if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__)
  4.    #error MinHook supports only x86 and x64 systems.
  5. #endif
  6.  
  7. #include <windows.h>
  8.  
  9. // MinHook Error Codes.
  10. typedef enum MH_STATUS
  11. {
  12.    // Unknown error. Should not be returned.
  13.    MH_UNKNOWN = -1,
  14.  
  15.    // Successful.
  16.    MH_OK = 0,
  17.  
  18.    // MinHook is already initialized.
  19.    MH_ERROR_ALREADY_INITIALIZED,
  20.  
  21.    // MinHook is not initialized yet, or already uninitialized.
  22.    MH_ERROR_NOT_INITIALIZED,
  23.  
  24.    // The hook for the specified target function is already created.
  25.    MH_ERROR_ALREADY_CREATED,
  26.  
  27.    // The hook for the specified target function is not created yet.
  28.    MH_ERROR_NOT_CREATED,
  29.  
  30.    // The hook for the specified target function is already enabled.
  31.    MH_ERROR_ENABLED,
  32.  
  33.    // The hook for the specified target function is not enabled yet, or already
  34.    // disabled.
  35.    MH_ERROR_DISABLED,
  36.  
  37.    // The specified pointer is invalid. It points the address of non-allocated
  38.    // and/or non-executable region.
  39.    MH_ERROR_NOT_EXECUTABLE,
  40.  
  41.    // The specified target function cannot be hooked.
  42.    MH_ERROR_UNSUPPORTED_FUNCTION,
  43.  
  44.    // Failed to allocate memory.
  45.    MH_ERROR_MEMORY_ALLOC,
  46.  
  47.    // Failed to change the memory protection.
  48.    MH_ERROR_MEMORY_PROTECT,
  49.  
  50.    // The specified module is not loaded.
  51.    MH_ERROR_MODULE_NOT_FOUND,
  52.  
  53.    // The specified function is not found.
  54.    MH_ERROR_FUNCTION_NOT_FOUND
  55. }
  56. MH_STATUS;
  57.  
  58. // Can be passed as a parameter to MH_EnableHook, MH_DisableHook,
  59. // MH_QueueEnableHook or MH_QueueDisableHook.
  60. #define MH_ALL_HOOKS NULL
  61.  
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65.  
  66.    // Initialize the MinHook library. You must call this function EXACTLY ONCE
  67.    // at the beginning of your program.
  68.    MH_STATUS WINAPI MH_Initialize(VOID);
  69.  
  70.    // Uninitialize the MinHook library. You must call this function EXACTLY
  71.    // ONCE at the end of your program.
  72.    MH_STATUS WINAPI MH_Uninitialize(VOID);
  73.  
  74.    // Creates a Hook for the specified target function, in disabled state.
  75.    // Parameters:
  76.    //   pTarget    [in]  A pointer to the target function, which will be
  77.    //                    overridden by the detour function.
  78.    //   pDetour    [in]  A pointer to the detour function, which will override
  79.    //                    the target function.
  80.    //   ppOriginal [out] A pointer to the trampoline function, which will be
  81.    //                    used to call the original target function.
  82.    //                    This parameter can be NULL.
  83.    MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal);
  84.  
  85.    // Creates a Hook for the specified API function, in disabled state.
  86.    // Parameters:
  87.    //   pszModule  [in]  A pointer to the loaded module name which contains the
  88.    //                    target function.
  89.    //   pszTarget  [in]  A pointer to the target function name, which will be
  90.    //                    overridden by the detour function.
  91.    //   pDetour    [in]  A pointer to the detour function, which will override
  92.    //                    the target function.
  93.    //   ppOriginal [out] A pointer to the trampoline function, which will be
  94.    //                    used to call the original target function.
  95.    //                    This parameter can be NULL.
  96.    MH_STATUS WINAPI MH_CreateHookApi(
  97.        LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal);
  98.  
  99.    // Creates a Hook for the specified API function, in disabled state.
  100.    // Parameters:
  101.    //   pszModule  [in]  A pointer to the loaded module name which contains the
  102.    //                    target function.
  103.    //   pszTarget  [in]  A pointer to the target function name, which will be
  104.    //                    overridden by the detour function.
  105.    //   pDetour    [in]  A pointer to the detour function, which will override
  106.    //                    the target function.
  107.    //   ppOriginal [out] A pointer to the trampoline function, which will be
  108.    //                    used to call the original target function.
  109.    //                    This parameter can be NULL.
  110.    //   ppTarget   [out] A pointer to the target function, which will be used
  111.    //                    with other functions.
  112.    //                    This parameter can be NULL.
  113.    MH_STATUS WINAPI MH_CreateHookApiEx(
  114.        LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal, LPVOID *ppTarget);
  115.  
  116.    // Removes an already created hook.
  117.    // Parameters:
  118.    //   pTarget [in] A pointer to the target function.
  119.    MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget);
  120.  
  121.    // Enables an already created hook.
  122.    // Parameters:
  123.    //   pTarget [in] A pointer to the target function.
  124.    //                If this parameter is MH_ALL_HOOKS, all created hooks are
  125.    //                enabled in one go.
  126.    MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget);
  127.  
  128.    // Disables an already created hook.
  129.    // Parameters:
  130.    //   pTarget [in] A pointer to the target function.
  131.    //                If this parameter is MH_ALL_HOOKS, all created hooks are
  132.    //                disabled in one go.
  133.    MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget);
  134.  
  135.    // Queues to enable an already created hook.
  136.    // Parameters:
  137.    //   pTarget [in] A pointer to the target function.
  138.    //                If this parameter is MH_ALL_HOOKS, all created hooks are
  139.    //                queued to be enabled.
  140.    MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget);
  141.  
  142.    // Queues to disable an already created hook.
  143.    // Parameters:
  144.    //   pTarget [in] A pointer to the target function.
  145.    //                If this parameter is MH_ALL_HOOKS, all created hooks are
  146.    //                queued to be disabled.
  147.    MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget);
  148.  
  149.    // Applies all queued changes in one go.
  150.    MH_STATUS WINAPI MH_ApplyQueued(VOID);
  151.  
  152.    // Translates the MH_STATUS to its name as a string.
  153.    const char * WINAPI MH_StatusToString(MH_STATUS status);
  154.  
  155. #ifdef __cplusplus
  156. }
  157. #endif
  158.  
  159.  

Como podría agregar a las funciones casts a void* digamos dentro de los parametros, ya que necesito hacer la conversión de un puntero a función a un void*.


Título: Re: Como resolver estos errores?
Publicado por: ivancea96 en 14 Marzo 2017, 15:50 pm
Como no sé exactamente cómo está tu proyecto, te pongo un ejemplo:

Código:
DynamicLinkSample.cpp:43:35: error: invalid conversion from 'int (__attribute__(
(__stdcall__)) *)(HWND, LPCWSTR, LPCWSTR, UINT) {aka int (__attribute__((__stdca
ll__)) *)(HWND__*, const wchar_t*, const wchar_t*, unsigned int)}' to 'LPVOID {a
ka void*}' [-fpermissive]
     if (MH_EnableHook(&MessageBoxW) != MH_OK)
                                   ^

Y según has puesto, MH_EnableHook es:
Código
  1. MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget);
&MessageBoxW no es un void*, es un unteor a esa función. Podrías poner:
Código
  1. if (MH_EnableHook((void*)&MessageBoxW) != MH_OK)

Y algunos de los otros errores son más de lo mismo.


Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 14 Marzo 2017, 16:13 pm
El proyecto mio es este:
Código
  1. #include <Windows.h>
  2. #include "C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h"
  3.  
  4. #if defined _M_X64
  5. #pragma comment(lib, "MinHook.x64.lib")
  6. #elif defined _M_IX86
  7. #pragma comment(lib, "MinHook.x86.lib")
  8. #endif
  9.  
  10. // Helper function for MH_CreateHookApi().
  11. template <typename T>
  12. inline MH_STATUS MH_CreateHookApiEx(LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, T** ppOriginal)
  13. {
  14.    return MH_CreateHookApi(pszModule, pszProcName, pDetour, reinterpret_cast<LPVOID*>(ppOriginal));
  15. }
  16.  
  17. typedef int (WINAPI *MESSAGEBOXW)(HWND, LPCWSTR, LPCWSTR, UINT);
  18.  
  19. // Pointer for calling original MessageBoxW.
  20. MESSAGEBOXW fpMessageBoxW = NULL;
  21.  
  22. // Detour function which overrides MessageBoxW.
  23. int WINAPI DetourMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
  24. {
  25.    return fpMessageBoxW(hWnd, L"Hooked!", lpCaption, uType);
  26. }
  27.  
  28. int main()
  29. {
  30.    // Initialize MinHook.
  31.    if (MH_Initialize() != MH_OK)
  32.    {
  33.        return 1;
  34.    }
  35.  
  36.    // Create a hook for MessageBoxW, in disabled state.
  37.    if (MH_CreateHookApiEx(L"user32", "MessageBoxW", &DetourMessageBoxW, &fpMessageBoxW) != MH_OK)
  38.    {
  39.        return 1;
  40.    }
  41.  
  42.    // Enable the hook for MessageBoxW.
  43.    if (MH_EnableHook((void*)&MessageBoxW) != MH_OK)
  44.    {
  45.        return 1;
  46.    }
  47.  
  48.    // Expected to tell "Hooked!".
  49.    MessageBoxW(NULL, L"Not hooked...", L"MinHook Sample", MB_OK);
  50.  
  51.    // Disable the hook for MessageBoxW.
  52.    if (MH_DisableHook((void*)&MessageBoxW) != MH_OK)
  53.    {
  54.        return 1;
  55.    }
  56.  
  57.    // Expected to tell "Not hooked...".
  58.    MessageBoxW(NULL, L"Not hooked...", L"MinHook Sample", MB_OK);
  59.  
  60.    // Uninitialize MinHook.
  61.    if (MH_Uninitialize() != MH_OK)
  62.    {
  63.        return 1;
  64.    }
  65.  
  66.    return 0;
  67. }

Y cambie lo de messagebox añadiendole los void*. Aún así obtengo otros errores crees que los podría solucionar igual?:
Código:
C:\Users\Androide\Desktop\minhook\Dynamic>cd C:\Users\Androide\Desktop\minhook\D
ynamic

C:\Users\Androide\Desktop\minhook\Dynamic>g++ -o Dynamic.exe Dynamic.cpp
Dynamic.cpp: In function 'int main()':
Dynamic.cpp:37:88: error: no matching function for call to 'MH_CreateHookApiEx(c
onst wchar_t [7], const char [12], int (__attribute__((__stdcall__)) *)(HWND, LP
CWSTR, LPCWSTR, UINT), int (__attribute__((__stdcall__)) **)(HWND, LPCWSTR, LPCW
STR, UINT))'
     if (MH_CreateHookApiEx(L"user32", "MessageBoxW", &DetourMessageBoxW, &fpMes
sageBoxW) != MH_OK)

        ^
Dynamic.cpp:37:88: note: candidates are:
In file included from Dynamic.cpp:2:0:
C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h:141:
22: note: MH_STATUS MH_CreateHookApiEx(LPCWSTR, LPCSTR, LPVOID, void**, void**)
     MH_STATUS WINAPI MH_CreateHookApiEx(
                      ^
C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h:141:
22: note:   candidate expects 5 arguments, 4 provided
Dynamic.cpp:12:18: note: template<class T> MH_STATUS MH_CreateHookApiEx(LPCWSTR,
 LPCSTR, LPVOID, T**)
 inline MH_STATUS MH_CreateHookApiEx(LPCWSTR pszModule, LPCSTR pszProcName, LPVO
ID pDetour, T** ppOriginal)
                  ^
Dynamic.cpp:12:18: note:   template argument deduction/substitution failed:
Dynamic.cpp:37:88: note:   cannot convert 'DetourMessageBoxW' (type 'int (__attr
ibute__((__stdcall__)) *)(HWND, LPCWSTR, LPCWSTR, UINT) {aka int (__attribute__(
(__stdcall__)) *)(HWND__*, const wchar_t*, const wchar_t*, unsigned int)}') to t
ype 'LPVOID {aka void*}'
     if (MH_CreateHookApiEx(L"user32", "MessageBoxW", &DetourMessageBoxW, &fpMes
sageBoxW) != MH_OK)

        ^

Sino tendré que crear mi proyecto en c y punto.


Título: Re: Como resolver estos errores?
Publicado por: ivancea96 en 14 Marzo 2017, 19:27 pm
Varios de esos errores son lo mismo:
Código:
if (MH_CreateHookApiEx(L"user32", "MessageBoxW", &DetourMessageBoxW, &fpMes
sageBoxW) != MH_OK)
A &DetourMessageBoxW hay que ponerle también el void*.


Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 14 Marzo 2017, 19:42 pm
Varios de esos errores son lo mismo:

Hola disculpa tienes razón pero ahora creo que tendré que declararlos porque me devuelve estos error, supongo algo habré me faltara o no lo habré incluido bien:
Código:
C:\Users\Androide\Desktop\minhook\Dynamic>gcc -o bot.exe Dynamic.cpp
C:\Users\Androide\AppData\Local\Temp\ccHkYwzX.o:Dynamic.cpp:(.text+0x48): undefi
ned reference to `MH_Initialize@0'
C:\Users\Androide\AppData\Local\Temp\ccHkYwzX.o:Dynamic.cpp:(.text+0x9e): undefi
ned reference to `MH_EnableHook@4'
C:\Users\Androide\AppData\Local\Temp\ccHkYwzX.o:Dynamic.cpp:(.text+0xe7): undefi
ned reference to `MH_DisableHook@4'
C:\Users\Androide\AppData\Local\Temp\ccHkYwzX.o:Dynamic.cpp:(.text+0x126): undef
ined reference to `MH_Uninitialize@0'
C:\Users\Androide\AppData\Local\Temp\ccHkYwzX.o:Dynamic.cpp:(.text$_Z18MH_Create
HookApiExIFiP6HWND__PKwS3_jEE9MH_STATUSS3_PKcPvPPT_[__Z18MH_CreateHookApiExIFiP6
HWND__PKwS3_jEE9MH_STATUSS3_PKcPvPPT_]+0xfffffd2e): undefined reference to `MH_C
reateHookApi@16'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw
32/bin/ld.exe: C:\Users\Androide\AppData\Local\Temp\ccHkYwzX.o: bad reloc addres
s 0x22 in section `.text$_Z18MH_CreateHookApiExIFiP6HWND__PKwS3_jEE9MH_STATUSS3_
PKcPvPPT_[__Z18MH_CreateHookApiExIFiP6HWND__PKwS3_jEE9MH_STATUSS3_PKcPvPPT_]'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw
32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status


Título: Re: Como resolver estos errores?
Publicado por: ivancea96 en 14 Marzo 2017, 19:47 pm
Si ya te compila, entonces vamos al segundo paso.
¿Linkeaste correctamente la librería? Esos son errores de linker.

Bueno, leyendo la línea, no:
Citar
gcc -o bot.exe Dynamic.cpp

Cuando tratas de compilar un programa con uno o más archvios de código o librerías, hay que hacerlo por pasos.

Primero, compilar los códigos:
Citar
g++ -o Dynamic.o -c Dynamic.cpp

Luego, linkear todo:
Citar
g++ -o bot.exe Dynamic.o libreria1.o archivo2.o


Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 14 Marzo 2017, 20:51 pm
Vale tienes razón no sabía que se podia hacer por partes lo cual  es de gran utilidad. Tengo una pequeña duda ahora he compilado la libreria para la versión para mingw (la cual me da los archivos .o para el linkeado), aparentemente se crea pero en consola me muestra lo siguiente:

Código:
C:\Users\Androide\Desktop\minhook-master\build\MinGW>windres -i ../../dll_reso
ces/MinHook.rc -o MinHook_rc.o   && dllwrap --driver-name g++ -o MinHook.dll -
sm=intel --def ../../dll_resources/MinHook.def -Wl,-enable-stdcall-fixup -Wall
inHook_rc.o ../../src/*.c ../../src/HDE/*.c -I../../include -I../../src -Werro
-std=c++11 -s -static-libgcc -static-libstdc++  || pause
../../src/hook.c: In function 'void Freeze(PFROZEN_THREADS, UINT, UINT)':
../../src/hook.c:319:82: error: 'OpenThread' was not declared in this scope
             HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItem
i]);

  ^
../../src/hook.c: In function 'void Unfreeze(PFROZEN_THREADS)':
../../src/hook.c:338:82: error: 'OpenThread' was not declared in this scope
             HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItem
i]);

  ^
dllwrap: g++ exited with status 1

Después cojo el fichero .o y linkeo:
Código:
C:\Users\Androide\Desktop\minhook\Dynamic>g++ -o Dynamic.o -c Dynamic.cpp

C:\Users\Androide\Desktop\minhook\Dynamic>g++ -o bot.exe Dynamic.o MinHook_rc.o
Dynamic.o:Dynamic.cpp:(.text+0x48): undefined reference to `MH_Initialize@0'
Dynamic.o:Dynamic.cpp:(.text+0x9e): undefined reference to `MH_EnableHook@4'
Dynamic.o:Dynamic.cpp:(.text+0xe7): undefined reference to `MH_DisableHook@4'
Dynamic.o:Dynamic.cpp:(.text+0x126): undefined reference to `MH_Uninitialize@0'
Dynamic.o:Dynamic.cpp:(.text$_Z18MH_CreateHookApiExIFiP6HWND__PKwS3_jEE9MH_STATU
SS3_PKcPvPPT_[__Z18MH_CreateHookApiExIFiP6HWND__PKwS3_jEE9MH_STATUSS3_PKcPvPPT_]
+0xfffffd2e): undefined reference to `MH_CreateHookApi@16'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw
32/bin/ld.exe: Dynamic.o: bad reloc address 0x22 in section `.text$_Z18MH_Create
HookApiExIFiP6HWND__PKwS3_jEE9MH_STATUSS3_PKcPvPPT_[__Z18MH_CreateHookApiExIFiP6
HWND__PKwS3_jEE9MH_STATUSS3_PKcPvPPT_]'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw
32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

Crees que se deba al error de la libreria o al mejor pienso que el .o que obtengo sea la causa del problema.

Pienso que la razón es el error que no me incluye los .o correctamente de mi fichero hook.c por el error que cite.


Título: Re: Como resolver estos errores?
Publicado por: ivancea96 en 14 Marzo 2017, 21:03 pm
Antes de nada, me aprece raro que al generar la librería de esos errores. ¿Siempre te los dió?


Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 14 Marzo 2017, 21:38 pm
Al final me devuelve este error cuando añado la libreria que es (hook.c) con todas sus .o ficheros de linkeado, y perdona por liarla tanto con tanto texto, me devuelve:
Código:
C:\Users\Androide\Desktop\minhook\Dynamic>g++ -o bot.exe Dynamic.o hook.o hde32.
o buffer.o trampoline.o
hook.o:hook.c:(.text+0x60b): undefined reference to `OpenThread'
hook.o:hook.c:(.text+0x69d): undefined reference to `OpenThread'
hook.o:hook.c:(.text+0xa2c): undefined reference to `InitializeBuffer'
hook.o:hook.c:(.text+0xa7d): undefined reference to `UninitializeBuffer'
hook.o:hook.c:(.text+0xb14): undefined reference to `IsExecutableAddress'
hook.o:hook.c:(.text+0xb27): undefined reference to `IsExecutableAddress'
hook.o:hook.c:(.text+0xb52): undefined reference to `AllocateBuffer'
hook.o:hook.c:(.text+0xb7c): undefined reference to `CreateTrampolineFunction'
hook.o:hook.c:(.text+0xca0): undefined reference to `FreeBuffer'
hook.o:hook.c:(.text+0xd82): undefined reference to `FreeBuffer'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw
32/bin/ld.exe: hook.o: bad reloc address 0x13c in section `.rdata'
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw
32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

Supongo que tendré que linkear tambien a la librería openthread añadiendo -lopenthread o algo así.

Con gloox se me soluciono los errores añadiendo el linkeado de estas librerias -lws2_32 -ldnsapi -lgdi32 -lcrypt32 -lsecur32 supongo será igual para este proyecto pero con otras librerias de linkeado.


Título: Re: Como resolver estos errores?
Publicado por: ivancea96 en 14 Marzo 2017, 22:41 pm
Prueba compilando como hacías antes así:
Código:
gcc -o bot.exe Dynamic.cpp -L"Direccion de la carpeta de los archivos de la librería" -lhook -lhde32 -lbuffer -ltrampoline

De todos modos, estaba leyendo y:
Código
  1. #pragma comment(lib, "MinHook.x64.lib")
Tienes eso en el código. Eso solo funciona en VC++. Y esa es otra, ¿tienes un .lib? Si tienes ese .lib, entonces prueba algo como:
Código:
gcc -o bot.exe Dynamic.cpp -L"Direccion de la carpeta de los archivos de la librería" -l"MinHook.x64"

En fin, si no te funciona nada de esto, mira información sobre la librería...


Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 14 Marzo 2017, 23:55 pm
Me referia a esto(lo solucione así como indicastes solo añadiendo los linkeados):
-------------- Build: Debug in main (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g -IC:\openssl-1.0.1c_static_w32_mingw\include -IC:\openssl-1.0.1c_static_w32_mingw\include -IC:\Users\Androide\Desktop\gloox\src -c C:\Users\Androide\Desktop\main\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\openssl-1.0.1c_static_w32_mingw -LC:\Users\Androide\Desktop\gloox -o bin\Debug\main.exe obj\Debug\main.o   C:\openssl-1.0.1c_static_w32_mingw\libcrypto.a C:\openssl-1.0.1c_static_w32_mingw\libssl.a C:\Users\Androide\Desktop\gloox\libgloox.a -lws2_32 -ldnsapi -lgdi32 -lcrypt32 -lsecur32

Me han recomendado usar cmake pero no se muy bien como compilar mi proyecto con cmake ya que usa una version antigua:
Código:
TDM-GCC 4.9.2 SJLJ (released in October 30, 2014),

Pero la cuestión es como usar cmake captura de cmake y mis ficheros:
(https://cloud.githubusercontent.com/assets/23561866/23924816/9608cc6e-090c-11e7-80cd-1e13c3630145.PNG)
(https://cloud.githubusercontent.com/assets/23561866/23924937/1d7e2d4c-090d-11e7-86c8-d63e866bed6a.PNG)

Supongo que tendré que hacer un proyecto en codeblocks y compilarlo. Se supone que tengo que generar el makefile de mi proyecto con mingw creo y luego compilarlo con cmake que esta actualizado y no da estos problemas.


Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 15 Marzo 2017, 02:28 am
Parece ser que el error open thread es resuelto usando la versión de msys que utiliza una versión mas actualizada. Me aparecen los mismos errores de undefined reference es decir del proyecto como los que resolvistes anteriormente:
Código:
$ g++ -o /c/Users/Androide/Desktop/minhook/Dynamic/Dynamic.exe /c/Users/Androide/Desktop/minhook/Dynamic/Dynamic.o /c/Users/Androide/Desktop/minhook/Dynamic/hook.o
C:/Users/Androide/Desktop/minhook/Dynamic/hook.o:hook.c:(.text+0xab6): undefined reference to `InitializeBuffer()'
C:/Users/Androide/Desktop/minhook/Dynamic/hook.o:hook.c:(.text+0xb07): undefined reference to `UninitializeBuffer()'
C:/Users/Androide/Desktop/minhook/Dynamic/hook.o:hook.c:(.text+0xba2): undefined reference to `IsExecutableAddress(void*)'
C:/Users/Androide/Desktop/minhook/Dynamic/hook.o:hook.c:(.text+0xbb1): undefined reference to `IsExecutableAddress(void*)'
C:/Users/Androide/Desktop/minhook/Dynamic/hook.o:hook.c:(.text+0xbec): undefined reference to `AllocateBuffer(void*)'
C:/Users/Androide/Desktop/minhook/Dynamic/hook.o:hook.c:(.text+0xc16): undefined reference to `CreateTrampolineFunction(_TRAMPOLINE*)'
C:/Users/Androide/Desktop/minhook/Dynamic/hook.o:hook.c:(.text+0xd3d): undefined reference to `FreeBuffer(void*)'
C:/Users/Androide/Desktop/minhook/Dynamic/hook.o:hook.c:(.text+0xe17): undefined reference to `FreeBuffer(void*)'
collect2.exe: error: ld returned 1 exit status


Supongo que se podrá resolver usando void en estos métodos como me dijistes anteriormente.

Te pongo el código de la librería:
http://rextester.com/GLAIG22887 (http://rextester.com/GLAIG22887)


Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 15 Marzo 2017, 15:05 pm
Hola ivancea te he puesto el error actualizado que es de la librería pienso que se solucionara igual si tienes unos instantes fijate sino lo dejo asi. saludos y gracias.


Título: Re: Como resolver estos errores?
Publicado por: ivancea96 en 15 Marzo 2017, 15:21 pm
No, esos son errores del linker. Tienes que diferenciarlos. Cuando pone "ld returned 1" es error del linker ("ld" es el linker de GCC). Las undefined references también son del linker. "hook.o", está trabajando con el código objeto, ergo probablemente también sea del linker. ".text+0xab6", ".text" es una sección de un ejecutable, así que también implica linker.

En cualquier caso. Los errores de linker se solucionan linkeando bien las librerías, valga la redundacia. Intuyo que "InitializeBuffer" es una función de una librería. No veo que se la hayas indicado al compilar, con -L y/o -l.


Título: Re: Como resolver estos errores?
Publicado por: Borito30 en 15 Marzo 2017, 15:36 pm
Te pongo un ejemplo, tengo hasta el buffer creado .a:
(http://i.imgsafe.org/962164ea00.png)

Muchas gracias funciono. Os pongo el ultimo comando que teneis que poner:
Código:
g++ -o bot.exe Dynamic.o hook.o -L/c/Users/Androide/Desktop/minhook/Dynamic/ trampoline.a buffer.a hde32.a

Recordaros que codeblocks trae una versión antigua que a veces pues no incluye ciertas librerias por defecto y si actualizais evitais conflicto , gracias  ivancea por tu ayuda.