示例#1
0
 def __init__(self):
     self.types = {
         CTypeId(PADDING_TYPE_NAME): self.obj_pad,
         CTypeId('char'): self.obj_char,
         CTypeId('short'): self.obj_short,
         CTypeId('int'): self.obj_int,
         CTypeId('void'): self.obj_void,
         CTypeId('long', ): self.obj_long,
         CTypeId('float'): self.obj_float,
         CTypeId('double'): self.obj_double,
         CTypeId('signed', 'char'): self.obj_char,
         CTypeId('unsigned', 'char'): self.obj_uchar,
         CTypeId('short', 'int'): self.obj_short,
         CTypeId('signed', 'short'): self.obj_short,
         CTypeId('signed', 'short', 'int'): self.obj_short,
         CTypeId('unsigned', 'short'): self.obj_ushort,
         CTypeId('unsigned', 'short', 'int'): self.obj_ushort,
         CTypeId('unsigned', ): self.obj_uint,
         CTypeId('unsigned', 'int'): self.obj_uint,
         CTypeId('signed', 'int'): self.obj_int,
         CTypeId('long', 'int'): self.obj_long,
         CTypeId('long', 'long'): self.obj_long,
         CTypeId('long', 'long', 'int'): self.obj_long,
         CTypeId('signed', 'long', 'long'): self.obj_long,
         CTypeId('unsigned', 'long', 'long'): self.obj_ulong,
         CTypeId('signed', 'long', 'long', 'int'): self.obj_long,
         CTypeId('unsigned', 'long', 'long', 'int'): self.obj_ulong,
         CTypeId('signed', 'long'): self.obj_long,
         CTypeId('unsigned', 'long'): self.obj_ulong,
         CTypeId('signed', 'long', 'int'): self.obj_long,
         CTypeId('unsigned', 'long', 'int'): self.obj_ulong,
         CTypeId('long', 'double'): self.obj_ldouble,
         CTypePtr(CTypeId('void')): self.obj_uint,
     }
示例#2
0
        unsigned int length;
        struct line* line;
};
"""

# Type manager for x86 64: structures not packed
base_types = CTypeAMD64_unk()
types_ast = CAstTypes()

# Add C types definition
types_ast.add_c_decl(text)

types_mngr = CTypesManagerNotPacked(types_ast, base_types)

# Create the ptr variable with type "struct rectangle*"
ptr_rectangle = types_mngr.get_objc(CTypePtr(CTypeStruct('rectangle')))

ptr = ExprId('ptr', 64)
c_context = {ptr.name: ptr_rectangle}
mychandler = CHandler(types_mngr, {})

# Parse some C accesses
c_acceses = [
    "ptr->width", "ptr->length", "ptr->line", "ptr->line->color",
    "ptr->line->color[3]", "ptr->line->size"
]

for c_str in c_acceses:
    expr = mychandler.c_to_expr(c_str, c_context)
    c_type = mychandler.c_to_type(c_str, c_context)
    print 'C access:', c_str
示例#3
0
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)

open('graph_irflow.dot', 'w').write(ir_arch_a.graph.dot())

# Main function's first argument's type is "struct ll_human*"
ptr_llhuman = types_mngr.get_objc(CTypePtr(CTypeStruct('ll_human')))
arg0 = ExprId('ptr', 64)
ctx = {ir_arch_a.arch.regs.RDI: arg0}
expr_types = {arg0: (ptr_llhuman,),
              ExprInt(0x8A, 64): (ptr_llhuman,)}

mychandler = MyCHandler(types_mngr, expr_types)

for expr in get_funcs_arg0(ctx, ir_arch_a, lbl_head):
    print "Access:", expr
    for c_str, ctype in mychandler.expr_to_c_and_types(expr):
        print '\taccess:', c_str
        print '\tc type:', ctype
示例#4
0
obj_array4 = types_mngr.get_objc(CTypeId("array4"))

obj_charint = types_mngr.get_objc(CTypeUnion("char_int"))

assert cmp(obj_int, obj_uint) != 0
assert cmp(obj_int, obj_long) != 0

assert cmp(obj_array1, obj_array1) == 0
assert cmp(obj_array1, obj_array2) == 0
assert cmp(obj_array1, obj_array3) != 0
assert cmp(obj_array1, obj_array4) != 0

assert cmp(obj_charint, obj_charint) == 0
assert cmp(obj_charint, obj_uint) != 0

obj_test = types_mngr.get_objc(CTypePtr(CTypeId("Test")))

ptr_test = ExprId("ptr_Test", 64)
obj_recurse = types_mngr.get_objc(CTypePtr(CTypeStruct("recurse")))
# Test cmp same recursive object
obj_recurse_bis = types_mngr.get_objc(CTypePtr(CTypeStruct("recurse")))
assert cmp(obj_recurse, obj_recurse_bis) == 0

set_test = set([obj_recurse, obj_recurse_bis])
assert len(set_test) == 1
ptr_recurse = ExprId("ptr_recurse", 64)

obj_test_st = types_mngr.get_objc(CTypeStruct("test_st"))
print repr(obj_test_st)
obj_test_context = types_mngr.get_objc(CTypeStruct("test_context"))
print repr(obj_test_context)