OldSchoolHack

Register / Login English

Crash bei injecten in anwendung wenn eigen erstellte Form verwendet wird


icon Crash bei injecten in anwendung wenn eigen erstellte Form verwendet wird #1

Join Date: Jun 2012

Posts: 1

Wenn ich die standart Form verwende klappt alles. Sobald ich aber die eigenerstellte Form aufrufe crasht es nach dem injecten der .dll .

main.cpp
CPP Code:
  1. #include "OSHGui.hpp"
  2. #include "Drawing/Direct3D9/RendererDX9.hpp"
  3. #include "Input/Windows.hpp"
  4. #include "Controls/Form.hpp"
  5. #include "FormManager.hpp"
  6. #include "MainForm.hpp"
  7. using namespace OSHGui;
  8.  
  9. //---------------------------------------------------------------------------
  10. DWORD FindPattern(const HMODULE module, const BYTE *pattern, LPCTSTR mask);
  11. void* DetourFunction(BYTE *source, const BYTE *destination, const int length);
  12. typedef HRESULT (WINAPI *oEndScene)(LPDIRECT3DDEVICE9 pDevice);
  13. oEndScene pEndScene = nullptr;
  14. //---------------------------------------------------------------------------
  15. //global vars
  16. //---------------------------------------------------------------------------
  17. Input::Windows input;
  18. Drawing::RendererDX9 *renderer;
  19. HHOOK messageHookHandle;
  20. //---------------------------------------------------------------------------
  21. LRESULT CALLBACK KeyboardHook(int code, WPARAM wParam, LPARAM lParam)
  22. {
  23. if (lParam & 0x80000000 || lParam & 0x40000000)
  24. {
  25. return CallNextHookEx(messageHookHandle, code, wParam, lParam);
  26. }
  27.  
  28. if (code == HC_ACTION)
  29. {
  30. if(input.ProcessMessage((LPMSG)lParam))
  31. {
  32. return true;
  33. }
  34. }
  35.  
  36. return CallNextHookEx(messageHookHandle, code, wParam, lParam);
  37. }
  38. //---------------------------------------------------------------------------
  39. HRESULT WINAPI hook_EndScene(LPDIRECT3DDEVICE9 pDevice)
  40. {
  41. Application *app = Application::Instance();
  42. static bool initGui = true;
  43. if (initGui)
  44. {
  45. initGui = false;
  46. renderer = new Drawing::RendererDX9(pDevice);
  47. app->Create(renderer);
  48.  
  49. messageHookHandle = SetWindowsHookExW(WH_GETMESSAGE, KeyboardHook, 0, GetCurrentThreadId());
  50.  
  51. app->Run(std::shared_ptr<Form>(new MainForm()));
  52. app->Enable();
  53. }
  54.  
  55. renderer->Begin();
  56. app->Render();
  57. renderer->End();
  58.  
  59. return pEndScene(pDevice);
  60. }
  61. //---------------------------------------------------------------------------
  62. bool WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved)
  63. {
  64. if (dwReason == DLL_PROCESS_ATTACH)
  65. {
  66. DisableThreadLibraryCalls(hDll);
  67.  
  68. HMODULE d3d9 = NULL;
  69. for (; !(d3d9 = GetModuleHandle("d3d9.dll")); Sleep(100));
  70.  
  71. DWORD device = FindPattern(d3d9, (BYTE*)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx") + 2;
  72. DWORD *VTable = NULL;
  73. memcpy(&VTable, (void*)device, 4);
  74. pEndScene = (oEndScene)DetourFunction((BYTE*)VTable[42], (BYTE*)hook_EndScene, 5);
  75. }
  76. return true;
  77. }
  78. //---------------------------------------------------------------------------
  79. //Utils
  80. //---------------------------------------------------------------------------
  81. bool DataCompare(const BYTE *data, const BYTE *pattern, LPCTSTR mask)
  82. {
  83. for (; *mask; ++mask, ++data, ++pattern)
  84. {
  85. if (*mask == 'x' && *data != *pattern)
  86. {
  87. return false;
  88. }
  89. }
  90.  
  91. return *mask == 0;
  92. }
  93. //---------------------------------------------------------------------------
  94. DWORD FindPattern(const HMODULE module, const BYTE *pattern, LPCTSTR mask)
  95. {
  96. if (module == NULL || module == INVALID_HANDLE_VALUE)
  97. {
  98. throw Misc::ArgumentNullException("module");
  99. }
  100.  
  101. PIMAGE_DOS_HEADER dosHeader =(PIMAGE_DOS_HEADER)module;
  102.  
  103. if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE)
  104. {
  105. throw Misc::Exception("e_magic != IMAGE_DOS_SIGNATURE");
  106. }
  107.  
  108. PIMAGE_NT_HEADERS NTHead = (PIMAGE_NT_HEADERS)((DWORD)dosHeader + (DWORD)dosHeader->e_lfanew);
  109.  
  110. if (NTHead->Signature != IMAGE_NT_SIGNATURE)
  111. {
  112. throw Misc::Exception("Signature != IMAGE_NT_SIGNATURE");
  113. }
  114.  
  115. DWORD address = (DWORD)module + NTHead->OptionalHeader.BaseOfCode;
  116. DWORD size = NTHead->OptionalHeader.SizeOfCode;
  117.  
  118. for (DWORD i = NULL; i < size; i++)
  119. {
  120. if (DataCompare((BYTE*)(address + i), pattern, mask))
  121. {
  122. return address + i;
  123. }
  124. }
  125.  
  126. return NULL;
  127. }
  128. //---------------------------------------------------------------------------
  129. void* DetourFunction(BYTE *source, const BYTE *destination, const int length)
  130. {
  131. BYTE *trampolin = (BYTE*)malloc(5 + length);
  132. DWORD dwback;
  133.  
  134. VirtualProtect(trampolin, length + 5, PAGE_EXECUTE_READWRITE, &dwback);
  135. VirtualProtect(source, length, PAGE_EXECUTE_READWRITE, &dwback);
  136.  
  137. memcpy(trampolin, source, length);
  138. trampolin += length;
  139.  
  140. trampolin[0] = 0xE9;
  141. *(DWORD*)(trampolin + 1) = (DWORD)(source + length - trampolin) - 5;
  142.  
  143. source[0] = 0xE9;
  144. *(DWORD*)(source + 1) = (DWORD)(destination - source) - 5;
  145.  
  146. for (int i = 5; i < length; i++)
  147. {
  148. source[i] = 0x90;
  149. }
  150.  
  151. return trampolin - length;
  152. }
  153. //---------------------------------------------------------------------------

