| 112 | use super::*; |
| 113 | |
| 114 | fn assert_load_bias( |
| 115 | start_addr: u64, |
| 116 | end_addr: u64, |
| 117 | file_offset: u64, |
| 118 | module_path: &str, |
| 119 | expected_load_bias: u64, |
| 120 | ) { |
| 121 | let file_data = std::fs::read(module_path).expect("Failed to read test binary"); |
| 122 | let object = object::File::parse(&file_data[..]).expect("Failed to parse test binary"); |
| 123 | let load_bias = |
| 124 | elf_helper::compute_load_bias(&object, start_addr, end_addr, file_offset).unwrap(); |
| 125 | println!("Load bias for {module_path}: 0x{load_bias:x}"); |
| 126 | assert_eq!( |
| 127 | load_bias, expected_load_bias, |
| 128 | "Invalid load bias: {load_bias:x} != {expected_load_bias:x}" |
| 129 | ); |
| 130 | } |
| 131 | |
| 132 | // Note: You can double-check the values by getting the /proc/<pid>/maps via gdb: |
| 133 | // ``` |