Beispiel #1
0
    def __init__(self, custom_methods, *args, **kwargs):
        from miasm2.jitter.loader.elf import vm_load_elf, preload_elf, libimp_elf
        from miasm2.os_dep import linux_stdlib
        methods = linux_stdlib.__dict__
        methods.update(custom_methods)

        super(OS_Linux, self).__init__(methods, *args, **kwargs)

        # Import manager
        self.libs = libimp_elf()

        with open(self.fname, "rb") as fstream:
            self.elf = vm_load_elf(self.jitter.vm,
                                   fstream.read(),
                                   name=self.fname,
                                   **kwargs)
        preload_elf(self.jitter.vm, self.elf, self.libs)

        self.entry_point = self.elf.Ehdr.entry

        # Library calls handler
        self.jitter.add_lib_handler(self.libs, methods)
        linux_stdlib.ABORT_ADDR = self.CALL_FINISH_ADDR

        # Arguments
        self.argv = [self.PROGRAM_PATH]
        if self.options.command_line:
            self.argv += self.options.command_line
        self.envp = self.options.environment_vars
Beispiel #2
0
    def __init__(self, custom_methods, *args, **kwargs):
        from miasm2.jitter.loader.elf import libimp_elf
        from miasm2.os_dep import linux_stdlib
        methods = linux_stdlib.__dict__
        methods.update(custom_methods)

        super(OS_Linux_str, self).__init__(methods, *args, **kwargs)

        # Import manager
        libs = libimp_elf()
        self.libs = libs

        data = open(self.fname, "rb").read()
        self.options.load_base_addr = int(self.options.load_base_addr, 0)
        self.jitter.vm.add_memory_page(self.options.load_base_addr,
                                       PAGE_READ | PAGE_WRITE, data,
                                       "Initial Str")

        # Library calls handler
        self.jitter.add_lib_handler(libs, methods)
        linux_stdlib.ABORT_ADDR = self.CALL_FINISH_ADDR

        # Arguments
        self.argv = [self.PROGRAM_PATH]
        if self.options.command_line:
            self.argv += self.options.command_line
        self.envp = self.options.environment_vars
Beispiel #3
0
    def __init__(self, custom_methods, *args, **kwargs):
        from miasm2.jitter.loader.elf import libimp_elf
        from miasm2.os_dep import linux_stdlib
        methods = linux_stdlib.__dict__
        methods.update(custom_methods)

        super(OS_Linux_str, self).__init__(methods, *args, **kwargs)

        # Import manager
        libs = libimp_elf()
        self.libs = libs

        data = open(self.fname).read()
        self.options.load_base_addr = int(self.options.load_base_addr, 0)
        self.jitter.vm.add_memory_page(
            self.options.load_base_addr, PAGE_READ | PAGE_WRITE, data,
            "Initial Str")

        # Library calls handler
        self.jitter.add_lib_handler(libs, methods)

        # Arguments
        self.argv = [self.PROGRAM_PATH]
        if self.options.command_line:
             self.argv += self.options.command_line
        self.envp = self.options.environment_vars
Beispiel #4
0
    def init_stub(self):
        """Initialize stubbing capabilities"""
        if not isinstance(self.engine, MiasmEngine):
            # Unsupported capability
            return

        # Get stubs' implementation
        context = {}
        for fpath in config.stubs:
            execfile(fpath, context)
        if not context:
            return

        libs = None
        if isinstance(self.ctr, ContainerPE):
            from miasm2.jitter.loader.pe import preload_pe, libimp_pe
            libs = libimp_pe()
            preload_pe(self.jitter.vm, self.ctr.executable, libs)

        elif isinstance(self.ctr, ContainerELF):
            from miasm2.jitter.loader.elf import preload_elf, libimp_elf
            libs = libimp_elf()
            preload_elf(self.jitter.vm, self.ctr.executable, libs)

        else:
            return

        # Add associated breakpoints
        self.jitter.add_lib_handler(libs, context)
Beispiel #5
0
    def __init__(self, custom_methods, *args, **kwargs):
        from miasm2.jitter.loader.elf import vm_load_elf, preload_elf, libimp_elf
        from miasm2.os_dep import linux_stdlib
        methods = linux_stdlib.__dict__
        methods.update(custom_methods)

        super(OS_Linux, self).__init__(methods, *args, **kwargs)

        # Import manager
        self.libs = libimp_elf()

        with open(self.fname) as fstream:
            self.elf = vm_load_elf(self.jitter.vm, fstream.read(),
                                   name=self.fname, **kwargs)
        preload_elf(self.jitter.vm, self.elf, self.libs)

        self.entry_point = self.elf.Ehdr.entry

        # Library calls handler
        self.jitter.add_lib_handler(self.libs, methods)

        # Arguments
        self.argv = [self.PROGRAM_PATH]
        if self.options.command_line:
             self.argv += self.options.command_line
        self.envp = self.options.environment_vars
