Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Rike

a

Recommended Posts

Eae pessoal beleza

Sou novo aqui no forum xD

 

Eu estou com problemas em compilar dados

 

queria saber se alguem pode compilalos para mim

 

Sou iniciante nisso nao intendo nada.

 

#include "xfsconf.h"

xfs::xfs(void)
{
}

xfs::~xfs(void)
{
}

int xfs::decompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen){
	ZlibEngine *c_stream = new ZlibEngine;

	uLongf total_Len = *destLen;
	uLongf currentSize = 0;

	while(currentSize < total_Len){
		*destLen = total_Len;
		sourceLen = (*(uLongf *)source) & 0xFFFFFF;
		source += 5;
		int error = c_stream->decompress(dest + currentSize, destLen, source, sourceLen);
		if (error != Z_OK) {
			*destLen = currentSize;
			break;
		}
		source		+= sourceLen;
		currentSize += *destLen;
	}

	return 1;
}
int xfs::unpack(void){
	FileInfoBlock *myFile = (FileInfoBlock*)this->xfsInfo;
	for (int i=0; i < this->xfsInfoLen / FILE_INFO_LEN; i++){
		int size = (int)strlen(this->OutputDir) + strlen(myFile->header);
		char *fileToCreate = (char *)malloc(size+1);
		strcpy(fileToCreate, this->OutputDir);
		strcat(fileToCreate, "\\");
		strcat(fileToCreate, myFile->header);

		Bytef *pCurrFile	= buff + myFile->position;
		uLongf outputSize	= myFile->unpackedSize;
		uLongf inputSize	= myFile->packedSize;
		uLongf initSize		= (*(uLongf *)pCurrFile) & 0xFFFF;
		if (outputSize == initSize) pCurrFile += 3;
		//if(*(pCurrFile+5) == 0x78) pCurrFile += 0x05;
		//else pCurrFile +=0x08;
		Bytef *out = (Bytef *)malloc(outputSize);
		//if(!strcmp(myFile->header,"dragon.img")){
		//	_asm nop;
		//}
		int error = this->decompress(out, &outputSize, pCurrFile, inputSize);
		FILE *fo = fopen(fileToCreate,"wb");
		fwrite(out, outputSize, 1, fo);
		fclose(fo);

		myFile++;
	}
	return 1;
}
int xfs::unpackInfo(){
	return 1;
}
int xfs::init(Bytef *fbuff, char *outputDir){
	this->OutputDir = outputDir;
	int err = CreateDirectoryA(outputDir, NULL);

	this->buff = fbuff;
	this->pPacketTail	= buff + *((long *)fbuff);
	this->signBlockLen	= *this->pPacketTail;

	this->pPacketInfo	= this->pPacketTail + this->signBlockLen + 1;
	this->xfsInfoLen	= (*(long *)pPacketInfo) & 0x00FFFFFF;
	this->pPacketInfo	+= 3;

	
	ZlibEngine *c_stream = new ZlibEngine;
	unsigned long outLength = this->xfsInfoLen * 100;
	this->xfsInfo = (Bytef *)malloc(outLength);
	c_stream->decompress(this->xfsInfo,&outLength,this->pPacketInfo,this->xfsInfoLen);
	this->xfsInfoLen = outLength;
	return INIT_OK;
}

//
// This file contains the implementation the
// the ZlibEngine class, used to simplify
// compression and decompression of files
// using the Zlib engine.
//
// The ZlibEngine is a Tiny Software (tm) project.
// You may use the code in this project without restriction.
// Contact markn@tiny.com for more information.
//

#if defined( _WINDOWS )
#include <windows.h>
#endif

//
// The constructor initializes a couple of members
// of the z_stream class.  See the Zlib documentation
// for details on what those members do
//

ZlibEngine::ZlibEngine()
{
	zalloc = 0;  //z_stream member
	zfree = 0;   //z_stream member
	opaque = 0;  //z_stream member
//
// I initialize these members just for tidiness.
//
	fin = 0;
	fout = 0;
}

//
// compress() is the public function used to compress
// a single file.  It has to take care of opening the
// input and output files and setting up the buffers for
// Zlib.  It then calls deflate() repeatedly until all
// input and output processing has been done, and finally
// closes the files and cleans up the Zlib structures.
//
int ZlibEngine::compress( const char *input,
						  const char *output,
						  int level )
{
	err = Z_OK;
	avail_in = 0;
	avail_out = output_length;
	next_out = output_buffer;
	m_AbortFlag = 0;

	fin  = fopen( input, "rb" );
	fout = fopen( output, "wb" );

	deflateInit( this, level );
	for (;; ) {
		if ( m_AbortFlag )
			break;
		if ( !load_input() )
			break;
		err = deflate( this, Z_NO_FLUSH );
		flush_output();
		if ( err != Z_OK )
			break;
		progress( percent() );
	}
	for (;; ) {
		if ( m_AbortFlag )
			break;
		err = deflate( this, Z_FINISH );
		if ( !flush_output() )
			break;
		if ( err != Z_OK )
			break;
	}
	progress( percent() );
	deflateEnd( this );
	if ( m_AbortFlag )
		status( "User Abort" );
	else if ( err != Z_OK && err != Z_STREAM_END )
		status( "Zlib Error" );
	else {
		status( "Success" );
		err = Z_OK;
	}
	fclose( fin );
	fclose( fout );
	fin = 0;
	fout = 0;
	if ( m_AbortFlag )
		return Z_USER_ABORT;
	else
		return err;
}

