need help asm to pb

Just starting out? Need help? Post your questions and find answers here.
sazuker
New User
New User
Posts: 9
Joined: Thu Jun 05, 2008 6:48 pm

need help asm to pb

Post by sazuker »

Anyone could help me my pb translation is not working right
Your help would be much appreciated

org asm code

Code: Select all

ProcInstallHook proc uses ebx edi esi hookProc:DWORD, targetProc:DWORD, patchLen:DWORD
	mov esi, patchLen
	mov edi, targetProc
	mov eax, esi
	add eax, 5
	invoke Alloc, eax
	mov ebx, eax
	invoke MemCopy, edi, eax, esi
	invoke VirtualProtect, edi, 5, PAGE_EXECUTE_READWRITE, ADDR targetProc
	mov eax, hookProc
	sub eax, edi
	sub eax, 5
	mov BYTE PTR [edi], 0E9h
	mov [edi + 1], eax
	invoke VirtualProtect, edi, 5, targetProc, ADDR targetProc
	sub edi, ebx
	add esi, ebx
	sub edi, 5
	mov BYTE PTR [esi], 0E9h
	mov [esi + 1], edi
	return ebx
ProcInstallHook endp 

my PBcode

Code: Select all

Procedure ProcInstallHook(hookProc.l, targetProc.l, patchLen.l)
  myESI.l = patchLen
  myEDI.l = targetProc
  myEAX = myESI
  myEAX+5
  myEBX.l = AllocateMemory(myEAX)
  CopyMemory(@myEDI, @myEAX, myESI)
  VirtualProtect_(@myEDI, 5, PAGE_EXECUTE_READWRITE, @targetProc)
  myEAX = hookProc
  myEAX-myEDI
  myEAX-5
  PokeB(@myEDI, $E9)
  PokeL(@myEDI + 1, eax)
  VirtualProtect_(@myEDI, 5, targetProc, @targetProc)
  myEDI-myEBX
  myESI+myEBX
  myEDI-5
  PokeB(@myESI, $E9)
  PokeL(@myESI + 1, edi)
  ProcedureReturn myEBX
EndProcedure
Thanks!!!
Helle
Enthusiast
Enthusiast
Posts: 178
Joined: Wed Apr 12, 2006 7:59 pm
Location: Germany
Contact:

Post by Helle »

PAGE_EXECUTE_READWRITE is a constant, take

Code: Select all

#PAGE_EXECUTE_READWRITE
Gruss
Helle
sazuker
New User
New User
Posts: 9
Joined: Thu Jun 05, 2008 6:48 pm

Post by sazuker »

still doesnt werk :cry:
pointers and addresses are killing me
anyone could help me pls
Helle
Enthusiast
Enthusiast
Posts: 178
Joined: Wed Apr 12, 2006 7:59 pm
Location: Germany
Contact:

Post by Helle »

Code: Select all

Procedure ProcInstallHook(hookProc.l, targetProc.l, patchLen.l) 
  ;Global targetProc.l
  Global myEAX.l
  Global myEBX.l
  Global myEDI.l = targetProc
  Global myESI.l = patchLen 
     
  myEAX = myESI 
  myEAX+5 
  myEBX.l = AllocateMemory(myEAX) 
  CopyMemory(@myEDI, @myEAX, myESI) 
  VirtualProtect_(myEDI, 5, #PAGE_EXECUTE_READWRITE, @targetProc) 
  myEAX = hookProc 
  myEAX-myEDI 
  myEAX-5 
  PokeB(@myEDI, $E9) 
  PokeL(@myEDI + 1, eax) 
  VirtualProtect_(myEDI, 5, targetProc, @targetProc) 
  myEDI-myEBX 
  myESI+myEBX 
  myEDI-5 
  PokeB(@myESI, $E9) 
  PokeL(@myESI + 1, edi) 
  ProcedureReturn myEBX 
EndProcedure
Gruß
Helle

P.S.: I use VirtualProtectEx()
Edit: The 1.Parameter of VirtualProtect is a value, not a pointer.
For a example (patching) with VirtualProtectEx see http://www.purebasic.fr/german/viewtopic.php?t=16780 (comments in german).
sazuker
New User
New User
Posts: 9
Joined: Thu Jun 05, 2008 6:48 pm

Post by sazuker »

thx for all the help Helle
its now running!!!! :)
Post Reply