| 1 | use std::io::Error; |
| 2 | |
| 3 | use self::parser::Parser; |
| 4 | use crate::MachineType; |
| 5 | |
| 6 | mod parser; |
| 7 | |
| 8 | /// Simple .DEF file parser |
| 9 | #[derive(Debug, Clone, Default)] |
| 10 | pub struct ModuleDef { |
| 11 | pub exports: Vec<ShortExport>, |
| 12 | pub import_name: String, |
| 13 | pub image_base: u64, |
| 14 | pub stack_reserve: u64, |
| 15 | pub stack_commit: u64, |
| 16 | pub heap_reserve: u64, |
| 17 | pub heap_commit: u64, |
| 18 | pub major_image_version: u32, |
| 19 | pub minor_image_version: u32, |
| 20 | pub major_os_version: u32, |
| 21 | pub minor_os_version: u32, |
| 22 | } |
| 23 | |
| 24 | impl ModuleDef { |
| 25 | pub fn parse(def: &str, machine: MachineType) -> Result<ModuleDef, Error> { |
| 26 | Parser::new(def, machine).parse() |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /// COFF short export |
| 31 | #[derive(Debug, Clone, Default)] |
| 32 | pub struct ShortExport { |
| 33 | /// The name of the export as specified in the .def file or on the command |
| 34 | /// line, i.e. "foo" in "/EXPORT:foo", and "bar" in "/EXPORT:foo=bar" |
| 35 | pub name: String, |
| 36 | /// The external, exported name. Only non-empty when export renaming is in |
| 37 | /// effect, i.e. "foo" in "/EXPORT:foo=bar". |
| 38 | pub ext_name: Option<String>, |
| 39 | /// The real, mangled symbol name from the object file. |
| 40 | pub symbol_name: String, |
| 41 | /// Creates a weak alias. This is the name of the weak aliasee. In a .def |
| 42 | /// file, this is "baz" in "EXPORTS\nfoo = bar == baz". |
| 43 | pub alias_target: String, |
| 44 | pub ordinal: u16, |
| 45 | pub no_name: bool, |
| 46 | pub data: bool, |
| 47 | pub private: bool, |
| 48 | pub constant: bool, |
| 49 | } |