diff --git a/test/main.c b/test/main.c index 6617ba4..a8dc956 100644 --- a/test/main.c +++ b/test/main.c @@ -93,16 +93,22 @@ char *loadfile(const char *fname, unsigned int *s) { bool unpackpld(const char *filedata, unsigned int filesize, const char *filename) { + if (filedata == NULL || filesize <= 0) { + return false; + } struct PldHeader h; - if (filedata != NULL && filesize > 0) { - getpldh(&h, filedata); - } - int size = 0; + getpldh(&h, filedata); + char *fn = NULL; + fn = (char*)malloc(strlen(filename) + 3 + 4); + int size = 0; unsigned int i = 0; for (i = 0; i < h.numOffset; i++) { size = sizeofpldstruct(&h, i, filesize); - printf("%x\n", size); + sprintf(fn, "%s_%d", filename, i); + write(fn, filedata + h.offsets[i], size); } + free(fn); + return true; } void write(const char *filename,