示例#1
0
bool ShadeDB8_mpp::decompress_file_to_uint8()
{
	size_t status;
	uint8 *pTmp_data;

	size_t mem_size = p_vmpp_uint8_size + p_impp_uint8_size;

	pTmp_data = (uint8 *)malloc(mem_size);

	status = tinfl_decompress_mem_to_mem((void *)pTmp_data, mem_size, pCmp_data, p_compressed_size, TINFL_FLAG_PARSE_ZLIB_HEADER);

	memcpy(p_vmpp, pTmp_data, p_vmpp_uint8_size);
	memcpy(p_impp, pTmp_data + p_vmpp_uint8_size, p_impp_uint8_size);

	free(pTmp_data);

	if (status == TINFL_DECOMPRESS_MEM_TO_MEM_FAILED)
	{
		std::stringstream outm;
		outm << "tinfl_decompress_mem_to_mem() failed with status " << (int)status;
		p_error_msg = outm.str();
		return EXIT_FAILURE;
	}

	return true;
};
示例#2
0
void _startC(register_t a0, register_t a1, register_t a2, register_t a3){
	__asm__ __volatile__(
			"lui	$t0, 0x80ff\n"
			"move 	$sp, $t0\n"
			"ehb");

	uint32_t* ptr = (unsigned int*)FLASHADDR;
	void (*entry_point)(register_t, register_t, register_t, register_t) = (void*)FAIL;

	for(int i = 0; i < 0x200; i++) {//32MB
		if(*ptr != MAGIC){
			ptr += 0x1000; // 0xbc800000 0x1000 / sizeof(uint32_t); //+4 - 0x40000
			continue;
		}
		//found TRX - copy as-is to 0x80001000
		struct trx_header* h = (struct trx_header*)ptr;
		uint32_t* kstart = (uint32_t*)(((char*)ptr) + h->offsets[1]);
		int size = h->offsets[2] - h->offsets[1];
		uint32_t* dst = (uint32_t*)TARGETADDR;

		entry_point = (void*)TARGETADDR;
		size_t res = tinfl_decompress_mem_to_mem((uint32_t*)TARGETADDR, 0x700000, kstart, size, TINFL_FLAG_PARSE_GZIP_HEADER);

		if(res > 0x900000){
			entry_point = (void*)FAIL3;
			entry_point(res,a1,a2,a3);
		}

		entry_point(a0,a1,a2,a3);
	}
	entry_point(a0,a1,a2,a3);
}
示例#3
0
void us_uncompress_resource_data(const unsigned char* data, size_t size,
                                 unsigned char* uncompressedData, size_t uncompressedSize)
{
  size_t bytesWritten = 0;

  memset(us_uncompress_error_msg, 0, sizeof(us_uncompress_error_msg));

  if (data == NULL)
  {
    return;
  }

  if (uncompressedData == NULL)
  {
    sprintf(us_uncompress_error_msg, "us_uncompress_resource_data: Buffer for uncomcpressing data is NULL");
    return;
  }

  bytesWritten = tinfl_decompress_mem_to_mem(uncompressedData, uncompressedSize,
                                             data, size,
                                             TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
  if (bytesWritten != uncompressedSize)
  {
    sprintf(us_uncompress_error_msg, "us_uncompress_resource_data: tinfl_decompress_mem_to_mem failed");
  }
}
示例#4
0
bool ZipFileReader::ReadFileToString(ZipFile *zip, const char *filename, std::string *result) {
  ZipFileName *zn;
  for(size_t i=0;;i++) {
    if (i == zip->list.size()) goto error;
    zn = &zip->list[i];
    if (stricmp(zn->name.c_str(), filename) == 0) break;
  }
  if ( (zn->compress_size|zn->decompress_size) >= 64*1024*1024) goto error;
  {
    result->resize(zn->compress_size);
    if (zip->file_io->Read(zn->file_offset, &(*result)[0], zn->compress_size) != zn->compress_size) goto error;
    if (zn->method == 8) {
      std::string tmp;
      std::swap(tmp, *result);
      result->resize(zn->decompress_size);
      uint32 destlen = zn->decompress_size;
      size_t r = tinfl_decompress_mem_to_mem(&(*result)[0], destlen, tmp.c_str(), tmp.size(), 0);
      if ((int)r < 0) goto error;
    }
    return true;
  }
error:
  result->clear();
  return false;
}
示例#5
0
// This function loaded a file with a given name from ROM storage.
// The file is loaded into "addr + offset" address.
void rom_load_file(const char* name, char* addr, int offset) {
    struct rom_file_t* file;
    for (file = &rom_files[0]; file->name; ++file) {
        if (strcmp(name, file->name)) continue;
        int const expected_sz = file->end - file->start + 1;
        if (offset == -1)
            offset = file->start;
        if (offset + expected_sz > 0x10000) {
            console_printf("ERROR: Offset %04X + file size %04X is "
                           "greater then 0x10000.", offset, expected_sz);
            return;
        }
        if (file->compressed) {
            if (tinfl_decompress_mem_to_mem(addr + offset, expected_sz,
                                            file->image, file->size, 0)
                == TINFL_DECOMPRESS_MEM_TO_MEM_FAILED) {
                console_printf("ERROR: Unable to decompress the file.\r\n");
                return;
            }
        } else {
            // If the given offset is -1, we load to the file start address.
            memcpy(addr + offset, file->image, expected_sz);
        }
        console_printf("File is successfully loaded at %04X-%04X.\r\n",
                       offset, offset + expected_sz - 1);
        return;
    }
    console_printf("ERROR: File not found.\r\n");
}