예제 #1
0
def Parse(input_line):
    input_line = input_line.strip()
    line.current = input_line

    disabled = input_line.startswith("!")
    if disabled: line.current[1:]

    label = ParseToken(line.current, "Label", False, True)

    identifier = ""
    identifier = ParseToken(line.current, "Parameter", True, True)

    block = BlockMappings2.get(identifier)
    #Todo blocks
    if block:
        # Init the block object here
        # For some reason it will not init a new object if it's called frin the dict
        block = block()
        block.FromLS(line.current)
        if block:
            block.Dict["label"] = label
            block.Dict["block_type"] = identifier
            return block
        else:
            # ERROR
            return False
    else:
        return None
def Parse(input_line):
    input_line = input_line.strip()
    line = LineParser()
    line.current = input_line

    disabled = input_line.startswith("!")
    if disabled: line.current[1:]

    label = ParseToken(line,"Label", False, True)
    
    identifier = ""
    identifier = ParseToken(line,"Parameter", True, True)

    # Get the class for the matching identifier
    block = BlockMappings2.get(identifier)
    #Todo blocks
    if block:
        # Init a new class
        block = block()
        block.FromLS(line)
        if block:
            block.label = label
            block.block_type = identifier
            return block
        else:
            # ERROR
            return False
    else:
        return None
    def FromLS(self, line: LineParser) -> None:
        if str(line.current).startswith("!"):
            return None

        self.group = ParseEnum(line)

        if self.group == UtilityGroup.List:

            self.list_name = ParseLiteral(line)
            self.list_action = ParseEnum(line)

            if self.list_action == ListAction.Join:
                self.Separator = ParseLiteral(line)

            elif self.list_action == ListAction.Sort:
                while Lookahead(line) == "Boolean":
                    boolean_name, boolean_value = SetBool(line, self)

            elif self.list_action == ListAction.Map or \
                self.list_action == ListAction.Zip or \
                self.list_action == ListAction.Concat:
                self.SecondListName = ParseLiteral(line)

            elif self.list_action == ListAction.Add:
                self.ListItem = ParseLiteral(line)
                self.ListIndex = ParseLiteral(line)

            elif self.list_action == ListAction.Remove:
                self.ListIndex = ParseLiteral(line)

            elif self.list_action == ListAction.RemoveValues:
                self.ListElementComparer = ParseEnum(line)
                self.ListComparisonTerm = ParseLiteral(line)
            else:
                pass

        elif self.group == UtilityGroup.Variable:
            self.VarName = ParseLiteral(line)
            self.var_action = ParseEnum(line)
            if self.var_action == VarAction.Split:
                self.SplitSeparator = ParseLiteral(line)

        elif self.group == UtilityGroup.Conversion:
            self.ConversionFrom = ParseEnum(line)
            self.ConversionTo = ParseEnum(line)
            self.InputString = ParseLiteral(line)

        elif self.group == UtilityGroup.File:
            self.FilePath = ParseLiteral(line)
            self.file_action = ParseEnum(line)

            if self.file_action in [
                    FileAction.Write, FileAction.WriteLines, FileAction.Append,
                    FileAction.AppendLines, FileAction.Copy, FileAction.Move
            ]:
                self.InputString = ParseLiteral(line)

        elif self.group == UtilityGroup.Folder:
            self.FolderPath = ParseLiteral(line)
            self.folder_action = ParseEnum(line)

        # Try to parse the arrow, otherwise just return the block as is with default var name and var / cap choice
        if not ParseToken(line, "Arrow", False, True):
            return self.Dict

        # Parse the VAR / CAP
        varType = ParseToken(line, "Parameter", True, True)
        if str(varType.upper()) == "VAR" or str(varType.upper()) == "CAP":
            if str(varType.upper()) == "CAP":
                self.Dict["IsCapture"] = True
                self.isCapture = True

        # Parse the variable/capture name
        VariableName = ParseToken(line, "Literal", True, True)
        self.VariableName = VariableName
