summaryrefslogtreecommitdiff
path: root/tools/lictool.c
blob: 4fcf493fc6f38369cce033c706910ee7818fc886 (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * lictool
 * 
 * Tool for manipulating PS1 license files
 */
 
#include <stdio.h>
#include <string.h>

unsigned char lic_buffer[37632]; // 16 CD sectors..

//0x2E08

void display_usage();

void display_usage()
{
	printf(""
	"lictool - PS1 license file manipulation tool\n"
	"usage: lictool <input> <output> <options>\n"
	"\n"
	"Options:\n"
	" -tmd=<file>      TMD file for boot logo\n"
	" -removelogo      Remove logo from license file\n");
}

int main(int argc, char *argv[])
{
	int x,y,z,sz;
	FILE *f;
	
	if(argc < 3)
	{
		display_usage();
		return 0;
	}
	
	f = fopen(argv[1], "rb");
	
	if(f == NULL)
	{
		printf("Could not open input license file! Aborting.\n");
		return -1;
	}
	
	fread(lic_buffer, sizeof(char), 37632, f);
	fclose(f);
	
	for(x = 3; x < argc; x++)
	{
		if(strncmp(argv[x], "-tmd=", 5) == 0)
		{
			f = fopen(argv[x] + 5, "rb");
			
			if(f == NULL)
				printf("Could not open TMD file %s. Ignoring option.\n", argv[x] + 5);
			else
			{				
				fseek(f, 0, SEEK_END);
				sz = ftell(f);
				fseek(f, 0, SEEK_SET);
				z = 0x2E08;
				
				for(y = 0; y < sz; y++)
				{
					if((z - ((z / 2352)*2352)) == 2072)
						z+=304;
					
					fread(&lic_buffer[z], sizeof(char), 1, f);
					
					z++;
				}
			
				fclose(f);
			}
		}
		else if(strncmp(argv[x], "-removelogo", 11) == 0)
		{
			z = 0x2E08;
			
			for(y = 0; y < 12; y++)
				lic_buffer[z+y] = 0;
			
			lic_buffer[z] = 0x41;
		}
	}
	
	f = fopen(argv[2], "wb");
	
	if(f == NULL)
	{
		printf("Could not open output file path for writing! Aborting.\n");
		return -1;
	}
	
	fwrite(lic_buffer, sizeof(char), 37632, f);
	fclose(f);
	
	return 0;
}