summaryrefslogtreecommitdiff
path: root/python/c++filt.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/c++filt.py')
-rw-r--r--python/c++filt.py114
1 files changed, 114 insertions, 0 deletions
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()