Skip to content

Commit

Permalink
Updated: Documentation for new features
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Sep 10, 2023
1 parent 3f76b7d commit 061f415
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,12 @@ Note: Rust/C port also works with FreeBSD (untested), and has partial [(limited)
free_get_buffer_result(result);
```

!!! note "Use `append_code` instead of `append_bytes` if you need to add executable code. (Currently unavailable in C# port)"

### Allocate Memory

!!! info "Allows you to temporarily allocate memory within a specific address range and size constraints."


=== "C#"

```csharp
Expand Down Expand Up @@ -217,42 +218,32 @@ Note: Rust/C port also works with FreeBSD (untested), and has partial [(limited)

!!! note "You can specify another process with `TargetProcess = someProcess` in `BufferAllocatorSettings`, but this is only supported on Windows."

### Clear Instruction Cache

!!! warning "Not currently available in C# version. Submit an issue request or PR if you need this."
### Overwriting Allocated Instructions

!!! info "This is required for some non-x86 architectures such as ARM64, PowerPC, MIPS etc."
!!! info "On non-x86 architectures, some extra actions may be needed when overwriting executable code allocated with `append_code`."

!!! tip "If you use `append_code` instead of `append_bytes`, clearing cache is automatically done."
!!! note "This involves clearing instruction cache, and abiding by Write XOR Execute restrictions."

=== "Rust"

```rust
let mut settings = BufferAllocatorSettings::new();
settings.min_address = 0;
settings.max_address = i32::MAX as usize;
settings.size = 4096;

let item = Buffers::allocate_private_memory(&mut settings).unwrap();

// You have allocated memory in first 2GiB of address space.
assert!(item.base_address.as_ptr() != std::ptr::null_mut());
assert!(item.size >= settings.size as usize);
Self::overwrite_allocated_code(address, size, |addr, size| {
// Do stuff with executable code
});
```

=== "C/C++"

```cpp
BufferSearchSettings settings;
settings.MinAddress = 0;
settings.MaxAddress = INT_MAX;
settings.Size = 4096;

AllocationResult item = allocate_private_memory(&mut settings);
void do_stuff_with_executable_code(char* addr, size_t size) {
// Modify executable code in buffer
}

// You have allocated memory in first 2GiB of address space.
overwrite_allocated_code(address, size, do_stuff_with_executable_code);
```

!!! warning "Not currently available in C# version. Submit an issue request or PR if you need this."

## Community Feedback

If you have questions/bug reports/etc. feel free to [Open an Issue](https://github.com/Reloaded-Project/Reloaded.Memory.Buffers/issues/new).
Expand Down

0 comments on commit 061f415

Please sign in to comment.