Advertisement
Guest User

Untitled

a guest
Dec 25th, 2012
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.06 KB | None | 0 0
  1. procedure PackerFunctionAsm;
  2. begin
  3.   asm
  4.     push eax //Fake Call Emulation (Eax Contains Return Address)
  5.     push ebp
  6.     mov ebp,esp
  7.     cmp [ebp+8],0
  8.     je @@VerifyProtector1
  9.     cmp [ebp+8],1
  10.     je @@VerifyProtector2
  11.     cmp [ebp+8],2
  12.     je @@GetHardwareID1
  13.     ret 4
  14.   @@VerifyProtector1:
  15.     push [ebp+$10]
  16.     push [ebp+$C]
  17.     call VerifyFunction1
  18.     mov esp,ebp
  19.     pop ebp
  20.     ret $C
  21.   @@VerifyProtector2:
  22.     push [ebp+$10]
  23.     push [ebp+$C]
  24.     call VerifyFunction2
  25.     mov esp,ebp
  26.     pop ebp
  27.     ret $C
  28.   @@GetHardwareID1:
  29.     push [ebp+$C]
  30.     call GetHardwareID1
  31.     mov esp,ebp
  32.     pop ebp
  33.     ret $8
  34.   end;
  35. end;
  36.  
  37. function PackerFunctionHandler(var Exp:EXCEPTION_POINTERS):Integer;stdcall;
  38. var
  39.   i:Dword;
  40.   CorrectFunction:Boolean;
  41.   dwExceptionAddress:Dword;
  42. begin
  43.   result:=0;
  44.   If Exp.ExceptionRecord.ExceptionCode=STATUS_PRIVILEGED_INSTRUCTION then
  45.   begin
  46.     //31 C0 8B C0 90 F4
  47.     CorrectFunction:=False;
  48.     dwExceptionAddress:=Exp.ContextRecord.Eip;
  49.     dwExceptionAddress:=dwExceptionAddress-5;
  50.     if pbyte(dwExceptionAddress)^=$31 then
  51.       if pbyte(dwExceptionAddress+1)^=$C0 then
  52.         if pbyte(dwExceptionAddress+2)^=$89 then
  53.           if pbyte(dwExceptionAddress+3)^=$C0 then
  54.             if pbyte(dwExceptionAddress+4)^=$90 then
  55.               if pbyte(dwExceptionAddress+5)^=$F4 then
  56.                 CorrectFunction:=True;
  57.     if pbyte(dwExceptionAddress)^=$33 then
  58.       if pbyte(dwExceptionAddress+1)^=$C0 then
  59.         if pbyte(dwExceptionAddress+2)^=$8B then
  60.           if pbyte(dwExceptionAddress+3)^=$C0 then
  61.             if pbyte(dwExceptionAddress+4)^=$90 then
  62.               if pbyte(dwExceptionAddress+5)^=$F4 then
  63.                 CorrectFunction:=True;
  64.     If Not CorrectFunction Then
  65.       Exit;
  66.     Exp.ContextRecord.Eax:=Exp.ContextRecord.Eip+1; //Store Return Address in Eax
  67.     Exp.ContextRecord.EFlags:=Exp.ContextRecord.EFlags and (not $100); //Destroy Trap Flag
  68.     Exp.ContextRecord.Eip:=Dword(@PackerFunctionAsm); //Set Eip to Function Processor
  69.     Result:=-1;
  70.     Exit;
  71.   end;
  72. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement