Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

Commit 0c3f9a7

Browse files
authored
Merge pull request #55 from Razican/update
Updated packages and formatted. Also fixed 3 warnings.
2 parents 17abb6e + ec152c2 commit 0c3f9a7

30 files changed

+8100
-637
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ rust:
2424
- nightly
2525
- beta
2626
- stable
27-
- 1.15.1
27+
- 1.20.0
2828

2929
matrix:
3030
allow_failures:
@@ -52,4 +52,4 @@ notifications:
5252
recipients:
5353
5454
on_success: change
55-
on_failure: always
55+
on_failure: always

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Parser for resources.arsc contained on APKs and binary XML decompresser
1010
keywords = ["android", "arsc", "apk", "parser"]
1111

1212
[dependencies]
13-
byteorder = "^1.0"
14-
error-chain = "^0.10"
15-
ansi_term = "^0.9"
16-
log = "^0.3"
17-
env_logger = "^0.4"
18-
zip = { version = "^0.2", optional = true}
19-
encoding = "^0.2"
20-
xml-rs = "^0.4"
13+
byteorder = "1.1"
14+
error-chain = "0.11"
15+
ansi_term = "0.10"
16+
log = "0.3"
17+
env_logger = "0.4"
18+
zip = { version = "0.2", optional = true}
19+
encoding = "0.2"
20+
xml-rs = "0.6"
2121

2222
[features]
2323
default = ["zip_decode"]

