|
5 | 5 | import ctypes |
6 | 6 | import time |
7 | 7 | import re |
8 | | -import os |
9 | 8 |
|
10 | | -from sys import version_info |
11 | 9 | from dataclasses import dataclass |
12 | 10 |
|
13 | 11 | if idc.__EA64__: |
14 | 12 | ea_t = ctypes.c_uint64 |
15 | 13 | ptr_t = ctypes.c_int64 |
16 | 14 | get_ptr = idaapi.get_qword |
17 | | - # Calling this a lot so we'll speed up the invocations by manually implementing this here |
18 | | - def is_ptr(f): return (f & idaapi.MS_CLS) == idaapi.FF_DATA and (f & idaapi.DT_TYPE) == idaapi.FF_QWORD |
| 15 | + FF_PTR = idaapi.FF_QWORD |
19 | 16 | else: |
20 | 17 | ea_t = ctypes.c_uint32 |
21 | 18 | ptr_t = ctypes.c_int32 |
22 | 19 | get_ptr = idaapi.get_dword |
23 | | - def is_ptr(f): return (f & idaapi.MS_CLS) == idaapi.FF_DATA and (f & idaapi.DT_TYPE) == idaapi.FF_DWORD |
| 20 | + FF_PTR = idaapi.FF_DWORD |
24 | 21 |
|
25 | | -def is_off(f): return f & (idaapi.FF_0OFF|idaapi.FF_1OFF) != 0 |
| 22 | +# Calling these a lot so we'll speed up the invocations by manually implementing them here |
| 23 | +def is_off(f): return (f & (idaapi.FF_0OFF|idaapi.FF_1OFF)) != 0 |
26 | 24 | def is_code(f): return (f & idaapi.MS_CLS) == idaapi.FF_CODE |
27 | 25 | def has_any_name(f): return (f & idaapi.FF_ANYNAME) != 0 |
| 26 | +def is_ptr(f): return (f & idaapi.MS_CLS) == idaapi.FF_DATA and (f & idaapi.DT_TYPE) == FF_PTR |
28 | 27 |
|
29 | 28 | # Let's go https://www.blackhat.com/presentations/bh-dc-07/Sabanal_Yason/Paper/bh-dc-07-Sabanal_Yason-WP.pdf |
30 | 29 |
|
@@ -245,16 +244,17 @@ class VFunc: |
245 | 244 | postname: str |
246 | 245 | sname: str |
247 | 246 |
|
248 | | -def make_vfunc(ea=idc.BADADDR, mangledname="", inheritid=-1, vaddr=idc.BADADDR): |
249 | | - name = "" |
250 | | - postname = "" |
251 | | - sname = "" |
252 | | - if mangledname: |
253 | | - name = idaapi.demangle_name(mangledname, idaapi.MNG_LONG_FORM) or mangledname |
254 | | - if name: |
255 | | - postname = get_func_postname(name) |
256 | | - sname = postname.split("(")[0] |
257 | | - return VFunc(ea, vaddr, mangledname, inheritid, name, postname, sname) |
| 247 | + @staticmethod |
| 248 | + def create(ea=idc.BADADDR, mangledname="", inheritid=-1, vaddr=idc.BADADDR): |
| 249 | + name = "" |
| 250 | + postname = "" |
| 251 | + sname = "" |
| 252 | + if mangledname: |
| 253 | + name = idaapi.demangle_name(mangledname, idaapi.MNG_LONG_FORM) or mangledname |
| 254 | + if name: |
| 255 | + postname = get_func_postname(name) |
| 256 | + sname = postname.split("(")[0] |
| 257 | + return VFunc(ea, vaddr, mangledname, inheritid, name, postname, sname) |
258 | 258 |
|
259 | 259 | class VOptions(object): |
260 | 260 | StringMethod = 1 << 0 |
@@ -412,7 +412,7 @@ def parse_vtable_addresses(ea): |
412 | 412 | if not is_code(fflags): |
413 | 413 | break |
414 | 414 |
|
415 | | - funcs.append(make_vfunc(ea=offs, vaddr=ea)) |
| 415 | + funcs.append(VFunc.create(ea=offs, vaddr=ea)) |
416 | 416 |
|
417 | 417 | ea = idaapi.next_head(ea, idc.BADADDR) |
418 | 418 | return funcs |
@@ -684,6 +684,8 @@ def is_thunk(thunkfunc, targetfuncs): |
684 | 684 | return False |
685 | 685 |
|
686 | 686 | def build_export_table(linuxtables, wintables): |
| 687 | + # Table is built mainly for readability but having one that is actually parsable would |
| 688 | + # be a cool idea for the future |
687 | 689 | exporttable = {} |
688 | 690 | # Save Linux only tables for exporting too |
689 | 691 | winless = {k: linuxtables[k] for k in linuxtables.keys() - wintables.keys()} |
@@ -895,7 +897,7 @@ def fix_win_overloads(linuxitems, winitems, vclass, functable): |
895 | 897 | currfuncs = linuxitems[i].funcs |
896 | 898 | vfuncs = [] |
897 | 899 | for u in range(len(currfuncs)): |
898 | | - f = make_vfunc(mangledname=currfuncs[u]) |
| 900 | + f = VFunc.create(mangledname=currfuncs[u]) |
899 | 901 | for j, baseclass in enumerate(vclass.baseclasses.values()): |
900 | 902 | if f.postname in baseclass.postnames: |
901 | 903 | f.inheritid = j |
|
0 commit comments