Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (33 sloc) 1.31 KB
from shutil import copyfile
from zipfile import ZipFile
import os
def replace_val(s, key, new_val):
start = s.index(f'{key}="')
end = s.index('"', start + 5)
s = s.replace(s[start:end+1], f'{key}="{new_val}"')
return s
metadata = {
'CMG': '82802EAEB4B2B4B2B0B6B0B6',
'DPB': '0406A830A8AFC5AFC5503BB0C5E451A1601C8376D39507149E04DBDE9B2528620BA427CCE0E6',
'GC': '86842AB22EB6B1B7B1B7B1',
}
f = input('Enter Filename of xlsm file: ')
new_filename = f[:f.index('.xlsm')] + '.zip'
copyfile(f, new_filename)
with ZipFile('new_arc.zip', 'w') as new_arc:
with ZipFile(new_filename, 'r') as zip:
for file in zip.namelist():
if file != 'xl/vbaProject.bin':
with new_arc.open(file, 'w') as new_file:
with zip.open(file, 'r') as old_file:
new_file.write(old_file.read())
with new_arc.open('xl/vbaProject.bin', 'w') as new_config:
with zip.open('xl/vbaProject.bin') as config:
old_s = config.read()
s = old_s.decode('ansi')
for key, val in metadata.items():
s = replace_val(s, key, val)
s = s.encode('ansi')
new_config.write(s)
os.rename('new_arc.zip', f'{f[:f.index(".xlsm")]} - Unlocked.xlsm')
os.remove(new_filename)
You can’t perform that action at this time.