Code
Assembly, patches and code memory, all put back when the plugin goes. Any thread. Returned text and slices are good till the thread’s next call into Wraith.
enable(): voiddisable(): voiddestroy(): voidenable()disable()destroy()void Enable()void Disable()void Destroy()sal::Result<void, Wraith::CodeError> enable() constsal::Result<void, Wraith::CodeError> disable() constvoid destroy() constpub fn enable(&self) -> Result<(), wraith::CodeError>pub fn disable(&self) -> Result<(), wraith::CodeError>pub fn destroy(&self)fn enable(self: Wraith.Patch) (Wraith.CodeError || rt.Failure)!voidfn disable(self: Wraith.Patch) (Wraith.CodeError || rt.Failure)!voidfn destroy(self: Wraith.Patch) voiduint32_t Wraith_Patch_enable(Wraith_Patch self)uint32_t Wraith_Patch_disable(Wraith_Patch self)void Wraith_Patch_destroy(Wraith_Patch self)enable
Section titled “enable”Fails with CodeError.
disable
Section titled “disable”Fails with CodeError.
destroy
Section titled “destroy”Puts the code back for good. Fine to call twice.
Get it with Api.code().
assemble(source: string, address: number | bigint): Array<number>patch(target: number | bigint, source: string, options: import("salamander").Given<Wraith.Patch.Options>): Wraith.PatchpatchBytes(target: number | bigint, bytes: Array<number>, options: import("salamander").Given<Wraith.Patch.Options>): Wraith.Patchinject(target: number | bigint, source: string, options: import("salamander").Given<Wraith.Patch.Options>): Wraith.Patchalloc(size: number, near: number | bigint): numberfree(address: number | bigint): voidplace(request: import("salamander").Given<Wraith.Code.PlaceRequest>): Wraith.Code.Placeddisassemble(address: number | bigint, count: number): Array<Wraith.Code.Instruction>instructionLength(address: number | bigint): numberassemble(source: string, address: integer): (integer)[]patch(target: integer, source: string, options: Wraith.Patch.Options): Wraith.PatchpatchBytes(target: integer, bytes: (integer)[], options: Wraith.Patch.Options): Wraith.Patchinject(target: integer, source: string, options: Wraith.Patch.Options): Wraith.Patchalloc(size: integer, near: integer): integerfree(address: integer)place(request: Wraith.Code.PlaceRequest): Wraith.Code.Placeddisassemble(address: integer, count: integer): (Wraith.Code.Instruction)[]instructionLength(address: integer): integerbyte[] Assemble(string source, nuint address)Wraith.Patch? Patch(nuint target, string source, Wraith.Patch.Options options)Wraith.Patch? PatchBytes(nuint target, System.ReadOnlySpan<byte> bytes, Wraith.Patch.Options options)Wraith.Patch? Inject(nuint target, string source, Wraith.Patch.Options options)nuint Alloc(uint size, nuint near)void Free(nuint address)Wraith.Code.Placed Place(Wraith.Code.PlaceRequest request)Wraith.Code.Instruction[] Disassemble(nuint address, uint count)uint InstructionLength(nuint address)sal::Result<std::span<const uint8_t>, Wraith::CodeError> assemble(std::string_view source, uintptr_t address) constsal::Result<Wraith::Patch, Wraith::CodeError> patch(uintptr_t target, std::string_view source, Wraith::Patch_Options options) constsal::Result<Wraith::Patch, Wraith::CodeError> patchBytes(uintptr_t target, std::span<const uint8_t> bytes, Wraith::Patch_Options options) constsal::Result<Wraith::Patch, Wraith::CodeError> inject(uintptr_t target, std::string_view source, Wraith::Patch_Options options) constsal::Result<uintptr_t, Wraith::CodeError> alloc(uint32_t size, uintptr_t near) constvoid free(uintptr_t address) constsal::Result<Wraith::Code_Placed, Wraith::CodeError> place(Wraith::Code_PlaceRequest request) constsal::Result<std::span<const Wraith::Code_Instruction>, Wraith::CodeError> disassemble(uintptr_t address, uint32_t count) constsal::Result<uint32_t, Wraith::CodeError> instructionLength(uintptr_t address) constpub fn assemble(&self, source: &str, address: usize) -> Result<&[u8], wraith::CodeError>pub fn patch(&self, target: usize, source: &str, options: wraith::PatchOptions) -> Result<wraith::Patch, wraith::CodeError>pub fn patch_bytes(&self, target: usize, bytes: &[u8], options: wraith::PatchOptions) -> Result<wraith::Patch, wraith::CodeError>pub fn inject(&self, target: usize, source: &str, options: wraith::PatchOptions) -> Result<wraith::Patch, wraith::CodeError>pub fn alloc(&self, size: u32, near: usize) -> Result<usize, wraith::CodeError>pub fn free(&self, address: usize)pub fn place(&self, request: wraith::CodePlaceRequest) -> Result<wraith::CodePlaced, wraith::CodeError>pub fn disassemble(&self, address: usize, count: u32) -> Result<&[wraith::CodeInstruction], wraith::CodeError>pub fn instruction_length(&self, address: usize) -> Result<u32, wraith::CodeError>fn assemble(self: Wraith.Code, source: []const u8, address: usize) (Wraith.CodeError || rt.Failure)![]const u8fn patch(self: Wraith.Code, target: usize, source: []const u8, options: Wraith.Patch.Options) (Wraith.CodeError || rt.Failure)!Wraith.Patchfn patchBytes(self: Wraith.Code, target: usize, bytes: []const u8, options: Wraith.Patch.Options) (Wraith.CodeError || rt.Failure)!Wraith.Patchfn inject(self: Wraith.Code, target: usize, source: []const u8, options: Wraith.Patch.Options) (Wraith.CodeError || rt.Failure)!Wraith.Patchfn alloc(self: Wraith.Code, size: u32, near: usize) (Wraith.CodeError || rt.Failure)!usizefn free(self: Wraith.Code, address: usize) voidfn place(self: Wraith.Code, request: Wraith.Code.PlaceRequest) (Wraith.CodeError || rt.Failure)!Wraith.Code.Placedfn disassemble(self: Wraith.Code, address: usize, count: u32) (Wraith.CodeError || rt.Failure)![]const Wraith.Code.Instructionfn instructionLength(self: Wraith.Code, address: usize) (Wraith.CodeError || rt.Failure)!u32uint32_t Wraith_Code_assemble(Wraith_Code self, sal_string source, uintptr_t address, Slice_u8 *out)uint32_t Wraith_Code_patch(Wraith_Code self, uintptr_t target, sal_string source, Wraith_Patch_Options options, Wraith_Patch *out)uint32_t Wraith_Code_patchBytes(Wraith_Code self, uintptr_t target, Slice_u8 bytes, Wraith_Patch_Options options, Wraith_Patch *out)uint32_t Wraith_Code_inject(Wraith_Code self, uintptr_t target, sal_string source, Wraith_Patch_Options options, Wraith_Patch *out)uint32_t Wraith_Code_alloc(Wraith_Code self, uint32_t size, uintptr_t near, uintptr_t *out)void Wraith_Code_free(Wraith_Code self, uintptr_t address)uint32_t Wraith_Code_place(Wraith_Code self, Wraith_Code_PlaceRequest request, Wraith_Code_Placed *out)uint32_t Wraith_Code_disassemble(Wraith_Code self, uintptr_t address, uint32_t count, Slice_Wraith_Code_Instruction *out)uint32_t Wraith_Code_instructionLength(Wraith_Code self, uintptr_t address, uint32_t *out)assemble
Section titled “assemble”source as if it were at address.
Fails with CodeError.
Replaces code at target with asm, in place or in a cave. jmp original runs it as it was.
Fails with CodeError. Uses Patch.Options, Patch.
patchBytes
Section titled “patchBytes”Writes exactly bytes over the code at target.
Fails with CodeError. Uses Patch.Options, Patch.
inject
Section titled “inject”Runs asm in a cave before the instruction at target. jmp resume skips it. Only disabled and names count.
Fails with CodeError. Uses Patch.Options, Patch.
RWX memory, within a jump of near unless it’s 0.
Fails with CodeError.
Data and the code that reads it placed together so the code always reaches it. Nothing’s left if it fails.
Fails with CodeError. Uses Code.PlaceRequest, Code.Placed.
disassemble
Section titled “disassemble”Up to count instructions (0 is 1), stopping early at unreadable memory or non-code.
Fails with CodeError. Uses Code.Instruction.
instructionLength
Section titled “instructionLength”Up to count instructions (0 is 1), stopping early at unreadable memory or non-code.
Fails with CodeError.
CodeError
Section titled “CodeError”What can go wrong, besides Cancelled, Unsupported and Gone.
| Code | Error | |
|---|---|---|
| 1 | InvalidAsm |
|
| 2 | TooLong |
|
| 3 | Unreadable |
|
| 4 | UnexpectedBytes |
expect didn’t match what’s there |
| 5 | InvalidPattern |
An expect that doesn’t parse |
| 6 | AlreadyHooked |
Someone else hooked or patched it |
| 7 | TargetModified |
It changed since it was looked at |
| 8 | SplitsInstruction |
A size that ends inside an instruction |
| 9 | OutOfReach |
No room near enough |
| 10 | InvalidInstruction |
Not code |
| 11 | Failed |
Patch.Options
Section titled “Patch.Options”A struct, 0x30 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | size |
u32 |
Bytes replaced, ending between instructions. 0 is what expect covers, or the one instruction. |
| 0x8 | expect |
string |
Bytes like 89 83 ?? ?? or asm like cmp ecx, eax that must be there first. Empty skips the check. |
| 0x18 | disabled |
bool |
Starts off rather than on |
| 0x20 | names |
[]Addresses.Name |
Before the address list’s |
size: numberexpect: stringdisabled: booleannames: Array<Wraith.Addresses.Name>size: integerexpect: stringdisabled: booleannames: (Wraith.Addresses.Name)[]uint Sizestring Expectbool DisabledWraith.Addresses.Name[] Namesuint32_t sizesal::String expectbool disabledsal::Slice<Wraith::Addresses_Name> namespub size: u32pub expect: salamander::Strpub disabled: boolpub names: salamander::Slice<wraith::AddressesName>size: u32expect: []const u8disabled: boolnames: []const Wraith.Addresses.Nameuint32_t sizesal_string expectbool disabledSlice_Wraith_Addresses_Name namesCode.Instruction
Section titled “Code.Instruction”A struct, 0x30 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | address |
usize |
|
| 0x8 | length |
u32 |
|
| 0x10 | bytes |
[]u8 |
|
| 0x20 | text |
string |
Intel syntax |
address: numberlength: numberbytes: Array<number>text: stringaddress: integerlength: integerbytes: (integer)[]text: stringnuint Addressuint Lengthbyte[] Bytesstring Textuintptr_t addressuint32_t lengthsal::Slice<uint8_t> bytessal::String textpub address: usizepub length: u32pub bytes: salamander::Slice<u8>pub text: salamander::Straddress: usizelength: u32bytes: []const u8text: []const u8uintptr_t addressuint32_t lengthSlice_u8 bytessal_string textCode.PlaceName
Section titled “Code.PlaceName”A name for somewhere in data place places.
A struct, 0x18 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | name |
string |
|
| 0x10 | offset |
u32 |
Bytes into the data |
name: stringoffset: numbername: stringoffset: integerstring Nameuint Offsetsal::String nameuint32_t offsetpub name: salamander::Strpub offset: u32name: []const u8offset: u32sal_string nameuint32_t offsetCode.PlaceData
Section titled “Code.PlaceData”A struct, 0x18 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | size |
u32 |
|
| 0x4 | alignment |
u32 |
0 is 8 |
| 0x8 | names |
[]Code.PlaceName |
Names its code can use |
size: numberalignment: numbernames: Array<Wraith.Code.PlaceName>size: integeralignment: integernames: (Wraith.Code.PlaceName)[]uint Sizeuint AlignmentWraith.Code.PlaceName[] Namesuint32_t sizeuint32_t alignmentsal::Slice<Wraith::Code_PlaceName> namespub size: u32pub alignment: u32pub names: salamander::Slice<wraith::CodePlaceName>size: u32alignment: u32names: []const Wraith.Code.PlaceNameuint32_t sizeuint32_t alignmentSlice_Wraith_Code_PlaceName namesCode.PlaceCode
Section titled “Code.PlaceCode”A struct, 0x40 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | target |
usize |
|
| 0x8 | source |
string |
|
| 0x18 | inject |
bool |
Goes before the instruction like inject, else replaces code like patch |
| 0x1c | size |
u32 |
Like Patch.Options |
| 0x20 | expect |
string |
|
| 0x30 | names |
[]Addresses.Name |
After the data’s and before the address list’s |
target: numbersource: stringinject: booleansize: numberexpect: stringnames: Array<Wraith.Addresses.Name>target: integersource: stringinject: booleansize: integerexpect: stringnames: (Wraith.Addresses.Name)[]nuint Targetstring Sourcebool Injectuint Sizestring ExpectWraith.Addresses.Name[] Namesuintptr_t targetsal::String sourcebool injectuint32_t sizesal::String expectsal::Slice<Wraith::Addresses_Name> namespub target: usizepub source: salamander::Strpub inject: boolpub size: u32pub expect: salamander::Strpub names: salamander::Slice<wraith::AddressesName>target: usizesource: []const u8inject: boolsize: u32expect: []const u8names: []const Wraith.Addresses.Nameuintptr_t targetsal_string sourcebool injectuint32_t sizesal_string expectSlice_Wraith_Addresses_Name namesCode.PlaceRequest
Section titled “Code.PlaceRequest”A struct, 0x28 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | near |
usize |
What the data’s near when no code jumps to it |
| 0x8 | data |
[]Code.PlaceData |
|
| 0x18 | code |
[]Code.PlaceCode |
near: numberdata: Array<Wraith.Code.PlaceData>code: Array<Wraith.Code.PlaceCode>near: integerdata: (Wraith.Code.PlaceData)[]code: (Wraith.Code.PlaceCode)[]nuint NearWraith.Code.PlaceData[] DataWraith.Code.PlaceCode[] Codeuintptr_t nearsal::Slice<Wraith::Code_PlaceData> datasal::Slice<Wraith::Code_PlaceCode> codepub near: usizepub data: salamander::Slice<wraith::CodePlaceData>pub code: salamander::Slice<wraith::CodePlaceCode>near: usizedata: []const Wraith.Code.PlaceDatacode: []const Wraith.Code.PlaceCodeuintptr_t nearSlice_Wraith_Code_PlaceData dataSlice_Wraith_Code_PlaceCode codeCode.Placed
Section titled “Code.Placed”A struct, 0x20 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | data |
[]usize |
Where each data went, in order |
| 0x10 | code |
[]Patch |
Each code’s patch, in order. They start off. |
data: Array<number>code: Array<Wraith.Patch>data: (integer)[]code: (Wraith.Patch)[]nuint[] DataWraith.Patch?[] Codesal::Slice<uintptr_t> datasal::Slice<Wraith::Patch> codepub data: salamander::Slice<usize>pub code: salamander::Slice<wraith::Patch>data: []const usizecode: []const Wraith.PatchSlice_usize dataSlice_Wraith_Patch codewraith.io · Mods on the Hub · Get Wraith
Made with ♥ by Asgard
