static void test_vasprintf () { int repeat; for (repeat = 0; repeat <= 8; repeat++) { char *result; int retval = my_asprintf (&result, "%d", 12345); ASSERT (retval == 5); ASSERT (result != NULL); ASSERT (strcmp (result, "12345") == 0); free (result); } for (repeat = 0; repeat <= 8; repeat++) { char *result; int retval = my_asprintf (&result, "%08lx", 12345); ASSERT (retval == 8); ASSERT (result != NULL); ASSERT (strcmp (result, "00003039") == 0); free (result); } }
void InstructionConsumer::operator()(VexPtr<Oracle> &oracle, DumpFix &df, const DynAnalysisRip &dar, unsigned long cntr) { _logfile = open_logfile(1000000, "logs/%ld", cntr + start_instr); printf("Considering %s, log logs/%ld\n", dar.name(), cntr + start_instr); fprintf(_logfile, "Log for %s:\n", dar.name()); fflush(0); consider_rip(dar, 1, oracle, df, opt, -1, -1, ALLOW_GC); fclose(_logfile); _logfile = stdout; instructions_processed++; double completion = instructions_processed / double(instructions_to_process); double elapsed = now() - start; double total_estimated = elapsed / completion; double endd = total_estimated + start; if (isinf(endd)) return; time_t end = endd; char *times; if (first) { low_end_time = endd; high_end_time = endd; first = false; times = my_asprintf("finish at %s", ctime(&end)); } else { low_end_time = low_end_time * .99 + endd * 0.01; high_end_time = high_end_time * .99 + endd * 0.01; if (low_end_time > endd) low_end_time = endd; if (high_end_time < endd) high_end_time = endd; char *t = strdup(ctime(&end)); t[strlen(t)-1] = 0; end = low_end_time; char *t2 = strdup(ctime(&end)); t2[strlen(t2)-1] = 0; end = high_end_time; char *t3 = strdup(ctime(&end)); t3[strlen(t3)-1] = 0; times = my_asprintf("finish at %s [%s,%s]\n", t, t2, t3); free(t); free(t2); free(t3); } printf("Done %ld/%ld(%f%%) in %f seconds (%f each); %f left; %s", instructions_processed, total_instructions, completion * 100, elapsed, elapsed / instructions_processed, total_estimated - elapsed, times); free(times); }
static void ffi_open_fn(VMState *state, CallInfo *info) { VM_ASSERT(info->args_len == 1, "wrong arity: expected 1, got %i", info->args_len); Object *root = state->root; Object *string_base = state->shared->vcache.string_base; Object *array_base = state->shared->vcache.array_base; Object *ffi = AS_OBJ(OBJECT_LOOKUP(root, ffi)); Object *handle_base = AS_OBJ(OBJECT_LOOKUP(ffi, handle)); StringObject *sarg = (StringObject*) obj_instance_of(OBJ_OR_NULL(load_arg(state->frame, INFO_ARGS_PTR(info)[0])), string_base); VM_ASSERT(sarg, "argument to ffi.open must be string!"); Object *libmap = AS_OBJ(OBJECT_LOOKUP(ffi, library_map)); char *file = sarg->value; bool file_found = false; FastKey file_key = prepare_key(file, strlen(file)); Value mapping = object_lookup_p(libmap, &file_key, &file_found); const char **file_list_ptr = NULL; int file_list_len = 0; if (file_found) { ArrayObject *aobj = (ArrayObject*) obj_instance_of(OBJ_OR_NULL(mapping), array_base); StringObject *sobj = (StringObject*) obj_instance_of(OBJ_OR_NULL(mapping), string_base); if (aobj) { file_list_len = aobj->length; file_list_ptr = malloc(sizeof(char*) * file_list_len); for (int i = 0; i < file_list_len; i++) { StringObject *file = (StringObject*) obj_instance_of(OBJ_OR_NULL(aobj->ptr[i]), string_base); VM_ASSERT(file, "library_map sub-entries must be string"); file_list_ptr[i] = my_asprintf("%s", file->value); // outside gc, make copy } } else if (sobj) { file_list_len = 1; file_list_ptr = malloc(sizeof(char*) * 1); file_list_ptr[0] = my_asprintf("%s", sobj->value); } else VM_ASSERT(false, "library_map entries must be string or array"); } else { file_list_len = 1; file_list_ptr = malloc(sizeof(char*) * 1); file_list_ptr[0] = file; } void *dlptr = my_dlopen(file_list_len, file_list_ptr); Object *handle_obj = AS_OBJ(make_object(state, handle_base, false)); handle_obj->flags |= OBJ_FROZEN; OBJECT_SET(state, handle_obj, pointer, make_ptr(state, dlptr)); vm_return(state, info, OBJ2VAL(handle_obj)); }
IRExpr *transformIRExpr(IRExpr *e) { std::map<int, IRExpr *> argVals; if (f->matches(e, argVals)) { if (!cee) cee = mkIRCallee( 0, my_asprintf("f%d", (*f_cntr)++), /* XXX memory leak XXX */ NULL, 0); IRExpr **args; args = alloc_irexpr_array(argVals.size() + 1); for (int i = 0; i < (int)argVals.size(); i++) { assert(argVals[i+1]); args[i] = argVals[i+1]; } args[argVals.size()] = NULL; IRExpr *res = IRExpr_CCall(cee, e->type(), args); if (debug_use_functions) printf("Transform %s to %s using %s\n", nameIRExpr(e), nameIRExpr(res), f->name()); return res; } return StateMachineTransformer::transformIRExpr(e); }
void DumpFix::operator()(VexPtr<CrashSummary, &ir_heap> &summary, int i, int nrStoreCfgs, GarbageCollectionToken ) { __set_profiling(dumpfix); printCrashSummary(summary, _logfile); int fd; static int cntr; char *buf = NULL; do { free(buf); buf = my_asprintf("crash_summaries/%d", cntr); cntr++; fd = open(buf, O_WRONLY|O_EXCL|O_CREAT, 0600); } while (fd == -1 && errno == EEXIST); if (fd == -1) err(1, "opening %s", buf); fprintf(_logfile, "Write summary to %s\n", buf); free(buf); FILE *f = fdopen(fd, "w"); if (!f) err(1, "fdopen()"); fprintf(f, "summary from dyn rip %s, %d/%d\n", dr.name(), i, nrStoreCfgs); printCrashSummary(summary, f); fclose(f); }
char *dlerror() { return my_asprintf("win32 error %i", GetLastError());; }
char *mkName() const { return my_asprintf("expr = %s, %sevaluatable", nameIRExpr(cond), evaluatable ? "" : "not "); }