idx
int64
func
string
target
int64
441,424
void RGWPostObj_ObjStore_S3::send_response() { if (op_ret == 0 && parts.count("success_action_redirect")) { string redirect; part_str(parts, "success_action_redirect", &redirect); string tenant; string bucket; string key; string etag_str = "\""; etag_str.append(etag); etag_str.append("\""); string etag_url; url_encode(s->bucket_tenant, tenant); /* surely overkill, but cheap */ url_encode(s->bucket_name, bucket); url_encode(s->object.name, key); url_encode(etag_str, etag_url); if (!s->bucket_tenant.empty()) { /* * What we really would like is to quaily the bucket name, so * that the client could simply copy it and paste into next request. * Unfortunately, in S3 we cannot know if the client will decide * to come through DNS, with "bucket.tenant" sytanx, or through * URL with "tenant\bucket" syntax. Therefore, we provide the * tenant separately. */ redirect.append("?tenant="); redirect.append(tenant); redirect.append("&bucket="); redirect.append(bucket); } else { redirect.append("?bucket="); redirect.append(bucket); } redirect.append("&key="); redirect.append(key); redirect.append("&etag="); redirect.append(etag_url); int r = check_utf8(redirect.c_str(), redirect.size()); if (r < 0) { op_ret = r; goto done; } dump_redirect(s, redirect); op_ret = STATUS_REDIRECT; } else if (op_ret == 0 && parts.count("success_action_status")) { string status_string; uint32_t status_int; part_str(parts, "success_action_status", &status_string); int r = stringtoul(status_string, &status_int); if (r < 0) { op_ret = r; goto done; } switch (status_int) { case 200: break; case 201: op_ret = STATUS_CREATED; break; default: op_ret = STATUS_NO_CONTENT; break; } } else if (! op_ret) { op_ret = STATUS_NO_CONTENT; } done: if (op_ret == STATUS_CREATED) { for (auto &it : crypt_http_responses) dump_header(s, it.first, it.second); s->formatter->open_object_section("PostResponse"); if (g_conf->rgw_dns_name.length()) s->formatter->dump_format("Location", "%s/%s", s->info.script_uri.c_str(), s->object.name.c_str()); if (!s->bucket_tenant.empty()) s->formatter->dump_string("Tenant", s->bucket_tenant); s->formatter->dump_string("Bucket", s->bucket_name); s->formatter->dump_string("Key", s->object.name); s->formatter->close_section(); } s->err.message = err_msg; set_req_state_err(s, op_ret); dump_errno(s); if (op_ret >= 0) { dump_content_length(s, s->formatter->get_len()); } end_header(s, this); if (op_ret != STATUS_CREATED) return; rgw_flush_formatter_and_reset(s, s->formatter); }
0
67,067
void test_checkout_nasty__dotgit_alternate_data_stream(void) { test_checkout_fails("refs/heads/dotgit_alternate_data_stream", ".git/dummy-file"); test_checkout_fails("refs/heads/dotgit_alternate_data_stream", ".git::$INDEX_ALLOCATION/dummy-file"); }
0
426,894
static Image *ReadXWDImage(const ImageInfo *image_info,ExceptionInfo *exception) { #define CheckOverflowException(length,width,height) \ (((height) != 0) && ((length)/((size_t) height) != ((size_t) width))) char *comment; Image *image; int x_status; MagickBooleanType authentic_colormap; MagickStatusType status; Quantum index; register ssize_t x; register Quantum *q; register ssize_t i; register size_t pixel; size_t length; ssize_t count, y; unsigned long lsb_first; XColor *colors; XImage *ximage; XWDFileHeader header; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickCoreSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); image=AcquireImage(image_info,exception); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Read in header information. */ count=ReadBlob(image,sz_XWDheader,(unsigned char *) &header); if (count != sz_XWDheader) ThrowReaderException(CorruptImageError,"UnableToReadImageHeader"); /* Ensure the header byte-order is most-significant byte first. */ lsb_first=1; if ((int) (*(char *) &lsb_first) != 0) MSBOrderLong((unsigned char *) &header,sz_XWDheader); /* Check to see if the dump file is in the proper format. */ if (header.file_version != XWD_FILE_VERSION) ThrowReaderException(CorruptImageError,"FileFormatVersionMismatch"); if (header.header_size < sz_XWDheader) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); if ((header.bits_per_pixel == 0) || (header.bits_per_pixel > 32)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); if ((header.bitmap_bit_order != MSBFirst) && (header.bitmap_bit_order != LSBFirst)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); if (((header.bitmap_pad % 8) != 0) || (header.bitmap_pad > 32)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); if (header.bitmap_unit > 32) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); if (header.ncolors > 256) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); switch (header.visual_class) { case StaticGray: case GrayScale: case StaticColor: case PseudoColor: case TrueColor: case DirectColor: break; default: ThrowReaderException(CorruptImageError,"ImproperImageHeader"); } switch (header.pixmap_format) { case XYBitmap: case XYPixmap: case ZPixmap: break; default: ThrowReaderException(CorruptImageError,"ImproperImageHeader"); } length=(size_t) (header.header_size-sz_XWDheader); comment=(char *) AcquireQuantumMemory(length+1,sizeof(*comment)); if (comment == (char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); count=ReadBlob(image,length,(unsigned char *) comment); comment[length]='\0'; (void) SetImageProperty(image,"comment",comment,exception); comment=DestroyString(comment); if (count != (ssize_t) length) ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); /* Initialize the X image. */ ximage=(XImage *) AcquireMagickMemory(sizeof(*ximage)); if (ximage == (XImage *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); ximage->depth=(int) header.pixmap_depth; ximage->format=(int) header.pixmap_format; ximage->xoffset=(int) header.xoffset; ximage->data=(char *) NULL; ximage->width=(int) header.pixmap_width; ximage->height=(int) header.pixmap_height; ximage->bitmap_pad=(int) header.bitmap_pad; ximage->bytes_per_line=(int) header.bytes_per_line; ximage->byte_order=(int) header.byte_order; ximage->bitmap_unit=(int) header.bitmap_unit; ximage->bitmap_bit_order=(int) header.bitmap_bit_order; ximage->bits_per_pixel=(int) header.bits_per_pixel; ximage->red_mask=header.red_mask; ximage->green_mask=header.green_mask; ximage->blue_mask=header.blue_mask; if ((ximage->width < 0) || (ximage->height < 0) || (ximage->depth < 0) || (ximage->format < 0) || (ximage->byte_order < 0) || (ximage->bitmap_bit_order < 0) || (ximage->bitmap_pad < 0) || (ximage->bytes_per_line < 0)) { ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(CorruptImageError,"ImproperImageHeader"); } if ((ximage->width > 65535) || (ximage->height > 65535)) { ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(CorruptImageError,"ImproperImageHeader"); } if ((ximage->bits_per_pixel > 32) || (ximage->bitmap_unit > 32)) { ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(CorruptImageError,"ImproperImageHeader"); } x_status=XInitImage(ximage); if (x_status == 0) { ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); } /* Read colormap. */ authentic_colormap=MagickFalse; colors=(XColor *) NULL; if (header.ncolors != 0) { XWDColor color; length=(size_t) header.ncolors; if (length > ((~0UL)/sizeof(*colors))) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); colors=(XColor *) AcquireQuantumMemory(length,sizeof(*colors)); if (colors == (XColor *) NULL) { ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } for (i=0; i < (ssize_t) header.ncolors; i++) { count=ReadBlob(image,sz_XWDColor,(unsigned char *) &color); if (count != sz_XWDColor) { colors=(XColor *) RelinquishMagickMemory(colors); ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); } colors[i].pixel=color.pixel; colors[i].red=color.red; colors[i].green=color.green; colors[i].blue=color.blue; colors[i].flags=(char) color.flags; if (color.flags != 0) authentic_colormap=MagickTrue; } /* Ensure the header byte-order is most-significant byte first. */ lsb_first=1; if ((int) (*(char *) &lsb_first) != 0) for (i=0; i < (ssize_t) header.ncolors; i++) { MSBOrderLong((unsigned char *) &colors[i].pixel, sizeof(colors[i].pixel)); MSBOrderShort((unsigned char *) &colors[i].red,3* sizeof(colors[i].red)); } } /* Allocate the pixel buffer. */ length=(size_t) ximage->bytes_per_line*ximage->height; if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height)) { if (header.ncolors != 0) colors=(XColor *) RelinquishMagickMemory(colors); ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(CorruptImageError,"ImproperImageHeader"); } if (ximage->format != ZPixmap) { size_t extent; extent=length; length*=ximage->depth; if (CheckOverflowException(length,extent,ximage->depth)) { if (header.ncolors != 0) colors=(XColor *) RelinquishMagickMemory(colors); ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(CorruptImageError,"ImproperImageHeader"); } } ximage->data=(char *) AcquireQuantumMemory(length,sizeof(*ximage->data)); if (ximage->data == (char *) NULL) { if (header.ncolors != 0) colors=(XColor *) RelinquishMagickMemory(colors); ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } count=ReadBlob(image,length,(unsigned char *) ximage->data); if (count != (ssize_t) length) { if (header.ncolors != 0) colors=(XColor *) RelinquishMagickMemory(colors); ximage->data=DestroyString(ximage->data); ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(CorruptImageError,"UnableToReadImageData"); } /* Convert image to MIFF format. */ image->columns=(size_t) ximage->width; image->rows=(size_t) ximage->height; image->depth=8; status=SetImageExtent(image,image->columns,image->rows,exception); if (status == MagickFalse) { if (header.ncolors != 0) colors=(XColor *) RelinquishMagickMemory(colors); ximage->data=DestroyString(ximage->data); ximage=(XImage *) RelinquishMagickMemory(ximage); return(DestroyImageList(image)); } if ((header.ncolors == 0U) || (ximage->red_mask != 0) || (ximage->green_mask != 0) || (ximage->blue_mask != 0)) image->storage_class=DirectClass; else image->storage_class=PseudoClass; image->colors=header.ncolors; if (image_info->ping == MagickFalse) switch (image->storage_class) { case DirectClass: default: { register size_t color; size_t blue_mask, blue_shift, green_mask, green_shift, red_mask, red_shift; /* Determine shift and mask for red, green, and blue. */ red_mask=ximage->red_mask; red_shift=0; while ((red_mask != 0) && ((red_mask & 0x01) == 0)) { red_mask>>=1; red_shift++; } green_mask=ximage->green_mask; green_shift=0; while ((green_mask != 0) && ((green_mask & 0x01) == 0)) { green_mask>>=1; green_shift++; } blue_mask=ximage->blue_mask; blue_shift=0; while ((blue_mask != 0) && ((blue_mask & 0x01) == 0)) { blue_mask>>=1; blue_shift++; } /* Convert X image to DirectClass packets. */ if ((image->colors != 0) && (authentic_colormap != MagickFalse)) for (y=0; y < (ssize_t) image->rows; y++) { q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { pixel=XGetPixel(ximage,(int) x,(int) y); index=(Quantum) ConstrainColormapIndex(image,(ssize_t) (pixel >> red_shift) & red_mask,exception); SetPixelRed(image,ScaleShortToQuantum( colors[(ssize_t) index].red),q); index=(Quantum) ConstrainColormapIndex(image,(ssize_t) (pixel >> green_shift) & green_mask,exception); SetPixelGreen(image,ScaleShortToQuantum( colors[(ssize_t) index].green),q); index=(Quantum) ConstrainColormapIndex(image,(ssize_t) (pixel >> blue_shift) & blue_mask,exception); SetPixelBlue(image,ScaleShortToQuantum( colors[(ssize_t) index].blue),q); q+=GetPixelChannels(image); } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } else for (y=0; y < (ssize_t) image->rows; y++) { q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { pixel=XGetPixel(ximage,(int) x,(int) y); color=(pixel >> red_shift) & red_mask; if (red_mask != 0) color=(color*65535UL)/red_mask; SetPixelRed(image,ScaleShortToQuantum((unsigned short) color),q); color=(pixel >> green_shift) & green_mask; if (green_mask != 0) color=(color*65535UL)/green_mask; SetPixelGreen(image,ScaleShortToQuantum((unsigned short) color), q); color=(pixel >> blue_shift) & blue_mask; if (blue_mask != 0) color=(color*65535UL)/blue_mask; SetPixelBlue(image,ScaleShortToQuantum((unsigned short) color),q); q+=GetPixelChannels(image); } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } break; } case PseudoClass: { /* Convert X image to PseudoClass packets. */ if (AcquireImageColormap(image,image->colors,exception) == MagickFalse) { if (header.ncolors != 0) colors=(XColor *) RelinquishMagickMemory(colors); ximage->data=DestroyString(ximage->data); ximage=(XImage *) RelinquishMagickMemory(ximage); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } for (i=0; i < (ssize_t) image->colors; i++) { image->colormap[i].red=(MagickRealType) ScaleShortToQuantum( colors[i].red); image->colormap[i].green=(MagickRealType) ScaleShortToQuantum( colors[i].green); image->colormap[i].blue=(MagickRealType) ScaleShortToQuantum( colors[i].blue); } for (y=0; y < (ssize_t) image->rows; y++) { q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { index=(Quantum) ConstrainColormapIndex(image,(ssize_t) XGetPixel(ximage,(int) x,(int) y),exception); SetPixelIndex(image,index,q); SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } break; } } /* Free image and colormap. */ if (header.ncolors != 0) colors=(XColor *) RelinquishMagickMemory(colors); ximage->data=DestroyString(ximage->data); ximage=(XImage *) RelinquishMagickMemory(ximage); if (EOFBlob(image) != MagickFalse) ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); (void) CloseBlob(image); return(GetFirstImageInList(image)); }
0
470,330
const char *__get_arch(r_bin_le_obj_t *bin) { switch (bin->header->cpu) { case 1: case 2: case 3: return "x86"; case 0x20: case 0x21: return "i860"; case 0x40: case 0x41: case 0x42: return "mips"; default: return "Unknown"; } }
0
33,462
static pyc_object *get_ref_object(RBuffer *buffer) { bool error = false; ut32 index = get_ut32 (buffer, &error); if (error) { return NULL; } if (index >= r_list_length (refs)) { return NULL; } pyc_object *obj = r_list_get_n (refs, index); return obj? copy_object (obj): NULL; }
0
136,445
juniper_mlppp_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_MLPPP; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; /* suppress Bundle-ID if frame was captured on a child-link * best indicator if the cookie looks like a proto */ if (ndo->ndo_eflag && EXTRACT_16BITS(&l2info.cookie) != PPP_OSI && EXTRACT_16BITS(&l2info.cookie) != (PPP_ADDRESS << 8 | PPP_CONTROL)) ND_PRINT((ndo, "Bundle-ID %u: ", l2info.bundle)); p+=l2info.header_len; /* first try the LSQ protos */ switch(l2info.proto) { case JUNIPER_LSQ_L3_PROTO_IPV4: /* IP traffic going to the RE would not have a cookie * -> this must be incoming IS-IS over PPP */ if (l2info.cookie[4] == (JUNIPER_LSQ_COOKIE_RE|JUNIPER_LSQ_COOKIE_DIR)) ppp_print(ndo, p, l2info.length); else ip_print(ndo, p, l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_IPV6: ip6_print(ndo, p,l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_MPLS: mpls_print(ndo, p, l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_ISO: isoclns_print(ndo, p, l2info.length); return l2info.header_len; default: break; } /* zero length cookie ? */ switch (EXTRACT_16BITS(&l2info.cookie)) { case PPP_OSI: ppp_print(ndo, p - 2, l2info.length + 2); break; case (PPP_ADDRESS << 8 | PPP_CONTROL): /* fall through */ default: ppp_print(ndo, p, l2info.length); break; } return l2info.header_len; }
0
413,144
catch(std::exception& e) { cerr<<"Receiver function died: "<<e.what()<<endl; exit(1); }
0
378,811
static SC_HTMLState sc_html_parse_tag(SC_HTMLParser *parser) { gchar buf[SC_HTMLBUFSIZE]; SC_HTMLTag *tag; sc_html_get_parenthesis(parser, buf, sizeof(buf)); tag = sc_html_get_tag(buf); parser->state = SC_HTML_UNKNOWN; if (!tag) return SC_HTML_UNKNOWN; if (!strcmp(tag->name, "br")) { parser->space = FALSE; sc_html_append_char(parser, '\n'); parser->state = SC_HTML_BR; } else if (!strcmp(tag->name, "a")) { GList *cur; for (cur = tag->attr; cur != NULL; cur = cur->next) { if (cur->data && !strcmp(((SC_HTMLAttr *)cur->data)->name, "href")) { g_free(parser->href); parser->href = g_strdup(((SC_HTMLAttr *)cur->data)->value); decode_href(parser); parser->state = SC_HTML_HREF_BEG; break; } } } else if (!strcmp(tag->name, "/a")) { parser->state = SC_HTML_HREF; } else if (!strcmp(tag->name, "p")) { parser->space = FALSE; if (!parser->empty_line) { parser->space = FALSE; if (!parser->newline) sc_html_append_char(parser, '\n'); sc_html_append_char(parser, '\n'); } parser->state = SC_HTML_PAR; } else if (!strcmp(tag->name, "pre")) { parser->pre = TRUE; parser->state = SC_HTML_PRE; } else if (!strcmp(tag->name, "/pre")) { parser->pre = FALSE; parser->state = SC_HTML_NORMAL; } else if (!strcmp(tag->name, "hr")) { if (!parser->newline) { parser->space = FALSE; sc_html_append_char(parser, '\n'); } sc_html_append_str(parser, HR_STR "\n", -1); parser->state = SC_HTML_HR; } else if (!strcmp(tag->name, "div") || !strcmp(tag->name, "ul") || !strcmp(tag->name, "li") || !strcmp(tag->name, "table") || !strcmp(tag->name, "tr") || (tag->name[0] == 'h' && g_ascii_isdigit(tag->name[1]))) { if (!parser->newline) { parser->space = FALSE; sc_html_append_char(parser, '\n'); } parser->state = SC_HTML_NORMAL; } else if (!strcmp(tag->name, "/table") || (tag->name[0] == '/' && tag->name[1] == 'h' && g_ascii_isdigit(tag->name[1]))) { if (!parser->empty_line) { parser->space = FALSE; if (!parser->newline) sc_html_append_char(parser, '\n'); sc_html_append_char(parser, '\n'); } parser->state = SC_HTML_NORMAL; } else if (!strcmp(tag->name, "/div") || !strcmp(tag->name, "/ul") || !strcmp(tag->name, "/li")) { if (!parser->newline) { parser->space = FALSE; sc_html_append_char(parser, '\n'); } parser->state = SC_HTML_NORMAL; } sc_html_free_tag(tag); return parser->state; }
0
123,886
static void ov518_configure(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; /* For 518 and 518+ */ static const struct ov_regvals init_518[] = { { R51x_SYS_RESET, 0x40 }, { R51x_SYS_INIT, 0xe1 }, { R51x_SYS_RESET, 0x3e }, { R51x_SYS_INIT, 0xe1 }, { R51x_SYS_RESET, 0x00 }, { R51x_SYS_INIT, 0xe1 }, { 0x46, 0x00 }, { 0x5d, 0x03 }, }; static const struct ov_regvals norm_518[] = { { R51x_SYS_SNAP, 0x02 }, /* Reset */ { R51x_SYS_SNAP, 0x01 }, /* Enable */ { 0x31, 0x0f }, { 0x5d, 0x03 }, { 0x24, 0x9f }, { 0x25, 0x90 }, { 0x20, 0x00 }, { 0x51, 0x04 }, { 0x71, 0x19 }, { 0x2f, 0x80 }, }; static const struct ov_regvals norm_518_p[] = { { R51x_SYS_SNAP, 0x02 }, /* Reset */ { R51x_SYS_SNAP, 0x01 }, /* Enable */ { 0x31, 0x0f }, { 0x5d, 0x03 }, { 0x24, 0x9f }, { 0x25, 0x90 }, { 0x20, 0x60 }, { 0x51, 0x02 }, { 0x71, 0x19 }, { 0x40, 0xff }, { 0x41, 0x42 }, { 0x46, 0x00 }, { 0x33, 0x04 }, { 0x21, 0x19 }, { 0x3f, 0x10 }, { 0x2f, 0x80 }, }; /* First 5 bits of custom ID reg are a revision ID on OV518 */ sd->revision = reg_r(sd, R51x_SYS_CUST_ID) & 0x1f; gspca_dbg(gspca_dev, D_PROBE, "Device revision %d\n", sd->revision); write_regvals(sd, init_518, ARRAY_SIZE(init_518)); /* Set LED GPIO pin to output mode */ reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02); switch (sd->bridge) { case BRIDGE_OV518: write_regvals(sd, norm_518, ARRAY_SIZE(norm_518)); break; case BRIDGE_OV518PLUS: write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p)); break; } ov51x_upload_quan_tables(sd); reg_w(sd, 0x2f, 0x80); }
0
276,377
bool Document::needsLayoutTreeUpdateForNode(const Node& node) const { if (!node.canParticipateInFlatTree()) return false; if (!needsLayoutTreeUpdate()) return false; if (!node.inShadowIncludingDocument()) return false; if (needsFullLayoutTreeUpdate() || node.needsStyleRecalc() || node.needsStyleInvalidation()) return true; for (const ContainerNode* ancestor = LayoutTreeBuilderTraversal::parent(node); ancestor; ancestor = LayoutTreeBuilderTraversal::parent(*ancestor)) { if (ancestor->needsStyleRecalc() || ancestor->needsStyleInvalidation() || ancestor->needsAdjacentStyleRecalc()) return true; } return false; }
0
95,935
u32 cdk_sk_get_keyid(cdk_pkt_seckey_t sk, u32 * keyid) { u32 lowbits = 0; if (sk && sk->pk) { lowbits = cdk_pk_get_keyid(sk->pk, keyid); sk->keyid[0] = sk->pk->keyid[0]; sk->keyid[1] = sk->pk->keyid[1]; } return lowbits; }
0
224,752
XvImageFormatValues * XvMCListSubpictureTypes ( Display * dpy, XvPortID port, int surface_type_id, int *count_return ) { XExtDisplayInfo *info = xvmc_find_display(dpy); xvmcListSubpictureTypesReply rep; xvmcListSubpictureTypesReq *req; XvImageFormatValues *ret = NULL; *count_return = 0; XvMCCheckExtension (dpy, info, NULL); LockDisplay (dpy); XvMCGetReq (ListSubpictureTypes, req); req->port = port; req->surface_type_id = surface_type_id; if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { UnlockDisplay (dpy); SyncHandle (); return NULL; } if(rep.num > 0) { if (rep.num < (INT_MAX / sizeof(XvImageFormatValues))) ret = Xmalloc(rep.num * sizeof(XvImageFormatValues)); if(ret) { xvImageFormatInfo Info; int i; *count_return = rep.num; for(i = 0; i < rep.num; i++) { _XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo); ret[i].id = Info.id; ret[i].type = Info.type; ret[i].byte_order = Info.byte_order; memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16); ret[i].bits_per_pixel = Info.bpp; ret[i].format = Info.format; ret[i].num_planes = Info.num_planes; ret[i].depth = Info.depth; ret[i].red_mask = Info.red_mask; ret[i].green_mask = Info.green_mask; ret[i].blue_mask = Info.blue_mask; ret[i].y_sample_bits = Info.y_sample_bits; ret[i].u_sample_bits = Info.u_sample_bits; ret[i].v_sample_bits = Info.v_sample_bits; ret[i].horz_y_period = Info.horz_y_period; ret[i].horz_u_period = Info.horz_u_period; ret[i].horz_v_period = Info.horz_v_period; ret[i].vert_y_period = Info.vert_y_period; ret[i].vert_u_period = Info.vert_u_period; ret[i].vert_v_period = Info.vert_v_period; memcpy(&(ret[i].component_order[0]), &(Info.comp_order[0]), 32); ret[i].scanline_order = Info.scanline_order; } } else _XEatDataWords(dpy, rep.length); } UnlockDisplay (dpy); SyncHandle (); return ret; }
0
416,503
c_pdf14trans_is_closing(const gs_composite_t * composite_action, gs_composite_t ** ppcte, gx_device *dev) { gs_pdf14trans_t *pct0 = (gs_pdf14trans_t *)composite_action; int op0 = pct0->params.pdf14_op; switch (op0) { default: return_error(gs_error_unregistered); /* Must not happen. */ case PDF14_PUSH_DEVICE: return COMP_ENQUEUE; case PDF14_ABORT_DEVICE: return COMP_ENQUEUE; case PDF14_POP_DEVICE: if (*ppcte == NULL) return COMP_ENQUEUE; else { gs_compositor_closing_state state = find_opening_op(PDF14_PUSH_DEVICE, ppcte, COMP_EXEC_IDLE); if (state == COMP_EXEC_IDLE) return COMP_DROP_QUEUE; return state; } case PDF14_BEGIN_TRANS_GROUP: return COMP_ENQUEUE; case PDF14_END_TRANS_GROUP: case PDF14_END_TRANS_TEXT_GROUP: if (*ppcte == NULL) return COMP_EXEC_QUEUE; return find_opening_op(PDF14_BEGIN_TRANS_GROUP, ppcte, COMP_MARK_IDLE); case PDF14_BEGIN_TRANS_MASK: return COMP_ENQUEUE; case PDF14_PUSH_TRANS_STATE: return COMP_ENQUEUE; case PDF14_POP_TRANS_STATE: return COMP_ENQUEUE; case PDF14_PUSH_SMASK_COLOR: return COMP_ENQUEUE; break; case PDF14_POP_SMASK_COLOR: return COMP_ENQUEUE; break; case PDF14_END_TRANS_MASK: if (*ppcte == NULL) return COMP_EXEC_QUEUE; return find_opening_op(PDF14_BEGIN_TRANS_MASK, ppcte, COMP_MARK_IDLE); case PDF14_SET_BLEND_PARAMS: if (*ppcte == NULL) return COMP_ENQUEUE; /* hack : ignore csel - here it is always zero : */ return find_same_op(composite_action, PDF14_SET_BLEND_PARAMS, ppcte); } }
0
484,364
void JBIG2Stream::resetGenericStats(unsigned int templ, JArithmeticDecoderStats *prevStats) { int size; size = contextSize[templ]; if (prevStats && prevStats->getContextSize() == size) { if (genericRegionStats->getContextSize() == size) { genericRegionStats->copyFrom(prevStats); } else { delete genericRegionStats; genericRegionStats = prevStats->copy(); } } else { if (genericRegionStats->getContextSize() == size) { genericRegionStats->reset(); } else { delete genericRegionStats; genericRegionStats = new JArithmeticDecoderStats(1 << size); } } }
0
227,093
void StackTrace::OutputToStream(std::ostream* os) const { StreamBacktraceOutputHandler handler(os); ProcessBacktrace(trace_, count_, &handler); }
0
24,431
void main_file_cleanup ( main_file * xfile ) { XD3_ASSERT ( xfile != NULL ) ; if ( main_file_isopen ( xfile ) ) { main_file_close ( xfile ) ; } if ( xfile -> snprintf_buf != NULL ) { main_free ( xfile -> snprintf_buf ) ; xfile -> snprintf_buf = NULL ; } if ( xfile -> filename_copy != NULL ) { main_free ( xfile -> filename_copy ) ; xfile -> filename_copy = NULL ; } }
0
307,612
CompositingReasons RenderLayerCompositor::directReasonsForCompositing(const RenderLayer* layer) const { RenderObject* renderer = layer->renderer(); CompositingReasons directReasons = CompositingReasonNone; if (requiresCompositingForTransform(renderer)) directReasons |= CompositingReason3DTransform; if (requiresCompositingForVideo(renderer)) directReasons |= CompositingReasonVideo; else if (requiresCompositingForCanvas(renderer)) directReasons |= CompositingReasonCanvas; else if (requiresCompositingForPlugin(renderer)) directReasons |= CompositingReasonPlugin; else if (requiresCompositingForFrame(renderer)) directReasons |= CompositingReasonIFrame; if (requiresCompositingForBackfaceVisibilityHidden(renderer)) directReasons |= CompositingReasonBackfaceVisibilityHidden; if (requiresCompositingForAnimation(renderer)) directReasons |= CompositingReasonAnimation; if (requiresCompositingForTransition(renderer)) directReasons |= CompositingReasonAnimation; if (requiresCompositingForFilters(renderer)) directReasons |= CompositingReasonFilters; if (requiresCompositingForPosition(renderer, layer)) directReasons |= renderer->style()->position() == FixedPosition ? CompositingReasonPositionFixed : CompositingReasonPositionSticky; if (requiresCompositingForOverflowScrolling(layer)) directReasons |= CompositingReasonOverflowScrollingTouch; if (requiresCompositingForOverflowScrollingParent(layer)) directReasons |= CompositingReasonOverflowScrollingParent; if (requiresCompositingForOutOfFlowClipping(layer)) directReasons |= CompositingReasonOutOfFlowClipping; return directReasons; }
0
138,474
static HuffReader *get_huffman_group(WebPContext *s, ImageContext *img, int x, int y) { ImageContext *gimg = &s->image[IMAGE_ROLE_ENTROPY]; int group = 0; if (gimg->size_reduction > 0) { int group_x = x >> gimg->size_reduction; int group_y = y >> gimg->size_reduction; int g0 = GET_PIXEL_COMP(gimg->frame, group_x, group_y, 1); int g1 = GET_PIXEL_COMP(gimg->frame, group_x, group_y, 2); group = g0 << 8 | g1; } return &img->huffman_groups[group * HUFFMAN_CODES_PER_META_CODE]; }
0
214,203
TopSitesImpl* top_sites() { return top_sites_impl_.get(); }
0
105,582
void DeallocatorWrapperFunc(void* data, size_t len, void* dlmt_vptr) { TFE_CallDLManagedTensorDeleter(dlmt_vptr); }
0
87,965
static void MSLIgnorableWhitespace(void *context,const xmlChar *c,int length) { MSLInfo *msl_info; /* Receiving some ignorable whitespaces from the parser. */ (void) LogMagickEvent(CoderEvent,GetMagickModule(), " SAX.ignorableWhitespace(%.30s, %d)",c,length); msl_info=(MSLInfo *) context; (void) msl_info; }
0
230,818
bool ID3::removeUnsynchronizationV2_4(bool iTunesHack) { size_t oldSize = mSize; size_t offset = 0; while (mSize >= 10 && offset <= mSize - 10) { if (!memcmp(&mData[offset], "\0\0\0\0", 4)) { break; } size_t dataSize; if (iTunesHack) { dataSize = U32_AT(&mData[offset + 4]); } else if (!ParseSyncsafeInteger(&mData[offset + 4], &dataSize)) { return false; } if (dataSize > mSize - 10 - offset) { return false; } uint16_t flags = U16_AT(&mData[offset + 8]); uint16_t prevFlags = flags; if (flags & 1) { if (mSize < 14 || mSize - 14 < offset || dataSize < 4) { return false; } memmove(&mData[offset + 10], &mData[offset + 14], mSize - offset - 14); mSize -= 4; dataSize -= 4; flags &= ~1; } if ((flags & 2) && (dataSize >= 2)) { size_t readOffset = offset + 11; size_t writeOffset = offset + 11; for (size_t i = 0; i + 1 < dataSize; ++i) { if (mData[readOffset - 1] == 0xff && mData[readOffset] == 0x00) { ++readOffset; --mSize; --dataSize; } if (i + 1 < dataSize) { // Only move data if there's actually something to move. // This handles the special case of the data being only [0xff, 0x00] // which should be converted to just 0xff if unsynchronization is on. mData[writeOffset++] = mData[readOffset++]; } } if (readOffset <= oldSize) { memmove(&mData[writeOffset], &mData[readOffset], oldSize - readOffset); } else { ALOGE("b/34618607 (%zu %zu %zu %zu)", readOffset, writeOffset, oldSize, mSize); android_errorWriteLog(0x534e4554, "34618607"); } } flags &= ~2; if (flags != prevFlags || iTunesHack) { WriteSyncsafeInteger(&mData[offset + 4], dataSize); mData[offset + 8] = flags >> 8; mData[offset + 9] = flags & 0xff; } offset += 10 + dataSize; } memset(&mData[mSize], 0, oldSize - mSize); return true; }
0
184,190
static void checkMutexEnter(sqlite3_mutex *p){ CheckMutex *pCheck = (CheckMutex*)p; if( pCheck->iType==SQLITE_MUTEX_WARNONCONTENTION ){ if( SQLITE_OK==pGlobalMutexMethods->xMutexTry(pCheck->mutex) ){ return; } sqlite3_log(SQLITE_MISUSE, "illegal multi-threaded access to database connection" ); } pGlobalMutexMethods->xMutexEnter(pCheck->mutex); }
0
218,350
static v8::Persistent<v8::FunctionTemplate> ConfigureV8Float64ArrayTemplate(v8::Persistent<v8::FunctionTemplate> desc) { desc->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = configureTemplate(desc, "Float64Array", V8ArrayBufferView::GetTemplate(), V8Float64Array::internalFieldCount, 0, 0, 0, 0); UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. desc->SetCallHandler(V8Float64Array::constructorCallback); v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate(); v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate(); UNUSED_PARAM(instance); // In some cases, it will not be used. UNUSED_PARAM(proto); // In some cases, it will not be used. const int fooArgc = 1; v8::Handle<v8::FunctionTemplate> fooArgv[fooArgc] = { V8Float32Array::GetRawTemplate() }; v8::Handle<v8::Signature> fooSignature = v8::Signature::New(desc, fooArgc, fooArgv); proto->Set(v8::String::New("foo"), v8::FunctionTemplate::New(Float64ArrayV8Internal::fooCallback, v8::Handle<v8::Value>(), fooSignature)); desc->Set(getToStringName(), getToStringTemplate()); return desc; }
0
16,927
int ff_MPV_frame_start ( MpegEncContext * s , AVCodecContext * avctx ) { int i , ret ; Picture * pic ; s -> mb_skipped = 0 ; if ( s -> out_format != FMT_H264 || s -> codec_id == AV_CODEC_ID_SVQ3 ) { if ( s -> pict_type != AV_PICTURE_TYPE_B && s -> last_picture_ptr && s -> last_picture_ptr != s -> next_picture_ptr && s -> last_picture_ptr -> f . data [ 0 ] ) { ff_mpeg_unref_picture ( s , s -> last_picture_ptr ) ; } if ( ! s -> encoding ) { for ( i = 0 ; i < MAX_PICTURE_COUNT ; i ++ ) { if ( & s -> picture [ i ] != s -> last_picture_ptr && & s -> picture [ i ] != s -> next_picture_ptr && s -> picture [ i ] . reference && ! s -> picture [ i ] . needs_realloc ) { if ( ! ( avctx -> active_thread_type & FF_THREAD_FRAME ) ) av_log ( avctx , AV_LOG_ERROR , "releasing zombie picture\n" ) ; ff_mpeg_unref_picture ( s , & s -> picture [ i ] ) ; } } } } if ( ! s -> encoding ) { ff_release_unused_pictures ( s , 1 ) ; if ( s -> current_picture_ptr && s -> current_picture_ptr -> f . data [ 0 ] == NULL ) { pic = s -> current_picture_ptr ; } else { i = ff_find_unused_picture ( s , 0 ) ; if ( i < 0 ) { av_log ( s -> avctx , AV_LOG_ERROR , "no frame buffer available\n" ) ; return i ; } pic = & s -> picture [ i ] ; } pic -> reference = 0 ; if ( ! s -> droppable ) { if ( s -> codec_id == AV_CODEC_ID_H264 ) pic -> reference = s -> picture_structure ; else if ( s -> pict_type != AV_PICTURE_TYPE_B ) pic -> reference = 3 ; } pic -> f . coded_picture_number = s -> coded_picture_number ++ ; if ( ff_alloc_picture ( s , pic , 0 ) < 0 ) return - 1 ; s -> current_picture_ptr = pic ; s -> current_picture_ptr -> f . top_field_first = s -> top_field_first ; if ( s -> codec_id == AV_CODEC_ID_MPEG1VIDEO || s -> codec_id == AV_CODEC_ID_MPEG2VIDEO ) { if ( s -> picture_structure != PICT_FRAME ) s -> current_picture_ptr -> f . top_field_first = ( s -> picture_structure == PICT_TOP_FIELD ) == s -> first_field ; } s -> current_picture_ptr -> f . interlaced_frame = ! s -> progressive_frame && ! s -> progressive_sequence ; s -> current_picture_ptr -> field_picture = s -> picture_structure != PICT_FRAME ; } s -> current_picture_ptr -> f . pict_type = s -> pict_type ; s -> current_picture_ptr -> f . key_frame = s -> pict_type == AV_PICTURE_TYPE_I ; ff_mpeg_unref_picture ( s , & s -> current_picture ) ; if ( ( ret = ff_mpeg_ref_picture ( s , & s -> current_picture , s -> current_picture_ptr ) ) < 0 ) return ret ; if ( s -> codec_id != AV_CODEC_ID_H264 && s -> pict_type != AV_PICTURE_TYPE_B ) { s -> last_picture_ptr = s -> next_picture_ptr ; if ( ! s -> droppable ) s -> next_picture_ptr = s -> current_picture_ptr ; } av_dlog ( s -> avctx , "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n" , s -> last_picture_ptr , s -> next_picture_ptr , s -> current_picture_ptr , s -> last_picture_ptr ? s -> last_picture_ptr -> f . data [ 0 ] : NULL , s -> next_picture_ptr ? s -> next_picture_ptr -> f . data [ 0 ] : NULL , s -> current_picture_ptr ? s -> current_picture_ptr -> f . data [ 0 ] : NULL , s -> pict_type , s -> droppable ) ; if ( s -> codec_id != AV_CODEC_ID_H264 ) { if ( ( s -> last_picture_ptr == NULL || s -> last_picture_ptr -> f . data [ 0 ] == NULL ) && ( s -> pict_type != AV_PICTURE_TYPE_I || s -> picture_structure != PICT_FRAME ) ) { int h_chroma_shift , v_chroma_shift ; av_pix_fmt_get_chroma_sub_sample ( s -> avctx -> pix_fmt , & h_chroma_shift , & v_chroma_shift ) ; if ( s -> pict_type != AV_PICTURE_TYPE_I ) av_log ( avctx , AV_LOG_ERROR , "warning: first frame is no keyframe\n" ) ; else if ( s -> picture_structure != PICT_FRAME ) av_log ( avctx , AV_LOG_INFO , "allocate dummy last picture for field based first keyframe\n" ) ; i = ff_find_unused_picture ( s , 0 ) ; if ( i < 0 ) { av_log ( s -> avctx , AV_LOG_ERROR , "no frame buffer available\n" ) ; return i ; } s -> last_picture_ptr = & s -> picture [ i ] ; if ( ff_alloc_picture ( s , s -> last_picture_ptr , 0 ) < 0 ) { s -> last_picture_ptr = NULL ; return - 1 ; } memset ( s -> last_picture_ptr -> f . data [ 0 ] , 0 , avctx -> height * s -> last_picture_ptr -> f . linesize [ 0 ] ) ; memset ( s -> last_picture_ptr -> f . data [ 1 ] , 0x80 , ( avctx -> height >> v_chroma_shift ) * s -> last_picture_ptr -> f . linesize [ 1 ] ) ; memset ( s -> last_picture_ptr -> f . data [ 2 ] , 0x80 , ( avctx -> height >> v_chroma_shift ) * s -> last_picture_ptr -> f . linesize [ 2 ] ) ; ff_thread_report_progress ( & s -> last_picture_ptr -> tf , INT_MAX , 0 ) ; ff_thread_report_progress ( & s -> last_picture_ptr -> tf , INT_MAX , 1 ) ; } if ( ( s -> next_picture_ptr == NULL || s -> next_picture_ptr -> f . data [ 0 ] == NULL ) && s -> pict_type == AV_PICTURE_TYPE_B ) { i = ff_find_unused_picture ( s , 0 ) ; if ( i < 0 ) { av_log ( s -> avctx , AV_LOG_ERROR , "no frame buffer available\n" ) ; return i ; } s -> next_picture_ptr = & s -> picture [ i ] ; if ( ff_alloc_picture ( s , s -> next_picture_ptr , 0 ) < 0 ) { s -> next_picture_ptr = NULL ; return - 1 ; } ff_thread_report_progress ( & s -> next_picture_ptr -> tf , INT_MAX , 0 ) ; ff_thread_report_progress ( & s -> next_picture_ptr -> tf , INT_MAX , 1 ) ; } } if ( s -> codec_id != AV_CODEC_ID_H264 ) { if ( s -> last_picture_ptr ) { ff_mpeg_unref_picture ( s , & s -> last_picture ) ; if ( s -> last_picture_ptr -> f . data [ 0 ] && ( ret = ff_mpeg_ref_picture ( s , & s -> last_picture , s -> last_picture_ptr ) ) < 0 ) return ret ; } if ( s -> next_picture_ptr ) { ff_mpeg_unref_picture ( s , & s -> next_picture ) ; if ( s -> next_picture_ptr -> f . data [ 0 ] && ( ret = ff_mpeg_ref_picture ( s , & s -> next_picture , s -> next_picture_ptr ) ) < 0 ) return ret ; } assert ( s -> pict_type == AV_PICTURE_TYPE_I || ( s -> last_picture_ptr && s -> last_picture_ptr -> f . data [ 0 ] ) ) ; } if ( s -> picture_structure != PICT_FRAME && s -> out_format != FMT_H264 ) { int i ; for ( i = 0 ; i < 4 ; i ++ ) { if ( s -> picture_structure == PICT_BOTTOM_FIELD ) { s -> current_picture . f . data [ i ] += s -> current_picture . f . linesize [ i ] ; } s -> current_picture . f . linesize [ i ] *= 2 ; s -> last_picture . f . linesize [ i ] *= 2 ; s -> next_picture . f . linesize [ i ] *= 2 ; } } s -> err_recognition = avctx -> err_recognition ; if ( s -> mpeg_quant || s -> codec_id == AV_CODEC_ID_MPEG2VIDEO ) { s -> dct_unquantize_intra = s -> dct_unquantize_mpeg2_intra ; s -> dct_unquantize_inter = s -> dct_unquantize_mpeg2_inter ; } else if ( s -> out_format == FMT_H263 || s -> out_format == FMT_H261 ) { s -> dct_unquantize_intra = s -> dct_unquantize_h263_intra ; s -> dct_unquantize_inter = s -> dct_unquantize_h263_inter ; } else { s -> dct_unquantize_intra = s -> dct_unquantize_mpeg1_intra ; s -> dct_unquantize_inter = s -> dct_unquantize_mpeg1_inter ; } if ( s -> dct_error_sum ) { assert ( s -> avctx -> noise_reduction && s -> encoding ) ; update_noise_reduction ( s ) ; } if ( CONFIG_MPEG_XVMC_DECODER && s -> avctx -> xvmc_acceleration ) return ff_xvmc_field_start ( s , avctx ) ; return 0 ; }
0
231,599
bool ScriptOnly(const Extension* extension, const GURL& url, const GURL& top_url, int tab_id) { return AllowedScript(extension, url, top_url, tab_id) && !extension->permissions_data()->CanCaptureVisiblePage(tab_id, NULL); }
0
264,719
DEFUN(deletePrevBuf, DELETE_PREVBUF, "Delete previous buffer (mainly for local CGI-scripts)") { Buffer *buf = Currentbuf->nextBuffer; if (buf) delBuffer(buf); }
0
117,310
void streamEncodeID(void *buf, streamID *id) { uint64_t e[2]; e[0] = htonu64(id->ms); e[1] = htonu64(id->seq); memcpy(buf,e,sizeof(e)); }
0
190,231
Tab::Tab(TabController* controller) : controller_(controller), title_(new views::Label()), title_animation_(this) { DCHECK(controller); tab_style_ = TabStyleViews::CreateForTab(this); set_notify_enter_exit_on_child(true); SetID(VIEW_ID_TAB); SetBorder(views::CreateEmptyBorder(tab_style()->GetContentsInsets())); title_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); title_->SetElideBehavior(gfx::FADE_TAIL); title_->SetHandlesTooltips(false); title_->SetAutoColorReadabilityEnabled(false); title_->SetText(CoreTabHelper::GetDefaultTitle()); AddChildView(title_); SetEventTargeter(std::make_unique<views::ViewTargeter>(this)); icon_ = new TabIcon; AddChildView(icon_); alert_indicator_ = new AlertIndicator(this); AddChildView(alert_indicator_); close_button_ = new TabCloseButton( this, base::BindRepeating(&TabController::OnMouseEventInTab, base::Unretained(controller_))); AddChildView(close_button_); close_button_->AddObserver(this); set_context_menu_controller(this); title_animation_.SetDuration(base::TimeDelta::FromMilliseconds(100)); SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); focus_ring_ = views::FocusRing::Install(this); }
0
420,455
void CLASS process_Sony_0x9403(uchar *buf, ushort len) { if (len < 6) return; uchar bufx = SonySubstitution[buf[4]]; if ((bufx == 0x00) || (bufx == 0x94)) return; imgdata.other.SensorTemperature = (float)((short)SonySubstitution[buf[5]]); return; }
0
508,734
_set_source_rsvg_solid_colour (RsvgDrawingCtx * ctx, RsvgSolidColour * colour, guint8 opacity, guint32 current_colour) { RsvgCairoRender *render = RSVG_CAIRO_RENDER (ctx->render); cairo_t *cr = render->cr; guint32 argb = colour->argb; double r, g, b, a; if (colour->currentcolour) argb = current_colour; r = ((argb >> 16) & 0xff) / 255.0; g = ((argb >> 8) & 0xff) / 255.0; b = ((argb >> 0) & 0xff) / 255.0; a = (argb >> 24) / 255.0 * (opacity / 255.0); cairo_set_source_rgba (cr, r, g, b, a); }
0
153,777
stack_double(int is_alloca, char** arg_alloc_base, StackType** arg_stk_base, StackType** arg_stk_end, StackType** arg_stk, MatchArg* msa) { unsigned int n; int used; size_t size; size_t new_size; char* alloc_base; char* new_alloc_base; StackType *stk_base, *stk_end, *stk; alloc_base = *arg_alloc_base; stk_base = *arg_stk_base; stk_end = *arg_stk_end; stk = *arg_stk; n = (unsigned int )(stk_end - stk_base); size = sizeof(StackIndex) * msa->ptr_num + sizeof(StackType) * n; n *= 2; new_size = sizeof(StackIndex) * msa->ptr_num + sizeof(StackType) * n; if (is_alloca != 0) { new_alloc_base = (char* )xmalloc(new_size); if (IS_NULL(new_alloc_base)) { STACK_SAVE; return ONIGERR_MEMORY; } xmemcpy(new_alloc_base, alloc_base, size); } else { if (msa->match_stack_limit != 0 && n > msa->match_stack_limit) { if ((unsigned int )(stk_end - stk_base) == msa->match_stack_limit) return ONIGERR_MATCH_STACK_LIMIT_OVER; else n = msa->match_stack_limit; } new_alloc_base = (char* )xrealloc(alloc_base, new_size); if (IS_NULL(new_alloc_base)) { STACK_SAVE; return ONIGERR_MEMORY; } } alloc_base = new_alloc_base; used = (int )(stk - stk_base); *arg_alloc_base = alloc_base; *arg_stk_base = (StackType* )(alloc_base + (sizeof(StackIndex) * msa->ptr_num)); *arg_stk = *arg_stk_base + used; *arg_stk_end = *arg_stk_base + n; return 0; }
0
381,480
set_debug (void) { int numok = (debug_level && digitp (debug_level)); int numlvl = numok? atoi (debug_level) : 0; if (!debug_level) ; else if (!strcmp (debug_level, "none") || (numok && numlvl < 1)) opt.debug = 0; else if (!strcmp (debug_level, "basic") || (numok && numlvl <= 2)) opt.debug = DBG_ASSUAN_VALUE; else if (!strcmp (debug_level, "advanced") || (numok && numlvl <= 5)) opt.debug = DBG_ASSUAN_VALUE|DBG_X509_VALUE; else if (!strcmp (debug_level, "expert") || (numok && numlvl <= 8)) opt.debug = (DBG_ASSUAN_VALUE|DBG_X509_VALUE |DBG_CACHE_VALUE|DBG_CRYPTO_VALUE); else if (!strcmp (debug_level, "guru") || numok) { opt.debug = ~0; /* Unless the "guru" string has been used we don't want to allow hashing debugging. The rationale is that people tend to select the highest debug value and would then clutter their disk with debug files which may reveal confidential data. */ if (numok) opt.debug &= ~(DBG_HASHING_VALUE); } else { log_error (_("invalid debug-level '%s' given\n"), debug_level); gpgsm_exit (2); } opt.debug |= debug_value; if (opt.debug && !opt.verbose) opt.verbose = 1; if (opt.debug) opt.quiet = 0; if (opt.debug & DBG_MPI_VALUE) gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 2); if (opt.debug & DBG_CRYPTO_VALUE ) gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1); gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose); if (opt.debug) log_info ("enabled debug flags:%s%s%s%s%s%s%s%s\n", (opt.debug & DBG_X509_VALUE )? " x509":"", (opt.debug & DBG_MPI_VALUE )? " mpi":"", (opt.debug & DBG_CRYPTO_VALUE )? " crypto":"", (opt.debug & DBG_MEMORY_VALUE )? " memory":"", (opt.debug & DBG_CACHE_VALUE )? " cache":"", (opt.debug & DBG_MEMSTAT_VALUE)? " memstat":"", (opt.debug & DBG_HASHING_VALUE)? " hashing":"", (opt.debug & DBG_ASSUAN_VALUE )? " assuan":"" ); }
0
287,798
bool asn1_read_BOOLEAN(struct asn1_data *data, bool *v) { uint8_t tmp = 0; asn1_start_tag(data, ASN1_BOOLEAN); asn1_read_uint8(data, &tmp); if (tmp == 0xFF) { *v = true; } else { *v = false; } asn1_end_tag(data); return !data->has_error; }
1
41,276
static void rfcomm_tty_throttle(struct tty_struct *tty) { struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data; BT_DBG("tty %p dev %p", tty, dev); rfcomm_dlc_throttle(dev->dlc); }
0
233,976
static bool ExecuteJustifyRight(LocalFrame& frame, Event*, EditorCommandSource source, const String&) { return ExecuteApplyParagraphStyle(frame, source, InputEvent::InputType::kFormatJustifyRight, CSSPropertyTextAlign, "right"); }
0
120,066
void ByteCodeGenerator::EmitClassConstructorEndCode(FuncInfo *funcInfo) { if (funcInfo->thisPointerRegister != Js::Constants::NoRegister) { // We need to try and load 'this' from the scope slot, if there is one. EmitScopeSlotLoadThis(funcInfo, funcInfo->thisPointerRegister); this->Writer()->Reg2(Js::OpCode::Ld_A, ByteCodeGenerator::ReturnRegister, funcInfo->thisPointerRegister); } }
0
412,022
relpTcpSetRemHost(relpTcp_t *pThis, struct sockaddr *pAddr) { relpEngine_t *pEngine; int error; unsigned char szIP[NI_MAXHOST] = ""; unsigned char szHname[NI_MAXHOST] = ""; struct addrinfo hints, *res; size_t len; ENTER_RELPFUNC; RELPOBJ_assert(pThis, Tcp); pEngine = pThis->pEngine; assert(pAddr != NULL); error = getnameinfo(pAddr, SALEN(pAddr), (char*)szIP, sizeof(szIP), NULL, 0, NI_NUMERICHOST); if(error) { pThis->pEngine->dbgprint("Malformed from address %s\n", gai_strerror(error)); strcpy((char*)szHname, "???"); strcpy((char*)szIP, "???"); ABORT_FINALIZE(RELP_RET_INVALID_HNAME); } if(pEngine->bEnableDns) { error = getnameinfo(pAddr, SALEN(pAddr), (char*)szHname, sizeof(szHname), NULL, 0, NI_NAMEREQD); if(error == 0) { memset (&hints, 0, sizeof (struct addrinfo)); hints.ai_flags = AI_NUMERICHOST; hints.ai_socktype = SOCK_STREAM; /* we now do a lookup once again. This one should fail, * because we should not have obtained a non-numeric address. If * we got a numeric one, someone messed with DNS! */ if(getaddrinfo((char*)szHname, NULL, &hints, &res) == 0) { freeaddrinfo (res); /* OK, we know we have evil, so let's indicate this to our caller */ snprintf((char*)szHname, NI_MAXHOST, "[MALICIOUS:IP=%s]", szIP); pEngine->dbgprint("Malicious PTR record, IP = \"%s\" HOST = \"%s\"", szIP, szHname); iRet = RELP_RET_MALICIOUS_HNAME; } } else { strcpy((char*)szHname, (char*)szIP); } } else { strcpy((char*)szHname, (char*)szIP); } /* We now have the names, so now let's allocate memory and store them permanently. * (side note: we may hold on to these values for quite a while, thus we trim their * memory consumption) */ len = strlen((char*)szIP) + 1; /* +1 for \0 byte */ if((pThis->pRemHostIP = malloc(len)) == NULL) ABORT_FINALIZE(RELP_RET_OUT_OF_MEMORY); memcpy(pThis->pRemHostIP, szIP, len); len = strlen((char*)szHname) + 1; /* +1 for \0 byte */ if((pThis->pRemHostName = malloc(len)) == NULL) { free(pThis->pRemHostIP); /* prevent leak */ pThis->pRemHostIP = NULL; ABORT_FINALIZE(RELP_RET_OUT_OF_MEMORY); } memcpy(pThis->pRemHostName, szHname, len); finalize_it: LEAVE_RELPFUNC; }
0
415,708
char *put_dec_full8(char *buf, unsigned r) { unsigned q; /* 0 <= r < 10^8 */ q = (r * (u64)0x28f5c29) >> 32; *((u16 *)buf) = decpair[r - 100*q]; buf += 2; /* 0 <= q < 10^6 */ r = (q * (u64)0x28f5c29) >> 32; *((u16 *)buf) = decpair[q - 100*r]; buf += 2; /* 0 <= r < 10^4 */ q = (r * 0x147b) >> 19; *((u16 *)buf) = decpair[r - 100*q]; buf += 2; /* 0 <= q < 100 */ *((u16 *)buf) = decpair[q]; buf += 2; return buf; }
0
31,578
GraphConstructor(const Options& opts, Graph* g, ShapeRefiner* refiner, std::vector<std::pair<Node*, int>>* return_tensors, std::vector<Node*>* return_nodes, std::vector<SafeTensorId>* missing_unused_input_map_keys) : opts_(opts), g_(g), original_versions_(g->versions()), prefix_(opts.prefix), refiner_(refiner), return_tensors_(return_tensors), return_nodes_(return_nodes), missing_unused_input_map_keys_(missing_unused_input_map_keys) {}
0
167,826
static int ssh_comp_none_block(void *handle, unsigned char *block, int len, unsigned char **outblock, int *outlen) { return 0; }
0
209,757
bool RenderBox::sizesLogicalWidthToFitContent(const Length& logicalWidth) const { if (isFloating() || (isInlineBlockOrInlineTable() && !isMarquee())) return true; if (logicalWidth.type() == Intrinsic) return true; if (parent()->isMarquee()) { EMarqueeDirection dir = parent()->style()->marqueeDirection(); if (dir == MAUTO || dir == MFORWARD || dir == MBACKWARD || dir == MLEFT || dir == MRIGHT) return true; } if (parent()->isFlexibleBox()) { if (!parent()->style()->isColumnFlexDirection() || parent()->style()->flexWrap() != FlexNoWrap) return true; if (!columnFlexItemHasStretchAlignment(this)) return true; } if (parent()->isDeprecatedFlexibleBox() && (parent()->style()->boxOrient() == HORIZONTAL || parent()->style()->boxAlign() != BSTRETCH)) return true; if (logicalWidth.isAuto() && !isStretchingColumnFlexItem(this) && autoWidthShouldFitContent()) return true; if (isHorizontalWritingMode() != containingBlock()->isHorizontalWritingMode()) return true; return false; }
0
318,776
static AVFilterBufferRef *copy_buffer_ref(AVFilterContext *ctx, AVFilterBufferRef *ref) { AVFilterLink *outlink = ctx->outputs[0]; AVFilterBufferRef *buf; int channels, data_size, i; switch (outlink->type) { case AVMEDIA_TYPE_VIDEO: buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, ref->video->w, ref->video->h); av_image_copy(buf->data, buf->linesize, (void*)ref->data, ref->linesize, ref->format, ref->video->w, ref->video->h); break; case AVMEDIA_TYPE_AUDIO: buf = ff_get_audio_buffer(outlink, AV_PERM_WRITE, ref->audio->nb_samples); channels = av_get_channel_layout_nb_channels(ref->audio->channel_layout); av_samples_copy(buf->extended_data, ref->buf->extended_data, 0, 0, ref->audio->nb_samples, channels, ref->format); break; default: } avfilter_copy_buffer_ref_props(buf, ref); return buf; }
1
57,205
static QSvgNode *createTextAreaNode(QSvgNode *parent, const QXmlStreamAttributes &attributes, QSvgHandler *handler) { QSvgText *node = static_cast<QSvgText *>(createTextNode(parent, attributes, handler)); if (node) { QSvgHandler::LengthType type; qreal width = parseLength(attributes.value(QLatin1String("width")), type, handler); qreal height = parseLength(attributes.value(QLatin1String("height")), type, handler); node->setTextArea(QSizeF(width, height)); } return node; }
0
196,691
ofproto_group_lookup__(const struct ofproto *ofproto, uint32_t group_id, ovs_version_t version) { struct ofgroup *group; CMAP_FOR_EACH_WITH_HASH (group, cmap_node, hash_int(group_id, 0), &ofproto->groups) { if (group->group_id == group_id && versions_visible_in_version(&group->versions, version)) { return group; } } return NULL; }
0
301,874
static int dn_accept(struct socket *sock, struct socket *newsock, int flags) { struct sock *sk = sock->sk, *newsk; struct sk_buff *skb = NULL; struct dn_skb_cb *cb; unsigned char menuver; int err = 0; unsigned char type; long timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); struct dst_entry *dst; lock_sock(sk); if (sk->sk_state != TCP_LISTEN || DN_SK(sk)->state != DN_O) { release_sock(sk); return -EINVAL; } skb = skb_dequeue(&sk->sk_receive_queue); if (skb == NULL) { skb = dn_wait_for_connect(sk, &timeo); if (IS_ERR(skb)) { release_sock(sk); return PTR_ERR(skb); } } cb = DN_SKB_CB(skb); sk->sk_ack_backlog--; newsk = dn_alloc_sock(sock_net(sk), newsock, sk->sk_allocation, 0); if (newsk == NULL) { release_sock(sk); kfree_skb(skb); return -ENOBUFS; } release_sock(sk); dst = skb_dst(skb); sk_dst_set(newsk, dst); skb_dst_set(skb, NULL); DN_SK(newsk)->state = DN_CR; DN_SK(newsk)->addrrem = cb->src_port; DN_SK(newsk)->services_rem = cb->services; DN_SK(newsk)->info_rem = cb->info; DN_SK(newsk)->segsize_rem = cb->segsize; DN_SK(newsk)->accept_mode = DN_SK(sk)->accept_mode; if (DN_SK(newsk)->segsize_rem < 230) DN_SK(newsk)->segsize_rem = 230; if ((DN_SK(newsk)->services_rem & NSP_FC_MASK) == NSP_FC_NONE) DN_SK(newsk)->max_window = decnet_no_fc_max_cwnd; newsk->sk_state = TCP_LISTEN; memcpy(&(DN_SK(newsk)->addr), &(DN_SK(sk)->addr), sizeof(struct sockaddr_dn)); /* * If we are listening on a wild socket, we don't want * the newly created socket on the wrong hash queue. */ DN_SK(newsk)->addr.sdn_flags &= ~SDF_WILD; skb_pull(skb, dn_username2sockaddr(skb->data, skb->len, &(DN_SK(newsk)->addr), &type)); skb_pull(skb, dn_username2sockaddr(skb->data, skb->len, &(DN_SK(newsk)->peer), &type)); *(__le16 *)(DN_SK(newsk)->peer.sdn_add.a_addr) = cb->src; *(__le16 *)(DN_SK(newsk)->addr.sdn_add.a_addr) = cb->dst; menuver = *skb->data; skb_pull(skb, 1); if (menuver & DN_MENUVER_ACC) dn_access_copy(skb, &(DN_SK(newsk)->accessdata)); if (menuver & DN_MENUVER_USR) dn_user_copy(skb, &(DN_SK(newsk)->conndata_in)); if (menuver & DN_MENUVER_PRX) DN_SK(newsk)->peer.sdn_flags |= SDF_PROXY; if (menuver & DN_MENUVER_UIC) DN_SK(newsk)->peer.sdn_flags |= SDF_UICPROXY; kfree_skb(skb); memcpy(&(DN_SK(newsk)->conndata_out), &(DN_SK(sk)->conndata_out), sizeof(struct optdata_dn)); memcpy(&(DN_SK(newsk)->discdata_out), &(DN_SK(sk)->discdata_out), sizeof(struct optdata_dn)); lock_sock(newsk); err = dn_hash_sock(newsk); if (err == 0) { sock_reset_flag(newsk, SOCK_ZAPPED); dn_send_conn_ack(newsk); /* * Here we use sk->sk_allocation since although the conn conf is * for the newsk, the context is the old socket. */ if (DN_SK(newsk)->accept_mode == ACC_IMMED) err = dn_confirm_accept(newsk, &timeo, sk->sk_allocation); } release_sock(newsk); return err; }
0
11,698
void ResetPaddingKeyForTesting() { *GetPaddingKey() = SymmetricKey::GenerateRandomKey(kPaddingKeyAlgorithm, 128); }
1
520,548
Field *tmp_table_field_from_field_type(TABLE *table) { DBUG_ASSERT(is_fixed()); const Type_handler *h= type_handler()->type_handler_for_tmp_table(this); return h->make_and_init_table_field(&name, Record_addr(maybe_null), *this, table); }
0
124,443
CModule::EModRet CModule::OnUserCTCPMessage(CCTCPMessage& Message) { CString sTarget = Message.GetTarget(); CString sText = Message.GetText(); EModRet ret = OnUserCTCP(sTarget, sText); Message.SetTarget(sTarget); Message.SetText(sText); return ret; }
0
139,876
f_byteidx(typval_T *argvars, typval_T *rettv) { byteidx(argvars, rettv, FALSE); }
0
444,022
Http::Status ServerConnectionImpl::dispatch(Buffer::Instance& data) { // TODO(#10878): Remove this wrapper when exception removal is complete. innerDispatch may either // throw an exception or return an error status. The utility wrapper catches exceptions and // converts them to error statuses. return Http::Utility::exceptionToStatus( [&](Buffer::Instance& data) -> Http::Status { return innerDispatch(data); }, data); }
0
358,943
static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid, u32 pid, u32 seq, u16 flags, int event) { struct tcmsg *tcm; struct nlmsghdr *nlh; unsigned char *b = skb_tail_pointer(skb); struct gnet_dump d; nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*tcm), flags); tcm = NLMSG_DATA(nlh); tcm->tcm_family = AF_UNSPEC; tcm->tcm__pad1 = 0; tcm->tcm__pad2 = 0; tcm->tcm_ifindex = qdisc_dev(q)->ifindex; tcm->tcm_parent = clid; tcm->tcm_handle = q->handle; tcm->tcm_info = atomic_read(&q->refcnt); NLA_PUT_STRING(skb, TCA_KIND, q->ops->id); if (q->ops->dump && q->ops->dump(q, skb) < 0) goto nla_put_failure; q->qstats.qlen = q->q.qlen; if (q->stab && qdisc_dump_stab(skb, q->stab) < 0) goto nla_put_failure; if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS, TCA_XSTATS, qdisc_root_sleeping_lock(q), &d) < 0) goto nla_put_failure; if (q->ops->dump_stats && q->ops->dump_stats(q, &d) < 0) goto nla_put_failure; if (gnet_stats_copy_basic(&d, &q->bstats) < 0 || gnet_stats_copy_rate_est(&d, &q->rate_est) < 0 || gnet_stats_copy_queue(&d, &q->qstats) < 0) goto nla_put_failure; if (gnet_stats_finish_copy(&d) < 0) goto nla_put_failure; nlh->nlmsg_len = skb_tail_pointer(skb) - b; return skb->len; nlmsg_failure: nla_put_failure: nlmsg_trim(skb, b); return -1; }
0
331,353
static int enable_write_target(BDRVVVFATState *s, Error **errp) { BlockDriver *bdrv_qcow; QEMUOptionParameter *options; int ret; int size = sector2cluster(s, s->sector_count); s->used_clusters = calloc(size, 1); array_init(&(s->commits), sizeof(commit_t)); s->qcow_filename = g_malloc(1024); ret = get_tmp_filename(s->qcow_filename, 1024); if (ret < 0) { error_setg_errno(errp, -ret, "can't create temporary file"); goto err; } bdrv_qcow = bdrv_find_format("qcow"); options = parse_option_parameters("", bdrv_qcow->create_options, NULL); set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512); set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:"); ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, errp); if (ret < 0) { goto err; } s->qcow = NULL; ret = bdrv_open(&s->qcow, s->qcow_filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow, errp); if (ret < 0) { goto err; } #ifndef _WIN32 unlink(s->qcow_filename); #endif bdrv_set_backing_hd(s->bs, bdrv_new("", &error_abort)); s->bs->backing_hd->drv = &vvfat_write_target; s->bs->backing_hd->opaque = g_malloc(sizeof(void*)); *(void**)s->bs->backing_hd->opaque = s; return 0; err: g_free(s->qcow_filename); s->qcow_filename = NULL; return ret; }
1
344,376
goa_ews_client_autodiscover (GoaEwsClient *client, const gchar *email, const gchar *password, const gchar *username, const gchar *server, gboolean accept_ssl_errors, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { AutodiscoverData *data; AutodiscoverAuthData *auth; gchar *url1; gchar *url2; xmlDoc *doc; xmlOutputBuffer *buf; g_return_if_fail (GOA_IS_EWS_CLIENT (client)); g_return_if_fail (email != NULL || email[0] != '\0'); g_return_if_fail (password != NULL || password[0] != '\0'); g_return_if_fail (username != NULL || username[0] != '\0'); g_return_if_fail (server != NULL || server[0] != '\0'); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); doc = ews_client_create_autodiscover_xml (email); buf = xmlAllocOutputBuffer (NULL); xmlNodeDumpOutput (buf, doc, xmlDocGetRootElement (doc), 0, 1, NULL); xmlOutputBufferFlush (buf); url1 = g_strdup_printf ("https://%s/autodiscover/autodiscover.xml", server); url2 = g_strdup_printf ("https://autodiscover.%s/autodiscover/autodiscover.xml", server); /* http://msdn.microsoft.com/en-us/library/ee332364.aspx says we are * supposed to try $domain and then autodiscover.$domain. But some * people have broken firewalls on the former which drop packets * instead of rejecting connections, and make the request take ages * to time out. So run both queries in parallel and let the fastest * (successful) one win. */ data = g_slice_new0 (AutodiscoverData); data->buf = buf; data->res = g_simple_async_result_new (G_OBJECT (client), callback, user_data, goa_ews_client_autodiscover); data->msgs[0] = ews_client_create_msg_for_url (url1, buf); data->msgs[1] = ews_client_create_msg_for_url (url2, buf); data->session = soup_session_async_new_with_options (SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE, SOUP_SESSION_SSL_STRICT, FALSE, SOUP_SESSION_USE_NTLM, TRUE, SOUP_SESSION_USE_THREAD_CONTEXT, TRUE, NULL); data->accept_ssl_errors = accept_ssl_errors; if (cancellable != NULL) { data->cancellable = g_object_ref (cancellable); data->cancellable_id = g_cancellable_connect (data->cancellable, G_CALLBACK (ews_client_autodiscover_cancelled_cb), data, NULL); g_simple_async_result_set_check_cancellable (data->res, data->cancellable); } auth = g_slice_new0 (AutodiscoverAuthData); auth->username = g_strdup (username); auth->password = g_strdup (password); g_signal_connect_data (data->session, "authenticate", G_CALLBACK (ews_client_authenticate), auth, ews_client_autodiscover_auth_data_free, 0); soup_session_queue_message (data->session, data->msgs[0], ews_client_autodiscover_response_cb, data); soup_session_queue_message (data->session, data->msgs[1], ews_client_autodiscover_response_cb, data); g_free (url2); g_free (url1); xmlFreeDoc (doc); }
1
59,262
static int update_eth_regs_async(pegasus_t *pegasus) { int ret = -ENOMEM; struct urb *async_urb; struct usb_ctrlrequest *req; req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC); if (req == NULL) return ret; async_urb = usb_alloc_urb(0, GFP_ATOMIC); if (async_urb == NULL) { kfree(req); return ret; } req->bRequestType = PEGASUS_REQT_WRITE; req->bRequest = PEGASUS_REQ_SET_REGS; req->wValue = cpu_to_le16(0); req->wIndex = cpu_to_le16(EthCtrl0); req->wLength = cpu_to_le16(3); usb_fill_control_urb(async_urb, pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), (void *)req, pegasus->eth_regs, 3, async_ctrl_callback, req); ret = usb_submit_urb(async_urb, GFP_ATOMIC); if (ret) { if (ret == -ENODEV) netif_device_detach(pegasus->net); netif_err(pegasus, drv, pegasus->net, "%s returned %d\n", __func__, ret); } return ret; }
0
265,844
static int attach_auth_trunc(struct xfrm_algo_auth **algpp, u8 *props, struct nlattr *rta) { struct xfrm_algo_auth *p, *ualg; struct xfrm_algo_desc *algo; if (!rta) return 0; ualg = nla_data(rta); algo = xfrm_aalg_get_byname(ualg->alg_name, 1); if (!algo) return -ENOSYS; if (ualg->alg_trunc_len > algo->uinfo.auth.icv_fullbits) return -EINVAL; *props = algo->desc.sadb_alg_id; p = kmemdup(ualg, xfrm_alg_auth_len(ualg), GFP_KERNEL); if (!p) return -ENOMEM; strcpy(p->alg_name, algo->name); if (!p->alg_trunc_len) p->alg_trunc_len = algo->uinfo.auth.icv_truncbits; *algpp = p; return 0; }
0
2,326
nvmet_fc_find_target_queue(struct nvmet_fc_tgtport *tgtport, u64 connection_id) { struct nvmet_fc_tgt_assoc *assoc; struct nvmet_fc_tgt_queue *queue; u64 association_id = nvmet_fc_getassociationid(connection_id); u16 qid = nvmet_fc_getqueueid(connection_id); unsigned long flags; spin_lock_irqsave(&tgtport->lock, flags); list_for_each_entry(assoc, &tgtport->assoc_list, a_list) { if (association_id == assoc->association_id) { queue = assoc->queues[qid]; if (queue && (!atomic_read(&queue->connected) || !nvmet_fc_tgt_q_get(queue))) queue = NULL; spin_unlock_irqrestore(&tgtport->lock, flags); return queue; } } spin_unlock_irqrestore(&tgtport->lock, flags); return NULL; }
1
196,660
get_reply_key_win(krb5_context context, const krb5_data *content, unsigned nonce, krb5_keyblock **key) { ReplyKeyPack_Win2k key_pack; krb5_error_code ret; size_t size; ret = decode_ReplyKeyPack_Win2k(content->data, content->length, &key_pack, &size); if (ret) { krb5_set_error_message(context, ret, N_("PKINIT decoding reply key failed", "")); free_ReplyKeyPack_Win2k(&key_pack); return ret; } if ((unsigned)key_pack.nonce != nonce) { krb5_set_error_message(context, ret, N_("PKINIT enckey nonce is wrong", "")); free_ReplyKeyPack_Win2k(&key_pack); return KRB5KRB_AP_ERR_MODIFIED; } *key = malloc (sizeof (**key)); if (*key == NULL) { free_ReplyKeyPack_Win2k(&key_pack); return krb5_enomem(context); } ret = copy_EncryptionKey(&key_pack.replyKey, *key); free_ReplyKeyPack_Win2k(&key_pack); if (ret) { krb5_set_error_message(context, ret, N_("PKINIT failed copying reply key", "")); free(*key); *key = NULL; } return ret; }
0
247,488
void CL_ShellExecute_URL_f( void ) { qboolean doexit; Com_DPrintf( "CL_ShellExecute_URL_f\n" ); if ( Q_stricmp( Cmd_Argv( 1 ),"open" ) ) { Com_DPrintf( "invalid CL_ShellExecute_URL_f syntax (shellExecute \"open\" <url> <doExit>)\n" ); return; } if ( Cmd_Argc() < 4 ) { doexit = qtrue; } else { doexit = (qboolean)( atoi( Cmd_Argv( 3 ) ) ); } Sys_OpenURL( Cmd_Argv( 2 ),doexit ); }
0
43,886
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr) { return cmd_start(adata, cmdstr, IMAP_CMD_NO_FLAGS); }
0
485,506
static void nf_tables_unregister_hook(struct net *net, const struct nft_table *table, struct nft_chain *chain) { return __nf_tables_unregister_hook(net, table, chain, false); }
0
109,521
TfLiteRegistration* Register_DEPTH_TO_SPACE_REF() { static TfLiteRegistration r = { nullptr, nullptr, depth_to_space::Prepare, depth_to_space::Eval<depth_to_space::kReference>}; return &r; }
0
420,693
static int h2c_handle_goaway(struct h2c *h2c) { int error; int last; if (h2c->dsi != 0) { error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } if (h2c->dfl < 8) { error = H2_ERR_FRAME_SIZE_ERROR; goto conn_err; } /* process full frame only */ if (b_data(&h2c->dbuf) < h2c->dfl) return 0; last = h2_get_n32(&h2c->dbuf, 0); h2c->errcode = h2_get_n32(&h2c->dbuf, 4); h2_wake_some_streams(h2c, last, CS_FL_ERR_PENDING); if (h2c->last_sid < 0) h2c->last_sid = last; return 1; conn_err: h2c_error(h2c, error); return 0; }
0
126,373
static int fr_ioctl(struct net_device *dev, struct ifreq *ifr) { fr_proto __user *fr_s = ifr->ifr_settings.ifs_ifsu.fr; const size_t size = sizeof(fr_proto); fr_proto new_settings; hdlc_device *hdlc = dev_to_hdlc(dev); fr_proto_pvc pvc; int result; switch (ifr->ifr_settings.type) { case IF_GET_PROTO: if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */ return -EINVAL; ifr->ifr_settings.type = IF_PROTO_FR; if (ifr->ifr_settings.size < size) { ifr->ifr_settings.size = size; /* data size wanted */ return -ENOBUFS; } if (copy_to_user(fr_s, &state(hdlc)->settings, size)) return -EFAULT; return 0; case IF_PROTO_FR: if (!capable(CAP_NET_ADMIN)) return -EPERM; if (dev->flags & IFF_UP) return -EBUSY; if (copy_from_user(&new_settings, fr_s, size)) return -EFAULT; if (new_settings.lmi == LMI_DEFAULT) new_settings.lmi = LMI_ANSI; if ((new_settings.lmi != LMI_NONE && new_settings.lmi != LMI_ANSI && new_settings.lmi != LMI_CCITT && new_settings.lmi != LMI_CISCO) || new_settings.t391 < 1 || new_settings.t392 < 2 || new_settings.n391 < 1 || new_settings.n392 < 1 || new_settings.n393 < new_settings.n392 || new_settings.n393 > 32 || (new_settings.dce != 0 && new_settings.dce != 1)) return -EINVAL; result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT); if (result) return result; if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */ result = attach_hdlc_protocol(dev, &proto, sizeof(struct frad_state)); if (result) return result; state(hdlc)->first_pvc = NULL; state(hdlc)->dce_pvc_count = 0; } memcpy(&state(hdlc)->settings, &new_settings, size); dev->type = ARPHRD_FRAD; return 0; case IF_PROTO_FR_ADD_PVC: case IF_PROTO_FR_DEL_PVC: case IF_PROTO_FR_ADD_ETH_PVC: case IF_PROTO_FR_DEL_ETH_PVC: if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */ return -EINVAL; if (!capable(CAP_NET_ADMIN)) return -EPERM; if (copy_from_user(&pvc, ifr->ifr_settings.ifs_ifsu.fr_pvc, sizeof(fr_proto_pvc))) return -EFAULT; if (pvc.dlci <= 0 || pvc.dlci >= 1024) return -EINVAL; /* Only 10 bits, DLCI 0 reserved */ if (ifr->ifr_settings.type == IF_PROTO_FR_ADD_ETH_PVC || ifr->ifr_settings.type == IF_PROTO_FR_DEL_ETH_PVC) result = ARPHRD_ETHER; /* bridged Ethernet device */ else result = ARPHRD_DLCI; if (ifr->ifr_settings.type == IF_PROTO_FR_ADD_PVC || ifr->ifr_settings.type == IF_PROTO_FR_ADD_ETH_PVC) return fr_add_pvc(dev, pvc.dlci, result); else return fr_del_pvc(hdlc, pvc.dlci, result); } return -EINVAL; }
0
229,262
void RenderFrameImpl::SendFailedProvisionalLoad( const blink::WebURLRequest& request, const WebURLError& error, blink::WebLocalFrame* frame) { bool show_repost_interstitial = (error.reason() == net::ERR_CACHE_MISS && base::EqualsASCII(request.HttpMethod().Utf16(), "POST")); FrameHostMsg_DidFailProvisionalLoadWithError_Params params; params.error_code = error.reason(); GetContentClient()->renderer()->GetErrorDescription( request, error, &params.error_description); params.url = error.url(), params.showing_repost_interstitial = show_repost_interstitial; Send(new FrameHostMsg_DidFailProvisionalLoadWithError(routing_id_, params)); }
0
24,150
static void _setWithOids ( ArchiveHandle * AH , TocEntry * te ) { if ( AH -> currWithOids != te -> withOids ) { _doSetWithOids ( AH , te -> withOids ) ; AH -> currWithOids = te -> withOids ; } }
0
345,969
SMBC_attr_server(TALLOC_CTX *ctx, SMBCCTX *context, const char *server, uint16_t port, const char *share, char **pp_workgroup, char **pp_username, char **pp_password) { int flags; struct cli_state *ipc_cli = NULL; struct rpc_pipe_client *pipe_hnd = NULL; NTSTATUS nt_status; SMBCSRV *srv=NULL; SMBCSRV *ipc_srv=NULL; /* * Use srv->cli->desthost and srv->cli->share instead of * server and share below to connect to the actual share, * i.e., a normal share or a referred share from * 'msdfs proxy' share. */ srv = SMBC_server(ctx, context, true, server, port, share, pp_workgroup, pp_username, pp_password); if (!srv) { return NULL; } server = smbXcli_conn_remote_name(srv->cli->conn); share = srv->cli->share; /* * See if we've already created this special connection. Reference * our "special" share name '*IPC$', which is an impossible real share * name due to the leading asterisk. */ ipc_srv = SMBC_find_server(ctx, context, server, "*IPC$", pp_workgroup, pp_username, pp_password); if (!ipc_srv) { /* We didn't find a cached connection. Get the password */ if (!*pp_password || (*pp_password)[0] == '\0') { /* ... then retrieve it now. */ SMBC_call_auth_fn(ctx, context, server, share, pp_workgroup, pp_username, pp_password); if (!*pp_workgroup || !*pp_username || !*pp_password) { errno = ENOMEM; return NULL; } } flags = 0; if (smbc_getOptionUseKerberos(context)) { flags |= CLI_FULL_CONNECTION_USE_KERBEROS; } if (smbc_getOptionUseCCache(context)) { flags |= CLI_FULL_CONNECTION_USE_CCACHE; } nt_status = cli_full_connection(&ipc_cli, lp_netbios_name(), server, NULL, 0, "IPC$", "?????", *pp_username, *pp_workgroup, *pp_password, flags, SMB_SIGNING_DEFAULT); if (! NT_STATUS_IS_OK(nt_status)) { DEBUG(1,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status))); errno = ENOTSUP; return NULL; } if (context->internal->smb_encryption_level) { /* Attempt UNIX smb encryption. */ if (!NT_STATUS_IS_OK(cli_force_encryption(ipc_cli, *pp_username, *pp_password, *pp_workgroup))) { /* * context->smb_encryption_level == * 1 means don't fail if encryption can't be * negotiated, == 2 means fail if encryption * can't be negotiated. */ DEBUG(4,(" SMB encrypt failed on IPC$\n")); if (context->internal->smb_encryption_level == 2) { cli_shutdown(ipc_cli); errno = EPERM; return NULL; } } DEBUG(4,(" SMB encrypt ok on IPC$\n")); } ipc_srv = SMB_MALLOC_P(SMBCSRV); if (!ipc_srv) { errno = ENOMEM; cli_shutdown(ipc_cli); return NULL; } ZERO_STRUCTP(ipc_srv); ipc_srv->cli = ipc_cli; nt_status = cli_rpc_pipe_open_noauth( ipc_srv->cli, &ndr_table_lsarpc, &pipe_hnd); if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(1, ("cli_nt_session_open fail!\n")); errno = ENOTSUP; cli_shutdown(ipc_srv->cli); free(ipc_srv); return NULL; } /* * Some systems don't support * SEC_FLAG_MAXIMUM_ALLOWED, but NT sends 0x2000000 * so we might as well do it too. */ nt_status = rpccli_lsa_open_policy( pipe_hnd, talloc_tos(), True, GENERIC_EXECUTE_ACCESS, &ipc_srv->pol); if (!NT_STATUS_IS_OK(nt_status)) { errno = SMBC_errno(context, ipc_srv->cli); cli_shutdown(ipc_srv->cli); free(ipc_srv); return NULL; } /* now add it to the cache (internal or external) */ errno = 0; /* let cache function set errno if it likes */ if (smbc_getFunctionAddCachedServer(context)(context, ipc_srv, server, "*IPC$", *pp_workgroup, *pp_username)) { DEBUG(3, (" Failed to add server to cache\n")); if (errno == 0) { errno = ENOMEM; } cli_shutdown(ipc_srv->cli); free(ipc_srv); return NULL; } DLIST_ADD(context->internal->servers, ipc_srv); } return ipc_srv; }
1
241,527
bool ResourceDispatcherHost::Read(URLRequest* request, int* bytes_read) { ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); DCHECK(!info->is_paused()); net::IOBuffer* buf; int buf_size; if (!info->resource_handler()->OnWillRead(info->request_id(), &buf, &buf_size, -1)) { return false; } DCHECK(buf); DCHECK(buf_size > 0); info->set_has_started_reading(true); return request->Read(buf, buf_size, bytes_read); }
0
42,606
COMPS_HSList* comps_objmrtree_keys(COMPS_ObjMRTree * rt) { return __comps_objmrtree_all(rt, 0); }
0
257,288
TEST ( DownloadPrefsTest , AutoOpenPrefSkipsDangerousFileTypesInPrefs ) { const base : : FilePath kDangerousFilePath ( FILE_PATH_LITERAL ( "/b/very-bad.swf" ) ) ; const base : : FilePath kSafeFilePath ( FILE_PATH_LITERAL ( "/goodothing-wrong.txt" ) ) ; content : : TestBrowserThreadBundle threads_are_required_for_testing_profile ; TestingProfile profile ; profile . GetPrefs ( ) -> SetString ( prefs : : kDownloadExtensionsToOpen , "swf:txt" ) ; DownloadPrefs prefs ( & profile ) ; EXPECT_FALSE ( prefs . IsAutoOpenEnabledBasedOnExtension ( kDangerousFilePath ) ) ; EXPECT_TRUE ( prefs . IsAutoOpenEnabledBasedOnExtension ( kSafeFilePath ) ) ; }
0
259,061
static int l_session_open (lua_State *L) { int rc; ssh_userdata *state = NULL; luaL_checkinteger(L, 2); lua_settop(L, 2); state = (ssh_userdata *)lua_newuserdata(L, sizeof(ssh_userdata)); /* index 3 */ assert(lua_gettop(L) == 3); state->session = NULL; state->sp[0] = -1; state->sp[1] = -1; lua_pushvalue(L, lua_upvalueindex(1)); /* metatable */ lua_setmetatable(L, 3); lua_newtable(L); lua_setuservalue(L, 3); lua_getuservalue(L, 3); /* index 4 - a table associated with userdata*/ assert(lua_gettop(L) == 4); state->session = libssh2_session_init(); if (state->session == NULL) { // A session could not be created because of memory limit return nseU_safeerror(L, "trying to initiate session"); } libssh2_session_set_blocking(state->session, 0); if (make_socketpair(state->sp, 1) == -1) return nseU_safeerror(L, "trying to create socketpair"); #ifdef WIN32 unsigned long s_mode = 1; // non-blocking rc = ioctlsocket(state->sp[1], FIONBIO, (unsigned long *)&s_mode); if (rc != NO_ERROR) return nseU_safeerror(L, "%s", strerror(errno)); #else // get file descriptor flags rc = fcntl(state->sp[1], F_GETFD); if (rc == -1) return nseU_safeerror(L, "%s", strerror(errno)); // add non-blocking flag and update file descriptor flags rc |= O_NONBLOCK; rc = fcntl(state->sp[1], F_SETFL, rc); if (rc == -1) return nseU_safeerror(L, "%s", strerror(errno)); #endif lua_getglobal(L, "nmap"); lua_getfield(L, -1, "new_socket"); lua_replace(L, -2); lua_call(L, 0, 1); lua_setfield(L, 4, "sock"); lua_pushliteral(L, ""); lua_setfield(L, 4, "sp_buff"); assert(lua_gettop(L) == 4); lua_getfield(L, 4, "sock"); lua_getfield(L, -1, "connect"); lua_insert(L, -2); /* swap */ lua_pushvalue(L, 1); lua_pushvalue(L, 2); lua_callk(L, 3, 2, 3, finish_session_open); return finish_session_open(L,0,0); }
0
459,226
gst_h264_create_sei_memory_avc (guint8 nal_length_size, GArray * messages) { g_return_val_if_fail (nal_length_size > 0 && nal_length_size < 5, NULL); g_return_val_if_fail (messages != NULL, NULL); g_return_val_if_fail (messages->len > 0, NULL); return gst_h264_create_sei_memory_internal (nal_length_size, TRUE, messages); }
0
514,190
span_renderer_init (cairo_abstract_span_renderer_t *_r, const cairo_composite_rectangles_t *composite, cairo_antialias_t antialias, cairo_bool_t needs_clip) { cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *)_r; cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; const cairo_pattern_t *source = &composite->source_pattern.base; cairo_operator_t op = composite->op; cairo_int_status_t status; TRACE ((stderr, "%s: antialias=%d, needs_clip=%d\n", __FUNCTION__, antialias, needs_clip)); if (needs_clip) return CAIRO_INT_STATUS_UNSUPPORTED; r->composite = composite; r->mask = NULL; r->src = NULL; r->base.finish = NULL; status = mono_renderer_init (r, composite, antialias, needs_clip); if (status != CAIRO_INT_STATUS_UNSUPPORTED) return status; status = inplace_renderer_init (r, composite, antialias, needs_clip); if (status != CAIRO_INT_STATUS_UNSUPPORTED) return status; r->bpp = 0; if (op == CAIRO_OPERATOR_CLEAR) { #if PIXMAN_HAS_OP_LERP op = PIXMAN_OP_LERP_CLEAR; #else source = &_cairo_pattern_white.base; op = PIXMAN_OP_OUT_REVERSE; #endif } else if (dst->base.is_clear && (op == CAIRO_OPERATOR_SOURCE || op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD)) { op = PIXMAN_OP_SRC; } else if (op == CAIRO_OPERATOR_SOURCE) { if (_cairo_pattern_is_opaque (&composite->source_pattern.base, &composite->source_sample_area)) { op = PIXMAN_OP_OVER; } else { #if PIXMAN_HAS_OP_LERP op = PIXMAN_OP_LERP_SRC; #else return CAIRO_INT_STATUS_UNSUPPORTED; #endif } } else { op = _pixman_operator (op); } r->op = op; r->src = _pixman_image_for_pattern (dst, source, FALSE, &composite->unbounded, &composite->source_sample_area, &r->u.mask.src_x, &r->u.mask.src_y); if (unlikely (r->src == NULL)) return _cairo_error (CAIRO_STATUS_NO_MEMORY); r->opacity = 1.0; if (composite->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { r->opacity = composite->mask_pattern.solid.color.alpha; } else { pixman_image_t *mask; int mask_x, mask_y; mask = _pixman_image_for_pattern (dst, &composite->mask_pattern.base, TRUE, &composite->unbounded, &composite->mask_sample_area, &mask_x, &mask_y); if (unlikely (mask == NULL)) return _cairo_error (CAIRO_STATUS_NO_MEMORY); /* XXX Component-alpha? */ if ((dst->base.content & CAIRO_CONTENT_COLOR) == 0 && _cairo_pattern_is_opaque (source, &composite->source_sample_area)) { pixman_image_unref (r->src); r->src = mask; r->u.mask.src_x = mask_x; r->u.mask.src_y = mask_y; mask = NULL; } if (mask) { pixman_image_unref (mask); return CAIRO_INT_STATUS_UNSUPPORTED; } } r->u.mask.extents = composite->unbounded; r->u.mask.stride = (r->u.mask.extents.width + 3) & ~3; if (r->u.mask.extents.height * r->u.mask.stride > SZ_BUF) { r->mask = pixman_image_create_bits (PIXMAN_a8, r->u.mask.extents.width, r->u.mask.extents.height, NULL, 0); r->base.render_rows = _cairo_image_spans; r->base.finish = NULL; } else { r->mask = pixman_image_create_bits (PIXMAN_a8, r->u.mask.extents.width, r->u.mask.extents.height, (uint32_t *)r->_buf, r->u.mask.stride); r->base.render_rows = _cairo_image_spans_and_zero; r->base.finish = _cairo_image_finish_spans_and_zero; } if (unlikely (r->mask == NULL)) return _cairo_error (CAIRO_STATUS_NO_MEMORY); r->u.mask.data = (uint8_t *) pixman_image_get_data (r->mask); r->u.mask.stride = pixman_image_get_stride (r->mask); r->u.mask.extents.height += r->u.mask.extents.y; return CAIRO_STATUS_SUCCESS; }
0
169,827
bool HTMLFormElement::rendererIsNeeded(const RenderStyle& style) { if (!m_wasDemoted) return HTMLElement::rendererIsNeeded(style); ContainerNode* node = parentNode(); RenderObject* parentRenderer = node->renderer(); bool parentIsTableElementPart = (parentRenderer->isTable() && isHTMLTableElement(node)) || (parentRenderer->isTableRow() && node->hasTagName(trTag)) || (parentRenderer->isTableSection() && node->hasTagName(tbodyTag)) || (parentRenderer->isRenderTableCol() && node->hasTagName(colTag)) || (parentRenderer->isTableCell() && node->hasTagName(trTag)); if (!parentIsTableElementPart) return true; EDisplay display = style.display(); bool formIsTablePart = display == TABLE || display == INLINE_TABLE || display == TABLE_ROW_GROUP || display == TABLE_HEADER_GROUP || display == TABLE_FOOTER_GROUP || display == TABLE_ROW || display == TABLE_COLUMN_GROUP || display == TABLE_COLUMN || display == TABLE_CELL || display == TABLE_CAPTION; return formIsTablePart; }
0
275,298
bool OSExchangeDataProviderWin::GetFilenames( std::vector<OSExchangeData::FileInfo>* filenames) const { std::vector<base::string16> filenames_local; bool success = ClipboardUtil::GetFilenames(source_object_, &filenames_local); if (success) { for (size_t i = 0; i < filenames_local.size(); ++i) filenames->push_back( OSExchangeData::FileInfo(base::FilePath(filenames_local[i]), base::FilePath())); } return success; }
0
191,028
static SRP_gN_cache *SRP_gN_new_init(const char *ch) { unsigned char tmp[MAX_LEN]; int len; SRP_gN_cache *newgN = (SRP_gN_cache *)OPENSSL_malloc(sizeof(SRP_gN_cache)); if (newgN == NULL) return NULL; if ((newgN->b64_bn = BUF_strdup(ch)) == NULL) goto err; len = t_fromb64(tmp, ch); if ((newgN->bn = BN_bin2bn(tmp, len, NULL))) return newgN; OPENSSL_free(newgN->b64_bn); err: OPENSSL_free(newgN); return NULL; }
0
95,397
static int __init ip_vs_genl_register(void) { return genl_register_family_with_ops(&ip_vs_genl_family, ip_vs_genl_ops, ARRAY_SIZE(ip_vs_genl_ops)); }
0
487,601
breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( const std::string& process_type) { base::FilePath dumps_path; base::PathService::Get(electron::DIR_CRASH_DUMPS, &dumps_path); { ANNOTATE_SCOPED_MEMORY_LEAK; bool upload = ElectronCrashReporterClient::Get()->GetCollectStatsConsent(); breakpad::CrashHandlerHostLinux* crash_handler = new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload); crash_handler->StartUploaderThread(); return crash_handler; } }
0
204,037
static views::View* AddPaddedTitleCard(views::View* view, TitleCard* title_card, int width) { views::View* titled_view = new views::View(); views::GridLayout* layout = titled_view->SetLayoutManager( std::make_unique<views::GridLayout>(titled_view)); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); const gfx::Insets dialog_insets = provider->GetInsetsMetric(views::INSETS_DIALOG); views::ColumnSet* columns = layout->AddColumnSet(0); columns->AddPaddingColumn(1.0, dialog_insets.left()); int available_width = width - dialog_insets.width(); columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, views::GridLayout::kFixedSize, views::GridLayout::FIXED, available_width, available_width); columns->AddPaddingColumn(1.0, dialog_insets.right()); layout->AddColumnSet(1)->AddColumn( views::GridLayout::FILL, views::GridLayout::FILL, views::GridLayout::kFixedSize, views::GridLayout::FIXED, width, width); layout->StartRowWithPadding(1.0, 0, views::GridLayout::kFixedSize, kVerticalSpacing); layout->AddView(title_card); layout->StartRowWithPadding(1.0, 1.0, views::GridLayout::kFixedSize, kVerticalSpacing); layout->AddView(new views::Separator()); layout->StartRow(1.0, 1.0); layout->AddView(view); return titled_view; }
0
273,192
suggest_trie_walk( suginfo_T *su, langp_T *lp, char_u *fword, int soundfold) { char_u tword[MAXWLEN]; // good word collected so far trystate_T stack[MAXWLEN]; char_u preword[MAXWLEN * 3]; // word found with proper case; // concatenation of prefix compound // words and split word. NUL terminated // when going deeper but not when coming // back. char_u compflags[MAXWLEN]; // compound flags, one for each word trystate_T *sp; int newscore; int score; char_u *byts, *fbyts, *pbyts; idx_T *idxs, *fidxs, *pidxs; int depth; int c, c2, c3; int n = 0; int flags; garray_T *gap; idx_T arridx; int len; char_u *p; fromto_T *ftp; int fl = 0, tl; int repextra = 0; // extra bytes in fword[] from REP item slang_T *slang = lp->lp_slang; int fword_ends; int goodword_ends; #ifdef DEBUG_TRIEWALK // Stores the name of the change made at each level. char_u changename[MAXWLEN][80]; #endif int breakcheckcount = 1000; #ifdef FEAT_RELTIME proftime_T time_limit; #endif int compound_ok; // Go through the whole case-fold tree, try changes at each node. // "tword[]" contains the word collected from nodes in the tree. // "fword[]" the word we are trying to match with (initially the bad // word). depth = 0; sp = &stack[0]; CLEAR_POINTER(sp); sp->ts_curi = 1; if (soundfold) { // Going through the soundfold tree. byts = fbyts = slang->sl_sbyts; idxs = fidxs = slang->sl_sidxs; pbyts = NULL; pidxs = NULL; sp->ts_prefixdepth = PFD_NOPREFIX; sp->ts_state = STATE_START; } else { // When there are postponed prefixes we need to use these first. At // the end of the prefix we continue in the case-fold tree. fbyts = slang->sl_fbyts; fidxs = slang->sl_fidxs; pbyts = slang->sl_pbyts; pidxs = slang->sl_pidxs; if (pbyts != NULL) { byts = pbyts; idxs = pidxs; sp->ts_prefixdepth = PFD_PREFIXTREE; sp->ts_state = STATE_NOPREFIX; // try without prefix first } else { byts = fbyts; idxs = fidxs; sp->ts_prefixdepth = PFD_NOPREFIX; sp->ts_state = STATE_START; } } #ifdef FEAT_RELTIME // The loop may take an indefinite amount of time. Break out after some // time. if (spell_suggest_timeout > 0) profile_setlimit(spell_suggest_timeout, &time_limit); #endif // Loop to find all suggestions. At each round we either: // - For the current state try one operation, advance "ts_curi", // increase "depth". // - When a state is done go to the next, set "ts_state". // - When all states are tried decrease "depth". while (depth >= 0 && !got_int) { sp = &stack[depth]; switch (sp->ts_state) { case STATE_START: case STATE_NOPREFIX: // Start of node: Deal with NUL bytes, which means // tword[] may end here. arridx = sp->ts_arridx; // current node in the tree len = byts[arridx]; // bytes in this node arridx += sp->ts_curi; // index of current byte if (sp->ts_prefixdepth == PFD_PREFIXTREE) { // Skip over the NUL bytes, we use them later. for (n = 0; n < len && byts[arridx + n] == 0; ++n) ; sp->ts_curi += n; // Always past NUL bytes now. n = (int)sp->ts_state; PROF_STORE(sp->ts_state) sp->ts_state = STATE_ENDNUL; sp->ts_save_badflags = su->su_badflags; // At end of a prefix or at start of prefixtree: check for // following word. if (depth < MAXWLEN - 1 && (byts[arridx] == 0 || n == (int)STATE_NOPREFIX)) { // Set su->su_badflags to the caps type at this position. // Use the caps type until here for the prefix itself. if (has_mbyte) n = nofold_len(fword, sp->ts_fidx, su->su_badptr); else n = sp->ts_fidx; flags = badword_captype(su->su_badptr, su->su_badptr + n); su->su_badflags = badword_captype(su->su_badptr + n, su->su_badptr + su->su_badlen); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "prefix"); #endif go_deeper(stack, depth, 0); ++depth; sp = &stack[depth]; sp->ts_prefixdepth = depth - 1; byts = fbyts; idxs = fidxs; sp->ts_arridx = 0; // Move the prefix to preword[] with the right case // and make find_keepcap_word() works. tword[sp->ts_twordlen] = NUL; make_case_word(tword + sp->ts_splitoff, preword + sp->ts_prewordlen, flags); sp->ts_prewordlen = (char_u)STRLEN(preword); sp->ts_splitoff = sp->ts_twordlen; } break; } if (sp->ts_curi > len || byts[arridx] != 0) { // Past bytes in node and/or past NUL bytes. PROF_STORE(sp->ts_state) sp->ts_state = STATE_ENDNUL; sp->ts_save_badflags = su->su_badflags; break; } // End of word in tree. ++sp->ts_curi; // eat one NUL byte flags = (int)idxs[arridx]; // Skip words with the NOSUGGEST flag. if (flags & WF_NOSUGGEST) break; fword_ends = (fword[sp->ts_fidx] == NUL || (soundfold ? VIM_ISWHITE(fword[sp->ts_fidx]) : !spell_iswordp(fword + sp->ts_fidx, curwin))); tword[sp->ts_twordlen] = NUL; if (sp->ts_prefixdepth <= PFD_NOTSPECIAL && (sp->ts_flags & TSF_PREFIXOK) == 0 && pbyts != NULL) { // There was a prefix before the word. Check that the prefix // can be used with this word. // Count the length of the NULs in the prefix. If there are // none this must be the first try without a prefix. n = stack[sp->ts_prefixdepth].ts_arridx; len = pbyts[n++]; for (c = 0; c < len && pbyts[n + c] == 0; ++c) ; if (c > 0) { c = valid_word_prefix(c, n, flags, tword + sp->ts_splitoff, slang, FALSE); if (c == 0) break; // Use the WF_RARE flag for a rare prefix. if (c & WF_RAREPFX) flags |= WF_RARE; // Tricky: when checking for both prefix and compounding // we run into the prefix flag first. // Remember that it's OK, so that we accept the prefix // when arriving at a compound flag. sp->ts_flags |= TSF_PREFIXOK; } } // Check NEEDCOMPOUND: can't use word without compounding. Do try // appending another compound word below. if (sp->ts_complen == sp->ts_compsplit && fword_ends && (flags & WF_NEEDCOMP)) goodword_ends = FALSE; else goodword_ends = TRUE; p = NULL; compound_ok = TRUE; if (sp->ts_complen > sp->ts_compsplit) { if (slang->sl_nobreak) { // There was a word before this word. When there was no // change in this word (it was correct) add the first word // as a suggestion. If this word was corrected too, we // need to check if a correct word follows. if (sp->ts_fidx - sp->ts_splitfidx == sp->ts_twordlen - sp->ts_splitoff && STRNCMP(fword + sp->ts_splitfidx, tword + sp->ts_splitoff, sp->ts_fidx - sp->ts_splitfidx) == 0) { preword[sp->ts_prewordlen] = NUL; newscore = score_wordcount_adj(slang, sp->ts_score, preword + sp->ts_prewordlen, sp->ts_prewordlen > 0); // Add the suggestion if the score isn't too bad. if (newscore <= su->su_maxscore) add_suggestion(su, &su->su_ga, preword, sp->ts_splitfidx - repextra, newscore, 0, FALSE, lp->lp_sallang, FALSE); break; } } else { // There was a compound word before this word. If this // word does not support compounding then give up // (splitting is tried for the word without compound // flag). if (((unsigned)flags >> 24) == 0 || sp->ts_twordlen - sp->ts_splitoff < slang->sl_compminlen) break; // For multi-byte chars check character length against // COMPOUNDMIN. if (has_mbyte && slang->sl_compminlen > 0 && mb_charlen(tword + sp->ts_splitoff) < slang->sl_compminlen) break; compflags[sp->ts_complen] = ((unsigned)flags >> 24); compflags[sp->ts_complen + 1] = NUL; vim_strncpy(preword + sp->ts_prewordlen, tword + sp->ts_splitoff, sp->ts_twordlen - sp->ts_splitoff); // Verify CHECKCOMPOUNDPATTERN rules. if (match_checkcompoundpattern(preword, sp->ts_prewordlen, &slang->sl_comppat)) compound_ok = FALSE; if (compound_ok) { p = preword; while (*skiptowhite(p) != NUL) p = skipwhite(skiptowhite(p)); if (fword_ends && !can_compound(slang, p, compflags + sp->ts_compsplit)) // Compound is not allowed. But it may still be // possible if we add another (short) word. compound_ok = FALSE; } // Get pointer to last char of previous word. p = preword + sp->ts_prewordlen; MB_PTR_BACK(preword, p); } } // Form the word with proper case in preword. // If there is a word from a previous split, append. // For the soundfold tree don't change the case, simply append. if (soundfold) STRCPY(preword + sp->ts_prewordlen, tword + sp->ts_splitoff); else if (flags & WF_KEEPCAP) // Must find the word in the keep-case tree. find_keepcap_word(slang, tword + sp->ts_splitoff, preword + sp->ts_prewordlen); else { // Include badflags: If the badword is onecap or allcap // use that for the goodword too. But if the badword is // allcap and it's only one char long use onecap. c = su->su_badflags; if ((c & WF_ALLCAP) && su->su_badlen == (*mb_ptr2len)(su->su_badptr)) c = WF_ONECAP; c |= flags; // When appending a compound word after a word character don't // use Onecap. if (p != NULL && spell_iswordp_nmw(p, curwin)) c &= ~WF_ONECAP; make_case_word(tword + sp->ts_splitoff, preword + sp->ts_prewordlen, c); } if (!soundfold) { // Don't use a banned word. It may appear again as a good // word, thus remember it. if (flags & WF_BANNED) { add_banned(su, preword + sp->ts_prewordlen); break; } if ((sp->ts_complen == sp->ts_compsplit && WAS_BANNED(su, preword + sp->ts_prewordlen)) || WAS_BANNED(su, preword)) { if (slang->sl_compprog == NULL) break; // the word so far was banned but we may try compounding goodword_ends = FALSE; } } newscore = 0; if (!soundfold) // soundfold words don't have flags { if ((flags & WF_REGION) && (((unsigned)flags >> 16) & lp->lp_region) == 0) newscore += SCORE_REGION; if (flags & WF_RARE) newscore += SCORE_RARE; if (!spell_valid_case(su->su_badflags, captype(preword + sp->ts_prewordlen, NULL))) newscore += SCORE_ICASE; } // TODO: how about splitting in the soundfold tree? if (fword_ends && goodword_ends && sp->ts_fidx >= sp->ts_fidxtry && compound_ok) { // The badword also ends: add suggestions. #ifdef DEBUG_TRIEWALK if (soundfold && STRCMP(preword, "smwrd") == 0) { int j; // print the stack of changes that brought us here smsg("------ %s -------", fword); for (j = 0; j < depth; ++j) smsg("%s", changename[j]); } #endif if (soundfold) { // For soundfolded words we need to find the original // words, the edit distance and then add them. add_sound_suggest(su, preword, sp->ts_score, lp); } else if (sp->ts_fidx > 0) { // Give a penalty when changing non-word char to word // char, e.g., "thes," -> "these". p = fword + sp->ts_fidx; MB_PTR_BACK(fword, p); if (!spell_iswordp(p, curwin) && *preword != NUL) { p = preword + STRLEN(preword); MB_PTR_BACK(preword, p); if (spell_iswordp(p, curwin)) newscore += SCORE_NONWORD; } // Give a bonus to words seen before. score = score_wordcount_adj(slang, sp->ts_score + newscore, preword + sp->ts_prewordlen, sp->ts_prewordlen > 0); // Add the suggestion if the score isn't too bad. if (score <= su->su_maxscore) { add_suggestion(su, &su->su_ga, preword, sp->ts_fidx - repextra, score, 0, FALSE, lp->lp_sallang, FALSE); if (su->su_badflags & WF_MIXCAP) { // We really don't know if the word should be // upper or lower case, add both. c = captype(preword, NULL); if (c == 0 || c == WF_ALLCAP) { make_case_word(tword + sp->ts_splitoff, preword + sp->ts_prewordlen, c == 0 ? WF_ALLCAP : 0); add_suggestion(su, &su->su_ga, preword, sp->ts_fidx - repextra, score + SCORE_ICASE, 0, FALSE, lp->lp_sallang, FALSE); } } } } } // Try word split and/or compounding. if ((sp->ts_fidx >= sp->ts_fidxtry || fword_ends) // Don't split halfway a character. && (!has_mbyte || sp->ts_tcharlen == 0)) { int try_compound; int try_split; // If past the end of the bad word don't try a split. // Otherwise try changing the next word. E.g., find // suggestions for "the the" where the second "the" is // different. It's done like a split. // TODO: word split for soundfold words try_split = (sp->ts_fidx - repextra < su->su_badlen) && !soundfold; // Get here in several situations: // 1. The word in the tree ends: // If the word allows compounding try that. Otherwise try // a split by inserting a space. For both check that a // valid words starts at fword[sp->ts_fidx]. // For NOBREAK do like compounding to be able to check if // the next word is valid. // 2. The badword does end, but it was due to a change (e.g., // a swap). No need to split, but do check that the // following word is valid. // 3. The badword and the word in the tree end. It may still // be possible to compound another (short) word. try_compound = FALSE; if (!soundfold && !slang->sl_nocompoundsugs && slang->sl_compprog != NULL && ((unsigned)flags >> 24) != 0 && sp->ts_twordlen - sp->ts_splitoff >= slang->sl_compminlen && (!has_mbyte || slang->sl_compminlen == 0 || mb_charlen(tword + sp->ts_splitoff) >= slang->sl_compminlen) && (slang->sl_compsylmax < MAXWLEN || sp->ts_complen + 1 - sp->ts_compsplit < slang->sl_compmax) && (can_be_compound(sp, slang, compflags, ((unsigned)flags >> 24)))) { try_compound = TRUE; compflags[sp->ts_complen] = ((unsigned)flags >> 24); compflags[sp->ts_complen + 1] = NUL; } // For NOBREAK we never try splitting, it won't make any word // valid. if (slang->sl_nobreak && !slang->sl_nocompoundsugs) try_compound = TRUE; // If we could add a compound word, and it's also possible to // split at this point, do the split first and set // TSF_DIDSPLIT to avoid doing it again. else if (!fword_ends && try_compound && (sp->ts_flags & TSF_DIDSPLIT) == 0) { try_compound = FALSE; sp->ts_flags |= TSF_DIDSPLIT; --sp->ts_curi; // do the same NUL again compflags[sp->ts_complen] = NUL; } else sp->ts_flags &= ~TSF_DIDSPLIT; if (try_split || try_compound) { if (!try_compound && (!fword_ends || !goodword_ends)) { // If we're going to split need to check that the // words so far are valid for compounding. If there // is only one word it must not have the NEEDCOMPOUND // flag. if (sp->ts_complen == sp->ts_compsplit && (flags & WF_NEEDCOMP)) break; p = preword; while (*skiptowhite(p) != NUL) p = skipwhite(skiptowhite(p)); if (sp->ts_complen > sp->ts_compsplit && !can_compound(slang, p, compflags + sp->ts_compsplit)) break; if (slang->sl_nosplitsugs) newscore += SCORE_SPLIT_NO; else newscore += SCORE_SPLIT; // Give a bonus to words seen before. newscore = score_wordcount_adj(slang, newscore, preword + sp->ts_prewordlen, TRUE); } if (TRY_DEEPER(su, stack, depth, newscore)) { go_deeper(stack, depth, newscore); #ifdef DEBUG_TRIEWALK if (!try_compound && !fword_ends) sprintf(changename[depth], "%.*s-%s: split", sp->ts_twordlen, tword, fword + sp->ts_fidx); else sprintf(changename[depth], "%.*s-%s: compound", sp->ts_twordlen, tword, fword + sp->ts_fidx); #endif // Save things to be restored at STATE_SPLITUNDO. sp->ts_save_badflags = su->su_badflags; PROF_STORE(sp->ts_state) sp->ts_state = STATE_SPLITUNDO; ++depth; sp = &stack[depth]; // Append a space to preword when splitting. if (!try_compound && !fword_ends) STRCAT(preword, " "); sp->ts_prewordlen = (char_u)STRLEN(preword); sp->ts_splitoff = sp->ts_twordlen; sp->ts_splitfidx = sp->ts_fidx; // If the badword has a non-word character at this // position skip it. That means replacing the // non-word character with a space. Always skip a // character when the word ends. But only when the // good word can end. if (((!try_compound && !spell_iswordp_nmw(fword + sp->ts_fidx, curwin)) || fword_ends) && fword[sp->ts_fidx] != NUL && goodword_ends) { int l; l = mb_ptr2len(fword + sp->ts_fidx); if (fword_ends) { // Copy the skipped character to preword. mch_memmove(preword + sp->ts_prewordlen, fword + sp->ts_fidx, l); sp->ts_prewordlen += l; preword[sp->ts_prewordlen] = NUL; } else sp->ts_score -= SCORE_SPLIT - SCORE_SUBST; sp->ts_fidx += l; } // When compounding include compound flag in // compflags[] (already set above). When splitting we // may start compounding over again. if (try_compound) ++sp->ts_complen; else sp->ts_compsplit = sp->ts_complen; sp->ts_prefixdepth = PFD_NOPREFIX; // set su->su_badflags to the caps type at this // position if (has_mbyte) n = nofold_len(fword, sp->ts_fidx, su->su_badptr); else n = sp->ts_fidx; su->su_badflags = badword_captype(su->su_badptr + n, su->su_badptr + su->su_badlen); // Restart at top of the tree. sp->ts_arridx = 0; // If there are postponed prefixes, try these too. if (pbyts != NULL) { byts = pbyts; idxs = pidxs; sp->ts_prefixdepth = PFD_PREFIXTREE; PROF_STORE(sp->ts_state) sp->ts_state = STATE_NOPREFIX; } } } } break; case STATE_SPLITUNDO: // Undo the changes done for word split or compound word. su->su_badflags = sp->ts_save_badflags; // Continue looking for NUL bytes. PROF_STORE(sp->ts_state) sp->ts_state = STATE_START; // In case we went into the prefix tree. byts = fbyts; idxs = fidxs; break; case STATE_ENDNUL: // Past the NUL bytes in the node. su->su_badflags = sp->ts_save_badflags; if (fword[sp->ts_fidx] == NUL && sp->ts_tcharlen == 0) { // The badword ends, can't use STATE_PLAIN. PROF_STORE(sp->ts_state) sp->ts_state = STATE_DEL; break; } PROF_STORE(sp->ts_state) sp->ts_state = STATE_PLAIN; // FALLTHROUGH case STATE_PLAIN: // Go over all possible bytes at this node, add each to tword[] // and use child node. "ts_curi" is the index. arridx = sp->ts_arridx; if (sp->ts_curi > byts[arridx]) { // Done all bytes at this node, do next state. When still at // already changed bytes skip the other tricks. PROF_STORE(sp->ts_state) if (sp->ts_fidx >= sp->ts_fidxtry) sp->ts_state = STATE_DEL; else sp->ts_state = STATE_FINAL; } else { arridx += sp->ts_curi++; c = byts[arridx]; // Normal byte, go one level deeper. If it's not equal to the // byte in the bad word adjust the score. But don't even try // when the byte was already changed. And don't try when we // just deleted this byte, accepting it is always cheaper than // delete + substitute. if (c == fword[sp->ts_fidx] || (sp->ts_tcharlen > 0 && sp->ts_isdiff != DIFF_NONE)) newscore = 0; else newscore = SCORE_SUBST; if ((newscore == 0 || (sp->ts_fidx >= sp->ts_fidxtry && ((sp->ts_flags & TSF_DIDDEL) == 0 || c != fword[sp->ts_delidx]))) && TRY_DEEPER(su, stack, depth, newscore)) { go_deeper(stack, depth, newscore); #ifdef DEBUG_TRIEWALK if (newscore > 0) sprintf(changename[depth], "%.*s-%s: subst %c to %c", sp->ts_twordlen, tword, fword + sp->ts_fidx, fword[sp->ts_fidx], c); else sprintf(changename[depth], "%.*s-%s: accept %c", sp->ts_twordlen, tword, fword + sp->ts_fidx, fword[sp->ts_fidx]); #endif ++depth; sp = &stack[depth]; ++sp->ts_fidx; tword[sp->ts_twordlen++] = c; sp->ts_arridx = idxs[arridx]; if (newscore == SCORE_SUBST) sp->ts_isdiff = DIFF_YES; if (has_mbyte) { // Multi-byte characters are a bit complicated to // handle: They differ when any of the bytes differ // and then their length may also differ. if (sp->ts_tcharlen == 0) { // First byte. sp->ts_tcharidx = 0; sp->ts_tcharlen = MB_BYTE2LEN(c); sp->ts_fcharstart = sp->ts_fidx - 1; sp->ts_isdiff = (newscore != 0) ? DIFF_YES : DIFF_NONE; } else if (sp->ts_isdiff == DIFF_INSERT) // When inserting trail bytes don't advance in the // bad word. --sp->ts_fidx; if (++sp->ts_tcharidx == sp->ts_tcharlen) { // Last byte of character. if (sp->ts_isdiff == DIFF_YES) { // Correct ts_fidx for the byte length of the // character (we didn't check that before). sp->ts_fidx = sp->ts_fcharstart + mb_ptr2len( fword + sp->ts_fcharstart); // For changing a composing character adjust // the score from SCORE_SUBST to // SCORE_SUBCOMP. if (enc_utf8 && utf_iscomposing( utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen)) && utf_iscomposing( utf_ptr2char(fword + sp->ts_fcharstart))) sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP; // For a similar character adjust score from // SCORE_SUBST to SCORE_SIMILAR. else if (!soundfold && slang->sl_has_map && similar_chars(slang, mb_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen), mb_ptr2char(fword + sp->ts_fcharstart))) sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; } else if (sp->ts_isdiff == DIFF_INSERT && sp->ts_twordlen > sp->ts_tcharlen) { p = tword + sp->ts_twordlen - sp->ts_tcharlen; c = mb_ptr2char(p); if (enc_utf8 && utf_iscomposing(c)) { // Inserting a composing char doesn't // count that much. sp->ts_score -= SCORE_INS - SCORE_INSCOMP; } else { // If the previous character was the same, // thus doubling a character, give a bonus // to the score. Also for the soundfold // tree (might seem illogical but does // give better scores). MB_PTR_BACK(tword, p); if (c == mb_ptr2char(p)) sp->ts_score -= SCORE_INS - SCORE_INSDUP; } } // Starting a new char, reset the length. sp->ts_tcharlen = 0; } } else { // If we found a similar char adjust the score. // We do this after calling go_deeper() because // it's slow. if (newscore != 0 && !soundfold && slang->sl_has_map && similar_chars(slang, c, fword[sp->ts_fidx - 1])) sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; } } } break; case STATE_DEL: // When past the first byte of a multi-byte char don't try // delete/insert/swap a character. if (has_mbyte && sp->ts_tcharlen > 0) { PROF_STORE(sp->ts_state) sp->ts_state = STATE_FINAL; break; } // Try skipping one character in the bad word (delete it). PROF_STORE(sp->ts_state) sp->ts_state = STATE_INS_PREP; sp->ts_curi = 1; if (soundfold && sp->ts_fidx == 0 && fword[sp->ts_fidx] == '*') // Deleting a vowel at the start of a word counts less, see // soundalike_score(). newscore = 2 * SCORE_DEL / 3; else newscore = SCORE_DEL; if (fword[sp->ts_fidx] != NUL && TRY_DEEPER(su, stack, depth, newscore)) { go_deeper(stack, depth, newscore); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: delete %c", sp->ts_twordlen, tword, fword + sp->ts_fidx, fword[sp->ts_fidx]); #endif ++depth; // Remember what character we deleted, so that we can avoid // inserting it again. stack[depth].ts_flags |= TSF_DIDDEL; stack[depth].ts_delidx = sp->ts_fidx; // Advance over the character in fword[]. Give a bonus to the // score if the same character is following "nn" -> "n". It's // a bit illogical for soundfold tree but it does give better // results. if (has_mbyte) { c = mb_ptr2char(fword + sp->ts_fidx); stack[depth].ts_fidx += mb_ptr2len(fword + sp->ts_fidx); if (enc_utf8 && utf_iscomposing(c)) stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; else if (c == mb_ptr2char(fword + stack[depth].ts_fidx)) stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; } else { ++stack[depth].ts_fidx; if (fword[sp->ts_fidx] == fword[sp->ts_fidx + 1]) stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; } break; } // FALLTHROUGH case STATE_INS_PREP: if (sp->ts_flags & TSF_DIDDEL) { // If we just deleted a byte then inserting won't make sense, // a substitute is always cheaper. PROF_STORE(sp->ts_state) sp->ts_state = STATE_SWAP; break; } // skip over NUL bytes n = sp->ts_arridx; for (;;) { if (sp->ts_curi > byts[n]) { // Only NUL bytes at this node, go to next state. PROF_STORE(sp->ts_state) sp->ts_state = STATE_SWAP; break; } if (byts[n + sp->ts_curi] != NUL) { // Found a byte to insert. PROF_STORE(sp->ts_state) sp->ts_state = STATE_INS; break; } ++sp->ts_curi; } break; // FALLTHROUGH case STATE_INS: // Insert one byte. Repeat this for each possible byte at this // node. n = sp->ts_arridx; if (sp->ts_curi > byts[n]) { // Done all bytes at this node, go to next state. PROF_STORE(sp->ts_state) sp->ts_state = STATE_SWAP; break; } // Do one more byte at this node, but: // - Skip NUL bytes. // - Skip the byte if it's equal to the byte in the word, // accepting that byte is always better. n += sp->ts_curi++; c = byts[n]; if (soundfold && sp->ts_twordlen == 0 && c == '*') // Inserting a vowel at the start of a word counts less, // see soundalike_score(). newscore = 2 * SCORE_INS / 3; else newscore = SCORE_INS; if (c != fword[sp->ts_fidx] && TRY_DEEPER(su, stack, depth, newscore)) { go_deeper(stack, depth, newscore); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: insert %c", sp->ts_twordlen, tword, fword + sp->ts_fidx, c); #endif ++depth; sp = &stack[depth]; tword[sp->ts_twordlen++] = c; sp->ts_arridx = idxs[n]; if (has_mbyte) { fl = MB_BYTE2LEN(c); if (fl > 1) { // There are following bytes for the same character. // We must find all bytes before trying // delete/insert/swap/etc. sp->ts_tcharlen = fl; sp->ts_tcharidx = 1; sp->ts_isdiff = DIFF_INSERT; } } else fl = 1; if (fl == 1) { // If the previous character was the same, thus doubling a // character, give a bonus to the score. Also for // soundfold words (illogical but does give a better // score). if (sp->ts_twordlen >= 2 && tword[sp->ts_twordlen - 2] == c) sp->ts_score -= SCORE_INS - SCORE_INSDUP; } } break; case STATE_SWAP: // Swap two bytes in the bad word: "12" -> "21". // We change "fword" here, it's changed back afterwards at // STATE_UNSWAP. p = fword + sp->ts_fidx; c = *p; if (c == NUL) { // End of word, can't swap or replace. PROF_STORE(sp->ts_state) sp->ts_state = STATE_FINAL; break; } // Don't swap if the first character is not a word character. // SWAP3 etc. also don't make sense then. if (!soundfold && !spell_iswordp(p, curwin)) { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; break; } if (has_mbyte) { n = MB_CPTR2LEN(p); c = mb_ptr2char(p); if (p[n] == NUL) c2 = NUL; else if (!soundfold && !spell_iswordp(p + n, curwin)) c2 = c; // don't swap non-word char else c2 = mb_ptr2char(p + n); } else { if (p[1] == NUL) c2 = NUL; else if (!soundfold && !spell_iswordp(p + 1, curwin)) c2 = c; // don't swap non-word char else c2 = p[1]; } // When the second character is NUL we can't swap. if (c2 == NUL) { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; break; } // When characters are identical, swap won't do anything. // Also get here if the second char is not a word character. if (c == c2) { PROF_STORE(sp->ts_state) sp->ts_state = STATE_SWAP3; break; } if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) { go_deeper(stack, depth, SCORE_SWAP); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: swap %c and %c", sp->ts_twordlen, tword, fword + sp->ts_fidx, c, c2); #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNSWAP; ++depth; if (has_mbyte) { fl = mb_char2len(c2); mch_memmove(p, p + n, fl); mb_char2bytes(c, p + fl); stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; } else { p[0] = c2; p[1] = c; stack[depth].ts_fidxtry = sp->ts_fidx + 2; } } else { // If this swap doesn't work then SWAP3 won't either. PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; } break; case STATE_UNSWAP: // Undo the STATE_SWAP swap: "21" -> "12". p = fword + sp->ts_fidx; if (has_mbyte) { n = mb_ptr2len(p); c = mb_ptr2char(p + n); mch_memmove(p + mb_ptr2len(p + n), p, n); mb_char2bytes(c, p); } else { c = *p; *p = p[1]; p[1] = c; } // FALLTHROUGH case STATE_SWAP3: // Swap two bytes, skipping one: "123" -> "321". We change // "fword" here, it's changed back afterwards at STATE_UNSWAP3. p = fword + sp->ts_fidx; if (has_mbyte) { n = MB_CPTR2LEN(p); c = mb_ptr2char(p); fl = MB_CPTR2LEN(p + n); c2 = mb_ptr2char(p + n); if (!soundfold && !spell_iswordp(p + n + fl, curwin)) c3 = c; // don't swap non-word char else c3 = mb_ptr2char(p + n + fl); } else { c = *p; c2 = p[1]; if (!soundfold && !spell_iswordp(p + 2, curwin)) c3 = c; // don't swap non-word char else c3 = p[2]; } // When characters are identical: "121" then SWAP3 result is // identical, ROT3L result is same as SWAP: "211", ROT3L result is // same as SWAP on next char: "112". Thus skip all swapping. // Also skip when c3 is NUL. // Also get here when the third character is not a word character. // Second character may any char: "a.b" -> "b.a" if (c == c3 || c3 == NUL) { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; break; } if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3)) { go_deeper(stack, depth, SCORE_SWAP3); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: swap3 %c and %c", sp->ts_twordlen, tword, fword + sp->ts_fidx, c, c3); #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNSWAP3; ++depth; if (has_mbyte) { tl = mb_char2len(c3); mch_memmove(p, p + n + fl, tl); mb_char2bytes(c2, p + tl); mb_char2bytes(c, p + fl + tl); stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl; } else { p[0] = p[2]; p[2] = c; stack[depth].ts_fidxtry = sp->ts_fidx + 3; } } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; } break; case STATE_UNSWAP3: // Undo STATE_SWAP3: "321" -> "123" p = fword + sp->ts_fidx; if (has_mbyte) { n = mb_ptr2len(p); c2 = mb_ptr2char(p + n); fl = mb_ptr2len(p + n); c = mb_ptr2char(p + n + fl); tl = mb_ptr2len(p + n + fl); mch_memmove(p + fl + tl, p, n); mb_char2bytes(c, p); mb_char2bytes(c2, p + tl); p = p + tl; } else { c = *p; *p = p[2]; p[2] = c; ++p; } if (!soundfold && !spell_iswordp(p, curwin)) { // Middle char is not a word char, skip the rotate. First and // third char were already checked at swap and swap3. PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; break; } // Rotate three characters left: "123" -> "231". We change // "fword" here, it's changed back afterwards at STATE_UNROT3L. if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3)) { go_deeper(stack, depth, SCORE_SWAP3); #ifdef DEBUG_TRIEWALK p = fword + sp->ts_fidx; sprintf(changename[depth], "%.*s-%s: rotate left %c%c%c", sp->ts_twordlen, tword, fword + sp->ts_fidx, p[0], p[1], p[2]); #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNROT3L; ++depth; p = fword + sp->ts_fidx; if (has_mbyte) { n = MB_CPTR2LEN(p); c = mb_ptr2char(p); fl = MB_CPTR2LEN(p + n); fl += MB_CPTR2LEN(p + n + fl); mch_memmove(p, p + n, fl); mb_char2bytes(c, p + fl); stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; } else { c = *p; *p = p[1]; p[1] = p[2]; p[2] = c; stack[depth].ts_fidxtry = sp->ts_fidx + 3; } } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; } break; case STATE_UNROT3L: // Undo ROT3L: "231" -> "123" p = fword + sp->ts_fidx; if (has_mbyte) { n = mb_ptr2len(p); n += mb_ptr2len(p + n); c = mb_ptr2char(p + n); tl = mb_ptr2len(p + n); mch_memmove(p + tl, p, n); mb_char2bytes(c, p); } else { c = p[2]; p[2] = p[1]; p[1] = *p; *p = c; } // Rotate three bytes right: "123" -> "312". We change "fword" // here, it's changed back afterwards at STATE_UNROT3R. if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3)) { go_deeper(stack, depth, SCORE_SWAP3); #ifdef DEBUG_TRIEWALK p = fword + sp->ts_fidx; sprintf(changename[depth], "%.*s-%s: rotate right %c%c%c", sp->ts_twordlen, tword, fword + sp->ts_fidx, p[0], p[1], p[2]); #endif PROF_STORE(sp->ts_state) sp->ts_state = STATE_UNROT3R; ++depth; p = fword + sp->ts_fidx; if (has_mbyte) { n = MB_CPTR2LEN(p); n += MB_CPTR2LEN(p + n); c = mb_ptr2char(p + n); tl = MB_CPTR2LEN(p + n); mch_memmove(p + tl, p, n); mb_char2bytes(c, p); stack[depth].ts_fidxtry = sp->ts_fidx + n + tl; } else { c = p[2]; p[2] = p[1]; p[1] = *p; *p = c; stack[depth].ts_fidxtry = sp->ts_fidx + 3; } } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; } break; case STATE_UNROT3R: // Undo ROT3R: "312" -> "123" p = fword + sp->ts_fidx; if (has_mbyte) { c = mb_ptr2char(p); tl = mb_ptr2len(p); n = mb_ptr2len(p + tl); n += mb_ptr2len(p + tl + n); mch_memmove(p, p + tl, n); mb_char2bytes(c, p + n); } else { c = *p; *p = p[1]; p[1] = p[2]; p[2] = c; } // FALLTHROUGH case STATE_REP_INI: // Check if matching with REP items from the .aff file would work. // Quickly skip if: // - there are no REP items and we are not in the soundfold trie // - the score is going to be too high anyway // - already applied a REP item or swapped here if ((lp->lp_replang == NULL && !soundfold) || sp->ts_score + SCORE_REP >= su->su_maxscore || sp->ts_fidx < sp->ts_fidxtry) { PROF_STORE(sp->ts_state) sp->ts_state = STATE_FINAL; break; } // Use the first byte to quickly find the first entry that may // match. If the index is -1 there is none. if (soundfold) sp->ts_curi = slang->sl_repsal_first[fword[sp->ts_fidx]]; else sp->ts_curi = lp->lp_replang->sl_rep_first[fword[sp->ts_fidx]]; if (sp->ts_curi < 0) { PROF_STORE(sp->ts_state) sp->ts_state = STATE_FINAL; break; } PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP; // FALLTHROUGH case STATE_REP: // Try matching with REP items from the .aff file. For each match // replace the characters and check if the resulting word is // valid. p = fword + sp->ts_fidx; if (soundfold) gap = &slang->sl_repsal; else gap = &lp->lp_replang->sl_rep; while (sp->ts_curi < gap->ga_len) { ftp = (fromto_T *)gap->ga_data + sp->ts_curi++; if (*ftp->ft_from != *p) { // past possible matching entries sp->ts_curi = gap->ga_len; break; } if (STRNCMP(ftp->ft_from, p, STRLEN(ftp->ft_from)) == 0 && TRY_DEEPER(su, stack, depth, SCORE_REP)) { go_deeper(stack, depth, SCORE_REP); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "%.*s-%s: replace %s with %s", sp->ts_twordlen, tword, fword + sp->ts_fidx, ftp->ft_from, ftp->ft_to); #endif // Need to undo this afterwards. PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_UNDO; // Change the "from" to the "to" string. ++depth; fl = (int)STRLEN(ftp->ft_from); tl = (int)STRLEN(ftp->ft_to); if (fl != tl) { STRMOVE(p + tl, p + fl); repextra += tl - fl; } mch_memmove(p, ftp->ft_to, tl); stack[depth].ts_fidxtry = sp->ts_fidx + tl; stack[depth].ts_tcharlen = 0; break; } } if (sp->ts_curi >= gap->ga_len && sp->ts_state == STATE_REP) { // No (more) matches. PROF_STORE(sp->ts_state) sp->ts_state = STATE_FINAL; } break; case STATE_REP_UNDO: // Undo a REP replacement and continue with the next one. if (soundfold) gap = &slang->sl_repsal; else gap = &lp->lp_replang->sl_rep; ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1; fl = (int)STRLEN(ftp->ft_from); tl = (int)STRLEN(ftp->ft_to); p = fword + sp->ts_fidx; if (fl != tl) { STRMOVE(p + fl, p + tl); repextra -= tl - fl; } mch_memmove(p, ftp->ft_from, fl); PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP; break; default: // Did all possible states at this level, go up one level. --depth; if (depth >= 0 && stack[depth].ts_prefixdepth == PFD_PREFIXTREE) { // Continue in or go back to the prefix tree. byts = pbyts; idxs = pidxs; } // Don't check for CTRL-C too often, it takes time. if (--breakcheckcount == 0) { ui_breakcheck(); breakcheckcount = 1000; #ifdef FEAT_RELTIME if (spell_suggest_timeout > 0 && profile_passed_limit(&time_limit)) got_int = TRUE; #endif } } } }
0
233,845
static void ServerNameToSyncAPIName(const std::string& server_name, std::string* out) { CHECK(out); int length_to_copy = server_name.length(); if (IsNameServerIllegalAfterTrimming(server_name) && EndsWithSpace(server_name)) { --length_to_copy; } *out = std::string(server_name.c_str(), length_to_copy); }
0
489,427
GF_Err nhmldump_process(GF_Filter *filter) { GF_NHMLDumpCtx *ctx = gf_filter_get_udta(filter); GF_FilterPacket *pck; char *data; u32 pck_size; if (!ctx->side_streams_config) { return nhmldump_config_side_stream(filter, ctx); } pck = gf_filter_pid_get_packet(ctx->ipid); if (!pck) { if (gf_filter_pid_is_eos(ctx->ipid)) { if (ctx->bs_w && ctx->szRootName) { char nhml[1024]; u32 size; gf_bs_reassign_buffer(ctx->bs_w, ctx->nhml_buffer, ctx->nhml_buffer_size); sprintf(nhml, "</%s>\n", ctx->szRootName); gf_bs_write_data(ctx->bs_w, nhml, (u32) strlen(nhml)); gf_bs_get_content_no_truncate(ctx->bs_w, &ctx->nhml_buffer, &size, &ctx->nhml_buffer_size); if (ctx->filep) { gf_fwrite(ctx->nhml_buffer, size, ctx->filep); } else { GF_FilterPacket *dst_pck; u8 *output; dst_pck = gf_filter_pck_new_alloc(ctx->opid_nhml, size, &output); if (dst_pck) { memcpy(output, ctx->nhml_buffer, size); gf_filter_pck_set_framing(dst_pck, GF_FALSE, GF_TRUE); gf_filter_pck_send(dst_pck); } } ctx->szRootName = NULL; } if (ctx->opid_nhml) gf_filter_pid_set_eos(ctx->opid_nhml); if (ctx->opid_mdia) gf_filter_pid_set_eos(ctx->opid_mdia); if (ctx->opid_info) gf_filter_pid_set_eos(ctx->opid_info); return GF_EOS; } return GF_OK; } if (!ctx->bs_w) ctx->bs_w = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); else gf_bs_reassign_buffer(ctx->bs_w, ctx->nhml_buffer, ctx->nhml_buffer_size); if (ctx->first) { nhmldump_send_header(ctx); gf_bs_reassign_buffer(ctx->bs_w, ctx->nhml_buffer, ctx->nhml_buffer_size); } //get media data data = (char *) gf_filter_pck_get_data(pck, &pck_size); //send data if (ctx->is_dims) { nhmldump_send_dims(ctx, data, pck_size, pck); } else { nhmldump_send_frame(ctx, data, pck_size, pck); } ctx->first = GF_FALSE; if (ctx->exporter) { u32 timescale = gf_filter_pck_get_timescale(pck); u64 ts = gf_filter_pck_get_cts(pck); gf_set_progress("Exporting", ts*ctx->duration.den, ctx->duration.num*timescale); } gf_filter_pid_drop_packet(ctx->ipid); return GF_OK; }
0
359,460
lt_dlmakeresident (lt_dlhandle handle) { int errors = 0; if (!handle) { LT__SETERROR (INVALID_HANDLE); ++errors; } else { handle->info.is_resident = 1; } return errors; }
0
199,062
LogLuvEncodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) { tmsize_t rowlen = TIFFScanlineSize(tif); if (rowlen == 0) return 0; assert(cc%rowlen == 0); while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) { bp += rowlen; cc -= rowlen; } return (cc == 0); }
0
296,613
EC_Group::EC_Group(const std::string& str) { if(str == "") return; // no initialization / uninitialized try { OID oid = OIDS::lookup(str); if(oid.empty() == false) m_data = ec_group_data().lookup(oid); } catch(Invalid_OID&) { } if(m_data == nullptr) { if(str.size() > 30 && str.substr(0, 29) == "-----BEGIN EC PARAMETERS-----") { // OK try it as PEM ... secure_vector<uint8_t> ber = PEM_Code::decode_check_label(str, "EC PARAMETERS"); this->m_data = BER_decode_EC_group(ber.data(), ber.size()); } } if(m_data == nullptr) throw Invalid_Argument("Unknown ECC group '" + str + "'"); }
0
107,928
openlog (const char *ident, int logstat, int logfac) { /* Protect against multiple users. */ __libc_cleanup_region_start ((void (*) __P ((void *))) __libc_mutex_unlock, &syslog_lock); __libc_lock_lock (syslog_lock); openlog_internal (ident, logstat, logfac); /* Free the lock. */ __libc_cleanup_region_end (1); }
0
265,182
static void udf_write_failed(struct address_space *mapping, loff_t to) { struct inode *inode = mapping->host; struct udf_inode_info *iinfo = UDF_I(inode); loff_t isize = inode->i_size; if (to > isize) { truncate_pagecache(inode, isize); if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { down_write(&iinfo->i_data_sem); udf_clear_extent_cache(inode); udf_truncate_extents(inode); up_write(&iinfo->i_data_sem); } } }
0
515,327
int smtp_server_connection_flush(struct smtp_server_connection *conn) { struct ostream *output = conn->conn.output; int ret; if ((ret = o_stream_flush(output)) <= 0) { if (ret < 0) smtp_server_connection_handle_output_error(conn); return ret; } return 1; }
0
244,817
mcid_char_imp(fz_context *ctx, pdf_filter_processor *p, tag_record *tr, int uni, int remove) { if (tr->mcid_obj == NULL) /* No object, or already deleted */ return; if (remove) { /* Remove the expanded abbreviation, if there is one. */ pdf_dict_del(ctx, tr->mcid_obj, PDF_NAME(E)); /* Remove the structure title, if there is one. */ pdf_dict_del(ctx, tr->mcid_obj, PDF_NAME(T)); } /* Edit the Alt string */ walk_string(ctx, uni, remove, &tr->alt); /* Edit the ActualText string */ walk_string(ctx, uni, remove, &tr->actualtext); /* If we're removing a character, and either of the strings * haven't matched up to what we were expecting, then just * delete the whole string. */ else if (tr->alt.pos >= 0 || tr->actualtext.pos >= 0) { /* The strings are making sense so far */ remove = 0; /* The strings are making sense so far */ remove = 0; } if (remove) { /* Anything else we have to err on the side of caution and if (tr->alt.pos == -1) pdf_dict_del(ctx, tr->mcid_obj, PDF_NAME(Alt)); pdf_drop_obj(ctx, tr->mcid_obj); tr->mcid_obj = NULL; fz_free(ctx, tr->alt.utf8); tr->alt.utf8 = NULL; fz_free(ctx, tr->actualtext.utf8); tr->actualtext.utf8 = NULL; } }
0
94,283
SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3, unsigned long, arg4, unsigned long, arg5) { switch (option) { case KEYCTL_GET_KEYRING_ID: return keyctl_get_keyring_ID((key_serial_t) arg2, (int) arg3); case KEYCTL_JOIN_SESSION_KEYRING: return keyctl_join_session_keyring((const char __user *) arg2); case KEYCTL_UPDATE: return keyctl_update_key((key_serial_t) arg2, (const void __user *) arg3, (size_t) arg4); case KEYCTL_REVOKE: return keyctl_revoke_key((key_serial_t) arg2); case KEYCTL_DESCRIBE: return keyctl_describe_key((key_serial_t) arg2, (char __user *) arg3, (unsigned) arg4); case KEYCTL_CLEAR: return keyctl_keyring_clear((key_serial_t) arg2); case KEYCTL_LINK: return keyctl_keyring_link((key_serial_t) arg2, (key_serial_t) arg3); case KEYCTL_UNLINK: return keyctl_keyring_unlink((key_serial_t) arg2, (key_serial_t) arg3); case KEYCTL_SEARCH: return keyctl_keyring_search((key_serial_t) arg2, (const char __user *) arg3, (const char __user *) arg4, (key_serial_t) arg5); case KEYCTL_READ: return keyctl_read_key((key_serial_t) arg2, (char __user *) arg3, (size_t) arg4); case KEYCTL_CHOWN: return keyctl_chown_key((key_serial_t) arg2, (uid_t) arg3, (gid_t) arg4); case KEYCTL_SETPERM: return keyctl_setperm_key((key_serial_t) arg2, (key_perm_t) arg3); case KEYCTL_INSTANTIATE: return keyctl_instantiate_key((key_serial_t) arg2, (const void __user *) arg3, (size_t) arg4, (key_serial_t) arg5); case KEYCTL_NEGATE: return keyctl_negate_key((key_serial_t) arg2, (unsigned) arg3, (key_serial_t) arg4); case KEYCTL_SET_REQKEY_KEYRING: return keyctl_set_reqkey_keyring(arg2); case KEYCTL_SET_TIMEOUT: return keyctl_set_timeout((key_serial_t) arg2, (unsigned) arg3); case KEYCTL_ASSUME_AUTHORITY: return keyctl_assume_authority((key_serial_t) arg2); case KEYCTL_GET_SECURITY: return keyctl_get_security((key_serial_t) arg2, (char __user *) arg3, (size_t) arg4); case KEYCTL_SESSION_TO_PARENT: return keyctl_session_to_parent(); case KEYCTL_REJECT: return keyctl_reject_key((key_serial_t) arg2, (unsigned) arg3, (unsigned) arg4, (key_serial_t) arg5); case KEYCTL_INSTANTIATE_IOV: return keyctl_instantiate_key_iov( (key_serial_t) arg2, (const struct iovec __user *) arg3, (unsigned) arg4, (key_serial_t) arg5); case KEYCTL_INVALIDATE: return keyctl_invalidate_key((key_serial_t) arg2); case KEYCTL_GET_PERSISTENT: return keyctl_get_persistent((uid_t)arg2, (key_serial_t)arg3); case KEYCTL_DH_COMPUTE: return keyctl_dh_compute((struct keyctl_dh_params __user *) arg2, (char __user *) arg3, (size_t) arg4, (void __user *) arg5); default: return -EOPNOTSUPP; } }
0
176,685
bool SelectFileDialogImpl::IsRunning(HWND owning_hwnd) const { return listener_ && IsRunningDialogForOwner(owning_hwnd); }
0
7,032
int cli_scanpe(cli_ctx *ctx) { uint16_t e_magic; /* DOS signature ("MZ") */ uint16_t nsections; uint32_t e_lfanew; /* address of new exe header */ uint32_t ep, vep; /* entry point (raw, virtual) */ uint8_t polipos = 0; time_t timestamp; struct pe_image_file_hdr file_hdr; union { struct pe_image_optional_hdr64 opt64; struct pe_image_optional_hdr32 opt32; } pe_opt; struct pe_image_section_hdr *section_hdr; char sname[9], epbuff[4096], *tempfile; uint32_t epsize; ssize_t bytes, at; unsigned int i, found, upx_success = 0, min = 0, max = 0, err, overlays = 0; unsigned int ssize = 0, dsize = 0, dll = 0, pe_plus = 0, corrupted_cur; int (*upxfn)(const char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t) = NULL; const char *src = NULL; char *dest = NULL; int ndesc, ret = CL_CLEAN, upack = 0, native=0; size_t fsize; uint32_t valign, falign, hdr_size, j; struct cli_exe_section *exe_sections; char timestr[32]; struct pe_image_data_dir *dirs; struct cli_bc_ctx *bc_ctx; fmap_t *map; struct cli_pe_hook_data pedata; #ifdef HAVE__INTERNAL__SHA_COLLECT int sha_collect = ctx->sha_collect; #endif const char *archtype=NULL, *subsystem=NULL; uint32_t viruses_found = 0; #if HAVE_JSON int toval = 0; struct json_object *pe_json=NULL; char jsonbuf[128]; #endif if(!ctx) { cli_errmsg("cli_scanpe: ctx == NULL\n"); return CL_ENULLARG; } #if HAVE_JSON if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) { return CL_ETIMEOUT; } if (ctx->options & CL_SCAN_FILE_PROPERTIES) { pe_json = get_pe_property(ctx); } #endif map = *ctx->fmap; if(fmap_readn(map, &e_magic, 0, sizeof(e_magic)) != sizeof(e_magic)) { cli_dbgmsg("Can't read DOS signature\n"); return CL_CLEAN; } if(EC16(e_magic) != PE_IMAGE_DOS_SIGNATURE && EC16(e_magic) != PE_IMAGE_DOS_SIGNATURE_OLD) { cli_dbgmsg("Invalid DOS signature\n"); return CL_CLEAN; } if(fmap_readn(map, &e_lfanew, 58 + sizeof(e_magic), sizeof(e_lfanew)) != sizeof(e_lfanew)) { cli_dbgmsg("Can't read new header address\n"); /* truncated header? */ if(DETECT_BROKEN_PE) { cli_append_virus(ctx,"Heuristics.Broken.Executable"); return CL_VIRUS; } return CL_CLEAN; } e_lfanew = EC32(e_lfanew); cli_dbgmsg("e_lfanew == %d\n", e_lfanew); if(!e_lfanew) { cli_dbgmsg("Not a PE file\n"); return CL_CLEAN; } if(fmap_readn(map, &file_hdr, e_lfanew, sizeof(struct pe_image_file_hdr)) != sizeof(struct pe_image_file_hdr)) { /* bad information in e_lfanew - probably not a PE file */ cli_dbgmsg("Can't read file header\n"); return CL_CLEAN; } if(EC32(file_hdr.Magic) != PE_IMAGE_NT_SIGNATURE) { cli_dbgmsg("Invalid PE signature (probably NE file)\n"); return CL_CLEAN; } if(EC16(file_hdr.Characteristics) & 0x2000) { #if HAVE_JSON if ((pe_json)) cli_jsonstr(pe_json, "Type", "DLL"); #endif cli_dbgmsg("File type: DLL\n"); dll = 1; } else if(EC16(file_hdr.Characteristics) & 0x01) { #if HAVE_JSON if ((pe_json)) cli_jsonstr(pe_json, "Type", "EXE"); #endif cli_dbgmsg("File type: Executable\n"); } switch(EC16(file_hdr.Machine)) { case 0x0: archtype = "Unknown"; break; case 0x14c: archtype = "80386"; break; case 0x14d: archtype = "80486"; break; case 0x14e: archtype = "80586"; break; case 0x160: archtype = "R30000 (big-endian)"; break; case 0x162: archtype = "R3000"; break; case 0x166: archtype = "R4000"; break; case 0x168: archtype = "R10000"; break; case 0x184: archtype = "DEC Alpha AXP"; break; case 0x284: archtype = "DEC Alpha AXP 64bit"; break; case 0x1f0: archtype = "PowerPC"; break; case 0x200: archtype = "IA64"; break; case 0x268: archtype = "M68k"; break; case 0x266: archtype = "MIPS16"; break; case 0x366: archtype = "MIPS+FPU"; break; case 0x466: archtype = "MIPS16+FPU"; break; case 0x1a2: archtype = "Hitachi SH3"; break; case 0x1a3: archtype = "Hitachi SH3-DSP"; break; case 0x1a4: archtype = "Hitachi SH3-E"; break; case 0x1a6: archtype = "Hitachi SH4"; break; case 0x1a8: archtype = "Hitachi SH5"; break; case 0x1c0: archtype = "ARM"; break; case 0x1c2: archtype = "THUMB"; break; case 0x1d3: archtype = "AM33"; break; case 0x520: archtype = "Infineon TriCore"; break; case 0xcef: archtype = "CEF"; break; case 0xebc: archtype = "EFI Byte Code"; break; case 0x9041: archtype = "M32R"; break; case 0xc0ee: archtype = "CEEE"; break; case 0x8664: archtype = "AMD64"; break; default: archtype = "Unknown"; } if ((archtype)) { cli_dbgmsg("Machine type: %s\n", archtype); #if HAVE_JSON cli_jsonstr(pe_json, "ArchType", archtype); #endif } nsections = EC16(file_hdr.NumberOfSections); if(nsections < 1 || nsections > 96) { #if HAVE_JSON pe_add_heuristic_property(ctx, "BadNumberOfSections"); #endif if(DETECT_BROKEN_PE) { cli_append_virus(ctx,"Heuristics.Broken.Executable"); return CL_VIRUS; } if(!ctx->corrupted_input) { if(nsections) cli_warnmsg("PE file contains %d sections\n", nsections); else cli_warnmsg("PE file contains no sections\n"); } return CL_CLEAN; } cli_dbgmsg("NumberOfSections: %d\n", nsections); timestamp = (time_t) EC32(file_hdr.TimeDateStamp); cli_dbgmsg("TimeDateStamp: %s", cli_ctime(&timestamp, timestr, sizeof(timestr))); #if HAVE_JSON cli_jsonstr(pe_json, "TimeDateStamp", cli_ctime(&timestamp, timestr, sizeof(timestr))); #endif cli_dbgmsg("SizeOfOptionalHeader: %x\n", EC16(file_hdr.SizeOfOptionalHeader)); #if HAVE_JSON cli_jsonint(pe_json, "SizeOfOptionalHeader", EC16(file_hdr.SizeOfOptionalHeader)); #endif if (EC16(file_hdr.SizeOfOptionalHeader) < sizeof(struct pe_image_optional_hdr32)) { #if HAVE_JSON pe_add_heuristic_property(ctx, "BadOptionalHeaderSize"); #endif cli_dbgmsg("SizeOfOptionalHeader too small\n"); if(DETECT_BROKEN_PE) { cli_append_virus(ctx,"Heuristics.Broken.Executable"); return CL_VIRUS; } return CL_CLEAN; } at = e_lfanew + sizeof(struct pe_image_file_hdr); if(fmap_readn(map, &optional_hdr32, at, sizeof(struct pe_image_optional_hdr32)) != sizeof(struct pe_image_optional_hdr32)) { cli_dbgmsg("Can't read optional file header\n"); if(DETECT_BROKEN_PE) { cli_append_virus(ctx,"Heuristics.Broken.Executable"); return CL_VIRUS; } return CL_CLEAN; } at += sizeof(struct pe_image_optional_hdr32); /* This will be a chicken and egg problem until we drop 9x */ if(EC16(optional_hdr64.Magic)==PE32P_SIGNATURE) { #if HAVE_JSON pe_add_heuristic_property(ctx, "BadOptionalHeaderSizePE32Plus"); #endif if(EC16(file_hdr.SizeOfOptionalHeader)!=sizeof(struct pe_image_optional_hdr64)) { /* FIXME: need to play around a bit more with xp64 */ cli_dbgmsg("Incorrect SizeOfOptionalHeader for PE32+\n"); if(DETECT_BROKEN_PE) { cli_append_virus(ctx,"Heuristics.Broken.Executable"); return CL_VIRUS; } return CL_CLEAN; } pe_plus = 1; } if(!pe_plus) { /* PE */ if (EC16(file_hdr.SizeOfOptionalHeader)!=sizeof(struct pe_image_optional_hdr32)) { /* Seek to the end of the long header */ at += EC16(file_hdr.SizeOfOptionalHeader)-sizeof(struct pe_image_optional_hdr32); } if(DCONF & PE_CONF_UPACK) upack = (EC16(file_hdr.SizeOfOptionalHeader)==0x148); vep = EC32(optional_hdr32.AddressOfEntryPoint); hdr_size = EC32(optional_hdr32.SizeOfHeaders); cli_dbgmsg("File format: PE\n"); cli_dbgmsg("MajorLinkerVersion: %d\n", optional_hdr32.MajorLinkerVersion); cli_dbgmsg("MinorLinkerVersion: %d\n", optional_hdr32.MinorLinkerVersion); cli_dbgmsg("SizeOfCode: 0x%x\n", EC32(optional_hdr32.SizeOfCode)); cli_dbgmsg("SizeOfInitializedData: 0x%x\n", EC32(optional_hdr32.SizeOfInitializedData)); cli_dbgmsg("SizeOfUninitializedData: 0x%x\n", EC32(optional_hdr32.SizeOfUninitializedData)); cli_dbgmsg("AddressOfEntryPoint: 0x%x\n", vep); cli_dbgmsg("BaseOfCode: 0x%x\n", EC32(optional_hdr32.BaseOfCode)); cli_dbgmsg("SectionAlignment: 0x%x\n", EC32(optional_hdr32.SectionAlignment)); cli_dbgmsg("FileAlignment: 0x%x\n", EC32(optional_hdr32.FileAlignment)); cli_dbgmsg("MajorSubsystemVersion: %d\n", EC16(optional_hdr32.MajorSubsystemVersion)); cli_dbgmsg("MinorSubsystemVersion: %d\n", EC16(optional_hdr32.MinorSubsystemVersion)); cli_dbgmsg("SizeOfImage: 0x%x\n", EC32(optional_hdr32.SizeOfImage)); cli_dbgmsg("SizeOfHeaders: 0x%x\n", hdr_size); cli_dbgmsg("NumberOfRvaAndSizes: %d\n", EC32(optional_hdr32.NumberOfRvaAndSizes)); dirs = optional_hdr32.DataDirectory; #if HAVE_JSON cli_jsonint(pe_json, "MajorLinkerVersion", optional_hdr32.MajorLinkerVersion); cli_jsonint(pe_json, "MinorLinkerVersion", optional_hdr32.MinorLinkerVersion); cli_jsonint(pe_json, "SizeOfCode", EC32(optional_hdr32.SizeOfCode)); cli_jsonint(pe_json, "SizeOfInitializedData", EC32(optional_hdr32.SizeOfInitializedData)); cli_jsonint(pe_json, "SizeOfUninitializedData", EC32(optional_hdr32.SizeOfUninitializedData)); cli_jsonint(pe_json, "NumberOfRvaAndSizes", EC32(optional_hdr32.NumberOfRvaAndSizes)); cli_jsonint(pe_json, "MajorSubsystemVersion", EC16(optional_hdr32.MajorSubsystemVersion)); cli_jsonint(pe_json, "MinorSubsystemVersion", EC16(optional_hdr32.MinorSubsystemVersion)); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", EC32(optional_hdr32.BaseOfCode)); cli_jsonstr(pe_json, "BaseOfCode", jsonbuf); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", EC32(optional_hdr32.SectionAlignment)); cli_jsonstr(pe_json, "SectionAlignment", jsonbuf); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", EC32(optional_hdr32.FileAlignment)); cli_jsonstr(pe_json, "FileAlignment", jsonbuf); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", EC32(optional_hdr32.SizeOfImage)); cli_jsonstr(pe_json, "SizeOfImage", jsonbuf); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", hdr_size); cli_jsonstr(pe_json, "SizeOfHeaders", jsonbuf); #endif } else { /* PE+ */ /* read the remaining part of the header */ if(fmap_readn(map, &optional_hdr32 + 1, at, sizeof(struct pe_image_optional_hdr64) - sizeof(struct pe_image_optional_hdr32)) != sizeof(struct pe_image_optional_hdr64) - sizeof(struct pe_image_optional_hdr32)) { cli_dbgmsg("Can't read optional file header\n"); if(DETECT_BROKEN_PE) { cli_append_virus(ctx,"Heuristics.Broken.Executable"); return CL_VIRUS; } return CL_CLEAN; } at += sizeof(struct pe_image_optional_hdr64) - sizeof(struct pe_image_optional_hdr32); vep = EC32(optional_hdr64.AddressOfEntryPoint); hdr_size = EC32(optional_hdr64.SizeOfHeaders); cli_dbgmsg("File format: PE32+\n"); cli_dbgmsg("MajorLinkerVersion: %d\n", optional_hdr64.MajorLinkerVersion); cli_dbgmsg("MinorLinkerVersion: %d\n", optional_hdr64.MinorLinkerVersion); cli_dbgmsg("SizeOfCode: 0x%x\n", EC32(optional_hdr64.SizeOfCode)); cli_dbgmsg("SizeOfInitializedData: 0x%x\n", EC32(optional_hdr64.SizeOfInitializedData)); cli_dbgmsg("SizeOfUninitializedData: 0x%x\n", EC32(optional_hdr64.SizeOfUninitializedData)); cli_dbgmsg("AddressOfEntryPoint: 0x%x\n", vep); cli_dbgmsg("BaseOfCode: 0x%x\n", EC32(optional_hdr64.BaseOfCode)); cli_dbgmsg("SectionAlignment: 0x%x\n", EC32(optional_hdr64.SectionAlignment)); cli_dbgmsg("FileAlignment: 0x%x\n", EC32(optional_hdr64.FileAlignment)); cli_dbgmsg("MajorSubsystemVersion: %d\n", EC16(optional_hdr64.MajorSubsystemVersion)); cli_dbgmsg("MinorSubsystemVersion: %d\n", EC16(optional_hdr64.MinorSubsystemVersion)); cli_dbgmsg("SizeOfImage: 0x%x\n", EC32(optional_hdr64.SizeOfImage)); cli_dbgmsg("SizeOfHeaders: 0x%x\n", hdr_size); cli_dbgmsg("NumberOfRvaAndSizes: %d\n", EC32(optional_hdr64.NumberOfRvaAndSizes)); dirs = optional_hdr64.DataDirectory; #if HAVE_JSON cli_jsonint(pe_json, "MajorLinkerVersion", optional_hdr64.MajorLinkerVersion); cli_jsonint(pe_json, "MinorLinkerVersion", optional_hdr64.MinorLinkerVersion); cli_jsonint(pe_json, "SizeOfCode", EC32(optional_hdr64.SizeOfCode)); cli_jsonint(pe_json, "SizeOfInitializedData", EC32(optional_hdr64.SizeOfInitializedData)); cli_jsonint(pe_json, "SizeOfUninitializedData", EC32(optional_hdr64.SizeOfUninitializedData)); cli_jsonint(pe_json, "NumberOfRvaAndSizes", EC32(optional_hdr64.NumberOfRvaAndSizes)); cli_jsonint(pe_json, "MajorSubsystemVersion", EC16(optional_hdr64.MajorSubsystemVersion)); cli_jsonint(pe_json, "MinorSubsystemVersion", EC16(optional_hdr64.MinorSubsystemVersion)); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", EC32(optional_hdr64.BaseOfCode)); cli_jsonstr(pe_json, "BaseOfCode", jsonbuf); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", EC32(optional_hdr64.SectionAlignment)); cli_jsonstr(pe_json, "SectionAlignment", jsonbuf); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", EC32(optional_hdr64.FileAlignment)); cli_jsonstr(pe_json, "FileAlignment", jsonbuf); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", EC32(optional_hdr64.SizeOfImage)); cli_jsonstr(pe_json, "SizeOfImage", jsonbuf); snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", hdr_size); cli_jsonstr(pe_json, "SizeOfHeaders", jsonbuf); #endif } #if HAVE_JSON if (ctx->options & CL_SCAN_FILE_PROPERTIES) { snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", vep); cli_jsonstr(pe_json, "EntryPoint", jsonbuf); } #endif switch(pe_plus ? EC16(optional_hdr64.Subsystem) : EC16(optional_hdr32.Subsystem)) { case 0: subsystem = "Unknown"; break; case 1: subsystem = "Native (svc)"; native = 1; break; case 2: subsystem = "Win32 GUI"; break; case 3: subsystem = "Win32 console"; break; case 5: subsystem = "OS/2 console"; break; case 7: subsystem = "POSIX console"; break; case 8: subsystem = "Native Win9x driver"; break; case 9: subsystem = "WinCE GUI"; break; case 10: subsystem = "EFI application"; break; case 11: subsystem = "EFI driver"; break; case 12: subsystem = "EFI runtime driver"; break; case 13: subsystem = "EFI ROM image"; break; case 14: subsystem = "Xbox"; break; case 16: subsystem = "Boot application"; break; default: subsystem = "Unknown"; } cli_dbgmsg("Subsystem: %s\n", subsystem); #if HAVE_JSON cli_jsonstr(pe_json, "Subsystem", subsystem); #endif cli_dbgmsg("------------------------------------\n"); if (DETECT_BROKEN_PE && !native && (!(pe_plus?EC32(optional_hdr64.SectionAlignment):EC32(optional_hdr32.SectionAlignment)) || (pe_plus?EC32(optional_hdr64.SectionAlignment):EC32(optional_hdr32.SectionAlignment))%0x1000)) { cli_dbgmsg("Bad virtual alignemnt\n"); cli_append_virus(ctx,"Heuristics.Broken.Executable"); return CL_VIRUS; } if (DETECT_BROKEN_PE && !native && (!(pe_plus?EC32(optional_hdr64.FileAlignment):EC32(optional_hdr32.FileAlignment)) || (pe_plus?EC32(optional_hdr64.FileAlignment):EC32(optional_hdr32.FileAlignment))%0x200)) { cli_dbgmsg("Bad file alignemnt\n"); cli_append_virus(ctx, "Heuristics.Broken.Executable"); return CL_VIRUS; } fsize = map->len; section_hdr = (struct pe_image_section_hdr *) cli_calloc(nsections, sizeof(struct pe_image_section_hdr)); if(!section_hdr) { cli_dbgmsg("Can't allocate memory for section headers\n"); return CL_EMEM; } exe_sections = (struct cli_exe_section *) cli_calloc(nsections, sizeof(struct cli_exe_section)); if(!exe_sections) { cli_dbgmsg("Can't allocate memory for section headers\n"); free(section_hdr); return CL_EMEM; } valign = (pe_plus)?EC32(optional_hdr64.SectionAlignment):EC32(optional_hdr32.SectionAlignment); falign = (pe_plus)?EC32(optional_hdr64.FileAlignment):EC32(optional_hdr32.FileAlignment); if(fmap_readn(map, section_hdr, at, sizeof(struct pe_image_section_hdr)*nsections) != (int)(nsections*sizeof(struct pe_image_section_hdr))) { cli_dbgmsg("Can't read section header\n"); cli_dbgmsg("Possibly broken PE file\n"); free(section_hdr); free(exe_sections); if(DETECT_BROKEN_PE) { cli_append_virus(ctx,"Heuristics.Broken.Executable"); return CL_VIRUS; } return CL_CLEAN; } at += sizeof(struct pe_image_section_hdr)*nsections; for(i = 0; falign!=0x200 && i<nsections; i++) { /* file alignment fallback mode - blah */ if (falign && section_hdr[i].SizeOfRawData && EC32(section_hdr[i].PointerToRawData)%falign && !(EC32(section_hdr[i].PointerToRawData)%0x200)) { cli_dbgmsg("Found misaligned section, using 0x200\n"); falign = 0x200; } } hdr_size = PESALIGN(hdr_size, valign); /* Aligned headers virtual size */ #if HAVE_JSON cli_jsonint(pe_json, "NumberOfSections", nsections); #endif for(i = 0; i < nsections; i++) { strncpy(sname, (char *) section_hdr[i].Name, 8); sname[8] = 0; exe_sections[i].rva = PEALIGN(EC32(section_hdr[i].VirtualAddress), valign); exe_sections[i].vsz = PESALIGN(EC32(section_hdr[i].VirtualSize), valign); exe_sections[i].raw = PEALIGN(EC32(section_hdr[i].PointerToRawData), falign); exe_sections[i].rsz = PESALIGN(EC32(section_hdr[i].SizeOfRawData), falign); exe_sections[i].chr = EC32(section_hdr[i].Characteristics); exe_sections[i].urva = EC32(section_hdr[i].VirtualAddress); /* Just in case */ exe_sections[i].uvsz = EC32(section_hdr[i].VirtualSize); exe_sections[i].uraw = EC32(section_hdr[i].PointerToRawData); exe_sections[i].ursz = EC32(section_hdr[i].SizeOfRawData); #if HAVE_JSON add_section_info(ctx, &exe_sections[i]); if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) { free(section_hdr); free(exe_sections); return CL_ETIMEOUT; } #endif if (!exe_sections[i].vsz && exe_sections[i].rsz) exe_sections[i].vsz=PESALIGN(exe_sections[i].ursz, valign); if (exe_sections[i].rsz && fsize>exe_sections[i].raw && !CLI_ISCONTAINED(0, (uint32_t) fsize, exe_sections[i].raw, exe_sections[i].rsz)) exe_sections[i].rsz = fsize - exe_sections[i].raw; cli_dbgmsg("Section %d\n", i); cli_dbgmsg("Section name: %s\n", sname); cli_dbgmsg("Section data (from headers - in memory)\n"); cli_dbgmsg("VirtualSize: 0x%x 0x%x\n", exe_sections[i].uvsz, exe_sections[i].vsz); cli_dbgmsg("VirtualAddress: 0x%x 0x%x\n", exe_sections[i].urva, exe_sections[i].rva); cli_dbgmsg("SizeOfRawData: 0x%x 0x%x\n", exe_sections[i].ursz, exe_sections[i].rsz); cli_dbgmsg("PointerToRawData: 0x%x 0x%x\n", exe_sections[i].uraw, exe_sections[i].raw); if(exe_sections[i].chr & 0x20) { cli_dbgmsg("Section contains executable code\n"); if(exe_sections[i].vsz < exe_sections[i].rsz) { cli_dbgmsg("Section contains free space\n"); /* cli_dbgmsg("Dumping %d bytes\n", section_hdr.SizeOfRawData - section_hdr.VirtualSize); ddump(desc, section_hdr.PointerToRawData + section_hdr.VirtualSize, section_hdr.SizeOfRawData - section_hdr.VirtualSize, cli_gentemp(NULL)); */ } } if(exe_sections[i].chr & 0x20000000) cli_dbgmsg("Section's memory is executable\n"); if(exe_sections[i].chr & 0x80000000) cli_dbgmsg("Section's memory is writeable\n"); if (DETECT_BROKEN_PE && (!valign || (exe_sections[i].urva % valign))) { /* Bad virtual alignment */ cli_dbgmsg("VirtualAddress is misaligned\n"); cli_dbgmsg("------------------------------------\n"); cli_append_virus(ctx, "Heuristics.Broken.Executable"); free(section_hdr); free(exe_sections); return CL_VIRUS; } if (exe_sections[i].rsz) { /* Don't bother with virtual only sections */ if (exe_sections[i].raw >= fsize) { /* really broken */ cli_dbgmsg("Broken PE file - Section %d starts beyond the end of file (Offset@ %lu, Total filesize %lu)\n", i, (unsigned long)exe_sections[i].raw, (unsigned long)fsize); cli_dbgmsg("------------------------------------\n"); free(section_hdr); free(exe_sections); if(DETECT_BROKEN_PE) { cli_append_virus(ctx, "Heuristics.Broken.Executable"); return CL_VIRUS; } return CL_CLEAN; /* no ninjas to see here! move along! */ } if(SCAN_ALGO && (DCONF & PE_CONF_POLIPOS) && !*sname && exe_sections[i].vsz > 40000 && exe_sections[i].vsz < 70000 && exe_sections[i].chr == 0xe0000060) polipos = i; /* check hash section sigs */ if((DCONF & PE_CONF_MD5SECT) && ctx->engine->hm_mdb) { ret = scan_pe_mdb(ctx, &exe_sections[i]); if (ret != CL_CLEAN) { if (ret != CL_VIRUS) cli_errmsg("scan_pe: scan_pe_mdb failed: %s!\n", cl_strerror(ret)); cli_dbgmsg("------------------------------------\n"); free(section_hdr); free(exe_sections); return ret; } } } cli_dbgmsg("------------------------------------\n"); if (exe_sections[i].urva>>31 || exe_sections[i].uvsz>>31 || (exe_sections[i].rsz && exe_sections[i].uraw>>31) || exe_sections[i].ursz>>31) { cli_dbgmsg("Found PE values with sign bit set\n"); free(section_hdr); free(exe_sections); if(DETECT_BROKEN_PE) { cli_append_virus(ctx, "Heuristics.Broken.Executable"); return CL_VIRUS; } return CL_CLEAN; } if(!i) { if (DETECT_BROKEN_PE && exe_sections[i].urva!=hdr_size) { /* Bad first section RVA */ cli_dbgmsg("First section is in the wrong place\n"); cli_append_virus(ctx, "Heuristics.Broken.Executable"); free(section_hdr); free(exe_sections); return CL_VIRUS; } min = exe_sections[i].rva; max = exe_sections[i].rva + exe_sections[i].rsz; } else { if (DETECT_BROKEN_PE && exe_sections[i].urva - exe_sections[i-1].urva != exe_sections[i-1].vsz) { /* No holes, no overlapping, no virtual disorder */ cli_dbgmsg("Virtually misplaced section (wrong order, overlapping, non contiguous)\n"); cli_append_virus(ctx, "Heuristics.Broken.Executable"); free(section_hdr); free(exe_sections); return CL_VIRUS; } if(exe_sections[i].rva < min) min = exe_sections[i].rva; if(exe_sections[i].rva + exe_sections[i].rsz > max) { max = exe_sections[i].rva + exe_sections[i].rsz; overlays = exe_sections[i].raw + exe_sections[i].rsz; } } } free(section_hdr); if(!(ep = cli_rawaddr(vep, exe_sections, nsections, &err, fsize, hdr_size)) && err) { cli_dbgmsg("EntryPoint out of file\n"); free(exe_sections); if(DETECT_BROKEN_PE) { cli_append_virus(ctx,"Heuristics.Broken.Executable"); return CL_VIRUS; } return CL_CLEAN; } #if HAVE_JSON cli_jsonint(pe_json, "EntryPointOffset", ep); if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) { return CL_ETIMEOUT; } #endif cli_dbgmsg("EntryPoint offset: 0x%x (%d)\n", ep, ep); if(pe_plus) { /* Do not continue for PE32+ files */ free(exe_sections); return CL_CLEAN; } epsize = fmap_readn(map, epbuff, ep, 4096); /* Disasm scan disabled since it's now handled by the bytecode */ /* CLI_UNPTEMP("DISASM",(exe_sections,0)); */ /* if(disasmbuf((unsigned char*)epbuff, epsize, ndesc)) */ /* ret = cli_scandesc(ndesc, ctx, CL_TYPE_PE_DISASM, 1, NULL, AC_SCAN_VIR); */ /* close(ndesc); */ /* CLI_TMPUNLK(); */ /* free(tempfile); */ /* if(ret == CL_VIRUS) { */ /* free(exe_sections); */ /* return ret; */ /* } */ if(overlays) { int overlays_sz = fsize - overlays; if(overlays_sz > 0) { ret = cli_scanishield(ctx, overlays, overlays_sz); if(ret != CL_CLEAN) { free(exe_sections); return ret; } } } pedata.nsections = nsections; pedata.ep = ep; pedata.offset = 0; memcpy(&pedata.file_hdr, &file_hdr, sizeof(file_hdr)); memcpy(&pedata.opt32, &pe_opt.opt32, sizeof(pe_opt.opt32)); memcpy(&pedata.opt64, &pe_opt.opt64, sizeof(pe_opt.opt64)); memcpy(&pedata.dirs, dirs, sizeof(pedata.dirs)); pedata.e_lfanew = e_lfanew; pedata.overlays = overlays; pedata.overlays_sz = fsize - overlays; pedata.hdr_size = hdr_size; /* Bytecode BC_PE_ALL hook */ bc_ctx = cli_bytecode_context_alloc(); if (!bc_ctx) { cli_errmsg("cli_scanpe: can't allocate memory for bc_ctx\n"); free(exe_sections); return CL_EMEM; } cli_bytecode_context_setpe(bc_ctx, &pedata, exe_sections); cli_bytecode_context_setctx(bc_ctx, ctx); ret = cli_bytecode_runhook(ctx, ctx->engine, bc_ctx, BC_PE_ALL, map); switch (ret) { case CL_ENULLARG: cli_warnmsg("cli_scanpe: NULL argument supplied\n"); break; case CL_VIRUS: case CL_BREAK: free(exe_sections); cli_bytecode_context_destroy(bc_ctx); return ret == CL_VIRUS ? CL_VIRUS : CL_CLEAN; } cli_bytecode_context_destroy(bc_ctx); /* Attempt to detect some popular polymorphic viruses */ /* W32.Parite.B */ if(SCAN_ALGO && (DCONF & PE_CONF_PARITE) && !dll && epsize == 4096 && ep == exe_sections[nsections - 1].raw) { const char *pt = cli_memstr(epbuff, 4040, "\x47\x65\x74\x50\x72\x6f\x63\x41\x64\x64\x72\x65\x73\x73\x00", 15); if(pt) { pt += 15; if((((uint32_t)cli_readint32(pt) ^ (uint32_t)cli_readint32(pt + 4)) == 0x505a4f) && (((uint32_t)cli_readint32(pt + 8) ^ (uint32_t)cli_readint32(pt + 12)) == 0xffffb) && (((uint32_t)cli_readint32(pt + 16) ^ (uint32_t)cli_readint32(pt + 20)) == 0xb8)) { cli_append_virus(ctx,"Heuristics.W32.Parite.B"); if (!SCAN_ALL) { free(exe_sections); return CL_VIRUS; } viruses_found++; } } } /* Kriz */ if(SCAN_ALGO && (DCONF & PE_CONF_KRIZ) && epsize >= 200 && CLI_ISCONTAINED(exe_sections[nsections - 1].raw, exe_sections[nsections - 1].rsz, ep, 0x0fd2) && epbuff[1]=='\x9c' && epbuff[2]=='\x60') { enum {KZSTRASH,KZSCDELTA,KZSPDELTA,KZSGETSIZE,KZSXORPRFX,KZSXOR,KZSDDELTA,KZSLOOP,KZSTOP}; uint8_t kzs[] = {KZSTRASH,KZSCDELTA,KZSPDELTA,KZSGETSIZE,KZSTRASH,KZSXORPRFX,KZSXOR,KZSTRASH,KZSDDELTA,KZSTRASH,KZSLOOP,KZSTOP}; uint8_t *kzstate = kzs; uint8_t *kzcode = (uint8_t *)epbuff + 3; uint8_t kzdptr=0xff, kzdsize=0xff; int kzlen = 197, kzinitlen=0xffff, kzxorlen=-1; cli_dbgmsg("in kriz\n"); while(*kzstate!=KZSTOP) { uint8_t op; if(kzlen<=6) break; op = *kzcode++; kzlen--; switch (*kzstate) { case KZSTRASH: case KZSGETSIZE: { int opsz=0; switch(op) { case 0x81: kzcode+=5; kzlen-=5; break; case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbd: case 0xbe: case 0xbf: if(*kzstate==KZSGETSIZE && cli_readint32(kzcode)==0x0fd2) { kzinitlen = kzlen-5; kzdsize=op-0xb8; kzstate++; op=4; /* fake the register to avoid breaking out */ cli_dbgmsg("kriz: using #%d as size counter\n", kzdsize); } opsz=4; case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4d: case 0x4e: case 0x4f: op&=7; if(op!=kzdptr && op!=kzdsize) { kzcode+=opsz; kzlen-=opsz; break; } default: kzcode--; kzlen++; kzstate++; } break; } case KZSCDELTA: if(op==0xe8 && (uint32_t)cli_readint32(kzcode) < 0xff) { kzlen-=*kzcode+4; kzcode+=*kzcode+4; kzstate++; } else *kzstate=KZSTOP; break; case KZSPDELTA: if((op&0xf8)==0x58 && (kzdptr=op-0x58)!=4) { kzstate++; cli_dbgmsg("kriz: using #%d as pointer\n", kzdptr); } else *kzstate=KZSTOP; break; case KZSXORPRFX: kzstate++; if(op==0x3e) break; case KZSXOR: if (op==0x80 && *kzcode==kzdptr+0xb0) { kzxorlen=kzlen; kzcode+=+6; kzlen-=+6; kzstate++; } else *kzstate=KZSTOP; break; case KZSDDELTA: if (op==kzdptr+0x48) kzstate++; else *kzstate=KZSTOP; break; case KZSLOOP: if (op==kzdsize+0x48 && *kzcode==0x75 && kzlen-(int8_t)kzcode[1]-3<=kzinitlen && kzlen-(int8_t)kzcode[1]>=kzxorlen) { cli_append_virus(ctx,"Heuristics.W32.Kriz"); if (!SCAN_ALL) { free(exe_sections); return CL_VIRUS; } viruses_found++; } cli_dbgmsg("kriz: loop out of bounds, corrupted sample?\n"); kzstate++; } } } /* W32.Magistr.A/B */ if(SCAN_ALGO && (DCONF & PE_CONF_MAGISTR) && !dll && (nsections>1) && (exe_sections[nsections - 1].chr & 0x80000000)) { uint32_t rsize, vsize, dam = 0; vsize = exe_sections[nsections - 1].uvsz; rsize = exe_sections[nsections - 1].rsz; if(rsize < exe_sections[nsections - 1].ursz) { rsize = exe_sections[nsections - 1].ursz; dam = 1; } if(vsize >= 0x612c && rsize >= 0x612c && ((vsize & 0xff) == 0xec)) { int bw = rsize < 0x7000 ? rsize : 0x7000; const char *tbuff; if((tbuff = fmap_need_off_once(map, exe_sections[nsections - 1].raw + rsize - bw, 4096))) { if(cli_memstr(tbuff, 4091, "\xe8\x2c\x61\x00\x00", 5)) { cli_append_virus(ctx, dam ? "Heuristics.W32.Magistr.A.dam" : "Heuristics.W32.Magistr.A"); if (!SCAN_ALL) { free(exe_sections); return CL_VIRUS; } viruses_found++; } } } else if(rsize >= 0x7000 && vsize >= 0x7000 && ((vsize & 0xff) == 0xed)) { int bw = rsize < 0x8000 ? rsize : 0x8000; const char *tbuff; if((tbuff = fmap_need_off_once(map, exe_sections[nsections - 1].raw + rsize - bw, 4096))) { if(cli_memstr(tbuff, 4091, "\xe8\x04\x72\x00\x00", 5)) { cli_append_virus(ctx,dam ? "Heuristics.W32.Magistr.B.dam" : "Heuristics.W32.Magistr.B"); if (!SCAN_ALL) { free(exe_sections); return CL_VIRUS; } viruses_found++; } } } } /* W32.Polipos.A */ while(polipos && !dll && nsections > 2 && nsections < 13 && e_lfanew <= 0x800 && (EC16(optional_hdr32.Subsystem) == 2 || EC16(optional_hdr32.Subsystem) == 3) && EC16(file_hdr.Machine) == 0x14c && optional_hdr32.SizeOfStackReserve >= 0x80000) { uint32_t jump, jold, *jumps = NULL; const uint8_t *code; unsigned int xsjs = 0; if(exe_sections[0].rsz > CLI_MAX_ALLOCATION) break; if(!exe_sections[0].rsz) break; if(!(code=fmap_need_off_once(map, exe_sections[0].raw, exe_sections[0].rsz))) break; for(i=0; i<exe_sections[0].rsz - 5; i++) { if((uint8_t)(code[i]-0xe8) > 1) continue; jump = cli_rawaddr(exe_sections[0].rva+i+5+cli_readint32(&code[i+1]), exe_sections, nsections, &err, fsize, hdr_size); if(err || !CLI_ISCONTAINED(exe_sections[polipos].raw, exe_sections[polipos].rsz, jump, 9)) continue; if(xsjs % 128 == 0) { if(xsjs == 1280) break; if(!(jumps=(uint32_t *)cli_realloc2(jumps, (xsjs+128)*sizeof(uint32_t)))) { free(exe_sections); return CL_EMEM; } } j=0; for(; j<xsjs; j++) { if(jumps[j]<jump) continue; if(jumps[j]==jump) { xsjs--; break; } jold=jumps[j]; jumps[j]=jump; jump=jold; } jumps[j]=jump; xsjs++; } if(!xsjs) break; cli_dbgmsg("Polipos: Checking %d xsect jump(s)\n", xsjs); for(i=0;i<xsjs;i++) { if(!(code = fmap_need_off_once(map, jumps[i], 9))) continue; if((jump=cli_readint32(code))==0x60ec8b55 || (code[4]==0x0ec && ((jump==0x83ec8b55 && code[6]==0x60) || (jump==0x81ec8b55 && !code[7] && !code[8])))) { cli_append_virus(ctx,"Heuristics.W32.Polipos.A"); if (!SCAN_ALL) { free(jumps); free(exe_sections); return CL_VIRUS; } viruses_found++; } } free(jumps); break; } /* Trojan.Swizzor.Gen */ if (SCAN_ALGO && (DCONF & PE_CONF_SWIZZOR) && nsections > 1 && fsize > 64*1024 && fsize < 4*1024*1024) { if(dirs[2].Size) { struct swizz_stats *stats = cli_calloc(1, sizeof(*stats)); unsigned int m = 1000; ret = CL_CLEAN; if (!stats) ret = CL_EMEM; else { cli_parseres_special(EC32(dirs[2].VirtualAddress), EC32(dirs[2].VirtualAddress), map, exe_sections, nsections, fsize, hdr_size, 0, 0, &m, stats); if ((ret = cli_detect_swizz(stats)) == CL_VIRUS) { cli_append_virus(ctx,"Heuristics.Trojan.Swizzor.Gen"); } free(stats); } if (ret != CL_CLEAN) { if (!(ret == CL_VIRUS && SCAN_ALL)) { free(exe_sections); return ret; } viruses_found++; } } } /* !!!!!!!!!!!!!! PACKERS START HERE !!!!!!!!!!!!!! */ corrupted_cur = ctx->corrupted_input; ctx->corrupted_input = 2; /* caller will reset on return */ /* UPX, FSG, MEW support */ /* try to find the first section with physical size == 0 */ found = 0; if(DCONF & (PE_CONF_UPX | PE_CONF_FSG | PE_CONF_MEW)) { for(i = 0; i < (unsigned int) nsections - 1; i++) { if(!exe_sections[i].rsz && exe_sections[i].vsz && exe_sections[i + 1].rsz && exe_sections[i + 1].vsz) { found = 1; cli_dbgmsg("UPX/FSG/MEW: empty section found - assuming compression\n"); #if HAVE_JSON cli_jsonbool(pe_json, "HasEmptySection", 1); #endif break; } } } /* MEW support */ if (found && (DCONF & PE_CONF_MEW) && epsize>=16 && epbuff[0]=='\xe9') { uint32_t fileoffset; const char *tbuff; fileoffset = (vep + cli_readint32(epbuff + 1) + 5); while (fileoffset == 0x154 || fileoffset == 0x158) { char *src; uint32_t offdiff, uselzma; cli_dbgmsg ("MEW: found MEW characteristics %08X + %08X + 5 = %08X\n", cli_readint32(epbuff + 1), vep, cli_readint32(epbuff + 1) + vep + 5); if(!(tbuff = fmap_need_off_once(map, fileoffset, 0xb0))) break; if (fileoffset == 0x154) cli_dbgmsg("MEW: Win9x compatibility was set!\n"); else cli_dbgmsg("MEW: Win9x compatibility was NOT set!\n"); if((offdiff = cli_readint32(tbuff+1) - EC32(optional_hdr32.ImageBase)) <= exe_sections[i + 1].rva || offdiff >= exe_sections[i + 1].rva + exe_sections[i + 1].raw - 4) { cli_dbgmsg("MEW: ESI is not in proper section\n"); break; } offdiff -= exe_sections[i + 1].rva; if(!exe_sections[i + 1].rsz) { cli_dbgmsg("MEW: mew section is empty\n"); break; } ssize = exe_sections[i + 1].vsz; dsize = exe_sections[i].vsz; cli_dbgmsg("MEW: ssize %08x dsize %08x offdiff: %08x\n", ssize, dsize, offdiff); CLI_UNPSIZELIMITS("MEW", MAX(ssize, dsize)); CLI_UNPSIZELIMITS("MEW", MAX(ssize + dsize, exe_sections[i + 1].rsz)); if (exe_sections[i + 1].rsz < offdiff + 12 || exe_sections[i + 1].rsz > ssize) { cli_dbgmsg("MEW: Size mismatch: %08x\n", exe_sections[i + 1].rsz); break; } /* allocate needed buffer */ if (!(src = cli_calloc (ssize + dsize, sizeof(char)))) { free(exe_sections); return CL_EMEM; } if((bytes = fmap_readn(map, src + dsize, exe_sections[i + 1].raw, exe_sections[i + 1].rsz)) != exe_sections[i + 1].rsz) { cli_dbgmsg("MEW: Can't read %d bytes [read: %lu]\n", exe_sections[i + 1].rsz, (unsigned long)bytes); free(exe_sections); free(src); return CL_EREAD; } cli_dbgmsg("MEW: %u (%08x) bytes read\n", (unsigned int)bytes, (unsigned int)bytes); /* count offset to lzma proc, if lzma used, 0xe8 -> call */ if (tbuff[0x7b] == '\xe8') { if (!CLI_ISCONTAINED(exe_sections[1].rva, exe_sections[1].vsz, cli_readint32(tbuff + 0x7c) + fileoffset + 0x80, 4)) { cli_dbgmsg("MEW: lzma proc out of bounds!\n"); free(src); break; /* to next unpacker in chain */ } uselzma = cli_readint32(tbuff + 0x7c) - (exe_sections[0].rva - fileoffset - 0x80); } else { uselzma = 0; } #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "MEW"); #endif CLI_UNPTEMP("MEW",(src,exe_sections,0)); CLI_UNPRESULTS("MEW",(unmew11(src, offdiff, ssize, dsize, EC32(optional_hdr32.ImageBase), exe_sections[0].rva, uselzma, ndesc)),1,(src,0)); break; } } if(epsize<168) { free(exe_sections); return CL_CLEAN; } if (found || upack) { /* Check EP for UPX vs. FSG vs. Upack */ /* Upack 0.39 produces 2 types of executables * 3 sections: | 2 sections (one empty, I don't chech found if !upack, since it's in OR above): * mov esi, value | pusha * lodsd | call $+0x9 * push eax | * * Upack 1.1/1.2 Beta produces [based on 2 samples (sUx) provided by aCaB]: * 2 sections * mov esi, value * loads * mov edi, eax * * Upack unknown [sample 0297729] * 3 sections * mov esi, value * push [esi] * jmp * */ /* upack 0.39-3s + sample 0151477*/ while(((upack && nsections == 3) && /* 3 sections */ (( epbuff[0] == '\xbe' && cli_readint32(epbuff + 1) - EC32(optional_hdr32.ImageBase) > min && /* mov esi */ epbuff[5] == '\xad' && epbuff[6] == '\x50' /* lodsd; push eax */ ) || /* based on 0297729 sample from aCaB */ (epbuff[0] == '\xbe' && cli_readint32(epbuff + 1) - EC32(optional_hdr32.ImageBase) > min && /* mov esi */ epbuff[5] == '\xff' && epbuff[6] == '\x36' /* push [esi] */ ) )) || ((!upack && nsections == 2) && /* 2 sections */ (( /* upack 0.39-2s */ epbuff[0] == '\x60' && epbuff[1] == '\xe8' && cli_readint32(epbuff+2) == 0x9 /* pusha; call+9 */ ) || ( /* upack 1.1/1.2, based on 2 samples */ epbuff[0] == '\xbe' && cli_readint32(epbuff+1) - EC32(optional_hdr32.ImageBase) < min && /* mov esi */ cli_readint32(epbuff + 1) - EC32(optional_hdr32.ImageBase) > 0 && epbuff[5] == '\xad' && epbuff[6] == '\x8b' && epbuff[7] == '\xf8' /* loads; mov edi, eax */ ) )) ) { uint32_t vma, off; int a,b,c; cli_dbgmsg("Upack characteristics found.\n"); a = exe_sections[0].vsz; b = exe_sections[1].vsz; if (upack) { cli_dbgmsg("Upack: var set\n"); c = exe_sections[2].vsz; ssize = exe_sections[0].ursz + exe_sections[0].uraw; off = exe_sections[0].rva; vma = EC32(optional_hdr32.ImageBase) + exe_sections[0].rva; } else { cli_dbgmsg("Upack: var NOT set\n"); c = exe_sections[1].rva; ssize = exe_sections[1].uraw; off = 0; vma = exe_sections[1].rva - exe_sections[1].uraw; } dsize = a+b+c; CLI_UNPSIZELIMITS("Upack", MAX(MAX(dsize, ssize), exe_sections[1].ursz)); if (!CLI_ISCONTAINED(0, dsize, exe_sections[1].rva - off, exe_sections[1].ursz) || (upack && !CLI_ISCONTAINED(0, dsize, exe_sections[2].rva - exe_sections[0].rva, ssize)) || ssize > dsize) { cli_dbgmsg("Upack: probably malformed pe-header, skipping to next unpacker\n"); break; } if((dest = (char *) cli_calloc(dsize, sizeof(char))) == NULL) { free(exe_sections); return CL_EMEM; } if((unsigned int)fmap_readn(map, dest, 0, ssize) != ssize) { cli_dbgmsg("Upack: Can't read raw data of section 0\n"); free(dest); break; } if(upack) memmove(dest + exe_sections[2].rva - exe_sections[0].rva, dest, ssize); if((unsigned int)fmap_readn(map, dest + exe_sections[1].rva - off, exe_sections[1].uraw, exe_sections[1].ursz) != exe_sections[1].ursz) { cli_dbgmsg("Upack: Can't read raw data of section 1\n"); free(dest); break; } #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "Upack"); #endif CLI_UNPTEMP("Upack",(dest,exe_sections,0)); CLI_UNPRESULTS("Upack",(unupack(upack, dest, dsize, epbuff, vma, ep, EC32(optional_hdr32.ImageBase), exe_sections[0].rva, ndesc)),1,(dest,0)); break; } } while(found && (DCONF & PE_CONF_FSG) && epbuff[0] == '\x87' && epbuff[1] == '\x25') { const char *dst; /* FSG v2.0 support - thanks to aCaB ! */ uint32_t newesi, newedi, newebx, newedx; ssize = exe_sections[i + 1].rsz; dsize = exe_sections[i].vsz; CLI_UNPSIZELIMITS("FSG", MAX(dsize, ssize)); if(ssize <= 0x19 || dsize <= ssize) { cli_dbgmsg("FSG: Size mismatch (ssize: %d, dsize: %d)\n", ssize, dsize); free(exe_sections); return CL_CLEAN; } newedx = cli_readint32(epbuff + 2) - EC32(optional_hdr32.ImageBase); if(!CLI_ISCONTAINED(exe_sections[i + 1].rva, exe_sections[i + 1].rsz, newedx, 4)) { cli_dbgmsg("FSG: xchg out of bounds (%x), giving up\n", newedx); break; } if(!exe_sections[i + 1].rsz || !(src = fmap_need_off_once(map, exe_sections[i + 1].raw, ssize))) { cli_dbgmsg("Can't read raw data of section %d\n", i + 1); free(exe_sections); return CL_ESEEK; } dst = src + newedx - exe_sections[i + 1].rva; if(newedx < exe_sections[i + 1].rva || !CLI_ISCONTAINED(src, ssize, dst, 4)) { cli_dbgmsg("FSG: New ESP out of bounds\n"); break; } newedx = cli_readint32(dst) - EC32(optional_hdr32.ImageBase); if(!CLI_ISCONTAINED(exe_sections[i + 1].rva, exe_sections[i + 1].rsz, newedx, 4)) { cli_dbgmsg("FSG: New ESP (%x) is wrong\n", newedx); break; } dst = src + newedx - exe_sections[i + 1].rva; if(!CLI_ISCONTAINED(src, ssize, dst, 32)) { cli_dbgmsg("FSG: New stack out of bounds\n"); break; } newedi = cli_readint32(dst) - EC32(optional_hdr32.ImageBase); newesi = cli_readint32(dst + 4) - EC32(optional_hdr32.ImageBase); newebx = cli_readint32(dst + 16) - EC32(optional_hdr32.ImageBase); newedx = cli_readint32(dst + 20); if(newedi != exe_sections[i].rva) { cli_dbgmsg("FSG: Bad destination buffer (edi is %x should be %x)\n", newedi, exe_sections[i].rva); break; } if(newesi < exe_sections[i + 1].rva || newesi - exe_sections[i + 1].rva >= exe_sections[i + 1].rsz) { cli_dbgmsg("FSG: Source buffer out of section bounds\n"); break; } if(!CLI_ISCONTAINED(exe_sections[i + 1].rva, exe_sections[i + 1].rsz, newebx, 16)) { cli_dbgmsg("FSG: Array of functions out of bounds\n"); break; } newedx=cli_readint32(newebx + 12 - exe_sections[i + 1].rva + src) - EC32(optional_hdr32.ImageBase); cli_dbgmsg("FSG: found old EP @%x\n",newedx); if((dest = (char *) cli_calloc(dsize, sizeof(char))) == NULL) { free(exe_sections); return CL_EMEM; } #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "FSG"); #endif CLI_UNPTEMP("FSG",(dest,exe_sections,0)); CLI_UNPRESULTSFSG2("FSG",(unfsg_200(newesi - exe_sections[i + 1].rva + src, dest, ssize + exe_sections[i + 1].rva - newesi, dsize, newedi, EC32(optional_hdr32.ImageBase), newedx, ndesc)),1,(dest,0)); break; } while(found && (DCONF & PE_CONF_FSG) && epbuff[0] == '\xbe' && cli_readint32(epbuff + 1) - EC32(optional_hdr32.ImageBase) < min) { /* FSG support - v. 1.33 (thx trog for the many samples) */ int sectcnt = 0; const char *support; uint32_t newesi, newedi, oldep, gp, t; struct cli_exe_section *sections; ssize = exe_sections[i + 1].rsz; dsize = exe_sections[i].vsz; CLI_UNPSIZELIMITS("FSG", MAX(dsize, ssize)); if(ssize <= 0x19 || dsize <= ssize) { cli_dbgmsg("FSG: Size mismatch (ssize: %d, dsize: %d)\n", ssize, dsize); free(exe_sections); return CL_CLEAN; } if(!(t = cli_rawaddr(cli_readint32(epbuff + 1) - EC32(optional_hdr32.ImageBase), NULL, 0 , &err, fsize, hdr_size)) && err ) { cli_dbgmsg("FSG: Support data out of padding area\n"); break; } gp = exe_sections[i + 1].raw - t; CLI_UNPSIZELIMITS("FSG", gp); if(!(support = fmap_need_off_once(map, t, gp))) { cli_dbgmsg("Can't read %d bytes from padding area\n", gp); free(exe_sections); return CL_EREAD; } /* newebx = cli_readint32(support) - EC32(optional_hdr32.ImageBase); Unused */ newedi = cli_readint32(support + 4) - EC32(optional_hdr32.ImageBase); /* 1st dest */ newesi = cli_readint32(support + 8) - EC32(optional_hdr32.ImageBase); /* Source */ if(newesi < exe_sections[i + 1].rva || newesi - exe_sections[i + 1].rva >= exe_sections[i + 1].rsz) { cli_dbgmsg("FSG: Source buffer out of section bounds\n"); break; } if(newedi != exe_sections[i].rva) { cli_dbgmsg("FSG: Bad destination (is %x should be %x)\n", newedi, exe_sections[i].rva); break; } /* Counting original sections */ for(t = 12; t < gp - 4; t += 4) { uint32_t rva = cli_readint32(support+t); if(!rva) break; rva -= EC32(optional_hdr32.ImageBase)+1; sectcnt++; if(rva % 0x1000) cli_dbgmsg("FSG: Original section %d is misaligned\n", sectcnt); if(rva < exe_sections[i].rva || rva - exe_sections[i].rva >= exe_sections[i].vsz) { cli_dbgmsg("FSG: Original section %d is out of bounds\n", sectcnt); break; } } if(t >= gp - 4 || cli_readint32(support + t)) { break; } if((sections = (struct cli_exe_section *) cli_malloc((sectcnt + 1) * sizeof(struct cli_exe_section))) == NULL) { cli_errmsg("FSG: Unable to allocate memory for sections %lu\n", (sectcnt + 1) * sizeof(struct cli_exe_section)); free(exe_sections); return CL_EMEM; } sections[0].rva = newedi; for(t = 1; t <= (uint32_t)sectcnt; t++) sections[t].rva = cli_readint32(support + 8 + t * 4) - 1 - EC32(optional_hdr32.ImageBase); if(!exe_sections[i + 1].rsz || !(src = fmap_need_off_once(map, exe_sections[i + 1].raw, ssize))) { cli_dbgmsg("Can't read raw data of section %d\n", i); free(exe_sections); free(sections); return CL_EREAD; } if((dest = (char *) cli_calloc(dsize, sizeof(char))) == NULL) { free(exe_sections); free(sections); return CL_EMEM; } oldep = vep + 161 + 6 + cli_readint32(epbuff+163); cli_dbgmsg("FSG: found old EP @%x\n", oldep); #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "FSG"); #endif CLI_UNPTEMP("FSG",(dest,sections,exe_sections,0)); CLI_UNPRESULTSFSG1("FSG",(unfsg_133(src + newesi - exe_sections[i + 1].rva, dest, ssize + exe_sections[i + 1].rva - newesi, dsize, sections, sectcnt, EC32(optional_hdr32.ImageBase), oldep, ndesc)),1,(dest,sections,0)); break; /* were done with 1.33 */ } while(found && (DCONF & PE_CONF_FSG) && epbuff[0] == '\xbb' && cli_readint32(epbuff + 1) - EC32(optional_hdr32.ImageBase) < min && epbuff[5] == '\xbf' && epbuff[10] == '\xbe' && vep >= exe_sections[i + 1].rva && vep - exe_sections[i + 1].rva > exe_sections[i + 1].rva - 0xe0 ) { /* FSG support - v. 1.31 */ int sectcnt = 0; uint32_t gp, t = cli_rawaddr(cli_readint32(epbuff+1) - EC32(optional_hdr32.ImageBase), NULL, 0 , &err, fsize, hdr_size); const char *support; uint32_t newesi = cli_readint32(epbuff+11) - EC32(optional_hdr32.ImageBase); uint32_t newedi = cli_readint32(epbuff+6) - EC32(optional_hdr32.ImageBase); uint32_t oldep = vep - exe_sections[i + 1].rva; struct cli_exe_section *sections; ssize = exe_sections[i + 1].rsz; dsize = exe_sections[i].vsz; if(err) { cli_dbgmsg("FSG: Support data out of padding area\n"); break; } if(newesi < exe_sections[i + 1].rva || newesi - exe_sections[i + 1].rva >= exe_sections[i + 1].raw) { cli_dbgmsg("FSG: Source buffer out of section bounds\n"); break; } if(newedi != exe_sections[i].rva) { cli_dbgmsg("FSG: Bad destination (is %x should be %x)\n", newedi, exe_sections[i].rva); break; } CLI_UNPSIZELIMITS("FSG", MAX(dsize, ssize)); if(ssize <= 0x19 || dsize <= ssize) { cli_dbgmsg("FSG: Size mismatch (ssize: %d, dsize: %d)\n", ssize, dsize); free(exe_sections); return CL_CLEAN; } gp = exe_sections[i + 1].raw - t; CLI_UNPSIZELIMITS("FSG", gp) if(!(support = fmap_need_off_once(map, t, gp))) { cli_dbgmsg("Can't read %d bytes from padding area\n", gp); free(exe_sections); return CL_EREAD; } /* Counting original sections */ for(t = 0; t < gp - 2; t += 2) { uint32_t rva = support[t]|(support[t+1]<<8); if (rva == 2 || rva == 1) break; rva = ((rva-2)<<12) - EC32(optional_hdr32.ImageBase); sectcnt++; if(rva < exe_sections[i].rva || rva - exe_sections[i].rva >= exe_sections[i].vsz) { cli_dbgmsg("FSG: Original section %d is out of bounds\n", sectcnt); break; } } if(t >= gp-10 || cli_readint32(support + t + 6) != 2) { break; } if((sections = (struct cli_exe_section *) cli_malloc((sectcnt + 1) * sizeof(struct cli_exe_section))) == NULL) { cli_errmsg("FSG: Unable to allocate memory for sections %lu\n", (sectcnt + 1) * sizeof(struct cli_exe_section)); free(exe_sections); return CL_EMEM; } sections[0].rva = newedi; for(t = 0; t <= (uint32_t)sectcnt - 1; t++) { sections[t+1].rva = (((support[t*2]|(support[t*2+1]<<8))-2)<<12)-EC32(optional_hdr32.ImageBase); } if(!exe_sections[i + 1].rsz || !(src = fmap_need_off_once(map, exe_sections[i + 1].raw, ssize))) { cli_dbgmsg("FSG: Can't read raw data of section %d\n", i); free(exe_sections); free(sections); return CL_EREAD; } if((dest = (char *) cli_calloc(dsize, sizeof(char))) == NULL) { free(exe_sections); free(sections); return CL_EMEM; } gp = 0xda + 6*(epbuff[16]=='\xe8'); oldep = vep + gp + 6 + cli_readint32(src+gp+2+oldep); cli_dbgmsg("FSG: found old EP @%x\n", oldep); #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "FSG"); #endif CLI_UNPTEMP("FSG",(dest,sections,exe_sections,0)); CLI_UNPRESULTSFSG1("FSG",(unfsg_133(src + newesi - exe_sections[i + 1].rva, dest, ssize + exe_sections[i + 1].rva - newesi, dsize, sections, sectcnt, EC32(optional_hdr32.ImageBase), oldep, ndesc)),1,(dest,sections,0)); break; /* were done with 1.31 */ } if(found && (DCONF & PE_CONF_UPX)) { /* UPX support */ /* we assume (i + 1) is UPX1 */ ssize = exe_sections[i + 1].rsz; dsize = exe_sections[i].vsz + exe_sections[i + 1].vsz; /* cli_dbgmsg("UPX: ssize %u dsize %u\n", ssize, dsize); */ CLI_UNPSIZELIMITS("UPX", MAX(dsize, ssize)); if(ssize <= 0x19 || dsize <= ssize || dsize > CLI_MAX_ALLOCATION ) { cli_dbgmsg("UPX: Size mismatch or dsize too big (ssize: %d, dsize: %d)\n", ssize, dsize); free(exe_sections); return CL_CLEAN; } if(!exe_sections[i + 1].rsz || !(src = fmap_need_off_once(map, exe_sections[i + 1].raw, ssize))) { cli_dbgmsg("UPX: Can't read raw data of section %d\n", i+1); free(exe_sections); return CL_EREAD; } if((dest = (char *) cli_calloc(dsize + 8192, sizeof(char))) == NULL) { free(exe_sections); return CL_EMEM; } /* try to detect UPX code */ if(cli_memstr(UPX_NRV2B, 24, epbuff + 0x69, 13) || cli_memstr(UPX_NRV2B, 24, epbuff + 0x69 + 8, 13)) { cli_dbgmsg("UPX: Looks like a NRV2B decompression routine\n"); upxfn = upx_inflate2b; } else if(cli_memstr(UPX_NRV2D, 24, epbuff + 0x69, 13) || cli_memstr(UPX_NRV2D, 24, epbuff + 0x69 + 8, 13)) { cli_dbgmsg("UPX: Looks like a NRV2D decompression routine\n"); upxfn = upx_inflate2d; } else if(cli_memstr(UPX_NRV2E, 24, epbuff + 0x69, 13) || cli_memstr(UPX_NRV2E, 24, epbuff + 0x69 + 8, 13)) { cli_dbgmsg("UPX: Looks like a NRV2E decompression routine\n"); upxfn = upx_inflate2e; } if(upxfn) { int skew = cli_readint32(epbuff + 2) - EC32(optional_hdr32.ImageBase) - exe_sections[i + 1].rva; if(epbuff[1] != '\xbe' || skew <= 0 || skew > 0xfff) { /* FIXME: legit skews?? */ skew = 0; } else if ((unsigned int)skew > ssize) { /* Ignore suggested skew larger than section size */ skew = 0; } else { cli_dbgmsg("UPX: UPX1 seems skewed by %d bytes\n", skew); } /* Try skewed first (skew may be zero) */ if(upxfn(src + skew, ssize - skew, dest, &dsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep-skew) >= 0) { upx_success = 1; } /* If skew not successful and non-zero, try no skew */ else if(skew && (upxfn(src, ssize, dest, &dsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep) >= 0)) { upx_success = 1; } if(upx_success) cli_dbgmsg("UPX: Successfully decompressed\n"); else cli_dbgmsg("UPX: Preferred decompressor failed\n"); } if(!upx_success && upxfn != upx_inflate2b) { if(upx_inflate2b(src, ssize, dest, &dsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep) == -1 && upx_inflate2b(src + 0x15, ssize - 0x15, dest, &dsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep - 0x15) == -1) { cli_dbgmsg("UPX: NRV2B decompressor failed\n"); } else { upx_success = 1; cli_dbgmsg("UPX: Successfully decompressed with NRV2B\n"); } } if(!upx_success && upxfn != upx_inflate2d) { if(upx_inflate2d(src, ssize, dest, &dsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep) == -1 && upx_inflate2d(src + 0x15, ssize - 0x15, dest, &dsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep - 0x15) == -1) { cli_dbgmsg("UPX: NRV2D decompressor failed\n"); } else { upx_success = 1; cli_dbgmsg("UPX: Successfully decompressed with NRV2D\n"); } } if(!upx_success && upxfn != upx_inflate2e) { if(upx_inflate2e(src, ssize, dest, &dsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep) == -1 && upx_inflate2e(src + 0x15, ssize - 0x15, dest, &dsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep - 0x15) == -1) { cli_dbgmsg("UPX: NRV2E decompressor failed\n"); } else { upx_success = 1; cli_dbgmsg("UPX: Successfully decompressed with NRV2E\n"); } } if(cli_memstr(UPX_LZMA2, 20, epbuff + 0x2f, 20)) { uint32_t strictdsize=cli_readint32(epbuff+0x21), skew = 0; if(ssize > 0x15 && epbuff[0] == '\x60' && epbuff[1] == '\xbe') { skew = cli_readint32(epbuff+2) - exe_sections[i + 1].rva - optional_hdr32.ImageBase; if(skew!=0x15) skew = 0; } if(strictdsize<=dsize) upx_success = upx_inflatelzma(src+skew, ssize-skew, dest, &strictdsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep) >=0; } else if (cli_memstr(UPX_LZMA1, 20, epbuff + 0x39, 20)) { uint32_t strictdsize=cli_readint32(epbuff+0x2b), skew = 0; if(ssize > 0x15 && epbuff[0] == '\x60' && epbuff[1] == '\xbe') { skew = cli_readint32(epbuff+2) - exe_sections[i + 1].rva - optional_hdr32.ImageBase; if(skew!=0x15) skew = 0; } if(strictdsize<=dsize) upx_success = upx_inflatelzma(src+skew, ssize-skew, dest, &strictdsize, exe_sections[i].rva, exe_sections[i + 1].rva, vep) >=0; } if(!upx_success) { cli_dbgmsg("UPX: All decompressors failed\n"); free(dest); } } if(upx_success) { free(exe_sections); CLI_UNPTEMP("UPX/FSG",(dest,0)); #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "UPX"); #endif if((unsigned int) write(ndesc, dest, dsize) != dsize) { cli_dbgmsg("UPX/FSG: Can't write %d bytes\n", dsize); free(tempfile); free(dest); close(ndesc); return CL_EWRITE; } free(dest); if (lseek(ndesc, 0, SEEK_SET) == -1) { cli_dbgmsg("UPX/FSG: lseek() failed\n"); close(ndesc); CLI_TMPUNLK(); free(tempfile); SHA_RESET; return CL_ESEEK; } if(ctx->engine->keeptmp) cli_dbgmsg("UPX/FSG: Decompressed data saved in %s\n", tempfile); cli_dbgmsg("***** Scanning decompressed file *****\n"); SHA_OFF; if((ret = cli_magic_scandesc(ndesc, ctx)) == CL_VIRUS) { close(ndesc); CLI_TMPUNLK(); free(tempfile); SHA_RESET; return CL_VIRUS; } SHA_RESET; close(ndesc); CLI_TMPUNLK(); free(tempfile); return ret; } /* Petite */ if(epsize<200) { free(exe_sections); return CL_CLEAN; } found = 2; if(epbuff[0] != '\xb8' || (uint32_t) cli_readint32(epbuff + 1) != exe_sections[nsections - 1].rva + EC32(optional_hdr32.ImageBase)) { if(nsections < 2 || epbuff[0] != '\xb8' || (uint32_t) cli_readint32(epbuff + 1) != exe_sections[nsections - 2].rva + EC32(optional_hdr32.ImageBase)) found = 0; else found = 1; } if(found && (DCONF & PE_CONF_PETITE)) { cli_dbgmsg("Petite: v2.%d compression detected\n", found); if(cli_readint32(epbuff + 0x80) == 0x163c988d) { cli_dbgmsg("Petite: level zero compression is not supported yet\n"); } else { dsize = max - min; CLI_UNPSIZELIMITS("Petite", dsize); if((dest = (char *) cli_calloc(dsize, sizeof(char))) == NULL) { cli_dbgmsg("Petite: Can't allocate %d bytes\n", dsize); free(exe_sections); return CL_EMEM; } for(i = 0 ; i < nsections; i++) { if(exe_sections[i].raw) { if(!exe_sections[i].rsz || (unsigned int)fmap_readn(map, dest + exe_sections[i].rva - min, exe_sections[i].raw, exe_sections[i].ursz) != exe_sections[i].ursz) { free(exe_sections); free(dest); return CL_CLEAN; } } } #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "Petite"); #endif CLI_UNPTEMP("Petite",(dest,exe_sections,0)); CLI_UNPRESULTS("Petite",(petite_inflate2x_1to9(dest, min, max - min, exe_sections, nsections - (found == 1 ? 1 : 0), EC32(optional_hdr32.ImageBase),vep, ndesc, found, EC32(optional_hdr32.DataDirectory[2].VirtualAddress),EC32(optional_hdr32.DataDirectory[2].Size))),0,(dest,0)); } } /* PESpin 1.1 */ if((DCONF & PE_CONF_PESPIN) && nsections > 1 && vep >= exe_sections[nsections - 1].rva && vep < exe_sections[nsections - 1].rva + exe_sections[nsections - 1].rsz - 0x3217 - 4 && memcmp(epbuff+4, "\xe8\x00\x00\x00\x00\x8b\x1c\x24\x83\xc3", 10) == 0) { char *spinned; CLI_UNPSIZELIMITS("PEspin", fsize); if((spinned = (char *) cli_malloc(fsize)) == NULL) { cli_errmsg("PESping: Unable to allocate memory for spinned %lu\n", (unsigned long)fsize); free(exe_sections); return CL_EMEM; } if((size_t) fmap_readn(map, spinned, 0, fsize) != fsize) { cli_dbgmsg("PESpin: Can't read %lu bytes\n", (unsigned long)fsize); free(spinned); free(exe_sections); return CL_EREAD; } #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "PEspin"); #endif CLI_UNPTEMP("PESpin",(spinned,exe_sections,0)); CLI_UNPRESULTS_("PEspin",SPINCASE(),(unspin(spinned, fsize, exe_sections, nsections - 1, vep, ndesc, ctx)),0,(spinned,0)); } /* yC 1.3 & variants */ if((DCONF & PE_CONF_YC) && nsections > 1 && (EC32(optional_hdr32.AddressOfEntryPoint) == exe_sections[nsections - 1].rva + 0x60)) { uint32_t ecx = 0; int16_t offset; /* yC 1.3 */ if (!memcmp(epbuff, "\x55\x8B\xEC\x53\x56\x57\x60\xE8\x00\x00\x00\x00\x5D\x81\xED", 15) && !memcmp(epbuff+0x26, "\x8D\x3A\x8B\xF7\x33\xC0\xEB\x04\x90\xEB\x01\xC2\xAC", 13) && ((uint8_t)epbuff[0x13] == 0xB9) && ((uint16_t)(cli_readint16(epbuff+0x18)) == 0xE981) && !memcmp(epbuff+0x1e,"\x8B\xD5\x81\xC2", 4)) { offset = 0; if (0x6c - cli_readint32(epbuff+0xf) + cli_readint32(epbuff+0x22) == 0xC6) ecx = cli_readint32(epbuff+0x14) - cli_readint32(epbuff+0x1a); } /* yC 1.3 variant */ if (!ecx && !memcmp(epbuff, "\x55\x8B\xEC\x83\xEC\x40\x53\x56\x57", 9) && !memcmp(epbuff+0x17, "\xe8\x00\x00\x00\x00\x5d\x81\xed", 8) && ((uint8_t)epbuff[0x23] == 0xB9)) { offset = 0x10; if (0x6c - cli_readint32(epbuff+0x1f) + cli_readint32(epbuff+0x32) == 0xC6) ecx = cli_readint32(epbuff+0x24) - cli_readint32(epbuff+0x2a); } /* yC 1.x/modified */ if (!ecx && !memcmp(epbuff, "\x60\xe8\x00\x00\x00\x00\x5d\x81\xed",9) && ((uint8_t)epbuff[0xd] == 0xb9) && ((uint16_t)cli_readint16(epbuff + 0x12)== 0xbd8d) && !memcmp(epbuff+0x18, "\x8b\xf7\xac", 3)) { offset = -0x18; if (0x66 - cli_readint32(epbuff+0x9) + cli_readint32(epbuff+0x14) == 0xae) ecx = cli_readint32(epbuff+0xe); } if (ecx > 0x800 && ecx < 0x2000 && !memcmp(epbuff+0x63+offset, "\xaa\xe2\xcc", 3) && (fsize >= exe_sections[nsections-1].raw + 0xC6 + ecx + offset)) { char *spinned; if((spinned = (char *) cli_malloc(fsize)) == NULL) { cli_errmsg("yC: Unable to allocate memory for spinned %lu\n", (unsigned long)fsize); free(exe_sections); return CL_EMEM; } if((size_t) fmap_readn(map, spinned, 0, fsize) != fsize) { cli_dbgmsg("yC: Can't read %lu bytes\n", (unsigned long)fsize); free(spinned); free(exe_sections); return CL_EREAD; } #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "yC"); #endif cli_dbgmsg("%d,%d,%d,%d\n", nsections-1, e_lfanew, ecx, offset); CLI_UNPTEMP("yC",(spinned,exe_sections,0)); CLI_UNPRESULTS("yC",(yc_decrypt(spinned, fsize, exe_sections, nsections-1, e_lfanew, ndesc, ecx, offset)),0,(spinned,0)); } } /* WWPack */ while ((DCONF & PE_CONF_WWPACK) && nsections > 1 && vep == exe_sections[nsections - 1].rva && memcmp(epbuff, "\x53\x55\x8b\xe8\x33\xdb\xeb", 7) == 0 && memcmp(epbuff+0x68, "\xe8\x00\x00\x00\x00\x58\x2d\x6d\x00\x00\x00\x50\x60\x33\xc9\x50\x58\x50\x50", 19) == 0) { uint32_t head = exe_sections[nsections - 1].raw; uint8_t *packer; char *src; ssize = 0; for(i=0 ; ; i++) { if(exe_sections[i].raw<head) head=exe_sections[i].raw; if(i+1==nsections) break; if(ssize<exe_sections[i].rva+exe_sections[i].vsz) ssize=exe_sections[i].rva+exe_sections[i].vsz; } if(!head || !ssize || head>ssize) break; CLI_UNPSIZELIMITS("WWPack", ssize); if(!(src=(char *)cli_calloc(ssize, sizeof(char)))) { free(exe_sections); return CL_EMEM; } if((size_t) fmap_readn(map, src, 0, head) != head) { cli_dbgmsg("WWPack: Can't read %d bytes from headers\n", head); free(src); free(exe_sections); return CL_EREAD; } for(i = 0 ; i < (unsigned int)nsections-1; i++) { if(!exe_sections[i].rsz) continue; if(!CLI_ISCONTAINED(src, ssize, src+exe_sections[i].rva, exe_sections[i].rsz)) break; if((unsigned int)fmap_readn(map, src+exe_sections[i].rva, exe_sections[i].raw, exe_sections[i].rsz)!=exe_sections[i].rsz) break; } if(i+1!=nsections) { cli_dbgmsg("WWpack: Probably hacked/damaged file.\n"); free(src); break; } if((packer = (uint8_t *) cli_calloc(exe_sections[nsections - 1].rsz, sizeof(char))) == NULL) { free(src); free(exe_sections); return CL_EMEM; } if(!exe_sections[nsections - 1].rsz || (size_t) fmap_readn(map, packer, exe_sections[nsections - 1].raw, exe_sections[nsections - 1].rsz) != exe_sections[nsections - 1].rsz) { cli_dbgmsg("WWPack: Can't read %d bytes from wwpack sect\n", exe_sections[nsections - 1].rsz); free(src); free(packer); free(exe_sections); return CL_EREAD; } #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "WWPack"); #endif CLI_UNPTEMP("WWPack",(src,packer,exe_sections,0)); CLI_UNPRESULTS("WWPack",(wwunpack((uint8_t *)src, ssize, packer, exe_sections, nsections-1, e_lfanew, ndesc)),0,(src,packer,0)); break; } /* ASPACK support */ while((DCONF & PE_CONF_ASPACK) && ep+58+0x70e < fsize && !memcmp(epbuff,"\x60\xe8\x03\x00\x00\x00\xe9\xeb",8)) { char *src; if(epsize<0x3bf || memcmp(epbuff+0x3b9, "\x68\x00\x00\x00\x00\xc3",6)) break; ssize = 0; for(i=0 ; i< nsections ; i++) if(ssize<exe_sections[i].rva+exe_sections[i].vsz) ssize=exe_sections[i].rva+exe_sections[i].vsz; if(!ssize) break; CLI_UNPSIZELIMITS("Aspack", ssize); if(!(src=(char *)cli_calloc(ssize, sizeof(char)))) { free(exe_sections); return CL_EMEM; } for(i = 0 ; i < (unsigned int)nsections; i++) { if(!exe_sections[i].rsz) continue; if(!CLI_ISCONTAINED(src, ssize, src+exe_sections[i].rva, exe_sections[i].rsz)) break; if((unsigned int)fmap_readn(map, src+exe_sections[i].rva, exe_sections[i].raw, exe_sections[i].rsz)!=exe_sections[i].rsz) break; } if(i!=nsections) { cli_dbgmsg("Aspack: Probably hacked/damaged Aspack file.\n"); free(src); break; } #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "Aspack"); #endif CLI_UNPTEMP("Aspack",(src,exe_sections,0)); CLI_UNPRESULTS("Aspack",(unaspack212((uint8_t *)src, ssize, exe_sections, nsections, vep-1, EC32(optional_hdr32.ImageBase), ndesc)),1,(src,0)); break; } /* NsPack */ while (DCONF & PE_CONF_NSPACK) { uint32_t eprva = vep; uint32_t start_of_stuff, rep = ep; unsigned int nowinldr; const char *nbuff; src=epbuff; if (*epbuff=='\xe9') { /* bitched headers */ eprva = cli_readint32(epbuff+1)+vep+5; if (!(rep = cli_rawaddr(eprva, exe_sections, nsections, &err, fsize, hdr_size)) && err) break; if (!(nbuff = fmap_need_off_once(map, rep, 24))) break; src = nbuff; } if (memcmp(src, "\x9c\x60\xe8\x00\x00\x00\x00\x5d\xb8\x07\x00\x00\x00", 13)) break; nowinldr = 0x54-cli_readint32(src+17); cli_dbgmsg("NsPack: Found *start_of_stuff @delta-%x\n", nowinldr); if(!(nbuff = fmap_need_off_once(map, rep-nowinldr, 4))) break; start_of_stuff=rep+cli_readint32(nbuff); if(!(nbuff = fmap_need_off_once(map, start_of_stuff, 20))) break; src = nbuff; if (!cli_readint32(nbuff)) { start_of_stuff+=4; /* FIXME: more to do */ src+=4; } ssize = cli_readint32(src+5)|0xff; dsize = cli_readint32(src+9); CLI_UNPSIZELIMITS("NsPack", MAX(ssize,dsize)); if (!ssize || !dsize || dsize != exe_sections[0].vsz) break; if (!(dest=cli_malloc(dsize))) { cli_errmsg("NsPack: Unable to allocate memory for dest %u\n", dsize); break; } /* memset(dest, 0xfc, dsize); */ if(!(src = fmap_need_off(map, start_of_stuff, ssize))) { free(dest); break; } /* memset(src, 0x00, ssize); */ eprva+=0x27a; if (!(rep = cli_rawaddr(eprva, exe_sections, nsections, &err, fsize, hdr_size)) && err) { free(dest); break; } if(!(nbuff = fmap_need_off_once(map, rep, 5))) { free(dest); break; } fmap_unneed_off(map, start_of_stuff, ssize); eprva=eprva+5+cli_readint32(nbuff+1); cli_dbgmsg("NsPack: OEP = %08x\n", eprva); #if HAVE_JSON cli_jsonstr(pe_json, "Packer", "NsPack"); #endif CLI_UNPTEMP("NsPack",(dest,exe_sections,0)); CLI_UNPRESULTS("NsPack",(unspack(src, dest, ctx, exe_sections[0].rva, EC32(optional_hdr32.ImageBase), eprva, ndesc)),0,(dest,0)); break; } /* to be continued ... */ /* !!!!!!!!!!!!!! PACKERS END HERE !!!!!!!!!!!!!! */ ctx->corrupted_input = corrupted_cur; /* Bytecode BC_PE_UNPACKER hook */ bc_ctx = cli_bytecode_context_alloc(); if (!bc_ctx) { cli_errmsg("cli_scanpe: can't allocate memory for bc_ctx\n"); return CL_EMEM; } cli_bytecode_context_setpe(bc_ctx, &pedata, exe_sections); cli_bytecode_context_setctx(bc_ctx, ctx); ret = cli_bytecode_runhook(ctx, ctx->engine, bc_ctx, BC_PE_UNPACKER, map); switch (ret) { case CL_VIRUS: free(exe_sections); cli_bytecode_context_destroy(bc_ctx); return CL_VIRUS; case CL_SUCCESS: ndesc = cli_bytecode_context_getresult_file(bc_ctx, &tempfile); cli_bytecode_context_destroy(bc_ctx); if (ndesc != -1 && tempfile) { CLI_UNPRESULTS("bytecode PE hook", 1, 1, (0)); } break; default: cli_bytecode_context_destroy(bc_ctx); } free(exe_sections); #if HAVE_JSON if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) { return CL_ETIMEOUT; } #endif if (SCAN_ALL && viruses_found) return CL_VIRUS; return CL_CLEAN;
1
324,252
static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp) { VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev); DeviceState *vdev = DEVICE(&dev->vdev); DeviceState *qdev = DEVICE(ccw_dev); Error *err = NULL; char *bus_name; /* * For command line compatibility, this sets the virtio-scsi-device bus * name as before. */ if (qdev->id) { bus_name = g_strdup_printf("%s.0", qdev->id); virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name); g_free(bus_name); } qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", &err); if (err) { error_propagate(errp, err); } }
0
372,385
cmsFloat32Number CMSEXPORT cmsEvalToneCurveFloat(const cmsToneCurve* Curve, cmsFloat32Number v) { _cmsAssert(Curve != NULL); // Check for 16 bits table. If so, this is a limited-precision tone curve if (Curve ->nSegments == 0) { cmsUInt16Number In, Out; In = (cmsUInt16Number) _cmsQuickSaturateWord(v * 65535.0); Out = cmsEvalToneCurve16(Curve, In); return (cmsFloat32Number) (Out / 65535.0); } return (cmsFloat32Number) EvalSegmentedFn(Curve, v); }
0
129,415
void CLASS sony_arw2_load_raw() { uchar *data, *dp; ushort pix[16]; int row, col, val, max, min, imax, imin, sh, bit, i; data = (uchar *) malloc (raw_width); merror (data, "sony_arw2_load_raw()"); for (row=0; row < height; row++) { fread (data, 1, raw_width, ifp); for (dp=data, col=0; col < raw_width-30; dp+=16) { max = 0x7ff & (val = sget4(dp)); min = 0x7ff & val >> 11; imax = 0x0f & val >> 22; imin = 0x0f & val >> 26; for (sh=0; sh < 4 && 0x80 << sh <= max-min; sh++); for (bit=30, i=0; i < 16; i++) if (i == imax) pix[i] = max; else if (i == imin) pix[i] = min; else { pix[i] = ((sget2(dp+(bit >> 3)) >> (bit & 7) & 0x7f) << sh) + min; if (pix[i] > 0x7ff) pix[i] = 0x7ff; bit += 7; } for (i=0; i < 16; i++, col+=2) if (col < width) BAYER(row,col) = curve[pix[i] << 1] >> 2; col -= col & 1 ? 1:31; } } free (data); }
0
491,216
TPMI_DH_PERSISTENT_Unmarshal(TPMI_DH_PERSISTENT *target, BYTE **buffer, INT32 *size) { TPM_RC rc = TPM_RC_SUCCESS; TPMI_DH_PERSISTENT orig_target = *target; // libtpms added if (rc == TPM_RC_SUCCESS) { rc = TPM_HANDLE_Unmarshal(target, buffer, size); } if (rc == TPM_RC_SUCCESS) { BOOL isNotPersistent = (*target < PERSISTENT_FIRST) || (*target > PERSISTENT_LAST); if (isNotPersistent) { rc = TPM_RC_VALUE; *target = orig_target; // libtpms added } } return rc; }
0
277,414
bool CSSComputedStyleDeclaration::useFixedFontDefaultSize() const { if (!m_node) return false; RefPtr<RenderStyle> style = m_node->computedStyle(m_pseudoElementSpecifier); if (!style) return false; return style->fontDescription().useFixedDefaultSize(); }
0
492,608
gimp_channel_all (GimpChannel *channel, gboolean push_undo) { g_return_if_fail (GIMP_IS_CHANNEL (channel)); if (! gimp_item_is_attached (GIMP_ITEM (channel))) push_undo = FALSE; GIMP_CHANNEL_GET_CLASS (channel)->all (channel, push_undo); }
0
54,666
static inline void evmcs_load(u64 phys_addr) {}
0
191,094
void RenderView::didExecuteCommand(const WebString& command_name) { const std::string& name = UTF16ToUTF8(command_name); if (StartsWithASCII(name, "Move", true) || StartsWithASCII(name, "Insert", true) || StartsWithASCII(name, "Delete", true)) return; RenderThread::current()->Send( new ViewHostMsg_UserMetricsRecordAction(name)); }
0