Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <direct.h>
- #include <iostream>
- #include <string>
- using namespace std;
- void decode(unsigned char *p, int h)
- {
- for(int a=0;a<h;a++)
- {
- p[a]^=(unsigned char)194;
- p[a]=(p[a]<<4)|(p[a]>>4);
- }
- }
- int main(int argc, char* argv[])
- {
- if (!argv[1])
- {
- printf("Usage: wdfextract <WDFFile>\n");
- return 1;
- //argv[1] = "env.wdf";
- }
- char fname[256];
- FILE *f1, *f2;
- char *p;
- int *fsizes, *startpos;
- int a,b,n,h;
- string dir = ".//";
- dir += argv[1];
- dir.replace(dir.size() - 4,4,"");
- const char* cdir = dir.c_str();
- mkdir(cdir);
- chdir(cdir);
- string file = "..//";
- file += argv[1];
- const char* cfile = file.c_str();
- f1=fopen(cfile, "rb");
- fseek(f1, 4, SEEK_SET);
- fread(&n, 1, 4, f1); //number of files
- fsizes=new int[n];
- startpos=new int[n];
- fread(&a, 1, 4, f1); //offset of file table
- fseek(f1, a, SEEK_SET);
- h=0;
- for(a=0;a<n;a++)
- {
- fread(&b, 1, 4, f1);
- fread(&startpos[a], 1, 4, f1);
- fread(&fsizes[a], 1, 4, f1);
- fread(&b, 1, 4, f1);
- h+=fsizes[a];
- }
- char *guess[12]={"DAT","dds", "wav", "lnd", "voq", "tga", "bmp", "sp", "jpg", "rt", "mp3", "LND"};
- cout << "\n";
- for(a=0;a<n;a++)
- {
- fseek(f1, startpos[a], SEEK_SET);
- fread(&b, 1, 4, f1);
- switch(b)
- {
- case 0x20534444: b=1; break; //DDS
- case 0x46464952: b=2; break; //WAVE
- case 0xd736a713: b=4; break; //voq
- case 0x00020000: b=5; break; //tga
- case 0x65636152: b=9; break; //
- case 0xe0ffd8ff: b=8; break; //
- default:
- if((b&0xffff)==0x4d42)b=6;
- else if((b&0xffff)==0x5053)b=7;
- else if((b&0xffff)==0x4449)b=10;
- else if((b&0xffff)==0xfbff)b=10;
- else if((b&0xff)==2)b=3;
- else if((b&0xff)==1)b=11; //sometimes its lnd, sometimes its not...
- else
- {
- b=0;
- //printf("unknown type %d %c\n", (int)ch, ch);
- }
- };
- sprintf(fname, "F%d.%s", a, guess[b]);
- for (int i=0; i<argc; i++)
- {
- //cout << " " << argv[i];
- if (argv[i] == "-v")
- {
- cout << "Extracting: " << fname << "\n";
- }
- else
- {
- cout << "Arg:" << argv[i] << "\n";
- }
- }
- f2=fopen(fname, "w+b");
- p=new char[fsizes[a]];
- fseek(f1, startpos[a], SEEK_SET);
- fread(p, 1, fsizes[a], f1);
- if(b==4)decode((unsigned char*)p, fsizes[a]);
- fwrite(p, 1, fsizes[a], f2);
- delete[] p;
- fclose(f2);
- }
- fclose(f1);
- delete[] fsizes;
- delete[] startpos;
- printf("%d files\n%d bytes\n", n, h);
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment