def __init__(self):
     self.mixer = Mixer()
     self.remove = Remove()
     self.utils = Utils()
 def __init__(self):
     self.mixer = Mixer()
     self.utils = Utils()
     self.simpleSpace = " "
예제 #3
0
 def __init__(self):
     self.mixer = Mixer()
     self.utils = Utils()
     self.pythonExcludeDefaultString = "exclude/string_to_string_mixed/exclude_word_do_not_modify.txt"
     self.pythonExcludeUserString = "exclude/string_to_string_mixed/exclude_word_by_user.txt"
     self.pythonExcludeUserFileName = "exclude/file_name/exclude_file_name_by_user.txt"
예제 #4
0
 def __init__(self):
     self.mixer              = Mixer()
     self.remove             = Remove()
     self.utils              = Utils()
     self.pythonExcludeWords = "exclude_python_words.txt"
     self.pythonIncludeWords = "include_python_words.txt"
예제 #5
0
    def FilesName(self, codeArg, outputArg, mixerLevelArg, verboseArg):
        filesNameDict           = {}
        filesNameDictNoExt      = {}
        filesNameFound          = []
        filesNameFoundNoExt     = []
        filesNameMixed          = []
        checkFilesFound         = []
        countRecursFiles        = 0
        checkRenameInDir        = 0
        checkRenameInCode       = 0
        unix                    = False
        win                     = False
        currentPosition         = os.getcwd()
        utils                   = Utils()
        mixer                   = Mixer()
        remove                  = Remove()

        if codeArg == "python":
            detectFiles = "py"
            blockDir    = "__pycache__"
            blockFile   = "__init__"

            detectImport = r"\s*from\s+|\s*import\s+"
    
        recursFiles = [f for f in glob.glob("{0}{1}**{1}*.{2}".format(outputArg, utils.Platform(), detectFiles), recursive=True)]

        for number in recursFiles:
                countRecursFiles += 1

        for file in recursFiles:
            if blockDir in file or blockFile in file:
                continue
            else:
                if "\"" in file:
                    parseFilePath = file.split("\"")
                    win = True
                else:
                    parseFilePath = file.split("/")
                    unix = True

                checkFilesFound.append(file)

                mixer = self.mixer.GetStringMixer(mixerLevelArg)
                filesNameDict[parseFilePath[-1]] = mixer + ".py" 
                filesNameDictNoExt[parseFilePath[-1].replace(".py", "")] = mixer
                
                filesNameFound.append(parseFilePath[-1])
                filesNameMixed.append(mixer + ".py")

                removeExt = parseFilePath[-1].replace(".py","")
                filesNameFoundNoExt.append(removeExt)
            
        # -- Diplay all files found with their mixed values if verbose arg is actived -- #
        if verboseArg:
            print("\n[+] Files name found with their mixed values :\n")
            for key, value in filesNameDict.items():
                print("-> {0} : {1}".format(key, value))
        
        print("\n[+] Running replace files name in {0} file(s)...\n".format(countRecursFiles))
        
        # -- Replace all files name to random strings with length defined -- #
        with tqdm.tqdm(total=countRecursFiles) as pbar:
            for file in recursFiles:
                pbar.update(1)
                if blockDir in file:
                    continue
                else:
                    # -- Rename all files in python code -- #
                    with fileinput.input(file, inplace=True) as inputFile:
                        for eachLine in inputFile:
                            try:
                                for fileName in filesNameFound:
                                   for fileNameNoExt in filesNameFoundNoExt:
                                        if fileName in eachLine or fileNameNoExt in eachLine:
                                            if not ".py" in eachLine:
                                                if re.match(detectImport, eachLine):
                                                    eachLine = Replace.EachLine(self, codeArg, eachLine, filesNameDictNoExt.items(), True)
                                                    print(eachLine)
                                                    raise BreakLoop
                                                else:
                                                    continue
                                            else: 
                                                eachLine = Replace.EachLine(self, codeArg, eachLine, filesNameDict.items(), True)
                                                print(eachLine)
                                                raise BreakLoop
                                        else:
                                            continue
                                print(eachLine) 
                            except BreakLoop:
                                continue

                    # -- Rename all files in their directories -- #
                    if "\"" in file:
                        parseFilePath = file.split("\"")
                        win = True
                    else:
                        parseFilePath = file.split("/")
                        unix = True

                    for key, value in filesNameDict.items():        
                        if key == parseFilePath[-1]:
                            parseFilePath.remove(parseFilePath[-1])
                            if unix == True:
                                parseFilePathToMove = "/".join(parseFilePath)
                            else:
                                parseFilePathToMove = "\"".join(parseFilePath)
                            os.chdir(parseFilePathToMove) # Move in directory to rename python file
                            os.rename(key, value)
                        else:
                            continue
                    os.chdir(currentPosition) # Return to old position   

        # -- Check if all files name are been replaced to random strings with length defined -- #    
        for i in checkFilesFound:
            i.replace(".py", "")

        # -- Check for file(s) name -- #
        for file in recursFiles:
            if blockDir in file or blockFile in file:
                continue
            else:
                for i in checkFilesFound:
                    if i in file:
                        checkFilesFound.remove(i)
                        continue

        # -- Check for code if file(s) name -- #
        if checkFilesFound != []:
            for file in recursFiles:
                if blockDir in file or blockFile in file:
                    continue
                else:
                    with open(file, "r") as inputFile:
                        for line in inputFile:
                            for i in checkFilesFound:
                                if i in line:
                                    checkFilesFound.remove(i)
                                    continue

        if checkFilesFound == []:
            if (remove.Backslashes(codeArg, outputArg) == 0):    
                return EXIT_SUCCESS        
            else:
                return EXIT_FAILURE
        else:
            return EXIT_FAILURE
