From eb7f4a8d88c1fd822b29e32cfac2a3443c8bee34 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 14 Jun 2015 14:56:06 -0700 Subject: [PATCH] Cleanup of dumping code to use cstdio --- source/utils/savedatacheck/savedatacheck.cpp | 68 ++++++++------------ source/utils/shared_font/shared_font.cpp | 43 ++++++------- 2 files changed, 45 insertions(+), 66 deletions(-) diff --git a/source/utils/savedatacheck/savedatacheck.cpp b/source/utils/savedatacheck/savedatacheck.cpp index d3b7c08..e63df17 100644 --- a/source/utils/savedatacheck/savedatacheck.cpp +++ b/source/utils/savedatacheck/savedatacheck.cpp @@ -12,54 +12,44 @@ #include "utils/shared_font/shared_font.h" namespace SaveDataCheck { - -std::string BuildSharedRomFSFilename(u8* lowpath) { - const u32* split_lowpath = reinterpret_cast(lowpath); + +std::string BuildSharedRomFSFilename(u32* lowpath) { char* filename_buffer; - asprintf(&filename_buffer, "/%08x%08x.bin", split_lowpath[1], split_lowpath[0]); + asprintf(&filename_buffer, "/%08lx%08lx.bin", lowpath[1], lowpath[0]); std::string filename(filename_buffer); free(filename_buffer); return filename; } - -void DumpSharedRomFS(u8* archive_binary_lowpath) { + +void DumpSharedRomFS(u32* archive_binary_lowpath) { std::string output_file = BuildSharedRomFSFilename(archive_binary_lowpath); - + // Read RomFS bin from SaveDataCheck... - + Handle romfs_handle; u64 romfs_size = 0; u32 romfs_bytes_read = 0; - - FS_archive savedatacheck_archive = { 0x2345678a, { PATH_BINARY, 16, archive_binary_lowpath } }; + + FS_archive savedatacheck_archive = { 0x2345678a, { PATH_BINARY, 16, (u8*)archive_binary_lowpath } }; u8 file_binary_lowpath[20] = {}; FS_path romfs_path = { PATH_BINARY, 20, file_binary_lowpath }; - + print(GFX_TOP, "Dumping SaveDataCheck RomFS (%s)... ", output_file.c_str()); FSUSER_OpenFileDirectly(NULL, &romfs_handle, savedatacheck_archive, romfs_path, FS_OPEN_READ, FS_ATTRIBUTE_NONE); FSFILE_GetSize(romfs_handle, &romfs_size); - + std::unique_ptr romfs_data_buffer(new u8[romfs_size]); FSFILE_Read(romfs_handle, &romfs_bytes_read, 0, romfs_data_buffer.get(), romfs_size); FSFILE_Close(romfs_handle); - + // Dump RomFS bin to SDMC... - - Handle file_handle; - u32 bytes_written = 0; - FS_path fs_path = FS_makePath(PATH_CHAR, output_file.c_str()); - FS_archive sdmc_archive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } }; - - FSUSER_OpenArchive(NULL, &sdmc_archive); - FSUSER_OpenFile(NULL, &file_handle, sdmc_archive, fs_path, FS_OPEN_CREATE | FS_OPEN_WRITE, FS_ATTRIBUTE_NONE); - Result res = FSFILE_Write(file_handle, &bytes_written, 0x0, romfs_data_buffer.get(), romfs_size, FS_WRITE_FLUSH); - FSFILE_Close(file_handle); - FSUSER_CloseArchive(NULL, &sdmc_archive); - - // Check result... - - if (res == 0 && bytes_written == romfs_size) + + FILE* out_file = fopen(output_file.c_str(), "wb"); + size_t bytes_written = fwrite(romfs_data_buffer.get(), 1, romfs_size, out_file); + fclose(out_file); + + if (bytes_written == romfs_size) print(GFX_TOP, "Done!\n"); else print(GFX_TOP, "Failed!\n"); @@ -67,22 +57,16 @@ void DumpSharedRomFS(u8* archive_binary_lowpath) { void Dump() { // savedatacheck/000400db00010302.bin - u8 binary_lowpath_000400db00010302[] = { - 0x02, 0x03, 0x01, 0x00, 0xdb, 0x00, 0x04, 0x00, 0x00, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 - }; - DumpSharedRomFS(binary_lowpath_000400db00010302); - + u64 binary_lowpath_000400db00010302[] = { 0x000400db00010302, 0x00000001ffffff00 }; + DumpSharedRomFS((u32*)binary_lowpath_000400db00010302); + // savedatacheck/0004009b00010202.bin - u8 binary_lowpath_0004009b00010202[] = { - 0x02, 0x02, 0x01, 0x00, 0x9b, 0x00, 0x04, 0x00, 0x00, 0xff, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00 - }; - DumpSharedRomFS(binary_lowpath_0004009b00010202); - + u64 binary_lowpath_0004009b00010202[] = { 0x0004009b00010202, 0x00000002ffffff00 }; + DumpSharedRomFS((u32*)binary_lowpath_0004009b00010202); + // savedatacheck/0004009b00010402.bin - u8 binary_lowpath_0004009b00010402[] = { - 0x02, 0x04, 0x01, 0x00, 0x9b, 0x00, 0x04, 0x00, 0x00, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 - }; - DumpSharedRomFS(binary_lowpath_0004009b00010402); + u64 binary_lowpath_0004009b00010402[] = { 0x0004009b00010402, 0x00000001ffffff00 }; + DumpSharedRomFS((u32*)binary_lowpath_0004009b00010402); } } // namespace diff --git a/source/utils/shared_font/shared_font.cpp b/source/utils/shared_font/shared_font.cpp index 181068b..4e9edef 100644 --- a/source/utils/shared_font/shared_font.cpp +++ b/source/utils/shared_font/shared_font.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include + #include <3ds.h> #include "output.h" @@ -13,47 +15,40 @@ static const u32 SHARED_FONT_SIZE = 0x300000; void Dump() { static const char* path = "/shared_font.bin"; - + print(GFX_TOP, "Dumping shared system font (%s)... ", path); - + // Connect to APT service... - + Handle apt_handle; srvGetServiceHandle(&apt_handle, "APT:U"); u32* cmdbuf=getThreadCommandBuffer(); - + // Call APT::GetSharedFont function to load font into memory... - + cmdbuf[0] = 0x00440000; svcSendSyncRequest(apt_handle); Handle mem_handle = cmdbuf[4]; void* shared_font_addr = reinterpret_cast(cmdbuf[2]); - + // Close APT handle... - + svcCloseHandle(apt_handle); - + // Map shared font memory... - + svcMapMemoryBlock(mem_handle, 0, MEMPERM_READ, MEMPERM_DONTCARE); - + // Dump shared font to SDMC... - - Handle file_handle; - u32 bytes_written = 0; - static const FS_path fs_path = FS_makePath(PATH_CHAR, path); - FS_archive sdmc_archive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } }; - - FSUSER_OpenArchive(NULL, &sdmc_archive); - FSUSER_OpenFile(NULL, &file_handle, sdmc_archive, fs_path, FS_OPEN_CREATE | FS_OPEN_WRITE, FS_ATTRIBUTE_NONE); - Result res = FSFILE_Write(file_handle, &bytes_written, 0x0, shared_font_addr, SHARED_FONT_SIZE, FS_WRITE_FLUSH); - FSFILE_Close(file_handle); - FSUSER_CloseArchive(NULL, &sdmc_archive); - + + FILE* out_file = fopen(path, "wb"); + size_t bytes_written = fwrite(shared_font_addr, 1, SHARED_FONT_SIZE, out_file); + fclose(out_file); + // Check result... - - if (res == 0 && bytes_written == SHARED_FONT_SIZE) + + if (bytes_written == SHARED_FONT_SIZE) print(GFX_TOP, "Done!\n"); else print(GFX_TOP, "Failed!\n");