예제 #4
0
    def FromLS(self, input_line):
        input_line = input_line.strip()
        line.current = input_line
        MultipartContents = []
        CustomHeaders = {}
        CustomCookies = {}
        ResponseType = "String"

        if str(input_line).startswith("!"):
            return None

        self.Dict = {}

        Method = ParseEnum(line.current)
        self.Dict["Method"] = Method
        self.Method = Method

        Url = ParseLiteral(line.current)
        self.Dict["Url"] = Url
        self.Url = Url

        self.Dict["Booleans"] = {}
        while Lookahead(line.current) == "Boolean":
            boolean_name, boolean_value = SetBool(line.current, self)
            self.Dict["Booleans"][boolean_name] = boolean_value

        while len(str(
                line.current)) != 0 and line.current.startswith("->") == False:
            parsed = ParseToken(line.current, "Parameter", True, True).upper()
            if parsed == "MULTIPART":
                self.Dict["RequestType"] = "Multipart"

            elif parsed == "BASICAUTH":
                self.Dict["RequestType"] = "BasicAuth"

            elif parsed == "STANDARD":
                self.Dict["RequestType"] = "Standard"
                self.RequestType = RequestType.Standard

            elif parsed == "RAW":
                self.Dict["RequestType"] = "Raw"

            elif parsed == "CONTENT":
                PostData = ParseLiteral(line.current)
                self.Dict["PostData"] = PostData
                self.PostData = PostData

            elif parsed == "RAWDATA":
                RawData = ParseLiteral(line.current)
                self.Dict["RawData"] = RawData

            elif parsed == "STRINGCONTENT":
                stringContentPair = ParseString(ParseLiteral(line.current),
                                                ':', 2)
                MultipartContents.append({
                    "Type": "STRING",
                    "Name": stringContentPair[0],
                    "Value": stringContentPair[1]
                })

            elif parsed == "FILECONTENT":
                stringContentPair = ParseString(ParseLiteral(line.current),
                                                ':', 3)
                MultipartContents.append({
                    "Type": "FILE",
                    "Name": stringContentPair[0],
                    "Value": stringContentPair[1]
                })

            elif parsed == "COOKIE":
                cookiePair = ParseString(ParseLiteral(line.current), ':', 2)
                CustomCookies[cookiePair[0]] = cookiePair[1]

            elif parsed == "HEADER":
                headerPair = ParseString(ParseLiteral(line.current), ':', 2)
                CustomHeaders[headerPair[0]] = headerPair[1]
                self.CustomHeaders[headerPair[0]] = headerPair[1]

            elif parsed == "CONTENTTYPE":
                ContentType = ParseLiteral(line.current)
                self.Dict["ContentType"] = ContentType
                self.ContentType = ContentType

            elif parsed == "USERNAME":
                AuthUser = ParseLiteral(line.current)
                self.Dict["AuthUser"] = AuthUser
                self.AuthUser = AuthUser

            elif parsed == "PASSWORD":
                AuthPass = ParseLiteral(line.current)
                self.Dict["AuthUser"] = AuthPass
                self.AuthPass = AuthPass

            elif parsed == "BOUNDARY":
                MultipartBoundary = ParseLiteral(line.current)
                self.Dict["MultipartBoundary"] = MultipartBoundary

            elif parsed == "SECPROTO":
                SecurityProtocol = ParseLiteral(line.current)
                self.Dict["SecurityProtocol"] = SecurityProtocol

            else:
                pass

        if line.current.startswith("->"):
            EnsureIdentifier(line.current, "->")
            outType = ParseToken(line.current, "Parameter", True, True)

            if outType.upper() == "STRING":
                ResponseType = "String"

            elif outType.upper() == "File":
                ResponseType = "FILE"
                DownloadPath = ParseLiteral(line.current)
                self.Dict["DownloadPath"] = DownloadPath
                while Lookahead(line.current) == "Boolean":

                    boolean_name, boolean_value = SetBool(line.current, self)
                    self.Dict["Booleans"][boolean_name] = boolean_value

            elif outType.upper() == "BASE64":
                ResponseType = "BASE64"
                OutputVariable = ParseLiteral(line.current)
                self.Dict["OutputVariable"] = OutputVariable

        self.Dict["CustomCookies"] = CustomCookies
        self.Dict["CustomHeaders"] = CustomHeaders
