diff --git a/androscalpel/src/instructions.rs b/androscalpel/src/instructions.rs index dc44fef..433ca39 100644 --- a/androscalpel/src/instructions.rs +++ b/androscalpel/src/instructions.rs @@ -26584,20 +26584,20 @@ impl AddIntLit { {}", self.dest, self.b, self.lit ) - } else if reg_on_4_bit { - InsFormat::Format22S { - op: 0xd0, - va: self.dest, - vb: self.b, - c: self.lit, - } - } else { + } else if lit_on_8_bits { InsFormat::Format22B { op: 0xd8, va: self.dest, vb: self.b, c: self.lit as i8, } + } else { + InsFormat::Format22S { + op: 0xd0, + va: self.dest, + vb: self.b, + c: self.lit, + } } } } @@ -26760,20 +26760,20 @@ impl RsubIntLit { {}", self.dest, self.b, self.lit ) - } else if reg_on_4_bit { - InsFormat::Format22S { - op: 0xd1, - va: self.dest, - vb: self.b, - c: self.lit, - } - } else { + } else if lit_on_8_bits { InsFormat::Format22B { op: 0xd9, va: self.dest, vb: self.b, c: self.lit as i8, } + } else { + InsFormat::Format22S { + op: 0xd1, + va: self.dest, + vb: self.b, + c: self.lit, + } } } } @@ -26936,20 +26936,20 @@ impl MulIntLit { {}", self.dest, self.b, self.lit ) - } else if reg_on_4_bit { - InsFormat::Format22S { - op: 0xd2, - va: self.dest, - vb: self.b, - c: self.lit, - } - } else { + } else if lit_on_8_bits { InsFormat::Format22B { op: 0xda, va: self.dest, vb: self.b, c: self.lit as i8, } + } else { + InsFormat::Format22S { + op: 0xd2, + va: self.dest, + vb: self.b, + c: self.lit, + } } } } @@ -27112,20 +27112,20 @@ impl DivIntLit { {}", self.dest, self.b, self.lit ) - } else if reg_on_4_bit { - InsFormat::Format22S { - op: 0xd3, - va: self.dest, - vb: self.b, - c: self.lit, - } - } else { + } else if lit_on_8_bits { InsFormat::Format22B { op: 0xdb, va: self.dest, vb: self.b, c: self.lit as i8, } + } else { + InsFormat::Format22S { + op: 0xd3, + va: self.dest, + vb: self.b, + c: self.lit, + } } } } @@ -27288,20 +27288,20 @@ impl RemIntLit { {}", self.dest, self.b, self.lit ) - } else if reg_on_4_bit { - InsFormat::Format22S { - op: 0xd4, - va: self.dest, - vb: self.b, - c: self.lit, - } - } else { + } else if lit_on_8_bits { InsFormat::Format22B { op: 0xdc, va: self.dest, vb: self.b, c: self.lit as i8, } + } else { + InsFormat::Format22S { + op: 0xd4, + va: self.dest, + vb: self.b, + c: self.lit, + } } } } @@ -27464,20 +27464,20 @@ impl AndIntLit { {}", self.dest, self.b, self.lit ) - } else if reg_on_4_bit { - InsFormat::Format22S { - op: 0xd5, - va: self.dest, - vb: self.b, - c: self.lit, - } - } else { + } else if lit_on_8_bits { InsFormat::Format22B { op: 0xdd, va: self.dest, vb: self.b, c: self.lit as i8, } + } else { + InsFormat::Format22S { + op: 0xd5, + va: self.dest, + vb: self.b, + c: self.lit, + } } } } @@ -27640,20 +27640,20 @@ impl OrIntLit { {}", self.dest, self.b, self.lit ) - } else if reg_on_4_bit { - InsFormat::Format22S { - op: 0xd6, - va: self.dest, - vb: self.b, - c: self.lit, - } - } else { + } else if lit_on_8_bits { InsFormat::Format22B { op: 0xde, va: self.dest, vb: self.b, c: self.lit as i8, } + } else { + InsFormat::Format22S { + op: 0xd6, + va: self.dest, + vb: self.b, + c: self.lit, + } } } } @@ -27816,20 +27816,20 @@ impl XorIntLit { {}", self.dest, self.b, self.lit ) - } else if reg_on_4_bit { - InsFormat::Format22S { - op: 0xd7, - va: self.dest, - vb: self.b, - c: self.lit, - } - } else { + } else if lit_on_8_bits { InsFormat::Format22B { op: 0xdf, va: self.dest, vb: self.b, c: self.lit as i8, } + } else { + InsFormat::Format22S { + op: 0xd7, + va: self.dest, + vb: self.b, + c: self.lit, + } } } } diff --git a/androscalpel_serializer/src/items/instructions.rs b/androscalpel_serializer/src/items/instructions.rs index 9c5ed93..47d188d 100644 --- a/androscalpel_serializer/src/items/instructions.rs +++ b/androscalpel_serializer/src/items/instructions.rs @@ -229,7 +229,7 @@ impl Instruction { if v != 0 { // TODO: is it enforced on actual android system? return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '10x' (00|op) \ + "Dalvik instruction format for op 0x{op:x}: '10x' (00|op) \ requires the first byte to be 0 found {v}" ))); } @@ -277,7 +277,7 @@ impl Instruction { if v != 0 { // TODO: is it enforced on actual android system? return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '20t' (00|op AAAA) \ + "Dalvik instruction format for op 0x{op:x}: '20t' (00|op AAAA) \ requires the first byte to be 0 found {v}" ))); } @@ -385,7 +385,7 @@ impl Instruction { if v != 0 { // TODO: is it enforced on actual android system? return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '30t' (00|op AAAA AAAA) \ + "Dalvik instruction format for op 0x{op:x}: '30t' (00|op AAAA AAAA) \ requires the first byte to be 0 found {v}" ))); } @@ -403,7 +403,7 @@ impl Instruction { if v != 0 { // TODO: is it enforced on actual android system? return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '32x' (00|op AAAA BBBB) \ + "Dalvik instruction format for op 0x{op:x}: '32x' (00|op AAAA BBBB) \ requires the first byte to be 0 found {v}" ))); } @@ -452,7 +452,7 @@ impl Instruction { let vg = val & 0b0000_1111; if a > 5 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35c' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35c' (A|G|op BBBB F|E|D|C) \ requires A to be between 0 and 5, found {a}" ))); } @@ -485,7 +485,7 @@ impl Instruction { let vg = val & 0b0000_1111; if a > 5 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35ms' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35ms' (A|G|op BBBB F|E|D|C) \ requires A to be between 0 and 5, found {a}" ))); } @@ -518,7 +518,7 @@ impl Instruction { let vg = val & 0b0000_1111; if a > 5 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35mi' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35mi' (A|G|op BBBB F|E|D|C) \ requires A to be between 0 and 5, found {a}" ))); } @@ -575,7 +575,7 @@ impl Instruction { let vg = val & 0b0000_1111; if a > 5 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '45cc' (A|G|op BBBB F|E|D|C HHHH) \ + "Dalvik instruction format for op 0x{op:x}: '45cc' (A|G|op BBBB F|E|D|C HHHH) \ requires A to be between 0 and 5, found {a}" ))); } @@ -673,13 +673,13 @@ impl Serializable for Instruction { Self::Format12X { vb, va, op } => { if vb & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '12x' (B|A|op) \ + "Dalvik instruction format for op 0x{op:x}: '12x' (B|A|op) \ requires B to be between 0 and 15, found {vb}" ))); } if va & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '12x' (B|A|op) \ + "Dalvik instruction format for op 0x{op:x}: '12x' (B|A|op) \ requires A to be between 0 and 15, found {va}" ))); } @@ -690,14 +690,14 @@ impl Serializable for Instruction { Self::Format11N { b, va, op } => { if *b < -8 || *b > 7 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '11n' (B|A|op) \ + "Dalvik instruction format for op 0x{op:x}: '11n' (B|A|op) \ requires B to be between -8 and 7, found {b}" ))); } let b = b.to_be_bytes()[0] & 0b0000_1111; if va & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '11n' (B|A|op) \ + "Dalvik instruction format for op 0x{op:x}: '11n' (B|A|op) \ requires A to be between 0 and 15, found {va}" ))); } @@ -763,13 +763,13 @@ impl Serializable for Instruction { Self::Format22T { vb, va, op, c } => { if vb & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '22t' (B|A|op CCCC) \ + "Dalvik instruction format for op 0x{op:x}: '22t' (B|A|op CCCC) \ requires B to be between 0 and 15, found {vb}" ))); } if va & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '22t' (B|A|op CCCC) \ + "Dalvik instruction format for op 0x{op:x}: '22t' (B|A|op CCCC) \ requires A to be between 0 and 15, found {va}" ))); } @@ -781,13 +781,13 @@ impl Serializable for Instruction { Self::Format22S { vb, va, op, c } => { if vb & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '22s' (B|A|op CCCC) \ + "Dalvik instruction format for op 0x{op:x}: '22s' (B|A|op CCCC) \ requires B to be between 0 and 15, found {vb}" ))); } if va & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '22s' (B|A|op CCCC) \ + "Dalvik instruction format for op 0x{op:x}: '22s' (B|A|op CCCC) \ requires A to be between 0 and 15, found {va}" ))); } @@ -800,13 +800,13 @@ impl Serializable for Instruction { Self::Format22C { vb, va, op, c } => { if vb & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '22c' (B|A|op CCCC) \ + "Dalvik instruction format for op 0x{op:x}: '22c' (B|A|op CCCC) \ requires B to be between 0 and 15, found {vb}" ))); } if va & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '22c' (B|A|op CCCC) \ + "Dalvik instruction format for op 0x{op:x}: '22c' (B|A|op CCCC) \ requires A to be between 0 and 15, found {va}" ))); } @@ -818,13 +818,13 @@ impl Serializable for Instruction { Self::Format22CS { vb, va, op, c } => { if vb & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '22cs' (B|A|op CCCC) \ + "Dalvik instruction format for op 0x{op:x}: '22cs' (B|A|op CCCC) \ requires B to be between 0 and 15, found {vb}" ))); } if va & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '22cs' (B|A|op CCCC) \ + "Dalvik instruction format for op 0x{op:x}: '22cs' (B|A|op CCCC) \ requires A to be between 0 and 15, found {va}" ))); } @@ -887,37 +887,37 @@ impl Serializable for Instruction { } => { if *a > 5 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35c' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35c' (A|G|op BBBB F|E|D|C) \ requires A to be between 0 and 5, found {a}" ))); } if vg & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35c' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35c' (A|G|op BBBB F|E|D|C) \ requires G to be between 0 and 15, found {vg}" ))); } if vf & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35c' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35c' (A|G|op BBBB F|E|D|C) \ requires F to be between 0 and 15, found {vf}" ))); } if ve & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35c' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35c' (A|G|op BBBB F|E|D|C) \ requires E to be between 0 and 15, found {ve}" ))); } if vd & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35c' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35c' (A|G|op BBBB F|E|D|C) \ requires D to be between 0 and 15, found {vd}" ))); } if vc & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35c' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35c' (A|G|op BBBB F|E|D|C) \ requires C to be between 0 and 15, found {vc}" ))); } @@ -942,37 +942,37 @@ impl Serializable for Instruction { } => { if *a > 5 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35ms' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35ms' (A|G|op BBBB F|E|D|C) \ requires A to be between 0 and 5, found {a}" ))); } if vg & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35ms' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35ms' (A|G|op BBBB F|E|D|C) \ requires G to be between 0 and 15, found {vg}" ))); } if vf & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35ms' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35ms' (A|G|op BBBB F|E|D|C) \ requires F to be between 0 and 15, found {vf}" ))); } if ve & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35ms' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35ms' (A|G|op BBBB F|E|D|C) \ requires E to be between 0 and 15, found {ve}" ))); } if vd & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35ms' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35ms' (A|G|op BBBB F|E|D|C) \ requires D to be between 0 and 15, found {vd}" ))); } if vc & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35ms' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35ms' (A|G|op BBBB F|E|D|C) \ requires C to be between 0 and 15, found {vc}" ))); } @@ -997,37 +997,37 @@ impl Serializable for Instruction { } => { if *a > 5 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35mi' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35mi' (A|G|op BBBB F|E|D|C) \ requires A to be between 0 and 5, found {a}" ))); } if vg & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35mi' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35mi' (A|G|op BBBB F|E|D|C) \ requires G to be between 0 and 15, found {vg}" ))); } if vf & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35mi' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35mi' (A|G|op BBBB F|E|D|C) \ requires F to be between 0 and 15, found {vf}" ))); } if ve & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35mi' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35mi' (A|G|op BBBB F|E|D|C) \ requires E to be between 0 and 15, found {ve}" ))); } if vd & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35mi' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35mi' (A|G|op BBBB F|E|D|C) \ requires D to be between 0 and 15, found {vd}" ))); } if vc & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '35mi' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '35mi' (A|G|op BBBB F|E|D|C) \ requires C to be between 0 and 15, found {vc}" ))); } @@ -1071,37 +1071,37 @@ impl Serializable for Instruction { } => { if *a > 5 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '45cc' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '45cc' (A|G|op BBBB F|E|D|C) \ requires A to be between 0 and 5, found {a}" ))); } if vg & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '45cc' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '45cc' (A|G|op BBBB F|E|D|C) \ requires G to be between 0 and 15, found {vg}" ))); } if vf & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '45cc' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '45cc' (A|G|op BBBB F|E|D|C) \ requires F to be between 0 and 15, found {vf}" ))); } if ve & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '45cc' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '45cc' (A|G|op BBBB F|E|D|C) \ requires E to be between 0 and 15, found {ve}" ))); } if vd & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '45cc' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '45cc' (A|G|op BBBB F|E|D|C) \ requires D to be between 0 and 15, found {vd}" ))); } if vc & 0b1111_0000 != 0 { return Err(Error::InconsistantStruct(format!( - "Dalvik instruction format '45cc' (A|G|op BBBB F|E|D|C) \ + "Dalvik instruction format for op 0x{op:x}: '45cc' (A|G|op BBBB F|E|D|C) \ requires C to be between 0 and 15, found {vc}" ))); } diff --git a/test.py b/test.py index 05a5504..fa28b53 100644 --- a/test.py +++ b/test.py @@ -85,16 +85,16 @@ for dex in dex_raw: new_apk.add_dex_file(dex) -# print("[+] Repackage") -# -# utils.replace_dex( -# APK_NAME, -# APK_NAME.parent / (APK_NAME.name.removesuffix(".apk") + "-instrumented.apk"), -# dex_raw, -# Path().parent / "my-release-key.jks", -# zipalign=Path.home() / "Android" / "Sdk" / "build-tools" / "34.0.0" / "zipalign", -# apksigner=Path.home() / "Android" / "Sdk" / "build-tools" / "34.0.0" / "apksigner", -# ) +print("[+] Repackage") + +utils.replace_dex( + APK_NAME, + APK_NAME.parent / (APK_NAME.name.removesuffix(".apk") + "-instrumented.apk"), + dex_raw, + Path().parent / "my-release-key.jks", + zipalign=Path.home() / "Android" / "Sdk" / "build-tools" / "34.0.0" / "zipalign", + apksigner=Path.home() / "Android" / "Sdk" / "build-tools" / "34.0.0" / "apksigner", +) last_id = None @@ -168,9 +168,9 @@ def cmp_list(a, b, req=0): apk_eq = new_apk == apk -print(f"apk are equals: {apk_eq}") -if not apk_eq: - cmp(new_apk, apk) +print(f"[+] apk are equals: {nice_bool(apk_eq)}") +# if not apk_eq: +# cmp(new_apk, apk) # Landroidx/constraintlayout/core/widgets/ConstraintWidget$1;.()V # mid = IdMethod(