forked from daryl317/fail0verflow-PS3-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cosunpack.c
64 lines (49 loc) · 1.02 KB
/
cosunpack.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
// Copyright 2010 Sven Peter <[email protected]>
// Copyright 2011 glevand <[email protected]>
// Licensed under the terms of the GNU GPL, version 2
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include "tools.h"
#ifdef WIN32
#define MKDIR(x,y) mkdir(x);
#else
#define MKDIR(x,y) mkdir(x,y)
#endif
static u8 *cos = NULL;
static void new_dir(const char *n)
{
MKDIR(n, 0777);
if (chdir(n) < 0)
fail("chdir");
}
static void do_toc(u8 *ptr)
{
u32 n_entries;
u32 i;
u8 *p;
u8 *tmp;
u64 size;
char name[0x20];
n_entries = be32(ptr + 0x04);
p = ptr + 0x10;
for(i = 0; i < n_entries; i++) {
memcpy(name, p + 16, 0x20);
tmp = ptr + be64(p);
size = be64(p + 0x08);
memcpy_to_file(name, tmp, size);
p += 0x30;
}
}
int main(int argc, char *argv[])
{
if (argc != 3)
fail("usage: cosunpack dump.b directory");
cos = mmap_file(argv[1]);
new_dir(argv[2]);
do_toc(cos);
return 0;
}