Skip to content

injector.py

ofrak.core.injector

BinaryInjectorModifier (Modifier)

Inject bytes at the given vm address in a MemoryRegion.

modify(self, resource, config) async

Modify the given resource.

Users should not call this method directly; rather, they should run Resource.run.

Parameters:

Name Type Description Default
resource Resource required
config BinaryInjectorModifierConfig

Optional config for modification. If an implementation provides a default, this default will always be used when config would otherwise be None. Note that a copy of the default config will be passed, so the default config values cannot be modified persistently by a component run.

required
Source code in ofrak/core/injector.py
async def modify(self, resource: Resource, config: BinaryInjectorModifierConfig):
    assert config is not None
    memory_region = await resource.view_as(MemoryRegion)
    for vm_address, patch in config.binary_patch_configs:
        offset = memory_region.get_offset_in_self(vm_address)
        region_resource_data_id = memory_region.resource.get_data_id()
        if region_resource_data_id is None:
            raise ValueError(
                "Cannot create DataPatch for a memory region resource with no " "data ID"
            )
        memory_region.resource.queue_patch(Range(offset, offset + len(patch)), patch)

BinaryInjectorModifierConfig (ComponentConfig) dataclass

BinaryInjectorModifierConfig(binary_patch_configs: List[Tuple[int, bytes]])