Guest User

Untitled

a guest
Nov 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. ######################## Function ########################
  2. Declare Function LoadLibraryA Lib "kernel32" (ByVal name As String) As IntPtr
  3. Declare Function GetProcAddress Lib "kernel32" (ByVal handle As IntPtr, ByVal name As String) As IntPtr
  4. Function CreateAPI(Of T)(ByVal name As String, ByVal method As String) As T
  5. Return DirectCast(DirectCast(Marshal.GetDelegateForFunctionPointer(GetProcAddress(LoadL​ibraryA(name), method), GetType(T)), Object), T)
  6. End Function
  7.  
  8. ######################## Original ########################
  9. <DllImport("kernel32", CharSet:=CharSet.Auto, SetLastError:=True)> _
  10. Public Shared Function VirtualProtectEx(ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UIntPtr, ByVal flNewProtect As UIntPtr, <Out()> ByVal lpflOldProtect As UInteger) As Integer
  11. End Function
  12.  
  13. ######################## Delegated ########################
  14. Delegate Function VirtualProtectEx(ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UIntPtr, ByVal flNewProtect As UIntPtr, <Out()> ByVal lpflOldProtect As UInteger) As Integer
  15.  
  16. ######################## Delegated API ########################
  17. Dim VPX = CreateAPI(Of VPX)("kernel32", "VirtualAllocEx")
Add Comment
Please, Sign In to add comment