Created
September 8, 2019 15:47
-
-
Save knight-ryu12/d18338ac55c18656428fc565b581da99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define _3DSX_MAGIC 0x58534433 // '3DSX' | |
#define _SMDH_MAGIC 0x48444d53 // 'SMDH' | |
#define _IVFC_MAGIC 0x43465649 // 'IVFC' | |
typedef struct | |
{ | |
uint32_t magic; | |
uint16_t headerSize, relocHdrSize; | |
uint32_t formatVer; | |
uint32_t flags; | |
// Sizes of the code, rodata and data segments + | |
// size of the BSS section (uninitialized latter half of the data segment) | |
uint32_t codeSegSize, rodataSegSize, dataSegSize, bssSize; | |
// offset and size of smdh | |
uint32_t smdhOffset, smdhSize; | |
// offset to filesystem | |
uint32_t fsOffset; | |
} _3DSX_Header; | |
typedef struct { | |
uint64_t logicalOfs; | |
uint64_t hashDataSize; | |
uint32_t blocksize; // in log2 | |
uint32_t reserved; | |
} _LevelData; | |
typedef struct { | |
uint32_t magic1; // "IVFC" | |
uint32_t magic2; //0x10000 | |
uint32_t masterhashSize; | |
_LevelData level1Data; | |
_LevelData level2Data; | |
_LevelData level3Data; | |
uint32_t reserved; | |
uint32_t optionalInfoSize; | |
} _IVFC_Header; | |
typedef struct { | |
// Each one is UTF-16 encoded. | |
uint8_t shortDesc[0x80]; | |
uint8_t longDesc[0x100]; | |
uint8_t Publisher[0x80]; | |
} _APPT_Header; | |
typedef struct | |
{ | |
// Applicaiton settings | |
uint8_t ageRating[0x10]; | |
uint32_t regLockout; | |
uint8_t mmID[0xC]; //M(atch)M(aker)ID | |
uint32_t flag; | |
uint16_t vEula; | |
uint16_t reserved; | |
uint32_t OADF; // Optimal Animation Default Frame ??? | |
uint32_t CECID; // Street pass ID | |
} _APPS_Header; | |
typedef struct { | |
uint8_t small[0x480]; // these encoding is word-order crap. | |
uint8_t large[0x1200]; | |
} _ICON_Header; | |
typedef struct { | |
uint32_t magic; | |
uint16_t version, reserved1; | |
_APPT_Header titles[16]; // 0x200 bytes long | |
_APPS_Header applicationSetting; | |
uint64_t reserved2; | |
_ICON_Header iconGraphic; | |
} _SMDH_Header; | |
void print_help(char *filename) { | |
printf("Usage %s [file.3dsx]\n", filename); | |
} | |
int main(int argv, char *argc[]) { | |
FILE *f = NULL; | |
_3DSX_Header _3dsx_header; | |
_SMDH_Header _smdh_header; | |
uint8_t buf[4]; | |
if (argv == 2) { | |
f = fopen(argc[1], "rb"); | |
} else { | |
print_help(argc[0]); | |
return 1; | |
} | |
if (f == NULL) { | |
printf("ERROR: can't open file\n"); | |
print_help(argc[0]); | |
return 2; | |
} | |
fread(&buf, 1, 4, f); // read 4 byte off | |
rewind(f); | |
if (buf == _3DSX_MAGIC) { | |
// 3DSX. | |
} else if (buf == _SMDH_MAGIC) { | |
// SMDH. | |
} else if (buf == _IVFC_MAGIC) { | |
// IVFC. | |
} else { | |
printf("This file isn't supported! bailing out.\n"); | |
return 3; | |
} | |
//FILE *f = fopen("test.3dsx", "rb"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment