add DexString::conctatenate and Idype::class_from_dex_string

This commit is contained in:
Jean-Marie Mineau 2025-03-26 15:07:46 +01:00
parent 4c4940e6b1
commit fce80fe019
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
4 changed files with 29 additions and 2 deletions

View file

@ -54,7 +54,7 @@ impl MethodCFG<'_> {
return HashMap::new(); return HashMap::new();
} }
// Initialize the entry block from function signature: // Initialize the entry block from function signature:
let mut i = (code.registers_size - code.ins_size(&self.method)) as usize; let mut i = (code.registers_size - code.ins_size(self.method)) as usize;
if !self.method.is_static { if !self.method.is_static {
end_block_reg_tys[0][i] = RegType::Object; // 'this' end_block_reg_tys[0][i] = RegType::Object; // 'this'
i += 1; i += 1;

View file

@ -428,6 +428,17 @@ impl IdType {
Self(format!("L{name};").into()) Self(format!("L{name};").into())
} }
/// Return the type for the class of fully qualified name `name`.
/// Same as [`IdType::class`] but with a [`DexString`] name.
#[cfg_attr(feature = "python", staticmethod)]
pub fn class_from_dex_string(name: &DexString) -> Self {
let mut repr = name.clone();
repr.0.utf16_size.0 += 2;
repr.0.data.insert(0, b'L');
repr.0.data.push(b';');
Self(repr)
}
/// Return the type for an array of the specify `type_` /// Return the type for an array of the specify `type_`
#[cfg_attr(feature = "python", staticmethod)] #[cfg_attr(feature = "python", staticmethod)]
pub fn array(type_: &IdType) -> Self { pub fn array(type_: &IdType) -> Self {

View file

@ -210,4 +210,20 @@ impl DexString {
strings.insert(self.clone()); strings.insert(self.clone());
strings strings
} }
/// Build the concatenation of two string.
pub fn conctatenate(&self, other: &Self) -> Self {
let Self(androscalpel_serializer::StringDataItem {
utf16_size: androscalpel_serializer::Uleb128(size1),
data: data1,
}) = self.clone();
let Self(androscalpel_serializer::StringDataItem {
utf16_size: androscalpel_serializer::Uleb128(size2),
data: data2,
}) = other.clone();
Self(androscalpel_serializer::StringDataItem {
utf16_size: androscalpel_serializer::Uleb128(size1 + size2),
data: data1.into_iter().chain(data2).collect(),
})
}
} }

View file

@ -424,7 +424,7 @@ impl DexWriter {
.unwrap() .unwrap()
}; };
let code = method.code.as_ref().unwrap().clone(); let code = method.code.as_ref().unwrap().clone();
let ins_size = code.ins_size(&method); let ins_size = code.ins_size(method);
let outs_size = code.outs_size(); let outs_size = code.outs_size();
// Estimate instructions addresses // Estimate instructions addresses
let mut min_addr = 0; let mut min_addr = 0;