void bits_fprint(FILE *f, const bits_t *bits) { string_t *s; s = bits_encode(bits); string_fprint(f, s); free(s); }
DCPluginSyncFilterResult dcplugin_sync_pre_filter(DCPlugin *dcplugin, DCPluginDNSPacket *dcp_packet) { FILE *fp = dcplugin_get_user_data(dcplugin); const unsigned char *wire_data = dcplugin_get_wire_data(dcp_packet); size_t wire_data_len = dcplugin_get_wire_data_len(dcp_packet); size_t i = (size_t) 12U; size_t csize = (size_t) 0U; unsigned short type; unsigned char c; _Bool first = 1; if (wire_data_len < 15U || wire_data[4] != 0U || wire_data[5] != 1U) { return DCP_SYNC_FILTER_RESULT_ERROR; } if (wire_data[i] == 0U) { putc_unlocked('.', fp); } while (i < wire_data_len && (csize = wire_data[i]) != 0U && csize < wire_data_len - i) { i++; if (first != 0) { first = 0; } else { putc_unlocked('.', fp); } string_fprint(fp, &wire_data[i], csize); i += csize; } type = 0U; if (i < wire_data_len - 2U) { type = (wire_data[i + 1U] << 8) + wire_data[i + 2U]; } if (type == 0x01) { fputs("\t[A]\n", fp); } else if (type == 0x02) { fputs("\t[NS]\n", fp); } else if (type == 0x0f) { fputs("\t[MX]\n", fp); } else if (type == 0x1c) { fputs("\t[AAAA]\n", fp); } else { fprintf(fp, "\t[0x%02hX]\n", type); } fflush(fp); return DCP_SYNC_FILTER_RESULT_OK; }
int blue_main(int argc, char **argv){ int arg_index; int mode=0; char * filename = NULL; char * output_filename = NULL; /* Not enough arguments */ if (argc < 2 ) usage(); Global = malloc(sizeof(struct Global)); if ( ! Global){ printf("Out of Memory\n"); exit(1); } Global->dbg_status = 0; /* handle arguments to blue */ for (arg_index=1; arg_index<argc ; arg_index++){ if (argv[arg_index][0] == '-'){ /* disassemble and quit*/ if ( strcmp(argv[arg_index], "-d")==0 ) mode = 1; else if ( strcmp(argv[arg_index], "-c")==0 ) mode = 2; else if ( strcmp(argv[arg_index], "-g")==0 ) Global->dbg_status = 1; else if ( strcmp(argv[arg_index], "-o")==0 ){ arg_index++; output_filename = argv[arg_index]; } else if ( strcmp(argv[arg_index], "-s")==0 ){ mode = 3 ; } else if ( strcmp(argv[arg_index], "-a")==0 ){ mode = 4 ; } if (argc <3) return 0; }else{ filename = argv[arg_index]; break; } } /* Initialization routines */ global_init(); link_setThreadState(0); // turn multi-threading off until needed if (mode==1){ /* DISASSEMBLE */ Link module = create_module_filename(filename); string_t code = disassemble(module->value.module->bytecode); string_fprint(code , stdout); exit(0); } else if (mode == 2){ /* COMPILE */ Link module = create_module_filename(filename); module_save( module, output_filename ? output_filename : "blue.blx"); exit(0); }else if (mode == 3){ /* COMPILE TO ASSEMBLY CODE */ char * acode = compile_file( filename); if ( memcmp( acode, "ERR:",4) ==0 ){ printf( acode+4); exit(0); } if (output_filename){ FILE * fp = fopen( output_filename,"wb"); fprintf(fp,acode); fclose(fp); }else{ printf(acode); } free(acode); exit(0); }else if (mode == 4){ /* ASSEMBLE THS ASSEMBLY CODE TO BYTECODE */ char * acode = file_load(filename); if ( memcmp( acode, "ERR:",4) ==0 ){ printf( acode+4); exit(0); } Bytes bytes = assemble( acode ); if (output_filename){ bytes_save(bytes, output_filename); }else{ bytes_save(bytes, "out.blx"); } free(acode); exit(0); } /* Add arguments from call to this application */ Link Arg = array_new(argc-arg_index); Link * Argv = array_getArray(Arg); Link a = NULL; int c = 0; for(c=0; c <argc-arg_index; c++){ a = create_string_str( string_new((argv+arg_index)[c]) ); Argv[c] =a; } /* creates and runs the module */ Link main_ret = module_new(filename, Arg); link_free(Arg); if (main_ret){ showBacktrace(main_ret); link_free(main_ret); } fflush(stdout); fflush(stderr); exit(0); return 0; }