tis-disable-js-adobe 13

  • package : tis-disable-js-adobe
  • version : 13
  • description : Disable Javascript in Adobe Reader
  • maintainer : Hubert TOUVET
  • date : 2018-02-27 18:58:39

setup.py

# -*- coding: utf-8 -*-
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')

    # change settings in all profiles
    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

        print profsid
        profpath = get_profile_path(profsid)
        if isdir(profpath):
            try:
                ntuserdat_path = makepath(profpath,u'NTUSER.DAT')

                if is_locked(ntuserdat_path):
                    regkey = profsid
                else:
                    regkey = u"profilemig_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S')

                try:
                    if regkey != profsid :
                        print(u'Load user registry %s into %s' % (ntuserdat_path,regkey))
                        run([u'reg',u'load',u'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([u'reg',u'unload',u'HKEY_USERS\\%s'%regkey])
            except Exception as e:
                print registry_readstring(HKEY_LOCAL_MACHINE,ur'SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%s' % u'S-1-5-21-2962184097-1786842987-440159514-1029',u'ProfileImagePath')
                print(u'Unable to process profile %s: %s' % (profpath,repr(e)))

def session_setup():
    for version in set(get_adobe_versions(HKEY_CURRENT_USER,regkey)+['DC']):
        disable_js(HKEY_CURRENT_USER,'',version)

    

Changelog

No changelog
    

manifest.sha256

[["setup.py", "176a96a74d785d2b8864d680b7e83a7e82749bbdd8845e2262cd20c91122bffe"], ["WAPT/certificate.crt", "79e5388683c0b6cb03f4f81e4e58e3a11463b2b6cf169dd9c453098027dcfaa4"], ["WAPT/wapt.psproj", "795d36d10109ca85357285f79090fac2be856e5830ea31fa913cc55cb825807b"], ["WAPT/control", "ac2f314ea4858f8202d25666e4f066a7c15a7d2485c6581e6bbfc7bb0a440f43"]]