Skip to content

Commit

Permalink
Use SegmentInjectorModifier in the PatchMaker user-guide.md (#395)
Browse files Browse the repository at this point in the history
Simplify the docs to use the `SegmentInjectorModifier` instead of manually injecting with the `BinaryPatchModifier`.

Co-authored-by: Wyatt <[email protected]>
  • Loading branch information
paulnoalhyt and whyitfor authored Jan 17, 2024
1 parent 852c18c commit 4b06fea
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions docs/user-guide/advanced/patch-maker/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,28 +355,10 @@ These steps are done through OFRAK core, and are described individually in the O
[lesson 6](https://github.com/redballoonsecurity/ofrak/tree/master/ofrak_tutorial/notebooks_with_outputs/6_code_insertion_with_extension.ipynb).

#### Injection
Inject the extended ELF segment with the compiled patch blob using OFRAK `BinaryPatchModifier`.

First extract the newly added segment containing the patch from the FEM:

```
with open(fem.executable.path, "rb") as f:
exe_data = f.read()
segment_data = b""
for segment in fem.executable.segments:
if segment.length == 0 or segment.vm_address == 0:
continue
segment_data = exe_data[segment.offset : segment.offset + segment.length]
break
assert len(segment_data) != 0
```

Then incorporate it into the resource tree:
Inject the extended ELF segment with the compiled patch blob using OFRAK `SegmentInjectorModifier`.

```
binary_patch_config = BinaryPatchConfig(new_segment.p_offset, segment_data)
await root_resource.run(BinaryPatchModifier, binary_patch_config)
await root_resource.run(SegmentInjectorModifier, config=SegmentInjectorModifierConfig.from_fem(fem))
```

#### Packing
Expand Down

0 comments on commit 4b06fea

Please sign in to comment.