|
发表于 2010-7-27 20:01:21
|
显示全部楼层
我也发一个解个npk的源码,是一个朋友在几年前给我的,放在硬盘里也没用,希望对大家有用。
npk包是使用zlib压缩,所以要使用这个程序,首先要把zib压缩后的数据截出来,然后用这个程序解压。- #include <cstdlib>
- #include <iostream>
- #include <sys/stat.h>
- #include <sys/types.h>
- //author :bbs.routerclub.com
- //直接用vc或者g++编译即可。
- using namespace std;
- struct NPKHEAD {
- unsigned char magic;
- unsigned char flag;
- unsigned char unknow[0x16];
- int size;
- short lenth_name;
- unsigned char name[];
- };
- int de_npk(FILE *source, char *dir) {
- NPKHEAD Npk;
- memset( (char*)(&Npk), 0, 0x1e);
- char* pathname = (char*)malloc( 256);
- char* fullpath = (char*)malloc( 256);
- while (fread(&Npk, 1, 0x1e, source) != 0) {
- memset(pathname, 0, 256);
- memset(fullpath, 0, 256);
- fread(pathname, 1, Npk.lenth_name, source);
- strcpy(fullpath, dir);
- strcat(fullpath, pathname);
- cout << fullpath << endl;
- if (Npk.flag == 0x41) {
- mkdir(fullpath, 777);
- } else {// if ( Npk.flag == 0x81 )
- FILE* dfile = fopen(fullpath, "wb");
- char* p = (char*)malloc(Npk.size);
- fread(p, 1, Npk.size, source);
- fwrite(p, 1, Npk.size, dfile);
- fclose(dfile);
- free(p);
- }
- }
- free(pathname);
- free(fullpath);
- return 0;
- }
- int main(int argc, char *argv[]) {
- FILE* source = fopen(argv[1], "rb");
- de_npk(source, argv[2]);
- return EXIT_SUCCESS;
- }
复制代码 |
|