@@ -169,6 +169,43 @@ fn execute_only() -> PyResult<()> {
169169 Ok ( ( ) )
170170}
171171
172+ fn step_modify_rip ( ) -> PyResult < ( ) > {
173+ let mut vm = new_trace_vm ( false ) ?;
174+ vm. mem_map ( 0x100 , 0x20 , MemoryProtection :: ExecuteRead ) ?;
175+
176+ // 0x100: 48 01 d8 add rax,rbx
177+ // 0x103: 48 83 e9 05 sub rcx,0x5
178+ // 0x107: 48 89 d9 mov rcx,rbx
179+ // 0x10a: 90 nop
180+ // 0x10b: 90 nop
181+ vm. mem_write ( 0x100 , b"\x48 \x01 \xD8 \x48 \x83 \xE9 \x05 \x48 \x89 \xD9 \x90 \x90 " . to_vec ( ) ) ?;
182+
183+ vm. reg_write ( "rax" , 0xF00 ) ?;
184+ vm. reg_write ( "rbx" , 0x210 ) ?;
185+ vm. reg_write ( "rip" , 0x100 ) ?;
186+
187+ println ! ( "starting run at {:#x}" , vm. reg_read( "rip" ) ?) ;
188+ let mut status = vm. step ( 1 ) ;
189+
190+ println ! (
191+ "ending run at {:#x} (status: {:?})" ,
192+ vm. reg_read( "rip" ) ?,
193+ status
194+ ) ;
195+ vm. reg_write ( "rip" , 0x100 ) ?;
196+ //vm.write_pc(0x100);
197+ //println!("pc: {:#x}", vm.read_pc());
198+ println ! ( "rip rewritten {:#x}" , vm. reg_read( "rip" ) ?) ;
199+ status = vm. step ( 1 ) ;
200+ println ! (
201+ "ending run at {:#x} (status: {:?})" ,
202+ vm. reg_read( "rip" ) ?,
203+ status
204+ ) ;
205+
206+ Ok ( ( ) )
207+ }
208+
172209fn main ( ) {
173210 // Make sure the GHIDRA_SRC environment variable is valid
174211 match std:: env:: var ( "GHIDRA_SRC" ) {
@@ -198,6 +235,7 @@ fn main() {
198235 ( "Block optimization bug" , block_optimization) ,
199236 ( "Rewind" , rewind) ,
200237 ( "Execute only" , execute_only) ,
238+ ( "Step modify rip" , step_modify_rip) ,
201239 ] ;
202240
203241 let mut success = 0 ;
0 commit comments