def extract_chromium_plugins(self, parent_dir): ret_list = [] extension_dirs = os.listdir(parent_dir) for extension_dir in extension_dirs: extension_path = os.path.join(parent_dir, extension_dir) if not os.path.isdir(extension_path): core.updatelog("Invalid extension directory: " + extension_path) continue extension_vers = os.listdir(extension_path) for ver in extension_vers: manifest_file = helper.fixpath(extension_path + "/" + ver + "/manifest.json") if not os.path.isfile(manifest_file): core.updatelog("Invalid extension directory: " + extension_path) continue ext_name = core.GetNameFromManifest(manifest_file) if ext_name: ext_version = ver.split('_')[0] ext_name = ext_name + ' version ' + ext_version # small hack to not let commas f**k around with the path ext_name = ext_name.replace(",", ",") ret_list.append(ext_name + ',' + helper.fixpath(extension_path + "/" + ver)) return ret_list
def googlechrome(self): # TODO: add support for mac os chrome_directory = "" if self.os == 'windows': chrome_directory = helper.fixpath( self.user_directory + '\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Extensions' ) elif self.os == 'linux': chrome_directory = helper.fixpath( self.user_directory + '/.config/google-chrome/Default/Extensions') if chrome_directory != "": if os.path.isdir(chrome_directory): core.updatelog('Found Google chrome extension directory: ' + chrome_directory) extension_dirs = os.listdir(chrome_directory) for extension_dir in extension_dirs: # print('\n\n') if os.path.isdir( os.path.join(chrome_directory, extension_dir)): # Every extension directory is like this: Extension/<id>/<version>/{contents} extension_path = os.path.join(chrome_directory, extension_dir) extension_vers = os.listdir(extension_path) for ver in extension_vers: manifest_file = helper.fixpath(extension_path + "/" + ver + '/manifest.json') if os.path.isfile(manifest_file): ext_name = core.GetNameFromManifest( manifest_file) if ext_name != False and ext_name != None: # append version with name ext_version = ver.split('_')[0] ext_name = ext_name + ' version ' + ext_version self.chrome_extensions.append( ext_name + ',' + helper.fixpath(extension_path + "/" + ver)) else: core.updatelog( 'Could not determine extension name.. skipping local chrome extension' ) else: core.updatelog( 'Invalid extension directory: ' + extension_path) return self.chrome_extensions else: core.updatelog('Could not find google chrome directory!') return False else: core.updatelog('Unsupported OS')
def createFirefoxListing(self, extension_directory, xpi_file): list_file = os.path.join(extension_directory, 'extanalysis.json') xpi_directory = os.path.join(extension_directory, xpi_file) if os.path.isfile(xpi_directory) and os.path.isfile(list_file): # extract the xpi file get name from manifest and delete the extract directory extract_directory = os.path.join( extension_directory, 'extanalysis_temp_directory_delete_if_not_done_automatically') try: core.updatelog('Trying to unzip xpi: ' + xpi_file) zip_contents = zipfile.ZipFile(xpi_directory, 'r') zip_contents.extractall(extract_directory) zip_contents.close() core.updatelog('Unzipped xpi successfully: ' + xpi_directory) xpi_manifest = os.path.join(extract_directory, 'manifest.json') if os.path.isfile(xpi_manifest): ext_name = core.GetNameFromManifest(xpi_manifest) if ext_name != False or ext_name != None: # DO shits core.updatelog(xpi_file + ' has the name: ' + ext_name + ' adding it to the list') list_content = open(list_file, 'r') list_content = list_content.read() list_content = json.loads(list_content) list_content['extensions'][xpi_file] = ({ "name": ext_name, "file": xpi_directory }) list_write = open(list_file, 'w+') list_write.write( json.dumps(list_content, indent=4, sort_keys=True)) list_write.close() core.updatelog( 'List updated! Deleting temp extract directory') shutil.rmtree(extract_directory) core.updatelog('Removed temp extract directory') return True else: core.updatelog( 'Could not file extension name hence it will not be added to the list' ) else: core.updatelog( 'No manifest file found after extracting xpi! Deleting temp extract directory' ) shutil.rmtree(extract_directory) core.updatelog('Removed temp extract directory') return False except Exception as e: core.updatelog('Error unzipping xpi file: ' + xpi_directory) logging.error(traceback.format_exc()) return False