Created
March 28, 2021 23:35
-
-
Save rw-r-r-0644/9ab87e6c101341b279e5342a0464c2ac 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 <iostream> | |
#include <fstream> | |
#include <arpa/inet.h> | |
#include <cstdint> | |
#include <cstring> | |
struct FST_Entry | |
{ | |
char name[12]; | |
uint8_t mode; | |
uint8_t attr; | |
uint16_t sub; | |
uint16_t sib; | |
uint32_t size; | |
uint16_t x1; | |
uint16_t uid; | |
uint16_t gid; | |
uint32_t x3; | |
} __attribute__((packed)); | |
struct ISFS_Superblock | |
{ | |
uint32_t magic; | |
uint32_t generation; | |
uint32_t field_0x8; | |
uint16_t fat[0x8000]; | |
FST_Entry fst[6143]; | |
uint8_t pad[20]; | |
} __attribute__((packed)); | |
ISFS_Superblock *craftSuperBlock(void) | |
{ | |
ISFS_Superblock *super = new ISFS_Superblock(); | |
super->magic = htonl(0x53465321); | |
super->generation = htonl(0xffff0000); | |
super->field_0x8 = htonl(0); | |
/* fill cluster chain */ | |
for (int i = 0; i < 0x8000; i++) { | |
super->fat[i] = htons(0xFFFC); | |
} | |
/* generate 59 recursive directory entries */ | |
unsigned ifst; | |
for (ifst = 0; ifst < 59; ifst++) { | |
strcpy(super->fst[ifst].name, (ifst) ? "a" : "/"); | |
super->fst[ifst].mode = 2; | |
super->fst[ifst].attr = 0; | |
super->fst[ifst].sib = htons(0xFFFF); | |
super->fst[ifst].sub = htons(ifst + 1); | |
} | |
return super; | |
} | |
bool writeFile(std::string const & filename, char const * data, size_t const bytes) | |
{ | |
std::ofstream fout(filename.c_str(), std::fstream::out | std::fstream::binary); | |
if (!fout) | |
return false; | |
fout.write(data, bytes); | |
return (fout.good()); | |
} | |
int main(int argc, char **argv) | |
{ | |
ISFS_Superblock *super = craftSuperBlock(); | |
writeFile("super.bin", (char const *)super, sizeof(*super)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment