void cop_init_rx_pbic(mapped_memory_pbic_root * mpr, unsigned long newBlockSize, unsigned long rx_size, int rx_bolt) { memory_block_t *mapped_range; int i, rc; mpr->avail_cops = (1 << COP_XML) | (1 << COP_REGX); mpr->PBICtype = COP_PBIC_RX; mpr->crb_cache = malloc(sizeof(struct dec_root) * 15); for (i = 0; i < 15; i++) { //verbose_print("%d: plain %p amper %p\n", i, mpr->crb_cache[i], &(mpr->crb_cache[i])); dec_init(&(mpr->crb_cache[i])); } dec_init(&(mpr->DDE_cache)); dec_init(&(mpr->memory_block_list)); #ifdef REENTRANT_ON sem_init(&(mpr->mnode_root_lock), 0, 1); sem_init(&(mpr->memory_block_lock), 0, 1); #endif errno = 0; mpr->Tree = cop_MMTree_create(newBlockSize); mapped_range = malloc(sizeof(memory_block_t)); if ((rc = posix_memalign((void **)&(mapped_range->base_address), (512 * 1024 * 1024), rx_size))) fprintf(stderr, "posix_memalign failed, %s\n", strerror(rc)); mapped_range->length = rx_size; mpr->bolted = rx_bolt; if (mpr->bolted) mapped_range->flags = COP_MAP_BOLT | COP_MAP_MLOCK; else mapped_range->flags = 0; cop_MMTree_insertmappedblock(mpr->Tree, mapped_range); dec_push(&(mpr->memory_block_list), mapped_range); // initial map and touching of pages to force // creation of the PTEs cop_remap_pool(mpr); }
void cop_init_cc_pbic(mapped_memory_pbic_root * mpr, unsigned long newBlockSize, unsigned long cc_size, int cc_bolt) { memory_block_t *mapped_range; int i, rc; mpr->avail_cops = (1 << COP_DECOMP) | (1 << COP_RNG) | (1 << COP_ASYM_CRYPTO) | (1 << COP_SYM_CRYPTO) | (1 << COP_ASYNC_DATA_MOVER); mpr->PBICtype = COP_PBIC_CC; mpr->crb_cache = malloc(sizeof(struct dec_root) * 15); for (i = 0; i < 15; i++) { //verbose_print("%d: plain %p amper %p\n", i, mpr->crb_cache[i], &(mpr->crb_cache[i])); dec_init(&(mpr->crb_cache[i])); } dec_init(&(mpr->DDE_cache)); dec_init(&(mpr->memory_block_list)); #ifdef REENTRANT_ON sem_init(&(mpr->mnode_root_lock), 0, 1); sem_init(&(mpr->memory_block_lock), 0, 1); #endif errno = 0; mpr->Tree = cop_MMTree_create(newBlockSize); mapped_range = malloc(sizeof(memory_block_t)); if ((rc = posix_memalign((void **)&(mapped_range->base_address), (64 * 1024), cc_size))) fprintf(stderr, "posix_memalign failed, %s\n", strerror(rc)); mapped_range->length = cc_size; mpr->bolted = cc_bolt; if (mpr->bolted) mapped_range->flags = COP_MAP_BOLT | COP_MAP_MLOCK; else mapped_range->flags = 0; cop_MMTree_insertmappedblock(mpr->Tree, mapped_range); dec_push(&(mpr->memory_block_list), mapped_range); cop_remap_pool(mpr); }
/*配置XVID CODEC视频编解码算法*/ void CMainFrame::Config_XVIECODEC() { //////////////////////////////////////////////////////////////// ENC_PARAM m_Param; m_Param.width = lpbiIn->bmiHeader.biWidth; //视频图像宽度 m_Param.height= lpbiIn->bmiHeader.biHeight; //视频图像高度 m_Param.bitrate = 800000; //码流大小,使用码流控制 m_Param.max_key_interval = 100; //关键帧间隔 m_Param.framerate = 25; //帧率 m_Param.quant = 0; //量化步长,0表示使用码流控制 enc_init(&m_Param); //创建xvid codec编码器 dec_init(m_Param.width,m_Param.height); //创建xvid codec解码器 //////////////////////////////////////////////////////////////// }
BD_DISC *disc_open(const char *device_path, fs_access *p_fs, struct bd_enc_info *enc_info, const char *keyfile_path, void *regs, void *psr_read, void *psr_write) { BD_DISC *p = _disc_init(); if (p) { if (p_fs && p_fs->open_dir) { p->fs_handle = p_fs->fs_handle; p->pf_file_open_bdrom = p_fs->open_file; p->pf_dir_open_bdrom = p_fs->open_dir; } _set_paths(p, device_path); #ifdef ENABLE_UDF /* check if disc root directory can be opened. If not, treat it as device/image file. */ BD_DIR_H *dp_img = device_path ? dir_open(device_path) : NULL; if (!dp_img) { void *udf = udf_image_open(device_path, p_fs ? p_fs->fs_handle : NULL, p_fs ? p_fs->read_blocks : NULL); if (!udf) { BD_DEBUG(DBG_FILE | DBG_CRIT, "failed opening UDF image %s\n", device_path); } else { p->fs_handle = udf; p->pf_fs_close = udf_image_close; p->pf_file_open_bdrom = udf_file_open; p->pf_dir_open_bdrom = udf_dir_open; p->udf_volid = udf_volume_id(udf); /* root not accessible with stdio */ X_FREE(p->disc_root); } } else { dir_close(dp_img); BD_DEBUG(DBG_FILE, "%s does not seem to be image file or device node\n", device_path); } #endif struct dec_dev dev = { p->fs_handle, p->pf_file_open_bdrom, p, (file_openFp)disc_open_path, p->disc_root, device_path }; p->dec = dec_init(&dev, enc_info, keyfile_path, regs, psr_read, psr_write); } return p; }
int satisfies(char key[4]) { struct dec dec; char * tok; int i; dec_init(&dec, cipher, cipher_length, key, 3); while (NULL != (tok = dec_token(&dec))) { i=0; while (tok[i] != (char)0) { tok[i] = lowercase(tok[i]); ++i; } if (!in_dict(tok)) { return 0; } } return 1; }
double score(char key[4]) { struct dec dec; char * tok; int i; size_t k, n; k = 0; n = 0; dec_init(&dec, cipher, cipher_length, key, 3); while (NULL != (tok = dec_token(&dec))) { i=0; while (tok[i] != (char)0) { tok[i] = lowercase(tok[i]); ++i; } if (in_dict(tok)) { k += 1; } n += 1; } return (double)k / (double)n; }
void process(int argc, char *argv[]) { char tmp[2]; char tmp2[64]; for (;;) { int t = getopt(argc, argv, "aig:c:r:bh"); if (t == -1) { break; } switch (t) { case 'r': reset_cmv = 1; case 'c': if (sscanf(optarg, "%s", tmp2) != 1) { fprintf(stderr, "error optarg: %s\n", optarg); exit(-1); } cfilename = argv[2]; use_cmv = 1; break; case 'b': bb = 1; break; case 'h': print_help(argv[0]); exit(0); case '?': break; //added by hjw case 'i': //for bpnet training printf("Use bp.\n"); use_bp = 1; if (sscanf(optarg, "%s", tmp) != 1) { fprintf(stderr, "error optarg: %s\n", optarg); exit(-1); } sample_color_id = atoi(tmp); break; case 'a': get_calib_sample = 1; break; case 'g': //get training samples printf("get training samples.\n"); get_training_sample = 1; if (sscanf(optarg, "%s", tmp) != 1) { fprintf(stderr, "error optarg: %s\n", optarg); exit(-1); } sample_color_id = atoi(tmp); break; default: fprintf(stderr, "error option: %d\n", t); exit(-1); } } if (argc - optind != 1 && use_bp != 1 && get_training_sample != 1 && get_calib_sample != 1) { print_help(argv[0]); exit(-1); } filename = argv[optind]; int fd = open(filename, O_RDONLY); if (fd < 0) { perror(filename); exit(-1); } int filelength=lseek(fd,0,SEEK_END); char *suffix = strrchr(filename, '.'); if (suffix == NULL) { fprintf(stderr, "unknown filename: %s\n", filename); exit(-1); } ++suffix; if (!strcmp(suffix, "raw")) { unsigned char *raw = mmap(NULL, RAW_SIZE, PROT_READ, MAP_SHARED, fd, 0); if (raw == MAP_FAILED) { perror("mmap"); exit(-1); } dec_init(W,H,R); dec_process(raw, src); } else if (!strcmp(suffix, "yuv")) { unsigned ori= mmap(NULL, YUV_SIZE, PROT_READ, MAP_SHARED, fd, 0); if (ori == MAP_FAILED) { perror("mmap"); exit(-1); } memcpy(src,ori,YUV_SIZE); //dec_init(W,H,R); //dec_process(raw, src,W,H,R); } else { fprintf(stderr, "unknown filename: %s\n", filename); exit(-1); } if (use_cmv) { cmv_init(&data, cfilename); printf("using color file %s\n", cfilename); cmv_process(&data, src); } }
int console_write_video(struct ast_channel *chan, struct ast_frame *f) { struct video_desc *env = get_video_desc(chan); struct video_dec_desc *v = env->in; if (!env->gui) /* no gui, no rendering */ return 0; if (v == NULL) env->in = v = dec_init(f->subclass & ~1); if (v == NULL) { /* This is not fatal, but we won't have incoming video */ ast_log(LOG_WARNING, "Cannot initialize input decoder\n"); return 0; } if (v->dec_in_cur == NULL) /* no buffer for incoming frames, drop */ return 0; #if defined(DROP_PACKETS) && DROP_PACKETS > 0 /* Simulate lost packets */ if ((random() % 10000) <= 100*DROP_PACKETS) { ast_log(LOG_NOTICE, "Packet lost [%d]\n", f->seqno); return 0; } #endif if (v->discard) { /* * In discard mode, drop packets until we find one with * the RTP marker set (which is the end of frame). * Note that the RTP marker flag is sent as the LSB of the * subclass, which is a bitmask of formats. The low bit is * normally used for audio so there is no interference. */ if (f->subclass & 0x01) { v->dec_in_cur->used = 0; v->dec_in_cur->ebit = 0; v->next_seq = f->seqno + 1; /* wrap at 16 bit */ v->discard = 0; ast_log(LOG_WARNING, "out of discard mode, frame %d\n", f->seqno); } return 0; } /* * Only in-order fragments will be accepted. Remember seqno * has 16 bit so there is wraparound. Also, ideally we could * accept a bit of reordering, but at the moment we don't. */ if (v->next_seq != f->seqno) { ast_log(LOG_WARNING, "discarding frame out of order, %d %d\n", v->next_seq, f->seqno); v->discard = 1; return 0; } v->next_seq++; if (f->data.ptr == NULL || f->datalen < 2) { ast_log(LOG_WARNING, "empty video frame, discard\n"); return 0; } if (v->d_callbacks->dec_decap(v->dec_in_cur, f->data.ptr, f->datalen)) { ast_log(LOG_WARNING, "error in dec_decap, enter discard\n"); v->discard = 1; } if (f->subclass & 0x01) { // RTP Marker /* prepare to decode: advance the buffer so the video thread knows. */ struct fbuf_t *tmp = v->dec_in_cur; /* store current pointer */ ast_mutex_lock(&env->dec_lock); if (++v->dec_in_cur == &v->dec_in[N_DEC_IN]) /* advance to next, circular */ v->dec_in_cur = &v->dec_in[0]; if (v->dec_in_dpy == NULL) { /* were not displaying anything, so set it */ v->dec_in_dpy = tmp; } else if (v->dec_in_dpy == v->dec_in_cur) { /* current slot is busy */ v->dec_in_cur = NULL; } ast_mutex_unlock(&env->dec_lock); } return 0; }
int main(int argc, char *argv[]) { int idx, tus, fsize; char capdev_str[128]; unsigned long ss; struct timeval ts, te; if(argc > 1) { // printf(" Usage : %s [file_path]\n", argv[0]); strcpy(capdev_str, argv[1]); } else { strcpy(capdev_str, dev_cap); } signal(SIGQUIT, exit_signal); signal(SIGINT, exit_signal); signal(SIGPIPE, SIG_IGN); if(display_init() < 0) { printf("display init error\n"); return 0; } if(dec_init(CAP_WIDTH, CAP_HEIGHT, VPU_V_MJPG) < 0) { printf("decodec init error\n"); goto err; } if ((fd_cap = open(capdev_str, O_RDWR)) < 0) { printf("Unable to open [%s]\n", capdev_str); goto err0; } if (setup_cap() < 0) { printf("Unable to setup capture\n"); goto err1; } printf("capture device setup done\n"); if (map_buffers() < 0) { printf("Unable to map I/O memory\n"); goto err1; } printf("buffers mapping done\n"); if (stream_start() < 0) { printf("Unable to start stream\n"); goto err2; } printf("Stream starting... with fps=%d\n", FPS_VIDEO); gettimeofday(&ts, 0); do { idx = frame_get(&fsize); frame_render(idx, fsize); frame_put(idx); gettimeofday(&te, 0); tus = (te.tv_sec - ts.tv_sec) * 1000000 + (te.tv_usec - ts.tv_usec); if(tus <= FRAME_DURATION) { if(!exitflag) usleep(FRAME_DURATION - tus); } else { // printf("rander a frame with %.3fms\n", tus / 1000.0); } printf("Rander a frame sz = %d, takes %.3fms\n", fsize, tus / 1000.0); gettimeofday(&ts, 0); } while(!exitflag); printf("Stopping stream...\n"); stream_stop(); err2: umap_buffers(); err1: close(fd_cap); err0: dec_exit(); err: display_exit(); return 0; }
int ReadDecodeXML(const char *file) { OS_XML xml; XML_NODE node = NULL; /* XML variables */ /* These are the available options for the rule configuration */ const char *xml_plugindecoder = "plugin_decoder"; const char *xml_decoder = "decoder"; const char *xml_decoder_name = "name"; const char *xml_decoder_status = "status"; const char *xml_usename = "use_own_name"; const char *xml_parent = "parent"; const char *xml_program_name = "program_name"; const char *xml_prematch = "prematch"; const char *xml_regex = "regex"; const char *xml_order = "order"; const char *xml_type = "type"; const char *xml_fts = "fts"; const char *xml_ftscomment = "ftscomment"; const char *xml_accumulate = "accumulate"; int i = 0; OSDecoderInfo *NULL_Decoder_tmp = NULL; /* Read the XML */ if ((i = OS_ReadXML(file, &xml)) < 0) { if ((i == -2) && (strcmp(file, XML_LDECODER) == 0)) { return (-2); } merror(XML_ERROR, ARGV0, file, xml.err, xml.err_line); return (0); } /* Apply any variables found */ if (OS_ApplyVariables(&xml) != 0) { merror(XML_ERROR_VAR, ARGV0, file, xml.err); return (0); } /* Get the root elements */ node = OS_GetElementsbyNode(&xml, NULL); if (!node) { if (strcmp(file, XML_LDECODER) != 0) { merror(XML_ELEMNULL, ARGV0); return (0); } return (-2); } /* Zero NULL_decoder */ if (!NULL_Decoder) { os_calloc(1, sizeof(OSDecoderInfo), NULL_Decoder_tmp); NULL_Decoder_tmp->id = 0; NULL_Decoder_tmp->type = SYSLOG; NULL_Decoder_tmp->name = NULL; NULL_Decoder_tmp->fts = 0; NULL_Decoder = NULL_Decoder_tmp; } i = 0; while (node[i]) { XML_NODE elements = NULL; OSDecoderInfo *pi; int j = 0; char *regex; char *prematch; char *p_name; if (!node[i]->element || strcasecmp(node[i]->element, xml_decoder) != 0) { merror(XML_INVELEM, ARGV0, node[i]->element); return (0); } /* Get name */ if ((!node[i]->attributes) || (!node[i]->values) || (!node[i]->values[0]) || (!node[i]->attributes[0]) || (strcasecmp(node[i]->attributes[0], xml_decoder_name) != 0)) { merror(XML_INVELEM, ARGV0, node[i]->element); return (0); } /* Check for additional entries */ if (node[i]->attributes[1] && node[i]->values[1]) { if (strcasecmp(node[i]->attributes[0], xml_decoder_status) != 0) { merror(XML_INVELEM, ARGV0, node[i]->element); return (0); } if (node[i]->attributes[2]) { merror(XML_INVELEM, ARGV0, node[i]->element); return (0); } } /* Get decoder options */ elements = OS_GetElementsbyNode(&xml, node[i]); if (elements == NULL) { merror(XML_ELEMNULL, ARGV0); return (0); } /* Create the OSDecoderInfo */ pi = (OSDecoderInfo *)calloc(1, sizeof(OSDecoderInfo)); if (pi == NULL) { merror(MEM_ERROR, ARGV0, errno, strerror(errno)); return (0); } /* Default values to the list */ pi->parent = NULL; pi->id = 0; pi->name = strdup(node[i]->values[0]); pi->order = NULL; pi->plugindecoder = NULL; pi->fts = 0; pi->accumulate = 0; pi->type = SYSLOG; pi->prematch = NULL; pi->program_name = NULL; pi->regex = NULL; pi->use_own_name = 0; pi->get_next = 0; pi->regex_offset = 0; pi->prematch_offset = 0; regex = NULL; prematch = NULL; p_name = NULL; /* Check if strdup worked */ if (!pi->name) { merror(MEM_ERROR, ARGV0, errno, strerror(errno)); return (0); } /* Add decoder */ if (!addDecoder2list(pi->name)) { merror(MEM_ERROR, ARGV0, errno, strerror(errno)); free(pi); return (0); } /* Loop over all the elements */ while (elements[j]) { if (!elements[j]->element) { merror(XML_ELEMNULL, ARGV0); return (0); } else if (!elements[j]->content) { merror(XML_VALUENULL, ARGV0, elements[j]->element); return (0); } /* Check if it is a child of a rule */ else if (strcasecmp(elements[j]->element, xml_parent) == 0) { pi->parent = _loadmemory(pi->parent, elements[j]->content); } /* Get the regex */ else if (strcasecmp(elements[j]->element, xml_regex) == 0) { int r_offset; r_offset = ReadDecodeAttrs(elements[j]->attributes, elements[j]->values); if (r_offset & AFTER_ERROR) { merror(DEC_REGEX_ERROR, ARGV0, pi->name); return (0); } /* Only the first regex entry may have an offset */ if (regex && r_offset) { merror(DUP_REGEX, ARGV0, pi->name); merror(DEC_REGEX_ERROR, ARGV0, pi->name); return (0); } /* regex offset */ if (r_offset) { pi->regex_offset = r_offset; } /* Assign regex */ regex = _loadmemory(regex, elements[j]->content); } /* Get the pre match */ else if (strcasecmp(elements[j]->element, xml_prematch) == 0) { int r_offset; r_offset = ReadDecodeAttrs( elements[j]->attributes, elements[j]->values); if (r_offset & AFTER_ERROR) { ErrorExit(DEC_REGEX_ERROR, ARGV0, pi->name); } /* Only the first prematch entry may have an offset */ if (prematch && r_offset) { merror(DUP_REGEX, ARGV0, pi->name); ErrorExit(DEC_REGEX_ERROR, ARGV0, pi->name); } if (r_offset) { pi->prematch_offset = r_offset; } prematch = _loadmemory(prematch, elements[j]->content); } /* Get program name */ else if (strcasecmp(elements[j]->element, xml_program_name) == 0) { p_name = _loadmemory(p_name, elements[j]->content); } /* Get the FTS comment */ else if (strcasecmp(elements[j]->element, xml_ftscomment) == 0) { } else if (strcasecmp(elements[j]->element, xml_usename) == 0) { if (strcmp(elements[j]->content, "true") == 0) { pi->use_own_name = 1; } } else if (strcasecmp(elements[j]->element, xml_plugindecoder) == 0) { int ed_c = 0; for (ed_c = 0; plugin_decoders[ed_c] != NULL; ed_c++) { if (strcmp(plugin_decoders[ed_c], elements[j]->content) == 0) { /* Initialize plugin */ void (*dec_init)(void) = (void (*)(void)) plugin_decoders_init[ed_c]; dec_init(); pi->plugindecoder = (void (*)(void *)) plugin_decoders_exec[ed_c]; break; } } /* Decoder not found */ if (pi->plugindecoder == NULL) { merror(INV_DECOPTION, ARGV0, elements[j]->element, elements[j]->content); return (0); } } /* Get the type */ else if (strcmp(elements[j]->element, xml_type) == 0) { if (strcmp(elements[j]->content, "firewall") == 0) { pi->type = FIREWALL; } else if (strcmp(elements[j]->content, "ids") == 0) { pi->type = IDS; } else if (strcmp(elements[j]->content, "web-log") == 0) { pi->type = WEBLOG; } else if (strcmp(elements[j]->content, "syslog") == 0) { pi->type = SYSLOG; } else if (strcmp(elements[j]->content, "squid") == 0) { pi->type = SQUID; } else if (strcmp(elements[j]->content, "windows") == 0) { pi->type = DECODER_WINDOWS; } else if (strcmp(elements[j]->content, "host-information") == 0) { pi->type = HOST_INFO; } else if (strcmp(elements[j]->content, "ossec") == 0) { pi->type = OSSEC_RL; } else { merror("%s: Invalid decoder type '%s'.", ARGV0, elements[j]->content); return (0); } } /* Get the order */ else if (strcasecmp(elements[j]->element, xml_order) == 0) { char **norder, **s_norder; int order_int = 0; /* Maximum number is 8 for the order */ norder = OS_StrBreak(',', elements[j]->content, 8); s_norder = norder; os_calloc(8, sizeof(void *), pi->order); /* Initialize the function pointers */ while (order_int < 8) { pi->order[order_int] = NULL; order_int++; } order_int = 0; /* Check the values from the order */ while (*norder) { if (strstr(*norder, "dstuser") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) DstUser_FP; } else if (strstr(*norder, "srcuser") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) SrcUser_FP; } /* User is an alias to dstuser */ else if (strstr(*norder, "user") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) DstUser_FP; } else if (strstr(*norder, "srcip") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) SrcIP_FP; } else if (strstr(*norder, "dstip") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) DstIP_FP; } else if (strstr(*norder, "srcport") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) SrcPort_FP; } else if (strstr(*norder, "dstport") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) DstPort_FP; } else if (strstr(*norder, "protocol") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) Protocol_FP; } else if (strstr(*norder, "action") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) Action_FP; } else if (strstr(*norder, "id") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) ID_FP; } else if (strstr(*norder, "url") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) Url_FP; } else if (strstr(*norder, "data") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) Data_FP; } else if (strstr(*norder, "extra_data") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) Data_FP; } else if (strstr(*norder, "status") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) Status_FP; } else if (strstr(*norder, "system_name") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) SystemName_FP; } else if (strstr(*norder, "filename") != NULL) { pi->order[order_int] = (void (*)(void *, char *)) FileName_FP; } else { ErrorExit("decode-xml: Wrong field '%s' in the order" " of decoder '%s'", *norder, pi->name); } free(*norder); norder++; order_int++; } free(s_norder); } else if (strcasecmp(elements[j]->element, xml_accumulate) == 0) { /* Enable Accumulator */ pi->accumulate = 1; } /* Get the FTS order */ else if (strcasecmp(elements[j]->element, xml_fts) == 0) { char **norder; char **s_norder; /* Maximum number is 8 for the FTS */ norder = OS_StrBreak(',', elements[j]->content, 8); if (norder == NULL) { ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno)); } /* Save the initial point to free later */ s_norder = norder; /* Check the values from the FTS */ while (*norder) { if (strstr(*norder, "dstuser") != NULL) { pi->fts |= FTS_DSTUSER; } if (strstr(*norder, "user") != NULL) { pi->fts |= FTS_DSTUSER; } else if (strstr(*norder, "srcuser") != NULL) { pi->fts |= FTS_SRCUSER; } else if (strstr(*norder, "srcip") != NULL) { pi->fts |= FTS_SRCIP; } else if (strstr(*norder, "dstip") != NULL) { pi->fts |= FTS_DSTIP; } else if (strstr(*norder, "id") != NULL) { pi->fts |= FTS_ID; } else if (strstr(*norder, "location") != NULL) { pi->fts |= FTS_LOCATION; } else if (strstr(*norder, "data") != NULL) { pi->fts |= FTS_DATA; } else if (strstr(*norder, "extra_data") != NULL) { pi->fts |= FTS_DATA; } else if (strstr(*norder, "system_name") != NULL) { pi->fts |= FTS_SYSTEMNAME; } else if (strstr(*norder, "name") != NULL) { pi->fts |= FTS_NAME; } else { ErrorExit("decode-xml: Wrong field '%s' in the fts" " decoder '%s'", *norder, pi->name); } free(*norder); norder++; } /* Clear memory here */ free(s_norder); } else { merror("%s: Invalid element '%s' for " "decoder '%s'", ARGV0, elements[j]->element, node[i]->element); return (0); } /* NEXT */ j++; } /* while(elements[j]) */ OS_ClearNode(elements); /* Prematch must be set */ if (!prematch && !pi->parent && !p_name) { merror(DECODE_NOPRE, ARGV0, pi->name); merror(DEC_REGEX_ERROR, ARGV0, pi->name); return (0); } /* If pi->regex is not set, fts must not be set too */ if ((!regex && (pi->fts || pi->order)) || (regex && !pi->order)) { merror(DEC_REGEX_ERROR, ARGV0, pi->name); return (0); } /* For the offsets */ if ((pi->regex_offset & AFTER_PARENT) && !pi->parent) { merror(INV_OFFSET, ARGV0, "after_parent"); merror(DEC_REGEX_ERROR, ARGV0, pi->name); return (0); } if (pi->regex_offset & AFTER_PREMATCH) { /* If after_prematch is set, but rule have * no parent, set AFTER_PARENT and unset * pre_match. */ if (!pi->parent) { pi->regex_offset = 0; pi->regex_offset |= AFTER_PARENT; } else if (!prematch) { merror(INV_OFFSET, ARGV0, "after_prematch"); merror(DEC_REGEX_ERROR, ARGV0, pi->name); return (0); } } /* For the after_regex offset */ if (pi->regex_offset & AFTER_PREVREGEX) { if (!pi->parent || !regex) { merror(INV_OFFSET, ARGV0, "after_regex"); merror(DEC_REGEX_ERROR, ARGV0, pi->name); return (0); } } /* Check the prematch offset */ if (pi->prematch_offset) { /* Only the after parent is allowed */ if (pi->prematch_offset & AFTER_PARENT) { if (!pi->parent) { merror(INV_OFFSET, ARGV0, "after_parent"); merror(DEC_REGEX_ERROR, ARGV0, pi->name); return (0); } } else { merror(DEC_REGEX_ERROR, ARGV0, pi->name); return (0); } } /* Compile the regex/prematch */ if (prematch) { os_calloc(1, sizeof(OSRegex), pi->prematch); if (!OSRegex_Compile(prematch, pi->prematch, 0)) { merror(REGEX_COMPILE, ARGV0, prematch, pi->prematch->error); return (0); } free(prematch); } /* Compile the p_name */ if (p_name) { os_calloc(1, sizeof(OSMatch), pi->program_name); if (!OSMatch_Compile(p_name, pi->program_name, 0)) { merror(REGEX_COMPILE, ARGV0, p_name, pi->program_name->error); return (0); } free(p_name); } /* We may not have the pi->regex */ if (regex) { os_calloc(1, sizeof(OSRegex), pi->regex); if (!OSRegex_Compile(regex, pi->regex, OS_RETURN_SUBSTRING)) { merror(REGEX_COMPILE, ARGV0, regex, pi->regex->error); return (0); } /* We must have the sub_strings to retrieve the nodes */ if (!pi->regex->sub_strings) { merror(REGEX_SUBS, ARGV0, regex); return (0); } free(regex); } /* Validate arguments */ if (pi->plugindecoder && (pi->regex || pi->order)) { merror(DECODE_ADD, ARGV0, pi->name); return (0); } /* Add osdecoder to the list */ if (!OS_AddOSDecoder(pi)) { merror(DECODER_ERROR, ARGV0); return (0); } i++; } /* while (node[i]) */ /* Clean node and XML structures */ OS_ClearNode(node); OS_ClearXML(&xml); return (1); }
int main(void) { int i; char x; struct dec dec; char * tok; char key[4]; if (0) { for (i=0; i<cipher_length; ++i) { printf("%c", lowercase(cipher[i])); } printf("\n"); dec_init(&dec, cipher, cipher_length, "aaa", 3); while (0 != (x = dec_read(&dec))) { printf("%c", lowercase(x)); } printf("\n"); /* tokenizer. */ dec_init(&dec, cipher, cipher_length, "aab", 3); while (NULL != (tok = dec_token(&dec))) { printf("%s -> sig: %llu\n", tok, sign_word(tok)); } return 0; } /* key generator */ double max_score, curr_score; char max_key[4]; init_dict("/usr/share/dict/words"); key[3] = (char)0; for (key[0]='a'; key[0] <= 'z'; ++key[0]) for (key[1]='a'; key[1] <= 'z'; ++key[1]) for (key[2]='a'; key[2] <= 'z'; ++key[2]) { if (1) { curr_score = score(key); if (verbose) printf("key: %s score: %.6lf\n", key, curr_score); if (curr_score > max_score) { max_score = curr_score; memcpy(max_key, key, 4); if (verbose) { printf("\n\n----- new max -- key: %s ---- score: %lf ----\n", max_key, max_score); dec_init(&dec, cipher, cipher_length, max_key, 3); while (0 != (x = dec_read(&dec))) { printf("%c", lowercase(x)); } printf("\n\n\n"); usleep(250000); } } } if (0) { if (satisfies(key)) { printf("good_key: %s\n", key); fprintf(stderr, "good_key: %s\n", key); } else { printf("bad_key: %s\n", key); } } } printf("\n\n------- key: %s ---- score: %lf ----\n", max_key, max_score); int sum = 0; dec_init(&dec, cipher, cipher_length, max_key, 3); while (0 != (x = dec_read(&dec))) { sum += x; printf("%c", x); } printf("\n\n\n"); printf("sum: %d\n", sum); return 0; }
ERL_NIF_TERM decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { Decoder* d; jiffy_st* st = (jiffy_st*) enif_priv_data(env); ErlNifBinary bin; ERL_NIF_TERM objs; ERL_NIF_TERM curr; ERL_NIF_TERM val = argv[2]; ERL_NIF_TERM trailer; ERL_NIF_TERM ret; size_t bytes_read = 0; if(argc != 5) { return enif_make_badarg(env); } else if(!enif_inspect_binary(env, argv[0], &bin)) { return enif_make_badarg(env); } else if(!enif_get_resource(env, argv[1], st->res_dec, (void**) &d)) { return enif_make_badarg(env); } else if(!enif_is_list(env, argv[3])) { return enif_make_badarg(env); } else if(!enif_is_list(env, argv[4])) { return enif_make_badarg(env); } dec_init(d, env, argv[0], &bin); objs = argv[3]; curr = argv[4]; while(d->i < bin.size) { if(should_yield(env, &bytes_read, d->bytes_per_red)) { return enif_make_tuple5( env, st->atom_iter, argv[1], val, objs, curr ); } bytes_read += 1; switch(dec_curr(d)) { case st_value: switch(d->p[d->i]) { case ' ': case '\n': case '\r': case '\t': d->i++; break; case 'n': if(d->i + 3 >= d->len) { ret = dec_error(d, "invalid_literal"); goto done; } if(memcmp(&(d->p[d->i]), "null", 4) != 0) { ret = dec_error(d, "invalid_literal"); goto done; } val = d->null_term; dec_pop(d, st_value); d->i += 4; break; case 't': if(d->i + 3 >= d->len) { ret = dec_error(d, "invalid_literal"); goto done; } if(memcmp(&(d->p[d->i]), "true", 4) != 0) { ret = dec_error(d, "invalid_literal"); goto done; } val = d->atoms->atom_true; dec_pop(d, st_value); d->i += 4; break; case 'f': if(d->i + 4 >= bin.size) { ret = dec_error(d, "invalid_literal"); goto done; } if(memcmp(&(d->p[d->i]), "false", 5) != 0) { ret = dec_error(d, "invalid_literal"); goto done; } val = d->atoms->atom_false; dec_pop(d, st_value); d->i += 5; break; case '\"': if(!dec_string(d, &val)) { ret = dec_error(d, "invalid_string"); goto done; } dec_pop(d, st_value); break; case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if(!dec_number(d, &val)) { ret = dec_error(d, "invalid_number"); goto done; } dec_pop(d, st_value); break; case '{': dec_push(d, st_object); dec_push(d, st_key); objs = enif_make_list_cell(env, curr, objs); curr = enif_make_list(env, 0); d->i++; break; case '[': dec_push(d, st_array); dec_push(d, st_value); objs = enif_make_list_cell(env, curr, objs); curr = enif_make_list(env, 0); d->i++; break; case ']': if(!enif_is_empty_list(env, curr)) { ret = dec_error(d, "invalid_json"); goto done; } dec_pop(d, st_value); if(dec_curr(d) != st_array) { ret = dec_error(d, "invalid_json"); goto done; } dec_pop(d, st_array); dec_pop(d, st_value); val = curr; // curr is [] if(!enif_get_list_cell(env, objs, &curr, &objs)) { ret = dec_error(d, "internal_error"); goto done; } d->i++; break; default: ret = dec_error(d, "invalid_json"); goto done; } if(dec_top(d) == 0) { dec_push(d, st_done); } else if(dec_curr(d) != st_value && dec_curr(d) != st_key) { dec_push(d, st_comma); curr = enif_make_list_cell(env, val, curr); } break; case st_key: switch(d->p[d->i]) { case ' ': case '\n': case '\r': case '\t': d->i++; break; case '\"': if(!dec_string(d, &val)) { ret = dec_error(d, "invalid_string"); goto done; } dec_pop(d, st_key); dec_push(d, st_colon); curr = enif_make_list_cell(env, val, curr); break; case '}': if(!enif_is_empty_list(env, curr)) { ret = dec_error(d, "invalid_json"); goto done; } dec_pop(d, st_key); dec_pop(d, st_object); dec_pop(d, st_value); val = make_empty_object(env, d->return_maps); if(!enif_get_list_cell(env, objs, &curr, &objs)) { ret = dec_error(d, "internal_error"); goto done; } if(dec_top(d) == 0) { dec_push(d, st_done); } else { dec_push(d, st_comma); curr = enif_make_list_cell(env, val, curr); } d->i++; break; default: ret = dec_error(d, "invalid_json"); goto done; } break; case st_colon: switch(d->p[d->i]) { case ' ': case '\n': case '\r': case '\t': d->i++; break; case ':': dec_pop(d, st_colon); dec_push(d, st_value); d->i++; break; default: ret = dec_error(d, "invalid_json"); goto done; } break; case st_comma: switch(d->p[d->i]) { case ' ': case '\n': case '\r': case '\t': d->i++; break; case ',': dec_pop(d, st_comma); switch(dec_curr(d)) { case st_object: dec_push(d, st_key); break; case st_array: dec_push(d, st_value); break; default: ret = dec_error(d, "internal_error"); goto done; } d->i++; break; case '}': dec_pop(d, st_comma); if(dec_curr(d) != st_object) { ret = dec_error(d, "invalid_json"); goto done; } dec_pop(d, st_object); dec_pop(d, st_value); if(!make_object(env, curr, &val, d->return_maps, d->dedupe_keys)) { ret = dec_error(d, "internal_object_error"); goto done; } if(!enif_get_list_cell(env, objs, &curr, &objs)) { ret = dec_error(d, "internal_error"); goto done; } if(dec_top(d) > 0) { dec_push(d, st_comma); curr = enif_make_list_cell(env, val, curr); } else { dec_push(d, st_done); } d->i++; break; case ']': dec_pop(d, st_comma); if(dec_curr(d) != st_array) { ret = dec_error(d, "invalid_json"); goto done; } dec_pop(d, st_array); dec_pop(d, st_value); val = make_array(env, curr); if(!enif_get_list_cell(env, objs, &curr, &objs)) { ret = dec_error(d, "internal_error"); goto done; } if(dec_top(d) > 0) { dec_push(d, st_comma); curr = enif_make_list_cell(env, val, curr); } else { dec_push(d, st_done); } d->i++; break; default: ret = dec_error(d, "invalid_json"); goto done; } break; case st_done: switch(d->p[d->i]) { case ' ': case '\n': case '\r': case '\t': d->i++; break; default: goto decode_done; } break; default: ret = dec_error(d, "invalid_internal_state"); goto done; } } decode_done: if(d->i < bin.size && d->return_trailer) { trailer = enif_make_sub_binary(env, argv[0], d->i, bin.size - d->i); val = enif_make_tuple3(env, d->atoms->atom_has_trailer, val, trailer); } else if(d->i < bin.size) { ret = dec_error(d, "invalid_trailing_data"); goto done; } if(dec_curr(d) != st_done) { ret = dec_error(d, "truncated_json"); } else if(d->is_partial) { ret = enif_make_tuple2(env, d->atoms->atom_partial, val); } else { ret = val; } done: return ret; }
void main(void) { const char *outrecfilename = "F:\\╡Бйтнд╪Ч\\test3.yuv"; const char *filename = "F:\\╡Бйтнд╪Ч\\test.m4v"; int frame, size, got_picture; FILE *fin, *fout; uint8_t inbuf[INBUF_SIZE ], *inbuf_ptr; int v_YuvInfo[5]; int32 used_bytes; xvid_dec_stats_t xvid_dec_stats; char *pZoom; int i; int h; fin = fopen(filename, "rb"); if (!fin) { fprintf(stderr, "could not open %s\n", filename); exit(1); } fout = fopen(outrecfilename, "wb"); if (!fin) { fprintf(stderr, "could not open %s\n", outrecfilename); exit(1); } dec_init(0, 0); size=0; used_bytes=0; i=0; while (1) { size += fread(inbuf+size, 1, INBUF_SIZE-size, fin); inbuf_ptr = inbuf; used_bytes=dec_main(inbuf_ptr, v_YuvInfo, size, &xvid_dec_stats, pZoom, 0); if(used_bytes>0 && xvid_dec_stats.type>0) { for(h=0;h< YDIM;h++) fwrite(v_YuvInfo[0]+v_YuvInfo[3]*h, 1, XDIM, fout ); for(h=0;h<YDIM/2;h++) fwrite(v_YuvInfo[1]+v_YuvInfo[3]*h/2, 1, XDIM/2, fout ); for(h=0;h<YDIM/2;h++) fwrite(v_YuvInfo[2]+v_YuvInfo[3]*h/2, 1, XDIM/2, fout ); } if(used_bytes>0) { size -= used_bytes; inbuf_ptr += used_bytes; memmove(inbuf, inbuf_ptr, size); } i++; if(i>500)break; } dec_stop(); fclose(fin); fclose(fout); }