Пример #1
0
    def test_ExprSlice_strcst(self):
        from miasm.expression.expression import ExprInt, ExprOp
        from miasm.ir.translators.translator import Translator
        translator_smt2 = Translator.to_language("smt2")

        args = [ExprInt(i, 32) for i in range(9)]

        self.assertEqual(translator_smt2.from_expr(args[0][1:2]),
                         r'((_ extract 1 1) (_ bv0 32))')
        self.assertRaises(ValueError, args[0].__getitem__, slice(1, 7, 2))
Пример #2
0
    def test_ExprSlice_strcst(self):
        from miasm.expression.expression import ExprInt, ExprOp
        from miasm.ir.translators.translator  import Translator
        translator_smt2 = Translator.to_language("smt2")

        args = [ExprInt(i, 32) for i in range(9)]

        self.assertEqual(
            translator_smt2.from_expr(args[0][1:2]), r'((_ extract 1 1) (_ bv0 32))')
        self.assertRaises(ValueError, args[0].__getitem__, slice(1,7,2))
Пример #3
0
    def test_ExprOp_strcst(self):
        from miasm.expression.expression import ExprInt, ExprOp
        from miasm.ir.translators.translator  import Translator
        translator_smt2 = Translator.to_language("smt2")

        args = [ExprInt(i, 32) for i in range(9)]

        self.assertEqual(
            translator_smt2.from_expr(ExprOp('|',  *args[:2])), r'(bvor (_ bv0 32) (_ bv1 32))')
        self.assertEqual(
            translator_smt2.from_expr(ExprOp('-',  *args[:2])), r'(bvsub (_ bv0 32) (_ bv1 32))')
        self.assertEqual(
            translator_smt2.from_expr(ExprOp('+',  *args[:3])), r'(bvadd (bvadd (_ bv0 32) (_ bv1 32)) (_ bv2 32))')
        self.assertRaises(NotImplementedError, translator_smt2.from_expr, ExprOp('X', *args[:1]))
Пример #4
0
    def test_ExprOp_strcst(self):
        from miasm.expression.expression import ExprInt, ExprOp
        from miasm.ir.translators.translator import Translator
        translator_smt2 = Translator.to_language("smt2")

        args = [ExprInt(i, 32) for i in range(9)]

        self.assertEqual(translator_smt2.from_expr(ExprOp('|', *args[:2])),
                         r'(bvor (_ bv0 32) (_ bv1 32))')
        self.assertEqual(translator_smt2.from_expr(ExprOp('-', *args[:2])),
                         r'(bvsub (_ bv0 32) (_ bv1 32))')
        self.assertEqual(translator_smt2.from_expr(ExprOp('+', *args[:3])),
                         r'(bvadd (bvadd (_ bv0 32) (_ bv1 32)) (_ bv2 32))')
        self.assertRaises(NotImplementedError, translator_smt2.from_expr,
                          ExprOp('X', *args[:1]))
Пример #5
0
            states_todo.add((addr_b, symbexec.symbols.copy(), tuple(list(conds) + list(viewitems(cond_group_b)))))
        elif addr == ret_addr:
            print('Return address reached')
            continue
        elif addr.is_int():
            addr = int(addr.arg)
            states_todo.add((addr, symbexec.symbols.copy(), tuple(conds)))
        elif addr.is_loc():
            states_todo.add((addr, symbexec.symbols.copy(), tuple(conds)))
        else:
            raise ValueError("Unsupported destination")


if __name__ == '__main__':
    loc_db = LocationDB()
    translator_smt2 = Translator.to_language("smt2")

    addr = int(options.address, 16)

    cont = Container.from_stream(open(args[0], 'rb'), loc_db)
    mdis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
    lifter = machine.lifter(mdis.loc_db)
    ircfg = lifter.new_ircfg()
    symbexec = SymbolicExecutionEngine(lifter)

    asmcfg = parse_asm.parse_txt(
        machine.mn, 32, '''
    init:
    PUSH argv
    PUSH argc
    PUSH ret_addr
Пример #6
0
            states_todo.add((addr_b, symbexec.symbols.copy(), tuple(list(conds) + list(viewitems(cond_group_b)))))
        elif addr == ret_addr:
            print('Return address reached')
            continue
        elif addr.is_int():
            addr = int(addr.arg)
            states_todo.add((addr, symbexec.symbols.copy(), tuple(conds)))
        elif addr.is_loc():
            states_todo.add((addr, symbexec.symbols.copy(), tuple(conds)))
        else:
            raise ValueError("Unsupported destination")


if __name__ == '__main__':

    translator_smt2 = Translator.to_language("smt2")

    addr = int(options.address, 16)

    cont = Container.from_stream(open(args[0], 'rb'))
    mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
    ir_arch = machine.ir(mdis.loc_db)
    ircfg = ir_arch.new_ircfg()
    symbexec = SymbolicExecutionEngine(ir_arch)

    asmcfg, loc_db = parse_asm.parse_txt(machine.mn, 32, '''
    init:
    PUSH argv
    PUSH argc
    PUSH ret_addr
    ''',