pe work
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
use crate::backend::ByteEncoder;
|
||||
|
||||
pub struct Import {
|
||||
pub name: String,
|
||||
pub names: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn encode(data: &mut ByteEncoder, imports: &[Import]) -> usize {
|
||||
let mut names = 0;
|
||||
for import in imports {
|
||||
for name in &import.names {
|
||||
data.extend(ImportLookupEntry::name().bytes());
|
||||
names += 1;
|
||||
}
|
||||
data.extend(ImportLookupEntry::NULL.bytes());
|
||||
}
|
||||
let table_addr = data.pos();
|
||||
for import in imports {
|
||||
let idt = ImportDirTable {
|
||||
lookup_table_rva: todo!(),
|
||||
time_date_stamp: 0,
|
||||
forwarder_chain: 0,
|
||||
name_rva: todo!(),
|
||||
address_table_rva: todo!(),
|
||||
};
|
||||
}
|
||||
for import in imports {
|
||||
for name in &import.names {
|
||||
hint_name_entry(data, 0, &name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct ImportDirTable {
|
||||
pub lookup_table_rva: u32,
|
||||
pub time_date_stamp: u32,
|
||||
pub forwarder_chain: u32,
|
||||
pub name_rva: u32,
|
||||
pub address_table_rva: u32,
|
||||
}
|
||||
|
||||
impl ImportDirTable {
|
||||
pub const NULL: Self = Self {
|
||||
lookup_table_rva: 0,
|
||||
time_date_stamp: 0,
|
||||
forwarder_chain: 0,
|
||||
name_rva: 0,
|
||||
address_table_rva: 0,
|
||||
};
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct ImportLookupEntry(u64);
|
||||
|
||||
impl ImportLookupEntry {
|
||||
pub const NULL: Self = Self(0);
|
||||
pub fn name(hint_name_table_rva: u32) -> Self {
|
||||
assert!(hint_name_table_rva >> 30 == 0);
|
||||
Self(hint_name_table_rva as u64)
|
||||
}
|
||||
pub fn ordinal(ordinal: u16) -> Self {
|
||||
Self(ordinal as u64 | (1 << 63))
|
||||
}
|
||||
pub fn bytes(&self) -> [u8; 8] {
|
||||
self.0.to_le_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hint_name_entry(out: &mut Vec<u8>, hint: u16, name: &str) {
|
||||
out.extend(hint.to_le_bytes());
|
||||
out.extend(name.as_bytes());
|
||||
out.push(0);
|
||||
if out.len() % 2 == 1 {
|
||||
out.push(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user