From c7ccd714ceeaabbe5ee682e361250c3cfd54f78f Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Fri, 9 Oct 2020 20:57:42 +0000 Subject: Expose Template Simplifier to the API, Adds Tests, and Adds Rust String FFI support to Python (see note) This introduces the ability to receive and free string from Rust in Python. For it to work, your exposed function name needs to begin with "BNRust", and the generator will create the appropriate code for freeing string return values and arguments. --- suite/testcommon.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'suite') diff --git a/suite/testcommon.py b/suite/testcommon.py index 09f9d589..b7251d42 100644 --- a/suite/testcommon.py +++ b/suite/testcommon.py @@ -590,6 +590,44 @@ class TestBuilder(Builder): testfunction = binja.Type.function(inttype, [inttype, inttype, inttype]) return ["Test_function params: " + str(testfunction.parameters), "Test_function pointer: " + str(testfunction.pointer(binja.Architecture["x86"], testfunction))] + def test_Simplifier(self): + """Template Simplification""" + result = [binja.demangle.simplify_name_to_string(s) for s in [ + # Simple + "std::__cxx11::basic_string, std::allocator >", + "std::vector >", + "std::vector, std::lessthan >", + "std::deque >", + "std::forward_list >", + "std::list >", + "std::stack >", + "std::queue >", + "std::set, std::allocator >", + "std::multiset, std::allocator >", + "std::map, std::allocator > >", + "std::multimap, std::allocator > >", + "std::unordered_set, std::equal_to, std::allocator >", + "std::unordered_multiset, std::equal_to, std::allocator >", + "std::unordered_map, std::equal_to, std::allocator > >", + "std::unordered_multimap, std::equal_to, std::allocator > >", + + # More complex + "std::__cxx11::basic_string, std::allocator >::basic_string", + "std::vector, std::allocator >, std::array >, std::allocator, std::allocator >, std::array > > >::_M_default_append(uint64_t)", + "std::vector >, std::allocator > > >::_M_check_len(uint64_t, char const*) const", + ]] + + # Test all the APIs + qName = binja.types.QualifiedName(["std", "__cxx11", "basic_string, std::allocator >"]) + result.append(binja.demangle.simplify_name_to_string(qName)) + result.append(str(binja.demangle.simplify_name_to_qualified_name(qName))) + result.append(str(binja.demangle.simplify_name_to_qualified_name(str(qName)))) + result.append(str(binja.demangle.simplify_name_to_qualified_name(str(qName), False).name)) + result.append("::".join(binja.demangle_gnu3(binja.Architecture['x86_64'], "_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm", False)[1])) + result.append("::".join(binja.demangle_gnu3(binja.Architecture['x86_64'], "_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm", True)[1])) + + return result + def test_Struct(self): """Struct produced different result""" retinfo = [] -- cgit v1.3.1