1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-26 05:42:07 +00:00
TegraExplorer/source/tegraexplorer/fs/fsextractbis.c

93 lines
2.3 KiB
C
Raw Normal View History

2020-03-19 15:11:18 +00:00
#include "fsutils.h"
#include <string.h>
#include "../../gfx/gfx.h"
#include "../gfx/gfxutils.h"
#include "../../utils/types.h"
#include "../../storage/emummc.h"
#include "../common/common.h"
#include "../../libs/fatfs/ff.h"
#include "../../utils/sprintf.h"
#include "../../mem/heap.h"
#include "../../storage/nx_emmc.h"
#include "../common/types.h"
#include "../utils/utils.h"
2020-04-05 15:07:25 +01:00
#include "fsactions.h"
2020-03-19 15:11:18 +00:00
void copy_fil_size(FIL* in_src, FIL* out_src, int size_src){
u8* buff;
2020-05-15 15:07:23 +01:00
buff = calloc(BUFSIZE, sizeof(u8));
2020-03-19 15:11:18 +00:00
int size = size_src;
int copysize;
while (size > 0){
2020-05-15 15:07:23 +01:00
copysize = MIN(BUFSIZE, size);
2020-03-19 15:11:18 +00:00
f_read(in_src, buff, copysize, NULL);
f_write(out_src, buff, copysize, NULL);
size -= copysize;
}
free(buff);
}
void gen_part(int size, FIL* in, char *path){
FIL out;
f_open(&out, path, FA_WRITE | FA_CREATE_ALWAYS);
copy_fil_size(in, &out, size);
f_close(&out);
}
2020-05-15 15:07:23 +01:00
const char *filenames[] = {
"BOOT0.bin",
"BOOT1.bin",
"BCPKG2-1-Normal-Main",
"BCPKG2-3-SafeMode-Main",
"BCPKG2-2-Normal-Sub",
"BCPKG2-4-SafeMode-Sub"
};
2020-03-19 15:11:18 +00:00
int extract_bis_file(char *path, char *outfolder){
FIL in;
int res;
2020-04-05 15:07:25 +01:00
char *tempPath;
2020-05-15 15:07:23 +01:00
BisFile header;
2020-03-19 15:11:18 +00:00
if ((res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING))){
gfx_errDisplay("extract_bis_file", res, 0);
return -1;
}
2020-05-15 15:07:23 +01:00
f_read(&in, &header, sizeof(BisFile), NULL);
for (int i = 0; i < 4; i++)
header.sizes[i] = FLIPU32(header.sizes[i]);
2020-03-19 15:11:18 +00:00
2020-05-15 15:07:23 +01:00
gfx_printf("Version: %s\n\n", header.version);
2020-03-19 15:11:18 +00:00
2020-05-15 15:07:23 +01:00
// Loop to actually extract stuff
for (int i = 0; i < 4; i++){
if (!(header.args & (BIT((7 - i)))))
continue;
2020-03-19 15:11:18 +00:00
2020-05-15 15:07:23 +01:00
gfx_printf("Extracting %s\n", filenames[i]);
gen_part(header.sizes[i], &in, fsutil_getnextloc(outfolder, filenames[i]));
2020-04-05 15:07:25 +01:00
}
2020-05-15 15:07:23 +01:00
// Loop to copy pkg2_1->2 and pkg2_3->4
for (int i = 4; i < 6; i++){
if (!(header.args & BIT((9 - i))))
continue;
2020-04-05 15:07:25 +01:00
2020-05-15 15:07:23 +01:00
utils_copystring(fsutil_getnextloc(outfolder, filenames[i - 2]), &tempPath);
gfx_printf("Copying %s\n", filenames[i]);
fsact_copy(tempPath, fsutil_getnextloc(outfolder, filenames[i]), COPY_MODE_PRINT);
2020-04-05 15:07:25 +01:00
RESETCOLOR;
free(tempPath);
}
2020-03-19 15:11:18 +00:00
gfx_printf("\n\nDone!\n");
f_close(&in);
return 0;
}