Hiho!
Now i will try to explain you how the MoleBox packer works in Pokemon Online client.
Only what you need is Tibia 8.10 (for comparisions), PO client and OllyDbg.
Let's take a look how Tibia and PO are getting handle to a file:
Now you can see that Tibia is using original CreateFileA API to get a handle instead of PO's unknown function. If you put breakpoint on PO's function, you will notice that it's requesting Tibia.spr same as original Tibia client.
Ok! Now go to 0x597100 address. There are pointers to API's what Tibia uses.
At the first look you can notice that packer changed pointers to some API's like:
CreateFileA, ReadFile
What's our goal? Write a simple program that will use changed API's and write original file.
Code:
#include <windows.h>
#include <stdio.h>
#include <process.h>
#define DEFAULT_BUF_LEN 40000000
// 40mb~
typedef HANDLE (__stdcall *_CREATEFILE) (LPCTSTR lpFileName,DWORD dwDesiredAccess,DWORD dwShareMode,LPSECURITY_ATTRIBUTES lpSecurityAttributes,DWORD dwCreationDisposition,DWORD dwFlagsAndAttributes,HANDLE hTemplateFile);
_CREATEFILE MBCreateFile = (_CREATEFILE)(*(DWORD*)0x597100);
typedef BOOL (__stdcall *_READFILE)(HANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped);
_READFILE MBReadFile = (_READFILE)(*(DWORD*)0x5970E8);
void ThreadProc(void *param)
{
DWORD bytesRead;
DWORD bytesWritten;
char *buffer = new char[DEFAULT_BUF_LEN]; //40mb~
HANDLE h = MBCreateFile("Tibia.spr", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
MBReadFile(h, buffer, DEFAULT_BUF_LEN, &bytesRead, NULL);
//
HANDLE p = CreateFile("Tibia2.spr", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(p, buffer, bytesRead, &bytesWritten, NULL);
CloseHandle(p);
delete[] buffer;
}
extern "C" BOOL APIENTRY DllMain (HINSTANCE hInst,
DWORD reason,
LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
{
_beginthread(ThreadProc, 0, NULL);
}
break;
}
return TRUE;
}
Next step is inject DLL to tibia and wait some seconds for Tibia2.spr in PO's directory.
In this tutorial i missed checking for compressed file size (buffer allocation).
If you want to get PIC for example.. You need to change "Tibia.spr" and "Tibia2.spr" strings (it won't work with exe).
Src&Bin attached.