-
Notifications
You must be signed in to change notification settings - Fork 2
/
dol_dump.rs
112 lines (100 loc) · 3.02 KB
/
dol_dump.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use std::path::PathBuf;
use clap::Parser;
use picori::Dol;
extern crate picori;
/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(
name = "dol_dump",
bin_name = "dol_dump",
author="Julgodis <self@julgodis.xyz>",
version=env!("CARGO_PKG_VERSION"),
about="Example program to dump .dol files using picori",
long_about = None)]
struct Args {
/// Path to the file to dump
#[arg()]
path: PathBuf,
/// Dump header
#[arg(short = 't', long)]
header: bool,
/// Dump sections
#[arg(short, long)]
sections: bool,
/// Dump data
#[arg(short, long)]
data: bool,
/// Dump all
#[arg(short, long)]
all: bool,
/// Column width
#[arg(short, long, default_value = "32")]
width: usize,
}
fn main() {
let args = Args::parse();
let mut dump_header = args.header;
let mut dump_sections = args.sections;
let mut dump_data = args.data;
if args.all {
dump_header = true;
dump_sections = true;
dump_data = true;
}
if !dump_header && !dump_sections && !dump_data {
println!("nothing to dump :(");
return;
}
let file = std::fs::File::open(args.path).unwrap();
let mut file = std::io::BufReader::new(file);
let dol = Dol::from_binary(&mut file).unwrap();
if dump_header {
println!("header:");
for i in 0..7 {
println!(
" [{:>2}] text offset: 0x{:08x}, address: 0x{:08x}, size: 0x{:08x}",
i, dol.header.text_offset[i], dol.header.text_address[i], dol.header.text_size[i]
);
}
for i in 0..11 {
println!(
" [{:>2}] data offset: 0x{:08x}, address: 0x{:08x}, size: 0x{:08x}",
i, dol.header.data_offset[i], dol.header.data_address[i], dol.header.data_size[i]
);
}
println!(
" bss address: 0x{:08x}, size: 0x{:08x}",
dol.header.bss_address, dol.header.bss_size
);
println!(" entry point: 0x{:08x}", dol.header.entry_point);
}
if dump_sections {
println!("sections:");
for (i, section) in dol.sections.iter().enumerate() {
println!(
" [{:>2}] {:<15} address: 0x{:08x}, size: 0x{:06x} (0x{:06x})",
i, section.name, section.address, section.size, section.aligned_size
);
}
}
if dump_data {
let width = match args.width {
0 => 1,
_ => args.width,
};
println!("data:");
for (i, section) in dol.sections.iter().enumerate() {
println!(
" [{:>2}] {:<15} address: 0x{:08x}",
i, section.name, section.address
);
for (j, line) in section.data.chunks(width).enumerate() {
print!("{:06x}: ", j * 32);
for byte in line {
print!("{:02x} ", byte);
}
println!();
}
}
}
}