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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use crate::error::*;
use std::path::{Path, PathBuf};
use std::process::Command;
pub struct Aapt2Dump {
subcommand: SubCommand,
filename_apk: PathBuf,
no_values: bool,
dumped_file: Option<PathBuf>,
verbose: bool,
help: bool,
}
impl Aapt2Dump {
pub fn new(subcommand: SubCommand, filename_apk: &Path) -> Self {
Self {
subcommand,
filename_apk: filename_apk.to_owned(),
no_values: false,
dumped_file: None,
verbose: false,
help: false,
}
}
pub fn no_values(&mut self, no_values: bool) -> &mut Self {
self.no_values = no_values;
self
}
pub fn dumped_file(&mut self, dumped_file: &Path) -> &mut Self {
self.dumped_file = Some(dumped_file.to_owned());
self
}
pub fn verbose(&mut self, verbose: bool) -> &mut Self {
self.verbose = verbose;
self
}
pub fn help(&mut self, help: bool) -> &mut Self {
self.help = help;
self
}
pub fn run(&self) -> Result<()> {
let mut aapt2 = Command::new("aapt2");
aapt2.arg("dump");
aapt2.arg(self.subcommand.to_string());
aapt2.arg(&self.filename_apk);
if self.no_values {
aapt2.arg("--no-values");
}
if let Some(dumped_file) = &self.dumped_file {
aapt2.arg("--file").arg(dumped_file);
}
if self.verbose {
aapt2.arg("-v");
}
if self.help {
aapt2.arg("-h");
}
aapt2.output_err(true)?;
Ok(())
}
}
pub enum SubCommand {
Apc,
Badging,
Configurations,
Packagename,
Permissions,
Strings,
Styleparents,
Resources,
Xmlstrings,
Xmltree,
}
impl std::fmt::Display for SubCommand {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Self::Apc => write!(f, "apc"),
Self::Badging => write!(f, "badging"),
Self::Configurations => write!(f, "configurations"),
Self::Packagename => write!(f, "packagename"),
Self::Permissions => write!(f, "permissions"),
Self::Strings => write!(f, "strings"),
Self::Styleparents => write!(f, "styleparents"),
Self::Resources => write!(f, "resources"),
Self::Xmlstrings => write!(f, "xmlstrings"),
Self::Xmltree => write!(f, "xmltree"),
}
}
}