Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Private Const PAGE_EXECUTE_READWRITE = &H40
  4.  
  5. Private Declare PtrSafe Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _
  6. (Destination As LongPtr, Source As LongPtr, ByVal Length As LongPtr)
  7.  
  8. Private Declare PtrSafe Function VirtualProtect Lib "kernel32" (lpAddress As LongPtr, _
  9. ByVal dwSize As LongPtr, ByVal flNewProtect As LongPtr, lpflOldProtect As LongPtr) As LongPtr
  10.  
  11. Private Declare PtrSafe Function GetModuleHandleA Lib "kernel32" (ByVal lpModuleName As String) As LongPtr
  12.  
  13. Private Declare PtrSafe Function GetProcAddress Lib "kernel32" (ByVal hModule As LongPtr, _
  14. ByVal lpProcName As String) As LongPtr
  15.  
  16. Private Declare PtrSafe Function DialogBoxParam Lib "user32" Alias "DialogBoxParamA" (ByVal hInstance As LongPtr, _
  17. ByVal pTemplateName As LongPtr, ByVal hWndParent As LongPtr, _
  18. ByVal lpDialogFunc As LongPtr, ByVal dwInitParam As LongPtr) As Integer
  19.  
  20. Dim HookBytes(0 To 5) As Byte
  21. Dim OriginBytes(0 To 5) As Byte
  22. Dim pFunc As LongPtr
  23. Dim Flag As Boolean
  24.  
  25. Private Function GetPtr(ByVal Value As LongPtr) As LongPtr
  26. GetPtr = Value
  27. End Function
  28.  
  29. Public Sub RecoverBytes()
  30. If Flag Then MoveMemory ByVal pFunc, ByVal VarPtr(OriginBytes(0)), 6
  31. End Sub
  32.  
  33. Public Function Hook() As Boolean
  34. Dim TmpBytes(0 To 5) As Byte
  35. Dim p As LongPtr
  36. Dim OriginProtect As LongPtr
  37.  
  38. Hook = False
  39.  
  40. pFunc = GetProcAddress(GetModuleHandleA("user32.dll"), "DialogBoxParamA")
  41.  
  42.  
  43. If VirtualProtect(ByVal pFunc, 6, PAGE_EXECUTE_READWRITE, OriginProtect) <> 0 Then
  44.  
  45. MoveMemory ByVal VarPtr(TmpBytes(0)), ByVal pFunc, 6
  46. If TmpBytes(0) <> &H68 Then
  47.  
  48. MoveMemory ByVal VarPtr(OriginBytes(0)), ByVal pFunc, 6
  49.  
  50. p = GetPtr(AddressOf MyDialogBoxParam)
  51.  
  52. HookBytes(0) = &H68
  53. MoveMemory ByVal VarPtr(HookBytes(1)), ByVal VarPtr(p), 4
  54. HookBytes(5) = &HC3
  55.  
  56. MoveMemory ByVal pFunc, ByVal VarPtr(HookBytes(0)), 6
  57. Flag = True
  58. Hook = True
  59. End If
  60. End If
  61. End Function
  62.  
  63. Private Function MyDialogBoxParam(ByVal hInstance As LongPtr, _
  64. ByVal pTemplateName As LongPtr, ByVal hWndParent As LongPtr, _
  65. ByVal lpDialogFunc As LongPtr, ByVal dwInitParam As LongPtr) As Integer
  66.  
  67. If pTemplateName = 4070 Then
  68. MyDialogBoxParam = 1
  69. Else
  70. RecoverBytes
  71. MyDialogBoxParam = DialogBoxParam(hInstance, pTemplateName, _
  72. hWndParent, lpDialogFunc, dwInitParam)
  73. Hook
  74. End If
  75. End Function
  76.  
  77.  
  78. Sub unprotected()
  79. If Hook Then
  80. MsgBox "VBA Project is unprotected!", vbInformation, "*****"
  81. End If
  82. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement