Paste: main.cpp

Author: su
Mode: c
Date: Mon, 27 Aug 2012 17:37:56
Plain Text |
#include <stdio.h>
#include "gff.h"

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

__int64 GetFileSize(FILE *fp)
{
	fpos_t size = 0;
	fseek(fp, 0, SEEK_END);
	fgetpos(fp, &size);
	fseek(fp, 0, SEEK_SET);
	return size;
}

int main()
{
	__int64 size = 0;

	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

	FILE *FILE_gff = fopen("C:\\m0_bandit01.dlg", "rb");

	if(FILE_gff == NULL)
	{
		printf("Error: Error opening gff\r\n");
		return -1;
	}

	size = GetFileSize(FILE_gff);

	printf("FileSize\t%ld bytes\r\n\r\n", size);

	unsigned char *MEMORY_gff = (unsigned char *)malloc(size);

	if(MEMORY_gff == NULL)
	{
		printf("Error: Error allocating memory\r\n");
		fclose(FILE_gff);
		return -1;
	}

	if(fread(MEMORY_gff, sizeof(unsigned char), size, FILE_gff) == NULL)
	{
		printf("Error: Error copying gff to memory\r\n");
		fclose(FILE_gff);
		free(MEMORY_gff);
		return -1;
	}else{
		fclose(FILE_gff);
	}

	GFF_File *test = (GFF_File *)MEMORY_gff;
	test->Struct = (Struct *)(MEMORY_gff + 0x38);

	printf("0x%08lx\tFileType\t%.4s\r\n", &test->FileType, test->FileType);
	printf("0x%08lx\tFileVersion\t%.4s\r\n", &test->FileVersion, test->FileVersion);
	printf("0x%08lx\tStructOffset\t0x%08lx(%lu)\r\n", &test->StructOffset, test->StructOffset, test->StructOffset);
	printf("0x%08lx\tStructCount\t0x%08lx(%lu)\r\n", &test->StructCount, test->StructCount, test->StructCount);
	printf("0x%08lx\tFieldOffset\t0x%08lx(%lu)\r\n", &test->FieldOffset, test->FieldOffset, test->FieldOffset);
	printf("0x%08lx\tFieldCount\t0x%08lx(%lu)\r\n", &test->FieldCount, test->FieldCount, test->FieldCount);
	printf("0x%08lx\tLabelOffset\t0x%08lx(%lu)\r\n", &test->LabelOffset, test->LabelOffset, test->LabelOffset);
	printf("0x%08lx\tLabelCount\t0x%08lx(%lu)\r\n", &test->LabelCount, test->LabelCount, test->LabelCount);
	printf("0x%08lx\tFieldDataOffset\t0x%08lx(%lu)\r\n", &test->FieldDataOffset, test->FieldDataOffset, test->FieldDataOffset);
	printf("0x%08lx\tFieldDataCount\t0x%08lx(%lu)\r\n", &test->FieldDataCount, test->FieldDataCount, test->FieldDataCount);
	printf("0x%08lx\tFieldIndicesOffset\t0x%08lx(%lu)\r\n", &test->FieldIndicesOffset, test->FieldIndicesOffset, test->FieldIndicesOffset);
	printf("0x%08lx\tFieldIndicesCount\t0x%08lx(%lu)\r\n", &test->FieldIndicesCount, test->FieldIndicesCount, test->FieldIndicesCount);
	printf("0x%08lx\tListIndicesOffset\t0x%08lx(%lu)\r\n", &test->ListIndicesOffset, test->ListIndicesOffset, test->ListIndicesOffset);
	printf("0x%08lx\tListIndicesCount\t0x%08lx(%lu)\r\n", &test->ListIndicesCount, test->ListIndicesCount, test->ListIndicesCount);

	for(int i = 0; i < test->StructCount; i++)
	{
		printf("0x%08lx\tStruct[%d]->Type\t0x%08lx(%lu)\r\n", &test->Struct[i].Type, i, test->Struct[i].Type, test->Struct[i].Type);
		printf("0x%08lx\tStruct[%d]->DataOrDataOffset\t0x%08lx(%lu)\r\n", &test->Struct[i].DataOrDataOffset, i, test->Struct[i].DataOrDataOffset, test->Struct[i].DataOrDataOffset);
		printf("0x%08lx\tStruct[%d]->FieldCount\t0x%08lx(%lu)\r\n", &test->Struct[i].FieldCount, i, test->Struct[i].FieldCount, test->Struct[i].FieldCount);
	}

	free(MEMORY_gff);
	return 0;
}

New Annotation

Summary:
Author:
Mode:
Body: