OK, so I found the C programming posts by a few people about byte-order swapping, and I've got that working just fine, but I'm a little confused as to how to grab those informations from a file, convert it, and then save that to a different file.
Code:
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <stdint.h>
using namespace std;
main(int argc, char *argv[])
{
FILE* originalSave;
FILE* newSave;
long fSize;
uint32_t *buffer;
int x;
uint32_t input = 0, j, result = 0, temp, final = 0, k;
originalSave = fopen(argv[1], "rb");
if (originalSave == NULL) {fputs("File error",stderr); exit(1);}
newSave = fopen("newSave.fla", "wb+");
fseek(originalSave, 0, SEEK_END);
fSize = ftell(originalSave);
rewind(originalSave);
buffer = (char*) malloc(sizeof(char)*fSize);
if (buffer == NULL)
{
fputs("Memory error",stderr); exit(2);
}
fread(buffer, 1, 4, originalSave);
result = ((buffer << 24) & 0xFF000000) |
((buffer << 8) & 0x00FF0000) |
((buffer >> 8) & 0x0000FF00) |
((buffer >> 24) & 0X000000FF);
printf("Original hex: %X\n;Swapped hex: %X\n", buffer, result);
//fwrite(buffer, fSize/4, 4, newSave);
//fclose(newSave);
//fclose(originalSave);
//free(buffer);
cout << "Press ENTER to continue...";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
return 0;
}
I don't even know if my code is functional (I get an error about invalid char or int to binary "operator>>" or whatever about the swap lines), but the structure should work, right? I'm completely confused by this.
Oh, and eventually, I want to be able to do this with a file of up to 128KB size, so...