如何反编译和重新编译数据库应用程序?
我有一个 Access 数据库应用程序,我想知道反编译和重新编译它的正确方法。
I have an Access database application and I would like to know the proper way of decompiling and recompiling it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
要反编译 Access 数据库,您需要创建包含以下元素的快捷方式:
所有这些都在一起,然后,快捷方式将如下所示:
显然,您的系统上的路径会有所不同。
我建议在运行此命令之前备份数据库。
如果数据库中有任何启动代码,您应该按住 Shift 键以绕过启动代码执行。
数据库打开后,您可以压缩和修复数据库以确保最佳性能。
压缩和修复后,您可以通过打开任何模块并使用
Debug Compile [DatabaseName]
命令来重新编译 VBA 代码。如果这是您想要经常执行的操作,您可以在 SendTo 菜单中创建“访问反编译”快捷方式。一旦“发送到”菜单中出现此快捷方式,您就可以右键单击任何 Access 数据库并选择“发送到 --> Access 反编译”,这比创建特定数据库的快捷方式要容易得多。
按照以下步骤使用 Access 反编译快捷方式自定义“发送到”菜单
创建 Access 可执行文件的快捷方式。
在快捷方式的目标中附加 /decompile 标志。快捷方式将如下所示:
“C:\Program Files\Microsoft Office\Office\MSACCESS.EXE”/反编译
打开 Windows 资源管理器并将以下内容粘贴到地址栏中:
%APPDATA%\Microsoft\Windows\SendTo
将您创建的快捷方式复制到 SendTo 文件夹中。
Access 反编译快捷方式现在可供使用。
要调用 Access 反编译快捷方式,请右键单击 Windows 资源管理器中的 Access 数据库,然后选择“发送到 --> Access 反编译”。请务必按住 Shift 键以绕过数据库中的任何启动代码。
To Decompile an Access database you'll need to create a shortcut with the following elements:
All together, then, the shortcut would look something like the following:
Obviously, the paths will be different on your system.
I'd recommend making a backup of your database before running this command.
If you have any startup code in your database you should hold down the shift key to bypass the startup code execution.
Once the database opens, you can compact and repair the database to ensure optimal performance.
After the compact and repair, you can recompile the VBA code by opening any module and using the
Debug Compile [DatabaseName]
command.If this is something you want to do frequently, you can create an "Access Decompile" shortcut in your SendTo Menu. Once you have this shortcut in the SendTo Menu you'll be able to right-click on any Access database and select "Send To --> Access Decompile", which is much easier than having to create a shortcut to the specific database.
Follow these steps to customize the Send To menu with an Access Decompile shortcut
Create a shortcut to the Access executable.
Append the /decompile flag in the Target for the shortcut. The shortcut will look like this:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" /decompile
Open Windows Explorer and paste the following into the address bar:
%APPDATA%\Microsoft\Windows\SendTo
Copy the shortcut you created into the SendTo Folder.
The Access Decompile Shortcut will now be available for use.
To invoke the Access Decompile shortcut, right click on an Access Database in Windows Explorer and select "Send To --> Access Decompile". Be sure to hold the shift key down to bypass any startup code in the database.
@Tim Lentine 的实用说明很好,但他遗漏了值得执行的反编译所需的实际步骤:
备份数据库。
压缩您的数据库。
使用按照 Tim 的指示创建的快捷方式,打开您的数据库。
关闭该 Access 实例。
打开一个新的 Access 实例并打开您刚刚反编译的数据库,但请确保绕过所有启动代码(即按住 Shift 键)。如果您不这样做,那么您不妨返回步骤 3 并重试,因为如果启动代码运行,您的代码将在您准备好之前重新编译。
压缩反编译的数据库(并确保按住 Shift 键,以便它绕过启动代码;请参阅#5)。
打开 VBE,然后在“调试”菜单上选择“编译 [项目名称]”。
在文件菜单上,保存项目。
再次紧凑。
为什么所有这些步骤都是必要的?
因为您不仅希望反编译 VBA,还希望确保在重新编译之前完全丢弃存储已编译 p 代码的所有数据页。
我还建议:
在 VBE 选项中,关闭 COMPILE ON DEMAND
在 VBE 中,将“编译”按钮添加到工具栏。
每两行或三行代码后,经常使用工具栏上的该按钮进行编译。
反编译不是你应该一直使用的东西,但是在繁重的编码过程中,我可能每天都会进行几次反编译。我通常将反编译/重新编译作为将应用程序发布到生产使用之前的最后一步。
最后,阅读 Michael Kaplan 关于该主题的文章可以更好地理解它。
@Tim Lentine's practical instructions are good, but he leaves out the actual steps required for a decompile to be worth doing:
backup your database.
compact your database.
using the shortcut created with Tim's instructions, open your database.
close that instance of Access.
open a new instance of Access and open the database you just decompiled, but BE SURE YOU BYPASS ALL STARTUP CODE (i.e., hold down the shift key). If you don't do that, then you might as well go back to step 3 and try again, since if the startup code runs, your code will recompile before you are ready to do so.
compact the decompiled database (and be sure you hold down the shift key so that it bypasses the startup code; see #5).
open the VBE and on the Debug menu, choose COMPILE [name of project].
on the file menu, save the project.
compact again.
Why are all these steps necessary?
Because you want to not just decompile the VBA, you want to make sure that all the data pages where the compiled p-code was stored are completely discarded before you recompile.
I also recommend:
in VBE options, turn off COMPILE ON DEMAND
in the VBE, add the COMPILE button to your toolbar.
compile often with that button on the toolbar, after every two or three lines of code.
Decompile is not something you should use all the time, but during heavy-duty coding, I might do a decompile a couple of times a day. And I generally decompile/recompile as the last step before releasing an app into production use.
Last of all, read Michael Kaplan's article on the subject to understand it better.
接受的答案很好,但是为每个数据库创建快捷方式有点不切实际。
您可以将其另存为 powershell 模块。
然后像这样调用它:
这使您可以从 power shell 命令行快速轻松地反编译任何数据库。
请注意,运行此命令时仍需要按住 Shift 键才能绕过应用程序启动。
The accepted answer is great, but it's a little impractical to create a shortcut for every database.
You can save this as a powershell module.
Then call it like this:
This allows you to quickly and easily decompile any db from the power shell command line.
Note that you still need to hold down the Shift key when you run this to bypass the application startup.
根据我的口味,这里的其他答案似乎都有点复杂。
要反编译 Access 数据库:
从开始菜单打开运行对话框,或点击Win + R
输入:
MSACCESS.EXE /decompile
(正确的安装应打开 Access 应用程序,您还可以提供 MSACCESS.EXE 的完整路径),然后按“确定”。访问现已开放。在刚刚打开的 Access 窗口中打开数据库。这将反编译它。
The other answers here all seem a little complex to my taste.
To decompile an Access database:
Open the Run dialog from the start menu, or hit Win + R
Type in:
MSACCESS.EXE /decompile
(a proper installation should open up the Access application, you could also provide the full path to MSACCESS.EXE), and press OK.Access now opens. Open up your DB in the Access window that just opened. That will decompile it.
我编写了一个 VBS 脚本来自动执行反编译过程。微软没有将其集成到 Access 中,这是愚蠢的,因为它是开发大量 VBA 应用程序时所必需的。
该脚本找到 MSACCESS.exe,并在位于脚本父目录中的数据库上运行带有反编译标志的 Access,该数据库的名称在代码中给出。
只需将此文本粘贴到扩展名为
.vbs
的文档中,然后双击即可运行。 Access 将启动、反编译已编译的 P 代码(“打包”代码),并自动将 VBA 源代码重新编译回 P 代码。I wrote a VBS script to automate the process of decompiling. It's silly that Microsoft hasn't integrated this into Access, considering it is a necessity when developing VBA-heavy applications.
The script locates MSACCESS.exe and runs Access with the decompile flag on a database located in the parent directory of the script, whose name is given in the code.
Simply paste this text into a document with a
.vbs
extension and double-click it to run. Access will launch, decompile the compiled P-code ("packed" code), and automatically recompile the VBA source back into P-code.或者,您可以在桌面上创建一个快捷方式(使用 /Decompile 标志),然后按住 SHIFT 拖放 Access 应用程序以绕过任何代码
Or simply you can create a shortcut on your Desktop (with the /Decompile Flag) and drag drop your Access application holding SHIFT to bypass any code