pyplugins.wrappers.generic module

generic.py - Base wrappers for plugin data structures

This module provides generic Python wrapper classes for plugin data structures, such as those returned by PANDA or other emulation/analysis frameworks. These wrappers provide a uniform interface for accessing fields, converting to dicts, and working with arrays of wrapped objects.

Overview

The main classes are: - Wrapper: A base class for wrapping a single object, providing attribute access, dict conversion, and pretty-printing. - ArrayWrapper: A base class for wrapping a list/array of objects, providing list-like access and iteration.

These classes are intended to be subclassed for specific data structures, but can also be used directly for simple cases.

Typical Usage

Suppose you have a plugin that returns a C struct or dict-like object:

from wrappers.generic import Wrapper, ArrayWrapper

# Wrap a single object
data = plugin.get_struct()
obj = Wrapper(data)
print(obj.field1)
print(obj.to_dict())

# Wrap an array of objects
array_data = plugin.get_array()
objs = ArrayWrapper([Wrapper(x) for x in array_data])
for o in objs:
    print(o)

Classes

  • Wrapper: Base class for single-object wrappers.

  • ArrayWrapper: Base class for array/list wrappers.

class pyplugins.wrappers.generic.ArrayWrapper(data, wrapper_cls=<class 'pyplugins.wrappers.generic.Wrapper'>)[source]

Bases: Generic[T]

Optimized base class for wrapping a list/array of objects. Performs LAZY wrapping: objects are only wrapped when accessed.

Parameters:
  • data (Sequence[Any])

  • wrapper_cls (Type[T])

to_list()[source]
Return type:

List[T]

class pyplugins.wrappers.generic.ConstDictWrapper(data)[source]

Bases: object

A read-only wrapper for dictionaries optimized for maximum read speed.

Attributes are injected directly into the instance’s __dict__ at initialization time, allowing for native C-speed attribute access (obj.field) without the overhead of __getattr__.

Parameters:

data (Dict[str, Any])

items()[source]

Pass-through for dict iteration.

keys()[source]

Pass-through for keys.

to_dict()[source]

Return the underlying data as a dict.

Return type:

Dict[str, Any]

values()[source]

Pass-through for values.

class pyplugins.wrappers.generic.Wrapper(obj)[source]

Bases: object

Optimized base class for wrapping a single object. Uses __slots__ and cached type flags to minimize __getattr__ overhead.

Parameters:

obj (Any)

to_dict()[source]
Return type:

Dict[str, Any]