from setuphelpers import *
import datetime
import sys
uninstallkey = []
def is_locked(filename):
"""Check if a file is locked"""
if isfile(filename):
try:
open(filename,'r')
return False
except IOError as e:
if e.errno == 13:
return True
raise
else:
return False
def get_adobe_versions(rootkey=HKEY_CURRENT_USER,prof=''):
try:
with reg_openkey_noredir(rootkey,makepath(prof,'Software','Adobe','Acrobat Reader')) as adobe:
return list(reg_enum_subkeys(adobe))
except:
return []
def disable_js(rootkey=HKEY_CURRENT_USER,prof='',version='DC'):
with reg_openkey_noredir(rootkey,makepath(prof,'Software','Adobe','Acrobat Reader',version,'JSPrefs'),sam=KEY_ALL_ACCESS,create_if_missing=True) as jsprefs:
reg_setvalue(jsprefs,'bEnableGlobalSecurity',1,type=REG_DWORD)
reg_setvalue(jsprefs,'bEnableJS',0,type=REG_DWORD)
def install():
for version in set(get_adobe_versions(HKEY_USERS,'.DEFAULT')+['DC']):
disable_js(HKEY_USERS,'.DEFAULT')
profiles_path = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
for profsid in reg_enum_subkeys(reg_openkey_noredir(HKEY_LOCAL_MACHINE,profiles_path)):
if not profsid.startswith('S-1-5-21-'):
continue
profpath = get_profile_path(profsid)
if isdir(profpath):
try:
ntuserdat_path = makepath(profpath,'NTUSER.DAT')
if is_locked(ntuserdat_path):
regkey = profsid
else:
regkey = "profilemig_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S')
try:
if regkey != profsid :
print('Load user registry %s into %s' % (ntuserdat_path,regkey))
run(['reg','load','HKEY_USERS\\%s'%regkey,ntuserdat_path])
for version in set(get_adobe_versions(HKEY_USERS,regkey)+['DC']):
print('Disable for version %s'%version)
disable_js(HKEY_USERS,regkey,version)
finally:
if regkey != profsid:
run_notfatal(['reg','unload','HKEY_USERS\\%s'%regkey])
except Exception as e:
print(registry_readstring(HKEY_LOCAL_MACHINE,r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%s' % 'S-1-5-21-2962184097-1786842987-440159514-1029','ProfileImagePath'))
print('Unable to process profile %s: %s' % (profpath,repr(e)))
def session_setup():
print('Disabling JS in Adobe Reader DC')
registry_setstring(HKEY_CURRENT_USER,r"SOFTWARE\Adobe\Acrobat Reader\DC\JSPrefs",'bEnableGlobalSecurity',1,type=REG_DWORD)
registry_setstring(HKEY_CURRENT_USER,r"Software\Adobe\Acrobat Reader\DC\JSPrefs",'bEnableJS',0,type=REG_DWORD)
def update_package():
version = control.version.split('-')[0]
control.version = '%s-%s'%(version,int(control.version.split('-')[-1])+1)
control.save_control_to_wapt()
print('Changing version to: %s in WAPT\\control' % control.version)