From fce80fe0193b235f77142b2b76951793cc383af2 Mon Sep 17 00:00:00 2001 From: Jean-Marie Mineau Date: Wed, 26 Mar 2025 15:07:46 +0100 Subject: [PATCH] add DexString::conctatenate and Idype::class_from_dex_string --- androscalpel/src/code_analysis/register_type.rs | 2 +- androscalpel/src/dex_id.rs | 11 +++++++++++ androscalpel/src/dex_string.rs | 16 ++++++++++++++++ androscalpel/src/dex_writer.rs | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/androscalpel/src/code_analysis/register_type.rs b/androscalpel/src/code_analysis/register_type.rs index e20e965..3ade15b 100644 --- a/androscalpel/src/code_analysis/register_type.rs +++ b/androscalpel/src/code_analysis/register_type.rs @@ -54,7 +54,7 @@ impl MethodCFG<'_> { return HashMap::new(); } // 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 { end_block_reg_tys[0][i] = RegType::Object; // 'this' i += 1; diff --git a/androscalpel/src/dex_id.rs b/androscalpel/src/dex_id.rs index 8d09483..75676ad 100644 --- a/androscalpel/src/dex_id.rs +++ b/androscalpel/src/dex_id.rs @@ -428,6 +428,17 @@ impl IdType { 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_` #[cfg_attr(feature = "python", staticmethod)] pub fn array(type_: &IdType) -> Self { diff --git a/androscalpel/src/dex_string.rs b/androscalpel/src/dex_string.rs index bb42dd3..4da2dc6 100644 --- a/androscalpel/src/dex_string.rs +++ b/androscalpel/src/dex_string.rs @@ -210,4 +210,20 @@ impl DexString { strings.insert(self.clone()); 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(), + }) + } } diff --git a/androscalpel/src/dex_writer.rs b/androscalpel/src/dex_writer.rs index 8c504b5..3ed6ec4 100644 --- a/androscalpel/src/dex_writer.rs +++ b/androscalpel/src/dex_writer.rs @@ -424,7 +424,7 @@ impl DexWriter { .unwrap() }; 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(); // Estimate instructions addresses let mut min_addr = 0;