@@ -35,28 +35,28 @@ impl Patch for RawPatch {
35
35
impl RawPatch {
36
36
#[ cfg( target_arch = "x86_64" ) ]
37
37
fn get_patch ( _target : GuestAddr , destination : GuestAddr ) -> Vec < u8 > {
38
- // mov rax, 0xdeadfacef00dd00d
39
- // jmp rax
40
- let addr = destination . to_ne_bytes ( ) ;
41
- # [ rustfmt :: skip ]
42
- let insns : & [ & [ u8 ] ] = & [
43
- & [ 0x48 , 0xb8 ] , & addr ,
44
- & [ 0xff , 0xe0 ] ,
45
- ] ;
46
- insns . concat ( )
38
+ use dynasmrt :: { DynasmApi , VecAssembler , dynasm , x64 :: X64Relocation } ;
39
+ let mut assembler = VecAssembler :: < X64Relocation > :: new ( 0 ) ;
40
+
41
+ dynasm ! ( assembler
42
+ ; . arch x64
43
+ ; mov rax , QWORD destination as _
44
+ ; jmp rax
45
+ ) ;
46
+ assembler . finalize ( ) . expect ( "valid static assembly" )
47
47
}
48
48
49
49
#[ cfg( target_arch = "x86" ) ]
50
50
fn get_patch ( _target : GuestAddr , destination : GuestAddr ) -> Vec < u8 > {
51
- // mov eax, 0xdeadface
52
- // jmp eax
53
- let addr = destination . to_ne_bytes ( ) ;
54
- # [ rustfmt :: skip ]
55
- let insns : & [ & [ u8 ] ] = & [
56
- & [ 0xb8 ] , & addr ,
57
- & [ 0xff , 0xe0 ] ,
58
- ] ;
59
- insns . concat ( )
51
+ use dynasmrt :: { DynasmApi , VecAssembler , dynasm , x86 :: X86Relocation } ;
52
+ let mut assembler = VecAssembler :: < X86Relocation > :: new ( 0 ) ;
53
+
54
+ dynasm ! ( assembler
55
+ ; . arch x86
56
+ ; mov eax , DWORD destination as _
57
+ ; jmp eax
58
+ ) ;
59
+ assembler . finalize ( ) . expect ( "valid static assembly" )
60
60
}
61
61
62
62
#[ cfg( target_arch = "arm" ) ]
@@ -88,17 +88,17 @@ impl RawPatch {
88
88
89
89
#[ cfg( target_arch = "aarch64" ) ]
90
90
fn get_patch ( _target : GuestAddr , destination : GuestAddr ) -> Vec < u8 > {
91
- // ldr x16, #8
92
- // br x16
93
- // .quad 0xdeadfacef00dd00d
94
- let addr = destination . to_ne_bytes ( ) ;
95
- # [ rustfmt :: skip ]
96
- let insns : & [ & [ u8 ] ] = & [
97
- & [ 0x50 , 0x00 , 0x00 , 0x58 ] ,
98
- & [ 0x00 , 0x02 , 0x1f , 0xd6 ] ,
99
- & addr
100
- ] ;
101
- insns . concat ( )
91
+ use dynasmrt :: { DynasmApi , VecAssembler , aarch64 :: Aarch64Relocation , dynasm } ;
92
+ let mut assembler = VecAssembler :: < Aarch64Relocation > :: new ( 0 ) ;
93
+
94
+ dynasm ! ( assembler
95
+ ; . arch aarch64
96
+ ; ldr x16 , # 8
97
+ ; br x16
98
+ ; . i64 destination as _
99
+ ) ;
100
+
101
+ assembler . finalize ( ) . expect ( "valid static assembly" )
102
102
}
103
103
104
104
#[ cfg( target_arch = "powerpc" ) ]
0 commit comments