This software and its source code (if available) are licensed under the Apache-2.0 license (unless otherwise specified) which DOES NOT APPLY to any third-party code (such as zlib for example) and borrowed Assembler code (ripped code from other software executable files).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#pragma pack(push, 1)
typedef struct {
uint32_t magic; /* "BPK "*/
uint32_t build; /* 0x00010001 */
uint32_t utime; /* archive Unix time (last modification?..) */
uint32_t zero; /* always 0?.. */
uint32_t count;
} bpk_head; /* sizeof() == 20 */
typedef struct {
char name[108];
uint32_t offs;
uint32_t size1;
uint32_t flag; /* bit 2 (0x04) is set when file encrypted */
uint32_t size2; /* always same as size1?.. */
uint32_t CRC32; /* checksum must be calculated BEFORE decrypt! */
} bpk_item; /* sizeof() == 128 */
#pragma pack(pop)
void makedirs(char *path) {
char *s;
if (path) {
for (s = path; *s; s++) {
if ((*s == '\\') || (*s == '/')) {
*s = 0;
mkdir(path);
*s = '\\';
}
}
}
}
void dumpdata(char *name, void *data, uint32_t size) {
FILE *f;
if (name) {
f = fopen(name, "wb");
if (f) {
if (data && size) {
fwrite(data, size, 1, f);
}
fclose(f);
}
}
}
void readdata(FILE *fl, void *data, uint32_t size) {
if (data && size) {
memset(data, 0, size);
if (fl) {
fread(data, size, 1, fl);
}
}
}
void bpk_decrypt(uint8_t *p, uint32_t l, uint32_t k) {
while (l--) {
k = (214013 * k) + 2531011;
*p ^= k >> 16;
p++;
}
}
int main(int argc, char *argv[]) {
bpk_head head;
bpk_item *list;
uint32_t i, sz;
uint8_t *p;
FILE *fl;
printf("No one knows about sex .BPK extractor v1.0\n(c) CTPAX-X Team 2025\nhttp://www.CTPAX-X.org/\n\n");
if (argc != 2) {
printf("Usage: unbpkvfs <filename.bpk>\n\n");
return(1);
}
fl = fopen(argv[1], "rb");
if (!fl) {
printf("Error: can't open input file.\n\n");
return(2);
}
fseek(fl, 0, SEEK_END);
sz = ftell(fl);
fseek(fl, 0, SEEK_SET);
readdata(fl, &head, sizeof(head));
if ((head.magic != 0x204B5042) || (head.build != 0x00010001) || (!head.count)) {
fclose(fl);
printf("Error: invalid input file format.\n\n");
return(3);
}
i = head.count * sizeof(list[0]);
list = (bpk_item *) malloc(i);
if (!list) {
fclose(fl);
printf("Error: not enough memory for contents table.\n\n");
return(4);
}
readdata(fl, list, i);
bpk_decrypt((uint8_t *) list, i, head.count);
for (i = 0; i < head.count; i++) {
/*printf("%08X %08X %08X %08X %u %s\n", list[i].offs, list[i].size1, list[i].size2, list[i].data, list[i].flag, list[i].name);*/
printf("%s\n", list[i].name);
p = (uint8_t *) malloc(list[i].size1);
if (p) {
fseek(fl, list[i].offs, SEEK_SET);
readdata(fl, p, list[i].size1);
/* decrypt if needed */
if (list[i].flag & 4) {
bpk_decrypt(p, list[i].size1, list[i].offs);
}
makedirs(list[i].name);
dumpdata(list[i].name, p, list[i].size1);
free(p);
}
}
free(list);
fclose(fl);
printf("\ndone\n\n");
return(0);
}