我被要求更新一些Excel 2003宏,但是VBA项目有密码保护,而且似乎缺乏文档…没人知道密码。

是否有一种方法可以删除或破解VBA项目的密码?


当前回答

我的工具VbaDiff直接从文件中读取VBA,因此您可以使用它从大多数办公文档中恢复受保护的VBA代码,而无需求助于十六进制编辑器。

其他回答

Access、Excel、Powerpoint或Word文档上的VBA项目密码(带有扩展名. accdb . xlsm . xltm . docm . dotm . potm . ppsm的2007、2010、2013或2016版本)可以轻松删除。

这只是将文件名扩展名更改为. zip,解压缩文件,并使用任何基本的十六进制编辑器(如XVI32)来“打破”现有密码的问题,这会“混淆”Office,因此它会在下次打开文件时提示输入新密码。

步骤总结:

rename the file so it has a .ZIP extension. open the ZIP and go to the XL folder. extract vbaProject.bin and open it with a Hex Editor "Search & Replace" to "replace all" changing DPB to DPX. Save changes, place the .bin file back into the zip, return it to it's normal extension and open the file like normal. ALT+F11 to enter the VB Editor and right-click in the Project Explorer to choose VBA Project Properties. On the Protection tab, Set a new password. Click OK, Close the file, Re-open it, hit ALT+F11. Enter the new password that you set.

此时,如果您愿意,您可以完全删除密码。

完整的说明和我制作的“way back when”视频在YouTube上。

令人震惊的是,这种解决方法已经存在多年了,而微软还没有解决这个问题。


这个故事的寓意是什么?

Microsoft Office VBA项目密码不依赖于任何敏感信息的安全。如果安全性很重要,请使用第三方加密软件。

万一你的街区 没有发生= \ r \ nDPB“XXXX”=“XXXXX”\ r \ nGC =“XXXXXX” 如果您的“已知密码”文件比“未知密码”文件中的现有块短,请用后面的零填充十六进制字符串以达到正确的长度。

e.g.

CMG=“xxxxxx”\r\nDPB=“xxxxx”\r\nGC=“xxxxx”

在未知密码文件中,应设置为

CMG="XXXX00"\r\nDPB="XXXXX000"\r\nGC="XXXXXX0000"保留文件长度。

我在office 2007中也使用过。xla(97/2003格式)文件。

我的工具VbaDiff直接从文件中读取VBA,因此您可以使用它从大多数办公文档中恢复受保护的VBA代码,而无需求助于十六进制编辑器。

事实上,大多数启用宏的Office文档的代码文件都没有加密,密码只会阻止使用Office程序打开项目。 这意味着,正如其他答案所建议的那样,您通常可以使用Office替代品来访问和编辑该文件。

但是,如果你只是需要访问代码,你可以使用oldump .py这样的工具来提取宏代码。这对于恶意软件分析非常有用,还可以从文件中获取大部分代码,这样如果忘记密码,就不必从头开始了。

此外,许多excel文件在打开时动态设置密码。这意味着如果您可以阅读代码,您通常可以找到明文密码或消除混淆。

oledump.py例子:

列出一个办公文档中的所有“流”(嵌入式二进制文件或代码文件):

python oledump.py -v yourExcelFile.xlsm

输出:

A: xl/vbaProject.bin
 A1:      2000 'PROJECT'
 A2:      1500 'PROJECTwm'
 A3: M    1224 'VBA/Module1'
 A4: M   18694 'VBA/Module2'
 A5: M   11877 'VBA/Module3'
...

旁边带M的流是宏,这是未加密的VBA代码

提取流

python oledump.py -s A3 -v yourExcelFile.xlsm > Module1.vba

这将把A3流中包含的代码输出到Module1.vba。

我通常将此与循环结合起来,将所有文件解压缩到一个文件夹中。这个快速的PowerShell脚本将提取大多数文件中的所有流:

New-Item -ItemType Directory "Output"

# just hardcode the highest stream outputted by oledump.py -v
$max = 5 
for ($i = 1; $i -le $max; $i++) {
    python oledump.py -s "A$i" -v yourExcelFile.xlsm > ".\Output\A$i"
}

注意,这将只提取人类可读的文件。

是的,只要你使用的是。xls格式的电子表格(2003年以前Excel的默认格式)。对于Excel 2007以后,默认是.xlsx,这是一个相当安全的格式,这个方法将不起作用。

正如Treb所说,这是一个简单的比较。一种方法是使用十六进制编辑器(参见Windows的十六进制编辑器)简单地交换文件中的密码条目。循序渐进的例子:

Create a new simple excel file. In the VBA part, set a simple password (say - 1234). Save the file and exit. Then check the file size - see Stewbob's gotcha Open the file you just created with a hex editor. Copy the lines starting with the following keys: CMG=.... DPB=... GC=... FIRST BACKUP the excel file you don't know the VBA password for, then open it with your hex editor, and paste the above copied lines from the dummy file. Save the excel file and exit. Now, open the excel file you need to see the VBA code in. The password for the VBA code will simply be 1234 (as in the example I'm showing here).

如果你需要使用Excel 2007或2010,下面有一些其他的答案可能会有帮助,特别是这些:1、2、3。

编辑2015年2月:另一种看起来很有前途的方法,看看Đức Thanh nguy的新答案。