diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-07-07 10:52:48 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-07-07 10:52:48 (GMT) |
commit | d0a46c9aa30c13f2fffe3a35ce807894337ff009 (patch) | |
tree | b697f4198fbc99b249a8c00e4c3aa8c559c0fbc4 | |
parent | 909c7ef10ad000ec988e35a95c2bbc6b22ffe242 (diff) |
Played with the Itanium demangling Python API.
-rw-r--r-- | misc/hole.cpp | 41 | ||||
-rw-r--r-- | python/c++filt.py | 114 |
2 files changed, 155 insertions, 0 deletions
diff --git a/misc/hole.cpp b/misc/hole.cpp new file mode 100644 index 0000000..1f38d83 --- /dev/null +++ b/misc/hole.cpp @@ -0,0 +1,41 @@ + +#include <iostream> +#include <vector> + +namespace How { + + namespace Deep { + + namespace The { + + template <typename t0, typename t1> + class Rabbit { + + public: + + template<typename st0, typename st1, typename st2> + static t1 HoleIs(std::vector<bool> a) + { + return 0; + } + + }; + + } + + } + +} + +int main() +{ + How::Deep::The::Rabbit<char [2], double *> r; + + typedef int (* func) (double); + + std::vector<bool> array(10); + + std::cout << "Hello" << std::endl; + std::cout << r.HoleIs<int, func, double>(array) << std::endl; + +} diff --git a/python/c++filt.py b/python/c++filt.py new file mode 100644 index 0000000..db6b47e --- /dev/null +++ b/python/c++filt.py @@ -0,0 +1,114 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import argparse +import sys +import pychrysalide +from pychrysalide.analysis.types import TemplateType +from pychrysalide.mangling import ItaniumDemangler + + + +def display_template_params(root): + """Look for template parameters in a type and its namespace.""" + + if root: + + got = display_template_params(root.namespace) + + if isinstance(root, TemplateType): + + for p in root.params: + print(' -', p, '(', type(p), ')') + + got = True + + else: + + got = False + + return got + + +if __name__ == '__main__': + """Entry point.""" + + parser = argparse.ArgumentParser(description='c++filt - Demangle C++ Itanium symbols.', add_help=False) + + parser.add_argument('-h', '--help', action='store_true', help='Display the command line options.') + + parser.add_argument('symbol', type=str, help='Symbol to be demangled') + + args = parser.parse_args() + + if args.help: + parser.print_help() + sys.exit(1) + + demangler = ItaniumDemangler() + + demangled = demangler.decode_routine(args.symbol) + + if demangled is None: + print('Error') + + else: + + print() + + print(demangled) + print() + + print('Namespace') + print('---------') + + print(' -', demangled.namespace, '(', type(demangled.namespace), ')') + print() + + print('Template parameters') + print('-------------------') + + got = display_template_params(demangled.namespace) + + if demangled.typed_name: + got |= display_template_params(demangled.typed_name) + + if not(got): + print(' - (none)') + + print() + + print('Name') + print('----') + + if demangled.typed_name: + print(' -', demangled.typed_name, '(', type(demangled.typed_name), ')') + + else: + print(' -', demangled.name, '(', type(demangled.name), ')') + + print() + + print('Return') + print('------') + + print(' -', demangled.ret, '(', type(demangled.ret), ')') + print() + + print('Arguments') + print('------') + + args = demangled.args + + if len(args) == 0: + print(' - (none)') + + else: + + count = 0 + + for a in args: + print(' - [%d] -' % count, a.type, '(', type(a.type), ')') + count += 1 + + print() |