예제 #6
0
    def StringsToHex(self, codeArg, outputArg, mixerLevelArg):
        getLetterLineList   = []
        countRecursFiles    = 0
        checkPrint          = 0
        checkHexError       = False
        checkPrintError     = False
        hexLine             = ""
        utils               = Utils()
        mixer               = Mixer()
        remove              = Remove()

        if codeArg == "python":
            detectFiles = "py"
            blockDir    = "__pycache__"

            detectExecFunc  = r"exec\(\w+\)"
            detectQuotes    = r"[\'|\"]{3}"

        recursFiles = [f for f in glob.glob("{0}{1}**{1}*.{2}".format(outputArg, utils.Platform(), detectFiles), recursive=True)]

        for number in recursFiles:
                countRecursFiles += 1

        print("\n[+] Running replace all strings to their hexadecimal value in {0} file(s)...\n".format(countRecursFiles))

        # -- Replace all strings to their hexadecimal value -- #
        with tqdm.tqdm(total=countRecursFiles) as pbar:
            for file in recursFiles:
                checkPrint = 0 # initialize check print() func at the begining of each file
                pbar.update(1)
                if blockDir in file:
                    continue
                else:
                    # -- Add a new first random line and move the old first line to the second line to avoid replacing it -- #
                    with open(file, "r") as inputFile:
                        stringRandomMixer   = mixer.GetStringMixer(mixerLevelArg)
                        firstLine           = "{0}\n".format(stringRandomMixer)
                        line                = inputFile.readlines()

                        line.insert(0, firstLine)

                    with open(file, "w") as inputFile:
                        inputFile.writelines(line)

                    # -- Replace all lines-- #
                    with fileinput.input(file, inplace=True) as inputFile:
                        for eachLine in inputFile:
                            if checkPrint == 0:
                                varMixer = mixer.GetStringMixer(mixerLevelArg)
                                print(varMixer + "=\"\"\"")
                                checkPrint = 1   
                            else:
                                getLetterLineList = [] # initialize list     
                                for letterLine in eachLine:
                                    letterToHex = "\\x" + str(letterLine.encode().hex())
                                    getLetterLineList.append(letterToHex) # Get list of all letters in line          
                                hexLine = "".join(getLetterLineList)
                                print(hexLine)

                    # -- Add exec funtions to interpret hex code in strings -- #
                    with open(file, "a") as inputFile:
                        inputFile.write("\"\"\"")
                        inputFile.write("\nexec({0})".format(varMixer))

        # -- Check if all lines are replaced of hexadecimal value -- #
        for file in recursFiles: 
            if blockDir in file:
                continue
            else:
                with open(file, "r") as inputFile:
                    for eachLine in inputFile:
                        if not eachLine:
                            continue
                        else:
                            if not "\\x" in eachLine:
                                if re.match(detectQuotes, eachLine):
                                    continue
                                elif re.match(detectExecFunc, eachLine):
                                    continue
                                else:
                                    checkError = True
                            else:
                                continue
            
        if (remove.Backslashes(codeArg, outputArg) == 0):
            if checkHexError == False:
                return EXIT_SUCCESS        
            else:
                return EXIT_FAILURE
        else:
            return EXIT_FAILURE
 def __init__(self):
     self.mixer  = Mixer()
     self.remove = Remove()
     self.utils  = Utils()
     self.pythonExcludeDefaultString = "exclude/string_to_string_mixed/exclude_word_do_not_modify.txt"
     self.pythonExcludeUserString    = "exclude/string_to_string_mixed/exclude_word_by_user.txt"