How to use the unicorn.Uc function in unicorn

To help you get started, we’ve selected a few unicorn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github melynx / taintinduce / unicorn_cpu / unicorn_cpu.py View on Github external
def __init__(self, archstring, debug=False):
        self.debug = debug
        self.arch = globals()[archstring]()
        self.ks = keystone.Ks(self.arch.ks_arch[0], self.arch.ks_arch[1])
        self.mu = unicorn.Uc(self.arch.uc_arch[0], self.arch.uc_arch[1])
        self.md = capstone.Cs(self.arch.cs_arch[0], self.arch.cs_arch[1])


        self.pc_reg     = self.arch.pc_reg
        self.state_reg  = self.arch.state_reg
        self.cpu_regs   = self.arch.cpu_regs
        self.mem_regs   = {}

        self.mu.mem_map(self.arch.code_addr, self.arch.code_mem)
        self._mem_invalid_hook = self.mu.hook_add(UC_HOOK_MEM_READ_UNMAPPED | UC_HOOK_MEM_WRITE_UNMAPPED, self._invalid_mem)
        #self._mem_invalid_hook2 = self.mu.hook_add(UC_HOOK_MEM_FETCH_UNMAPPED, self._invalid_mem_fetch)
        self._code_hook = self.mu.hook_add(UC_HOOK_CODE, self._code_hook, None, self.arch.code_addr, self.arch.code_addr + self.arch.code_mem)

        self.pages = set()

        # TODO: have to figure out how to remove this state... :(
github SimonTheCoder / pyGDB_remote / unicorn_machine.py View on Github external
def __init__(self,arch=unicorn.UC_ARCH_ARM64,mode=unicorn.UC_MODE_ARM,write_auto_map = True):
        bit = None 
        if arch == unicorn.UC_ARCH_ARM64:
            bit = 64
        else:
            bit = 32
        super(Unicorn_machine, self).__init__(bit)
        self.mu = unicorn.Uc(arch,mode)
        self.mu.hook_add(unicorn.UC_HOOK_MEM_UNMAPPED,self._uc_hook_mem_unmapped)
        
        #force UC run every instruction instead of block
        self.mu.hook_add(unicorn.UC_HOOK_CODE,self._uc_hook_code)
        
        self.write_auto_map = write_auto_map 

        self.last_pc = None

        self.single_inst_state = 0
github iGio90 / Dwarf / lib / emulator.py View on Github external
def setup_arm(self):
        self.thumb = self.context.pc.thumb
        if self.thumb:
            self._current_cpu_mode = unicorn.UC_MODE_THUMB
            self.cs = Cs(CS_ARCH_ARM, CS_MODE_THUMB)
            self.uc = unicorn.Uc(unicorn.UC_ARCH_ARM, unicorn.UC_MODE_THUMB)
            # Enable VFP instr
            self.uc.mem_map(0x1000, 1024)
            self.uc.mem_write(0x1000, binascii.unhexlify(VFP))
            self.uc.emu_start(0x1000 | 1, 0x1000 + len(VFP))
            self.uc.mem_unmap(0x1000, 1024)
        else:
            self.cs = Cs(CS_ARCH_ARM, CS_MODE_ARM)
            self.uc = unicorn.Uc(unicorn.UC_ARCH_ARM, unicorn.UC_MODE_ARM)
            self._current_cpu_mode = unicorn.UC_MODE_ARM
github smuniz / pimp_my_ride / pimp_my_ride.py View on Github external
raise PimpMyRideException("Mode not specified")

        if self.start_address is None:
            raise PimpMyRideException("Start address not specified")

        if self.return_address is None:
            raise PimpMyRideException("Return address not specified")

        if not len(self.__memory_areas):
            raise PimpMyRideException("No memory areas specified")

        if not len(self.__memory_contents):
            raise PimpMyRideException("No memory contents specified")

        # Create a new Unicorn instance.
        self.__uc = uc.Uc(self.architecture, self.mode)

        # Create a new Capstone instance.
        self.__cs = cs.Cs(self._cs_arch, self._cs_mode) 

        #
        # Initialize the emulator memory.
        #
        self.__initialize_memory()

        #
        # Inialize the emulator hooks.
        #
        self.__initialize_hooks()

        #
        # Inialize the emulated CPU registers.