serialize part of the debug info item
This commit is contained in:
parent
6637745cdf
commit
0b8dce9266
4 changed files with 32 additions and 13 deletions
|
|
@ -35,11 +35,8 @@ impl Apk {
|
||||||
let class = self.get_class_from_dex_file(class, &dex)?;
|
let class = self.get_class_from_dex_file(class, &dex)?;
|
||||||
self.classes.insert(class.descriptor.clone(), class);
|
self.classes.insert(class.descriptor.clone(), class);
|
||||||
}
|
}
|
||||||
self.not_referenced_strings.extend(
|
self.not_referenced_strings
|
||||||
dex.get_not_resolved_strings()?
|
.extend(dex.get_not_resolved_strings()?.into_iter().map(DexString));
|
||||||
.into_iter()
|
|
||||||
.map(|string| DexString(string)),
|
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2203,9 +2200,13 @@ impl Apk {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let debug_info = if let Some(debug_info) = debug_info {
|
let debug_info = if let Some(debug_info) = debug_info {
|
||||||
debug_info.serialize_to_vec()?
|
let mut cursor = std::io::Cursor::new(vec![]);
|
||||||
|
debug_info
|
||||||
|
.bytecode
|
||||||
|
.serialize(&mut cursor, DbgBytecode::EndSequence)?;
|
||||||
|
(debug_info.line_start.0, cursor.into_inner())
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
(0, vec![])
|
||||||
};
|
};
|
||||||
let mut labels: HashMap<usize, String> = HashMap::new();
|
let mut labels: HashMap<usize, String> = HashMap::new();
|
||||||
let mut tries = HashMap::new();
|
let mut tries = HashMap::new();
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ pub struct Code {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
/// The debug info
|
/// The debug info
|
||||||
#[pyo3(get)]
|
#[pyo3(get)]
|
||||||
pub debug_info: Vec<u8>, // Should be stripped, copying like this just don't work
|
pub debug_info: (u32, Vec<u8>), // Should be stripped, copying like this just don't work
|
||||||
/// The names of the parameters if given
|
/// The names of the parameters if given
|
||||||
#[pyo3(get)]
|
#[pyo3(get)]
|
||||||
pub parameter_names: Option<Vec<Option<DexString>>>,
|
pub parameter_names: Option<Vec<Option<DexString>>>,
|
||||||
|
|
@ -81,7 +81,7 @@ impl Code {
|
||||||
outs_size,
|
outs_size,
|
||||||
insns,
|
insns,
|
||||||
parameter_names,
|
parameter_names,
|
||||||
debug_info: vec![],
|
debug_info: (0, vec![]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1308,13 +1308,32 @@ impl DexWriter {
|
||||||
try_.handler_off += handlers.size_field().size() as u16;
|
try_.handler_off += handlers.size_field().size() as u16;
|
||||||
}
|
}
|
||||||
|
|
||||||
let debug_info_off = if code.debug_info.is_empty() {
|
let debug_info_off = if code.debug_info.1.is_empty() && code.parameter_names.is_none() {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
let debug_info_off = self
|
let debug_info_off = self
|
||||||
.section_manager
|
.section_manager
|
||||||
.get_aligned_size(Section::DebugInfoItem);
|
.get_aligned_size(Section::DebugInfoItem);
|
||||||
let item = DebugInfoItem::deserialize_from_slice(&code.debug_info)?;
|
let mut cursor = Cursor::new(code.debug_info.1);
|
||||||
|
let mut item = DebugInfoItem {
|
||||||
|
line_start: Uleb128(code.debug_info.0),
|
||||||
|
parameter_names: vec![],
|
||||||
|
bytecode: Vec::<DbgBytecode>::deserialize(&mut cursor, DbgBytecode::EndSequence)?,
|
||||||
|
};
|
||||||
|
if let Some(parameter_names) = code.parameter_names {
|
||||||
|
for name in ¶meter_names {
|
||||||
|
if let Some(name) = name {
|
||||||
|
item.parameter_names
|
||||||
|
.push(Uleb128p1(*self.strings.get(name).ok_or(anyhow!(
|
||||||
|
"String {} (name of param of {}) not found",
|
||||||
|
name.__str__(),
|
||||||
|
method_id.__repr__()
|
||||||
|
))? as u32));
|
||||||
|
} else {
|
||||||
|
item.parameter_names.push(NO_INDEX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
self.section_manager
|
self.section_manager
|
||||||
.add_elt(Section::DebugInfoItem, Some(item.size()));
|
.add_elt(Section::DebugInfoItem, Some(item.size()));
|
||||||
self.debug_info_items.push(item);
|
self.debug_info_items.push(item);
|
||||||
|
|
@ -2600,7 +2619,6 @@ impl DexWriter {
|
||||||
set.serialize(&mut buffer)?;
|
set.serialize(&mut buffer)?;
|
||||||
}
|
}
|
||||||
// CodeItem section
|
// CodeItem section
|
||||||
println!("Actual code offset: 0x{:x}", buffer.position());
|
|
||||||
self.check_section_offset(&buffer, Section::CodeItem);
|
self.check_section_offset(&buffer, Section::CodeItem);
|
||||||
for code_item in &self.code_items {
|
for code_item in &self.code_items {
|
||||||
Self::fix_section_alignement(&mut buffer, Section::CodeItem)?;
|
Self::fix_section_alignement(&mut buffer, Section::CodeItem)?;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ pub struct DexFileReader<'a> {
|
||||||
header: HeaderItem,
|
header: HeaderItem,
|
||||||
string_ids: Vec<StringIdItem>,
|
string_ids: Vec<StringIdItem>,
|
||||||
/// If `string_was_resolved[string_idx]` is true, the string was resolved at some point.
|
/// If `string_was_resolved[string_idx]` is true, the string was resolved at some point.
|
||||||
/// This alows us to get the strings that are in a dex file but not used by its
|
/// This allows us to get the strings that are in a dex file but not used by its
|
||||||
/// classes. (Yes, they are some, looking at you `~~D8{"backend":"dex","compilation-mode":
|
/// classes. (Yes, they are some, looking at you `~~D8{"backend":"dex","compilation-mode":
|
||||||
/// "release","has-checksums":false,"min-api":24,"version":"8.2.42"}`)
|
/// "release","has-checksums":false,"min-api":24,"version":"8.2.42"}`)
|
||||||
string_was_resolved: Vec<AtomicBool>,
|
string_was_resolved: Vec<AtomicBool>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue