static int randomize_shebang(int fd) { int num_args,i,rand_length; write(fd,"#",1); if (rand()%2) insert_whitespace(fd); write(fd,"!",1); if (rand()%2) insert_whitespace(fd); switch(rand()%4) { case 0: get_random_shell(filename, FILENAME_SIZE); break; case 1: get_random_file(filename, FILENAME_SIZE, RANDOM_FILE_RANDOM); break; case 2: get_random_file(filename, FILENAME_SIZE, RANDOM_FILE_SYSTEM); break; case 3: get_random_file(filename, FILENAME_SIZE, RANDOM_FILE_EXECUTABLE); break; } /* Possibly corrupt filename */ if (rand()%10==1) string_corrupt(filename); /* Write out filename */ write(fd,filename,strlen(filename)); if (rand()%2) insert_whitespace(fd); /* random number of command line args */ switch(rand()%3) { case 0: num_args=0; break; case 1: num_args=rand()%4; break; case 2: num_args=rand()%20000; break; default: num_args=0; break; } for(i=0;i<num_args;i++) { get_random_file(filename, FILENAME_SIZE, RANDOM_FILE_RANDOM); write(fd,filename,strlen(filename)); insert_whitespace(fd); } /* write random data */ if (rand()%2) { rand_length=rand()%FILENAME_SIZE; for(i=0;i<rand_length;i++) { filename[i]=rand(); } write(fd,filename,rand_length); } return 0; }
/** * @brief Public contructor. * @param input_device Input device specifier. * @param audio_device Audio output device specifier, * e.g. hw:0 when using ALSA or Portaudio. */ receiver::receiver(const std::string input_device, const std::string audio_device, unsigned int decimation) : d_running(false), d_input_rate(96000.0), d_audio_rate(48000), d_decim(decimation), d_rf_freq(144800000.0), d_filter_offset(0.0), d_cw_offset(0.0), d_recording_iq(false), d_recording_wav(false), d_sniffer_active(false), d_iq_rev(false), d_dc_cancel(false), d_iq_balance(false), d_demod(RX_DEMOD_OFF) { tb = gr::make_top_block("gqrx"); if (input_device.empty()) { src = osmosdr::source::make("file="+get_random_file()+",freq=428e6,rate=96000,repeat=true,throttle=true"); } else { input_devstr = input_device; src = osmosdr::source::make(input_device); } // input decimator if (d_decim >= 2) { try { input_decim = make_hbf_decim(d_decim); } catch (std::range_error &e) { std::cout << "Error creating input decimator " << d_decim << ": " << e.what() << std::endl << "Using decimation 1." << std::endl; d_decim = 1; } d_quad_rate = d_input_rate / (double)d_decim; } else { d_quad_rate = d_input_rate; } // create I/Q sink and close it iq_sink = gr::blocks::file_sink::make(sizeof(gr_complex), get_null_file().c_str(), true); iq_sink->set_unbuffered(true); iq_sink->close(); rx = make_nbrx(d_quad_rate, d_audio_rate); lo = gr::analog::sig_source_c::make(d_quad_rate, gr::analog::GR_SIN_WAVE, 0.0, 1.0); mixer = gr::blocks::multiply_cc::make(); iq_swap = make_iq_swap_cc(false); dc_corr = make_dc_corr_cc(d_quad_rate, 1.0); iq_fft = make_rx_fft_c(8192u, 0); audio_fft = make_rx_fft_f(8192u); audio_gain0 = gr::blocks::multiply_const_ff::make(0.1); audio_gain1 = gr::blocks::multiply_const_ff::make(0.1); wav_sink = gr::blocks::wavfile_sink::make(get_null_file().c_str(), 2, (unsigned int) d_audio_rate, 16); audio_udp_sink = make_udp_sink_f(); #ifdef WITH_PULSEAUDIO audio_snk = make_pa_sink(audio_device, d_audio_rate, "GQRX", "Audio output"); #else audio_snk = gr::audio::sink::make(d_audio_rate, audio_device, true); #endif output_devstr = audio_device; /* wav sink and source is created when rec/play is started */ audio_null_sink0 = gr::blocks::null_sink::make(sizeof(float)); audio_null_sink1 = gr::blocks::null_sink::make(sizeof(float)); sniffer = make_sniffer_f(); /* sniffer_rr is created at each activation. */ set_demod(RX_DEMOD_NFM); #ifndef QT_NO_DEBUG_OUTPUT gr::prefs pref; std::cout << "Using audio backend: " << pref.get_string("audio", "audio_module", "N/A") << std::endl; #endif }
//Gets the next music file to play. If a music file was set in the // config, that is used. Otherwise, fetches a random music file. s32 get_music_file() { struct stat st; char dirpath[200]; bool useDir = true; DIR_ITER *dir = NULL; //check for config set music file or path if (*CFG.music_file) { //if ((strstr(CFG.music_file, ".mp3") != NULL) // || (strstr(CFG.music_file, ".mod") != NULL)) { if (match_ext(CFG.music_file, ".mp3") || match_ext(CFG.music_file, ".mod")) { //load a specific file strcpy(music_fname, CFG.music_file); dbg_printf(gt("Music file: %s"), music_fname); dbg_printf("\n"); if (strlen(music_fname) < 5) return 0; if (stat(music_fname, &st) != 0) { dbg_printf(gt("File not found! %s"), music_fname); dbg_printf("\n"); return 0; } useDir = false; } else { //load a specific directory dir = diropen(CFG.music_file); if (!dir) { //not a valid dir so try default strcpy(dirpath, USBLOADER_PATH); } else { dirclose(dir); strcpy(dirpath, CFG.music_file); } } } else { strcpy(dirpath, USBLOADER_PATH); } //if a directory is being used, then get a random file to play if (useDir) { // try music.mp3 or music.mod get_random_file(".mp3", dirpath); //snprintf(music_fname, sizeof(music_fname), "%s/%s", USBLOADER_PATH, "music.mp3"); if (stat(music_fname, &st) != 0) { first_time = true; get_random_file(".mod", dirpath); //snprintf(music_fname, sizeof(music_fname), "%s/%s", USBLOADER_PATH, "music.mod"); if (stat(music_fname, &st) != 0) { dbg_printf(gt("music.mp3 or music.mod not found!")); dbg_printf("\n"); return 0; } } dbg_printf(gt("Music file from dir: %s"), music_fname); dbg_printf("\n"); } music_size = st.st_size; dbg_printf(gt("Music file size: %d"), music_size); dbg_printf("\n"); if (music_size <= 0) return 0; if (match_ext(music_fname, ".mp3")) { music_format = FORMAT_MP3; } else if (match_ext(music_fname, ".mod")) { music_format = FORMAT_MOD; } else { music_format = 0; return 0; } music_open(); if (!music_f) { if (*CFG.music_file || CFG.debug) { printf(gt("Error opening: %s"), music_fname); printf("\n"); sleep(2); } return 0; } return 1; //success }