예제 #5
0
    def FromLS(self, line: LineParser):

        if str(line.current).startswith("!"):
            return None

        self.Dict = {}

        ParseTarget = ParseLiteral(line)
        self.Dict["ParseTarget"] = ParseTarget
        self.ParseTarget = ParseTarget

        parse_type = ParseEnum(line)
        self.Dict["parse_type"] = parse_type
        self.ParseType = parse_type

        if parse_type == ParseType.REGEX:
            regex_pattern = ParseLiteral(line)
            self.Dict["regex_pattern"] = regex_pattern
            self.RegexString = regex_pattern

            regex_output = ParseLiteral(line)
            self.Dict["regex_output"] = regex_output
            self.RegexOutput = regex_output

            self.Dict["Booleans"] = {}
            while Lookahead(line) == "Boolean":
                boolean_name, boolean_value = SetBool(line, self)
                self.Dict["Booleans"][boolean_name] = boolean_value

        elif parse_type == ParseType.CSS:
            CssSelector = ParseLiteral(line)
            self.CssSelector = CssSelector
            self.Dict["CssSelector"] = CssSelector

            AttributeName = ParseLiteral(line)
            self.AttributeName = AttributeName
            self.Dict["AttributeName"] = AttributeName

            if Lookahead(line) == "Boolean":
                SetBool(line, self)
            elif Lookahead(line) == "Integer":
                CssElementIndex = ParseInt(line)
                self.CssElementIndex = CssElementIndex
                self.Dict["CssElementIndex"] = CssElementIndex
            self.Dict["Booleans"] = {}
            while Lookahead(line) == "Boolean":
                boolean_name, boolean_value = SetBool(line, self)
                self.Dict["Booleans"][boolean_name] = boolean_value

        elif parse_type == ParseType.JSON:
            JsonField = ParseLiteral(line)
            self.Dict["JsonField"] = JsonField
            self.JsonField = JsonField
            self.Dict["Booleans"] = {}
            while Lookahead(line) == "Boolean":
                boolean_name, boolean_value = SetBool(line, self)
                self.Dict["Booleans"][boolean_name] = boolean_value

        elif parse_type == ParseType.LR:
            LeftString = ParseLiteral(line)
            self.Dict["LeftString"] = LeftString
            self.LeftString = LeftString
            RightString = ParseLiteral(line)
            self.RightString = RightString
            self.Dict["RightString"] = RightString
            self.Dict["Booleans"] = {}
            while Lookahead(line) == "Boolean":
                boolean_name, boolean_value = SetBool(line, self)
                self.Dict["Booleans"][boolean_name] = boolean_value

        else:
            return None

        arrow = ParseToken(line, "Arrow", True, True)

        var_type = ParseToken(line, "Parameter", True, True)

        IsCapture = False
        if str(var_type.upper()) == "VAR" or str(var_type.upper()) == "CAP":
            if str(var_type.upper()) == "CAP": IsCapture = True
        self.Dict["IsCapture"] = IsCapture
        self.IsCapture = IsCapture

        variable_name = ParseLiteral(line)
        self.Dict["variable_name"] = variable_name
        self.VariableName = variable_name

        prefix = ParseLiteral(line)
        self.Dict["prefix"] = prefix
        self.Prefix = prefix

        suffix = ParseLiteral(line)
        self.Dict["suffix"] = suffix
        self.Suffix = suffix
    def FromLS(self, line: LineParser):
        if str(line.current).startswith("!"):
            return None

        method = ParseEnum(line)
        self.method = method

        url = ParseLiteral(line)
        self.url = url

        while Lookahead(line) == "Boolean":
            boolean_name, boolean_value = SetBool(line, self)

        while len(str(
                line.current)) != 0 and line.current.startswith("->") == False:
            parsed = ParseToken(line, "Parameter", True, True).upper()
            if parsed == "MULTIPART":
                self.request_type = RequestType.Multipart

            elif parsed == "BASICAUTH":
                self.request_type = RequestType.BasicAuth

            elif parsed == "STANDARD":
                self.request_type = RequestType.Standard

            elif parsed == "RAW":
                self.request_type = RequestType.Raw

            elif parsed == "CONTENT":
                post_data = ParseLiteral(line)
                self.post_data = post_data

            elif parsed == "RAWDATA":
                raw_data = ParseLiteral(line)
                self.raw_data = raw_data

            elif parsed == "STRINGCONTENT":
                stringContentPair = ParseString(ParseLiteral(line), ':', 2)
                self.multipart_contents.append(
                    MultipartContent(stringContentPair[0],
                                     stringContentPair[1],
                                     MultipartContentType.String))

            elif parsed == "FILECONTENT":
                fileContentTriplet = ParseString(ParseLiteral(line), ':', 3)
                self.multipart_contents.append(
                    MultipartContent(fileContentTriplet[0],
                                     fileContentTriplet[1],
                                     MultipartContentType.File,
                                     fileContentTriplet[3]))

            elif parsed == "COOKIE":
                cookiePair = ParseString(ParseLiteral(line), ':', 2)
                self.custom_cookies[cookiePair[0]] = cookiePair[1]

            elif parsed == "HEADER":
                headerPair = ParseString(ParseLiteral(line), ':', 2)
                self.custom_headers[headerPair[0]] = headerPair[1]

            elif parsed == "CONTENTTYPE":
                ContentType = ParseLiteral(line)
                self.ContentType = ContentType

            elif parsed == "USERNAME":
                auth_user = ParseLiteral(line)
                self.auth_user = auth_user

            elif parsed == "PASSWORD":
                auth_pass = ParseLiteral(line)
                self.auth_pass = auth_pass

            elif parsed == "BOUNDARY":
                multipart_boundary = ParseLiteral(line)
                self.multipart_boundary = multipart_boundary

            elif parsed == "SECPROTO":
                SecurityProtocol = ParseLiteral(line)
                self.SecurityProtocol = SecurityProtocol

            else:
                pass

        if line.current.startswith("->"):
            EnsureIdentifier(line, "->")
            outType = ParseToken(line, "Parameter", True, True)

            if outType.upper() == "STRING":
                self.response_type = ResponseType.String

            elif outType.upper() == "FILE":
                self.response_type = ResponseType.File
                download_path = ParseLiteral(line)
                self.download_path = download_path
                while Lookahead(line) == "Boolean":
                    boolean_name, boolean_value = SetBool(line, self)

            elif outType.upper() == "BASE64":
                self.response_type = ResponseType.Base64String
                output_variable = ParseLiteral(line)
                self.output_variable = output_variable
