ssn-installer/src/main.c

57 lines
1.4 KiB
C
Raw Normal View History

2018-07-17 14:05:22 +02:00
#include <errno.h>
#include <stdio.h>
2018-07-17 14:05:22 +02:00
#include <string.h>
//Import our code
#include "decrypt.h"
2018-07-17 17:19:13 +02:00
#include "fileReader.h"
2018-07-24 18:10:07 +02:00
#include "utils/min.h"
2018-07-17 14:05:22 +02:00
int main(int argc, unsigned char *argv[]) {
printf("Hello World!\n");
2018-07-24 18:10:07 +02:00
//TODO: verify argv and assign it to variables
2018-07-24 18:17:15 +02:00
char* archiveName = "1234";
const unsigned long archiveOffset = 0UL;
const unsigned long fileLength = 0xffffUL;
uint32_t key0 = 0;
uint32_t key1 = 0;
uint32_t key2 = 0;
2018-07-17 14:05:22 +02:00
2018-07-17 15:05:57 +02:00
//Initialise file reader
2018-07-24 18:17:15 +02:00
initFileReader(archiveName, archiveOffset);
2018-07-17 15:05:57 +02:00
//Skip header (30 bytes + additional length)
2018-07-24 17:07:47 +02:00
char* fileHeader = getBytes(30UL);
printf(fileHeader);
2018-07-24 18:10:07 +02:00
//TODO: check that header is correct
2018-07-24 18:17:15 +02:00
//TODO: read additional length
const unsigned long additionalLength = 0UL;
getBytes(additionalLength);
2018-07-17 15:05:57 +02:00
//Initialise decryption (pass decryption keys)
2018-07-24 18:17:15 +02:00
initDecryptor(key0, key1, key2);
2018-07-17 15:05:57 +02:00
//Skip 12-byte encryption header
2018-07-24 18:17:15 +02:00
const unsigned long encrHeaderLength = 12UL;
char* encrHeader = getBytes(encrHeaderLength);
decrypt(encrHeader, encrHeaderLength);
2018-07-17 15:05:57 +02:00
2018-07-24 18:10:07 +02:00
//Read actual file
2018-07-24 18:17:15 +02:00
unsigned long remainingBytes = fileLength;
2018-07-24 18:10:07 +02:00
while (remainingBytes > 0) {
const unsigned long chunkSize = min(0xFF, remainingBytes);
char* chunk = getBytes(chunkSize);
remainingBytes -= chunkSize;
2018-07-17 15:05:57 +02:00
2018-07-24 18:10:07 +02:00
decrypt(chunk, chunkSize);
//Decompress file
//TODO
//Optionally perform xdelta3
//TODO
}
2018-07-17 15:05:57 +02:00
2018-07-17 14:05:22 +02:00
return 0;
}