Example #1
0
File: learn.py Project: ufwt/Sibyl
    def parse_types(self):
        """Extract the prototype of the targeted function and associated type"""
        ctype_manager = CTypesManagerNotPacked(CAstTypes(), CTypeAMD64_unk())
        with open(self.header_filename) as fdesc:
            data = fdesc.read()
            self.headerfile = HeaderFile(data, ctype_manager)

        self.prototype = self.headerfile.functions[self.functionname]
        self.types = ctype_manager
        self.logger.info("Found prototype: %s" % self.prototype)
Example #2
0
def get_types_mngr(headerFile):
    text = open(headerFile).read()
    base_types = CTypeAMD64_unk()
    types_ast = CAstTypes()

    # Add C types definition
    types_ast.add_c_decl(text)

    types_mngr = CTypesManagerNotPacked(types_ast, base_types)
    return types_mngr
Example #3
0
File: test.py Project: ufwt/Sibyl
    def __init__(self, *args, **kwargs):
        super(TestHeader, self).__init__(*args, **kwargs)
        ctype_manager = CTypesManagerNotPacked(CAstTypes(), CTypeAMD64_unk())

        hdr = HeaderFile(self.header, ctype_manager)
        proto = hdr.functions[self.func]
        self.c_handler = CHandler(
            hdr.ctype_manager, {
                'arg%d_%s' % (i, name): proto.args[name]
                for i, name in enumerate(proto.args_order)
            })
        self.cache_sizeof = {}
        self.cache_trad = {}
        self.cache_field_addr = {}
Example #4
0
def get_types_mngr(headerFile, arch):
    text = open(headerFile).read()
    if arch == "AMD64_unk":
        base_types = CTypeAMD64_unk()
    elif arch == "X86_32_unk":
        base_types = CTypeX86_unk()
    else:
        raise NotImplementedError("Unsupported arch")
    types_ast = CAstTypes()

    # Add C types definition
    types_ast.add_c_decl(text)

    types_mngr = CTypesManagerNotPacked(types_ast, base_types)
    return types_mngr
Example #5
0
    def __init__(self, *args, **kwargs):
        super(TestHeader, self).__init__(*args, **kwargs)
        # Requirement check
        if pycparser is None:
            raise ImportError(
                "pycparser module is needed to launch tests based"
                "on header files")

        ctype_manager = CTypesManagerNotPacked(CAstTypes(), CTypeAMD64_unk())

        hdr = HeaderFile(self.header, ctype_manager)
        proto = hdr.functions[self.func]
        self.c_handler = CHandler(
            hdr.ctype_manager, {
                'arg%d_%s' % (i, name): proto.args[name]
                for i, name in enumerate(proto.args_order)
            })
        self.cache_sizeof = {}
        self.cache_trad = {}
        self.cache_field_addr = {}
Example #6
0
        unsigned short age;
        unsigned int height;
        char name[50];
};

struct ll_human {
        struct ll_human* next;
        struct human human;
};
"""

base_types = CTypeAMD64_unk()
types_ast = CAstTypes()
types_ast.add_c_decl(text)

types_mngr = CTypesManagerNotPacked(types_ast, base_types)

# Analyze binary
cont = Container.fallback_container(data, None, addr=0)

machine = Machine("x86_64")
dis_engine, ira = machine.dis_engine, machine.ira

mdis = dis_engine(cont.bin_stream, symbol_pool=cont.symbol_pool)
addr_head = 0
blocks = mdis.dis_multiblock(addr_head)
lbl_head = mdis.symbol_pool.getby_offset(addr_head)

ir_arch_a = ira(mdis.symbol_pool)
for block in blocks:
    ir_arch_a.add_block(block)