예제 #1
0
static int StateCompressAcb(struct BurnArea *pba)
{
	// Set the data as the next available input
	Zstr.next_in=(unsigned char *)pba->Data;
	Zstr.avail_in=pba->nLen;
	CompGo(0); // Compress this Area
	Zstr.avail_in=0;
	Zstr.next_in=NULL;
	return 0;
}
예제 #2
0
// Compress a state using deflate
int StateCompress(unsigned char **pDef,int *pnDefLen,int bAll)
{
	int nRet=0;
	void *NewMem=NULL;
	memset(&Zstr,0,sizeof(Zstr));

	Comp=NULL;
	nCompLen=0;
	nCompFill=0; // Begin with a zero-length buffer
	nRet=CompEnlarge(8*1024);
	if (nRet!=0)
	{
		return 1;
	}

	nRet=deflateInit(&Zstr,Z_DEFAULT_COMPRESSION);
	BurnAcb=StateCompressAcb; // callback our function with each area
	BurnAreaScan(8|1,NULL);  // scan nvram,        read (from driver -> compress)
	if (bAll)
	{
		BurnAreaScan(4|1,NULL);    // scan volatile ram, read (from driver -> compress)
	}

	// Finish off
	CompGo(1);

	nRet=deflateEnd(&Zstr);

	// Size down
	NewMem=realloc(Comp,nCompFill);
	if (NewMem!=NULL)
	{
		Comp=(unsigned char *)NewMem;
		nCompLen=nCompFill;
	}

	// Return the buffer
	if (pDef    !=NULL)
	{
		*pDef    =Comp;
	}
	if (pnDefLen!=NULL)
	{
		*pnDefLen=nCompFill;
	}
	return 0;
}
예제 #3
0
파일: statec.cpp 프로젝트: ernestd/fbarr
// Compress a state using deflate
int BurnStateCompress(unsigned char** pDef, int* pnDefLen, int bAll)
{
	void* NewMem = NULL;

	memset(&Zstr, 0, sizeof(Zstr));

	Comp = NULL; nCompLen = 0; nCompFill = 0;					// Begin with a zero-length buffer
	if (CompEnlarge(8 * 1024)) {
		return 1;
	}

	deflateInit(&Zstr, Z_DEFAULT_COMPRESSION);

	BurnAcb = StateCompressAcb;									// callback our function with each area

	if (bAll) BurnAreaScan(ACB_FULLSCAN | ACB_READ, NULL);		// scan all ram, read (from driver <- decompress)
	else      BurnAreaScan(ACB_NVRAM    | ACB_READ, NULL);		// scan nvram,   read (from driver <- decompress)

	// Finish off
	CompGo(1);

	deflateEnd(&Zstr);

	// Size down
	NewMem = realloc(Comp, nCompFill);
	if (NewMem) {
		Comp = (unsigned char*)NewMem;
		nCompLen = nCompFill;
	}

	// Return the buffer
	if (pDef) {
		*pDef = Comp;
	}
	if (pnDefLen) {
		*pnDefLen = nCompFill;
	}

	return 0;
}