Beispiel #1
0
 def direction_ergodic(self, path_object: WindowsPath, parentDir, n=0):
     dir_file: list = list(path_object.iterdir())
     dir_file.sort(key=lambda x: x.name.lower())
     for item in dir_file:
         if self.ignore_judge(item.name):
             if self.tree_add(item, parentDir, n):
                 self.direction_ergodic(item, parentDir + item.name + "/",
                                        n + 1)
Beispiel #2
0
    def get_subdirlist(cls, path: str):
        """
        Return list of subdirectories

        :param path: base pathname as r'string'
        :return: list of subdirectories
        """
        wpath = WindowsPath(path)
        return [f.name for f in wpath.iterdir() if f.is_dir()]
Beispiel #3
0
def refold_dir(path: pathlib.WindowsPath, newer_path: pathlib.WindowsPath):
    for p in path.iterdir():
        if p.is_dir():
            refold_dir(p, newer_path)
        else:

            if not checkdir(p):  # 下层无目录,则为最底层目录,移动
                shutil.move(p, newer_path)
            return
Beispiel #4
0
    def get_subdirlist(cls, path: str):
        """
        Return list of subdirectories

        :param path: base pathname as r'string'
        :return: list of subdirectories
        """
        wpath = WindowsPath(path)
        return [f.name for f in wpath.iterdir() if f.is_dir()]
Beispiel #5
0
 def direction_ergodic(self, path_object: WindowsPath, n=0):
     dir_file: list = list(path_object.iterdir())
     dir_file.sort(key=lambda x: x.name.lower())
     dir_file = [f for f in filter(self.filter_file, dir_file)]
     for i, item in enumerate(dir_file):
         if i + 1 == len(dir_file):
             if self.tree_add(item, n, last=True):
                 self.direction_ergodic(item, n + 1)
         else:
             if self.tree_add(item, n, last=False):
                 self.direction_ergodic(item, n + 1)
def pathlib_walk(p: pathlib.WindowsPath, outputs: pathlib.WindowsPath,
                 year: int) -> None:
    """ Проходить по папках з .json та перетворює їх на таблиці. """
    for directory in p.iterdir():
        files = [
            directory / file_name for file_name in directory.glob("*.json")
        ]
        param_type, save_name = directory.parts[-2:]
        cumulative_dict = get_cumulative(files, item_type=param_type)
        noncumulative = transform(cumulative_dict,
                                  item_type=param_type,
                                  year=year)
        noncumulative.to_csv(outputs / f"{save_name}.csv", index=False)
Beispiel #7
0
def checkdir(path: pathlib.WindowsPath):
    # 下层有目录则返回True,无目录返回False
    return bool([p for p in path.iterdir() if p.is_dir()])
Beispiel #8
0
 def start(features):
     arrayoffolder = []
     subdirs = WindowsPath(
         r'C:\\APKTOOL\\decompile by python\\1 decompiles all apk file in the same directory'
     )
     numberofapps = 0
     for f in subdirs.iterdir():
         if f.is_dir():
             numberofapps = numberofapps + 1
             arrayoffolder.append(f)
             #all folders of the apps are appened to array later we willneed when extract
             #permission from androidmanifest xml file.
     i = 0  #to count apps in same directory
     while i != numberofapps:
         for fl in arrayoffolder[i].iterdir():
             k = ('%s\AndroidManifest.xml' % arrayoffolder[i])
             print(fl)
             if filecmp.cmp(fl, k):
                 #to find androidmanifest file on the folder. compreing returns true when dir are same
                 root = ET.parse(fl).getroot()
                 permissions = root.findall("uses-permission")
                 permission_in_checking_app = []
                 #array to save all 1 s and 0 s to  write a file
                 for perm in permissions:
                     for att in perm.attrib:
                         permission_in_checking_app.append(
                             [perm.attrib[att]])
                 #line above add all permmissions to an array.
                     data = []
                     #data array will have 0's and 1's of apps if they have perm.1 if doesnt have 0 for present perm.
                     for f in range(
                             328
                     ):  #totally we have 328 permis. we need to scan all perms to decide
                         #if we put 0 or 1 to data array.
                         for r in range(len(permission_in_checking_app)):
                             if (features[f]) == (
                                     permission_in_checking_app[r]):
                                 #permission_in_checking_app contain permissions of the app that
                                 #we are going to check. it may contain 2 or 10 or 328 etc.
                                 data.append(
                                     '1'
                                 )  #if contain the permission 1 will be added to data
                             else:
                                 data.append(
                                     '0'
                                 )  #if doesnt contain the permission 0 will be added to data
                 with open('train_test.csv', 'r') as csvinput:
                     with open('handler_of_train_test_data.csv',
                               'w') as csvoutput:
                         writer = csv.writer(csvoutput, lineterminator='\n')
                         reader = csv.reader(csvinput)
                         all = [
                         ]  #we need another array that is named all it saves all data of a single app
                         #that will be writen on a a row.
                         row = next(reader)
                         row.append(
                             '1')  #first row is type: malware or bening
                         all.append(row)
                         n = 0
                         for row in reader:
                             row.append(data[n])
                             all.append(row)
                             n = n + 1
                         writer.writerows(all)
                         csvinput.close()
                         csvoutput.close()
                 with open('handler_of_train_test_data.csv',
                           'r') as csvinput:
                     with open('train_test.csv', 'w') as csvoutput:
                         writer = csv.writer(csvoutput, lineterminator='\n')
                         reader = csv.reader(csvinput)
                         writer.writerows(reader)
                         csvinput.close()
                         csvoutput.close()
         i = i + 1