int ZlibEngine::decompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
{
	z_stream stream;
	int err;

	stream.next_in = (Bytef*)source;
	stream.avail_in = (uInt)sourceLen;
	/* Check for source > 64K on 16-bit machine: */
	if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;

	stream.next_out = dest;
	stream.avail_out = (uInt)*destLen;
	if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;

	stream.zalloc = (alloc_func)0;
	stream.zfree = (free_func)0;

	err = inflateInit(&stream);
	if (err != Z_OK) return err;

	err = inflate(&stream, Z_FINISH);
	*destLen = stream.total_out;
	if (err != Z_STREAM_END) {
		inflateEnd(&stream);
		if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
			return Z_DATA_ERROR;
		return err;
	}

	err = inflateEnd(&stream);
	return err;
}

//
// decompress has to do most of the same chores as compress().
// The only major difference it has is the absence of the level
// parameter.  The level isn't needed when decompressing data
// using the deflate algorithm.
//

int ZlibEngine::decompress( const char *input,
							const char *output )
{
	err = Z_OK;
	avail_in = 0;
	avail_out = output_length;
	next_out = output_buffer;
	m_AbortFlag = 0;

	fin  = fopen( input, "rb" );
	fout = fopen( output, "wb" );
	inflateInit( this );
	for (;; ) {
		if ( m_AbortFlag )
			break;
		if ( !load_input() )
			break;
		err = inflate( this, Z_NO_FLUSH );
		flush_output();
		if ( err != Z_OK )
			break;
		progress( percent() );
	}
	for (;; ) {
		if ( m_AbortFlag )
			break;
		err = inflate( this, Z_FINISH );
		if ( !flush_output() )
			break;
		if ( err != Z_OK )
			break;
	}
	progress( percent() );
	inflateEnd( this );
	if ( m_AbortFlag )
		status( "User Abort" );
	else if ( err != Z_OK && err != Z_STREAM_END )
		status( "Zlib Error" );
	else {
		status( "Success" );
		err = Z_OK;
	}
	if ( fin )
		fclose( fin );
	fin = 0;
	if ( fout )
		fclose( fout );
	fout = 0;
	if ( m_AbortFlag )
		return Z_USER_ABORT;
	else
		return err;
}
//
//  This function is called so as to provide the progress()
//  virtual function with a reasonable figure to indicate
//  how much processing has been done.  Note that the length
//  member is initialized when the input file is opened.
//
int ZlibEngine::percent()
{
	if ( length == 0 )
		return 100;
	else if ( length > 10000000L )
		return ( total_in / ( length / 100 ) );
	else
		return ( total_in * 100 / length );
}

//
//  Every time Zlib consumes all of the data in the
//  input buffer, this function gets called to reload.
//  The avail_in member is part of z_stream, and is
//  used to keep track of how much input is available.
//  I churn the Windows message loop to ensure that
//  the process can be aborted by a button press or
//  other Windows event.
//
int ZlibEngine::load_input()
{
#if defined( _WINDOWS )
	MSG msg;
	while ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
		TranslateMessage( &msg );
		DispatchMessage( &msg );
	}
#endif
	if ( avail_in == 0 ) {
		next_in = input_buffer;
		avail_in = fread( input_buffer, 1, input_length, fin );
	}
	return avail_in;
}

//
//  Every time Zlib filsl the output buffer with data,
//  this function gets called.  Its job is to write
//  that data out to the output file, then update
//  the z_stream member avail_out to indicate that more
//  space is now available.  I churn the Windows message
//  loop to ensure that the process can be aborted by a
//  button press or other Windows event.
//

int ZlibEngine::flush_output()
{
#if defined( _WINDOWS )
	MSG msg;
	while ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
		TranslateMessage( &msg );
		DispatchMessage( &msg );
	}
#endif
	unsigned int count = output_length - avail_out;
	if ( count ) {
		if ( fwrite( output_buffer, 1, count, fout ) != count ) {
			err = Z_ERRNO;
			return 0;
		}
		next_out = output_buffer;
		avail_out = output_length;
	}
	return count;
}

#define FILE_INFO_LEN (0x80)
#define INIT_OK 1

Compartilhar este post


Link para o post
Compartilhar em outros sites

No primeiro voce precisa desse arquivo: "xfsconf.h"

 

Se o segundo for esse arquivo é só compilar o primeiro e ter certeza que o .h está no mesmo diretório.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.