use std::fs;
use crate::arch::test::*;
use crate::*;
#[test]
fn load_pie_elf() {
init();
let binary_blob = fs::read("test/test.x86").expect("Can't read binary");
let binary = ElfBinary::new(binary_blob.as_slice()).expect("Got proper ELF file");
assert!(binary.is_pie());
let mut loader = TestLoader::new(0x1000_0000);
binary.load(&mut loader).expect("Can't load?");
for action in loader.actions.iter() {
println!("{:?}", action);
}
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Allocate(VAddr::from(0x0u64), 0x003bc, Flags(4)))
.is_some());
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Allocate(VAddr::from(0x1000u64), 0x288, Flags(1 | 4)))
.is_some());
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Allocate(VAddr::from(0x002000u64), 0x0016c, Flags(4)))
.is_some());
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Allocate(VAddr::from(0x3ef4u64), 0x12c, Flags(2 | 4)))
.is_some());
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Load(VAddr::from(0x0u64), 0x003bc))
.is_some());
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Load(VAddr::from(0x001000u64), 0x00288))
.is_some());
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Load(VAddr::from(0x002000u64), 0x0016c))
.is_some());
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Load(VAddr::from(0x00003ef4u64), 0x00128))
.is_some());
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Relocate(0x1000_0000 + 0x00003ef4, 0x1000_0000))
.is_some());
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Relocate(0x1000_0000 + 0x00003ef8, 0x1000_0000))
.is_some());
}
#[test]
fn check_nopie() {
init();
let binary_blob = fs::read("test/test_nopie.x86").expect("Can't read binary");
let binary = ElfBinary::new(binary_blob.as_slice()).expect("Got proper ELF file");
assert!(!binary.is_pie());
}
#[test]
fn check_tls() {
init();
let binary_blob = fs::read("test/tls.x86").expect("Can't read binary");
let binary = ElfBinary::new(binary_blob.as_slice()).expect("Got proper ELF file");
let mut loader = TestLoader::new(0x1000_0000);
binary.load(&mut loader).expect("Can't load?");
assert!(loader
.actions
.iter()
.find(|&&x| x == LoaderAction::Tls(VAddr::from(0x3ef0u64), 0x4, 0x8, 0x4))
.is_some());
}