From c83858311b7c667ce9c8665d6f43c599d82d5ad5 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Wed, 15 Apr 2020 20:06:41 -0400 Subject: [PATCH] More baby steps. --- source/cert.c | 16 ++++++ source/cert.h | 16 ++++++ source/crc32_fast.c | 3 +- source/crc32_fast.h | 10 ---- source/es.c | 16 ++++++ source/es.h | 16 ++++++ source/fs_ext.c | 16 ++++++ source/fs_ext.h | 16 ++++++ source/fspusb.c | 17 ++++++ source/fspusb.h | 21 ++++++-- source/gamecard.c | 21 +++++++- source/gamecard.h | 16 ++++++ source/keys.c | 16 ++++++ source/keys.h | 16 ++++++ source/main.c | 125 ++++++++++++++++++++++++++++++++++++++++---- source/nca.c | 16 ++++++ source/nca.h | 16 ++++++ source/rsa.c | 16 ++++++ source/rsa.h | 16 ++++++ source/save.c | 67 ++++++++++++++---------- source/save.h | 20 +++++-- source/services.c | 16 ++++++ source/services.h | 16 ++++++ source/signature.h | 16 ++++++ source/tik.c | 16 ++++++ source/tik.h | 16 ++++++ source/utils.c | 18 ++++++- source/utils.h | 16 ++++++ 28 files changed, 543 insertions(+), 63 deletions(-) delete mode 100644 source/crc32_fast.h diff --git a/source/cert.c b/source/cert.c index 751faf0..1da30aa 100644 --- a/source/cert.c +++ b/source/cert.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include diff --git a/source/cert.h b/source/cert.h index 64b0824..a495260 100644 --- a/source/cert.h +++ b/source/cert.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __CERT_H__ diff --git a/source/crc32_fast.c b/source/crc32_fast.c index 0e10ea9..9f1f620 100644 --- a/source/crc32_fast.c +++ b/source/crc32_fast.c @@ -8,8 +8,7 @@ #include #include #include - -#include "crc32_fast.h" +#include u32 crc32_for_byte(u32 r) { diff --git a/source/crc32_fast.h b/source/crc32_fast.h deleted file mode 100644 index 14a0705..0000000 --- a/source/crc32_fast.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#ifndef __CRC32_FAST_H__ -#define __CRC32_FAST_H__ - -#include - -void crc32(const void *data, u64 n_bytes, u32 *crc); - -#endif /* __CRC32_FAST_H__ */ diff --git a/source/es.c b/source/es.c index 397437d..748c2a8 100644 --- a/source/es.c +++ b/source/es.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include diff --git a/source/es.h b/source/es.h index 2029a45..92c2406 100644 --- a/source/es.h +++ b/source/es.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __ES_H__ diff --git a/source/fs_ext.c b/source/fs_ext.c index 5ca6b87..f7bab80 100644 --- a/source/fs_ext.c +++ b/source/fs_ext.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include diff --git a/source/fs_ext.h b/source/fs_ext.h index 0a9d8cb..2a6d82f 100644 --- a/source/fs_ext.h +++ b/source/fs_ext.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __FS_EXT_H__ diff --git a/source/fspusb.c b/source/fspusb.c index 05544e4..a0d135c 100644 --- a/source/fspusb.c +++ b/source/fspusb.c @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2019-2020 XorTroll + * Copyright (c) 2019-2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #define NX_SERVICE_ASSUME_NON_DOMAIN #include "fspusb.h" #include "service_guard.h" diff --git a/source/fspusb.h b/source/fspusb.h index efcd982..471e9b1 100644 --- a/source/fspusb.h +++ b/source/fspusb.h @@ -1,9 +1,20 @@ -/** - * @file fspusb.h - * @brief USB filesystem extension (fsp-usb) service IPC wrapper. - * @author XorTroll - * @copyright libnx Authors +/* + * Copyright (c) 2019-2020 XorTroll + * Copyright (c) 2019-2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + #pragma once #ifndef __FSPUSB_H__ diff --git a/source/gamecard.c b/source/gamecard.c index d476191..6a51a3f 100644 --- a/source/gamecard.c +++ b/source/gamecard.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include @@ -75,7 +91,8 @@ static void gamecardCloseStorageArea(void); static bool gamecardGetSizesFromStorageAreas(void); -/* Service guard used to generate thread-safe initialize + exit functions */ +/* Service guard used to generate thread-safe initialize + exit functions. */ +/* I'm using this here even though this actually isn't a service but who cares, it gets the job done. */ NX_GENERATE_SERVICE_GUARD(gamecard); bool gamecardIsReady(void) @@ -766,7 +783,7 @@ static bool gamecardGetSizesFromStorageAreas(void) gamecardCloseStorageArea(); - if (R_FAILED(rc)) + if (R_FAILED(rc) || !area_size) { LOGFILE("fsStorageGetSize failed to retrieve %s storage area size! (0x%08X)", GAMECARD_STORAGE_AREA_NAME(area), rc); g_gameCardStorageNormalAreaSize = g_gameCardStorageSecureAreaSize = 0; diff --git a/source/gamecard.h b/source/gamecard.h index 300fc37..a7dd244 100644 --- a/source/gamecard.h +++ b/source/gamecard.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __GAMECARD_H__ diff --git a/source/keys.c b/source/keys.c index 9921f91..2c986a0 100644 --- a/source/keys.c +++ b/source/keys.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include diff --git a/source/keys.h b/source/keys.h index d81930a..c9d399a 100644 --- a/source/keys.h +++ b/source/keys.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __KEYS_H__ diff --git a/source/main.c b/source/main.c index 4a21345..24000c0 100644 --- a/source/main.c +++ b/source/main.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include @@ -44,26 +60,113 @@ int main(int argc, char *argv[]) if (gamecardIsReady()) break; } - u64 size = 0; - if (!gamecardGetTotalRomSize(&size)) + FILE *tmp_file = NULL; + GameCardHeader header = {0}; + FsGameCardCertificate cert = {0}; + u64 total_size = 0, trimmed_size = 0; + u32 update_version = 0; + + if (gamecardGetHeader(&header)) { - printf("totalromsize failed"); - goto out2; + printf("header success\n"); + consoleUpdate(NULL); + + tmp_file = fopen("sdmc:/header.bin", "wb"); + if (tmp_file) + { + fwrite(&header, 1, sizeof(GameCardHeader), tmp_file); + fclose(tmp_file); + tmp_file = NULL; + printf("header saved\n"); + } else { + printf("header not saved\n"); + } + } else { + printf("header failed\n"); } - printf("totalromsize: 0x%lX\n", size); consoleUpdate(NULL); - if (!gamecardGetTrimmedRomSize(&size)) + if (gamecardGetTotalRomSize(&total_size)) { - printf("trimmedromsize failed"); - goto out2; + printf("total_size: 0x%lX\n", total_size); + } else { + printf("total_size failed\n"); } - printf("trimmedromsize: 0x%lX\n", size); - -out2: consoleUpdate(NULL); + + if (gamecardGetTrimmedRomSize(&trimmed_size)) + { + printf("trimmed_size: 0x%lX\n", trimmed_size); + } else { + printf("trimmed_size failed\n"); + } + + consoleUpdate(NULL); + + if (gamecardGetCertificate(&cert)) + { + printf("cert success\n"); + consoleUpdate(NULL); + + tmp_file = fopen("sdmc:/cert.bin", "wb"); + if (tmp_file) + { + fwrite(&cert, 1, sizeof(FsGameCardCertificate), tmp_file); + fclose(tmp_file); + tmp_file = NULL; + printf("cert saved\n"); + } else { + printf("cert not saved\n"); + } + } else { + printf("cert failed\n"); + } + + consoleUpdate(NULL); + + if (gamecardGetBundledFirmwareUpdateVersion(&update_version)) + { + printf("update_version: %u\n", update_version); + } else { + printf("update_version failed\n"); + } + + consoleUpdate(NULL); + + u8 *buf = malloc((u64)0x400300); // 4 MiB + 512 bytes + 256 bytes + if (buf) + { + printf("buf succeeded\n"); + consoleUpdate(NULL); + + if (gamecardRead(buf, (u64)0x400300, (u64)0x16F18100)) // force unaligned read that spans both storage areas + { + printf("read succeeded\n"); + consoleUpdate(NULL); + + tmp_file = fopen("sdmc:/data.bin", "wb"); + if (tmp_file) + { + fwrite(buf, 1, (u64)0x400300, tmp_file); + fclose(tmp_file); + tmp_file = NULL; + printf("data saved\n"); + } else { + printf("data not saved\n"); + } + } else { + printf("read failed\n"); + } + + free(buf); + } else { + printf("buf failed\n"); + } + + consoleUpdate(NULL); + SLEEP(3); consoleExit(NULL); diff --git a/source/nca.c b/source/nca.c index bf8ee17..0070e30 100644 --- a/source/nca.c +++ b/source/nca.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include diff --git a/source/nca.h b/source/nca.h index fc1a67c..1c4166b 100644 --- a/source/nca.h +++ b/source/nca.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __NCA_H__ diff --git a/source/rsa.c b/source/rsa.c index d1ebbcb..8ba17c0 100644 --- a/source/rsa.c +++ b/source/rsa.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include diff --git a/source/rsa.h b/source/rsa.h index d33a2c8..252d4e2 100644 --- a/source/rsa.h +++ b/source/rsa.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __RSA_H__ diff --git a/source/save.c b/source/save.c index 83d0e22..2c9ffbe 100644 --- a/source/save.c +++ b/source/save.c @@ -1,5 +1,19 @@ -/* Savedata container parsing code taken from Lockpick_RCM with some slight modifications */ -/* Big thanks to shchmue */ +/* + * Copyright (c) 2019-2020 shchmue + * Copyright (c) 2019-2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include #include @@ -122,39 +136,40 @@ static remap_segment_ctx_t *save_remap_init_segments(remap_header_t *header, rem for(i = 0; i < header->map_segment_count; i++) { - remap_segment_ctx_t *seg = &segments[i]; + remap_segment_ctx_t *seg = &(segments[i]); - seg->entries = calloc(1, sizeof(remap_entry_ctx_t)); + seg->entry_count = 0; + + seg->entries = calloc(1, sizeof(remap_entry_ctx_t*)); if (!seg->entries) { LOGFILE("Failed to allocate memory for remap segment entry #%u!", entry_idx); goto out; } - memcpy(seg->entries, &map_entries[entry_idx], sizeof(remap_entry_ctx_t)); + seg->entries[seg->entry_count++] = &map_entries[entry_idx]; seg->offset = map_entries[entry_idx].virtual_offset; - map_entries[entry_idx].segment = seg; - seg->entry_count = 1; - entry_idx++; + map_entries[entry_idx++].segment = seg; while(entry_idx < num_map_entries && map_entries[entry_idx - 1].virtual_offset_end == map_entries[entry_idx].virtual_offset) { map_entries[entry_idx].segment = seg; map_entries[entry_idx - 1].next = &map_entries[entry_idx]; - seg->entries = calloc(1, sizeof(remap_entry_ctx_t)); - if (!seg->entries) + remap_entry_ctx_t **ptr = calloc(sizeof(remap_entry_ctx_t*), seg->entry_count + 1); + if (!ptr) { LOGFILE("Failed to allocate memory for remap segment entry #%u!", entry_idx); goto out; } - memcpy(seg->entries, &map_entries[entry_idx], sizeof(remap_entry_ctx_t)); - seg->entry_count++; - entry_idx++; + memcpy(ptr, seg->entries, sizeof(remap_entry_ctx_t*) * seg->entry_count); + free(seg->entries); + seg->entries = ptr; + seg->entries[seg->entry_count++] = &map_entries[entry_idx++]; } - seg->length = (seg->entries[seg->entry_count - 1].virtual_offset_end - seg->entries[0].virtual_offset); + seg->length = (seg->entries[seg->entry_count - 1]->virtual_offset_end - seg->entries[0]->virtual_offset); } success = true; @@ -174,8 +189,7 @@ out: map_entries[entry_idx].segment->entries = NULL; } - map_entries[entry_idx].segment = NULL; - entry_idx++; + map_entries[entry_idx++].segment = NULL; while(entry_idx < num_map_entries && map_entries[entry_idx - 1].virtual_offset_end == map_entries[entry_idx].virtual_offset) { @@ -189,8 +203,7 @@ out: map_entries[entry_idx].segment->entries = NULL; } - map_entries[entry_idx].segment = NULL; - entry_idx++; + map_entries[entry_idx++].segment = NULL; } } @@ -215,7 +228,7 @@ static remap_entry_ctx_t *save_remap_get_map_entry(remap_storage_ctx_t *ctx, u64 { for(unsigned int i = 0; i < ctx->segments[segment_idx].entry_count; i++) { - if (ctx->segments[segment_idx].entries[i].virtual_offset_end > offset) return (&ctx->segments[segment_idx].entries[i]); + if (ctx->segments[segment_idx].entries[i]->virtual_offset_end > offset) return ctx->segments[segment_idx].entries[i]; } } @@ -360,7 +373,7 @@ static bool save_ivfc_storage_init(hierarchical_integrity_verification_storage_c u32 length; }; - static struct salt_source_t salt_sources[6] = { + static const struct salt_source_t salt_sources[6] = { { "HierarchicalIntegrityVerificationStorage::Master", 48 }, { "HierarchicalIntegrityVerificationStorage::L1", 44 }, { "HierarchicalIntegrityVerificationStorage::L2", 44 }, @@ -560,7 +573,7 @@ static bool save_ivfc_storage_read(integrity_verification_storage_ctx_t *ctx, vo } memcpy(data_buffer, ctx->salt, 0x20); - memcpy(data_buffer + 0x20, buffer, count); + memcpy(data_buffer + 0x20, buffer, ctx->sector_size); sha256CalculateHash(hash, data_buffer, ctx->sector_size + 0x20); hash[0x1F] |= 0x80; @@ -1223,9 +1236,7 @@ bool save_process(save_ctx_t *ctx) return success; } - if (!save_process_header(ctx)) return success; - - if (ctx->header_hash_validity == VALIDITY_INVALID) + if (!save_process_header(ctx) || ctx->header_hash_validity == VALIDITY_INVALID) { /* Try to parse Header B. */ fr = f_lseek(ctx->file, 0x4000); @@ -1242,9 +1253,7 @@ bool save_process(save_ctx_t *ctx) return success; } - if (!save_process_header(ctx)) return success; - - if (ctx->header_hash_validity == VALIDITY_INVALID) + if (!save_process_header(ctx) || ctx->header_hash_validity == VALIDITY_INVALID) { LOGFILE("Savefile header is invalid!"); return success; @@ -1591,7 +1600,7 @@ void save_free_contexts(save_ctx_t *ctx) { for(unsigned int j = 0; j < ctx->data_remap_storage.segments[i].entry_count; j++) { - if (&(ctx->data_remap_storage.segments[i].entries[j])) free(&(ctx->data_remap_storage.segments[i].entries[j])); + if (ctx->data_remap_storage.segments[i].entries[j]) free(ctx->data_remap_storage.segments[i].entries[j]); } } } @@ -1614,7 +1623,7 @@ void save_free_contexts(save_ctx_t *ctx) { for(unsigned int j = 0; j < ctx->meta_remap_storage.segments[i].entry_count; j++) { - if (&(ctx->meta_remap_storage.segments[i].entries[j])) free(&(ctx->meta_remap_storage.segments[i].entries[j])); + if (ctx->meta_remap_storage.segments[i].entries[j]) free(ctx->meta_remap_storage.segments[i].entries[j]); } } } diff --git a/source/save.h b/source/save.h index 66bda94..7b90cf8 100644 --- a/source/save.h +++ b/source/save.h @@ -1,5 +1,19 @@ -/* Savedata container parsing code taken from Lockpick_RCM with some slight modifications */ -/* Big thanks to shchmue */ +/* + * Copyright (c) 2019-2020 shchmue + * Copyright (c) 2019-2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #pragma once @@ -165,7 +179,7 @@ struct remap_entry_ctx_t { struct remap_segment_ctx_t{ u64 offset; u64 length; - remap_entry_ctx_t *entries; + remap_entry_ctx_t **entries; u64 entry_count; }; diff --git a/source/services.c b/source/services.c index 435fa94..e968f5c 100644 --- a/source/services.c +++ b/source/services.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include diff --git a/source/services.h b/source/services.h index 246f08f..c5db7e1 100644 --- a/source/services.h +++ b/source/services.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __SERVICES_H__ diff --git a/source/signature.h b/source/signature.h index 647f071..2c30c5c 100644 --- a/source/signature.h +++ b/source/signature.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __SIGNATURE_H__ diff --git a/source/tik.c b/source/tik.c index 74feaa8..eec3dc7 100644 --- a/source/tik.c +++ b/source/tik.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include diff --git a/source/tik.h b/source/tik.h index 6acba51..62e1b56 100644 --- a/source/tik.h +++ b/source/tik.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __TIK_H__ diff --git a/source/utils.c b/source/utils.c index fe12a8f..f1e5d06 100644 --- a/source/utils.c +++ b/source/utils.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include @@ -84,7 +100,7 @@ void utilsWriteLogMessage(const char *func_name, const char *fmt, ...) time_t now = time(NULL); struct tm *ts = localtime(&now); - fprintf(logfile, "%d/%d/%d %d:%d:%d -> %s: ", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec, func_name); + fprintf(logfile, "%d/%d/%d %d:%02d:%02d -> %s: ", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec, func_name); va_start(args, fmt); vfprintf(logfile, fmt, args); diff --git a/source/utils.h b/source/utils.h index d055d33..338709e 100644 --- a/source/utils.h +++ b/source/utils.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 DarkMatterCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #ifndef __UTILS_H__