josephw / titl

Tools for iTunes Libraries
60 stars 12 forks source link

10.2.2 library - whole library post-hdfm is encrypted #15

Open josephw opened 9 years ago

josephw commented 9 years ago

Original issue 15 created by josephw on 2011-05-19T05:03:15.000Z:

What steps will reproduce the problem?

  1. Run titl on a 905kb 10.2.2 library

What is the expected output? What do you see instead? I get a zlib exception. Changing the parser to decrypt the whole file (after the header) works.

What version of the product are you using? On what operating system? Checked out yesterday, OS X 10.6.7, iTunes 10.2.2

Please provide any additional information below. Apple must have fixed the bug introduced in 10.0 (100k library encryption) in 10.1 or 10.2. I don't have a 10.1 library of sufficient size to test with.

josephw commented 9 years ago

Comment #1 originally posted by josephw on 2011-05-29T05:41:44.000Z:

Thanks for this. It looks like the behaviour is different between MacOS and Windows.

One option is to fall back if one technique fails, but there may be fields in the header to distinguish between the two types beforehand.

josephw commented 9 years ago

Comment #2 originally posted by josephw on 2014-12-16T01:31:43.000Z:

// decrypt all full blocks in the body Key key = new SecretKeySpec("BHUILuilfghuila3".getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, key); int crypt_size = (data.length - header_size) & ~0xf; int max_crypt_size = read32(data, 0x5C); if (max_crypt_size != 0) crypt_size = Math.min(crypt_size, max_crypt_size); cipher.doFinal(data, header_size, crypt_size, data, header_size);

    // un-zip body
    Inflater inflater = new Inflater();
    inflater.setInput(data, header_size, data.length - header_size);
    byte[] clear_data = new byte[65536];
    while (!inflater.finished())
    {
        int n = inflater.inflate(clear_data);
        o.write(clear_data, 0, n);
    }

    library_data.header = new byte[header_size];
    System.arraycopy(data, 0, library_data.header, 0, header_size);
    library_data.body = o.toByteArray();