forked from yellows8/3ds_homemenuhax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomemenu_themelz_tool.c
72 lines (55 loc) · 1.3 KB
/
homemenu_themelz_tool.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
//Build with: gcc -o homemenu_themelz_tool lz11.c homemenu_themelz_tool.c
//This code simulates how Home Menu handles theme data decompression.
int decompress_lz11(unsigned char *compressed_datain, unsigned char *decompressed_dataout, int insize, int maxoutsize);
int main(int argc, char **argv)
{
FILE *f;
unsigned char *buffer;
int insize = 0;
int ret;
struct stat filestats;
if(argc<3)return 0;
if(stat(argv[1], &filestats)==-1)
{
printf("Failed to stat input.\n");
return 1;
}
insize = filestats.st_size;
if(insize > 0x150000)
{
printf("Input file is too large.\n");
return 3;
}
f = fopen(argv[1], "rb");
if(f==NULL)
{
printf("Failed to open input file for reading.\n");
return 2;
}
buffer = (unsigned char*)malloc(0x400000);
if(buffer==NULL)
{
printf("Failed to alloc mem.\n");
fclose(f);
return 4;
}
memset(buffer, 0, 0x400000);
fread(&buffer[0x150000], 1, insize, f);
fclose(f);
ret = decompress_lz11(&buffer[0x150000], buffer, insize, 0x400000);
printf("decompress_lz11() retval: %d\n", ret);
f = fopen(argv[2], "wb");
if(f==NULL)
{
printf("Failed to open output file for writing.\n");
free(buffer);
return 2;
}
fwrite(buffer, 1, 0x400000, f);
fclose(f);
return 0;
}