Class CModule

Compiles C source code to machine code, straight to memory. May also be constructed from a precompiled shared library.

Useful for implementing hot callbacks, e.g. for Interceptor and Stalker, but also useful when needing to start new threads in order to call functions in a tight loop, e.g. for fuzzing purposes.

Global functions are automatically exported as NativePointer properties named exactly like in the C source code. This means you can pass them to Interceptor and Stalker, or call them using NativeFunction.

In addition to accessing a curated subset of Gum, GLib, and standard C APIs, the code being mapped in can also communicate with JavaScript through the symbols exposed to it. These can be plugged in at creation, e.g. to share memory allocated using Memory.alloc(), or NativeCallback values for receiving callbacks from the C module.

To perform initialization and cleanup, you may define functions with the following names and signatures:

`void init (void)`
`void finalize (void)`

Note that all data is read-only, so writable globals should be declared extern, allocated using e.g. Memory.alloc(), and passed in as symbols through the constructor's second argument.

Hierarchy

  • CModule

Indexable

[name: string]: any

Constructors

Properties

Methods

Constructors

  • Creates a new C module from the provided code.

    Parameters

    • code: string | ArrayBuffer

      C source code to compile, or a precompiled shared library.

    • Optional symbols: CSymbols

      Symbols to expose to the C module. Declare them as extern. This may for example be one or more memory blocks allocated using Memory.alloc(), and/or NativeCallback values for receiving callbacks from the C module.

    • Optional options: CModuleOptions

      Options for customizing the construction.

    Returns CModule

Properties

builtins: CModuleBuiltins

Methods

  • Eagerly unmaps the module from memory. Useful for short-lived modules when waiting for a future garbage collection isn't desirable.

    Returns void

Generated using TypeDoc