# Path: sibyl/engine/engine.py
# class Engine(object):
#     """Wrapper on execution engine"""
# 
#     def __init__(self, machine):
#         """Instanciate an Engine
#         @machine: miasm2.analysis.machine:Machine instance"""
#         self.logger = init_logger(self.__class__.__name__)
# 
#     def take_snapshot(self):
#         self.vm_mem = self.jitter.vm.get_all_memory()
#         self.vm_regs = self.jitter.cpu.get_gpreg()
# 
#     def restore_snapshot(self, memory=True):
#         raise NotImplementedError("Abstract method")
# 
#     def run(self, address, timeout_seconds):
#         raise NotImplementedError("Abstract method")
# 
#     def prepare_run(self):
#         pass
# 
#     def restore_snapshot(self, memory=True):
#         raise NotImplementedError("Abstract method")
# 
# Path: sibyl/commons.py
# END_ADDR = 0x1337babe
# 
# def init_logger(name):
#     logger = logging.getLogger(name)
# 
#     console_handler = logging.StreamHandler()
#     log_format = "%(levelname)-5s: %(message)s"
#     console_handler.setFormatter(logging.Formatter(log_format))
#     logger.addHandler(console_handler)
# 
#     logger.setLevel(logging.ERROR)
#     return logger


from miasm2.core.utils import pck32, pck64
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
from sibyl.engine.engine import Engine
from sibyl.commons import END_ADDR, init_logger
    import unicorn
        import unicorn.x86_const as csts
        import unicorn.x86_const as csts
        import unicorn.arm_const as csts
        import unicorn.arm_const as csts
        import unicorn.mips_const as csts
        self.ask_attrib = ask_attrib

        self.mu = unicorn.Uc(arch, mode)
        self.vm = UcWrapVM(self.mu)
        self.cpu = cpucls(self.mu)

    def init_stack(self):
        self.vm.add_memory_page(0x1230000, PAGE_WRITE | PAGE_READ,
                                "\x00" * 0x10000, "Stack")
        setattr(self.cpu, self.ira.sp.name, 0x1230000 + 0x10000)

    def push_uint32_t(self, value):
        setattr(self.cpu, self.ira.sp.name,
                getattr(self.cpu, self.ira.sp.name) - self.ira.sp.size / 8)
        self.vm.set_mem(getattr(self.cpu, self.ira.sp.name), pck32(value))

    def push_uint64_t(self, value):
        setattr(self.cpu, self.ira.sp.name,
                getattr(self.cpu, self.ira.sp.name) - self.ira.sp.size / 8)
        self.vm.set_mem(getattr(self.cpu, self.ira.sp.name), pck64(value))

    def run(self, pc, timeout_seconds=1):
        # checking which instruction you want to emulate: THUMB/THUMB2 or others
        # Note we start at ADDRESS | 1 to indicate THUMB mode.
        try:
            if self.ask_arch == 'armt' and self.ask_attrib == 'l':
                self.mu.emu_start(pc | 1, END_ADDR, timeout_seconds * unicorn.UC_SECOND_SCALE)
            else:
                self.mu.emu_start(pc, END_ADDR, timeout_seconds * unicorn.UC_SECOND_SCALE)
        except unicorn.UcError as e:

# Path: sibyl/engine/engine.py
# class Engine(object):
#     """Wrapper on execution engine"""
# 
#     def __init__(self, machine):
#         """Instanciate an Engine
#         @machine: miasm2.analysis.machine:Machine instance"""
#         self.logger = init_logger(self.__class__.__name__)
# 
#     def take_snapshot(self):
#         self.vm_mem = self.jitter.vm.get_all_memory()
#         self.vm_regs = self.jitter.cpu.get_gpreg()
# 
#     def restore_snapshot(self, memory=True):
#         raise NotImplementedError("Abstract method")
# 
#     def run(self, address, timeout_seconds):
#         raise NotImplementedError("Abstract method")
# 
#     def prepare_run(self):
#         pass
# 
#     def restore_snapshot(self, memory=True):
#         raise NotImplementedError("Abstract method")
# 
# Path: sibyl/commons.py
# END_ADDR = 0x1337babe
# 
# def init_logger(name):
#     logger = logging.getLogger(name)
# 
#     console_handler = logging.StreamHandler()
#     log_format = "%(levelname)-5s: %(message)s"
#     console_handler.setFormatter(logging.Formatter(log_format))
#     logger.addHandler(console_handler)
# 
#     logger.setLevel(logging.ERROR)
#     return logger


# Path: sibyl/engine/qemu.py
from miasm2.core.utils import pck32, pck64
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
from sibyl.engine.engine import Engine
from sibyl.commons import END_ADDR, init_logger
    import unicorn
        import unicorn.x86_const as csts
        import unicorn.x86_const as csts
        import unicorn.arm_const as csts
        import unicorn.arm_const as csts
        import unicorn.mips_const as csts

        self.ask_attrib = ask_attrib

        self.mu = unicorn.Uc(arch, mode)
        self.vm = UcWrapVM(self.mu)
        self.cpu = cpucls(self.mu)

    def init_stack(self):
        self.vm.add_memory_page(0x1230000, PAGE_WRITE | PAGE_READ,
                                "\x00" * 0x10000, "Stack")
        setattr(self.cpu, self.ira.sp.name, 0x1230000 + 0x10000)

    def push_uint32_t(self, value):
        setattr(self.cpu, self.ira.sp.name,
                getattr(self.cpu, self.ira.sp.name) - self.ira.sp.size / 8)
        self.vm.set_mem(getattr(self.cpu, self.ira.sp.name), pck32(value))

    def push_uint64_t(self, value):
        setattr(self.cpu, self.ira.sp.name,
                getattr(self.cpu, self.ira.sp.name) - self.ira.sp.size / 8)
        self.vm.set_mem(getattr(self.cpu, self.ira.sp.name), pck64(value))

    def run(self, pc, timeout_seconds=1):
        # checking which instruction you want to emulate: THUMB/THUMB2 or others
        # Note we start at ADDRESS | 1 to indicate THUMB mode.
        try:
            if self.ask_arch == 'armt' and self.ask_attrib == 'l':
                self.mu.emu_start(pc | 1, END_ADDR, timeout_seconds * unicorn.UC_SECOND_SCALE)
            else:
                self.mu.emu_start(pc, END_ADDR, timeout_seconds * unicorn.UC_SECOND_SCALE)
        except unicorn.UcError as e:

            if getattr(self.cpu, self.ira.pc.name) != END_ADDR: