void write_files(const char *base) { char fn[256]; int newsize; newsize = gzip_decompress(file_buffer, installer, size_installer); if(newsize < 0) { pspDebugScreenPrintf("cannot decompress installer %d\n", newsize); return; } strcpy(fn, base); strcat(fn, "installer.prx"); write_file(fn, file_buffer, newsize); newsize = gzip_decompress(file_buffer, Rebootex_prx, size_Rebootex_prx); if(newsize < 0) { pspDebugScreenPrintf("cannot decompress rebootex %d\n", newsize); return; } strcpy(fn, base); strcat(fn, "Rebootex.prx"); write_file(fn, file_buffer, newsize); }
static int do_decompress(struct deflate_decompressor *decompressor, struct file_stream *in, struct file_stream *out) { const u8 *compressed_data = in->mmap_mem; size_t compressed_size = in->mmap_size; void *uncompressed_data = NULL; size_t uncompressed_size; enum decompress_result result; int ret; if (compressed_size < sizeof(u32)) { msg("%"TS": not in gzip format", in->name); ret = -1; goto out; } uncompressed_size = load_u32_gzip(&compressed_data[compressed_size - 4]); uncompressed_data = xmalloc(uncompressed_size); if (uncompressed_data == NULL) { msg("%"TS": file is probably too large to be processed by this " "program", in->name); ret = -1; goto out; } result = gzip_decompress(decompressor, compressed_data, compressed_size, uncompressed_data, uncompressed_size, NULL); if (result == DECOMPRESS_INSUFFICIENT_SPACE) { msg("%"TS": file corrupt or too large to be processed by this " "program", in->name); ret = -1; goto out; } if (result != DECOMPRESS_SUCCESS) { msg("%"TS": file corrupt or not in gzip format", in->name); ret = -1; goto out; } ret = full_write(out, uncompressed_data, uncompressed_size); out: free(uncompressed_data); return ret; }
// TODO: This is the most common automated request, but should integrate this with the client // for all requests. void process_response(http::Response *resp, unsigned *page_count, std::function<void(const MarketOrderSlim &order)> &cb) { if (resp->status.code == 200) { auto decompressed = gzip_decompress((const uint8_t*)resp->body.data(), resp->body.size()); resp->body.clear(); my_read_json(decompressed, page_count, cb); } else { std::stringstream ss; ss << "HTTP " << resp->status.code << " " << resp->status.msg; throw std::runtime_error(ss.str()); } }
int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen) { ssh_buffer dest = NULL; dest = gzip_decompress(session,buf, maxlen); if (dest == NULL) { return -1; } if (buffer_reinit(buf) < 0) { ssh_buffer_free(dest); return -1; } if (buffer_add_data(buf, buffer_get_rest(dest), buffer_get_rest_len(dest)) < 0) { ssh_buffer_free(dest); return -1; } ssh_buffer_free(dest); return 0; }
// Load a Lua "chunk" from a binary resource (for execution). Similar to // luaL_loadbuffer(), but this function knows how to handle (gzip-)decompression. int load_decompressed_buffer(lua_State *L, const char *data, size_t len, const char *name) { char chunkname[PATH_MAX]; // explicitly prefix chunk name with '=', so Lua doesn't tamper with it // (see e.g. http://lua.2524044.n2.nabble.com/Error-reporting-the-chunk-name-td4034634.html) snprintf(chunkname, sizeof(chunkname), "=%s", strip_pwd(name)); // (but strip PWD first) if (!is_gzipped(data)) { // this should be a plain(text) buffer, so we pass it to luaL_loadbuffer() directly return luaL_loadbuffer(L, data, len, chunkname); } // gzipped data, use decompressor before loading it size_t decompressed_size; char *decompressed = gzip_decompress(data, len, &decompressed_size); if (decompressed) { // decompression successful, continue with loading int result = luaL_loadbuffer(L, decompressed, decompressed_size, chunkname); free(decompressed); return result; } return luaL_error(L, "%s(%s): decompression of gzipped resource FAILED", __func__, name); }
static int readSectorCompressed(int sector, void *addr) { int ret; int n_sector; int offset, next_offset; int size; n_sector = sector - g_CISO_cur_idx; // not within sector idx cache? if (g_CISO_cur_idx == -1 || n_sector < 0 || n_sector >= NELEMS(g_CISO_idx_cache)) { ret = readRawData(g_CISO_idx_cache, sizeof(g_CISO_idx_cache), (sector << 2) + sizeof(CISOHeader)); if (ret < 0) { return ret; } g_CISO_cur_idx = sector; n_sector = 0; } offset = (g_CISO_idx_cache[n_sector] & 0x7FFFFFFF) << g_ciso_h.align; // is uncompressed data? if (g_CISO_idx_cache[n_sector] & 0x80000000) { return readRawData(addr, SECTOR_SIZE, offset); } sector++; n_sector = sector - g_CISO_cur_idx; if (g_CISO_cur_idx == -1 || n_sector < 0 || n_sector >= NELEMS(g_CISO_idx_cache)) { ret = readRawData(g_CISO_idx_cache, sizeof(g_CISO_idx_cache), (sector << 2) + sizeof(CISOHeader)); if (ret < 0) { return ret; } g_CISO_cur_idx = sector; n_sector = 0; } next_offset = (g_CISO_idx_cache[n_sector] & 0x7FFFFFFF) << g_ciso_h.align; size = next_offset - offset; if (size <= SECTOR_SIZE) size = SECTOR_SIZE; if (offset < g_ciso_dec_buf_offset || size + offset >= g_ciso_dec_buf_offset + CISO_DEC_BUFFER_SIZE) { ret = readRawData(g_ciso_dec_buf, CISO_DEC_BUFFER_SIZE, offset); if (ret < 0) { g_ciso_dec_buf_offset = 0xFFF00000; return ret; } g_ciso_dec_buf_offset = offset; } ret = gzip_decompress(addr, SECTOR_SIZE, g_ciso_dec_buf + offset - g_ciso_dec_buf_offset, size ); return ret; }