예제 #7
0
    def FromLS(self, input_line):
        input_line = input_line.strip()

        if str(input_line).startswith("!"):
            return None
        line.current = input_line
        self.Dict = {}

        self.Dict["IsCapture"] = False

        self.Dict["VariableName"] = ""

        self.Dict["InputString"] = ""

        self.Dict["Booleans"] = {}

        FunctionType = ParseEnum(line.current)
        self.Dict["FunctionType"] = FunctionType
        self.FunctionType = FunctionType

        if FunctionType == Function().Constant:
            pass

        elif FunctionType == Function().Hash:
            HashType = ParseEnum(line.current)
            self.Dict["HashType"] = HashType
            self.HashType = HashType

            while Lookahead(line.current) == "Boolean":
                boolean_name, boolean_value = SetBool(line.current, self)
                self.Dict["Booleans"][boolean_name] = boolean_value

        elif FunctionType == Function().HMAC:
            HashType = ParseEnum(line.current)
            self.Dict["HashType"] = HashType
            self.HashType = HashType
            HmacKey = ParseLiteral(line.current)
            self.Dict["HmacKey"] = HmacKey
            self.HmacKey = HmacKey
            while Lookahead(line.current) == "Boolean":
                boolean_name, boolean_value = SetBool(line.current, self)
                self.Dict["Booleans"][boolean_name] = boolean_value

        elif FunctionType == Function().Translate:
            while Lookahead(line.current) == "Boolean":
                boolean_name, boolean_value = SetBool(line.current, self)
                self.Dict["Booleans"][boolean_name] = boolean_value
            self.Dict["TranslationDictionary"] = {}
            while line.current and Lookahead(line.current) == "Parameter":
                EnsureIdentifier(line.current, "KEY")
                k = ParseLiteral(line.current)
                EnsureIdentifier(line.current, "VALUE")
                v = ParseLiteral(line.current)
                self.Dict["TranslationDictionary"][k] = v

        elif FunctionType == Function().DateToUnixTime:
            self.Dict["DateFormat"] = ParseLiteral(line.current)

        elif FunctionType == Function().UnixTimeToDate:
            self.Dict["DateFormat"] = ParseLiteral(line.current)
            if Lookahead(line.current) != "Literal":
                self.Dict["InputString"] = "yyyy-MM-dd:HH-mm-ss"

        elif FunctionType == Function().Replace:
            ReplaceWhat = ParseLiteral(line.current)
            self.Dict["ReplaceWhat"] = ReplaceWhat
            self.ReplaceWhat = ReplaceWhat

            ReplaceWith = ParseLiteral(line.current)
            self.Dict["ReplaceWith"] = ReplaceWith
            self.ReplaceWith = ReplaceWith

            if Lookahead(line.current) == "Boolean":
                boolean_name, boolean_value = SetBool(line.current, self)
                self.Dict["Booleans"][boolean_name] = boolean_value

        elif FunctionType == Function().RegexMatch:
            self.Dict["RegexMatch"] = ParseLiteral(line.current)

        elif FunctionType == Function().RandomNum:
            if Lookahead(line.current) == "Literal":
                RandomMin = ParseLiteral(line.current)
                RandomMax = ParseLiteral(line.current)
                self.Dict["RandomMin"] = RandomMin
                self.Dict["RandomMax"] = RandomMax
                self.RandomMin = RandomMin
                self.RandomMax = RandomMax
            # Support for old integer definition of Min and Max
            else:
                RandomMin = ParseLiteral(line.current)
                RandomMax = ParseLiteral(line.current)
                self.Dict["RandomMin"] = RandomMin
                self.Dict["RandomMax"] = RandomMax
                self.RandomMin = RandomMin
                self.RandomMax = RandomMax

            if Lookahead(line.current) == "Boolean":
                boolean_name, boolean_value = SetBool(line.current, self)
                self.Dict["Booleans"][boolean_name] = boolean_value

        elif FunctionType == Function().CountOccurrences:
            self.Dict["StringToFind"] = ParseLiteral(line.current)

        elif FunctionType == Function().CharAt:
            self.Dict["CharIndex"] = ParseLiteral(line.current)

        elif FunctionType == Function().Substring:
            self.Dict["SubstringIndex"] = ParseLiteral(line.current)
            self.Dict["SubstringLength"] = ParseLiteral(line.current)

        elif FunctionType == Function().RSAEncrypt:
            self.Dict["RsaN"] = ParseLiteral(line.current)
            self.Dict["RsaE"] = ParseLiteral(line.current)
            if Lookahead(line.current) == "Boolean":
                boolean_name, boolean_value = SetBool(line.current, self)
                self.Dict["Booleans"][boolean_name] = boolean_value

        elif FunctionType == Function().RSAPKCS1PAD2:
            self.Dict["RsaN"] = ParseLiteral(line.current)
            self.Dict["RsaE"] = ParseLiteral(line.current)

        elif FunctionType == Function().GetRandomUA:
            if ParseToken(line.current, "Parameter", False,
                          False) == "BROWSER":
                EnsureIdentifier(line.current, "BROWSER")
                self.Dict["Booleans"]["UserAgentSpecifyBrowser"] = True
                self.Dict["UserAgentBrowser"] = ParseEnum(line.current)

        elif FunctionType == Function().AESDecrypt:
            pass

        elif FunctionType == Function().AESEncrypt:
            self.Dict["AesKey"] = ParseLiteral(line.current)
            self.Dict["AesIV"] = ParseLiteral(line.current)
            self.Dict["AesMode"] = ParseEnum(line.current)
            self.Dict["AesPadding"] = ParseEnum(line.current)

        elif FunctionType == Function().PBKDF2PKCS5:
            if Lookahead(line.current) == "Literal":
                self.Dict["KdfSalt"] = ParseLiteral(line.current)
            else:
                self.Dict["KdfSaltSize"] = ParseInt(line.current)
                self.Dict["KdfIterations"] = ParseInt(line.current)
                self.Dict["KdfKeySize"] = ParseInt(line.current)
                self.Dict["KdfAlgorithm"] = ParseEnum(line.current)

        else:
            pass
        if Lookahead(line.current) == "Literal":
            inputString = ParseLiteral(line.current)
            self.InputString = inputString
            self.Dict["InputString"] = inputString

        # Try to parse the arrow, otherwise just return the block as is with default var name and var / cap choice
        if not ParseToken(line.current, "Arrow", False, True):
            return self.Dict

        # Parse the VAR / CAP
        varType = ParseToken(line.current, "Parameter", True, True)
        if str(varType.upper()) == "VAR" or str(varType.upper()) == "CAP":
            if str(varType.upper()) == "CAP":
                self.Dict["IsCapture"] = True
                self.isCapture = True

        # Parse the variable/capture name
        VariableName = ParseToken(line.current, "Literal", True, True)
        self.VariableName = VariableName
        self.Dict["VariableName"] = VariableName