-
Notifications
You must be signed in to change notification settings - Fork 14
/
norunpack.c
78 lines (64 loc) · 1.36 KB
/
norunpack.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
// Copyright 2010 Sven Peter <[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 *nor = 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);
if (strncmp(name, "asecure_loader", 0x20) == 0) {
new_dir("asecure_loader");
do_toc(ptr + be64(p));
if (chdir("..") < 0)
fail("chdir(..)");
} else if (strncmp(name, "ros", 3) == 0) {
new_dir(name);
do_toc(ptr + be64(p) + 0x10);
if (chdir("..") < 0)
fail("chdir(..)");
} else {
tmp = ptr + be64(p);
size = be64(p + 0x08);
if (be32(tmp + 0x10) == 0x53434500) {
tmp += 0x10;
size -= 0x10;
}
memcpy_to_file(name, tmp, size);
}
p += 0x30;
}
}
int main(int argc, char *argv[])
{
if (argc != 3)
fail("usage: norunpack dump.b directory");
nor = mmap_file(argv[1]);
new_dir(argv[2]);
do_toc(nor + 0x400);
return 0;
}