int lzss_decode_file(struct lzss *lzss, const char *in_path, const char *out_path) { struct lzss_io io; FILE *infile; FILE *outfile; int stat = -1; infile = fopen(in_path, "rb"); if (infile == NULL) goto exit_now; outfile = fopen(out_path, "wb"); if (outfile == NULL) goto exit_close_infile; io.rd = (lzss_rd_t)fgetc; io.wr = (lzss_wr_t)fputc; io.i = infile; io.o = outfile; stat = lzss_decode(lzss, &io); fclose(outfile); exit_close_infile: fclose(infile); exit_now: return stat; }
void* get_method_entries(char* data, size_t length, method_entry* methods, size_t* count) { method_block_header* pmbh = (method_block_header*)data; char *buffer, *pentry = data + pmbh->header_length; size_t i = (pmbh->header_length - sizeof(method_block_header)) / sizeof(unsigned short); #ifdef unix int fd; #endif // decrypt first if having a key if (pmbh->key) { buffer_transform(pentry, length - pmbh->header_length, pmbh->key); pmbh->key = 0; } // map memory and set execute flag #ifdef unix fd = open("/dev/zero", 0); if (fd == -1) return 0; buffer = mmap(0, BLOCK_MAXSIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0); close(fd); #else buffer = (char*)malloc(BLOCK_MAXSIZE); #endif // unix if (!buffer) return 0; // copy method shell-codes if (pmbh->compress_type == 0x01) { // lzss length = lzss_decode((unsigned char*)pentry, length - pmbh->header_length, (unsigned char*)buffer, pmbh->data_length); if (length != pmbh->data_length) {} // Decompress Exception! } else memcpy(buffer, pentry, length); // rebuild method entries if (i < *count) *count = i; for(i = 0; i < *count; i++) methods[i] = (method_entry)(buffer + pmbh->offsets[i]); return buffer; }