forked from int-0/ebootsigner
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathebootsign.c
129 lines (114 loc) · 2.45 KB
/
ebootsign.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <malloc/malloc.h>
#endif
#include <unistd.h>
#if defined(_MSC_VER) || defined (__MINGW32__)
#include <direct.h>
#define mkdir(p,m) _mkdir(p)
#endif
#define MAX_BUFFER_SIZE 1024*1024*5+1024*512
#define MAX_ORIGIN_FILE_SIZE 1024*1024*4
#include "main_crypter.h"
#include "unpack-pbp.h"
#include "pack-pbp.h"
#include "fix-realocations.h"
char *filename_list[10] = {
"name",
"EBOOT_signed.PBP",
"param.sfo",
"icon0.png",
"icon1.pmf",
"pic0.png",
"pic1.png",
"snd0.at3",
"data.psp",
"data.psar"
};
void clean_tmp(void) {
remove("param.sfo");
remove("icon0.png");
remove("icon1.pmf");
remove("pic0.png");
remove("pic1.png");
remove("snd0.at3");
remove("data.psp");
remove("data_unsigned.psp");
remove("data.psar");
chdir("../");
rmdir("tmp_sgn");
}
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("USAGE: %s <unsigned.pbp> <outfile.pbp>\n", argv[0]);
return 1;
}
const char *filename = argv[1];
FILE *infile;
// Try to open given filename
infile = fopen(filename, "rb");
if (infile == NULL) {
printf("ERROR: Could not open %s\n", filename);
return -1;
}
// Try to make given filename
char *dest_file = argv[2];
FILE *outfile;
remove(dest_file);
outfile = fopen(dest_file, "wb");
if (outfile == NULL) {
printf("ERROR: Could not create %s\n", dest_file);
return -1;
}
int err = 0;
// Make temp directory
mkdir("./tmp_sgn/", 0777);
chdir("./tmp_sgn/");
remove("param.sfo");
remove("icon0.png");
remove("icon1.pmf");
remove("pic0.png");
remove("pic1.png");
remove("snd0.at3");
remove("data.psp");
remove("data_unsigned.psp");
remove("data.psar");
// Unpack PBP file
err = unpack_pbp(infile);
if(err != 0) {
printf("Error while unpacking: %d\n",err);
clean_tmp();
return 1;
}
// Fix PRX realocations
err = fix_realocations();
if(err != 0) {
printf("Error while fixing realocations: %d\n",err);
clean_tmp();
return 1;
}
// Crypt PRX file
err = main_crypter();
if(err != 0) {
printf("Error while crypting: %d\n",err);
clean_tmp();
return 1;
}
// Repacking
err = pack_pbp(outfile, filename_list);
if(err != 0) {
printf("Error while packing: %d\n",err);
clean_tmp();
return 1;
}
// Done
clean_tmp();
return 0;
}