Exemplo n.º 1
0
 def _get_files_from_paths(self, paths):
     files = list()
     for path in paths:
         if os.path.isfile(path) and self._file_parser.is_media_file(path):
             file = File(path=path)
             if not os.path.exists(file.sub_absolute_path):
                 files.append(file)
         else:
             for item in os.listdir(path):
                 item_path = os.path.join(path, item)
                 if os.path.isfile(
                         item_path) and self._file_parser.is_media_file(
                             item_path):
                     file = File(path=item_path)
                     if not os.path.exists(file.sub_absolute_path):
                         files.append(file)
     return files
Exemplo n.º 2
0
    def doNameToNum(self):
        allMethodCallNameMap = {}
        for aSmali in self.accessSmaliSet.keys():
            self.accessSmaliSet[aSmali].createNameMap()
            callNameMap = self.accessSmaliSet[aSmali].methodCallNameMap
            for callName in callNameMap.keys():
                if callName not in allMethodCallNameMap.keys():
                    allMethodCallNameMap[callName] = callNameMap[callName]
                else:
                    raise ValueError("method call name map duplicate")

        for s in self.smaliList:
            sFile = File(os.path.join(self.path, s))
            sName = Smali.getSmaliName(s)
            if sName in self.accessSmaliSet.keys():
                sFile.replaces(self.accessSmaliSet[sName].methodDefNameMap)
            sFile.replaces(allMethodCallNameMap)
Exemplo n.º 3
0
 def dumpMap(self):
     """
         smalirootname.data:
 	    smaliname accessname accessnum
     """
     dumpStr = ""
     for sName in self.accessSmaliSet.keys():
         nameSet = self.accessSmaliSet[sName].methodNameSet
         for name in nameSet.keys():
             dumpStr=(dumpStr+sName+" "+name+" "+nameSet[name]+"\n")
     File(os.path.join(self.path, self.name+".data")).dump(dumpStr)
Exemplo n.º 4
0
def get_batch_paths(root_path, batch_size):
    paths = []
    for root, _, files in os.walk(root_path):
        for file_name in files:
            if len(paths) >= batch_size:
                break

            file_path = root + '\\' + file_name
            paths.append(File(file_path, file_name))

    return paths
Exemplo n.º 5
0
	def make_process(self):
		"""Performs specific processing depending on the arguments."""
		if self.subarg == 'check':
			hashtype = self.args.type or get_hashtype_from_string_length(self.args.HASH_SUM)

			if hashtype is None:
				e = Errors(to_exit=True, error_type='input error')
				e.print_error('the hash type was not recognized, please specify it using -t/--type <TYPE>',
				f'Available Hash Types: {", ".join(Process.HASHTYPES_LIST)}')

			self._process.checkfile(
				file=File(self.args.FILE, self.args.HASH_SUM),
				hashtype=hashtype, verbosity=self.args.verbose)
		elif self.subarg == 'calc':
			files = [File(fname) for fname in self.args.FILES]

			if self.args.type != 'all':
				self._process.calculate_hash_sum(
					files=files, verbosity=self.args.no_verbose,
					hashtype=self.args.type)
				if self.args.write:
					self._process.write(files, self.args.type, self.args.name)
			else:
				self._process.totalcheck(files)
		elif self.subarg == 'read':
			t = TextFile(self.args.filename)
			contents = t.get_content()

			if not any(contents):
				e = Errors(to_exit=True, error_type='reading error')
				e.print_error(f'{self.args.filename!r} is empty!')
			elif len(contents) == 1:
				self._process.checkfile(
					file=File(*contents[0]),
					hashtype=self.args.type or get_hashtype_from_filename(self.args.filename),
					verbosity=self.args.verbose)
			else:
				self._process.checkfiles(
					files=[File(*file_attrs) for file_attrs in contents],
					hashtype=self.args.type or get_hashtype_from_filename(self.args.filename),
					verbosity=self.args.verbose)
Exemplo n.º 6
0
 def create(self, path="", name=None) -> dict:
     if not self.file_tree.exist(path):
         error_str = "{}: No such directory".format(path)
         logging.error(error_str)
         return {"success": False, "message": error_str}
     if self.file_tree.exist("{}/{}".format(path, name)):
         error_str = "{}/{}: File already exist".format(path, name)
         logging.error(error_str)
         return {"success": False, "message": error_str}
     new_fid = self.file_id_manager.request_id()
     newfile = File(name, fid=new_fid)
     self.file_table[newfile.fid] = newfile
     self.file_tree.create(path, new_fid, name)
     self.fid_to_path[new_fid] = "{}/{}".format(path, name)
     return {"success": True, "message": newfile.fid}
Exemplo n.º 7
0
    def doNumToName(self):
        allMethodCallNumMap = {}
        for sName in self.accessSmaliSet.keys():
            callNumMap = self.accessSmaliSet[sName].methodCallNumMap
            for callNum in callNumMap.keys():
                if callNum not in allMethodCallNumMap.keys():
                    allMethodCallNumMap[callNum] = callNumMap[callNum]
                else:
                    raise ValueError("method call num map duplicate")

        for s in self.smaliList:
            sFile = File(os.path.join(self.path, s))
            sName = Smali.getSmaliName(s)
            if sName in self.accessSmaliSet.keys():
                sFile.replaces(self.accessSmaliSet[sName].methodDefNumMap)
            sFile.replaces(allMethodCallNumMap)
Exemplo n.º 8
0
    def doNameToNum(self):
        allMethodCallNameMap = {}
        for aSmali in self.accessSmaliSet.keys():
            self.accessSmaliSet[aSmali].createNameMap()
            callNameMap = self.accessSmaliSet[aSmali].methodCallNameMap
            for callName in callNameMap.keys():
                if callName not in allMethodCallNameMap.keys():
                    allMethodCallNameMap[callName] = callNameMap[callName]
                else:
                    raise ValueError("method call name map duplicate")

        for s in self.smaliList:
            sFile = File(os.path.join(self.path, s))
            sName = Smali.getSmaliName(s)
            if sName in self.accessSmaliSet.keys():
                sFile.replaces(self.accessSmaliSet[sName].methodDefNameMap)
            sFile.replaces(allMethodCallNameMap)