- Joined
- Sep 10, 2007
- Messages
- 970
- Reaction score
- 815
Alright so, I'm currently working on an open-source MRS class. I started on it last night and I'm now up to reading the file + extracting it. I still need to add checking to see if the archive is a ZIP, MRS, or encrypted. I'll be adding a little method for you to place your won encryption for the MRS files, and soon I'll be moving Gunz to 7z as ColdFX keeps bitching at me to do.
Example of ZMRS.cpp:
A lot of thanks to T6 for helping me out, lol. Also, Buga and Coldfx don't come bitching about me not freeing the memory. I was having slight issues with using free(); Like in readData(); I did:
and I get a heap error. Was annoying so I just left it.
Example of ZMRS.cpp:
Code:
#include "Stdafx.h"
#include "ZMRS.h"
ZMRS::ZMRS(char *szFile)
{
FHeaderTemp = new FileHeader( );
EndOfDir = new EndOfDirectory( );
MRS *zMRS = new MRS( );
FileHandle = CreateFileA ( szFile, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0 );
if ( FileHandle == INVALID_HANDLE_VALUE ) return;
SetFilePointer ( FileHandle, -22, NULL, FILE_END );
Temp = (unsigned char *)malloc(26);
if(readData (Temp,26))
{
memcpy ( EndOfDir,Temp,26);
if ( EndOfDir->Signature == 0x5030208 )
{
SetFilePointer(FileHandle,(EndOfDir->SizeOfDirectory + EndOfDir->ZipFileCommentLen + 22) * -1,NULL,FILE_END);
FileCount = EndOfDir->NumOfFiles;
for ( int i = 0; i < FileCount; i++)
{
if (!readData(FHeaderTemp,46))
return;
strcpy ( FHeaderTemp->FileName , getString ( FHeaderTemp->FileNameLen ));
FHeaderTemp->FileName[FHeaderTemp->FileNameLen] = 0;
strcpy(zMRS->szFile,FHeaderTemp->FileName);
zMRS->dwCRC = FHeaderTemp->CRC332;
zMRS->dwMagic = FHeaderTemp->RelativeOffset;
MRSFiles.push_back(zMRS);
zMRS = new MRS( );
FHeaderTemp = new FileHeader( );
}
}
}
}
ZMRS::~ZMRS(void)
{
}
void ZMRS::decryptData ( BYTE *pBuffer, int iLen)
{
for ( ; iLen >= 0; iLen--, pBuffer++ )
*pBuffer = ~static_cast<unsigned char>((*pBuffer>>3)|(*pBuffer<<5));
}
void ZMRS::encryptData ( BYTE *pBuffer, int iLen)
{
for ( ; iLen >= 0; iLen--, pBuffer++ )
*pBuffer = ~static_cast<unsigned char>((*pBuffer>>5)|(*pBuffer<<3));
}
bool ZMRS::readData ( void *pBuffer, int iLen )
{
DWORD dwReadBytes = 0;
if (!ReadFile ( FileHandle, pBuffer, iLen, &dwReadBytes, NULL))
return false;
unsigned char *mall = (unsigned char *)malloc ( dwReadBytes );
memcpy ( mall, pBuffer, dwReadBytes );
decryptData ( mall , dwReadBytes );
memcpy ( pBuffer, mall, dwReadBytes);
return true;
}
char *ZMRS::getString ( int iCount )
{
char *szBuffer = ( char * ) malloc ( iCount );
ZeroMemory ( szBuffer , iCount );
if ( !readData ( szBuffer, iCount ) ) return NULL;
return szBuffer;
}
void ZMRS::printData ( )
{
for each (MRS *mrs in MRSFiles)
{
printf ("File: [%s]. CRC32: [%u]. Relative Offset: [%u]\n",mrs->szFile, mrs->dwCRC, mrs->dwMagic);
}
}
A lot of thanks to T6 for helping me out, lol. Also, Buga and Coldfx don't come bitching about me not freeing the memory. I was having slight issues with using free(); Like in readData(); I did:
Code:
free(&mall);