Created
August 6, 2015 19:56
-
-
Save ahplummer/eed555f3f6739806eff4 to your computer and use it in GitHub Desktop.
Patches Microsoft Access ADP files when the 'AllowBypasskey' setting is set to false. This patch will force it to true, thus allowing the user to hit 'shift' key and bypass startup code as normal with Access.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import shutil | |
import os | |
def inplace_change(filename, old_string, new_string,debug): | |
with open(filename, mode='rb') as file: # b is important -> binary | |
fileContent = file.read() | |
if old_string in fileContent: | |
if debug == False: | |
print ('Changing "{old_string}" to "{new_string}"'.format(**locals())) | |
fileContent=fileContent.replace(old_string, new_string) | |
newfile=open(filename, 'wb') | |
newfile.write(fileContent) | |
newfile.flush() | |
newfile.close() | |
else: | |
print ('Due to debug, did not change "{old_string}" to "{new_string}"'.format(**locals())) | |
else: | |
print ('No occurances of "{old_string}" found'.format(**locals())) | |
parser = argparse.ArgumentParser(description='Checks Access ADP file and patches to allowbypass key') | |
parser.add_argument('-file','--file',help='File',required=True) | |
parser.add_argument('-debug','--debug',help='Debug',required=False) | |
args = vars(parser.parse_args()) | |
debug = False | |
if args['debug'] != None and args['debug'].upper() == 'TRUE': | |
debug = True | |
filename = args['file'] | |
basefilename = os.path.basename(filename) | |
workingfilename = os.path.dirname(filename) + os.path.sep + basefilename + '-HACKED' + os.path.splitext(basefilename)[1] | |
#copy file to working version. | |
shutil.copyfile(filename, workingfilename) | |
oldstring = '\x41\x00\x6c\x00\x6c\x00\x6f\x00\x77\x00\x42\x00\x79\x00\x70\x00\x61\x00\x73\x00\x73\x00\x4b\x00\x65\x00\x79\x00\x00\x00\x00\x00' | |
newstring = '\x41\x00\x6c\x00\x6c\x00\x6f\x00\x77\x00\x42\x00\x79\x00\x70\x00\x61\x00\x73\x00\x73\x00\x4b\x00\x65\x00\x79\x00\xff\xff\xff\xff' | |
inplace_change(workingfilename, oldstring, newstring, debug) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has been verified with MSAccess 2010