forked from TnA-Plastic/FreeMcBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_osd.c
95 lines (77 loc) · 3.12 KB
/
build_osd.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
/*
_____ ___ ____
____| | ____| PS2 Open Source Project
| ___| |____
---------------------------------------------------------------------------
Copyright (C) 2008 - Neme & jimmikaelkael (www.psx-scene.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the Free McBoot License.
This program and any related documentation is provided "as is"
WITHOUT ANY WARRANTIES, either express or implied, including, but not
limited to, implied warranties of fitness for a particular purpose. The
entire risk arising out of use or performance of the software remains
with you.
In no event shall the author be liable for any damages whatsoever
(including, without limitation, damages to your hardware or equipment,
environmental damage, loss of health, or any kind of pecuniary loss)
arising out of the use of or inability to use this software or
documentation, even if the author has been advised of the possibility of
such damages.
You should have received a copy of the Free McBoot License along with
this program; if not, please report at psx-scene :
http://psx-scene.com/forums/freevast/
---------------------------------------------------------------------------
build_osd.c
*/
#include <tamtypes.h>
#include <kernel.h>
#include <stdio.h>
#include <string.h>
//#include <sysclib.h>
int build_OSD(u8 *original_dvdelf, u8 *injected_dvdelf, u8 *hacked_dvdelf);
// Encrypted file Data Block struct
typedef struct {
u32 size; // Size of data block
u32 flags; // Flags : 3 -> block to decrypt, 0 -> block to take in input file, 2 -> block to prepare.
u8 checksum[8];
} Block_Data_t;
// Encrypted file bit table struct
typedef struct {
u32 headersize; // header size (same as mg_ELF_Header_t->mg_header_size)
u8 block_count; // Number of encrypted blocks
u8 pad1;
u8 pad2;
u8 pad3;
Block_Data_t blocks[63]; // Block description, see Block_Data_t
} Bit_Data_t;
// Encrypted file header struct
typedef struct {
u32 unknown1;
u32 unknown2;
u16 unknown3_half;
u16 version;
u32 unknown4;
u32 ELF_size; // Size of data blocks = Decrypted elf size
u16 mg_header_size; // header size
u16 unknown5;
u16 flags; // ? for header purpose
u16 BIT_count; // ?
u32 mg_zones;
} mg_ELF_Header_t;
int build_OSD(u8 *original_dvdelf, u8 *injected_dvdelf, u8 *hacked_dvdelf)
{
int i;
u32 offset;
Bit_Data_t *b;
b = (Bit_Data_t *) (injected_dvdelf + 32 + 8 + 32); // bit offset
printf("Merge: Replacing unencrypted blocks... ");
offset = b->headersize;
for (i = 0; i < b->block_count; i++) {
if ((b->blocks[i].flags & 2) == 0)
memcpy(original_dvdelf + offset, injected_dvdelf + offset, b->blocks[i].size);
offset += b->blocks[i].size;
}
printf("done.\n");
memcpy(hacked_dvdelf, original_dvdelf, ((mg_ELF_Header_t *)original_dvdelf)->ELF_size + ((mg_ELF_Header_t *)original_dvdelf)->mg_header_size);
return 1;
}