有没有办法在Excel VBA项目中破解密码? [英] Is there a way to crack the password on an Excel VBA Project?
问题描述
我被要求更新一些Excel 2003宏,但VBA项目受密码保护,似乎缺少文档...没有人知道密码。
有没有办法在VBA项目中删除或破解密码?
你可以试试这个直接 VBA
方法,不需要HEX编辑。它将适用于任何文件(* .xls,* .xlsm,* .xlam ...)。
测试和工作在
Excel 2007
Excel 2010
Excel 2013 - 32位版本。
Excel 2016 - 32位版本。
寻找64位版本?请参阅 https://stackoverflow.com/a/31005696/4342479
它的工作原理
我会尽力解释它是如何工作的 - 请原谅我的英文。
- Excel将调用系统函数创建密码对话框。
- 如果用户输入正确的密码并单击确定,此功能返回1.如果用户输入错误的密码或单击取消,该功能将返回0。
- 关闭对话框后,Excel将检查系统函数的返回值
- 如果此值为1,Excel将认为该密码是正确的,因此锁定的VBA项目将被打开。
- 下面的代码交换用于显示密码对话框的原始函数的内存,用户定义的函数将在调用时始终返回1。
使用代码
- 打开包含已锁定的VBA项目的文件
-
创建一个新的xlsm文件,并将此代码存储在 Module1 / p>
代码记入Siwtom(昵称),越南开发商
Option Explicit
Private Const PAGE_EXECUTE_READWRITE =& H40
私有声明Sub MoveMemory Libkernel32别名RtlMoveMemory _
(目的地长,源长,ByVal长度)
私有声明函数VirtualProtect Libkernel32(lpAddress As Long,_
ByVal dwSize As Long, ByVal flNewProtect As Long,lpflOldProtect As Long $ a
私有声明函数GetModuleHandleA Libkernel32(ByVal lpModuleName As String)As Long
私有声明函数GetProcAddress Libkernel32 (ByVal hModule As Long,_
ByVal lpProcName As String)As Long
私有声明函数DialogBoxParam Libuser32别名DialogBoxParamA(ByVal hInstance As Long,_
ByVal pTemplateName As Long,ByVal hWndParent As Long,_
ByVal lpDialogFunc As Long,ByVal dwInitParam As Long)As Integer
Dim HookBytes(0到5)As Byte
Dim OriginBytes(0到5)As Byte
Dim pFunc As Long
Dim Flag As Boolean
私有函数GetPtr(ByVal Value As Long)As Long
GetPtr = Value
结束函数
Public Sub RecoverBytes()
如果Flag Then MoveMemory ByVal pFunc,ByVal VarPtr(OriginBytes(0)),6
End Sub
公共函数Hook()As Boolean
Dim TmpBytes(0到5)As Byte
Dim p As Long
Dim OriginProtect As Long
Hook = False
pFunc = GetProcAddress(GetModuleHandleA(user32.dll ),DialogBoxParamA)
如果VirtualProtect(ByVal pFunc,6,PAGE_EXECUTE_READWRITE,OriginProtect) 0然后
MoveMemory ByVal VarPtr(TmpBytes(0)),ByVal pFunc,6
如果TmpBytes(0) & H68然后
MoveMemory ByVal VarPtr(OriginBytes(0)),ByVal pFunc,6
p = GetPtr(AddressOf MyDialogBoxParam)
HookBytes 0)=& H68
MoveMemory ByVal VarPtr(HookBytes(1)),ByVal VarPtr(p),4
HookBytes(5)=& HC3
MoveMemory ByVal pFunc ,ByVal VarPtr(HookBytes(0)),6
Flag = True
Hook = True
End If
End If
End Function
私有函数MyDialogBoxParam(ByVal hInstance As Long,_
ByVal pTemplateName As Long,ByVal hWndParent As Long,_
ByVal lpDialogFunc As Long,ByVal dwInitParam As Long)As Integer
如果pTemplateName = 4070然后
MyDialogBoxParam = 1
Else
RecoverBytes
MyDialogBoxParam = DialogBoxParam(hInstance,pTemplateName,_
hWndParent,lpDialogFunc,dwInitParam)
H ook
如果
结束函数
-
将此代码粘贴到 Module2 并运行
Sub unprotected()
如果Hook Then
MsgBox VBA项目无保护!,vb信息*****
如果
End Sub
-
回到您的VBA项目,享受。
I've been asked to update some Excel 2003 macros, but the VBA projects are password protected, and it seems there's a lack of documentation... no-one knows the passwords.
Is there a way of removing or cracking the password on a VBA project?
You can try this direct VBA
approach which doesn't require HEX editing. It will work for any files (*.xls, *.xlsm, *.xlam ...).
Tested and works on
Excel 2007
Excel 2010
Excel 2013 - 32 bit version.
Excel 2016 - 32 bit version.
Looking for 64 bit version? See https://stackoverflow.com/a/31005696/4342479
how it works
I will try my best to explain how it works - please excuse my english.
- Excel will call a system function to create the password dialog box.
- If user enters the right password and click OK, this function returns 1. If user enters the wrong password or click Cancel, this function returns 0.
- After the dialog box is closed, Excel checks the returned value of the system function
- if this value is 1, Excel will "think" that the password is right, hence the locked VBA project will be opened.
- The code below swaps the memory of the original function used to display the password dialog with a user defined function that will always return 1 when being called.
using the code
- Open the file(s) that contain your locked VBA Projects
Create a new xlsm file and store this code in Module1
code credited to Siwtom (nick name), a Vietnamese developer
Option Explicit Private Const PAGE_EXECUTE_READWRITE = &H40 Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Long, Source As Long, ByVal Length As Long) Private Declare Function VirtualProtect Lib "kernel32" (lpAddress As Long, _ ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long Private Declare Function GetModuleHandleA Lib "kernel32" (ByVal lpModuleName As String) As Long Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _ ByVal lpProcName As String) As Long Private Declare Function DialogBoxParam Lib "user32" Alias "DialogBoxParamA" (ByVal hInstance As Long, _ ByVal pTemplateName As Long, ByVal hWndParent As Long, _ ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Integer Dim HookBytes(0 To 5) As Byte Dim OriginBytes(0 To 5) As Byte Dim pFunc As Long Dim Flag As Boolean Private Function GetPtr(ByVal Value As Long) As Long GetPtr = Value End Function Public Sub RecoverBytes() If Flag Then MoveMemory ByVal pFunc, ByVal VarPtr(OriginBytes(0)), 6 End Sub Public Function Hook() As Boolean Dim TmpBytes(0 To 5) As Byte Dim p As Long Dim OriginProtect As Long Hook = False pFunc = GetProcAddress(GetModuleHandleA("user32.dll"), "DialogBoxParamA") If VirtualProtect(ByVal pFunc, 6, PAGE_EXECUTE_READWRITE, OriginProtect) <> 0 Then MoveMemory ByVal VarPtr(TmpBytes(0)), ByVal pFunc, 6 If TmpBytes(0) <> &H68 Then MoveMemory ByVal VarPtr(OriginBytes(0)), ByVal pFunc, 6 p = GetPtr(AddressOf MyDialogBoxParam) HookBytes(0) = &H68 MoveMemory ByVal VarPtr(HookBytes(1)), ByVal VarPtr(p), 4 HookBytes(5) = &HC3 MoveMemory ByVal pFunc, ByVal VarPtr(HookBytes(0)), 6 Flag = True Hook = True End If End If End Function Private Function MyDialogBoxParam(ByVal hInstance As Long, _ ByVal pTemplateName As Long, ByVal hWndParent As Long, _ ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Integer If pTemplateName = 4070 Then MyDialogBoxParam = 1 Else RecoverBytes MyDialogBoxParam = DialogBoxParam(hInstance, pTemplateName, _ hWndParent, lpDialogFunc, dwInitParam) Hook End If End Function
Paste this code in Module2 and run it
Sub unprotected() If Hook Then MsgBox "VBA Project is unprotected!", vbInformation, "*****" End If End Sub
Come back to your VBA Projects and enjoy.
这篇关于有没有办法在Excel VBA项目中破解密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!