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

Function test_binary_reader_read

rust/tests/binary_reader.rs:47–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45
46#[test]
47fn test_binary_reader_read() {
48 let _session = Session::new().expect("Failed to initialize session");
49 let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
50 let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
51 let mut reader = BinaryReader::new(&view);
52
53 // We want to do seeks with the image base.
54 reader.set_virtual_base(view.original_image_base());
55
56 reader
57 .seek(SeekFrom::Start(0))
58 .expect("Failed to seek to start");
59 let mut buffer = [0u8; 4];
60 reader
61 .read_exact(&mut buffer)
62 .expect("Failed to read 4 bytes");
63 assert_eq!(
64 buffer.len(),
65 4,
66 "Failed to read the correct number of bytes"
67 );
68
69 // Validate the buffer.
70 assert_eq!(
71 &buffer,
72 &[0x4c, 0x01, 0x87, 0x00],
73 "Buffer content does not match the expected bytes"
74 );
75
76 // Test attempting to read beyond the end of the file.
77 reader
78 .seek(SeekFrom::End(0))
79 .expect("Failed to seek to end");
80 let mut eof_buffer = [0u8; 1];
81 let result = reader.read(&mut eof_buffer);
82 assert!(
83 result.is_err(),
84 "Expected an error when reading past EOF, got success instead"
85 );
86}

Callers

nothing calls this directly

Calls 7

EndFunction · 0.85
joinMethod · 0.80
set_virtual_baseMethod · 0.80
loadFunction · 0.50
original_image_baseMethod · 0.45
seekMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected