Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi try ... except (https://www.delphipraxis.net/63155-try-except.html)

MCQ 14. Feb 2006 21:59

Re: try ... except
 
Zitat:

Zitat von jfheins
Läuft eigentlich ein Debugger ?

Nein
Zitat:

Zitat von jfheins
Ach, und was möchtest du machen ? :mrgreen:

Verhindern das der Prozess im Debugger gestartet wird ;)

Hier das logische Prinzip:
Delphi-Quellcode:
err:=false
try
//hier MUSS ein fehler erzeugt werden
except
err:=true
end
//hier kann mit hilfe der variable err kontrolliert werden ob die interne Fehlerbehandlungsroutine genutzt wurde oder ein Debugger angesprungen ist

jfheins 14. Feb 2006 22:02

Re: try ... except
 
Du könntest auch soetwas machen wie
Delphi-Quellcode:
 if IsDebuggerPresent then Application.Terminate;
http://msdn.microsoft.com/library/de...gerpresent.asp

;)

MCQ 14. Feb 2006 22:07

Re: try ... except
 
Nee lass man, Olly Shadow ist einer der bevorzugten Debugger unter WinXP. Dieser ist mit Plugins ausgestattet die IsDebuggerPresent mit falschen werten füttert und ihn somit für diese funktion unsichtbar macht. Genauer gesagt soll es eine DLL werden die Prozesse vorm Debuggen schützt und auf vielfache art und weise nach Debuggern sucht. In eingen CrackMe#s von mir hat diese art von Debugger-Checks auc sehr gut funktioniert, nur weiss ich nicht wieso es jetzt nicht funktioniert :(

MCQ 14. Feb 2006 22:15

Re: try ... except
 
hier mal der komplette source

Delphi-Quellcode:
library test;

uses
//  dialogs,sysutils,
  windows;

const
 IMAGEBASE = $00400000;
 CRC      = $4808181C;
{$R *.res}


procedure CheckSerial(serial:Pchar);
begin
if Serial='MCQs Debugger-Protection' then
MessageBox(0,'Gültige Serial - aber darum gings hier ja auch nicht ;)','',MB_ICONINFORMATION)
else
MessageBox(0,'ungültige Serial','Fehler',MB_ICONERROR)
end;


exports CheckSerial;



procedure ForceException;stdcall;
var start,ende,dw:DWORD;
    err:boolean;
begin
err:=false;
start:=GetTickCount;
try
 asm
  int 3  // <-- BreakPoint für Debugger
 end
except
 err:=true;
end;
ende:=GetTickCount;
if (start-ende>10) or not err then ExitProcess(0); // wenn Debugger angesprungen oder timeout dann ExitProcess
end;


procedure AntiBP;
label weiter;
var mycrc:DWORD;
begin
 asm
(*
  EAX - Start
  EBX - Länge
  ECX - Zähler
  EDX - CRC
*)
  push eax
  push ebx
  push ecx
  push edx
  mov eax,IMAGEBASE
  add eax,$3C
  mov eax,[eax]
  add eax, IMAGEBASE
  mov ebx, [eax+$1C] // Size of Code
  mov eax, [eax+$2C] // Base of Code
  add eax, IMAGEBASE
  xor ecx, ecx
  xor edx, edx
  weiter:
  xor edx,[eax+ecx]
  inc ecx
  cmp ecx,ebx
  jnz weiter
//  int 3
  mov mycrc,edx
  cmp edx,crc
  push 100
  call sleep
  pop edx
  pop ecx
  pop ebx
  pop eax
  jz AntiBP
  mov eax,offset ExitProcess
  call eax
  end;
//  showmessage(inttohex(mycrc,8));
  ExitProcess(0);
end;

procedure AntiAttach;
var pProc:Pointer;
    tmp:DWORD;
begin
pProc:=GetProcAddress(LoadLibrary('ntdll.dll'),'DbgUiRemoteBreakin');
VirtualProtect(pProc,1,PAGE_EXECUTE_READWRITE,tmp);
asm
 push eax
  mov eax,pProc
  mov [eax],$006A
  mov [eax+2],$B8
  mov [eax+3], offset ExitProcess
  mov [eax+7], $D0FF
 pop eax
end;
VirtualProtect(pProc,1,tmp,tmp);
end;


label SetAPIHook;
var tmp:DWORD;
begin
 asm
  push eax
  push ebx
  mov eax,IMAGEBASE
  add eax,$3C
  mov eax,[eax]
  add eax,IMAGEBASE
  add eax,$28
  mov eax,[eax]
  add eax,IMAGEBASE
  mov bl,[eax]
  xor bl,$23
  add bl,$11
  test bl,bl
  jnz SetAPIHook
  mov eax,offset ExitProcess
  push 0
  call eax // ExitProcess(0);
  SetAPIHook:
  pop ebx
  pop eax
  call AntiAttach
  call ForceException
 end;
