I'm currently coding a program that will remove macro passwords from Word files, Excel files etc. This is made for word documents with no normal standard password, but a password set on the macros from the Tools > Project Options > Protections
menu in Office.
I'm using method 3 on the below link to remove the password. However rather than editing it manually like method 3, I'm changing it via the Hex in method 2 but programmatically with VB. I have tested this method with a Hex editor and notepad ++ successfully. However notepad will not work.
Method of removing macro passwords
My Idea
- Change name of .docm to .zip
- Extract the contents of the Zip
- Open the Vbaproject.bin
- Change values from DPB to DPx
- Zip it back up
- Change format back .docm
I'm having issues with 4 as it changes the characters correctly in the output file, however it strips out other necessary content(special characters).
My vb.net code:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim filecontents = IO.File.ReadAllText("C:\Temp\Decrypter\Analysis\vbaProject.bin")
filecontents = filecontents.Replace(Convert.ToChar(&H44) & (Convert.ToChar(&H50) & (Convert.ToChar(&H42))), (Convert.ToChar(&H44) & Convert.ToChar(&H50) & (Convert.ToChar(&H78))))
IO.File.WriteAllText("C:\Temp\Decrypter\Analysis\vbaProject2.bin", filecontents)
Catch
MsgBox("Error")
End Try
End Sub
End Class
This code looks for DPB
in the vbaproject.bin file (44, 50, 42)
, then changes it to DPx (44, 50, 78)
. When opening the output document I can see the changes happened successfully, however when writing the .bin file back in to the .zip and repackaging in to the .docm this did not work. It works manually when I change these hex values via a hex editor.
I believe that the way it reads and writes the output file takes out all the special .bin characters. Similar to how following the above process with notepad on Windows does not work (perhaps certain textboxes can't read / see certain chars / values in different formats). However doing the same with notepad++ does work.
How can I change my above code so it doesn't strip out any special characters / other formats in the .bin file when I make the changes from DPB to DPx?
Any ideas are greatly appreciated!