🎨 Improve code quality
This commit is contained in:
parent
966e8bb7c1
commit
ad8d88a066
1 changed files with 6 additions and 5 deletions
11
src/main.c
11
src/main.c
|
@ -11,6 +11,7 @@
|
|||
|
||||
#define BUFFER_SIZE 0xffffUL
|
||||
#define ENCRYPTION_HEADER_LENGTH 12UL
|
||||
#define LOCAL_FILE_HEADER_MAGIC (uint32_t)0x04034b50
|
||||
|
||||
uint16_t getUint16(char* buffer) {
|
||||
return (uint16_t)buffer[0] | \
|
||||
|
@ -25,7 +26,7 @@ uint32_t getUint32(char* buffer) {
|
|||
|
||||
int main(int argc, unsigned char *argv[]) {
|
||||
if (argc != 4 && argc != 7) {
|
||||
fprintf(stderr, "Wrong arguments. Usage: patcher-installer <disk_name> <disk_offset> <file_size> [<key0> <key1> <key2>]");
|
||||
fprintf(stderr, "Wrong number of arguments. Usage: patcher-installer <disk_name> <disk_offset> <file_size> [<key0> <key1> <key2>]");
|
||||
exit(1);
|
||||
}
|
||||
//TODO: verify argv and assign it to variables
|
||||
|
@ -38,21 +39,21 @@ int main(int argc, unsigned char *argv[]) {
|
|||
uint32_t key0 = atoi(argv[4]);
|
||||
uint32_t key1 = atoi(argv[5]);
|
||||
uint32_t key2 = atoi(argv[6]);
|
||||
//Initialise decryption (pass decryption keys)
|
||||
//Initialize decryption (pass decryption keys)
|
||||
initDecryptor(key0, key1, key2);
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
|
||||
//Initialise file reader
|
||||
//Initialize file reader
|
||||
initFileReader(archiveName, archiveOffset);
|
||||
|
||||
//Skip local file header (30 bytes + additional length)
|
||||
char* fileHeader = getBytes(30UL);
|
||||
//Check that header is correct
|
||||
const uint32_t magic = getUint32(fileHeader);
|
||||
if (magic != (uint32_t)0x04034b50) {
|
||||
fprintf(stderr, "Wrong magic in local file header, expected 0x04034b50 but found %#010x.", magic);
|
||||
if (magic != LOCAL_FILE_HEADER_MAGIC) {
|
||||
fprintf(stderr, "Wrong magic in local file header, expected %#010x but found %#010x.", LOCAL_FILE_HEADER_MAGIC, magic);
|
||||
exit(1);
|
||||
}
|
||||
free(fileHeader);
|
||||
|
|
Loading…
Reference in a new issue