Beispiel #6
0
    def init_stub(self):
        """Initialize stubbing capabilities"""
        if not isinstance(self.engine, MiasmEngine):
            # Unsupported capability
            return

        # Get stubs' implementation
        context = {}
        for fpath in config.stubs:
            execfile(fpath, context)
        if not context:
            return

        libs = None
        if isinstance(self.ctr, ContainerPE):
            from miasm2.jitter.loader.pe import preload_pe, libimp_pe
            libs = libimp_pe()
            preload_pe(self.jitter.vm, self.ctr.executable, libs)

        elif isinstance(self.ctr, ContainerELF):
            from miasm2.jitter.loader.elf import preload_elf, libimp_elf
            libs = libimp_elf()
            preload_elf(self.jitter.vm, self.ctr.executable, libs)

        else:
            return

        # Add associated breakpoints
        self.jitter.add_lib_handler(libs, context)
Beispiel #7
0
    def __init__(self, custom_methods, *args, **kwargs):
        from miasm2.jitter.loader.elf import libimp_elf
        super(OS_Linux_str, self).__init__(custom_methods, *args, **kwargs)

        # Import manager
        libs = libimp_elf()
        self.libs = libs

        data = open(self.fname).read()
        self.options.load_base_addr = int(self.options.load_base_addr, 16)
        self.jitter.vm.add_memory_page(self.options.load_base_addr, PAGE_READ | PAGE_WRITE, data)

        # Library calls handler
        self.jitter.add_lib_handler(libs, custom_methods)
Beispiel #8
0
    def __init__(self, custom_methods, *args, **kwargs):
        from miasm2.jitter.loader.elf import vm_load_elf, preload_elf, libimp_elf

        super(OS_Linux, self).__init__(custom_methods, *args, **kwargs)

        # Import manager
        libs = libimp_elf()
        self.libs = libs

        elf = vm_load_elf(self.jitter.vm, self.fname)
        self.elf = elf
        preload_elf(self.jitter.vm, elf, libs)

        self.entry_point = elf.Ehdr.entry

        # Library calls handler
        self.jitter.add_lib_handler(libs, custom_methods)
Beispiel #9
0
    def __init__(self, custom_methods, *args, **kwargs):
        from miasm2.jitter.loader.elf import libimp_elf
        from miasm2.os_dep import linux_stdlib
        methods = linux_stdlib.__dict__
        methods.update(custom_methods)

        super(OS_Linux_str, self).__init__(methods, *args, **kwargs)

        # Import manager
        libs = libimp_elf()
        self.libs = libs

        data = open(self.fname).read()
        self.options.load_base_addr = int(self.options.load_base_addr, 16)
        self.jitter.vm.add_memory_page(self.options.load_base_addr, PAGE_READ | PAGE_WRITE, data)

        # Library calls handler
        self.jitter.add_lib_handler(libs, methods)
Beispiel #10
0
    def __init__(self, custom_methods, *args, **kwargs):
        from miasm2.jitter.loader.elf import vm_load_elf, preload_elf, libimp_elf
        from miasm2.os_dep import linux_stdlib
        methods = linux_stdlib.__dict__
        methods.update(custom_methods)

        super(OS_Linux, self).__init__(methods, *args, **kwargs)

        # Import manager
        self.libs = libimp_elf()

        with open(self.fname) as fstream:
            self.elf = vm_load_elf(self.jitter.vm, fstream.read(), **kwargs)
        preload_elf(self.jitter.vm, self.elf, self.libs)

        self.entry_point = self.elf.Ehdr.entry

        # Library calls handler
        self.jitter.add_lib_handler(self.libs, methods)
Beispiel #11
0
    def __init__(self, custom_methods, *args, **kwargs):
        from miasm2.jitter.loader.elf import vm_load_elf, preload_elf, libimp_elf
        from miasm2.os_dep import linux_stdlib
        methods = linux_stdlib.__dict__
        methods.update(custom_methods)

        super(OS_Linux, self).__init__(methods, *args, **kwargs)

        # Import manager
        self.libs = libimp_elf()

        with open(self.fname) as fstream:
            self.elf = vm_load_elf(self.jitter.vm, fstream.read(), **kwargs)
        preload_elf(self.jitter.vm, self.elf, self.libs)

        self.entry_point = self.elf.Ehdr.entry

        # Library calls handler
        self.jitter.add_lib_handler(self.libs, methods)