summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2015-08-05 07:47:34 +1000
committerDamien Zammit <damien@zamaudio.com>2015-08-05 07:47:34 +1000
commit78b7229f028978216a7d2217894fbe4909181c11 (patch)
treece613f7de629de3a88e68455e1fb2ff236361160
parent077da383a58c4201132e1895fa408fc170072ebf (diff)
Cleanups
Signed-off-by: Damien Zammit <damien@zamaudio.com>
-rw-r--r--ptfformat.cc15
-rw-r--r--ptfformat.h131
-rw-r--r--ptftool.cc2
3 files changed, 143 insertions, 5 deletions
diff --git a/ptfformat.cc b/ptfformat.cc
index 87bc33f..dde7367 100644
--- a/ptfformat.cc
+++ b/ptfformat.cc
@@ -15,6 +15,11 @@
*/
#include "ptfformat.h"
+
+#include <stdio.h>
+#include <string>
+#include <assert.h>
+
using namespace std;
static const uint32_t baselut[16] = {
@@ -102,9 +107,9 @@ PTFFormat::load(std::string path) {
unsigned char xxor[256];
unsigned char ct;
unsigned char px;
+ uint64_t key;
uint16_t i;
int j;
- int li;
int inv;
unsigned char message;
@@ -200,7 +205,6 @@ PTFFormat::load(std::string path) {
break;
case 0x40:
case 0xc0:
- li = c1;
xxor[0] = c0;
xxor[1] = c1;
for (i = 2; i < 256; i++) {
@@ -210,12 +214,13 @@ PTFFormat::load(std::string path) {
xxor[i] = ((xxor[i-1] + c1 - c0) & 0xff);
}
}
+
+ key = gen_secret(c1);
for (i = 0; i < 64; i++) {
- xxor[i] ^= (((gen_secret(li) >> i) & 1) * 2 * 0x40) + 0x40;
+ xxor[i] ^= (((key >> i) & 1) * 2 * 0x40) + 0x40;
}
- inv = 0;
for (i = 128; i < 192; i++) {
- inv = (((gen_secret(li) >> i) & 1) == 1) ? 1 : 3;
+ inv = (((key >> (i-128)) & 1) == 1) ? 1 : 3;
xxor[i] ^= (inv * 0x40);
}
diff --git a/ptfformat.h b/ptfformat.h
index 3e21b8c..0f60dc3 100644
--- a/ptfformat.h
+++ b/ptfformat.h
@@ -0,0 +1,131 @@
+/*
+ Copyright (C) 2015 Damien Zammit
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+*/
+#ifndef PTFFORMAT_H
+#define PTFFORMAT_H
+
+#include <string>
+#include <algorithm>
+#include <vector>
+#include <stdint.h>
+
+class PTFFormat {
+public:
+ PTFFormat();
+ ~PTFFormat();
+
+ /* Return values: 0 success
+ -1 could not open file as ptf
+ */
+ int load(std::string path);
+
+ typedef struct wav {
+ std::string filename;
+ uint16_t index;
+
+ int64_t posabsolute;
+ int64_t length;
+
+ bool operator ==(const struct wav& other) {
+ return (this->index == other.index);
+ }
+
+ } wav_t;
+
+ typedef struct region {
+ std::string name;
+ uint16_t index;
+ int64_t startpos;
+ int64_t sampleoffset;
+ int64_t length;
+ wav_t wave;
+
+ bool operator ==(const struct region& other) {
+ return (this->index == other.index);
+ }
+ } region_t;
+
+ typedef struct track {
+ std::string name;
+ uint16_t index;
+ uint8_t playlist;
+ region_t reg;
+
+ bool operator ==(const struct track& other) {
+ return (this->index == other.index);
+ }
+ } track_t;
+
+ std::vector<wav_t> audiofiles;
+ std::vector<region_t> regions;
+ std::vector<track_t> tracks;
+
+ static bool trackexistsin(std::vector<track_t> tr, uint16_t index) {
+ std::vector<track_t>::iterator begin = tr.begin();
+ std::vector<track_t>::iterator finish = tr.end();
+ std::vector<track_t>::iterator found;
+
+ track_t f = { std::string(""), index };
+
+ if ((found = std::find(begin, finish, f)) != finish) {
+ return true;
+ }
+ return false;
+ }
+
+ static bool regionexistsin(std::vector<region_t> reg, uint16_t index) {
+ std::vector<region_t>::iterator begin = reg.begin();
+ std::vector<region_t>::iterator finish = reg.end();
+ std::vector<region_t>::iterator found;
+
+ region_t r = { std::string(""), index };
+
+ if ((found = std::find(begin, finish, r)) != finish) {
+ return true;
+ }
+ return false;
+ }
+
+ static bool wavexistsin(std::vector<wav_t> wv, uint16_t index) {
+ std::vector<wav_t>::iterator begin = wv.begin();
+ std::vector<wav_t>::iterator finish = wv.end();
+ std::vector<wav_t>::iterator found;
+
+ wav_t w = { std::string(""), index };
+
+ if ((found = std::find(begin, finish, w)) != finish) {
+ return true;
+ }
+ return false;
+ }
+
+ uint32_t sessionrate;
+ uint8_t version;
+
+ unsigned char c0;
+ unsigned char c1;
+ unsigned char *ptfunxored;
+ int len;
+
+private:
+ bool foundin(std::string haystack, std::string needle);
+ void parse(void);
+ void parse8header(void);
+ void parse9header(void);
+ void parserest(void);
+ std::vector<wav_t> actualwavs;
+};
+
+
+#endif
diff --git a/ptftool.cc b/ptftool.cc
index 7ba1549..b99a38a 100644
--- a/ptftool.cc
+++ b/ptftool.cc
@@ -14,6 +14,8 @@
*/
#include "ptfformat.h"
+#include <cstdio>
+
using namespace std;
using std::string;