MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / test_binary_saving

Function test_binary_saving

rust/tests/binary_view.rs:19–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17
18#[test]
19fn test_binary_saving() {
20 let _session = Session::new().expect("Failed to initialize session");
21 let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
22 let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
23 // Verify the contents before we modify.
24 let contents_addr = view.original_image_base() + 0x1560;
25 let original_contents = view.read_vec(contents_addr, 4);
26 assert_eq!(original_contents, [0x00, 0xf1, 0x00, 0x00]);
27 assert_eq!(view.write(contents_addr, &[0xff, 0xff, 0xff, 0xff]), 4);
28 // Verify that we modified the binary
29 let modified_contents = view.read_vec(contents_addr, 4);
30 assert_eq!(modified_contents, [0xff, 0xff, 0xff, 0xff]);
31
32 // HACK: To prevent us from deadlocking in save_to_path we wait for all main thread actions to finish.
33 execute_on_main_thread_and_wait(|| {});
34
35 // Save the modified file
36 assert!(view.save_to_path(out_dir.join("atox.obj.new")));
37 // Verify that the file exists and is modified.
38 let new_view =
39 binaryninja::load(out_dir.join("atox.obj.new")).expect("Failed to load new view");
40 assert_eq!(
41 new_view.read_vec(contents_addr, 4),
42 [0xff, 0xff, 0xff, 0xff]
43 );
44}
45
46#[test]
47fn test_binary_saving_database() {

Callers

nothing calls this directly

Calls 5

joinMethod · 0.80
read_vecMethod · 0.80
loadFunction · 0.50
original_image_baseMethod · 0.45

Tested by

no test coverage detected