Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: TheNewOne on May 13, 2004, 09:35 AM

Title: Extracting Data From Mpq
Post by: TheNewOne on May 13, 2004, 09:35 AM
is there any documents on how someone would go about doing this? All links and support are appreciated.

Edit: Extracting Data From Mpq is what i ment for documents on it.
Title: Re:Extracting Data From Mpq
Post by: Eric on May 13, 2004, 10:25 AM
This can be done by using Storm.dll's API calls.

QuoteStorm_252 - int SFileCloseArchive(HANDLE hArchive);
Storm_253 - int SFileCloseFile(HANDLE hFile);
Storm_262 - int SFileDestroy();
Storm_265 - int SFileGetFileSize(HANDLE hFile, int * fileSizeHigh);
Storm_266 - int SFileOpenArchive(char * name, int flags, int, HANDLE * hArchive);
Storm_268 - int SFileOpenFileEx(HANDLE hArchive, char * fileName, int, HANDLE * hFile);
Storm_269 - int SFileReadFile(HANDLE hFile, void * buffer, int toRead, int * read, int);
Storm_271 - int SFileSetFilePointer(HANDLE hFile, int filePos, int * filePosHigh, int method);

Storm_465 - int setLastError(DWORD dwErrCode)

Storm_491 - int memcpy(void *src, void *dst, int count)
Storm_494 - int ZeroMemory(void *buf, int count)

Storm_501 - int memcpy(char *dst, char *src, int count)
Storm_506 - int strlen(char *string)
Storm_510 - int _strupr(char *)
Storm_579 - int _strlwr(char *)
Title: Re:Extracting Data From Mpq
Post by: Eibro on May 13, 2004, 04:37 PM
Quote from: LoRd[nK] on May 13, 2004, 10:25 AM
This can be done by using Storm.dll's API calls.

QuoteStorm_252 - int SFileCloseArchive(HANDLE hArchive);
Storm_253 - int SFileCloseFile(HANDLE hFile);
Storm_262 - int SFileDestroy();
Storm_265 - int SFileGetFileSize(HANDLE hFile, int * fileSizeHigh);
Storm_266 - int SFileOpenArchive(char * name, int flags, int, HANDLE * hArchive);
Storm_268 - int SFileOpenFileEx(HANDLE hArchive, char * fileName, int, HANDLE * hFile);
Storm_269 - int SFileReadFile(HANDLE hFile, void * buffer, int toRead, int * read, int);
Storm_271 - int SFileSetFilePointer(HANDLE hFile, int filePos, int * filePosHigh, int method);

Storm_465 - int setLastError(DWORD dwErrCode)

Storm_491 - int memcpy(void *src, void *dst, int count)
Storm_494 - int ZeroMemory(void *buf, int count)

Storm_501 - int memcpy(char *dst, char *src, int count)
Storm_506 - int strlen(char *string)
Storm_510 - int _strupr(char *)
Storm_579 - int _strlwr(char *)
AFAIK, the calling convention of those functions should be __stdcall. Also, the return value of  SFile* functions would be better represented as a BOOL.
Edit: In addition, SSetLastError doesn't return anything.
Title: Re:Extracting Data From Mpq
Post by: Skywing on May 13, 2004, 09:32 PM
Remember that you need to be careful about dynamic linking storm, because it tries to overwrite some of the tables used for mpq decoding if it discovers you using LoadLibrary on it.
Title: Re:Extracting Data From Mpq
Post by: iago on May 14, 2004, 01:26 PM
Yeah, what Skywing said.

Also, many of those are named wrong.

465   SErrSetLastError(DWORD dwErrCode)
491   int SMemCpy(void *src, void *dst, int count)
494   int SMemZero(void *buf, int count)
501   int SStrCpy(char *dst, char *src, int count)
506   int SStrLen(char *str)
510   int SStrUpr(char *str)
579   SStrLwr(char *str)


It's possible I got return values wrong, I didn't double check those.  And I'm not 100% sure about the names of the last two (SStrUpr, SStrLwr), somebody sent me those ones and I didn't doublecheck.
Title: Re:Extracting Data From Mpq
Post by: UserLoser. on May 14, 2004, 03:59 PM
Quote from: Skywing on May 13, 2004, 09:32 PM
Remember that you need to be careful about dynamic linking storm, because it tries to overwrite some of the tables used for mpq decoding if it discovers you using LoadLibrary on it.

I load Storm.dll via LoadLibrary on my VB client, and I can extract only some files which seem to be extracted ok, such as prepatch.lst, patch.txt, BNUpdate.exe, ect.. But as far as files such as Starcraft.exe, Storm.dll, and Battle.snp, those don't come out correctly? (or someone said blizzard bytecode or something like that?)
Title: Re:Extracting Data From Mpq
Post by: phvckmeh on May 15, 2004, 06:33 PM
how would u do this in vb6? like to extract a cdkey
Title: Re:Extracting Data From Mpq
Post by: TheNewOne on May 15, 2004, 08:07 PM
Use the info they gave us and convert. If it doesnt work try use other info on the net. Try google.
Title: Re:Extracting Data From Mpq
Post by: UserLoser. on May 15, 2004, 08:11 PM
Quote from: phvckmeh on May 15, 2004, 06:33 PM
how would u do this in vb6? like to extract a cdkey

You wouldn't use any of the functions posted from Storm to extract a CDKey
Title: Re:Extracting Data From Mpq
Post by: Skywing on May 17, 2004, 07:12 PM
Quote from: UserLoser. on May 14, 2004, 03:59 PM
Quote from: Skywing on May 13, 2004, 09:32 PM
Remember that you need to be careful about dynamic linking storm, because it tries to overwrite some of the tables used for mpq decoding if it discovers you using LoadLibrary on it.

I load Storm.dll via LoadLibrary on my VB client, and I can extract only some files which seem to be extracted ok, such as prepatch.lst, patch.txt, BNUpdate.exe, ect.. But as far as files such as Starcraft.exe, Storm.dll, and Battle.snp, those don't come out correctly? (or someone said blizzard bytecode or something like that?)
It's possible that Blizzard removed their protection.  For a long time, Storm.dll would destroy the datatables used for MPQ processing if you tried to LoadLibrary it.  I suppose they don't much care about people reading MPQs anymore though.
Title: Re:Extracting Data From Mpq
Post by: Maddox on May 19, 2004, 08:20 PM
I wouldn't think it would be that hard to dump those tables and reinitialize them afterwards.
Title: Re:Extracting Data From Mpq
Post by: Skywing on May 23, 2004, 10:11 PM
Quote from: Maddox on May 19, 2004, 08:20 PM
I wouldn't think it would be that hard to dump those tables and reinitialize them afterwards.
You could probably do that.  There are easier ways though, that don't require any particular Storm.dll version, such as calling DllMain yourself for DLL_PROCESS_ATTACH again, but with the optional PCONTEXT set appropriately for a static link attach.
Title: Re:Extracting Data From Mpq
Post by: Maddox on May 24, 2004, 05:01 PM
That assumes all initialized data is on the stack (which is probably true).
Title: Re:Extracting Data From Mpq
Post by: Skywing on May 26, 2004, 08:25 PM
Quote from: Maddox on May 24, 2004, 05:01 PM
That assumes all initialized data is on the stack (which is probably true).
No, it doesn't.  It's in Storm's data section, and Storm's DllMain initializes all of the relevant data on DLL_PROCESS_ATTACH.