ptformat: Decrypt ptf files exported from ptx sessions
authorDamien Zammit <damien@zamaudio.com>
Tue, 2 Aug 2016 12:20:24 +0000 (22:20 +1000)
committerDamien Zammit <damien@zamaudio.com>
Tue, 2 Aug 2016 12:25:20 +0000 (22:25 +1000)
libs/ptformat/ptfformat.cc
libs/ptformat/ptfformat.h

index 3d66ec025ec8a0ea0dfa867849932cb83b04cc05..1dba1ac31a6e7a11726e1640ce34f141a4f5398f 100644 (file)
@@ -234,6 +234,12 @@ PTFFormat::load(std::string path, int64_t targetsr) {
                unxor10();
        }
 
+       // Special case when ptx is exported to ptf in PT
+       if (v == 3) {
+               version = 11;
+               unxor_ptx_to_ptf();
+       }
+
        if (version == 0 || version == 5 || version == 7) {
                /* Haven't detected version yet so decipher */
                j = 0;
@@ -306,6 +312,28 @@ PTFFormat::unxor10(void)
        }
 }
 
+void
+PTFFormat::unxor_ptx_to_ptf(void)
+{
+       unsigned char keyy[16] = {      0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,
+                                       0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0
+       };
+       uint64_t j;
+       uint8_t i;
+
+       for (i = 0, j = 0x10; j < len; j++,i++) {
+               ptfunxored[j] ^= keyy[i];
+               if ((j % 16) == 0) {
+                       i = 0;
+                       if (ptfunxored[j] % 2 == 0) {
+                               ptfunxored[j]++;
+                       } else {
+                               ptfunxored[j]--;
+                       }
+               }
+       }
+}
+
 int
 PTFFormat::parse(void) {
        if (version == 5) {
index 785544daa054e53ff851b4c0e6ddcb91c38e016b..3a702aa10bd257246f1fd21475c2c8d217861252 100644 (file)
@@ -119,6 +119,7 @@ private:
        bool foundin(std::string haystack, std::string needle);
        int parse(void);
        void unxor10(void);
+       void unxor_ptx_to_ptf(void);
        void setrates(void);
        void parse5header(void);
        void parse7header(void);