Some code restructuring.
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@137 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
+8
-1
@@ -1,5 +1,12 @@
|
|||||||
unpkg: unpkg.c unpkg.h
|
unpkg: unpkg.c unpkg.h
|
||||||
gcc -W -Wall -g -O0 unpkg.c -o unpkg
|
gcc -W -Wall -g -O0 unpkg.c -o unpkg
|
||||||
|
|
||||||
|
parseres: parseres.c parseres.h
|
||||||
|
gcc -W -Wall -g -O0 parseres.c -o parseres
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm unpkg
|
rm unpkg unpkg.tgz parseres.o
|
||||||
|
|
||||||
|
tgz: unpkg.c unpkg.h Makefile parseres.c parseres.h
|
||||||
|
tar -cvzf unpkg.tgz unpkg.c unpkg.h Makefile parseres.c parseres.h
|
||||||
|
|
||||||
|
|||||||
+142
-88
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
|
|
||||||
index_header *readIndex(const uint8 *buf);
|
index_header *readIndex(const uint8 *buf);
|
||||||
|
void printIndex(const index_header *h, const uint8 *buf, FILE *out);
|
||||||
char *get_file_name(const uint8 *buf, const index_header *h,
|
char *get_file_name(const uint8 *buf, const index_header *h,
|
||||||
uint16 file_index);
|
uint16 file_index);
|
||||||
void writeFiles(const index_header *h, const uint8 *data);
|
void writeFiles(const index_header *h, const uint8 *data);
|
||||||
@@ -59,6 +60,7 @@ main(int argc, char *argv[]) {
|
|||||||
close(in);
|
close(in);
|
||||||
|
|
||||||
h = readIndex(buf);
|
h = readIndex(buf);
|
||||||
|
printIndex(h, buf, stderr);
|
||||||
|
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
char *dir = argv[2];
|
char *dir = argv[2];
|
||||||
@@ -86,39 +88,18 @@ readIndex(const uint8 *buf) {
|
|||||||
|
|
||||||
h = malloc(sizeof (index_header));
|
h = malloc(sizeof (index_header));
|
||||||
h->res_flags = MAKE_WORD(buf[0x00], buf[0x01]) ? 1 : 0;
|
h->res_flags = MAKE_WORD(buf[0x00], buf[0x01]) ? 1 : 0;
|
||||||
fprintf(stderr, "0x00000000 File type: %s\n",
|
|
||||||
h->res_flags ? "packaged" : "not packaged");
|
|
||||||
|
|
||||||
h->packmem_list_offs =
|
h->packmem_list_offs =
|
||||||
MAKE_DWORD(buf[0x02], buf[0x03], buf[0x04], buf[0x05]);
|
MAKE_DWORD(buf[0x02], buf[0x03], buf[0x04], buf[0x05]);
|
||||||
fprintf(stderr, "0x00000002 packmem_list_offs: 0x%08x\n",
|
|
||||||
h->packmem_list_offs);
|
|
||||||
|
|
||||||
h->path_list_offs =
|
h->path_list_offs =
|
||||||
MAKE_DWORD(buf[0x06], buf[0x07], buf[0x08], buf[0x09]);
|
MAKE_DWORD(buf[0x06], buf[0x07], buf[0x08], buf[0x09]);
|
||||||
fprintf(stderr, "0x00000006 path_list_offs: 0x%08x\n",
|
|
||||||
h->path_list_offs);
|
|
||||||
|
|
||||||
h->file_list_offs =
|
h->file_list_offs =
|
||||||
MAKE_DWORD(buf[0x0a], buf[0x0b], buf[0x0c], buf[0x0d]);
|
MAKE_DWORD(buf[0x0a], buf[0x0b], buf[0x0c], buf[0x0d]);
|
||||||
fprintf(stderr, "0x0000000a file_list_offs: 0x%08x\n",
|
|
||||||
h->file_list_offs);
|
|
||||||
|
|
||||||
h->num_packages = MAKE_WORD(buf[0x0e], buf[0x0f]);
|
h->num_packages = MAKE_WORD(buf[0x0e], buf[0x0f]);
|
||||||
fprintf(stderr, "0x0000000e Number of packages: %d\n",
|
|
||||||
h->num_packages);
|
|
||||||
|
|
||||||
h->num_types = MAKE_WORD(buf[0x10], buf[0x11]);
|
h->num_types = MAKE_WORD(buf[0x10], buf[0x11]);
|
||||||
fprintf(stderr, "0x00000010 Number of package types: %d\n",
|
|
||||||
h->num_types);
|
|
||||||
|
|
||||||
h->header_len = MAKE_DWORD(buf[0x12], buf[0x13], buf[0x14], buf[0x15]);
|
h->header_len = MAKE_DWORD(buf[0x12], buf[0x13], buf[0x14], buf[0x15]);
|
||||||
fprintf(stderr, "0x00000012 Header length: 0x%08x\n",
|
|
||||||
h->header_len);
|
|
||||||
|
|
||||||
bufptr = buf + 0x16;
|
bufptr = buf + 0x16;
|
||||||
h->package_list = malloc(h->num_packages * sizeof (package_desc));
|
h->package_list = malloc(h->num_packages * sizeof (package_desc));
|
||||||
fprintf(stderr, "0x00000016 package info:\n");
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint32 temp;
|
uint32 temp;
|
||||||
@@ -128,47 +109,30 @@ readIndex(const uint8 *buf) {
|
|||||||
h->package_list[i].num_types = GET_TYPE(temp);
|
h->package_list[i].num_types = GET_TYPE(temp);
|
||||||
h->package_list[i].num_instances = GET_INSTANCE(temp);
|
h->package_list[i].num_instances = GET_INSTANCE(temp);
|
||||||
h->package_list[i].file_index = GET_PACKAGE(temp);
|
h->package_list[i].file_index = GET_PACKAGE(temp);
|
||||||
fprintf(stderr, "0x%08x #%d, %d types, %d instances, "
|
|
||||||
"file index 0x%04x, ", bufptr - buf, i + 1,
|
|
||||||
h->package_list[i].num_types,
|
|
||||||
h->package_list[i].num_instances,
|
|
||||||
h->package_list[i].file_index);
|
|
||||||
bufptr += 4;
|
bufptr += 4;
|
||||||
|
|
||||||
temp = MAKE_DWORD(bufptr[0], bufptr[1], bufptr[2], bufptr[3]);
|
temp = MAKE_DWORD(bufptr[0], bufptr[1], bufptr[2], bufptr[3]);
|
||||||
h->package_list[i].flags = temp >> 24;
|
h->package_list[i].flags = temp >> 24;
|
||||||
h->package_list[i].data_loc = temp & 0x00ffffff;
|
h->package_list[i].data_loc = temp & 0x00ffffff;
|
||||||
|
|
||||||
if (h->package_list[i].flags != 0xff) {
|
|
||||||
fprintf(stderr, "BAD OFFSET!\n");
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "offset 0x%06x\n",
|
|
||||||
h->package_list[i].data_loc);
|
|
||||||
}
|
|
||||||
bufptr += 4;
|
bufptr += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type info:
|
// Type info:
|
||||||
h->type_list = malloc(h->num_types * sizeof (type_desc));
|
h->type_list = malloc(h->num_types * sizeof (type_desc));
|
||||||
fprintf(stderr, "0x%08x type info:\n", bufptr - buf);
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < h->num_types; i++) {
|
for (i = 0; i < h->num_types; i++) {
|
||||||
h->type_list[i].instance_count =
|
h->type_list[i].instance_count =
|
||||||
MAKE_WORD(bufptr[0], bufptr[1]);
|
MAKE_WORD(bufptr[0], bufptr[1]);
|
||||||
fprintf(stderr, "0x%08x #%d, %d instances\n",
|
|
||||||
bufptr - buf, i + 1, h->type_list[i].instance_count);
|
|
||||||
bufptr += 2;
|
bufptr += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((uint32) (bufptr - buf) != h->packmem_list_offs) {
|
if ((uint32) (bufptr - buf) != h->packmem_list_offs) {
|
||||||
fprintf(stderr, "PACKMEM_LIST NOT IMMEDIATELY AFTER TYPE LIST!\n");
|
|
||||||
bufptr = buf + h->packmem_list_offs;
|
bufptr = buf + h->packmem_list_offs;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "0x%08x packmem info:\n", bufptr - buf);
|
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
int num_types, num_instances;
|
int num_types, num_instances;
|
||||||
@@ -178,18 +142,11 @@ readIndex(const uint8 *buf) {
|
|||||||
uint32 next_offset;
|
uint32 next_offset;
|
||||||
if (h->res_flags) {
|
if (h->res_flags) {
|
||||||
// packaged
|
// packaged
|
||||||
char *filename;
|
h->package_list[i].filename = strdup(get_file_name(buf, h,
|
||||||
|
h->package_list[i].file_index));
|
||||||
filename = get_file_name(buf, h,
|
|
||||||
h->package_list[i].file_index);
|
|
||||||
if (filename == NULL)
|
|
||||||
filename = "<UNNAMED>";
|
|
||||||
fprintf(stderr, "0x%08x Package #%d (%s):\n",
|
|
||||||
bufptr - buf, i + 1, filename);
|
|
||||||
} else {
|
} else {
|
||||||
// not packaged
|
// not packaged
|
||||||
fprintf(stderr, "0x%08x Package #%d:\n",
|
h->package_list[i].filename = NULL;
|
||||||
bufptr - buf, i + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
num_types = h->package_list[i].num_types;
|
num_types = h->package_list[i].num_types;
|
||||||
@@ -202,12 +159,6 @@ readIndex(const uint8 *buf) {
|
|||||||
GET_INSTANCE(temp);
|
GET_INSTANCE(temp);
|
||||||
h->package_list[i].type_list[j].num_instances =
|
h->package_list[i].type_list[j].num_instances =
|
||||||
GET_PACKAGE(temp);
|
GET_PACKAGE(temp);
|
||||||
fprintf(stderr, "0x%08x Type #%d: type %d, "
|
|
||||||
"%d instances starting with #%d\n",
|
|
||||||
bufptr - buf, j,
|
|
||||||
h->package_list[i].type_list[j].type,
|
|
||||||
h->package_list[i].type_list[j].num_instances,
|
|
||||||
h->package_list[i].type_list[j].first_instance);
|
|
||||||
bufptr += 4;
|
bufptr += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,44 +170,26 @@ readIndex(const uint8 *buf) {
|
|||||||
int k;
|
int k;
|
||||||
|
|
||||||
num_instances = h->package_list[i].type_list[j].num_instances;
|
num_instances = h->package_list[i].type_list[j].num_instances;
|
||||||
if (h->res_flags) {
|
h->package_list[i].type_list[j].instances =
|
||||||
// packaged
|
malloc(sizeof (packdef_instance) * num_instances);
|
||||||
h->package_list[i].type_list[j].sizes =
|
|
||||||
malloc(sizeof (uint32) * num_instances);
|
|
||||||
h->package_list[i].type_list[j].offsets =
|
|
||||||
malloc(sizeof (uint32) * num_instances);
|
|
||||||
} else {
|
|
||||||
h->package_list[i].type_list[j].sizes = NULL;
|
|
||||||
h->package_list[i].type_list[j].offsets = NULL;
|
|
||||||
}
|
|
||||||
for (k = 0; k < num_instances; k++) {
|
for (k = 0; k < num_instances; k++) {
|
||||||
if (h->res_flags) {
|
if (h->res_flags) {
|
||||||
// packaged
|
// packaged
|
||||||
h->package_list[i].type_list[j].sizes[k] =
|
h->package_list[i].type_list[j].instances[k].size =
|
||||||
4 * MAKE_WORD(bufptr[0], bufptr[1]);
|
4 * MAKE_WORD(bufptr[0], bufptr[1]);
|
||||||
h->package_list[i].type_list[j].offsets[k] =
|
h->package_list[i].type_list[j].instances[k].offset =
|
||||||
next_offset;
|
next_offset;
|
||||||
next_offset +=
|
h->package_list[i].type_list[j].instances[k].
|
||||||
h->package_list[i].type_list[j].sizes[k];
|
filename = NULL;
|
||||||
fprintf(stderr, "0x%08x Instance #%d of "
|
next_offset += h->package_list[i].type_list[j].
|
||||||
"type %d: size %d bytes\n", bufptr - buf,
|
instances[k].size;
|
||||||
k + h->package_list[i].type_list[j].
|
|
||||||
first_instance,
|
|
||||||
h->package_list[i].type_list[j].type,
|
|
||||||
h->package_list[i].type_list[j].sizes[k]);
|
|
||||||
} else {
|
} else {
|
||||||
char *filename;
|
h->package_list[i].type_list[j].instances[k].size = 0;
|
||||||
|
h->package_list[i].type_list[j].instances[k].offset =
|
||||||
filename = get_file_name(buf, h,
|
0;
|
||||||
MAKE_WORD(bufptr[0], bufptr[1]));
|
h->package_list[i].type_list[j].instances[k].
|
||||||
if (filename == NULL)
|
filename = strdup(get_file_name(buf, h,
|
||||||
filename = "<UNNAMED>";
|
MAKE_WORD(bufptr[0], bufptr[1])));
|
||||||
fprintf(stderr, "0x%08x Instance #%d of "
|
|
||||||
"type %d: %s\n", bufptr - buf,
|
|
||||||
k + h->package_list[i].type_list[j].
|
|
||||||
first_instance,
|
|
||||||
h->package_list[i].type_list[j].type,
|
|
||||||
filename);
|
|
||||||
}
|
}
|
||||||
bufptr += 2;
|
bufptr += 2;
|
||||||
} // for k
|
} // for k
|
||||||
@@ -266,6 +199,125 @@ readIndex(const uint8 *buf) {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
printIndex(const index_header *h, const uint8 *buf, FILE *out) {
|
||||||
|
const uint8 *bufptr;
|
||||||
|
|
||||||
|
fprintf(out, "0x00000000 File type: %s\n",
|
||||||
|
h->res_flags ? "packaged" : "not packaged");
|
||||||
|
fprintf(out, "0x00000002 packmem_list_offs: 0x%08x\n",
|
||||||
|
h->packmem_list_offs);
|
||||||
|
fprintf(out, "0x00000006 path_list_offs: 0x%08x\n",
|
||||||
|
h->path_list_offs);
|
||||||
|
fprintf(out, "0x0000000a file_list_offs: 0x%08x\n",
|
||||||
|
h->file_list_offs);
|
||||||
|
fprintf(out, "0x0000000e Number of packages: %d\n",
|
||||||
|
h->num_packages);
|
||||||
|
fprintf(out, "0x00000010 Number of package types: %d\n",
|
||||||
|
h->num_types);
|
||||||
|
fprintf(out, "0x00000012 Header length: 0x%08x\n",
|
||||||
|
h->header_len);
|
||||||
|
|
||||||
|
bufptr = buf + 0x16;
|
||||||
|
fprintf(out, "0x00000016 package info:\n");
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < h->num_packages; i++) {
|
||||||
|
fprintf(out, "0x%08x #%d, %d types, %d instances, "
|
||||||
|
"file index 0x%04x, ", bufptr - buf, i + 1,
|
||||||
|
h->package_list[i].num_types,
|
||||||
|
h->package_list[i].num_instances,
|
||||||
|
h->package_list[i].file_index);
|
||||||
|
bufptr += 4;
|
||||||
|
|
||||||
|
if (h->package_list[i].flags != 0xff) {
|
||||||
|
fprintf(out, "BAD OFFSET!\n");
|
||||||
|
} else {
|
||||||
|
fprintf(out, "offset 0x%06x\n",
|
||||||
|
h->package_list[i].data_loc);
|
||||||
|
}
|
||||||
|
bufptr += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type info:
|
||||||
|
fprintf(out, "0x%08x type info:\n", bufptr - buf);
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < h->num_types; i++) {
|
||||||
|
fprintf(out, "0x%08x #%d, %d instances\n",
|
||||||
|
bufptr - buf, i + 1, h->type_list[i].instance_count);
|
||||||
|
bufptr += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((uint32) (bufptr - buf) != h->packmem_list_offs) {
|
||||||
|
fprintf(out, "PACKMEM_LIST NOT IMMEDIATELY AFTER TYPE LIST!\n");
|
||||||
|
bufptr = buf + h->packmem_list_offs;
|
||||||
|
}
|
||||||
|
fprintf(out, "0x%08x packmem info:\n", bufptr - buf);
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
int num_types, num_instances;
|
||||||
|
|
||||||
|
for (i = 0; i < h->num_packages; i++) {
|
||||||
|
if (h->res_flags) {
|
||||||
|
// packaged
|
||||||
|
fprintf(out, "0x%08x Package #%d (%s):\n",
|
||||||
|
bufptr - buf, i + 1,
|
||||||
|
(h->package_list[i].filename == NULL) ?
|
||||||
|
"<<UNNAMED>>" : h->package_list[i].filename);
|
||||||
|
} else {
|
||||||
|
// not packaged
|
||||||
|
fprintf(out, "0x%08x Package #%d:\n",
|
||||||
|
bufptr - buf, i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
num_types = h->package_list[i].num_types;
|
||||||
|
for (j = 0; j < num_types; j++) {
|
||||||
|
fprintf(out, "0x%08x Type #%d: type %d, "
|
||||||
|
"%d instances starting with #%d\n",
|
||||||
|
bufptr - buf, j,
|
||||||
|
h->package_list[i].type_list[j].type,
|
||||||
|
h->package_list[i].type_list[j].num_instances,
|
||||||
|
h->package_list[i].type_list[j].first_instance);
|
||||||
|
bufptr += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < num_types; j++) {
|
||||||
|
int k;
|
||||||
|
|
||||||
|
num_instances = h->package_list[i].type_list[j].num_instances;
|
||||||
|
for (k = 0; k < num_instances; k++) {
|
||||||
|
if (h->res_flags) {
|
||||||
|
// packaged
|
||||||
|
fprintf(out, "0x%08x Instance #%d of "
|
||||||
|
"type %d: size %d bytes\n", bufptr - buf,
|
||||||
|
k + h->package_list[i].type_list[j].
|
||||||
|
first_instance,
|
||||||
|
h->package_list[i].type_list[j].type,
|
||||||
|
h->package_list[i].type_list[j].instances[k].
|
||||||
|
size);
|
||||||
|
} else {
|
||||||
|
fprintf(out, "0x%08x Instance #%d of "
|
||||||
|
"type %d: %s\n", bufptr - buf,
|
||||||
|
k + h->package_list[i].type_list[j].
|
||||||
|
first_instance,
|
||||||
|
h->package_list[i].type_list[j].type,
|
||||||
|
(h->package_list[i].type_list[j].instances[k].
|
||||||
|
filename == NULL) ? "<<UNNAMED>>" :
|
||||||
|
h->package_list[i].type_list[j].instances[k].
|
||||||
|
filename);
|
||||||
|
}
|
||||||
|
bufptr += 2;
|
||||||
|
} // for k
|
||||||
|
} // for j
|
||||||
|
} // for i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
get_file_name(const uint8 *buf, const index_header *h, uint16 file_index) {
|
get_file_name(const uint8 *buf, const index_header *h, uint16 file_index) {
|
||||||
static char result[MAXPATHLEN];
|
static char result[MAXPATHLEN];
|
||||||
@@ -323,6 +375,7 @@ writeFile(const char *file, const uint8 *data, size_t len) {
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
writeFiles(const index_header *h, const uint8 *data) {
|
writeFiles(const index_header *h, const uint8 *data) {
|
||||||
int i;
|
int i;
|
||||||
@@ -345,8 +398,9 @@ writeFiles(const index_header *h, const uint8 *data) {
|
|||||||
h->package_list[i].type_list[j].type,
|
h->package_list[i].type_list[j].type,
|
||||||
h->package_list[i].type_list[j].first_instance + k);
|
h->package_list[i].type_list[j].first_instance + k);
|
||||||
writeFile(filename,
|
writeFile(filename,
|
||||||
&data[h->package_list[i].type_list[j].offsets[k]],
|
&data[h->package_list[i].type_list[j].instances[k].
|
||||||
h->package_list[i].type_list[j].sizes[k]);
|
offset],
|
||||||
|
h->package_list[i].type_list[j].instances[k].size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -24,12 +24,17 @@ typedef unsigned int uint32;
|
|||||||
((uint32)(i) << TYPE_BITS) | \
|
((uint32)(i) << TYPE_BITS) | \
|
||||||
((uint32)(t)))
|
((uint32)(t)))
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32 size; // only low 18 bits used, multiple of 4
|
||||||
|
uint32 offset;
|
||||||
|
char *filename;
|
||||||
|
} packdef_instance;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8 type;
|
uint8 type;
|
||||||
uint16 first_instance; // only low 13 bits used
|
uint16 first_instance; // only low 13 bits used
|
||||||
uint16 num_instances; // only low 11 bits used
|
uint16 num_instances; // only low 11 bits used
|
||||||
uint32 *sizes; // only low 18 bits used, multiple of 4
|
packdef_instance *instances;
|
||||||
uint32 *offsets;
|
|
||||||
} packtype_desc;
|
} packtype_desc;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -48,6 +53,7 @@ typedef struct {
|
|||||||
uint16 file_index; // only low 11 bits used
|
uint16 file_index; // only low 11 bits used
|
||||||
uint8 flags;
|
uint8 flags;
|
||||||
uint32 data_loc; // only low 24 bits used
|
uint32 data_loc; // only low 24 bits used
|
||||||
|
char *filename;
|
||||||
packtype_desc *type_list;
|
packtype_desc *type_list;
|
||||||
} package_desc;
|
} package_desc;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user