void NDSFile::load() { Common::File nds; open(nds); if (!isNDS(nds)) throw Common::Exception("Not a support NDS ROM file"); nds.seek(0x40); uint32 fileNameTableOffset = nds.readUint32LE(); uint32 fileNameTableLength = nds.readUint32LE(); uint32 fatOffset = nds.readUint32LE(); //uint32 fatLength = nds.readUint32LE(); try { readNames(nds, fileNameTableOffset, fileNameTableLength); readFAT(nds, fatOffset); if (nds.err()) throw Common::Exception(Common::kReadError); } catch (Common::Exception &e) { e.add("Failed reading NDS file"); throw; } }
void Runner::run() { if((device.fd=open(device.filename.c_str(), O_RDONLY))==-1) { std::cout <<"Cannot open device"<< std::endl; return; } if(readBootEntry()==-1) return; if(readFAT()==-1) return; if(readDirEntry()==-1) return; switch(action) { case PRINTBOOT: printFSinfo(); break; case LISTDIR: listDir(); break; case EIGHTPTHREE: eightPthree(); break; case LONGFN: longFN(); break; default: std::cout <<"what should I do?"<< std::endl; } close(device.fd); }
FILE *readfiletoFILE(char *shortname) { FILE *retfile = palloc(sizeof(FILE)); struct bpb *header = palloc(512); readblock(0, (unsigned char*)header, 1, 0); header = (struct bpb*)((unsigned char*)header + 3); fileentry_t *initEntry; initEntry = getinitialentry(shortname, header); unsigned int fatSize = (header->sectorsPerFAT * header->sectorSize); unsigned char *fat = readFAT(header, fatSize); retfile->currentreadoffset = 0; retfile->currentwriteoffset = 0; retfile->stream = palloc(initEntry->sizebytes); retfile->length = initEntry->sizebytes; unsigned short clusternum = initEntry->startcluster; unsigned int maxnumclusters = header->sectorsPerFAT * header->sectorSize / 16; while(clusternum && clusternum < maxnumclusters) { readcluster(clusternum, header, retfile->stream + retfile->currentwriteoffset); retfile->currentwriteoffset += (header->sectorsPerCluster * header->sectorSize); clusternum = nextcluster(clusternum, fat); } pfree(header); pfree(fat); return retfile; }
unsigned char *readfile(char *shortname) { struct bpb *header = palloc(512); readblock(0, (unsigned char*)header, 1, 0); header = (struct bpb*)((unsigned char*)header + 3); fileentry_t *initEntry; initEntry = getinitialentry(shortname, header); unsigned int fatSize = (header->sectorsPerFAT * header->sectorSize); unsigned char *fat = readFAT(header, fatSize); unsigned char *buffer = palloc(initEntry->sizebytes); unsigned char *retval = buffer; unsigned short clusternum = initEntry->startcluster; unsigned int maxnumclusters = header->sectorsPerFAT * header->sectorSize / 16; while(clusternum < maxnumclusters) { readcluster(clusternum, header, buffer); buffer += (header->sectorsPerCluster * header->sectorSize); clusternum = nextcluster(clusternum, fat); } pfree(header); pfree(fat); return retval; }
void NDSFile::load() { Common::File nds; open(nds); if (!readHeader(nds)) throw Common::Exception("Not a valid NDS ROM file"); try { readNames(nds, _fileNameTableOffset, _fileNameTableLength); readFAT(nds, _fatOffset); if (nds.err()) throw Common::Exception(Common::kReadError); } catch (Common::Exception &e) { e.add("Failed reading NDS file"); throw; } }
void NDSFile::load(Common::SeekableReadStream &nds) { if (!isNDS(nds, _title, _code, _maker)) throw Common::Exception("Not a supported NDS ROM file"); nds.seek(0x40); uint32 fileNameTableOffset = nds.readUint32LE(); uint32 fileNameTableLength = nds.readUint32LE(); uint32 fatOffset = nds.readUint32LE(); //uint32 fatLength = nds.readUint32LE(); try { readNames(nds, fileNameTableOffset, fileNameTableLength); readFAT(nds, fatOffset); } catch (Common::Exception &e) { e.add("Failed reading NDS file"); throw; } }