Beispiel #1
0
    def testEndToEnd(self):
        dex = cp.ProcessDex(DEX_DUMP.splitlines())
        mapping, _ = cp.ProcessProguardMapping(PROGUARD_MAPPING.splitlines(),
                                               dex)

        profile = cp.ProcessProfile(OBFUSCATED_PROFILE.splitlines(), mapping)
        with tempfile.NamedTemporaryFile() as temp:
            profile.WriteToFile(temp.name)
            with open(temp.name, 'r') as f:
                for a, b in zip(sorted(f),
                                sorted(UNOBFUSCATED_PROFILE.splitlines())):
                    self.assertEqual(a.strip(), b.strip())
Beispiel #2
0
    def testProcessDex(self):
        dex = cp.ProcessDex(DEX_DUMP.splitlines())
        self.assertIsNotNone(dex['a'])

        self.assertEqual(len(dex['a'].FindMethodsAtLine('<clinit>', 311, 313)),
                         1)
        self.assertEqual(len(dex['a'].FindMethodsAtLine('<clinit>', 309, 315)),
                         1)
        clinit = dex['a'].FindMethodsAtLine('<clinit>', 311, 313)[0]
        self.assertEqual(clinit.name, '<clinit>')
        self.assertEqual(clinit.return_type, 'V')
        self.assertEqual(clinit.param_types, 'Ljava/lang/String;')

        self.assertEqual(len(dex['a'].FindMethodsAtLine('a', 8, None)), 2)
        self.assertIsNone(dex['a'].FindMethodsAtLine('a', 100, None))
Beispiel #3
0
    def testProcessProfile(self):
        dex = cp.ProcessDex(DEX_DUMP.splitlines())
        mapping, _ = cp.ProcessProguardMapping(PROGUARD_MAPPING.splitlines(),
                                               dex)
        profile = cp.ProcessProfile(OBFUSCATED_PROFILE.splitlines(), mapping)

        getInstance = cp.Method('getInstance', 'Lorg/chromium/Original;', '',
                                'Lorg/chromium/Original;')
        initialize = cp.Method('initialize', 'Lorg/chromium/Original;', '',
                               'V')
        another = cp.Method('another', 'Lorg/chromium/Original;', '',
                            'Lorg/chromium/Original;')

        self.assertIn('Lorg/chromium/Original;', profile._classes)
        self.assertIn(getInstance, profile._methods)
        self.assertIn(initialize, profile._methods)
        self.assertIn(another, profile._methods)

        self.assertEqual(profile._methods[getInstance], set(['H', 'S', 'P']))
        self.assertEqual(profile._methods[initialize], set(['H', 'P']))
        self.assertEqual(profile._methods[another], set(['P']))
Beispiel #4
0
    def testProcessProguardMapping(self):
        dex = cp.ProcessDex(DEX_DUMP.splitlines())
        mapping, reverse = cp.ProcessProguardMapping(
            PROGUARD_MAPPING.splitlines(), dex)

        self.assertEqual('La;',
                         reverse.GetClassMapping('Lorg/chromium/Original;'))

        getInstance = cp.Method('getInstance', 'Lorg/chromium/Original;', '',
                                'Lorg/chromium/Original;')
        initialize = cp.Method('initialize', 'Lorg/chromium/Original;', '',
                               'V')
        another = cp.Method('another', 'Lorg/chromium/Original;', '',
                            'Lorg/chromium/Original;')
        subclassInit = cp.Method('<init>', 'Lorg/chromium/Original$Subclass;',
                                 'Lorg/chromium/Original;B', 'V')

        mapped = mapping.GetMethodMapping(
            cp.Method('a', 'La;', 'Ljava/lang/String;', 'I'))
        self.assertEqual(len(mapped), 2)
        self.assertIn(getInstance, mapped)
        self.assertNotIn(subclassInit, mapped)
        self.assertNotIn(
            cp.Method('inlined', 'Lorg/chromium/Original;', '', 'V'), mapped)
        self.assertIn(initialize, mapped)

        mapped = mapping.GetMethodMapping(
            cp.Method('a', 'La;', 'Ljava/lang/Object;', 'I'))
        self.assertEqual(len(mapped), 1)
        self.assertIn(getInstance, mapped)

        mapped = mapping.GetMethodMapping(cp.Method('b', 'La;', '', 'La;'))
        self.assertEqual(len(mapped), 1)
        self.assertIn(another, mapped)

        for from_method, to_methods in mapping._method_mapping.items():
            for to_method in to_methods:
                self.assertIn(from_method, reverse.GetMethodMapping(to_method))
        for from_class, to_class in mapping._class_mapping.items():
            self.assertEqual(from_class, reverse.GetClassMapping(to_class))