Exemplo n.º 1
0
    def __init__(self, index, caching=True):
        """Initialize the Entity instance.

        :param int index:
            The entity index to wrap.
        :param bool caching:
            Whether to lookup the cache for an existing instance or not.
        """
        # Initialize the object
        BaseEntity.__init__(self, index)
        Pointer.__init__(self, self.pointer)

        # Set the entity's base attributes
        type(self).index.set_cached_value(self, index)
Exemplo n.º 2
0
def get_relative_pointer_from_pointer(pointer, offset, size=4):
    """Return the relative pointer."""
    # Get the pointer
    pointer = Pointer(pointer)
    pointer += getattr(
        pointer, 'get_' + _singed_size_type[size])(offset) + offset + size

    return pointer
Exemplo n.º 3
0
    def __init__(self, pointer, size, op_codes=None):
        """Initialize the downloader.

        :param Pointer/int pointer:
            The pointer or memory address to patch the memory.
        :param int size:
            The size of the memory to be patched.
        :param bytes op_codes:
            A specific op-codes to patch the memory.
        :raise TypeError:
            Raised if ``pointer`` is not Pointer or int.
        :raise ValueError:
            Raised if the patcher is overlapping with
            another patcher's memory space.
        """

        if not isinstance(pointer, (Pointer, int)):
            raise TypeError("pointer type is not Pointer/int: {type}".format(
                type=repr(type(pointer))))

        self.address = int(pointer)
        self.size = size

        for patched in self._patched.values():
            if (self.address <= patched.address):
                small_address = self.address + self.size
                large_address = patched.address
            else:
                small_address = patched.address + patched.size
                large_address = self.address

            if small_address > large_address:
                patched_address = hex(patched.address)
                patched_original = ' '.join("{:02X}".format(i)
                                            for i in patched.original)
                patched_op_codes = ' '.join("{:02X}".format(i)
                                            for i in patched.op_codes)
                raise ValueError(
                    f"Patcher's memory space is overlapping!:\n    address '{patched_address}'\n    original '{patched_original}'\n    op_codes '{patched_op_codes}'"
                )

        Pointer(self.address).unprotect(self.size)

        self.pointer = ctypes.c_void_p(self.address)
        self.original = bytes(
            (ctypes.c_ubyte * self.size).from_address(self.address))
        self.op_codes = self.get_opcodes(op_codes, self.size)

        self.patched = False

        self._patched[id(self)] = self
Exemplo n.º 4
0
 def __sub__(self, other):
     """Return self-value."""
     return make_object(self.__class__, Pointer(int(self) - int(other)))
Exemplo n.º 5
0
 def __add__(self, other):
     """Return self+value."""
     return make_object(self.__class__, Pointer(int(self) + int(other)))