Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 1e49750

Browse files
idapython: add idc.GetType for function types
only supports stdcall calling convention atm
1 parent 740bb72 commit 1e49750

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

idb/idapython.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,31 @@ def RptCmt(self, ea):
649649
def GetCommentEx(self, ea, repeatable):
650650
return self.api.ida_bytes.get_cmt(ea, repeatable)
651651

652+
def GetType(self, ea):
653+
try:
654+
f = idb.analysis.Function(self.idb, ea)
655+
except Exception as e:
656+
logger.warning('failed to fetch function for GetType: %s', e)
657+
return None
658+
659+
try:
660+
name = f.get_name()
661+
sig = f.get_signature()
662+
except KeyError:
663+
return None
664+
665+
params = []
666+
for param in sig.parameters:
667+
params.append('%s %s' % (param.type, param.name))
668+
669+
return '{rtype:s} {cc:s} {name:s}({params:s})'.format(
670+
rtype=sig.rtype,
671+
cc=sig.calling_convention,
672+
name=name,
673+
params=', '.join(params),
674+
)
675+
676+
652677
@staticmethod
653678
def hasValue(flags):
654679
return flags & FLAGS.FF_IVL > 0

tests/test_idaapi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,16 @@ def test_exports(kernel32_idb, version, bitness, expected):
679679

680680
assert api.ida_entry.get_entry_ordinal(1572) == 0x68901695
681681
assert api.ida_entry.get_entry_name(0x68901695) == 'DllEntryPoint'
682+
683+
684+
@kern32_test()
685+
def test_GetType(kernel32_idb, version, bitness, expected):
686+
api = idb.IDAPython(kernel32_idb)
687+
assert api.idc.GetType(0x68901695) == 'BOOL __stdcall DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)'
688+
689+
# valid function, but no type data associated...
690+
691+
# .text:6899AE01 ; Attributes: bp-based frame
692+
# .text:6899AE01
693+
# .text:6899AE01 sub_6899AE01 proc near
694+
assert api.idc.GetType(0x6899AE01) == None

0 commit comments

Comments
 (0)