void Data::printme(FILE* port) { dfprintf((port, "Data:\n")); dfprintf((port, "\tframeNum = %d\n", frameNum)); dfprintf((port, "\tconfident = %s\n", confident?"true":"false")); dfprintf((port, "\tfailedLastTime = %s\n", failedLastTime?"true":"false")); dfprintf((port, "\tminSize = %dx%d\n", minSize.width, minSize.height)); }
static inline off_t mc_workspace_wanted( int fd ) { struct stat info; # ifndef DEBUG if( (fstat( fd, &info ) == 0) && (info.st_size > (off_t)(0)) ) { dfprintf(( stderr, "allocate workspace: %lu bytes", (unsigned long)(info.st_size) )); return info.st_size; } # endif dfprintf(( stderr, "allocate default workspace: %lu bytes", BUFSIZ )); return (off_t)(BUFSIZ); }
static int dump_report(md_array_printer * printer) { int fd; FILE *fp; char fname[128]; char tname[128]; if (disk_is_full()) { dsyslogf(LOG_NOTICE, "Not enough free disk space to write %s files", printer->format); return 1; } snprintf(fname, 128, "%d.dscdata.%s", Pcap_finish_time(), printer->extension); snprintf(tname, 128, "%s.XXXXXXXXX", fname); fd = mkstemp(tname); if (fd < 0) { dsyslogf(LOG_ERR, "%s: %s", tname, strerror(errno)); return 1; } fp = fdopen(fd, "w"); if (NULL == fp) { dsyslogf(LOG_ERR, "%s: %s", tname, strerror(errno)); close(fd); return 1; } dfprintf(0, "writing to %s", tname); fputs(printer->start_file, fp); /* amalloc_report(); */ pcap_report(fp, printer); dns_message_report(fp, printer); fputs(printer->end_file, fp); /* * XXX need chmod because files are written as root, but may be processed * by a non-priv user */ fchmod(fd, 0664); fclose(fp); dfprintf(0, "renaming to %s", fname); if (rename(tname, fname)) { dsyslogf(LOG_ERR, "unable to move report from %s to %s: %s", tname, fname, strerror(errno)); } return 0; }
void html_ctcp_table(FILE * ptr) { CTCPVerStats *c; lnode_t *tn; char *tempc; int x = 0; if (ptr) { fprintf(ptr, "%s", getstring(NULL, HTML_CTCP_HEADER)); list_sort(CTCPhead, sortctcp); tn = list_first(CTCPhead); while (tn) { c = lnode_get(tn); if (c->overall) { tempc = char_encode(c->version); dfprintf(ptr, getstring(NULL, HTML_CTCP_CONTENT), tempc, c->overall); free(tempc); x++; if (x > 10) { break; } } tn = list_next(CTCPhead, tn); } fprintf(ptr, "%s", getstring(NULL, HTML_CTCP_FOOTER)); } }
/* load PNG, TIFF, JPG, GIF or BMP to PIX datastructure. The actual supported * formats depends on how the leptonica was compiled */ PIX *loadimage(char *filename){ PIX *pix, *pixt; int format, bpp; format=fileformat(filename); // In later versions of leptonica you will have to do this // pixReadHeader(filename, format,NULL,NULL,NULL,bpp,NULL); if(format!=IFF_PNG && format!=IFF_JFIF_JPEG && format!=IFF_TIFF && format!= IFF_GIF && format!=7 && format!=8){ dfprintf(stderr,"Not recognised file format %i", format); return NULL; } if ((pix = pixRead(filename)) == NULL) return NULL; /* TODO: convert image to 1-bpp 300dpi regardless of scan */ bpp=pixGetDepth(pix); if(bpp>1){ /* printf("Bits per pixel=%i",bpp); exit(1); */ //pixThresholdForFgBg(pix,5,100,NULL,NULL); //pixContrastTRC(pix, pix, 1000); pixt = pixContrastNorm(NULL, pix, 10, 10, 40, 2, 2); pixDestroy(&pix); pix = pixGammaTRC(NULL, pixt, 1.5, 50, 235); pixt=pixThresholdToBinary(pix, 200); //pixt=pixThreshold8(pix,1,1,0); pixDestroy(&pix); pix=pixt; } return pix; }
void html_dailystats(FILE * ptr) { char timebuf[64]; struct tm tm; /* <tr><td colspan="2">Total Users Connected:</td> <td colspan="2"> 14839</td></tr> */ SET_SEGV_LOCATION(); if (ptr) { fprintf(ptr, "%s", getstring(NULL, HTML_DAILY_HEADER)); #ifdef MSVS2005 localtime_s(&tm, &stats->daily_users_time); #else tm = *localtime(&stats->daily_users_time); #endif strftime_lang(timebuf, sizeof(timebuf), NULL, STRFTIME_DATE_TIME_FORMAT, &tm); dfprintf(ptr, getstring(NULL, HTML_DAILY_USER), stats->daily_users, timebuf); dfprintf(ptr, getstring(NULL, HTML_DAILY_CHAN), stats->daily_chans); #ifdef MSVS2005 localtime_s(&tm, &stats->daily_opers_time); #else tm = *localtime(&stats->daily_opers_time); #endif strftime_lang(timebuf, sizeof(timebuf), NULL, STRFTIME_DATE_TIME_FORMAT, &tm); dfprintf(ptr, getstring(NULL, HTML_DAILY_OPERS), stats->daily_opers, timebuf); #ifdef MSVS2005 localtime_s(&tm, &stats->daily_servers_time); #else tm = *localtime(&stats->daily_servers_time); #endif strftime_lang(timebuf, sizeof(timebuf), NULL, STRFTIME_DATE_TIME_FORMAT, &tm); dfprintf(ptr, getstring(NULL, HTML_DAILY_SERVERS), stats->daily_servers, timebuf); fprintf(ptr, "%s", getstring(NULL, HTML_DAILY_RESET_AT)); fprintf(ptr, "%s", getstring(NULL, HTML_DAILY_FOOTER)); } }
static inline size_t mc_add_escape( iconv_t *iconv_map, char *msgbuf, wchar_t code ) { /* A trivial helper function, for encoding an escape sequence into the * compiled message stream. */ dfprintf(( stderr, "add escape code: %0#4.4x", code )); return iconv_wctomb( msgbuf, code ); }
int moveFileToQuarantine(char *source_fname){ char fname[1024]; // char picfname[1024]; char *base=calloc(1024,sizeof(char)); char *ridx=rindex(source_fname,'.'); char *ansarray; base=strncpy(base, source_fname,ridx-source_fname); char *picname=rindex(base,'/'); if(picname==NULL) picname=base; //sprintf(fname,"%s/%s.tif",quarantine_dir,picname); sprintf(fname,"%s/%s.%s",processed_dir,picname,ridx+1); int retval=rename(source_fname, fname); free(base); if(retval<0){ dfprintf(stderr,"rename not successful!\n"); return 1; } return 0; }
/* write result file */ int writerezfile(PIX *pixs,char *source_fname,ANS *ans, BAR *bar, SID *sid){ int i; float mincert; char fname[1024]; char picfname[1024]; char *base=calloc(1024,sizeof(char)); // char *ending=calloc(25,sizeof(char)); char *ridx=rindex(source_fname,'.'); char *ansarray; base=strncpy(base, source_fname,ridx-source_fname); char *picname=rindex(base,'/'); if(picname==NULL) picname=base; mincert=100.0; for(i=0;i<SID_LENGTH;i++){ if(sid->certainty[i]<mincert){ mincert=sid->certainty[i]; } } if(bar->barcode==NULL) sprintf(fname,"%s/%s.err",output_dir,picname); else if(mincert<SID_MIN_CERTAINTY) sprintf(fname,"%s/%s.war",output_dir,picname); else sprintf(fname,"%s/%s.rez",output_dir,picname); sprintf(picfname,"%s/%s.png",output_dir,picname); FILE *fh=fopen(fname,"w"); fprintf(fh,"%s\n",bar->barcode+1); fprintf(fh,"%s\n",sid->sid); fprintf(fh,"%s\n",ans->ans_string); fprintf(fh,"%d\n",(int)(mincert*100)); fprintf(fh,"A\n"); /* fprintf(fh,"x=array("); for(i=0;i<ans->up->n-1;i++){ fprintf(fh,"%f,",ans->up->mark[i].x); } fprintf(fh,"%f);",ans->up->mark[i].x); fprintf(fh,"y=array("); for(i=0;i<ans->right->n-1;i++){ fprintf(fh,"%f,",ans->right->mark[i].y); } fprintf(fh,"%f);\n",ans->right->mark[i].y); */ ansarray=ans_array(ans); fprintf(fh,"%s\n",ansarray); free(ansarray); fclose(fh); //rescale image PIX *pixd=pixScale(pixs, (float)1280/pixGetWidth(pixs),(float)1280/pixGetWidth(pixs)); saveimage(pixd,picfname); pixDestroy(&pixd); sprintf(fname,"%s/%s.%s",processed_dir,picname,ridx+1); int retval=rename(source_fname, fname); if(retval<0){ dfprintf(stderr,"rename not successful!\n"); } free(base); return 0; }
void main() { unsigned long* array = NULL; int set = 0, line = 0, k = 0; int start = 0, end = 0; struct timeval before, after; int bad = 0, try = 0, i = 0, tmp = 0; int bit = 0; float miss_time_all, miss_time, hit_time_all, hit_time, miss_hit_ratio, miss_hit_diff; uint32_t buffer = 0; /* Test: unsigned long must be 64bit*/ if( sizeof(unsigned long) != 8) { dfprintf(stderr, "Error: unsigned long must be 8 Byte for the program to work\n"); exit(1); } /* init array and load L1 data cache*/ do { array = malloc(sizeof(unsigned long) * ARRAY_LENGTH); }while( array == NULL && try++ <= 10); if( array == NULL) { dfprintf(stderr, "Error: cannot allocate array size:%d\n", ARRAY_LENGTH); exit(2); } /* Allign the start of the array to be the start of a cache line*/ if( ( (unsigned long)array & 0x038UL ) != 0) /*Start of array is not start of a cache line*/ { start = (0x08 - (( (unsigned long)array & 0x038UL ) >> 0x3)); }else{ start = 0; } dprintf("Allign the array with the cache line: start element's index is:%d\n", start); /* Initialize the array, load all L1 data cache, first round is cache miss, second round is cache hit, get ratio of cache miss/cach hit*/ for(i = 0; i < 2; i++) { for(set = 0; set < SET_NUM; set+=2) { bad = gettimeofday(&before, NULL); assert( !bad ); for( line = 0; line < LINE_NUM; line++) { for( k = get_array_index(set, line); k < get_array_index(set, line) + ELMT_PER_LINE; k++) { if(i == 0) array[k] = 0xFFFFFFFFFFFFFFFF; else tmp = array[k]; } } bad = gettimeofday(&after, NULL); assert( !bad ); if( i == 0 ) miss_time_all += get_elapsed_usec(before, after); else hit_time_all += get_elapsed_usec(before, after); } if( i == 0 ) { miss_time = miss_time_all / (SET_NUM / 2); } else { hit_time = hit_time_all / (SET_NUM / 2); } } dprintf("Initialize the L1D array: Each set(miss) takes:%.2fus; All array(miss) takes %.2fus in total\n", miss_time, miss_time_all); dprintf("Reload the L1D array: Each set(hit) takes:%.2fus; All array(hit) takes %.2f in total\n", hit_time, hit_time_all); miss_hit_ratio = miss_time * 1.0 / hit_time; miss_hit_diff = miss_time - hit_time; dprintf("Ratio of miss to hit per line is %.2f\n", miss_hit_ratio); sleep(2); /* Start the covert channel*/ dprintf("Start receiving the data\n"); buffer = 0; for(set = 0; set < SET_NUM; set += 2) /* Avoid prefetch effect*/ { bit = 0; bad = gettimeofday(&before, NULL); assert( !bad ); for( line = 0; line < LINE_NUM; line++) { for( k = get_array_index(set, line); k < get_array_index(set, line) + ELMT_PER_LINE; k++) { tmp = array[k]; } } bad = gettimeofday(&after, NULL); assert( !bad ); //if(get_elapsed_usec(before, after) / hit_time >= (miss_hit_ratio*3.0/5)) /*miss means the bit is 1*/ if(get_elapsed_usec(before, after) - hit_time >= (miss_hit_diff * 0.5) ) { bit = 1; } dprintf("set %d (bit %d): latency is %ld, miss_hit_diff is %.2f, bit received is: %d\n", set, set/2, get_elapsed_usec(before, after), get_elapsed_usec(before, after) - hit_time, bit); buffer |= (bit << set); //printf("Reload time is %ld, hit_time is %.2f, miss_hit_ratio is %.2f\n", get_elapsed_usec(before, after), hit_time, get_elapsed_usec(before, after) / hit_time); /* if( set%8 == 0 ) printf(" "); printf("%d", bit); */ } /* printf("\n"); */ printf("Receive 32bit: %#010x\n", buffer); free(array); }
int do_bzImage_load(struct kexec_info *info, const char *kernel, off_t kernel_len, const char *command_line, off_t command_line_len, const char *initrd, off_t initrd_len, int real_mode_entry, int debug) { struct x86_linux_header setup_header; struct x86_linux_param_header *real_mode; int setup_sects; char *kernel_version; size_t size; int kern16_size; unsigned long setup_base, setup_size; struct entry32_regs regs32; struct entry16_regs regs16; unsigned int relocatable_kernel = 0; unsigned long kernel32_load_addr; char *modified_cmdline; /* * Find out about the file I am about to load. */ if (kernel_len < sizeof(setup_header)) { return -1; } memcpy(&setup_header, kernel, sizeof(setup_header)); setup_sects = setup_header.setup_sects; if (setup_sects == 0) { setup_sects = 4; } kern16_size = (setup_sects +1) *512; kernel_version = ((unsigned char *)&setup_header) + 512 + setup_header.kver_addr; if (kernel_len < kern16_size) { fprintf(stderr, "BzImage truncated?\n"); return -1; } if (setup_header.protocol_version >= 0x0205) { relocatable_kernel = setup_header.relocatable_kernel; dfprintf(stdout, "bzImage is relocatable\n"); } /* Can't use bzImage for crash dump purposes with real mode entry */ if((info->kexec_flags & KEXEC_ON_CRASH) && real_mode_entry) { fprintf(stderr, "Can't use bzImage for crash dump purposes" " with real mode entry\n"); return -1; } if((info->kexec_flags & KEXEC_ON_CRASH) && !relocatable_kernel) { fprintf(stderr, "BzImage is not relocatable. Can't be used" " as capture kernel.\n"); return -1; } /* Need to append some command line parameters internally in case of * taking crash dumps. */ if (info->kexec_flags & KEXEC_ON_CRASH) { modified_cmdline = xmalloc(COMMAND_LINE_SIZE); memset((void *)modified_cmdline, 0, COMMAND_LINE_SIZE); if (command_line) { strncpy(modified_cmdline, command_line, COMMAND_LINE_SIZE); modified_cmdline[COMMAND_LINE_SIZE - 1] = '\0'; } /* If panic kernel is being loaded, additional segments need * to be created. load_crashdump_segments will take care of * loading the segments as high in memory as possible, hence * in turn as away as possible from kernel to avoid being * stomped by the kernel. */ if (load_crashdump_segments(info, modified_cmdline, -1, 0) < 0) return -1; /* Use new command line buffer */ command_line = modified_cmdline; command_line_len = strlen(command_line) +1; } /* Load the trampoline. This must load at a higher address * the the argument/parameter segment or the kernel will stomp * it's gdt. * * x86_64 purgatory code has got relocations type R_X86_64_32S * that means purgatory got to be loaded within first 2G otherwise * overflow takes place while applying relocations. */ if (!real_mode_entry && relocatable_kernel) elf_rel_build_load(info, &info->rhdr, purgatory, purgatory_size, 0x3000, 0x7fffffff, -1, 0); else elf_rel_build_load(info, &info->rhdr, purgatory, purgatory_size, 0x3000, 640*1024, -1, 0); dfprintf(stdout, "Loaded purgatory at addr 0x%lx\n", info->rhdr.rel_addr); /* The argument/parameter segment */ setup_size = kern16_size + command_line_len; real_mode = xmalloc(setup_size); memcpy(real_mode, kernel, kern16_size); if (info->kexec_flags & KEXEC_ON_CRASH) { /* If using bzImage for capture kernel, then we will not be * executing real mode code. setup segment can be loaded * anywhere as we will be just reading command line. */ setup_base = add_buffer(info, real_mode, setup_size, setup_size, 16, 0x3000, -1, 1); } else if (real_mode->protocol_version >= 0x0200) { /* Careful setup_base must be greater than 8K */ setup_base = add_buffer(info, real_mode, setup_size, setup_size, 16, 0x3000, 640*1024, 1); } else { add_segment(info, real_mode, setup_size, SETUP_BASE, setup_size); setup_base = SETUP_BASE; } dfprintf(stdout, "Loaded real-mode code and command line at 0x%lx\n", setup_base); /* Verify purgatory loads higher than the parameters */ if (info->rhdr.rel_addr < setup_base) { die("Could not put setup code above the kernel parameters\n"); } /* The main kernel segment */ size = kernel_len - kern16_size; if (real_mode->protocol_version >=0x0205 && relocatable_kernel) { /* Relocatable bzImage */ unsigned long kern_align = real_mode->kernel_alignment; unsigned long kernel32_max_addr = DEFAULT_BZIMAGE_ADDR_MAX; if (real_mode->protocol_version >= 0x0203) { if (kernel32_max_addr > real_mode->initrd_addr_max) kernel32_max_addr = real_mode->initrd_addr_max; } kernel32_load_addr = add_buffer(info, kernel + kern16_size, size, size, kern_align, 0x100000, kernel32_max_addr, 1); } else { kernel32_load_addr = KERN32_BASE; add_segment(info, kernel + kern16_size, size, kernel32_load_addr, size); } dfprintf(stdout, "Loaded 32bit kernel at 0x%lx\n", kernel32_load_addr); /* Tell the kernel what is going on */ setup_linux_bootloader_parameters(info, real_mode, setup_base, kern16_size, command_line, command_line_len, initrd, initrd_len); /* Get the initial register values */ elf_rel_get_symbol(&info->rhdr, "entry16_regs", ®s16, sizeof(regs16)); elf_rel_get_symbol(&info->rhdr, "entry32_regs", ®s32, sizeof(regs32)); /* * Initialize the 32bit start information. */ regs32.eax = 0; /* unused */ regs32.ebx = 0; /* 0 == boot not AP processor start */ regs32.ecx = 0; /* unused */ regs32.edx = 0; /* unused */ regs32.esi = setup_base; /* kernel parameters */ regs32.edi = 0; /* unused */ regs32.esp = elf_rel_get_addr(&info->rhdr, "stack_end"); /* stack, unused */ regs32.ebp = 0; /* unused */ regs32.eip = kernel32_load_addr; /* kernel entry point */ /* * Initialize the 16bit start information. */ regs16.cs = (setup_base>>4) + 0x20; regs16.ip = 0; regs16.ss = (elf_rel_get_addr(&info->rhdr, "stack_end") - 64*1024) >> 4; regs16.esp = 0xFFFC; if (real_mode_entry) { printf("Starting the kernel in real mode\n"); regs32.eip = elf_rel_get_addr(&info->rhdr, "entry16"); } if (real_mode_entry && debug) { unsigned long entry16_debug, pre32, first32; uint32_t old_first32; /* Find the location of the symbols */ entry16_debug = elf_rel_get_addr(&info->rhdr, "entry16_debug"); pre32 = elf_rel_get_addr(&info->rhdr, "entry16_debug_pre32"); first32 = elf_rel_get_addr(&info->rhdr, "entry16_debug_first32"); /* Hook all of the linux kernel hooks */ real_mode->rmode_switch_cs = entry16_debug >> 4; real_mode->rmode_switch_ip = pre32 - entry16_debug; old_first32 = real_mode->kernel_start; real_mode->kernel_start = first32; elf_rel_set_symbol(&info->rhdr, "entry16_debug_old_first32", &old_first32, sizeof(old_first32)); regs32.eip = entry16_debug; }