OldSchoolHack

Register / Login English

User Search: puelo

Search-Information
puelo
Threads
Thread Forum Last Post Posts Views
icon

Go to first new post Breakpoint Hooking Problem Posted on: Thu 17. Sep 2009, 13:51

puelo

preview Preview

Go To Post

Ahoy,

ich befasse mich seit einigen Wochen ernsthaft mit dem Thema Hack Coding in CS bzw. HL Engine.
Habe einen Loader geschrieben, welcher auch erfolgreich eine .dll injected. Nun habe ich in der .dll einige Funktionen , unter anderem eine welche Hooks für Breakpoints setzt.
Ich kann normal CS starten, den Loader starten und die .dll wird injected, aber sobald ich einen server joinen will (egal ob online, oder LAN), friert das Game ein - etwa beim letzten drittel des Ladebalkens -. Habe dann durch auskommentieren die "kaputte" Stelle gefunden, aber konnte keinen wirklichen Fehler feststellen.
Mit Ollydbg kann ich mich leider auch nicht dranhängen, denn wenn ich versuche hl.exe mit olly zu starten, dann kommt "Game currently unavailable". Wenn ich allerdings das Spiel öffne, und mich dann attache, und start drücke komme ich nichtmehr ins Game.

Hier das betroffene Stück Code:

TEXT Code:
  1.  
  2. bool bpSetHooks(void)
  3. {
  4. if (!pExceptionHandler || !bpBackupRegisters())
  5. return false;
  6.  
  7. CONTEXT ctx = { CONTEXT_DEBUG_REGISTERS };
  8.  
  9. // Register #1
  10. ctx.Dr0 = gBreakPoints.bp[0].dwAddr;
  11. ctx.Dr7 = 0x00000001;
  12.  
  13. // Register #2
  14. ctx.Dr1 = gBreakPoints.bp[1].dwAddr;
  15. ctx.Dr7 |= 0x00000004;
  16.  
  17. // Register #3
  18. ctx.Dr2 = gBreakPoints.bp[2].dwAddr;
  19. ctx.Dr7 |= 0x00000010;
  20.  
  21. // Register #4
  22. ctx.Dr3 = gBreakPoints.bp[3].dwAddr;
  23. ctx.Dr7 |= 0x00000040;
  24. return (SetThreadContext(gBreakPoints.hThread, &ctx) == TRUE);
  25.  
  26. return true;
  27. }
  28.  

Muss dazu sagen, dass dieses Codefragment nicht Original von mir stammt.
ko1n und Marvv haben das ursprünglich verwendet, also keine Flames plx

Danke für jede hilfreiche Antwort.
MFG
VB, C/C++, Delphi, etc

Thu 17. Sep 2009, 23:31

by puelo Go to last post
4 736
icon

Go to first new post Breakpoint Hooking Problem Posted on: Thu 17. Sep 2009, 13:51

puelo

preview Preview

Go To Post

Achja vergessen zu sagen.

Die Funktion wird bereits schon beim ersten Start ausgeführt, also ohne das ich auf einen Server joinen muss, wobei sie da keine Probleme macht.
Wenn ich diesen Teil auskommentiere kann ich auf einen Server joinen.
Also irgendwas läuft da wohl falsch
VB, C/C++, Delphi, etc

Thu 17. Sep 2009, 23:31

by puelo Go to last post
4 736
icon

Go to first new post Breakpoint Hooking Problem Posted on: Thu 17. Sep 2009, 13:51

puelo

preview Preview

Go To Post

Mhh hab den Fehler noch etwas eingrenzen können...

Es betrifft nur die letzten beiden Register:

TEXT Code:
  1. // Register #3
  2. ctx.Dr2 = 0x4003000; //gBreakPoints.bp[2].dwAddr;
  3. ctx.Dr7 |= 0x00000010;
  4.  
  5. // Register #4
  6. ctx.Dr3 = 0x4004000; //gBreakPoints.bp[3].dwAddr;
  7. ctx.Dr7 |= 0x00000040; // todo: dynamic loop here

Wenn ich, wie oben schon getan, manuell eine Addresse einsetze, dann freezt das Spiel nicht.

Die Funktion welche die Addressen setzt sieht folgendermaßen aus:
TEXT Code:
  1.  
  2. bool bpInitialize(breakpoints_t *pBreakPoints)
  3. {
  4. memcpy(&gBreakPoints, pBreakPoints, sizeof(gBreakPoints));
  5.  
  6. if (gBreakPoints.hThread == NULL)
  7. gBreakPoints.hThread = GetCurrentThread();
  8.  
  9. for (int i = 0; i < 4; i++)
  10. {
  11. if (*(gBreakPoints.bp[i].pSystemFunction) != NULL)
  12. continue;
  13.  
  14. gBreakPoints.bp[i].dwAddr = gBreakPoints.bp[i].dwFunctionAddr;
  15.  
  16. // length of opcode + 0x5
  17. size_t sStubSize = oplen((BYTE *)gBreakPoints.bp[i].dwAddr);
  18. *(gBreakPoints.bp[i].pSystemFunction) = malloc((sStubSize + 0x5));
  19.  
  20.  
  21. // copy the opcodes to the buffer
  22. memcpy(*(gBreakPoints.bp[i].pSystemFunction), (PVOID)gBreakPoints.bp[i].dwAddr, sStubSize);
  23.  
  24. // add a jmp instruction to the original system function at the end of the buffer
  25. *(PBYTE)((DWORD)*(gBreakPoints.bp[i].pSystemFunction) + (DWORD)sStubSize) = 0xE9;
  26. *(PDWORD)((DWORD)*(gBreakPoints.bp[i].pSystemFunction) + (DWORD)sStubSize + 0x1) = (((DWORD)gBreakPoints.bp[i].dwAddr + (DWORD)sStubSize) - ((DWORD)*(gBreakPoints.bp[i].pSystemFunction) + (DWORD)sStubSize + 0x5));
  27.  
  28. }
  29.  
  30. if (pExceptionHandler == NULL)
  31. pExceptionHandler = AddVectoredExceptionHandler(1, ExceptionHandler);
  32. return true;
  33. }
  34.  
VB, C/C++, Delphi, etc

Thu 17. Sep 2009, 23:31

by puelo Go to last post
4 736
icon

Go to first new post Breakpoint Hooking Problem Posted on: Thu 17. Sep 2009, 13:51

puelo

preview Preview

Go To Post

hat sich schon erledigt, hab die letzten beiden Debug Register Breakpoints manuell gesetzt.

Danke trotzdem.
VB, C/C++, Delphi, etc

Thu 17. Sep 2009, 23:31

by puelo Go to last post
4 736
Downloads
No downloads found.