Skip to content

Commit 2a05b83

Browse files
committed
printer now prints sections as well
1 parent a82b027 commit 2a05b83

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use thiserror::Error;
33
use std::io;
44

5-
// TODO: improve this. I need backtrace as well...
5+
// TODO: Make sure all is covered. backtrace required as well...
66
#[derive(Error, Debug)]
77
pub enum AppError {
88
#[error("IO Error")]

src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ mod parser;
1414
mod printer;
1515
mod error;
1616

17-
// TODO: add another command to print only brief of the file data (like in the beginning oof binja)
18-
1917
/// A command-line tool written in Rust to view and explore mach-o files.
2018
#[derive(Parser)]
2119
#[command(name = "Mach_O_Rust")]

src/parser.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ fn parse_load_commands<R: Read + Seek, E: ByteOrder>(file: &mut R, header: &Mach
6565
sections.push(load_command_sections);
6666
load_commands_strings.push(load_command_string);
6767

68-
// TODO: this one could be removed after we finish the parsing inline logic.
6968
advance_to_next_load_command(file, offset, load_command_prefix.cmdsize as u64)?;
7069
}
7170
Ok((load_commands, sections, load_commands_strings))
7271
}
7372

74-
// TODO: Handle all of the warnings emitted from building. I need to sub-parse some commands...
73+
// TODO: Sub-parse remaining commands as seen on warning after build...
7574
fn parse_command<R: Read, E: ByteOrder>(file: &mut R, load_command_prefix: &LoadCommandPrefix) ->Result<LoadCommand, AppError> {
7675
match load_command_prefix.cmd {
7776
LC_SYMTAB => SymtabCommand::from_file::<R, E>(file, load_command_prefix),
@@ -108,8 +107,6 @@ fn parse_command<R: Read, E: ByteOrder>(file: &mut R, load_command_prefix: &Load
108107
}
109108
}
110109

111-
112-
// TODO: make sure this works as intentional by printing it in printer.rs or by debug...
113110
fn parse_sections_for_segment<R: Read + Seek, E: ByteOrder>(file: &mut R, load_command: &LoadCommand) -> Result<Vec<Section>, AppError> {
114111
let mut load_command_sections = Vec::new();
115112
match load_command {

src/printer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub fn print_load_commands(load_commands: &(Vec<LoadCommand>, Vec<Vec<Section>>,
352352

353353
fn print_segment_command32(command: &SegmentCommand32, table: &mut Table) {
354354
print_lc_cmd_and_cmdsize(command.cmd, command.cmdsize, table);
355-
print_segname_bytes_array(&command.segname, table);
355+
print_segname_or_sectname_bytes_array(&command.segname, table);
356356
table.add_row(row![ Fcc->"vmaddr", Fyc->format!("0x{:x}", command.vmaddr), c->"-"]);
357357
table.add_row(row![ Fcc->"vmsize", Fyc->format!("0x{:x}", command.vmsize), c->"-"]);
358358
table.add_row(row![ Fcc->"fileoff", Fyc->format!("0x{:x}", command.fileoff), c->"-"]);
@@ -365,7 +365,7 @@ fn print_segment_command32(command: &SegmentCommand32, table: &mut Table) {
365365

366366
fn print_segment_command64(command: &SegmentCommand64, table: &mut Table) {
367367
print_lc_cmd_and_cmdsize(command.cmd, command.cmdsize, table);
368-
print_segname_bytes_array(&command.segname, table);
368+
print_segname_or_sectname_bytes_array(&command.segname, table);
369369
table.add_row(row![ Fcc->"vmaddr", Fyc->format!("0x{:x}", command.vmaddr), c->"-"]);
370370
table.add_row(row![ Fcc->"vmsize", Fyc->format!("0x{:x}", command.vmsize), c->"-"]);
371371
table.add_row(row![ Fcc->"fileoff", Fyc->format!("0x{:x}", command.fileoff), c->"-"]);
@@ -376,7 +376,7 @@ fn print_segment_command64(command: &SegmentCommand64, table: &mut Table) {
376376
print_segment_flags(command.flags, table);
377377
}
378378

379-
fn print_segname_bytes_array(bytes: &[u8], table: &mut Table) {
379+
fn print_segname_or_sectname_bytes_array(bytes: &[u8], table: &mut Table) {
380380
let mut result = String::from("[");
381381
for (index, &byte) in bytes.iter().enumerate() {
382382
if index % 4 == 0 && index != 0 {
@@ -455,8 +455,8 @@ fn print_sections_for_segment(sections: &Vec<Section>, table: &mut Table) {
455455
}
456456

457457
fn print_section32(section: &Section32, table: &mut Table) {
458-
print_segname_bytes_array(&section.sectname, table);
459-
print_segname_bytes_array(&section.segname, table);
458+
print_segname_or_sectname_bytes_array(&section.sectname, table);
459+
print_segname_or_sectname_bytes_array(&section.segname, table);
460460
table.add_row(row![ Fcc->"addr", Fyc->format!("0x{:x}", section.addr), c->"-"]);
461461
table.add_row(row![ Fcc->"size", Fyc->format!("0x{:x}", section.size), c->"-"]);
462462
table.add_row(row![ Fcc->"offset", Fyc->format!("0x{:x}", section.offset), c->"-"]);
@@ -469,8 +469,8 @@ fn print_section32(section: &Section32, table: &mut Table) {
469469
}
470470

471471
fn print_section64(section: &Section64, table: &mut Table) {
472-
print_segname_bytes_array(&section.sectname, table);
473-
print_segname_bytes_array(&section.segname, table);
472+
print_segname_or_sectname_bytes_array(&section.sectname, table);
473+
print_segname_or_sectname_bytes_array(&section.segname, table);
474474
table.add_row(row![ Fcc->"addr", Fyc->format!("0x{:x}", section.addr), c->"-"]);
475475
table.add_row(row![ Fcc->"size", Fyc->format!("0x{:x}", section.size), c->"-"]);
476476
table.add_row(row![ Fcc->"offset", Fyc->format!("0x{:x}", section.offset), c->"-"]);

0 commit comments

Comments
 (0)