BeginThread(nil,0,@AntiBP,nil,0,tmp);
end.
Bis auf die Funktion ForceException funtioniert es auch wunderbar

Luckie 14. Feb 2006 22:26

Re: try ... except
 
Lies dir das mal durch: http://www.michael-puff.de/Developer...acking_1.shtml

Und guck dir mal diesen Code an:
Delphi-Quellcode:
  asm
    pushad
    call @SetupSEHAndRaiseException
    mov  ecx, dword ptr [esp+12]
    mov  eax, fs:[$30]
    movzx eax, byte ptr [eax+$2]
    and  eax, eax
    jnz  @NoAddOpCodeSize
    mov  dword ptr [ecx+$B8], offset @AfterExceptionCause
    @NoAddOpCodeSize:
    mov  dword ptr [ecx+$04], eax
    mov  dword ptr [ecx+$08], eax
    mov  dword ptr [ecx+$0C], eax
    mov  dword ptr [ecx+$10], eax
    mov  dword ptr [ecx+$14], eax
    and  dword ptr [ecx+$18], $155
    and  dword ptr [ecx+$C0], $FFFFFEFF
    xor  eax, eax
    ret
    @SetupSEHAndRaiseException:
    xor  eax, eax
    push dword ptr fs:[eax]
    mov  fs:[eax], esp
    @KillCode:
    and  dword ptr [eax+$18], $155
    @AfterExceptionCause:
    pop  dword ptr fs:[$0]
    add  esp, $4
    popad
  end;
Wior der Code ausgeführt, crasht der Debugger. Läßt sich aber auch umgehen, wenn man weiß, wie. Lass dir gesagt sein, dass es keinen hundertprozentigen Crack-Schutz gibt.

MCQ 14. Feb 2006 22:37

Re: try ... except
 
Naja, ich werd es mal tracen und schauen was passiert.

Das es keinen 100%igen CrackSchutz ist mir klar, schließlich cracke ich selbst schon einige jahre (nur legale CrackMe's natürlich ;) ) aber wenn ich schon einen Schutz einbaue, dann möchte ich dch wenigstens das der Angreifer etwas davon merkt, und das ist bei IsDebuggerPresent nicht der fall daran ändert auch die nachprogrammierung von M. Puff nichts.

Danke erstmal für eure Hilfe, sollte ich trotz tracens nicht weiterkommen melde ich mich hier nochmal

Greez MCQ

tommie-lie 15. Feb 2006 14:40

Re: try ... except
 
Irgendwas scheint da massiv nicht zu stimmen, wenn selbst eine popelige EDevByZero-Exception durch try-except nicht abgefangen wird. Bei mir (XP, SP2, in einer VM) funktioniert es jedenfalls ohne Probleme, auch mit int3 und DebugBreak(). Hast du den Code mal auf einem zweiten System (vorzugsweise einer möglichst sauberen Installation) kompiliert und getestet?

Zitat:

Zitat von jfheins
In der Hilfe zu DebugBreak steht nämlich:
Zitat:

If the process is not being debugged, the function uses the search logic of a standard exception handler. In most cases, this causes the calling process to terminate because of an unhandled breakpoint exception.

Ich habe mal das markiert, worauf es ankommt ;-)
DebugBreak() tut auch nichts anderes, als eine schnöde Exception zu werfen, die wie jede andere auch abgefangen werden kann.

MCQ 15. Feb 2006 17:24

Re: try ... except
 
So, das Problem ist gelöst, ich hoffe mir kann jemannd erklären wieso es nach der einbindung von sysutils geklappt hat. Wenn windows beim ausführen von try-except etwas fehlen sollte, sollte dann der Compiler nicht meckern?

tommie-lie 15. Feb 2006 17:40

Re: try ... except
 
Zitat:

Zitat von MCQ
ich hoffe mir kann jemannd erklären wieso es nach der einbindung von sysutils geklappt hat

Munter ins Blaue vermutet: In SysUtils.pas sind die Exception-Klassen deklariert und vielleicht beeinflusst das die Arbeit eines excepts, ohne das der Compiler meckert.

m_junglas 20. Feb 2006 21:46

Re: try ... except
 
Hallo,

ich bin ja kein Delphi-Crack, aber ich vermisse da eine solche Zeile nach "except":

Delphi-Quellcode:
on <Deine_Exceptionklasse> do err := ....
Soweit ich weiss wird nur so die Exception als behandelt betrachtet. (?)

Tschau
/\/\arcus


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:14 Uhr.
Seite 2 von 3     12 3      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz