How to use the forbiddenfruit.__init__.PyTypeObject.from_address function in forbiddenfruit

To help you get started, we’ve selected a few forbiddenfruit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github clarete / forbiddenfruit / forbiddenfruit / __init__.py View on Github external
def _revert_special(klass, attr):
    tp_as_name, impl_method = override_dict[attr]
    tyobj = PyTypeObject.from_address(id(klass))
    tp_as_ptr = getattr(tyobj, tp_as_name)
    if tp_as_ptr:
        if tp_as_name in PyTypeObject_as_types_dict:
            tp_as = tp_as_ptr[0]

            struct_ty = PyTypeObject_as_types_dict[tp_as_name]
            for fname, ftype in struct_ty._fields_:
                if fname == impl_method:
                    cfunc_t = ftype

            setattr(tp_as, impl_method,
                ctypes.cast(ctypes.c_void_p(None), cfunc_t))
        else:
            if not (klass, attr) in tp_as_dict:
                # we didn't save this pointer
                # most likely never cursed