Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/bin/pedump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::io::{self, Write};
use std::path::PathBuf;
use std::process;

use pelite::image::IMAGE_FILE_MACHINE_ARM64;
use pelite::{FileMap, PeFile, Wrap};

//----------------------------------------------------------------
Expand All @@ -24,6 +25,8 @@ SYNOPSIS:
[-i | --imports]
[-e | --exports]
[-r | --relocs]
[-t | --tls]
[-c | --exceptions]
[-x | --resources]
[-g | --debug-info]

Expand Down Expand Up @@ -55,6 +58,9 @@ OPTIONS:
-t, --tls
Print the TLS directory.

-c, --exceptions
Print the exception directory.

-x, --resources
Print the embedded resource filesystem.

Expand All @@ -81,6 +87,7 @@ struct Parameters {
relocs: bool,
load_config: bool,
tls: bool,
exceptions: bool,
resources: bool,
debug_info: bool,
}
Expand All @@ -99,6 +106,7 @@ impl Default for Parameters {
relocs: false,
load_config: false,
tls: false,
exceptions: false,
resources: false,
debug_info: false,
};
Expand Down Expand Up @@ -139,6 +147,7 @@ impl Default for Parameters {
"--relocs" => vars.relocs = true,
"--load-config" => vars.load_config = true,
"--tls" => vars.tls = true,
"--exceptions" => vars.exceptions = true,
"--resources" => vars.resources = true,
"--debug-info" => vars.debug_info = true,
_ => abort(INVALID_ARG),
Expand All @@ -157,6 +166,7 @@ impl Default for Parameters {
'r' => vars.relocs = true,
'l' => vars.load_config = true,
't' => vars.tls = true,
'c' => vars.exceptions = true,
'x' => vars.resources = true,
'g' => vars.debug_info = true,
_ => abort(INVALID_ARG),
Expand Down Expand Up @@ -280,6 +290,24 @@ fn dump_pe64(args: &Parameters, file: pelite::pe64::PeFile) {
println!("No TLS Directory found.");
}
}
if args.exceptions {
use pelite::pe64::exception_arm64::Arm64ExceptionExt;

print!("{}", SEPARATOR);
let machine = file.file_header().Machine;
if machine == IMAGE_FILE_MACHINE_ARM64 {
match file.exception_arm64() {
Ok(exceptions) => print!("{:#?}", exceptions),
Err(_) => println!("No Exception Directory found."),
}
}
else if let Ok(exceptions) = file.exception() {
print!("{:#?}", exceptions);
}
else {
println!("No Exception Directory found.");
}
}
if args.debug_info {
print!("{}", SEPARATOR);
if let Ok(debug) = file.debug() {
Expand Down Expand Up @@ -361,6 +389,25 @@ fn dump_pe32(args: &Parameters, file: pelite::pe32::PeFile) {
println!("No TLS Directory found.");
}
}
if args.exceptions {
print!("{}", SEPARATOR);
if let Ok(exceptions) = file.exception() {
println!("Exception Directory - {} entries", exceptions.image().len());
for (index, func) in exceptions.functions().enumerate() {
let image = func.image();
println!(
"[{:04}] begin=0x{:08x} end=0x{:08x} unwind=0x{:08x}",
index,
image.BeginAddress,
image.EndAddress,
image.UnwindData,
);
}
}
else {
println!("No Exception Directory found.");
}
}
if args.debug_info {
print!("{}", SEPARATOR);
if let Ok(debug) = file.debug() {
Expand Down
11 changes: 11 additions & 0 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct IMAGE_DOS_HEADER {
pub const IMAGE_FILE_MACHINE_I386: u16 = 0x014c;
pub const IMAGE_FILE_MACHINE_IA64: u16 = 0x0200;
pub const IMAGE_FILE_MACHINE_AMD64: u16 = 0x8664;
pub const IMAGE_FILE_MACHINE_ARM64: u16 = 0xaa64;

pub const IMAGE_FILE_RELOCS_STRIPPED: u16 = 0x0001;
pub const IMAGE_FILE_EXECUTABLE_IMAGE: u16 = 0x0002;
Expand Down Expand Up @@ -825,6 +826,14 @@ pub struct RUNTIME_FUNCTION {
pub UnwindData: u32,
}

#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
#[repr(C)]
pub struct IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY {
pub BeginAddress: u32,
pub UnwindData: u32,
}

#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
#[repr(C)]
Expand Down Expand Up @@ -996,6 +1005,7 @@ unsafe impl Pod for WIN_CERTIFICATE {}
unsafe impl Pod for UNWIND_CODE {}
unsafe impl Pod for UNWIND_INFO {}
unsafe impl Pod for RUNTIME_FUNCTION {}
unsafe impl Pod for IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY {}
unsafe impl Pod for SCOPE_RECORD {}
unsafe impl Pod for SCOPE_TABLE {}
unsafe impl Pod for GUID {}
Expand Down Expand Up @@ -1035,6 +1045,7 @@ const _: [(); 40] = [(); mem::size_of::<IMAGE_TLS_DIRECTORY64>()];
const _: [(); 2] = [(); mem::size_of::<UNWIND_CODE>()];
const _: [(); 4] = [(); mem::size_of::<UNWIND_INFO>()]; // Unsized
const _: [(); 12] = [(); mem::size_of::<RUNTIME_FUNCTION>()];
const _: [(); 8] = [(); mem::size_of::<IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY>()];
const _: [(); 4] = [(); mem::size_of::<SCOPE_TABLE>()]; // Unsized
const _: [(); 16] = [(); mem::size_of::<SCOPE_RECORD>()];
const _: [(); 16] = [(); mem::size_of::<GUID>()];
Expand Down
21 changes: 18 additions & 3 deletions src/pe64/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,24 @@ impl<'a, P: Pe<'a>> Exception<'a, P> {
#[rustfmt::skip]
impl<'a, P: Pe<'a>> fmt::Debug for Exception<'a, P> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Exception")
.field("functions.len", &self.image.len())
.finish()
writeln!(f, "Exception {{")?;
writeln!(f, " functions.len: {},", self.image.len())?;
writeln!(f, " functions: [")?;
for (index, function) in self.functions().enumerate() {
let image = function.image();
let size = image.EndAddress.saturating_sub(image.BeginAddress);
writeln!(
f,
" [{:04}] begin=0x{:08x} end=0x{:08x} size=0x{:04x} unwind=0x{:08x},",
index,
image.BeginAddress,
image.EndAddress,
size,
image.UnwindData
)?;
}
writeln!(f, " ]")?;
write!(f, "}}")
}
}

Expand Down
Loading