Skip to content

Commit

Permalink
1616 debugging (#79)
Browse files Browse the repository at this point in the history
* Add support for 1616 debugging

* Make 1615 to_string sig more precise

On 1621 and onwards `to_string` has two matches, so let's make the sig
more precise
  • Loading branch information
vvvv-vvvv authored Dec 18, 2023
1 parent 4553e97 commit 2c4a2e8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
10 changes: 5 additions & 5 deletions auxtools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ signatures! {
),
runtime => universal_signature!(call, "E8 ?? ?? ?? ?? 83 C4 04 8B 85 ?? ?? ?? ?? 0F B6 C0 51 66 0F 6E C0 0F 5B C0"),
suspended_procs => version_dependent_signature!(
1615.. => (1, "A1 ?? ?? ?? ?? 8B C8 89 45 F4 3B D9 73 2A 8D 34 18 D1 EE 8B 0C B7"),
1615.. => (2, "8B 1D ?? ?? ?? ?? 56 8B 75 ?? 57 8B 3D ?? ?? ?? ?? 89 7D ?? 8B 86"),
..1614 => (1, "A1 ?? ?? ?? ?? 8B D8 89 45 ?? 89 75 ?? 3B DA 73 ?? 8D 0C ?? D1 E9 8B 04 ??")
),
suspended_procs_buffer => version_dependent_signature!(
1615.. => (2, "8B 1D ?? ?? ?? ?? 56 8B 75 08 57 8B 3D ?? ?? ?? ?? 89 7D F0 8B 86 88 00 00 00 89 45 F8"),
1615.. => (2, "8B 3D ?? ?? ?? ?? 89 7D ?? 8B 86 ?? ?? ?? ?? 89 45 ?? A1 ?? ?? ?? ?? 8B"),
..1614 => (2, "8B 35 ?? ?? ?? ?? 8B 80 ?? ?? ?? ?? 57 8B 3D ?? ?? ?? ?? 8B D7 89 45 ??")
),
to_string => version_dependent_signature!(
1615.. => "55 8B EC 6A FF 68 ?? ?? ?? ?? 64 A1 00 00 00 00 50 83 EC 24 53 56 57 A1 ?? ?? ?? ?? 33 C5 50 8D 45 F4 64 A3 00 00 00 00 8B 75",
1615.. => "55 8B EC 6A FF 68 ?? ?? ?? ?? 64 A1 00 00 00 00 50 83 EC 24 53 56 57 A1 ?? ?? ?? ?? 33 C5 50 8D 45 F4 64 A3 00 00 00 00 8B 75 ?? 8B 5D ?? BF 00 90 00 00 0F B6 C3 48 83 F8 53 0F 87",
1602..1614 => "55 8B EC 6A FF 68 ?? ?? ?? ?? 64 A1 00 00 00 00 50 83 EC 3C 56 57 A1 ?? ?? ?? ?? 33 C5 50 8D 45 F4 64 A3 00 00 00 00 8B 75",
1585..1602 => "55 8B EC 6A FF 68 ?? ?? ?? ?? 64 A1 ?? ?? ?? ?? 50 83 EC ?? 53 56 57 A1 ?? ?? ?? ?? 33 C5 50 8D 45 ?? 64 A3 ?? ?? ?? ?? 8B 1D ?? ?? ?? ??",
1561..1585 => "55 8B EC 6A FF 68 ?? ?? ?? ?? 64 A1 ?? ?? ?? ?? 50 83 EC 18 53 56 57 A1 ?? ?? ?? ?? 33 C5 50 8D 45 ?? 64 A3 ?? ?? ?? ?? 8B 4D ?? 0F B6 C1",
1543..1561 => "55 8B EC 6A FF 68 ?? ?? ?? ?? 64 A1 ?? ?? ?? ?? 50 83 EC 14 53 56 57 A1 ?? ?? ?? ?? 33 C5 50 8D 45 ?? 64 A3 ?? ?? ?? ?? 8B 4D ??",
..1543 => "55 8B EC 6A FF 68 ?? ?? ?? ?? 64 A1 ?? ?? ?? ?? 50 83 EC 10 53 56 57 A1 ?? ?? ?? ?? 33 C5 50 8D 45 ?? 64 A3 ?? ?? ?? ?? 8B 5D ?? 0F B6 C3"),

current_execution_context => version_dependent_signature!(
1615.. => (1, "A1 ?? ?? ?? ?? 56 53 6A 00 8B 00 57 6A 12 89 4D E0 FF 70 ??"),
1615.. => (1, "A1 ?? ?? ?? ?? 56 53 6A 00 8B 00 57 6A 12 89 4D ?? FF 70 ?? 8B 4D ?? FF"),
..1614 => (1, "A1 ?? ?? ?? ?? FF 75 ?? 89 4D ?? 8B 4D ?? 8B 00 6A 00 52 6A 12 FF 70 ??")
),
variable_names => version_dependent_signature!(
Expand Down Expand Up @@ -183,7 +183,7 @@ signatures! {
1543..1560 => "55 89 E5 83 EC 68 A1 ?? ?? ?? ?? 8B 15 ?? ?? ?? ?? 8B 0D ?? ?? ?? ?? 89 5D ??",
..1543 => "55 89 E5 83 EC 58 89 5D ?? 8B 5D ?? 89 75 ?? 8B 75 ?? 89 7D ?? 80 FB 54"
),
current_execution_context => universal_signature!(1, "A1 ?? ?? ?? ?? 85 C0 0F 84 ?? ?? ?? ?? 8B 00 85 C0 0F 84 ?? ?? ?? ?? 8B 00"),
current_execution_context => universal_signature!(1, "A1 ?? ?? ?? ?? C7 44 24 ?? 00 00 00 00 C7 44 24 ?? 00 00 00 00 89 74 24"),
variable_names => version_dependent_signature!(
1543.. => (1, "A1 ?? ?? ?? ?? 8B 13 8B 39 8B 75 ?? 8B 14 ?? 89 7D ?? 8B 3C ?? 83 EE 02"),
..1543 => (2, "8B 35 ?? ?? ?? ?? 89 5D ?? 0F B7 08 89 75 ?? 66 C7 45 ?? 00 00 89 7D ??")
Expand Down
13 changes: 7 additions & 6 deletions instruction_hooking/src/execute_instruction_hook.windows.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
.extern _execute_instruction_original
.extern _handle_instruction

// EAX = [CURRENT_EXECUTION_CONTEXT]
// EDI = [CURRENT_EXECUTION_CONTEXT]
_execute_instruction_hook:
// Give rust a chance to handle the instruction. Leaves [CURRENT_EXECUTION_CONTEXT] in EAX.
PUSH ECX
PUSH EDX
PUSH EAX
PUSH ECX
PUSH EDI
call _handle_instruction
MOV EDI, EAX
ADD ESP, 0x04
POP EDX
POP ECX
POP EAX

// Jump to BYOND's default do_instruction.
MOV ECX, _execute_instruction_original
JMP ECX
MOV EAX, _execute_instruction_original
JMP EAX
13 changes: 7 additions & 6 deletions instruction_hooking/src/execute_instruction_hook.windows.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
EXTERN execute_instruction_original : PTR
handle_instruction PROTO, opcode: DWORD

; EAX = [CURRENT_EXECUTION_CONTEXT]
; EDI = [CURRENT_EXECUTION_CONTEXT]
execute_instruction_hook PROC PUBLIC
; Give rust a chance to handle the instruction. Leaves [CURRENT_EXECUTION_CONTEXT] in EAX.
PUSH EAX
PUSH ECX
PUSH EDX
INVOKE handle_instruction, EAX
POP EDX
INVOKE handle_instruction, EDI
MOV EDI, EAX
POP ECX
POP EAX

; Jump to BYOND's default do_instruction.
MOV ECX, execute_instruction_original
JMP ECX
MOV EAX, execute_instruction_original
JMP EAX
execute_instruction_hook ENDP

END
7 changes: 2 additions & 5 deletions instruction_hooking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ use detour::RawDetour;

#[cfg(windows)]
signatures! {
execute_instruction => version_dependent_signature!(
1590.. => "0F B7 48 ?? 8B ?? ?? 8B F1 8B ?? ?? 81 ?? ?? ?? 00 00 0F 87 ?? ?? ?? ??",
..1590 => "0F B7 48 ?? 8B 78 ?? 8B F1 8B 14 ?? 81 FA ?? ?? 00 00 0F 87 ?? ?? ?? ??"
)
execute_instruction => universal_signature!("0F B7 47 ?? 8B 4F ?? 8B F0 8B 14 ?? 89 95 ?? ?? ?? ?? 81 FA 78 01 00 00")
}

#[cfg(unix)]
signatures! {
execute_instruction => universal_signature!("0F B7 47 ?? 8B 57 ?? 0F B7 D8 8B 0C ?? 81 F9 ?? ?? 00 00 77 ?? FF 24 8D ?? ?? ?? ??")
execute_instruction => universal_signature!("0F B7 C0 8D 14 ?? 8B 02 8B 52 ?? 8B 4E ?? 8B 5E ?? 89 46 ?? 89 56 ?? 89 0C 24")
}

// stackoverflow copypasta https://old.reddit.com/r/rust/comments/kkap4e/how_to_cast_a_boxdyn_mytrait_to_an_actual_struct/
Expand Down

0 comments on commit 2c4a2e8

Please sign in to comment.