void eid_unpack(s8 *file) { u32 i, length; u8 *eid = _read_buffer(file, &length); if(eid != NULL) { eid_header_t *h = (eid_header_t *)eid; //Fix header. _es_eid_header(h); eid_entry_t *e = (eid_entry_t *)(eid + sizeof(eid_header_t)); for(i = 0; i < h->entcnt; i++, e++) { //Fix entry. _es_eid_entry(e); s8 fname[128]; sprintf(fname, "%s%d", file, (u32)e->entnum); printf("writing entry @ offset 0x%08x (0x%08x bytes) to %s\n", e->offset, e->size, fname); _write_buffer(fname, eid + e->offset, e->size); } free(eid); } else printf("error: could not read %s\n", file); }
void eid4_decrypt(s8 *file_in, s8 *file_out) { u32 length; u8 *eid4 = _read_buffer(file_in, &length); if(eid4 != NULL) { eid4_decrypt_buffer(eid4); _write_buffer(file_out, eid4, EID4_SIZE); free(eid4); } }
void eid3_decrypt(s8 *file_in, s8 *file_out) { u32 length; u8 *eid3 = _read_buffer(file_in, &length); if(eid3 != NULL) { eid3_decrypt_buffer(eid3); _write_buffer(file_out, eid3, EID3_SIZE); free(eid3); } }
void eid2_generate_block(s8 *file_in, u32 blocktype, s8 *file_out) { u32 length; u8 *eid2 = _read_buffer(file_in, &length); if(eid2 != NULL) { u8 *block = eid2_generate_block_buffer(eid2, blocktype); if(block != NULL) { _write_buffer(file_out, block, EID4_SIZE); free(block); } free(eid2); } }
void eid0_decrypt(s8 *file_in, s8 *file_out) { u32 length; u8 *eid0 = _read_buffer(file_in, &length); if(eid0 != NULL) { u8 section_0[EID0_SECTION_0_SIZE]; eid0_decrypt_section_0(eid0, section_0); s8 fname[128]; sprintf(fname, "%s.section_0", file_out); _write_buffer(fname, section_0, 0xC0); free(eid0); } }
void write_btc(char* path, struct c_img* out_img){ int i, nr_blocks, j, fd, k; struct bits tmp; char *buf; fd = _open_for_write(path); write(fd, &out_img->width, sizeof(int)); write(fd, &out_img->height, sizeof(int)); nr_blocks = out_img->width * out_img->height / (BLOCK_SIZE * BLOCK_SIZE); buf = _alloc(nr_blocks * (2 + BLOCK_SIZE * BLOCK_SIZE / BITS_IN_BYTE)); k = 0; for (i=0; i<nr_blocks; i++){ //write a and b buf[k++] = out_img->blocks[i].a; buf[k++] = out_img->blocks[i].b; //from bytes to bits j = 0; while (j < BLOCK_SIZE * BLOCK_SIZE){ tmp.bit0 = out_img->blocks[i].bitplane[j++]; tmp.bit1 = out_img->blocks[i].bitplane[j++]; tmp.bit2 = out_img->blocks[i].bitplane[j++]; tmp.bit3 = out_img->blocks[i].bitplane[j++]; tmp.bit4 = out_img->blocks[i].bitplane[j++]; tmp.bit5 = out_img->blocks[i].bitplane[j++]; tmp.bit6 = out_img->blocks[i].bitplane[j++]; tmp.bit7 = out_img->blocks[i].bitplane[j++]; buf[k++] = *((char*)&tmp); } //write bitplane } _write_buffer(fd, buf, nr_blocks * (2 + BLOCK_SIZE * BLOCK_SIZE / BITS_IN_BYTE)); free_align(buf); close(fd); }
void OnException(int signo) { if (signo == SIGCHLD) return; MinimalBuffer buffer; int fd = -1; if (crashlog && (signo == SIGSEGV || signo == SIGABRT)) fd = open(crashlog, O_WRONLY | O_CREAT | O_TRUNC, 0644); /* print signal info */ BufferReset(&buffer); BufferAppendUInt64(&buffer, signo, 10); _write_string(fd, "=========================\n"); _write_string(fd, "FCITX " VERSION " -- Get Signal No.: "); _write_buffer(fd, &buffer); _write_string(fd, "\n"); /* print time info */ time_t t = time(NULL); BufferReset(&buffer); BufferAppendUInt64(&buffer, t, 10); _write_string(fd, "Date: try \"date -d @"); _write_buffer(fd, &buffer); _write_string(fd, "\" if you are using GNU date ***\n"); /* print process info */ BufferReset(&buffer); BufferAppendUInt64(&buffer, getpid(), 10); _write_string(fd, "ProcessID: "); _write_buffer(fd, &buffer); _write_string(fd, "\n"); #if defined(ENABLE_BACKTRACE) #define BACKTRACE_SIZE 32 void *array[BACKTRACE_SIZE] = { NULL, }; int size = backtrace(array, BACKTRACE_SIZE); backtrace_symbols_fd(array, size, STDERR_FILENO); if (fd >= 0) backtrace_symbols_fd(array, size, fd); #endif if (fd >= 0) close(fd); switch (signo) { case SIGABRT: case SIGSEGV: case SIGBUS: case SIGILL: case SIGFPE: exit(1); break; default: { if (!instance || !instance->initialized) { exit(1); break; } uint8_t sig = 0; if (signo < 0xff) sig = (uint8_t)(signo & 0xff); write(selfpipe[1], &sig, 1); signal(signo, OnException); } break; } }