int main() { LinkedListInit( & queueList ); LinkedListInit( & stackList ); AtomicListInit( & atomicList ); HeapInit( & heap ); int data; do { printf("enter a data value:\n0 to exit\n1 to remove a node\n2 to print the data structures\nor a larger number to add a node.\n"); scanf("%d", &data ); if( data == 0 ) return 0; else if( data == 1 ) Pop(); else if( data == 2 ) { printf("queue:"); DumpList( & queueList ); printf("stack:"); DumpList( & stackList ); printf("Atomic:"); DumpAtomic( &atomicList ); DumpHeap( & heap ); } else Add(data); }while( data != 0 ); return 0; }
void test4_1() { std::cout << "==================== test4_1 ====================\n"; const unsigned asize = 1; Digipen::Utils::srand(2, 1); BList<int, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; unsigned low = 10; unsigned high = 99; unsigned range = high - low; unsigned size = 16; int *ia = new int[range]; for (unsigned i = low; i < high; i++) ia[i - low] = i + 1; Shuffle(ia, range); for (unsigned i = 0; i < size; i++) { bl.insert(ia[i]); //DumpList(bl, true); //DumpList(bl); //std::cout << "==========================\n"; } DumpList(bl, false); print_subscript(bl); std::cout << std::endl << std::endl; DumpList(bl, false); DumpList(bl, true); DumpStats(bl); std::cout << std::endl; delete [] ia; }
void test7_2() { std::cout << "==================== test7_2 ====================\n"; const unsigned asize = 2; Digipen::Utils::srand(2, 1); BList<int, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; unsigned low = 10; unsigned high = 99; unsigned range = high - low; unsigned size = 16; int *ia = new int[range]; for (unsigned i = low; i < high; i++) ia[i - low] = i + 1; Shuffle(ia, range); for (unsigned i = 0; i < size; i++) bl.push_back(ia[i]); DumpList(bl, false); //DumpStats(bl); for (int i = size - 1; i >= 0; i -= 2) { std::cout << "Removing from index " << i << std::endl; bl.remove(i); DumpList(bl, true); } DumpList(bl, false); //DumpStats(bl); delete [] ia; }
void test8_8() { std::cout << "==================== test8_8 ====================\n"; const unsigned asize = 8; Digipen::Utils::srand(2, 1); BList<int, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; unsigned low = 10; unsigned high = 99; unsigned range = high - low; unsigned size = 16; int *ia = new int[range]; for (unsigned i = low; i < high; i++) ia[i - low] = i + 1; Shuffle(ia, range); for (unsigned i = 0; i < size; i++) bl.push_back(ia[i]); DumpList(bl, false); std::sort(ia, ia + size); for (unsigned i = 0; i < size - 4; i++) { std::cout << "Removing value " << ia[i] << std::endl; bl.remove_by_value(ia[i]); } DumpList(bl, false); delete [] ia; }
// left is full, right has room: add to right void testD() { std::cout << "===== left is full, right has room: add to right =====\n"; const unsigned asize = 2; Digipen::Utils::srand(2, 1); BList<int, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; bl.insert(20); bl.insert(40); bl.insert(30); DumpList(bl, false); bl.insert(35); DumpList(bl, false); }
/////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// // push_front void test1_1() { std::cout << "==================== test1_1 ====================\n"; const unsigned asize = 1; BList<int, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; for (int i = 1; i <= 16; i++) { bl.push_front(i); //DumpList(bl); //std::cout << "==========================\n"; } DumpList(bl, false); DumpList(bl, true); DumpStats(bl); std::cout << std::endl; }
// both are full: split left void testB() { std::cout << "===== both are full: split left =====\n"; const unsigned asize = 2; Digipen::Utils::srand(2, 1); BList<int, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; bl.insert(20); bl.insert(40); bl.insert(30); bl.insert(50); DumpList(bl, false); bl.insert(35); DumpList(bl, false); std::cout << std::endl; }
// both have room: add to left void testA() { std::cout << "===== both have room: add to left =====\n"; const unsigned asize = 2; Digipen::Utils::srand(2, 1); BList<int, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; bl.insert(20); bl.insert(40); bl.insert(30); bl.remove(1); DumpList(bl, false); bl.insert(30); DumpList(bl, false); std::cout << std::endl; }
int Sim_CheckAssertions(tAssertion *First) { int bFailure = 0; int assertion_num = 0; for( tAssertion *a = First; a; a = a->Next, assertion_num ++ ) { int i; for( i = 0; i < a->Condition.NItems; i ++ ) { if( !GetLinkVal(a->Condition.Items[i]) ) break ; } // If one condition failed, don't check if( i < a->Condition.NItems ) continue ; // Check that Expected == Actual for( i = 0; i < a->Expected.NItems; i ++ ) { if( GetLinkVal(a->Expected.Items[i]) != GetLinkVal(a->Values.Items[i]) ) break; } // Assertion passed if( i == a->Expected.NItems ) continue ; // Failed printf("\n - Assertion %i failed\n", assertion_num+1); printf(" if "); DumpList(&a->Condition, 1); printf("assert actual "); DumpList(&a->Values, 0); printf(" == expected "); DumpList(&a->Expected, 0); bFailure = 1; } return bFailure; }
void test10_4() { std::cout << "==================== test10_4 ====================\n"; const unsigned asize = 4; Digipen::Utils::srand(2, 1); BList<int, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; unsigned low = 10; unsigned high = 99; unsigned range = high - low; unsigned size = 16; int *ia = new int[range]; for (unsigned i = low; i < high; i++) ia[i - low] = i + 1; Shuffle(ia, range); for (unsigned i = 0; i < size; i++) bl.insert(ia[i]); DumpList(bl, false); DumpList(bl, true); DumpStats(bl); // assignment BList<int, asize> bl2; bl2 = bl; DumpList(bl2, false); DumpList(bl2, true); DumpStats(bl2); DumpList(bl, true); DumpStats(bl); delete [] ia; }
void test5_16() { std::cout << "==================== test5_16 ====================\n"; const unsigned asize = 16; BList<int, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; unsigned low = 10; unsigned high = 99; unsigned range = high - low; unsigned size = 16; int *ia = new int[range]; for (unsigned i = low; i < high; i++) ia[i - low] = i + 1; Shuffle(ia, range); for (unsigned i = 0; i < size; i++) bl.push_back(ia[i]); DumpList(bl, true); DumpList(bl, false); for (unsigned i = 0; i < size; i++) { int index = bl.find(ia[i]); if (index == -1) std::cout << "Item: " << ia[i] << " not found. Something's wrong.\n"; else std::cout << "Found " << ia[i] << " at index " << index << std::endl; } std::cout << std::endl; DumpStats(bl); std::cout << std::endl; delete [] ia; }
void test2() { std::cout << "==================== test2 ====================\n"; const unsigned asize = 4; Digipen::Utils::srand(2, 1); BList<Foo, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; bl.insert(Foo(3,2)); DumpList(bl, false); bl.insert(Foo(1,2)); DumpList(bl, false); bl.insert(Foo(2, 5)); DumpList(bl, false); bl.insert(Foo(2,7)); DumpList(bl, false); bl.insert(Foo(2,2)); DumpList(bl, false); bl.insert(Foo(3, 8)); DumpList(bl, false); DumpList(bl, true); DumpStats(bl); int index = bl.find(Foo(2,7)); std::cout << "Index of " << Foo(2,7) << " is " << index << std::endl; index = bl.find(Foo(1,8)); std::cout << "Index of " << Foo(1,8) << " is " << index << std::endl << std::endl; bl.remove(1); DumpList(bl, false); bl.remove_by_value(Foo(2,7)); DumpList(bl, false); DumpStats(bl); std::cout << "==========================\n"; std::cout << std::endl; }
void test1() { std::cout << "==================== test1 ====================\n"; const unsigned asize = 4; Digipen::Utils::srand(2, 1); BList<std::string, asize> bl; std::cout << "nodesize is " << bl.nodesize() << std::endl; const char *strings[] = {"this", "is", "just", "a", "bunch", "of", "random", "strings", "in", "the", "sentence"}; int count = sizeof(strings) / sizeof(*strings); for (int i = 0; i < count; i++) { bl.insert(strings[i]); DumpList(bl); } std::cout << "==========================\n"; std::cout << std::endl; }
int main( int argc, char **argv ) { struct stat stat_buff; stat_record_t sum_stat; printer_t print_header, print_record; nfprof_t profile_data; char *rfile, *Rfile, *Mdirs, *wfile, *ffile, *filter, *tstring, *stat_type; char *byte_limit_string, *packet_limit_string, *print_format, *record_header; char *print_order, *query_file, *UnCompress_file, *nameserver, *aggr_fmt; int c, ffd, ret, element_stat, fdump; int i, user_format, quiet, flow_stat, topN, aggregate, aggregate_mask, bidir; int print_stat, syntax_only, date_sorted, do_tag, compress, do_xstat; int plain_numbers, GuessDir, pipe_output, csv_output; time_t t_start, t_end; uint32_t limitflows; char Ident[IDENTLEN]; rfile = Rfile = Mdirs = wfile = ffile = filter = tstring = stat_type = NULL; byte_limit_string = packet_limit_string = NULL; fdump = aggregate = 0; aggregate_mask = 0; bidir = 0; t_start = t_end = 0; syntax_only = 0; topN = -1; flow_stat = 0; print_stat = 0; element_stat = 0; do_xstat = 0; limitflows = 0; date_sorted = 0; total_bytes = 0; total_flows = 0; skipped_blocks = 0; do_tag = 0; quiet = 0; user_format = 0; compress = 0; plain_numbers = 0; pipe_output = 0; csv_output = 0; is_anonymized = 0; GuessDir = 0; nameserver = NULL; print_format = NULL; print_header = NULL; print_record = NULL; print_order = NULL; query_file = NULL; UnCompress_file = NULL; aggr_fmt = NULL; record_header = NULL; Ident[0] = '\0'; while ((c = getopt(argc, argv, "6aA:Bbc:D:E:s:hHn:i:j:f:qzr:v:w:K:M:NImO:R:XZt:TVv:x:l:L:o:")) != EOF) { switch (c) { case 'h': usage(argv[0]); exit(0); break; case 'a': aggregate = 1; break; case 'A': if ( !ParseAggregateMask(optarg, &aggr_fmt ) ) { exit(255); } aggregate_mask = 1; break; case 'B': GuessDir = 1; case 'b': if ( !SetBidirAggregation() ) { exit(255); } bidir = 1; // implies aggregate = 1; break; case 'D': nameserver = optarg; if ( !set_nameserver(nameserver) ) { exit(255); } break; case 'E': query_file = optarg; if ( !InitExporterList() ) { exit(255); } PrintExporters(query_file); exit(0); break; case 'X': fdump = 1; break; case 'Z': syntax_only = 1; break; case 'q': quiet = 1; break; case 'z': compress = 1; break; case 'c': limitflows = atoi(optarg); if ( !limitflows ) { LogError("Option -c needs a number > 0\n"); exit(255); } break; case 's': stat_type = optarg; if ( !SetStat(stat_type, &element_stat, &flow_stat) ) { exit(255); } break; case 'V': { char *e1, *e2; e1 = ""; e2 = ""; #ifdef NSEL e1 = "NSEL-NEL"; #endif printf("%s: Version: %s%s%s\n",argv[0], e1, e2, nfdump_version); exit(0); } break; case 'l': packet_limit_string = optarg; break; case 'K': LogError("*** Anonymisation moved! Use nfanon to anonymise flows!\n"); exit(255); break; case 'H': do_xstat = 1; break; case 'L': byte_limit_string = optarg; break; case 'N': plain_numbers = 1; break; case 'f': ffile = optarg; break; case 't': tstring = optarg; break; case 'r': rfile = optarg; if ( strcmp(rfile, "-") == 0 ) rfile = NULL; break; case 'm': print_order = "tstart"; Parse_PrintOrder(print_order); date_sorted = 1; LogError("Option -m depricated. Use '-O tstart' instead\n"); break; case 'M': Mdirs = optarg; break; case 'I': print_stat++; break; case 'o': // output mode print_format = optarg; break; case 'O': { // stat order by int ret; print_order = optarg; ret = Parse_PrintOrder(print_order); if ( ret < 0 ) { LogError("Unknown print order '%s'\n", print_order); exit(255); } date_sorted = ret == 6; // index into order_mode } break; case 'R': Rfile = optarg; break; case 'w': wfile = optarg; break; case 'n': topN = atoi(optarg); if ( topN < 0 ) { LogError("TopnN number %i out of range\n", topN); exit(255); } break; case 'T': do_tag = 1; break; case 'i': strncpy(Ident, optarg, IDENT_SIZE); Ident[IDENT_SIZE - 1] = 0; if ( strchr(Ident, ' ') ) { LogError("Ident must not contain spaces\n"); exit(255); } break; case 'j': UnCompress_file = optarg; UnCompressFile(UnCompress_file); exit(0); break; case 'x': query_file = optarg; InitExtensionMaps(NO_EXTENSION_LIST); DumpExMaps(query_file); exit(0); break; case 'v': query_file = optarg; QueryFile(query_file); exit(0); break; case '6': // print long IPv6 addr Setv6Mode(1); break; default: usage(argv[0]); exit(0); } } if (argc - optind > 1) { usage(argv[0]); exit(255); } else { /* user specified a pcap filter */ filter = argv[optind]; FilterFilename = NULL; } // Change Ident only if ( rfile && strlen(Ident) > 0 ) { ChangeIdent(rfile, Ident); exit(0); } if ( (element_stat || flow_stat) && (topN == -1) ) topN = 10; if ( topN < 0 ) topN = 0; if ( (element_stat && !flow_stat) && aggregate_mask ) { LogError("Warning: Aggregation ignored for element statistics\n"); aggregate_mask = 0; } if ( !flow_stat && aggregate_mask ) { aggregate = 1; } if ( rfile && Rfile ) { LogError("-r and -R are mutually exclusive. Plase specify either -r or -R\n"); exit(255); } if ( Mdirs && !(rfile || Rfile) ) { LogError("-M needs either -r or -R to specify the file or file list. Add '-R .' for all files in the directories.\n"); exit(255); } extension_map_list = InitExtensionMaps(NEEDS_EXTENSION_LIST); if ( !InitExporterList() ) { exit(255); } SetupInputFileSequence(Mdirs, rfile, Rfile); if ( print_stat ) { nffile_t *nffile; if ( !rfile && !Rfile && !Mdirs) { LogError("Expect data file(s).\n"); exit(255); } memset((void *)&sum_stat, 0, sizeof(stat_record_t)); sum_stat.first_seen = 0x7fffffff; sum_stat.msec_first = 999; nffile = GetNextFile(NULL, 0, 0); if ( !nffile ) { LogError("Error open file: %s\n", strerror(errno)); exit(250); } while ( nffile && nffile != EMPTY_LIST ) { SumStatRecords(&sum_stat, nffile->stat_record); nffile = GetNextFile(nffile, 0, 0); } PrintStat(&sum_stat); exit(0); } // handle print mode if ( !print_format ) { // automatically select an appropriate output format for custom aggregation // aggr_fmt is compiled by ParseAggregateMask if ( aggr_fmt ) { int len = strlen(AggrPrependFmt) + strlen(aggr_fmt) + strlen(AggrAppendFmt) + 7; // +7 for 'fmt:', 2 spaces and '\0' print_format = malloc(len); if ( !print_format ) { LogError("malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror(errno) ); exit(255); } snprintf(print_format, len, "fmt:%s %s %s",AggrPrependFmt, aggr_fmt, AggrAppendFmt ); print_format[len-1] = '\0'; } else if ( bidir ) { print_format = "biline"; } else print_format = DefaultMode; } if ( strncasecmp(print_format, "fmt:", 4) == 0 ) { // special user defined output format char *format = &print_format[4]; if ( strlen(format) ) { if ( !ParseOutputFormat(format, plain_numbers, printmap) ) exit(255); print_record = format_special; record_header = get_record_header(); user_format = 1; } else { LogError("Missing format description for user defined output format!\n"); exit(255); } } else { // predefined output format // Check for long_v6 mode i = strlen(print_format); if ( i > 2 ) { if ( print_format[i-1] == '6' ) { Setv6Mode(1); print_format[i-1] = '\0'; } else Setv6Mode(0); } i = 0; while ( printmap[i].printmode ) { if ( strncasecmp(print_format, printmap[i].printmode, MAXMODELEN) == 0 ) { if ( printmap[i].Format ) { if ( !ParseOutputFormat(printmap[i].Format, plain_numbers, printmap) ) exit(255); // predefined custom format print_record = printmap[i].func; record_header = get_record_header(); user_format = 1; } else { // To support the pipe output format for element stats - check for pipe, and remember this if ( strncasecmp(print_format, "pipe", MAXMODELEN) == 0 ) { pipe_output = 1; } if ( strncasecmp(print_format, "csv", MAXMODELEN) == 0 ) { csv_output = 1; set_record_header(); record_header = get_record_header(); } // predefined static format print_record = printmap[i].func; user_format = 0; } break; } i++; } } if ( !print_record ) { LogError("Unknown output mode '%s'\n", print_format); exit(255); } // this is the only case, where headers are printed. if ( strncasecmp(print_format, "raw", 16) == 0 ) print_header = format_file_block_header; if ( aggregate && (flow_stat || element_stat) ) { aggregate = 0; LogError("Command line switch -s overwrites -a\n"); } if ( !filter && ffile ) { if ( stat(ffile, &stat_buff) ) { LogError("Can't stat filter file '%s': %s\n", ffile, strerror(errno)); exit(255); } filter = (char *)malloc(stat_buff.st_size+1); if ( !filter ) { LogError("malloc() error in %s line %d: %s\n", __FILE__, __LINE__, strerror(errno) ); exit(255); } ffd = open(ffile, O_RDONLY); if ( ffd < 0 ) { LogError("Can't open filter file '%s': %s\n", ffile, strerror(errno)); exit(255); } ret = read(ffd, (void *)filter, stat_buff.st_size); if ( ret < 0 ) { perror("Error reading filter file"); close(ffd); exit(255); } total_bytes += ret; filter[stat_buff.st_size] = 0; close(ffd); FilterFilename = ffile; } // if no filter is given, set the default ip filter which passes through every flow if ( !filter || strlen(filter) == 0 ) filter = "any"; Engine = CompileFilter(filter); if ( !Engine ) exit(254); if ( fdump ) { printf("StartNode: %i Engine: %s\n", Engine->StartNode, Engine->Extended ? "Extended" : "Fast"); DumpList(Engine); exit(0); } if ( syntax_only ) exit(0); if ( print_order && flow_stat ) { printf("-s record and -O (-m) are mutually exclusive options\n"); exit(255); } if ((aggregate || flow_stat || print_order) && !Init_FlowTable() ) exit(250); if (element_stat && !Init_StatTable(HashBits, NumPrealloc) ) exit(250); SetLimits(element_stat || aggregate || flow_stat, packet_limit_string, byte_limit_string); if ( tstring ) { if ( !ScanTimeFrame(tstring, &t_start, &t_end) ) exit(255); } if ( !(flow_stat || element_stat || wfile || quiet ) && record_header ) { if ( user_format ) { printf("%s\n", record_header); } else { // static format - no static format with header any more, but keep code anyway if ( Getv6Mode() ) { printf("%s\n", record_header); } else printf("%s\n", record_header); } } nfprof_start(&profile_data); sum_stat = process_data(wfile, element_stat, aggregate || flow_stat, print_order != NULL, print_header, print_record, t_start, t_end, limitflows, do_tag, compress, do_xstat); nfprof_end(&profile_data, total_flows); if ( total_bytes == 0 ) { printf("No matched flows\n"); exit(0); } if (aggregate || print_order) { if ( wfile ) { nffile_t *nffile = OpenNewFile(wfile, NULL, compress, is_anonymized, NULL); if ( !nffile ) exit(255); if ( ExportFlowTable(nffile, aggregate, bidir, date_sorted, extension_map_list) ) { CloseUpdateFile(nffile, Ident ); } else { CloseFile(nffile); unlink(wfile); } DisposeFile(nffile); } else { PrintFlowTable(print_record, topN, do_tag, GuessDir, extension_map_list); } } if (flow_stat) { PrintFlowStat(record_header, print_record, topN, do_tag, quiet, csv_output, extension_map_list); #ifdef DEVEL printf("Loopcnt: %u\n", loopcnt); #endif } if (element_stat) { PrintElementStat(&sum_stat, plain_numbers, record_header, print_record, topN, do_tag, quiet, pipe_output, csv_output); } if ( !quiet ) { if ( csv_output ) { PrintSummary(&sum_stat, plain_numbers, csv_output); } else if ( !wfile ) { if (is_anonymized) printf("IP addresses anonymised\n"); PrintSummary(&sum_stat, plain_numbers, csv_output); if ( t_last_flow == 0 ) { // in case of a pre 1.6.6 collected and empty flow file printf("Time window: <unknown>\n"); } else { printf("Time window: %s\n", TimeString(t_first_flow, t_last_flow)); } printf("Total flows processed: %u, Blocks skipped: %u, Bytes read: %llu\n", total_flows, skipped_blocks, (unsigned long long)total_bytes); nfprof_print(&profile_data, stdout); } } Dispose_FlowTable(); Dispose_StatTable(); FreeExtensionMaps(extension_map_list); #ifdef DEVEL if ( hash_hit || hash_miss ) printf("Hash hit: %i, miss: %i, skip: %i, ratio: %5.3f\n", hash_hit, hash_miss, hash_skip, (float)hash_hit/((float)(hash_hit+hash_miss))); #endif return 0; }
void ProcessTerm(Term t) { Term res; Atom procc=0; char regbuf[80]; if(is_compound(t)&&CompoundName(t)==OPR_LOCAL) { List l1,la=ConsumeCompoundArg(t,1); if(l_pro==0) { ErrorInfo(0); puts("local: must be within template."); return; } la=CommaToList(la); for(l1=la;l1;l1=ListTail(l1)) l_ali=AppendLast(l_ali, InterfSetAlias(MakeCompound1(OPR_ALIAS,ListFirst(l1)),0)); RemoveList(la); return; } /* if(is_compound(t) && GetAtomProperty(CompoundName(t),OPR_ALIAS)) {*/ if(!is_compound(t) || (CompoundName(t)!=OPR_ALIAS && CompoundName(t)!=OPR_IN && CompoundName(t)!=OPR_WHERE) ) { t=ProcessAlias(t); proc_hash(t); } /*WriteTerm(t);puts("");*/ /*}*/ if(is_list(t)) { List l, alisav; l_pro++; alisav=l_ali; l_ali=0; for(l=t;l;l=ListTail(l)) ProcessTerm(ListFirst(l)); if(l_ali) RemoveAlias(l_ali); RemoveList(t); l_pro--; l_ali=alisav; return; } if(is_atom(t)) procc=t; if(is_compound(t)) { procc=CompoundName(t); } if(procc==0) { if(!IsTermInput()) printf("File \"%s\", line %d: ",CurrentInputFile(), CurrentInputLine()); printf("Not a valid operator \'"); WriteTerm(t); printf("\'.\n"); FreeAtomic(t); return; } if(!IsTermInput()) sprintf(regbuf, "ProcTerm: File %s, line %d: %s statement.", CurrentInputFile(), CurrentInputLine(), AtomValue(procc)); else sprintf(regbuf, "(tty): %s statement.",AtomValue(procc)); RegisterLine(regbuf); if(!is_function(t,NULL)) { if(!IsTermInput()) printf("File \"%s\", line %d: ",CurrentInputFile(), CurrentInputLine()); printf("Unknown operator \'%s\' in expression\n\t",AtomValue(procc)); WriteTerm(t); puts(""); FreeAtomic(t); UnregisterLine(); return; } if(is_compound(t) && ((VerbMode && CompoundName(t)==OPR_LTERM) || VerbMode==3)) { char sment[1024]; sWriteTerm(sment,t); sment[55]='.'; sment[56]='.'; sment[57]='.'; sment[58]=0; printf("%s:%3d: %s\n",CurrentInputFile(),CurrentInputLine(),sment); } res=CallFunction(t,0); if(res!=0 && (IsTermInput())) { if(is_compound(res) && CompoundArity(t)==2 && CompoundName(res)==A_ALG1) res=Alg1ToExpr(res); if(is_list(res)) DumpList(res); else { WriteTerm(res); puts(""); } FreeAtomic(res); } UnregisterLine(); }
// arg & 1: decompile to C code (1) or normally (0) // arg & 2: print instruction list before splitting into nodes // arg & 4: dump current instruction // arg & 8: process all functions void idaapi run(int arg) { msg("Running The Desquirr decompiler plugin\n"); IdaPro* idapro; if (PLFM_386 == ph.id) idapro = new IdaX86(); else if (PLFM_ARM == ph.id) idapro = new IdaArm(); else { msg("Unexpected processor module\n"); return; } Frontend_ptr frontend(idapro); Frontend::Set(frontend); if (arg & 4) { idapro->DumpInsn(get_screen_ea()); return; } CodeStyle style = (arg & 1) ? C_STYLE : LISTING_STYLE; for (func_t *function= (arg&8)?get_next_func(0) : get_func(get_screen_ea()) ; function ; function= (arg&8)?get_next_func(function->startEA):0) { if (function->flags & FUNC_LIB) msg("Warning: Library function\n"); Instruction_list instructions; msg("-> Creating instruction list\n"); idapro->FillList(function, instructions); if (arg & 2) { msg("Instruction list:\n"); GenerateCode(instructions, style); break; } Node_list nodes; msg("-> Creating node list\n"); Node::CreateList(instructions, nodes); //if (g_bDumpNodeContents) DumpList(nodes); msg("-> Update uses and definitions\n"); UpdateUsesAndDefinitions(nodes); //if (g_bDumpNodeContents) DumpList(nodes); msg("-> Live register analysis\n"); Node::LiveRegisterAnalysis(nodes); //if (g_bDumpNodeContents) DumpList(nodes); msg("-> Finding DU chains\n"); Node::FindDefintionUseChains(nodes); if (g_bDumpNodeContents) DumpList(nodes); msg("-> Data flow analysis\n"); { DataFlowAnalysis analysis(nodes); analysis.AnalyzeNodeList(); // want destructor to run here :-) } if (g_bDumpNodeContents) DumpList(nodes); msg("Basic block list:\n"); GenerateCode(nodes, style); } }