Skip to content

Commit

Permalink
small corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaza committed Oct 21, 2024
1 parent f2639a1 commit 0ef3077
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
13 changes: 7 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ pub fn get_file_extended_information<P: AsRef<Path>>(file_path: P) -> Result<Fil
return Err(Error::FileNotFound);
}
let payload = read(file_path)?;
match goblin::Object::parse(&payload)? {
goblin::Object::PE(_) => {
let image = VecPE::from_disk_data(&payload);
Ok(PeFileInformation::parse(&image)?.into())
let image = VecPE::from_disk_data(&payload);
if let Ok(pe) = PeFileInformation::parse(&image) {
Ok(pe.into())
} else {
match goblin::Object::parse(&payload)? {
goblin::Object::Elf(elf) => Ok(ElfFileInformation::parse(&elf)?.into()),
_ => Err(Error::UnsupportedFileType),
}
goblin::Object::Elf(elf) => Ok(ElfFileInformation::parse(&elf)?.into()),
_ => Err(Error::UnsupportedFileType),
}
}
5 changes: 1 addition & 4 deletions src/pe/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ impl Imports {
return Err(exe::Error::BadDirectory(ImageDirectoryEntry::Import));
}
};

for import in import_directory.descriptors {
let mut entry = ImportEntry::default();

Expand All @@ -47,7 +46,7 @@ impl Imports {
};
for import_data in import_entries {
let function_name = match import_data {
ImportData::Ordinal(x) => x.to_string(),
ImportData::Ordinal(x) => format!("Ordinal({x})"),
ImportData::ImportByName(s) => s.to_string(),
};
let is_import_by_ordinal = matches!(import_data, ImportData::Ordinal(_));
Expand All @@ -56,10 +55,8 @@ impl Imports {
import_by_ordinal: is_import_by_ordinal,
});
}

result.modules.push(entry);
}

Ok(result)
}
}
Expand Down
19 changes: 12 additions & 7 deletions src/pe/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ impl TlsCallbacks {
pub fn parse(pe: &VecPE) -> Result<TlsCallbacks> {
let callbacks = match pe.get_arch()? {
exe::Arch::X86 => match ImageTLSDirectory32::parse(pe) {
Ok(tls) => tls
.get_callbacks(pe)?
.iter()
.map(|x| x.0.into())
.collect::<Vec<u64>>(),
_ => vec![],
Ok(tls) => {
let cc = tls.get_callbacks(pe)?;
cc.iter().map(|x| x.0.into()).collect::<Vec<u64>>()
}
Err(e) => {
eprintln!("{e}");
vec![]
}
},
exe::Arch::X64 => match ImageTLSDirectory64::parse(pe) {
Ok(tls) => tls
.get_callbacks(pe)?
.iter()
.map(|x| x.0)
.collect::<Vec<u64>>(),
_ => vec![],
Err(e) => {
eprintln!("{e}");
vec![]
}
},
};
Ok(TlsCallbacks { callbacks })
Expand Down

0 comments on commit 0ef3077

Please sign in to comment.