Exemplo n.º 1
0
    def test_qistoph_pr_27(self):
        """
        Tests support for Bool, Integer, Long classes (PR #27)
        """
        # Load the basic map
        jobj = self.read_file("testBoolIntLong.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug(pobj)

        # Basic checking
        self.assertEqual(pobj[u"key1"], u"value1")
        self.assertEqual(pobj[u"key2"], u"value2")
        self.assertEqual(pobj[u"int"], 9)
        self.assertEqual(pobj[u"int2"], 10)
        self.assertEqual(pobj[u"bool"], True)
        self.assertEqual(pobj[u"bool2"], True)

        # Load the parent map
        jobj2 = self.read_file("testBoolIntLong-2.ser")
        pobj2 = javaobj.loads(jobj2)
        _logger.debug(pobj2)

        parent_map = pobj2[u"subMap"]
        for key, value in pobj.items():
            self.assertEqual(parent_map[key], value)
Exemplo n.º 2
0
 def test_1(self):
     jobj = self.read_file("java/testDouble.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, '\x7f\xef\xff\xff\xff\xff\xff\xff')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Exemplo n.º 3
0
 def process(self, data):
     import javaobj as java
     return json.dumps(
         java.loads(data),
         indent=4,
         cls=self._encoder
     ).encode(self.codec)
Exemplo n.º 4
0
 def test_jceks_issue_5(self):
     """
     Tests the handling of JCEKS issue #5
     """
     jobj = self.read_file("jceks_issue_5.ser")
     pobj = javaobj.loads(jobj)
     _logger.info(pobj)
Exemplo n.º 5
0
 def test_0_rw(self):
     jobj = self.read_file("java/testChar.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, '\x00C')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Exemplo n.º 6
0
 def test_3(self):
     jobj = self.read_file("java/testBoolean.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, chr(0))
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Exemplo n.º 7
0
def get_imei():
    candidates = []

    class Parcel(object):
        # https://gist.github.com/ktnr74/60ac7bcc2cd17b43f2cb
        def __init__(self, text):
            if text.startswith(b'Result: Parcel(') and text.endswith(b'\')'):
                self.data = b''.join([struct.pack('<L', int(x, 16)) for x in re.findall(b'([0-9a-f]{8}) ', text)])
                self.resultcode = self.get_int(0)
            else:
                raise Exception('Unexpected input!')

        def get_int(self, offset=4):
            return int(struct.unpack('<L', self.data[offset:offset+4])[0])

        def get_utf16(self, offset=4):
            return (self.data[offset + 4: offset+4+self.get_int(offset) * 2]).decode('utf-16')

    out = subproc_succ("adb shell service call iphonesubinfo 1")
    imei = Parcel(out.strip()).get_utf16()
    logger.info(f"found imei={imei} from iphonesubinfo")
    candidates.append(imei)

    out = subproc_succ(f"adb shell su -c \"cat {MM_DIR}/MicroMsg/CompatibleInfo.cfg\"")
    try:
        # https://gist.github.com/ChiChou/36556fd412a9e3216abecf06e084e4d9
        jobj = javaobj.loads(out)
        imei = jobj[258]
    except:
        logger.warning("imei not found in CompatibleInfo.cfg")
    else:
        candidates.append(imei)
        logger.info(f"found imei={imei} in CompatibleInfo.cfg")
    logger.info(f"Possible imei: {candidates}")
    return list(set(candidates))
Exemplo n.º 8
0
def decodeobj(x):
    if x == b'NULL':
        return
    x = x.strip(b"X'\"")
    if not x:
        return
    return javaobj.loads(a2b_hex(x))
Exemplo n.º 9
0
 def test_0_rw(self):
     jobj = self.read_file("java/testChar.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, '\x00C')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Exemplo n.º 10
0
 def test_1(self):
     jobj = self.read_file("java/testDouble.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, '\x7f\xef\xff\xff\xff\xff\xff\xff')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Exemplo n.º 11
0
 def test_2(self):
     jobj = self.read_file("java/testBytes.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, 'HelloWorld')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Exemplo n.º 12
0
 def test_3(self):
     jobj = self.read_file("java/testBoolean.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, chr(0))
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Exemplo n.º 13
0
    def test_arrays(self):
        """
        Tests handling of Java arrays
        """
        jobj = self.read_file("objArrays.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug(pobj)

        classdesc = pobj.get_class()
        _logger.debug(classdesc)
        _logger.debug(classdesc.fields_names)
        _logger.debug(classdesc.fields_types)

        # public String[] stringArr = {"1", "2", "3"};
        # public int[] integerArr = {1,2,3};
        # public boolean[] boolArr = {true, false, true};
        # public TestConcrete[] concreteArr = {new TestConcrete(),
        #                                      new TestConcrete()};

        _logger.debug(pobj.stringArr)
        _logger.debug(pobj.integerArr)
        _logger.debug(pobj.boolArr)
        _logger.debug(pobj.concreteArr)

        self._try_marshalling(jobj, pobj)
Exemplo n.º 14
0
 def test_2(self):
     jobj = self.read_file("java/testBytes.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, 'HelloWorld')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Exemplo n.º 15
0
def get_uin():
    candidates = []
    try:
        uin = None
        out = subproc_succ(f"adb shell cat {MM_DIR}/shared_prefs/system_config_prefs.xml")
        for line in out.decode('utf-8').split("\n"):
            if "default_uin" in line:
                line = PyQuery(line)
                uin = line.attr["value"]
                break
        uin = int(uin)
    except Exception:
        logger.warning("uin not found in system_config_prefs.xml")
    else:
        candidates.append(uin)
        logger.info(f"found uin={uin} in system_config_prefs.xml")

    try:
        uin = None
        out = subproc_succ(f"adb shell cat {MM_DIR}/shared_prefs/com.tencent.mm_preferences.xml")
        for line in out.decode('utf-8').split("\n"):
            if "last_login_uin" in line:
                line = PyQuery(line)
                uin = line.text()
                break
        uin = int(uin)
    except Exception:
        logger.warning("uin not found in com.tencent.mm_preferences.xml")
    else:
        candidates.append(uin)
        logger.info(f"found uin={uin} in com.tencent.mm_preferences.xml")

    try:
        uin = None
        out = subproc_succ(f"adb shell cat {MM_DIR}/shared_prefs/auth_info_key_prefs.xml")
        for line in out.decode('utf-8').split("\n"):
            if "auth_uin" in line:
                line = PyQuery(line)
                uin = line.attr["value"]
                break
        uin = int(uin)
    except Exception:
        logger.warning("uin not found in auth_info_key_prefs.xml")
    else:
        candidates.append(uin)
        logger.info(f"found uin={uin} in auth_info_key_prefs.xml")

    try:
        out = subproc_succ(f"adb shell cat {MM_DIR}/MicroMsg/systemInfo.cfg")
        uin = javaobj.loads(out).get(1, 0)
    except:
        logger.warning("default uin not found in systemInfo.cfg")
    else:
        candidates.append(uin)
        logger.info(f"found uin={uin} in systemInfo.cfg")

    candidates = list({x for x in candidates if x != 0})
    logger.info(f"Possible uin: {candidates}")
    return candidates
Exemplo n.º 16
0
 def test_sets(self):
     for filename in ("testHashSet.ser", "testTreeSet.ser"):
         _logger.debug("Loading file: %s", filename)
         jobj = self.read_file(filename)
         pobj = javaobj.loads(jobj)
         _logger.debug(pobj)
         self.assertIsInstance(pobj, set)
         self.assertSetEqual({i.value for i in pobj}, {1, 2, 42})
 def extract_rsa_key(java_serialized_data):
     deserialized_data = javaobj.loads(java_serialized_data)
     rsa_key_bytes = deserialized_data.encoded
     rsa_key_string = ''
     for b in rsa_key_bytes:
         # convert to unsigned int
         rsa_key_string += chr(b & 0xff)
     return rsa_key_string
Exemplo n.º 18
0
    def test_4(self):
        jobj = self.read_file("obj4.ser")
        pobj = javaobj.loads(jobj)
        print pobj
        self.assertEqual(pobj, 127)

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Exemplo n.º 19
0
 def test_char_rw(self):
     """
     Reads testChar.ser and checks the serialization process
     """
     jobj = self.read_file("testChar.ser")
     pobj = javaobj.loads(jobj)
     _logger.debug("Read char object: %s", pobj)
     self.assertEqual(pobj, "\x00C")
     self._try_marshalling(jobj, pobj)
Exemplo n.º 20
0
    def last_bookmark():
        if BookmarkHandler.last_file:
            bookmark = open(BookmarkHandler.last_file, 'rb').read()
            parsed = javaobj.loads(bookmark)

            return "{}\n{}".format(parsed.mFileName,
                                   datetime.timedelta(
                                       seconds=parsed.mFilePosition))
        return "f**k"
Exemplo n.º 21
0
    def test_exception(self):
        jobj = self.read_file("objException.ser")
        pobj = javaobj.loads(jobj)
        print pobj

        classdesc = pobj.get_class()
        print classdesc
        print classdesc.fields_names
        print classdesc.fields_types
Exemplo n.º 22
0
 def test_class(self):
     """
     Reads the serialized String class
     """
     jobj = self.read_file("testClass.ser")
     pobj = javaobj.loads(jobj)
     _logger.debug("Read object: %s", pobj)
     self.assertEqual(pobj.name, 'java.lang.String')
     self._try_marshalling(jobj, pobj)
Exemplo n.º 23
0
    def test_7(self):
        jobj = self.read_file("java/testSwingObject.ser")
        pobj = javaobj.loads(jobj)
        print pobj

        classdesc = pobj.get_class()
        print classdesc
        print classdesc.fields_names
        print classdesc.fields_types
Exemplo n.º 24
0
 def test_class(self):
     """
     Reads the serialized String class
     """
     jobj = self.read_file("testClass.ser")
     pobj = javaobj.loads(jobj)
     _logger.debug("Read object: %s", pobj)
     self.assertEqual(pobj.name, "java.lang.String")
     self._try_marshalling(jobj, pobj)
Exemplo n.º 25
0
 def test_char_array(self):
     jobj = self.read_file("testCharArray.ser")
     pobj = javaobj.loads(jobj)
     _logger.debug(pobj)
     self.assertEqual(pobj, [
         u'\u0000', u'\ud800', u'\u0001', u'\udc00', u'\u0002', u'\uffff',
         u'\u0003'
     ])
     self._try_marshalling(jobj, pobj)
Exemplo n.º 26
0
 def test_char_rw(self):
     """
     Reads testChar.ser and checks the serialization process
     """
     jobj = self.read_file("testChar.ser")
     pobj = javaobj.loads(jobj)
     _logger.debug("Read char object: %s", pobj)
     self.assertEqual(pobj, '\x00C')
     self._try_marshalling(jobj, pobj)
Exemplo n.º 27
0
    def test_double_rw(self):
        """
        Reads testDouble.ser and checks the serialization process
        """
        jobj = self.read_file("testDouble.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read double object: %s", pobj)

        self.assertEqual(pobj, "\x7f\xef\xff\xff\xff\xff\xff\xff")
        self._try_marshalling(jobj, pobj)
Exemplo n.º 28
0
    def test_bytes_rw(self):
        """
        Reads testBytes.ser and checks the serialization process
        """
        jobj = self.read_file("testBytes.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read bytes: %s", pobj)

        self.assertEqual(pobj, "HelloWorld")
        self._try_marshalling(jobj, pobj)
Exemplo n.º 29
0
    def test_boolean(self):
        """
        Reads testBoolean.ser and checks the serialization process
        """
        jobj = self.read_file("testBoolean.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read boolean object: %s", pobj)

        self.assertEqual(pobj, chr(0))
        self._try_marshalling(jobj, pobj)
Exemplo n.º 30
0
    def test_double_rw(self):
        """
        Reads testDouble.ser and checks the serialization process
        """
        jobj = self.read_file("testDouble.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read double object: %s", pobj)

        self.assertEqual(pobj, '\x7f\xef\xff\xff\xff\xff\xff\xff')
        self._try_marshalling(jobj, pobj)
Exemplo n.º 31
0
 def test_char_rw(self):
     """
     Reads testChar.ser and checks the serialization process
     """
     jobj = self.read_file("testChar.ser")
     pobj = javaobj.loads(jobj)
     _logger.debug("Read char object: %s", pobj)
     self.assertEqual(pobj, '\x00C')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Exemplo n.º 32
0
    def test_bytes_rw(self):
        """
        Reads testBytes.ser and checks the serialization process
        """
        jobj = self.read_file("testBytes.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read bytes: %s", pobj)

        self.assertEqual(pobj, 'HelloWorld')
        self._try_marshalling(jobj, pobj)
Exemplo n.º 33
0
 def test_japan(self):
     # Japan.ser contains a string using wide characters: the name of the
     # state from Japan (according to wikipedia)
     jobj = self.read_file("testJapan.ser")
     pobj = javaobj.loads(jobj)
     _logger.debug(pobj)
     # Compare the UTF-8 encoded version of the name
     self.assertEqual(
         pobj, b"\xe6\x97\xa5\xe6\x9c\xac\xe5\x9b\xbd".decode("utf-8"))
     self._try_marshalling(jobj, pobj)
Exemplo n.º 34
0
    def test_boolean(self):
        """
        Reads testBoolean.ser and checks the serialization process
        """
        jobj = self.read_file("testBoolean.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read boolean object: %s", pobj)

        self.assertEqual(pobj, chr(0))
        self._try_marshalling(jobj, pobj)
Exemplo n.º 35
0
    def test_collections(self):
        jobj = self.read_file("objCollections.ser")
        pobj = javaobj.loads(jobj)
        print pobj

        print "arrayList:", pobj.arrayList
        self.assertTrue(isinstance(pobj.arrayList, list))
        print "hashMap:", pobj.hashMap
        self.assertTrue(isinstance(pobj.hashMap, dict))
        print "linkedList:", pobj.linkedList
        self.assertTrue(isinstance(pobj.linkedList, list)) # Fails
Exemplo n.º 36
0
    def __init__(self, desc, row):
        super().__init__(desc, row)

        self.obj = None
        if self.thumb_image:
            try:
                self.obj = javaobj.loads(self.thumb_image)
            except Exception as e:
                print(e, msg[19])
                pass
        self.sender = self.remote_resource or self.key_remote_jid
Exemplo n.º 37
0
    def test_collections(self):
        jobj = self.read_file("objCollections.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug(pobj)

        _logger.debug("arrayList: %s", pobj.arrayList)
        self.assertTrue(isinstance(pobj.arrayList, list))
        _logger.debug("hashMap: %s", pobj.hashMap)
        self.assertTrue(isinstance(pobj.hashMap, dict))
        _logger.debug("linkedList: %s", pobj.linkedList)
        self.assertTrue(isinstance(pobj.linkedList, list))
Exemplo n.º 38
0
    def test_class_with_byte_array_rw(self):
        jobj = self.read_file("testClassWithByteArray.ser")
        pobj = javaobj.loads(jobj)

        # j8spencer (Google, LLC) 2018-01-16:  It seems specific support for
        # byte arrays was added, but is a little out-of-step with the other
        # types in terms of style.  This UT was broken, since the "myArray"
        # member has the array stored as a tuple of ints (not a byte string)
        # in memeber called '_data.'  I've updated to pass the UTs.
        self.assertEqual(pobj.myArray._data, (1, 3, 7, 11))
        self._try_marshalling(jobj, pobj)
Exemplo n.º 39
0
def checkobj(fname):
    global model, graph
    with open(fname, "rb") as fd:
        jobj = fd.read()
    model = javaobj.loads(jobj)
    graph = model.graph
    check0(model, graph)
    check1(model, graph)
    subsequences = check2(model, graph)
    check3(model, graph, subsequences)
    return subsequences
Exemplo n.º 40
0
    def test_class(self):
        """
        Reads the serialized String class
        """
        jobj = self.read_file("testClass.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read object: %s", pobj)
        self.assertEqual(pobj.name, 'java.lang.String')

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Exemplo n.º 41
0
    def test_collections(self):
        jobj = self.read_file("objCollections.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug(pobj)

        _logger.debug("arrayList: %s", pobj.arrayList)
        self.assertTrue(isinstance(pobj.arrayList, list))
        _logger.debug("hashMap: %s", pobj.hashMap)
        self.assertTrue(isinstance(pobj.hashMap, dict))
        _logger.debug("linkedList: %s", pobj.linkedList)
        self.assertTrue(isinstance(pobj.linkedList, list))
Exemplo n.º 42
0
 def _try_marshalling(self, original_stream, original_object):
     """
     Tries to marshall an object and compares it to the original stream
     """
     marshalled_stream = javaobj.dumps(original_object)
     # Reloading the new dump allows to compare the decoding sequence
     try:
         javaobj.loads(marshalled_stream)
         self.assertEqual(original_stream, marshalled_stream)
     except:
         print("-" * 80)
         print("=" * 30, "Original", "=" * 30)
         print(
             javaobj.JavaObjectUnmarshaller._create_hexdump(
                 original_stream))
         print("*" * 30, "Marshalled", "*" * 30)
         print(
             javaobj.JavaObjectUnmarshaller._create_hexdump(
                 marshalled_stream))
         print("-" * 80)
         raise
Exemplo n.º 43
0
    def test_bytes_rw(self):
        """
        Reads testBytes.ser and checks the serialization process
        """
        jobj = self.read_file("testBytes.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read bytes: %s", pobj)

        self.assertEqual(pobj, 'HelloWorld')

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Exemplo n.º 44
0
    def test_byte(self):
        """
        Reads testByte.ser

        The result from javaobj is a single-character string.
        """
        jobj = self.read_file("testByte.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read Byte: %r", pobj)

        self.assertEqual(pobj, chr(127))
        self._try_marshalling(jobj, pobj)
Exemplo n.º 45
0
    def test_byte(self):
        """
        Reads testByte.ser

        The result from javaobj is a single-character string.
        """
        jobj = self.read_file("testByte.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read Byte: %r", pobj)

        self.assertEqual(pobj, chr(127))
        self._try_marshalling(jobj, pobj)
Exemplo n.º 46
0
    def test_double_rw(self):
        """
        Reads testDouble.ser and checks the serialization process
        """
        jobj = self.read_file("testDouble.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read double object: %s", pobj)

        self.assertEqual(pobj, '\x7f\xef\xff\xff\xff\xff\xff\xff')

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Exemplo n.º 47
0
def print_detail(task_id):
    cursor = db_connector.DBConnector.cursor()
    cursor.prepare(SQL_HI_DETAIL)
    cursor.execute(None, {'task_id': task_id})
    res = cursor.fetchone()

    if res is not None:
        blob_data = res[0]
        pobj = javaobj.loads(blob_data.read())
        print(pobj)

    cursor.close
Exemplo n.º 48
0
    def test_chars_rw(self):
        """
        Reads testChars.ser and checks the serialization process
        """
        # Expected string as a UTF-16 string
        expected = "python-javaobj".encode("utf-16-be").decode("latin1")

        jobj = self.read_file("testChars.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read char objects: %s", pobj)
        self.assertEqual(pobj, expected)
        self._try_marshalling(jobj, pobj)
Exemplo n.º 49
0
    def test_chars_rw(self):
        """
        Reads testChars.ser and checks the serialization process
        """
        # Expected string as a UTF-16 string
        expected = "python-javaobj".encode("utf-16-be").decode("latin1")

        jobj = self.read_file("testChars.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read char objects: %s", pobj)
        self.assertEqual(pobj, expected)
        self._try_marshalling(jobj, pobj)
Exemplo n.º 50
0
    def test_enums(self):
        jobj = self.read_file("objEnums.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug(pobj)

        classdesc = pobj.get_class()
        _logger.debug(classdesc)
        _logger.debug(classdesc.fields_names)
        _logger.debug(classdesc.fields_types)

        self.assertEqual(classdesc.name, "ClassWithEnum")
        self.assertEqual(pobj.color.classdesc.name, "Color")
        self.assertEqual(pobj.color.constant, "GREEN")
Exemplo n.º 51
0
    def test_super(self):
        jobj = self.read_file("objSuper.ser")
        pobj = javaobj.loads(jobj)
        print pobj

        classdesc = pobj.get_class()
        print classdesc
        print classdesc.fields_names
        print classdesc.fields_types

        print pobj.childString
        print pobj.bool
        print pobj.integer
Exemplo n.º 52
0
 def test_japan(self):
     """
     Tests the UTF encoding handling with Japanese characters
     """
     # Japan.ser contains a string using wide characters: the name of the
     # state from Japan (according to wikipedia)
     jobj = self.read_file("testJapan.ser")
     pobj = javaobj.loads(jobj)
     _logger.debug(pobj)
     # Compare the UTF-8 encoded version of the name
     self.assertEqual(
         pobj, b"\xe6\x97\xa5\xe6\x9c\xac\xe5\x9b\xbd".decode("utf-8")
     )
     self._try_marshalling(jobj, pobj)
Exemplo n.º 53
0
 def _try_marshalling(self, original_stream, original_object):
     """
     Tries to marshall an object and compares it to the original stream
     """
     marshalled_stream = javaobj.dumps(original_object)
     # Reloading the new dump allows to compare the decoding sequence
     try:
         javaobj.loads(marshalled_stream)
         self.assertEqual(original_stream, marshalled_stream)
     except Exception:
         print("-" * 80)
         print("=" * 30, "Original", "=" * 30)
         print(
             javaobj.JavaObjectUnmarshaller._create_hexdump(original_stream)
         )
         print("*" * 30, "Marshalled", "*" * 30)
         print(
             javaobj.JavaObjectUnmarshaller._create_hexdump(
                 marshalled_stream
             )
         )
         print("-" * 80)
         raise
Exemplo n.º 54
0
    def test_times(self):
        jobj = self.read_file("testTime.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug(pobj)

        # First one is a duration of 10s
        duration = pobj[0]
        self.assertEquals(duration.second, 10)

        # Check types
        self.assertIsInstance(pobj, javaobj.core.JavaArray)
        for obj in pobj:
            self.assertIsInstance(obj,
                                  javaobj.DefaultObjectTransformer.JavaTime)
Exemplo n.º 55
0
    def test_class_with_byte_array_rw(self):
        """
        Tests handling of classes containing a Byte Array
        """
        jobj = self.read_file("testClassWithByteArray.ser")
        pobj = javaobj.loads(jobj)

        # j8spencer (Google, LLC) 2018-01-16:  It seems specific support for
        # byte arrays was added, but is a little out-of-step with the other
        # types in terms of style.  This UT was broken, since the "myArray"
        # member has the array stored as a tuple of ints (not a byte string)
        # in memeber called '_data.'  I've updated to pass the UTs.
        self.assertEqual(pobj.myArray._data, (1, 3, 7, 11))
        self._try_marshalling(jobj, pobj)
Exemplo n.º 56
0
    def test_super(self):
        jobj = self.read_file("objSuper.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug(pobj)

        classdesc = pobj.get_class()
        _logger.debug(classdesc)
        _logger.debug(classdesc.fields_names)
        _logger.debug(classdesc.fields_types)

        self.assertEqual(pobj.childString, "Child!!")
        self.assertEqual(pobj.bool, True)
        self.assertEqual(pobj.integer, -1)
        self.assertEqual(pobj.superString, "Super!!")

        self._try_marshalling(jobj, pobj)
Exemplo n.º 57
0
    def test_5(self):
        jobj = self.read_file("java/test_readFields.ser")
        pobj = javaobj.loads(jobj)
        print pobj

        self.assertEqual(pobj.aField1, 'Gabba')
        self.assertEqual(pobj.aField2, None)

        classdesc = pobj.get_class()
        self.assertTrue(classdesc)
        self.assertEqual(classdesc.serialVersionUID, 0x7F0941F5)
        self.assertEqual(classdesc.name, "OneTest$SerializableTestHelper")
        print classdesc
        print classdesc.flags
        print classdesc.fields_names
        print classdesc.fields_types
        self.assertEqual(len(classdesc.fields_names), 3)
Exemplo n.º 58
0
    def test_enums(self):
        jobj = self.read_file("objEnums.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug(pobj)

        classdesc = pobj.get_class()
        _logger.debug(classdesc)
        _logger.debug(classdesc.fields_names)
        _logger.debug(classdesc.fields_types)

        self.assertEqual(classdesc.name, "ClassWithEnum")
        self.assertEqual(pobj.color.classdesc.name, "Color")
        self.assertEqual(pobj.color.constant, "GREEN")

        for color, intended in zip(pobj.colors, ("GREEN", "BLUE", "RED")):
            self.assertEqual(color.classdesc.name, "Color")
            self.assertEqual(color.constant, intended)
Exemplo n.º 59
0
    def test_arrays(self):
        jobj = self.read_file("objArrays.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug(pobj)

        classdesc = pobj.get_class()
        _logger.debug(classdesc)
        _logger.debug(classdesc.fields_names)
        _logger.debug(classdesc.fields_types)

        # public String[] stringArr = {"1", "2", "3"};
        # public int[] integerArr = {1,2,3};
        # public boolean[] boolArr = {true, false, true};
        # public TestConcrete[] concreteArr = {new TestConcrete(),
        #                                      new TestConcrete()};

        _logger.debug(pobj.stringArr)
        _logger.debug(pobj.integerArr)
        _logger.debug(pobj.boolArr)
        _logger.debug(pobj.concreteArr)

        self._try_marshalling(jobj, pobj)
Exemplo n.º 60
0
def list_dir():
    _uin = []
    _imei = []
    for path, dirs, files in os.walk('./apps'):
        for a in files:
            if a == 'EnMicroMsg.db':
                copyfile(f'{path}/{a}',
                         f'{int(time.time() * 1000)}-EnMicroMsg.db')
        if 'systemInfo.cfg' in files:
            with open(f'{path}/systemInfo.cfg', "rb") as fd:
                obj = javaobj.loads(fd.read())
                _uin.append(str(obj[1]))
        if 'auth_info_key_prefs.xml' in files:
            with open(f'{path}/auth_info_key_prefs.xml', "rb") as fd:
                result = etree.XML(fd.read())
                for a in result.getchildren():
                    if a.get('name') == '_auth_uin':
                        _uin.append(a.get('value'))
        if 'app_brand_global_sp.xml' in files:
            with open(f'{path}/app_brand_global_sp.xml', "rb") as fd:
                result = etree.XML(fd.read())
                for a in result.getchildren():
                    _uin.append(
                        a.getchildren()[0].text if a.getchildren() else '')
        if 'system_config_prefs.xml' in files:
            with open(f'{path}/system_config_prefs.xml', "rb") as fd:
                result = etree.XML(fd.read())
                for a in result.getchildren():
                    if a.get('name') == 'default_uin':
                        _uin.append(a.get('value'))
        if 'DENGTA_META.xml' in files:
            with open(f'{path}/DENGTA_META.xml', "rb") as fd:
                result = etree.XML(fd.read())
                for a in result.getchildren():
                    if a.get('name') == 'IMEI_DENGTA':
                        _imei.append(a.text)
    if delete:
        rmtree('./apps')
    return list(set(compute_password(_uin, _imei)))