| ... | ... |
@@ -15,8 +15,7 @@ |
| 15 | 15 |
along with the this software. If not, see <http://www.gnu.org/licenses/>. |
| 16 | 16 |
*/ |
| 17 | 17 |
|
| 18 |
-#ifndef _FIRMWARE_H_ |
|
| 19 |
-#define _FIRMWARE_H_ |
|
| 18 |
+#pragma once |
|
| 20 | 19 |
|
| 21 | 20 |
#include <memory> |
| 22 | 21 |
#include "types.h" |
| ... | ... |
@@ -80,5 +79,3 @@ public: |
| 80 | 79 |
|
| 81 | 80 |
int copy_firmware_user_data(uint8_t *dest_buffer, const uint8_t *fw_data); |
| 82 | 81 |
void NDS_FillDefaultFirmwareConfigData(struct NDS_fw_config_data *fw_config); |
| 83 |
- |
|
| 84 |
-#endif |
| ... | ... |
@@ -18,18 +18,19 @@ |
| 18 | 18 |
#ifndef _FIRMWARE_H_ |
| 19 | 19 |
#define _FIRMWARE_H_ |
| 20 | 20 |
|
| 21 |
-#include "common.h" |
|
| 21 |
+#include <memory> |
|
| 22 |
+#include "types.h" |
|
| 22 | 23 |
|
| 23 | 24 |
// the count of bytes copied from the firmware into memory |
| 24 |
-static const int NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT = 0x70; |
|
| 25 |
+const int NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT = 0x70; |
|
| 25 | 26 |
|
| 26 | 27 |
#define FW_CONFIG_FILE_EXT "dfc" |
| 27 | 28 |
|
| 28 | 29 |
class CFIRMWARE |
| 29 | 30 |
{
|
| 30 | 31 |
private: |
| 31 |
- uint8_t *tmp_data9; |
|
| 32 |
- uint8_t *tmp_data7; |
|
| 32 |
+ std::unique_ptr<uint8_t[]> tmp_data9; |
|
| 33 |
+ std::unique_ptr<uint8_t[]> tmp_data7; |
|
| 33 | 34 |
uint32_t size9, size7; |
| 34 | 35 |
|
| 35 | 36 |
uint32_t keyBuf[0x412]; |
| ... | ... |
@@ -41,16 +42,13 @@ private: |
| 41 | 42 |
void applyKeycode(uint32_t modulo); |
| 42 | 43 |
bool initKeycode(uint32_t idCode, int level, uint32_t modulo); |
| 43 | 44 |
uint16_t getBootCodeCRC16(); |
| 44 |
- uint32_t decrypt(const uint8_t *in, uint8_t* &out); |
|
| 45 |
- uint32_t decompress(const uint8_t *in, uint8_t* &out); |
|
| 46 |
- |
|
| 45 |
+ uint32_t decrypt(const uint8_t *in, std::unique_ptr<uint8_t[]> &out); |
|
| 46 |
+ uint32_t decompress(const uint8_t *in, std::unique_ptr<uint8_t[]> &out); |
|
| 47 | 47 |
public: |
| 48 |
- CFIRMWARE(): size9(0), size7(0), ARM9bootAddr(0), ARM7bootAddr(0), patched(0) {}
|
|
| 48 |
+ CFIRMWARE(): size9(0), size7(0), ARM9bootAddr(0), ARM7bootAddr(0), patched(0) { }
|
|
| 49 | 49 |
|
| 50 | 50 |
bool load(); |
| 51 | 51 |
|
| 52 |
- static std::string GetExternalFilePath(); |
|
| 53 |
- |
|
| 54 | 52 |
struct HEADER |
| 55 | 53 |
{
|
| 56 | 54 |
uint16_t part3_rom_gui9_addr; // 000h |
| ... | ... |
@@ -81,8 +79,6 @@ public: |
| 81 | 79 |
}; |
| 82 | 80 |
|
| 83 | 81 |
int copy_firmware_user_data(uint8_t *dest_buffer, const uint8_t *fw_data); |
| 84 |
-//int NDS_CreateDummyFirmware(struct NDS_fw_config_data *user_settings); |
|
| 85 | 82 |
void NDS_FillDefaultFirmwareConfigData(struct NDS_fw_config_data *fw_config); |
| 86 |
-//void NDS_PatchFirmwareMAC(); |
|
| 87 | 83 |
|
| 88 | 84 |
#endif |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,88 @@ |
| 1 |
+/* |
|
| 2 |
+ Copyright (C) 2009-2011 DeSmuME Team |
|
| 3 |
+ |
|
| 4 |
+ This file is free software: you can redistribute it and/or modify |
|
| 5 |
+ it under the terms of the GNU General Public License as published by |
|
| 6 |
+ the Free Software Foundation, either version 2 of the License, or |
|
| 7 |
+ (at your option) any later version. |
|
| 8 |
+ |
|
| 9 |
+ This file is distributed in the hope that it will be useful, |
|
| 10 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
+ GNU General Public License for more details. |
|
| 13 |
+ |
|
| 14 |
+ You should have received a copy of the GNU General Public License |
|
| 15 |
+ along with the this software. If not, see <http://www.gnu.org/licenses/>. |
|
| 16 |
+*/ |
|
| 17 |
+ |
|
| 18 |
+#ifndef _FIRMWARE_H_ |
|
| 19 |
+#define _FIRMWARE_H_ |
|
| 20 |
+ |
|
| 21 |
+#include "common.h" |
|
| 22 |
+ |
|
| 23 |
+// the count of bytes copied from the firmware into memory |
|
| 24 |
+static const int NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT = 0x70; |
|
| 25 |
+ |
|
| 26 |
+#define FW_CONFIG_FILE_EXT "dfc" |
|
| 27 |
+ |
|
| 28 |
+class CFIRMWARE |
|
| 29 |
+{
|
|
| 30 |
+private: |
|
| 31 |
+ uint8_t *tmp_data9; |
|
| 32 |
+ uint8_t *tmp_data7; |
|
| 33 |
+ uint32_t size9, size7; |
|
| 34 |
+ |
|
| 35 |
+ uint32_t keyBuf[0x412]; |
|
| 36 |
+ uint32_t keyCode[3]; |
|
| 37 |
+ |
|
| 38 |
+ bool getKeyBuf(); |
|
| 39 |
+ void crypt64BitUp(uint32_t *ptr); |
|
| 40 |
+ void crypt64BitDown(uint32_t *ptr); |
|
| 41 |
+ void applyKeycode(uint32_t modulo); |
|
| 42 |
+ bool initKeycode(uint32_t idCode, int level, uint32_t modulo); |
|
| 43 |
+ uint16_t getBootCodeCRC16(); |
|
| 44 |
+ uint32_t decrypt(const uint8_t *in, uint8_t* &out); |
|
| 45 |
+ uint32_t decompress(const uint8_t *in, uint8_t* &out); |
|
| 46 |
+ |
|
| 47 |
+public: |
|
| 48 |
+ CFIRMWARE(): size9(0), size7(0), ARM9bootAddr(0), ARM7bootAddr(0), patched(0) {}
|
|
| 49 |
+ |
|
| 50 |
+ bool load(); |
|
| 51 |
+ |
|
| 52 |
+ static std::string GetExternalFilePath(); |
|
| 53 |
+ |
|
| 54 |
+ struct HEADER |
|
| 55 |
+ {
|
|
| 56 |
+ uint16_t part3_rom_gui9_addr; // 000h |
|
| 57 |
+ uint16_t part4_rom_wifi7_addr; // 002h |
|
| 58 |
+ uint16_t part34_gui_wifi_crc16; // 004h |
|
| 59 |
+ uint16_t part12_boot_crc16; // 006h |
|
| 60 |
+ uint8_t fw_identifier[4]; // 008h |
|
| 61 |
+ uint16_t part1_rom_boot9_addr; // 00Ch |
|
| 62 |
+ uint16_t part1_ram_boot9_addr; // 00Eh |
|
| 63 |
+ uint16_t part2_rom_boot7_addr; // 010h |
|
| 64 |
+ uint16_t part2_ram_boot7_addr; // 012h |
|
| 65 |
+ uint16_t shift_amounts; // 014h |
|
| 66 |
+ uint16_t part5_data_gfx_addr; // 016h |
|
| 67 |
+ |
|
| 68 |
+ uint8_t fw_timestamp[5]; // 018h |
|
| 69 |
+ uint8_t console_type; // 01Dh |
|
| 70 |
+ uint16_t unused1; // 01Eh |
|
| 71 |
+ uint16_t user_settings_offset; // 020h |
|
| 72 |
+ uint16_t unknown1; // 022h |
|
| 73 |
+ uint16_t unknown2; // 024h |
|
| 74 |
+ uint16_t part5_crc16; // 026h |
|
| 75 |
+ uint16_t unused2; // 028h - FFh filled |
|
| 76 |
+ } header; |
|
| 77 |
+ |
|
| 78 |
+ uint32_t ARM9bootAddr; |
|
| 79 |
+ uint32_t ARM7bootAddr; |
|
| 80 |
+ bool patched; |
|
| 81 |
+}; |
|
| 82 |
+ |
|
| 83 |
+int copy_firmware_user_data(uint8_t *dest_buffer, const uint8_t *fw_data); |
|
| 84 |
+//int NDS_CreateDummyFirmware(struct NDS_fw_config_data *user_settings); |
|
| 85 |
+void NDS_FillDefaultFirmwareConfigData(struct NDS_fw_config_data *fw_config); |
|
| 86 |
+//void NDS_PatchFirmwareMAC(); |
|
| 87 |
+ |
|
| 88 |
+#endif |