Last active
June 1, 2018 03:45
-
-
Save Jakz/07e16ef3e371fec65ccf320f9a031de6 to your computer and use it in GitHub Desktop.
3ds Cart2 rom save remover
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 <cstdio> | |
#include <cstdlib> | |
#include <iostream> | |
using byte = uint8_t; | |
int main(int argc, const char* argv[]) | |
{ | |
if (argc == 2) | |
{ | |
FILE* in = fopen(argv[1], "rb"); | |
if (!in) | |
{ | |
std::cout << "Input file doesn't exist" << std::endl; | |
return -1; | |
} | |
FILE* out = fopen("out.3ds", "wb"); | |
if (!out) | |
{ | |
fclose(in); | |
std::cout << "Unable to create output file" << std::endl; | |
return -1; | |
} | |
constexpr size_t START_OFFSET = 0x77280000; | |
constexpr size_t END_OFFSET = 0x80000000; | |
constexpr size_t BUFFER_SIZE = 2 << 24; /* 16 MB */ | |
fseek(in, 0, SEEK_END); | |
const size_t fileLength = ftell(in); | |
fseek(in, 0, SEEK_SET); | |
size_t position = 0; | |
byte* buffer = new byte[BUFFER_SIZE]; | |
while (position < fileLength) | |
{ | |
const size_t step = std::min((position < START_OFFSET ? START_OFFSET : fileLength) - position, BUFFER_SIZE); | |
size_t check = 0; | |
if (position < START_OFFSET) | |
check = fread(buffer, 1, step, in); | |
else if (position == START_OFFSET) | |
std::fill(buffer, buffer + BUFFER_SIZE, 0xFF); | |
if (check != step) | |
{ | |
std::cout << "I/O read error" << std::endl; | |
break; | |
} | |
check = fwrite(buffer, 1, step, out); | |
if (check != step) | |
{ | |
std::cout << "I/O read error" << std::endl; | |
break; | |
} | |
else | |
std::cout << "processed " << position << " bytes.." << std::endl; | |
position += step; | |
} | |
delete [] buffer; | |
fclose(in); | |
fclose(out); | |
} | |
else | |
std::cout << "Please specify an input file" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment