Beispiel #1
0
 def __new__(cls, pattern):
     """
     If the pattern is completely static (no wildcards are present) a
     L{BytePattern} is created instead. That's because searching for a
     fixed byte pattern is faster than searching for a regular expression.
     """
     if '?' not in pattern:
         return BytePattern(HexInput.hexadecimal(pattern))
     return object.__new__(cls, pattern)
Beispiel #2
0
 def __new__(cls, pattern):
     """
     If the pattern is completely static (no wildcards are present) a
     L{BytePattern} is created instead. That's because searching for a
     fixed byte pattern is faster than searching for a regular expression.
     """
     if '?' not in pattern:
         return BytePattern( HexInput.hexadecimal(pattern) )
     return object.__new__(cls, pattern)
Beispiel #3
0
    def __init__(self, pattern):
        """
        Class constructor.

        @type  pattern: str
        @param pattern:
            Hexadecimal pattern matching with wildcards.

            Hex patterns must be in this form::
                "68 65 6c 6c 6f 20 77 6f 72 6c 64"  # "hello world"

            Spaces are optional. Capitalization of hex digits doesn't matter.
            This is exactly equivalent to the previous example::
                "68656C6C6F20776F726C64"            # "hello world"

            Wildcards are allowed, in the form of a C{?} sign in any hex digit::
                "5? 5? c3"          # pop register / pop register / ret
                "b8 ?? ?? ?? ??"    # mov eax, immediate value
        """
        super(HexPattern, self).__init__(pattern)
        if not HexInput.is_pattern(pattern):
            raise ValueError("Invalid hexadecimal pattern: %r" % pattern)
        self.length = HexInput.get_pattern_length(pattern)
        self.compiled = re.compile(HexInput.pattern(pattern), re.DOTALL)
Beispiel #4
0
    def __init__(self, pattern):
        """
        Class constructor.

        @type  pattern: str
        @param pattern:
            Hexadecimal pattern matching with wildcards.

            Hex patterns must be in this form::
                "68 65 6c 6c 6f 20 77 6f 72 6c 64"  # "hello world"

            Spaces are optional. Capitalization of hex digits doesn't matter.
            This is exactly equivalent to the previous example::
                "68656C6C6F20776F726C64"            # "hello world"

            Wildcards are allowed, in the form of a C{?} sign in any hex digit::
                "5? 5? c3"          # pop register / pop register / ret
                "b8 ?? ?? ?? ??"    # mov eax, immediate value
        """
        super(HexPattern, self).__init__(pattern)
        if not HexInput.is_pattern(pattern):
            raise ValueError("Invalid hexadecimal pattern: %r" % pattern)
        self.length   = HexInput.get_pattern_length(pattern)
        self.compiled = re.compile( HexInput.pattern(pattern), re.DOTALL )
Beispiel #5
0
    def __init__(self, hexa):
        """
        Hex patterns must be in this form::
            "68 65 6c 6c 6f 20 77 6f 72 6c 64"  # "hello world"

        Spaces are optional. Capitalization of hex digits doesn't matter.
        This is exactly equivalent to the previous example::
            "68656C6C6F20776F726C64"            # "hello world"

        Wildcards are allowed, in the form of a C{?} sign in any hex digit::
            "5? 5? c3"          # pop register / pop register / ret
            "b8 ?? ?? ?? ??"    # mov eax, immediate value

        @type  hexa: str
        @param hexa: Pattern to search for.
        """
        maxLength = len([x
                         for x in hexa if x in "?0123456789ABCDEFabcdef"]) / 2
        super(HexPattern, self).__init__(HexInput.pattern(hexa),
                                         maxLength=maxLength)
Beispiel #6
0
    def __init__(self, hexa):
        """
        Hex patterns must be in this form::
            "68 65 6c 6c 6f 20 77 6f 72 6c 64"  # "hello world"

        Spaces are optional. Capitalization of hex digits doesn't matter.
        This is exactly equivalent to the previous example::
            "68656C6C6F20776F726C64"            # "hello world"

        Wildcards are allowed, in the form of a C{?} sign in any hex digit::
            "5? 5? c3"          # pop register / pop register / ret
            "b8 ?? ?? ?? ??"    # mov eax, immediate value

        @type  hexa: str
        @param hexa: Pattern to search for.
        """
        maxLength = len([x for x in hexa
                            if x in "?0123456789ABCDEFabcdef"]) / 2
        super(HexPattern, self).__init__(HexInput.pattern(hexa),
                                         maxLength = maxLength)