mainform.hpp
CPP Code:
  1. #ifndef OSHGUI_MAINFORM_HPP
  2. #define OSHGUI_MAINFORM_HPP
  3.  
  4. #include <OSHGui.hpp>
  5.  
  6. class MainForm : public OSHGui::Form
  7. {
  8. public:
  9. MainForm();
  10.  
  11. private:
  12. void InitializeComponent()
  13. {
  14. SetName("MainForm");
  15. SetSize(OSHGui::Drawing::Size(645, 176));
  16. SetText("Administration");
  17.  
  18. button1 = new OSHGui::Button();
  19. button1->SetName("button1");
  20. button1->SetLocation(OSHGui::Drawing::Point(6, 7));
  21. button1->SetText("Server Settings");
  22. AddControl(button1);
  23.  
  24. button2 = new OSHGui::Button();
  25. button2->SetName("button2");
  26. button2->SetLocation(OSHGui::Drawing::Point(6, 38));
  27. button2->SetText("Event Manager");
  28. AddControl(button2);
  29.  
  30. button3 = new OSHGui::Button();
  31. button3->SetName("button3");
  32. button3->SetLocation(OSHGui::Drawing::Point(6, 69));
  33. button3->SetText("User Manager");
  34. AddControl(button3);
  35.  
  36. button4 = new OSHGui::Button();
  37. button4->SetName("button4");
  38. button4->SetLocation(OSHGui::Drawing::Point(6, 100));
  39. button4->SetText("Room Manager");
  40. AddControl(button4);
  41. }
  42.  
  43. OSHGui::Button *button1;
  44. OSHGui::Button *button2;
  45. OSHGui::Button *button3;
  46. OSHGui::Button *button4;
  47.  
  48. };
  49.  
  50. #endif

mainform.cpp
CPP Code:
  1. #include "MainForm.hpp"
  2. using namespace OSHGui;
  3.  
  4. MainForm::MainForm()
  5. {
  6. InitializeComponent();
  7. }
  8. //---------------------------------------------------------------------------

Ich hoffe mir kann jemand helfen.

icon #2

Join Date: Aug 2007

Posts: 8646

User-Rating:

199 positive
33 negative
Thread nicht gesehen -.-
An welcher Stelle crasht es denn? Am besten im Debugger schauen wo er stehen bleibt.

greetz KN4CK3R

__________________

Hallo