Skip to content

Instantly share code, notes, and snippets.

#
# tinfo_calc_udt_aligns.py : Generate a struct type given a list of members with offsets
#
# First, create a simple uint32 tinfo.
uint32 = idaapi.tinfo_t()
uint32.create_simple_type(idaapi.BTF_UINT32)
# The udt_type_data_t struct holds information about struct types.
udt_data = idaapi.udt_type_data_t()
# Lazy object instantiation
class Lazy(object):
def __new__(cls, realcls, args, kwargs):
# Use the real class's __new__ to get a new object instance.
obj = realcls.__new__(realcls, *args, **kwargs)
# Replace the class with Lazy until reified.
obj.__class__ = cls
# Store info we need to reify object.
@zerotypic
zerotypic / example1.py
Last active August 26, 2021 16:49
wilhelm AST example
In [10]: import wilhelm as W
In [11]: W.initialize(W.Feature.PATH)
In [12]: func = W.ast.Function(idaapi.get_screen_ea())
# Triggers a bug related to coroutines and stack frames.
# Run this in Python 3:
# $ python3 async_bug.py [bad]
# When the commandline argument "bad" is passed in, the bug is triggered, and the foo() coroutine never completes.
#
import asyncio
import sys
LOG = print
@zerotypic
zerotypic / idapython_asyncio.py
Last active March 11, 2022 12:38
Get asyncio working in IDAPython
# Insert this into your idapythonrc.py file.
from PyQt5.QtWidgets import QApplication
import qasync
import asyncio
qapp = QApplication.instance()
# Requires qasync from here: https://github.com/zerotypic/qasync/tree/evloop_already_running, if not already merged
loop = qasync.QEventLoop(qapp, already_running=True)
asyncio.set_event_loop(loop)
class to(object):
def __init__(self, func): self.func = func
def __ror__(self, other): return self.func(other)
42 | to(hex) | to(print)