Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readobj: add --no-string-indices option #629

Merged
merged 1 commit into from
Feb 3, 2024
Merged
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
8 changes: 8 additions & 0 deletions crates/examples/src/bin/readobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ fn main() {
.action(ArgAction::SetTrue)
.help("Print the PE resource directory"),
)
.arg(
Arg::new("no-string-indices")
.long("no-string-indices")
.action(ArgAction::SetTrue)
.help("Don't print string table indices"),
)
.get_matches();
let mut options = readobj::PrintOptions {
file: matches.get_flag("file-header"),
Expand All @@ -128,10 +134,12 @@ fn main() {
pe_imports: matches.get_flag("pe-imports"),
pe_exports: matches.get_flag("pe-exports"),
pe_resources: matches.get_flag("pe-resources"),
..readobj::PrintOptions::none()
};
if options == readobj::PrintOptions::none() {
options = readobj::PrintOptions::all();
}
options.string_indices = !matches.get_flag("no-string-indices");

let file_paths = matches.get_many::<PathBuf>("file").unwrap();
let file_count = file_paths.len();
Expand Down
19 changes: 15 additions & 4 deletions crates/examples/src/readobj/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,36 @@ use object::Endianness;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PrintOptions {
// Selectors
pub file: bool,
pub segments: bool,
pub sections: bool,
pub symbols: bool,
pub relocations: bool,

// ELF specific
// ELF specific selectors
pub elf_dynamic: bool,
pub elf_dynamic_symbols: bool,
pub elf_notes: bool,
pub elf_versions: bool,
pub elf_attributes: bool,

// Mach-O specific
// Mach-O specific selectors
pub macho_load_commands: bool,

// PE specific
// PE specific selectors
pub pe_rich: bool,
pub pe_base_relocs: bool,
pub pe_imports: bool,
pub pe_exports: bool,
pub pe_resources: bool,

// Modifiers
pub string_indices: bool,
}

impl PrintOptions {
/// Returns a new `PrintOptions` with all selectors enabled and default modifiers.
pub fn all() -> Self {
Self {
file: true,
Expand All @@ -50,9 +55,11 @@ impl PrintOptions {
pe_imports: true,
pe_exports: true,
pe_resources: true,
string_indices: true,
}
}

/// Returns a new `PrintOptions` with all selectors disabled and default modifiers.
pub fn none() -> Self {
Self {
file: false,
Expand All @@ -71,6 +78,7 @@ impl PrintOptions {
pe_imports: false,
pe_exports: false,
pe_resources: false,
string_indices: true,
}
}
}
Expand Down Expand Up @@ -159,7 +167,10 @@ impl<'a> Printer<'a> {
if let Some(s) = s {
self.field_name(name);
self.print_string(s);
writeln!(self.w, " (0x{:X})", value).unwrap();
if self.options.string_indices {
write!(self.w, " (0x{:X})", value).unwrap();
}
writeln!(self.w).unwrap();
} else {
self.field_hex(name, value);
}
Expand Down
Loading