Exemplo n.º 1
0
int ERFFile::readHeader(void)
{
	if(!typeIsCorrect()) return errcode = 11;
	if(!versionIsCorrect()) return errcode = 10;
	if(seek(8)) return errcode;
	if(binRead(9, &langcount, &locstrsize, &entrycount, &offlocstr,
			&offkeylist, &offreslist, &buildyear, &buildday, &(desc.stringref)))
		return errcode;
	// Extra format checks with the offsets
	// In MODs, every KeyList is padded with 0x00 at the end so that each
	// KeyList entry could use 32 bytes (instead of 24)
	// DOESN'T APPLY TO HAK! O_o
	// Check?
	if(((offlocstr+locstrsize) != offkeylist)) // || ((offkeylist+entrycount*32) != offreslist))
		return errcode = 24;
	inited.set(0);
	return errcode = 0;
}
Exemplo n.º 2
0
uint8 *GFFFile::getRaw(uint32 n, Struct &sct, uint32 &size)
{
	uint8 *data;

	errcode = 0;
	if(prepareGet(n, sct, NWN_VAR_VOID, offfielddata)) return NULL;
	if(binRead(size)) return NULL;
	if(!(data = (uint8 *) malloc(size)))
	{
		errcode = 4;
		return NULL;
	}
	if(rawRead((char *)data, size))
	{
		free(data);
		return NULL;
	}
	return data;
}
void decompressFile(FILE* outFp, FILE* inpFp)
{
    LZ4_streamDecode_t lz4StreamDecode_body;
    LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body;

    char decBuf[2][BLOCK_BYTES];
    int  decBufIndex = 0;

    LZ4_setStreamDecode(lz4StreamDecode, NULL, 0);

    while(1)
    {
        char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)];
        int  cmpBytes = 0;

        {
            const size_t readCount0 = intRead(inpFp, &cmpBytes);
            if((readCount0 != 1) || (cmpBytes <= 0))
            {
                break;
            }
            const size_t readCount1 = binRead(inpFp, cmpBuf, (size_t) cmpBytes);
            if(readCount1 != (size_t) cmpBytes)
            {
                break;
            }
        }
        {
            char* const decPtr = decBuf[decBufIndex];
            const int decBytes = LZ4_decompress_safe_continue(lz4StreamDecode, cmpBuf, decPtr, cmpBytes, BLOCK_BYTES);
            if(decBytes <= 0)
            {
                break;
            }
            binWrite(outFp, decPtr, (size_t) decBytes);
        }
        decBufIndex = (decBufIndex + 1) % 2;
    }
}
int main(int argc, char *argv[]) {
	//Check for binary file argument
	if(argc != 2) {
		printf("No binary file provided!\n");
		printf("Usage: emulate [binary_file]\n\n");
		exit(EXIT_FAILURE);
	}

	//----------INITIALIZE-------------
	//Initialize arm struct
	ARM arm;

	//memset(arm.memory, 0, MAX_MEMORY_SIZE); //zero array
	for(int i = 0; i < MAX_MEMORY_SIZE; ++i) {
		arm.memory[i] = 0;
	}

	//GPIO
	setGpioAddress(&arm); //setup GPIO address
	arm.pc = 0; //Execute from the beginning

	//memset(arm.registers, 0, NUMBER_OF_REGISTERS);
	for(int i = 0; i < NUMBER_OF_REGISTERS; ++i) {
		arm.registers[i] = 0;
	}

	arm.cpsr = 0;
	//Read the binary file (program) to the memory, starting from pos0
	binRead(arm.memory, argv[1]);
	int ir = 0; //INSTRUCTION REGISTER

	//-------FETCH-EXECUTE CYCLE-------
	do {
		//FETCH
		ir = arm.memory[arm.pc]; //Fetch the current instruction
		++arm.pc; //Increment pc counter
		//DECODE
		int cond = checkCond(&ir, &arm);

		if(cond) {
			//Determine type
			switch(getType(&ir)) {
				case DATA_PROCESSING:
					dataprocessing(&ir, &arm);
					break;

				case BRANCH:
					branch(&ir, &arm);
					break;

				case MULTIPLY:
					multiply(&ir, &arm);
					break;

				case SINGLE_DATA_TRANSFER:
					single_data_transfer(&ir, &arm);
					break;
			}
		}
	} while (ir != 0);

	//---------CLEAR GPIO VIRTUAL MEMORY-------
	clearGpioAddress(&arm);
	//---------PRINT ARM STATUS-------
	printARM(&arm);
	return EXIT_SUCCESS;
}