Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Karcrack en 30 Diciembre 2011, 12:51 pm



Título: [SNIPPET] mPatchFunction - Parchea funciones para hacer un jump a una nueva dir.
Publicado por: Karcrack en 30 Diciembre 2011, 12:51 pm
Código
  1. Option Explicit
  2.  
  3. '---------------------------------------------------------------------------------------
  4. ' Module    : mPatchFunction
  5. ' Author    : Karcrack
  6. ' Date      : 27/11/2011
  7. ' Purpose   : Patch function with JMP to new addr
  8. '---------------------------------------------------------------------------------------
  9.  
  10. 'NTDLL
  11. Private Declare Function NtWriteVirtualMemory Lib "NTDLL" (ByVal hProcess As Long, ByRef lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
  12.  
  13. Private Const CURRENT_PROCESS = (-1)
  14.  
  15. Public Function PatchFunction(ByVal pFnc As Long, ByVal pNewFnc As Long, Optional ByVal hProc As Long = CURRENT_PROCESS) As Boolean
  16.    Dim cCode   As Currency
  17.  
  18.    cCode = &HB8& * (0.0001@)                   'mov EAX, imm32
  19.    cCode = cCode + (pNewFnc * 0.0256@)         'imm32
  20.    cCode = cCode + (&HE0FF& * 109951162.7776@) 'jmp EAX
  21.  
  22.    PatchFunction = NtWriteVirtualMemory(hProc, ByVal pFnc&, cCode, &H8, 0&)
  23. End Function

Ejemplo de uso:
Código
  1. Sub Main()
  2.    Dim pMessageBoxW    As Long
  3.  
  4.    pMessageBoxW = GetProcAddress(LoadLibrary("USER32"), "MessageBoxW")
  5.  
  6.    If PatchFunction(AddressOf MessageBoxW__, pMessageBoxW) Then
  7.        If MessageBoxW__(0, "Did you like the function?", "Karcrack", vbYesNo) = vbYes Then
  8.            Call MessageBoxW__(0, "Glad you liked it", "Karcrack", 0)
  9.        Else
  10.            Call MessageBoxW__(0, "F**k you bastard xD", "Karcrack", 0)
  11.        End If
  12.    End If
  13. End Sub
  14.  
  15. Public Function MessageBoxW__(ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
  16.    'JMP &MessageBoxW@USER32
  17. End Function