void refresh_mesgs(t_interface *in, t_list list) { t_message *tmp; int i; int j; i = 15; clear_mesgs(in); while (list != NULL) { tmp = (t_message *)list->value; j = (strlen(tmp->msg) / 58) + ((strlen(tmp->msg) % 58 != 0) ? 1 : 0) - 1; while (j >= 0 && i > 0) { mvwprintw(WIN(w_mesgs), i, 1, "%.*s", 58, (tmp->msg) + (j * 58)); i--; if (j == 0 && i > 0) { write_pseudo(in, tmp->sender, i); i--; } j--; } list = list->next; } wrefresh(WIN(w_mesgs)); }
void ShowEscortMenu(char *msg) { int w,h,aw; int x,y; bkg bg; memset (&bg, 0, sizeof (bg)); bg.bIgnoreBg = 1; WINDOS( DDGrSetCurrentCanvas(&dd_VR_screen_pages[0]), GrSetCurrentCanvas(&VR_screen_pages[0]) ); GrSetCurFont( GAME_FONT ); GrGetStringSize(msg,&w,&h,&aw); x = (grdCurScreen->sc_w-w)/2; y = (grdCurScreen->sc_h-h)/4; GrSetFontColorRGBi (RGBA (0, PAL2RGBA (28), 0, 255), 1, 0, 0); PA_DFX (pa_set_frontbuffer_current()); PA_DFX (NMDrawBackground(x-15,y-15,x+w+15-1,y+h+15-1)); PA_DFX (pa_set_backbuffer_current()); NMDrawBackground(NULL,x-15,y-15,x+w+15-1,y+h+15-1); WIN(DDGRLOCK(dd_grd_curcanv)); PA_DFX (pa_set_frontbuffer_current()); PA_DFX (GrUString( x, y, msg )); PA_DFX (pa_set_backbuffer_current()); GrUString( x, y, msg ); WIN(DDGRUNLOCK(dd_grd_curcanv)); ResetCockpit(); }
void ScoreTableDrawCoop () { int i, color; int sorted [MAX_NUM_NET_PLAYERS]; MultiSortKillList (); WIN (DDGRLOCK (dd_grd_curcanv)); grdCurCanv->cvFont = MEDIUM3_FONT; GrString (0x8000, LHY (10), "COOPERATIVE SUMMARY", NULL); grdCurCanv->cvFont = SMALL_FONT; MultiGetKillList (sorted); ScoreTableDrawCoopNames (sorted); for (i=0; i<gameData.multiplayer.nPlayers; i++) { color = sorted [i]; if (gameData.multiplayer.players [sorted [i]].connected==0) GrSetFontColorRGBi (GRAY_RGBA, 1, 0, 0); else GrSetFontColorRGBi (RGBA_PAL2 (playerColors [color].r, playerColors [color].g, playerColors [color].b), 1, 0, 0); ScoreTableDrawCoopItem (i, sorted); } ScoreTableDrawDeaths (sorted); WIN (DDGRUNLOCK (dd_grd_curcanv)); WINDOS ( DDGrSetCurrentCanvas (NULL), GrSetCurrentCanvas (NULL) ); PA_DFX (pa_set_frontbuffer_current ()); PA_DFX (pa_set_backbuffer_current ()); GrPaletteStepLoad (NULL); GrUpdate (0); }
static void set_shadows(t_pixel *pixel, double *shadow) { if ((*shadow = 1 - *shadow) < 0) *shadow = 0; pixel->r = WIN(pixel->r * *shadow, 0, 255); pixel->g = WIN(pixel->g * *shadow, 0, 255); pixel->b = WIN(pixel->b * *shadow, 0, 255); }
void scores_draw_item( int i, stats_info * stats ) { char buffer[20]; int y; WIN(DDGRLOCK(dd_grd_curcanv)); y = 7+70+i*9; if (i==0) y -= 8; if ( i==MAX_HIGH_SCORES ) { y += 8; //scores_rprintf( 17+33+XX, y+YY, "" ); } else { scores_rprintf( 17+33+XX, y+YY, "%d.", i+1 ); } if (strlen(stats->name)==0) { GrPrintF( LHX(26+33+XX)+xOffs, LHY(y+YY)+yOffs, TXT_EMPTY ); WIN(DDGRUNLOCK(dd_grd_curcanv)); return; } GrPrintF( LHX(26+33+XX)+xOffs, LHY(y+YY)+yOffs, "%s", stats->name ); int_to_string(stats->score, buffer); scores_rprintf( 109+33+XX, y+YY, "%s", buffer ); GrPrintF( LHX(125+33+XX)+xOffs, LHY(y+YY)+yOffs, "%s", MENU_DIFFICULTY_TEXT(stats->diff_level) ); if ( (stats->starting_level > 0 ) && (stats->ending_level > 0 )) scores_rprintf( 192+33+XX, y+YY, "%d-%d", stats->starting_level, stats->ending_level ); else if ( (stats->starting_level < 0 ) && (stats->ending_level > 0 )) scores_rprintf( 192+33+XX, y+YY, "S%d-%d", -stats->starting_level, stats->ending_level ); else if ( (stats->starting_level < 0 ) && (stats->ending_level < 0 )) scores_rprintf( 192+33+XX, y+YY, "S%d-S%d", -stats->starting_level, -stats->ending_level ); else if ( (stats->starting_level > 0 ) && (stats->ending_level < 0 )) scores_rprintf( 192+33+XX, y+YY, "%d-S%d", stats->starting_level, -stats->ending_level ); { int h, m, s; h = stats->seconds/3600; s = stats->seconds%3600; m = s / 60; s = s % 60; scores_rprintf( 311-42+XX, y+YY, "%d:%02d:%02d", h, m, s ); } WIN(DDGRUNLOCK(dd_grd_curcanv)); }
void init_lum_shadow(t_all *infos, t_object *object, t_pixel *pixel, t_eye *eye) { t_spot *tmp_spot; t_coord pt_inter; t_coord v_norm; t_eye eye_tmp; double shadow; init_struct(eye, &eye_tmp, &pt_inter, pixel); lum_shadow(infos, &pt_inter, object, pixel); tmp_spot = infos->spots; shadow = 0; while (tmp_spot != NULL) { new_eye_posi(&eye_tmp, tmp_spot, &pt_inter); if (calc_obj(infos->objects, object, &eye_tmp) > 0) shadow += ((double) WIN(tmp_spot->intensity, 0, 100)) / SHADOW_FACTOR; tmp_spot = tmp_spot->next; } set_shadows(pixel, &shadow); if (object->reflexion > 0 && ++infos->travels < TRAVEL_LIMIT) { calc_vector_n(object, &pt_inter, &v_norm); init_reflection(&eye_tmp, eye, &v_norm, &pt_inter); reflection(infos, object, pixel, &eye_tmp); } }
/* Must be called with engine_mutex locked ! */ static int load_db(void) { unsigned int signo = 0; size_t used, total; int ret; INFN(); cl_engine_set_clcb_sigload(engine, sigload_callback, NULL); official_sigs = custom_sigs = 0; if((ret = cl_load(dbdir, engine, &signo, CL_DB_STDOPT & ~CL_DB_PHISHING & ~CL_DB_PHISHING_URLS)) != CL_SUCCESS) { cl_engine_free(engine); engine = NULL; FAIL(ret, "Failed to load database: %s", cl_strerror(ret)); } if((ret = cl_engine_compile(engine))) { cl_engine_free(engine); engine = NULL; FAIL(ret, "Failed to compile engine: %s", cl_strerror(ret)); } logg("load_db: loaded %d signatures (%u official, %u custom)\n", signo, official_sigs, custom_sigs); if (!mpool_getstats(engine, &used, &total)) logg("load_db: memory %.3f MB / %.3f MB\n", used/(1024*1024.0), total/(1024*1024.0)); touch_last_update(signo); WIN(); }
int CLAMAPI Scan_CreateInstance(CClamAVScanner **ppScanner) { instance *inst; INFN(); if(!ppScanner) FAIL(CL_ENULLARG, "NULL pScanner"); inst = (instance *)calloc(1, sizeof(*inst)); if(!inst) FAIL(CL_EMEM, "CreateInstance: OOM"); if(lock_engine()) { free(inst); FAIL(CL_ELOCK, "Failed to lock engine"); } if(!engine) { free(inst); unlock_engine(); FAIL(CL_ESTATE, "Create instance called with no engine"); } if(add_instance(inst)) { free(inst); unlock_engine(); FAIL(CL_EMEM, "add_instance failed"); } unlock_engine(); inst->scanopts = CL_SCAN_STDOPT; if (logg_verbose) inst->scanopts |= CL_SCAN_PERFORMANCE_INFO; *ppScanner = (CClamAVScanner *)inst; logg("Created new instance %p\n", inst); WIN(); }
int CLAMAPI Scan_SetLimit(int option, unsigned int value) { enum cl_engine_field limit; int err; INFN(); if(lock_engine()) FAIL(CL_ELOCK, "Failed to lock engine"); if(!engine) { unlock_engine(); FAIL(CL_ESTATE, "Engine is NULL"); } switch((enum CLAM_LIMIT_TYPE)option) { case CLAM_LIMIT_FILESIZE: logg("CLAM_LIMIT_FILESIZE: set to %u\n", value); limit = CL_ENGINE_MAX_FILESIZE; break; case CLAM_LIMIT_SCANSIZE: logg("CLAM_LIMIT_SCANSIZE: set to %u\n", value); limit = CL_ENGINE_MAX_SCANSIZE; break; case CLAM_LIMIT_RECURSION: logg("CLAM_LIMIT_RECURSION: set to %u\n", value); limit = CL_ENGINE_MAX_SCANSIZE; break; default: unlock_engine(); FAIL(CL_EARG, "Unsupported limit type: %d", option); } err = cl_engine_set_num(engine, limit, (long long)value); unlock_engine(); if(err) FAIL(err, "Failed to set engine value: %s", cl_strerror(err)); WIN(); }
int input_interface(t_interface *in, char *dst) { static char buf[4096] = {0}; static int index = 0; int key; key = wgetch(WIN(w_root)); if ( ' ' <= key && key <= '~' && index < 4096) return (key_insert(buf, key, &index, in)); else if ((key == 263 || key == 127) && index > 0) return (key_delete(buf, &index, in)); else if (key == '\n' && index > 0) return (key_send(buf, dst, &index, in)); else if (key == KEY_LEFT) { memcpy(dst, "/window left\0", 13); return (1); } else if (key == KEY_RIGHT) { memcpy(dst, "/window right\0", 14); return (1); } return (0); }
void kmatrix_redraw () { int i, color; int sorted [MAX_NUM_NET_PLAYERS]; xOffs = (grdCurCanv->cv_bitmap.bm_props.w - 640) / 2; yOffs = (grdCurCanv->cv_bitmap.bm_props.h - 480) / 2; if (xOffs < 0) xOffs = 0; if (yOffs < 0) yOffs = 0; if (gameData.app.nGameMode & GM_MULTI_COOP) { kmatrix_redraw_coop (); return; } MultiSortKillList (); WIN (DDGRLOCK (dd_grd_curcanv)); grdCurCanv->cv_font = MEDIUM3_FONT; GrString (0x8000, LHY (10), TXT_KILL_MATRIX_TITLE ); grdCurCanv->cv_font = SMALL_FONT; MultiGetKillList (sorted); kmatrix_draw_names (sorted); for (i=0; i<gameData.multi.nPlayers; i++) { if (gameData.app.nGameMode & GM_TEAM) color = GetTeam (sorted [i]); else color = sorted [i]; if (gameData.multi.players [sorted [i]].connected==0) GrSetFontColorRGBi (GRAY_RGBA, 1, 0, 0); else GrSetFontColorRGBi (RGBA_PAL2 (player_rgb [color].r, player_rgb [color].g, player_rgb [color].b), 1, 0, 0); kmatrix_draw_item (i, sorted); } kmatrix_draw_deaths (sorted); #if defined (POLY_ACC) pa_save_clut (); pa_update_clut (grPalette, 0, 256, 0); #endif PA_DFX (pa_set_frontbuffer_current ()); GrUpdate (0); PA_DFX (pa_set_backbuffer_current ()); #if defined (POLY_ACC) pa_restore_clut (); #endif WIN (DDGRUNLOCK (dd_grd_curcanv)); GrPaletteStepLoad (NULL); }
void ColorizeProcess(HANDLE hStdOut, WORD wDefaultAttributes, const TCHAR* conf, std::wstring& sCmdLine) { CopyFileThreadData OutData; OutData.hOut = hStdOut; OutData.wAttributes = wDefaultAttributes; CopyFileThreadData ErrData; ErrData.hOut = hStdOut; ErrData.wAttributes = FOREGROUND_RED | FOREGROUND_INTENSITY; LoadConf(OutData.vRegExAttribute, ErrData.vRegExAttribute, conf); Pipe hChildStd_OUT; Pipe hChildStd_ERR; OutData.hIn = hChildStd_OUT.read().get(); ErrData.hIn = hChildStd_ERR.read().get(); Handle hProcess; Handle hThread; { STARTUPINFO siStartupInfo = { sizeof(siStartupInfo) }; PROCESS_INFORMATION piProcessInfo = { 0 }; siStartupInfo.dwFlags = STARTF_USESTDHANDLES; siStartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); siStartupInfo.hStdOutput = hChildStd_OUT.write().get(); siStartupInfo.hStdError = hChildStd_ERR.write().get(); WIN(CreateProcess(NULL, const_cast<LPTSTR>(sCmdLine.c_str()), NULL, NULL, TRUE, 0, NULL, NULL, &siStartupInfo, &piProcessInfo), _T("CreateProcess")); hProcess.attach(piProcessInfo.hProcess); hThread.attach(piProcessInfo.hThread); } hChildStd_OUT.write().close(); hChildStd_ERR.write().close(); Handle hThreadOut(CreateThread(NULL, 0, &CopyFileThread, &OutData, 0, NULL)); Handle hThreadErr(CreateThread(NULL, 0, &CopyFileThread, &ErrData, 0, NULL)); HANDLE hWait[] = { hThreadOut.get(), hThreadErr.get(), hProcess.get() }; WIN(WaitForMultipleObjects(ARRAYSIZE(hWait), hWait, TRUE, INFINITE) == WAIT_OBJECT_0, _T("WaitForMultipleObjects")); }
static void nextword(int *xp, int *yp, int flags, int num) { int xx = fore->w_width, yy = fore->w_histheight + fore->w_height; int sx, oq, q, x, y; struct mline *ml; x = *xp; y = *yp; sx = (flags & NW_BACK) ? -1 : 1; if ((flags & NW_ENDOFWORD) && (flags & NW_MUSTMOVE)) x += sx; ml = WIN(y); for (oq = -1;; x += sx, oq = q) { if (x >= xx || x < 0) q = 0; else if (flags & NW_BIG) q = ml->image[x] == ' '; else q = is_letter(ml->image[x]); if (oq >= 0 && oq != q) { if (oq == 0 || !(flags & NW_ENDOFWORD)) *xp = x; else *xp = x - sx; *yp = y; if ((!(flags & NW_ENDOFWORD) && q) || ((flags & NW_ENDOFWORD) && oq)) { if (--num <= 0) return; } } if (x == xx) { x = -1; if (++y >= yy) return; ml = WIN(y); } else if (x < 0) { x = xx; if (--y < 0) return; ml = WIN(y); } } }
int CLAMAPI Scan_GetOption(CClamAVScanner *pScanner, int option, void *value, unsigned long inputLength, unsigned long *outLength) { instance *inst; unsigned int whichopt; INFN(); if(!pScanner) FAIL(CL_ENULLARG, "NULL pScanner"); if(!value || !inputLength) FAIL(CL_ENULLARG, "NULL value"); if(lock_instances()) FAIL(CL_ELOCK, "failed to lock instances"); inst = (instance *)pScanner; if(!is_instance(inst)) { unlock_instances(); FAIL(CL_EARG, "invalid instance %p", inst); } switch(option) { case CLAM_OPTION_SCAN_ARCHIVE: whichopt = CL_SCAN_ARCHIVE; break; case CLAM_OPTION_SCAN_MAIL: whichopt = CL_SCAN_MAIL; break; case CLAM_OPTION_SCAN_OLE2: whichopt = CL_SCAN_OLE2; break; case CLAM_OPTION_SCAN_HTML: whichopt = CL_SCAN_HTML; break; case CLAM_OPTION_SCAN_PE: whichopt = CL_SCAN_PE; break; case CLAM_OPTION_SCAN_PDF: whichopt = CL_SCAN_PDF; break; case CLAM_OPTION_SCAN_ALGORITHMIC: whichopt = CL_SCAN_ALGORITHMIC; break; case CLAM_OPTION_SCAN_ELF: whichopt = CL_SCAN_ELF; break; case CLAM_OPTION_SCAN_SWF: whichopt = CL_SCAN_SWF; break; default: unlock_instances(); FAIL(CL_EARG, "Unsupported option: %d", option); } *(unsigned int *)value = (inst->scanopts & whichopt) != 0; unlock_instances(); WIN(); }
void clear_mesgs(t_interface *in) { int i; i = 15; while (i > 0) { mvwprintw(WIN(w_mesgs), i, 1, "%*s", 58, " "); --i; } }
static int linestart(int y) { int x; uint32_t *i; for (x = markdata->left_mar, i = WIN(y)->image + x; x < fore->w_width - 1; x++) if (*i++ != ' ') break; if (x == fore->w_width - 1) x = markdata->left_mar; return x; }
static Xfid* fsysstat(Xfid *x, Fid *f) { Fcall t; t.stat = emalloc(messagesize-IOHDRSZ); t.nstat = dostat(WIN(x->f->qid), f->dir, t.stat, messagesize-IOHDRSZ, getclock()); x = respond(x, &t, nil); free(t.stat); return x; }
static int lineend(int y) { int x; uint32_t *i; for (x = markdata->right_mar, i = WIN(y)->image + x; x >= 0; x--) if (*i-- != ' ') break; if (x < 0) x = markdata->left_mar; return x; }
void ScoreTableRedraw () { int i, color; int sorted [MAX_NUM_NET_PLAYERS]; xOffs = (grdCurCanv->cvBitmap.bmProps.w - 640) / 2; yOffs = (grdCurCanv->cvBitmap.bmProps.h - 480) / 2; if (xOffs < 0) xOffs = 0; if (yOffs < 0) yOffs = 0; if (gameData.app.nGameMode & GM_MULTI_COOP) { ScoreTableDrawCoop (); return; } MultiSortKillList (); WIN (DDGRLOCK (dd_grd_curcanv)); grdCurCanv->cvFont = MEDIUM3_FONT; GrString (0x8000, LHY (10), TXT_KILL_MATRIX_TITLE, NULL); grdCurCanv->cvFont = SMALL_FONT; MultiGetKillList (sorted); ScoreTableDrawNames (sorted); for (i=0; i<gameData.multiplayer.nPlayers; i++) { if (gameData.app.nGameMode & GM_TEAM) color = GetTeam (sorted [i]); else color = sorted [i]; if (!gameData.multiplayer.players [sorted [i]].connected) GrSetFontColorRGBi (GRAY_RGBA, 1, 0, 0); else GrSetFontColorRGBi (RGBA_PAL2 (playerColors [color].r, playerColors [color].g, playerColors [color].b), 1, 0, 0); ScoreTableDrawItem (i, sorted); } ScoreTableDrawDeaths (sorted); PA_DFX (pa_set_frontbuffer_current ()); GrUpdate (0); PA_DFX (pa_set_backbuffer_current ()); WIN (DDGRUNLOCK (dd_grd_curcanv)); GrPaletteStepLoad (NULL); }
int GetHistory() { /* return value 1 if copybuffer changed */ int i = 0, q = 0, xx, yy, x, y; uint32_t *linep; struct mline *ml; x = fore->w_x; if (x >= fore->w_width) x = fore->w_width - 1; y = fore->w_y + fore->w_histheight; ml = WIN(y); for (xx = x - 1, linep = ml->image + xx; xx >= 0; xx--) if ((q = *linep--) != ' ') break; for (yy = y - 1; yy >= 0; yy--) { ml = WIN(yy); linep = ml->image; if (xx < 0 || eq(linep[xx], q)) { /* line is matching... */ for (i = fore->w_width - 1, linep += i; i >= x; i--) if (*linep-- != ' ') break; if (i >= x) break; } } if (yy < 0) return 0; if (D_user->u_plop.buf) UserFreeCopyBuffer(D_user); if ((D_user->u_plop.buf = malloc((unsigned)(i - x + 2))) == NULL) { LMsg(0, "Not enough memory... Sorry."); return 0; } memmove(D_user->u_plop.buf, (char *)linep - i + x + 1, i - x + 1); D_user->u_plop.len = i - x + 1; D_user->u_plop.enc = fore->w_encoding; return 1; }
void kmatrix_redraw_coop () { int i, color; int sorted [MAX_NUM_NET_PLAYERS]; MultiSortKillList (); WIN (DDGRLOCK (dd_grd_curcanv)); grdCurCanv->cv_font = MEDIUM3_FONT; GrString (0x8000, LHY (10), "COOPERATIVE SUMMARY" ); grdCurCanv->cv_font = SMALL_FONT; MultiGetKillList (sorted); kmatrix_draw_coop_names (sorted); for (i=0; i<gameData.multi.nPlayers; i++) { color = sorted [i]; if (gameData.multi.players [sorted [i]].connected==0) GrSetFontColorRGBi (GRAY_RGBA, 1, 0, 0); else GrSetFontColorRGBi (RGBA_PAL2 (player_rgb [color].r, player_rgb [color].g, player_rgb [color].b), 1, 0, 0); kmatrix_draw_coop_item (i, sorted); } kmatrix_draw_deaths (sorted); WIN (DDGRUNLOCK (dd_grd_curcanv)); WINDOS ( DDGrSetCurrentCanvas (NULL), GrSetCurrentCanvas (NULL) ); #if defined (POLY_ACC) pa_save_clut (); pa_update_clut (grPalette, 0, 256, 0); #endif PA_DFX (pa_set_frontbuffer_current ()); PA_DFX (pa_set_backbuffer_current ()); #if defined (POLY_ACC) pa_restore_clut (); #endif GrPaletteStepLoad (NULL); GrUpdate (0); }
int CLAMAPI Scan_SetScanCallback(CClamAVScanner *pScanner, CLAM_SCAN_CALLBACK pfnCallback, void *pContext) { instance *inst; logg("*in SetScanCallback(pScanner = %p, pfnCallback = %p, pContext = %p)\n", pScanner, pfnCallback, pContext); if(!pScanner) FAIL(CL_ENULLARG, "NULL pScanner"); if(lock_instances()) FAIL(CL_ELOCK, "failed to lock instances for instance %p", pScanner); inst = (instance *)pScanner; if(is_instance(inst)) { inst->scancb = pfnCallback; inst->scancb_ctx = pContext; unlock_instances(); WIN(); } unlock_instances(); FAIL(CL_EARG, "invalid instance %p", inst); }
// Caller: if we return error will retry once after 2 seconds. // No point in retrying more times since we are shutting down anyway. int CLAMAPI Scan_DestroyInstance(CClamAVScanner *pScanner) { int rc; INFN(); if(!pScanner) FAIL(CL_ENULLARG, "NULL pScanner"); if((rc = del_instance((instance *)pScanner))) { if (rc == CL_EBUSY) { // wait for one of the scanner threads to finish, and retry again, // thats better than caller always waiting 2 seconds to retry. if (WaitForSingleObject(reload_event, 1000) != WAIT_OBJECT_0) logg("Scan_DestroyInstance: timeout"); rc = del_instance((instance *)pScanner); } if (rc) FAIL(rc, "del_instance failed for %p", pScanner); } free(pScanner); logg("in Scan_DestroyInstance: Instance %p destroyed\n", pScanner); WIN(); }
int CLAMAPI Scan_DeleteScanInfo(CClamAVScanner *pScanner, PCLAM_SCAN_INFO_LIST pInfoList) { logg("*in Scan_DeleteScanInfo(pScanner = %p, pInfoList = %p)\n", pScanner, pInfoList); if(!pScanner) FAIL(CL_ENULLARG, "NULL pScanner"); if(!pInfoList) FAIL(CL_ENULLARG, "NULL pInfoList"); /* FIXME checking this is pointelss as the infolist is independent from pscanner */ // if(lock_instances()) //FAIL(CL_EMEM, "failed to lock instances"); // inst = (instance *)pScanner; // if(!is_instance(inst)) { //unlock_instances(); //FAIL(CL_EARG, "invalid instance"); // } // unlock_instances(); free(pInfoList); WIN(); }
int CLAMAPI Scan_Uninitialize(void) { // int rett; // __asm { //MOV eax, [ebp + 4] //mov rett, eax // } // logg("%x", rett); uninitialize_called = 1; INFN(); if(monitor_hdl) { SetEvent(monitor_event); if(WaitForSingleObject(monitor_hdl, 5000) != WAIT_OBJECT_0) { logg("^Scan_Uninitialize: forcibly terminating monitor thread after 5 seconds\n"); TerminateThread(monitor_hdl, 0); } } monitor_hdl = NULL; if(lock_engine()) FAIL(CL_ELOCK, "failed to lock engine"); if(!engine) { unlock_engine(); FAIL(CL_ESTATE, "attempted to uninit a NULL engine"); } if(lock_instances()) { unlock_engine(); FAIL(CL_ELOCK, "failed to lock instances"); } if(ninsts_avail != ninsts_total) { volatile unsigned int refcnt = ninsts_total - ninsts_avail; unlock_instances(); unlock_engine(); FAIL(CL_EBUSY, "Attempted to uninit the engine with %u active instances", refcnt); } unlock_instances(); free_engine_and_unlock(); WIN(); }
/* * nextchar sets *xp to the num-th occurrence of the target in the line. * * Returns -1 if the target doesn't appear num times, 0 otherwise. */ static int nextchar(int *xp, int *yp, int direction, char target, int num) { int width; /* width of the current window. */ int x; /* x coordinate of the current cursor position. */ int step; /* amount to increment x (+1 or -1) */ int adjust; /* Final adjustment of cursor position. */ char *displayed_line; /* Line in which search takes place. */ x = *xp; step = 1; adjust = 0; width = fore->w_width; displayed_line = (char *)WIN(*yp)->image; switch (direction) { case 't': adjust = -1; /* fall through */ case 'f': step = 1; break; case 'T': adjust = 1; /* fall through */ case 'F': step = -1; break; } x += step; for (; x >= 0 && x <= width; x += step) { if (displayed_line[x] == target) { if (--num == 0) { *xp = x + adjust; return 0; } } } return -1; }
int CLAMAPI Scan_GetLimit(int option, unsigned int *value) { enum cl_engine_field limit; long long curlimit; int err; INFN(); if(lock_engine()) FAIL(CL_ELOCK, "Failed to lock engine"); if(!engine) { unlock_engine(); FAIL(CL_ESTATE, "Engine is NULL"); } switch((enum CLAM_LIMIT_TYPE)option) { case CLAM_LIMIT_FILESIZE: limit = CL_ENGINE_MAX_FILESIZE; break; case CLAM_LIMIT_SCANSIZE: limit = CL_ENGINE_MAX_SCANSIZE; break; case CLAM_LIMIT_RECURSION: limit = CL_ENGINE_MAX_SCANSIZE; break; default: unlock_engine(); FAIL(CL_EARG, "Unsupported limit type: %d", option); } curlimit = cl_engine_get_num(engine, limit, &err); if(err) { unlock_engine(); FAIL(err, "Failed to get engine value: %s", cl_strerror(err)); } if(curlimit > 0xffffffff) *value = 0xffffffff; else *value = (unsigned int)curlimit; unlock_engine(); WIN(); }
void refresh_chans(t_interface *in, t_list list, t_channel *current) { t_channel *tmp; int i; i = 0; mvwprintw(WIN(w_chans), 1, 1, "%*s", 78, " "); while (list != NULL) { tmp = (t_channel *)list->value; if (current != NULL && strcmp(tmp->name, current->name) == 0) { wattron(WIN(w_chans), COLOR_PAIR(5)); mvwaddstr(WIN(w_chans), 1, i + 1, tmp->name); wattroff(WIN(w_chans), COLOR_PAIR(5)); } else mvwaddstr(WIN(w_chans), 1, i + 1, tmp->name); i += strlen(tmp->name) + 1; list = list->next; } wrefresh(WIN(w_chans)); }
int CLAMAPI Scan_ScanObjectByHandle(CClamAVScanner *pScanner, HANDLE object, int *pScanStatus, PCLAM_SCAN_INFO_LIST *pInfoList) { instance *inst; HANDLE duphdl, self; char *virname = NULL; int fd, res; unsigned int i; struct scan_ctx sctx; DWORD perf; logg("*in Scan_ScanObjectByHandle(pScanner = %p, HANDLE = %p, pScanStatus = %p, pInfoList = %p)\n", pScanner, object, pScanStatus, pInfoList); if(!pScanner) FAIL(CL_ENULLARG, "NULL pScanner"); if(!pScanStatus) FAIL(CL_ENULLARG, "NULL pScanStatus on instance %p", pScanner); self = GetCurrentProcess(); if(!DuplicateHandle(self, object, self, &duphdl, GENERIC_READ, FALSE, 0)) FAIL(CL_EDUP, "Duplicate handle failed for instance %p", pScanner); if((fd = _open_osfhandle((intptr_t)duphdl, _O_RDONLY)) == -1) { CloseHandle(duphdl); FAIL(CL_EOPEN, "Open handle failed for instance %p", pScanner); } if(lock_instances()) { close(fd); FAIL(CL_ELOCK, "failed to lock instances for instance %p", pScanner); } inst = (instance *)pScanner; for(i=0; i<ninsts_total; i++) { if(instances[i].inst == inst) break; } if(i == ninsts_total) { unlock_instances(); close(fd); FAIL(CL_EARG, "invalid instance %p", inst); } instances[i].refcnt++; ResetEvent(reload_event); unlock_instances(); sctx.entryfd = fd; sctx.inst = inst; sctx.cb_times = 0; sctx.copy_times = 0; logg("*Scan_ScanObjectByHandle (instance %p) invoking cl_scandesc with clamav context %p\n", inst, &sctx); perf = GetTickCount(); res = cl_scandesc_callback(fd, &virname, NULL, engine, inst->scanopts, &sctx); if(!inst->filetype) do { CLAM_SCAN_INFO si; CLAM_ACTION act; DWORD cbperf; wchar_t wvirname[MAX_VIRNAME_LEN] = L"Clam."; LONG lo = 0, hi = 0, hi2 = 0; si.cbSize = sizeof(si); si.flags = 0; si.scanPhase = SCAN_PHASE_FINAL; si.errorCode = CLAMAPI_SUCCESS; if(res == CL_VIRUS) { if(MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, virname, -1, &wvirname[5], MAX_VIRNAME_LEN - 5)) si.pThreatName = wvirname; else si.pThreatName = L"Clam.UNOFFICIAL"; } else si.pThreatName = NULL; logg("*in final_cb with clamav context %p, instance %p, fd %d, result %d, virusname %S)\n", &sctx, inst, fd, res, si.pThreatName); si.pThreatType = threat_type(virname); si.object = INVALID_HANDLE_VALUE; si.objectId = INVALID_HANDLE_VALUE; si.pInnerObjectPath = NULL; lo = SetFilePointer(duphdl, 0, &hi, FILE_CURRENT); SetFilePointer(duphdl, 0, &hi2, FILE_BEGIN); logg("*final_cb (clamav context %p, instance %p) invoking callback %p with context %p\n", &sctx, inst, inst->scancb, inst->scancb_ctx); cbperf = GetTickCount(); inst->scancb(&si, &act, inst->scancb_ctx); cbperf = GetTickCount() - cbperf; sctx.cb_times += cbperf; logg("*final_cb (clamav context %p, instance %p) callback completed with %u (result ignored) in %u ms\n", &sctx, inst, act, cbperf); SetFilePointer(duphdl, lo, &hi, FILE_BEGIN); } while(0); perf = GetTickCount() - perf; close(fd); logg("*Scan_ScanObjectByHandle (instance %p): cl_scandesc returned %d in %u ms (%d ms own, %d ms copy)\n", inst, res, perf, perf - sctx.cb_times - sctx.copy_times, sctx.copy_times); if(lock_instances()) FAIL(CL_ELOCK, "failed to lock instances for instance %p", pScanner); instances[i].refcnt--; if(!instances[i].refcnt) SetEvent(reload_event); unlock_instances(); if(res == CL_VIRUS) { logg("Scan_ScanObjectByHandle (instance %p): file is INFECTED with %s\n", inst, virname); if(pInfoList) { CLAM_SCAN_INFO_LIST *infolist = (CLAM_SCAN_INFO_LIST *)calloc(1, sizeof(CLAM_SCAN_INFO_LIST) + sizeof(CLAM_SCAN_INFO) + MAX_VIRNAME_LEN * 2); PCLAM_SCAN_INFO scaninfo; wchar_t *wvirname; if(!infolist) FAIL(CL_EMEM, "ScanByHandle (instance %p): OOM while allocating result list", inst); scaninfo = (PCLAM_SCAN_INFO)(infolist + 1); infolist->cbCount = 1; scaninfo->cbSize = sizeof(*scaninfo); scaninfo->scanPhase = SCAN_PHASE_FINAL; scaninfo->errorCode = CLAMAPI_SUCCESS; scaninfo->pThreatType = threat_type(virname); scaninfo->object = INVALID_HANDLE_VALUE; scaninfo->objectId = INVALID_HANDLE_VALUE; wvirname = (wchar_t *)(scaninfo + 1); scaninfo->pThreatName = wvirname; memcpy(wvirname, L"Clam.", 10); if(!MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, virname, -1, &wvirname[5], MAX_VIRNAME_LEN-5)) scaninfo->pThreatName = L"Clam.UNOFFICIAL"; *pInfoList = infolist; logg("*Scan_ScanObjectByHandle (instance %p): created result list %p\n", inst, infolist); } *pScanStatus = CLAM_INFECTED; } else if(res == CL_CLEAN) { logg("*Scan_ScanObjectByHandle (instance %p): file is CLEAN\n", inst); if(pInfoList) *pInfoList = NULL; *pScanStatus = CLAM_CLEAN; } else { FAIL(res, "Scan failed for instance %p: %s", inst, cl_strerror(res)); } WIN(); }
int CLAMAPI Scan_SetOption(CClamAVScanner *pScanner, int option, void *value, unsigned long inputLength) { instance *inst; unsigned int whichopt, newval; INFN(); if(!pScanner) FAIL(CL_ENULLARG, "NULL pScanner"); if(!value) FAIL(CL_ENULLARG, "NULL value"); if(lock_instances()) FAIL(CL_ELOCK, "failed to lock instances"); inst = (instance *)pScanner; if(!is_instance(inst)) { unlock_instances(); FAIL(CL_EARG, "invalid instance %p", inst); } newval = *(unsigned int *)value; switch(option) { case CLAM_OPTION_SCAN_ARCHIVE: logg("CLAM_OPTION_SCAN_ARCHIVE: %s on instance %p\n", newval ? "enabled" : "disabled", inst); whichopt = CL_SCAN_ARCHIVE; break; case CLAM_OPTION_SCAN_MAIL: logg("CLAM_OPTION_SCAN_MAIL: %s on instance %p\n", newval ? "enabled" : "disabled", inst); whichopt = CL_SCAN_MAIL; break; case CLAM_OPTION_SCAN_OLE2: logg("CLAM_OPTION_SCAN_OLE2: %s on instance %p\n", newval ? "enabled" : "disabled", inst); whichopt = CL_SCAN_OLE2; break; case CLAM_OPTION_SCAN_HTML: logg("CLAM_OPTION_SCAN_HTML: %s on instance %p\n", newval ? "enabled" : "disabled", inst); whichopt = CL_SCAN_HTML; break; case CLAM_OPTION_SCAN_PE: logg("CLAM_OPTION_SCAN_PE: %s on instance %p\n", newval ? "enabled" : "disabled", inst); whichopt = CL_SCAN_PE; break; case CLAM_OPTION_SCAN_PDF: logg("CLAM_OPTION_SCAN_PDF: %s on instance %p\n", newval ? "enabled" : "disabled", inst); whichopt = CL_SCAN_PDF; break; case CLAM_OPTION_SCAN_ALGORITHMIC: logg("CLAM_OPTION_SCAN_ALGORITHMIC: %s on instance %p\n", newval ? "enabled" : "disabled", inst); whichopt = CL_SCAN_ALGORITHMIC; break; case CLAM_OPTION_SCAN_ELF: logg("CLAM_OPTION_SCAN_ELF: %s on instance %p\n", newval ? "enabled" : "disabled", inst); whichopt = CL_SCAN_ELF; break; default: unlock_instances(); FAIL(CL_EARG, "Unsupported option: %d", option); } if(!newval) inst->scanopts &= ~whichopt; else inst->scanopts |= whichopt; unlock_instances(); WIN(); }