examples/converter.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ fn run() -> Result<()> {
6060
let mut archive = zip::ZipArchive::new(file).unwrap();
6161

6262
let mut resources_content = Vec::new();
63-
archive
64-
.by_name("resources.arsc")
65-
.unwrap()
66-
.read_to_end(&mut resources_content)?;
63+
archive.by_name("resources.arsc").unwrap().read_to_end(
64+
&mut resources_content,
65+
)?;
6766

6867
let mut resources_visitor = ModelVisitor::default();
6968
Executor::arsc(&resources_content, &mut resources_visitor)?;
@@ -80,8 +79,9 @@ fn run() -> Result<()> {
8079
let new_content = xml_content.clone();
8180

8281
let resources = resources_visitor.get_resources();
83-
let out = parse_xml(&new_content, resources)
84-
.chain_err(|| "Could not decode target file")?;
82+
let out = parse_xml(&new_content, resources).chain_err(
83+
|| "Could not decode target file",
84+
)?;
8585
println!("{}", out);
8686
}
8787
}
@@ -100,8 +100,9 @@ fn parse_xml<'a>(content: &[u8], resources: &'a Resources<'a>) -> Result<String>
100100
Some(ref root) => {
101101
match *visitor.get_string_table() {
102102
Some(_) => {
103-
return Xml::encode(visitor.get_namespaces(), root)
104-
.chain_err(|| "Could note encode XML");
103+
return Xml::encode(visitor.get_namespaces(), root).chain_err(
104+
|| "Could note encode XML",
105+
);
105106
}
106107
None => {
107108
println!("No string table found");

examples/exporter.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ fn run() -> Result<()> {
5252

5353
let path = Path::new(&apk_path);
5454
let mut apk = Apk::new(path).chain_err(|| "Error loading APK")?;
55-
apk.export(Path::new(&output), true)
56-
.chain_err(|| "APK could not be exported")?;
55+
apk.export(Path::new(&output), true).chain_err(
56+
|| "APK could not be exported",
57+
)?;
5758

5859
Ok(())
5960
}

src/apk.rs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ impl Apk {
1919
let mut buffer = Vec::new();
2020
let file = std::fs::File::open(&path)?;
2121
let mut zip_handler = ZipArchive::new(file)?;
22-
zip_handler
23-
.by_name("resources.arsc")?
24-
.read_to_end(&mut buffer)?;
22+
zip_handler.by_name("resources.arsc")?.read_to_end(
23+
&mut buffer,
24+
)?;
2525

2626
let apk = Apk {
2727
handler: zip_handler,
@@ -34,40 +34,43 @@ impl Apk {
3434
/// It exports to target output_path the contents of the APK, transcoding the binary XML files
3535
/// found on it.
3636
pub fn export<P: AsRef<Path>>(&mut self, output_path: P, force: bool) -> Result<()> {
37-
let decoder = self.decoder
38-
.get_decoder()
39-
.chain_err(|| "Could not get the decoder")?;
37+
let decoder = self.decoder.get_decoder().chain_err(
38+
|| "Could not get the decoder",
39+
)?;
4040

4141
if fs::create_dir_all(&output_path).is_err() && force {
42-
fs::remove_dir_all(&output_path)
43-
.chain_err(|| {
44-
format!("Could not clean target directory: {}",
45-
output_path.as_ref().display())
46-
})?;
47-
fs::create_dir_all(&output_path)
48-
.chain_err(|| {
49-
format!("Error creating the output folder: {}",
50-
output_path.as_ref().display())
51-
})?;
42+
fs::remove_dir_all(&output_path).chain_err(|| {
43+
format!(
44+
"Could not clean target directory: {}",
45+
output_path.as_ref().display()
46+
)
47+
})?;
48+
fs::create_dir_all(&output_path).chain_err(|| {
49+
format!(
50+
"Error creating the output folder: {}",
51+
output_path.as_ref().display()
52+
)
53+
})?;
5254
}
5355

5456
// Iterate over all the files on the ZIP and extract them
5557
for i in 0..self.handler.len() {
5658
let (file_name, contents) = {
57-
let mut current_file = self.handler
58-
.by_index(i)
59-
.chain_err(|| "Could not read ZIP entry")?;
59+
let mut current_file = self.handler.by_index(i).chain_err(
60+
|| "Could not read ZIP entry",
61+
)?;
6062
let mut contents = Vec::new();
61-
current_file
62-
.read_to_end(&mut contents)
63-
.chain_err(|| format!("Could not read: {}", current_file.name()))?;
63+
current_file.read_to_end(&mut contents).chain_err(|| {
64+
format!("Could not read: {}", current_file.name())
65+
})?;
6466
let is_xml = current_file.name().to_string();
6567

6668
(is_xml, contents)
6769
};
6870

6971
let contents = if (file_name.starts_with("res/") && file_name.ends_with(".xml")) ||
70-
file_name == "AndroidManifest.xml" {
72+
file_name == "AndroidManifest.xml"
73+
{
7174

7275
decoder
7376
.xml_visitor(&contents)
@@ -86,24 +89,26 @@ impl Apk {
8689
Ok(())
8790
}
8891

89-
fn write_file<B: AsRef<Path>, R: AsRef<Path>>(base_path: B,
90-
relative: R,
91-
content: &[u8])
92-
-> Result<()> {
92+
fn write_file<B: AsRef<Path>, R: AsRef<Path>>(
93+
base_path: B,
94+
relative: R,
95+
content: &[u8],
96+
) -> Result<()> {
9397
let full_path = base_path.as_ref().join(&relative);
9498
// println!("Full path: {}", full_path.display());
95-
fs::create_dir_all(full_path.parent().unwrap())
96-
.chain_err(|| "Could not create the output dir")?;
99+
fs::create_dir_all(full_path.parent().unwrap()).chain_err(
100+
|| "Could not create the output dir",
101+
)?;
97102

98103
let mut descriptor = fs::OpenOptions::new()
99104
.write(true)
100105
.create_new(true)
101106
.open(full_path)
102107
.chain_err(|| "Could not open file to write")?;
103108

104-
descriptor
105-
.write_all(content)
106-
.chain_err(|| "Could not write to target file")?;
109+
descriptor.write_all(content).chain_err(
110+
|| "Could not write to target file",
111+
)?;
107112

108113
Ok(())
109114
}

src/chunks/chunk_header.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ impl ChunkHeader {
5151

5252
impl fmt::Display for ChunkHeader {
5353
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54-
write!(f,
55-
"(Token:{:X}; Start: {}; Data: {}; End {})",
56-
self.chunk_type,
57-
self.offset,
58-
self.get_data_offset(),
59-
self.get_chunk_end())
54+
write!(
55+
f,
56+
"(Token:{:X}; Start: {}; Data: {}; End {})",
57+
self.chunk_type,
58+
self.offset,
59+
self.get_data_offset(),
60+
self.get_chunk_end()
61+
)
6062
}
6163
}
6264

src/chunks/resource.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ impl<'a> ResourceWrapper<'a> {
2121
let amount_of_resources = (count / 4) - 2;
2222

2323
if count > self.raw_data.len() as u32 {
24-
return Err(format!("There is not enough data on the buffer ({}) to read \
24+
return Err(
25+
format!(
26+
"There is not enough data on the buffer ({}) to read \
2527
the reported resources count ({})",
26-
self.raw_data.len(),
27-
count)
28-
.into());
28+
self.raw_data.len(),
29+
count
30+
).into(),
31+
);
2932
}
3033

3134
let mut resources = Vec::with_capacity(amount_of_resources as usize);
@@ -68,8 +71,10 @@ mod tests {
6871

6972
let result = wrapper.get_resources();
7073
assert!(result.is_err());
71-
assert_eq!("There is not enough data on the buffer (16) to read the \
74+
assert_eq!(
75+
"There is not enough data on the buffer (16) to read the \
7276
reported resources count (255)",
73-
result.err().unwrap().to_string());
77+
result.err().unwrap().to_string()
78+
);
7479
}
7580
}

src/chunks/string_table.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ impl<'a> StringTable for StringTableWrapper<'a> {
167167
return Err("Index out of bounds".into());
168168
}
169169

170-
let string = self.get_string_position(idx)
171-
.and_then(|position| self.parse_string(position as u32))?;
170+
let string = self.get_string_position(idx).and_then(|position| {
171+
self.parse_string(position as u32)
172+
})?;
172173

173174
Ok(Rc::new(string))
174175
}

src/chunks/table_type/mod.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'a> TableTypeWrapper<'a> {
4444
self.decode_entries(&mut cursor)
4545
}
4646

47-
fn decode_entries(&self, mut cursor: &mut Cursor<&[u8]>) -> Result<Vec<Entry>> {
47+
fn decode_entries(&self, cursor: &mut Cursor<&[u8]>) -> Result<Vec<Entry>> {
4848
let mut offsets = Vec::new();
4949
let mut entries = Vec::new();
5050

@@ -87,10 +87,11 @@ impl<'a> TableTypeWrapper<'a> {
8787
}
8888
}
8989

90-
fn decode_simple_entry(cursor: &mut Cursor<&[u8]>,
91-
header: &EntryHeader,
92-
id: u32)
93-
-> Result<Option<Entry>> {
90+
fn decode_simple_entry(
91+
cursor: &mut Cursor<&[u8]>,
92+
header: &EntryHeader,
93+
id: u32,
94+
) -> Result<Option<Entry>> {
9495
cursor.read_u16::<LittleEndian>()?;
9596
// Padding
9697
cursor.read_u8()?;
@@ -103,10 +104,11 @@ impl<'a> TableTypeWrapper<'a> {
103104
Ok(Some(entry))
104105
}
105106

106-
fn decode_complex_entry(cursor: &mut Cursor<&[u8]>,
107-
header: &EntryHeader,
108-
id: u32)
109-
-> Result<Option<Entry>> {
107+
fn decode_complex_entry(
108+
cursor: &mut Cursor<&[u8]>,
109+
header: &EntryHeader,
110+
id: u32,
111+
) -> Result<Option<Entry>> {
110112
let parent_entry = cursor.read_u32::<LittleEndian>()?;
111113
let value_count = cursor.read_u32::<LittleEndian>()?;
112114
let mut entries = Vec::with_capacity(value_count as usize);
@@ -116,10 +118,12 @@ impl<'a> TableTypeWrapper<'a> {
116118
}
117119

118120
for j in 0..value_count {
119-
debug!("Parsing value: {}/{} (@{})",
120-
j,
121-
value_count - 1,
122-
cursor.position());
121+
debug!(
122+
"Parsing value: {}/{} (@{})",
123+
j,
124+
value_count - 1,
125+
cursor.position()
126+
);
123127
let val_id = cursor.read_u32::<LittleEndian>()?;
124128
cursor.read_u16::<LittleEndian>()?;
125129
// Padding
@@ -162,7 +166,8 @@ impl<'a> TableType for TableTypeWrapper<'a> {
162166
let end = self.data_offset as usize;
163167

164168
if ini > end || (end - ini) <= 28 || self.raw_data.len() < ini ||
165-
self.raw_data.len() < end {
169+
self.raw_data.len() < end
170+
{
166171
return Err("Configuration slice is not valid".into());
167172
}
168173

@@ -174,9 +179,8 @@ impl<'a> TableType for TableTypeWrapper<'a> {
174179

175180
fn get_entry(&self, index: u32) -> Result<Entry> {
176181
let entries = self.get_entries()?;
177-
entries
178-
.get(index as usize)
179-
.cloned()
180-
.ok_or_else(|| "Entry not found".into())
182+
entries.get(index as usize).cloned().ok_or_else(|| {
183+
"Entry not found".into()
184+
})
181185
}
182186
}

src/chunks/table_type_spec.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ impl<'a> TypeSpec for TypeSpecWrapper<'a> {
4646
let amount = self.get_amount()?;
4747

4848
if index >= amount {
49-
return Err(format!("Invalid flag on index {} out of {}", index, amount).into());
49+
return Err(
50+
format!("Invalid flag on index {} out of {}", index, amount).into(),
51+
);
5052
}
5153

5254
let mut cursor = Cursor::new(self.raw_data);
@@ -75,7 +77,9 @@ mod tests {
7577

7678
let errored_flag = wrapper.get_flag(1541);
7779
assert!(errored_flag.is_err());
78-
assert_eq!("Invalid flag on index 1541 out of 1541",
79-
errored_flag.err().unwrap().to_string());
80+
assert_eq!(
81+
"Invalid flag on index 1541 out of 1541",
82+
errored_flag.err().unwrap().to_string()
83+
);
8084
}
8185
}

0 commit comments

Comments
 (0)