Skip to content

Commit 7757959

Browse files
authored
Create 64bit version
added 64 bit version
1 parent 7b3a4b0 commit 7757959

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

64bit version

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 11) As Byte
21+
Dim OriginBytes(0 To 11) 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)), 12
31+
End Sub
32+
33+
Public Function Hook() As Boolean
34+
Dim TmpBytes(0 To 11) As Byte
35+
Dim p As LongPtr, osi As Byte
36+
Dim OriginProtect As LongPtr
37+
38+
Hook = False
39+
40+
#If Win64 Then
41+
osi = 1
42+
#Else
43+
osi = 0
44+
#End If
45+
46+
pFunc = GetProcAddress(GetModuleHandleA("user32.dll"), "DialogBoxParamA")
47+
48+
If VirtualProtect(ByVal pFunc, 12, PAGE_EXECUTE_READWRITE, OriginProtect) <> 0 Then
49+
50+
MoveMemory ByVal VarPtr(TmpBytes(0)), ByVal pFunc, osi + 1
51+
If TmpBytes(osi) <> &HB8 Then
52+
53+
MoveMemory ByVal VarPtr(OriginBytes(0)), ByVal pFunc, 12
54+
55+
p = GetPtr(AddressOf MyDialogBoxParam)
56+
57+
If osi Then HookBytes(0) = &H48
58+
HookBytes(osi) = &HB8
59+
osi = osi + 1
60+
MoveMemory ByVal VarPtr(HookBytes(osi)), ByVal VarPtr(p), 4 * osi
61+
HookBytes(osi + 4 * osi) = &HFF
62+
HookBytes(osi + 4 * osi + 1) = &HE0
63+
64+
MoveMemory ByVal pFunc, ByVal VarPtr(HookBytes(0)), 12
65+
Flag = True
66+
Hook = True
67+
End If
68+
End If
69+
End Function
70+
71+
Private Function MyDialogBoxParam(ByVal hInstance As LongPtr, _
72+
ByVal pTemplateName As LongPtr, ByVal hWndParent As LongPtr, _
73+
ByVal lpDialogFunc As LongPtr, ByVal dwInitParam As LongPtr) As Integer
74+
75+
If pTemplateName = 4070 Then
76+
MyDialogBoxParam = 1
77+
Else
78+
RecoverBytes
79+
MyDialogBoxParam = DialogBoxParam(hInstance, pTemplateName, _
80+
hWndParent, lpDialogFunc, dwInitParam)
81+
Hook
82+
End If
83+
End Function
84+
85+
Sub unprotected()
86+
If Hook Then
87+
MsgBox "VBA Project is unprotected!", vbInformation, "*****"
88+
End If
89+
End Sub

0 commit comments

Comments
 (0)