majia1166
级别: 注册会员
编号: 88214
精华: 0
发帖: 20
威望: 0 点
配偶: 单身
火 花 币: 17112 HHB
注册时间:2008-04-27
最后登陆:2013-12-01
|
bws图片解包
#include "stdafx.h" #include <iostream> using namespace std; typedef unsigned char BYTE; void uncompress(char *pak, char * file);
int _tmain(int argc, _TCHAR* argv[]) { uncompress("C:\\Users\\Administrator\\Desktop\\压缩的数据", "C:\\Users\\Administrator\\Desktop\\face.ttx"); }
bool readbit(BYTE *p, int &pos, int &cur) { static int flag = 8; if(flag == 0) { pos = cur++; flag = 8; } return p[pos] & (1 << (flag---1)); }
void uncompress(char *pak, char * unpak) { FILE *f1 = fopen(pak, "rb"); FILE *f2 = fopen(unpak, "wb");
fseek(f1, 0, SEEK_END); int f1len = ftell(f1); fseek(f1, 0, SEEK_SET); BYTE *f1buf = (BYTE*)malloc(f1len); fread(f1buf, f1len, 1, f1); fclose(f1);
int header = *(int*)(f1buf + 0);//TARC int number = *(int*)(f1buf + 4);//file number int offset = *(int*)(f1buf + 8);//point to filename int unknown = *(int*)(f1buf + 0xc);//unknown int offset1 = *(int*)(f1buf + 0x10);//point to first file (value>>1) int size = *(int*)(f1buf + 0x14);//first filesize int unknown1 = *(int*)(f1buf + 0x18);//fileID??? /* 0x1c uncompress size 0x20 compress size 0x24 compress data ----------------------------------- 解压后TTX图片格式 0x0 TTX0 0x4 总是0? 0x8 13:256色 14:16色 0xc 数据大小 0x10 宽 0x14 高 0x18 未知(缺失的调色板?) 0x1c 调色板大小 0x20 调色板+数据 */
BYTE *p = (BYTE*)(f1buf+0x24);//data BYTE *p1 = (BYTE*)malloc(0x4420);// 0x1c 0x4420 自己改 int controlpos = 0, datapos = 1, epos = 0; while(epos < 0x4420) { if(readbit(p, controlpos, datapos)) p1[epos++] = p[datapos++]; else { int len = 0; if(readbit(p, controlpos, datapos)) { int t1 = (p[datapos] << 8) + p[datapos + 1]; datapos += 2; len = t1 & 7; t1 >>= 3; t1 |= -0x2000; if(len) len += 2; else len = p[datapos++] +1; for(int i = 0; i < len; ++i) { p1[epos] = p1[epos + t1]; ++epos; } } else { len = readbit(p, controlpos, datapos) * 2 + readbit(p, controlpos, datapos) + 2; int tpos = 256 - p[datapos++]; for(int i = 0; i < len; ++i) { p1[epos] = p1[epos - tpos]; ++epos; } } } } fwrite(p1, 0x4420, 1, f2);//大小自己改 fclose(f2); free(p1); free(f1buf); }
|
|
[楼 主]
|
Posted:2011-10-17 12:48| |
顶端
| |