Attached is a compiled dll/source
Happy Holidays
lzsshook.cpp
Code: Select all
// Zmathue 2011
// Do what ever you like with this code
// Usage, inject this dll into thug2.exe with any dll injector and it will lzss compress your in.txt file for you
/*
I was doing some disassembly work recently and figured I could use some practice, and I remembered how a lzss (specific to thps/neversoft games) compressor is needed to recreate pre's. So I started removing the lzss function from thug2.exe but found that it depended on too many other functions for me to easily remove it so I created this instead. This is SAMPLE code for a dll that can be injected into thug2.exe while running and will compress your files. Files compressed with this have been successfully decompressed with aluigi's unlszz.h(used in prereaper). I would create a pre builder but I do not really have any interest in THPS any more.
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
bool HOOKED = false;
int __stdcall (*lzss)(unsigned char *in, unsigned char *out, int size, int isDebug) = NULL;
extern "C" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ){
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
if(!HOOKED){
FILE *file,*outfile;
unsigned char *buffer,*outbuffer;
char buf[200];
int *address = (int*)0x00401700;
lzss = (int (__stdcall *)(unsigned char *in, unsigned char *out, int size, int isDebug))address;
MessageBox(0,"Press ok to continue","",0);
//Open file
file = fopen("in.txt", "rb");
outfile = fopen("out.txt", "wb");
if (!file){
return false;
}else if (!outfile){
MessageBox(0,"Unable to open file out.txt","",0);
return false;
}
fseek(file, 0, SEEK_END);
unsigned long fileLen= ftell(file);
fseek(file, 0, SEEK_SET);
buffer=(unsigned char*)malloc(fileLen+1);
if (!buffer){
MessageBox(0,"Memory error!","",0);
fclose(file);
return false;
}
fread(buffer, fileLen, 1, file);
outbuffer=(unsigned char*)malloc(fileLen*3); //hope this is large enough, i mean it is a compressor after all
if (!outbuffer){
MessageBox(0,"Memory error!","",0);
fclose(file);
return false;
}
//sprintf(buf,"buffer size: %d",fileLen+1);
//MessageBox(0,buf,"",0);
int size = lzss(buffer, outbuffer, fileLen+1, 1);
fwrite (outbuffer, 1, size, outfile);
fclose(file);
fclose(outfile);
free(buffer);
free(outbuffer);
HOOKED = true;
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}