#define VERSIONE_PROGRAMMA "MV Smart Downloader v 3.04.01 by mamo139" //#define LINUX_VERSION #define console_mode //#define console_mode_grafica #define _CRT_SECURE_NO_WARNINGS #ifdef LINUX_VERSION typedef void* LPVOID; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #else #include #include #include #include #include #include #include #include #pragma comment(lib,"wsock32.lib") #pragma comment(lib,"atk-1.0.lib") #pragma comment(lib,"cairo.lib") #pragma comment(lib,"gio-2.0.lib") #pragma comment(lib,"glib-2.0.lib") #pragma comment(lib,"gmodule-2.0.lib") #pragma comment(lib,"gobject-2.0.lib") #pragma comment(lib,"gthread-2.0.lib") #pragma comment(lib,"gailutil.lib") #pragma comment(lib,"gdk_pixbuf-2.0.lib") #pragma comment(lib,"gdk-win32-2.0.lib") #pragma comment(lib,"gtk-win32-2.0.lib") #pragma comment(lib,"pango-1.0.lib") #pragma comment(lib,"pangocairo-1.0.lib") #pragma comment(lib,"pangoft2-1.0.lib") #pragma comment(lib,"pangowin32-1.0.lib") #endif int processi_num = 10; int download_buffer_size = 1024; int connect_timeout = 15; //timeout della funzione connect() non bloccante int socket_timeout = 15000; //timeout per la conessione double stat_production_time = 0.2; //ogni quanto ricalcolare la percentuale in secondi double speed_production_time = 1; //ogni quanto ricalcolare la velocitā in secondi char *proxylist_file = "proxylist.txt"; long proxy_scarica(char *fileremoto, char *host,char *video_buffer, char *proxy_ip, int timeout_sec, long video_time, long video_lunghezza, float *proxy_speed, long *video_current_point, gboolean *reset); int proxy_scarica_su_stringa(char *fileremoto, char *host,char *stringa, char *proxy_ip, int timeout_sec); long scarica_mv_video(char *video_id, long video_time, long video_lunghezza, char *proxy_ip, char *video_buffer, float* proxy_speed, long *video_current_point, gboolean *reset); int mv_decode(char *string, long key1, long key2); long mv_video_lunghezza(char *video_id, char *proxy_ip); int proxylist_counter(char *file); int proxylist_loader(char **proxylist,char * file); int funzione(LPVOID param); int cambia_proxy_processo(); #ifdef console_mode int tell_me(LPVOID param); #endif #ifdef LINUX_VERSION char *itoa(int value, char *string, int radix); #endif int main_thread(); int main_grafica_uploader(); char * read_clipboard(); typedef struct connection_data { int processo_id; char processo_status; char ** proxylist; float proxy_speed; long proxy_num; long proxy_point; char * video_id; char * video_buffer; long video_point; long video_starting_point; long video_current_point; long video_lunghezza; gboolean reset; float percentage; } connection_data; //***************** gtk widget //finestra main GtkWidget *finestra1; GtkWidget *tabella1; GtkWidget *label_mvid, *label_processi_scaricanti, *label_processi_terminati; GtkWidget *label_time; GtkWidget *label_global_speed, *label_global_speed_value; GtkWidget *label_global_average_speed, *label_global_average_speed_value; GtkWidget *label_global_time_to_end, *label_global_time_to_end_value; GtkWidget *progressbar_main; GtkWidget **progressbar_parziale, **label_download_parziale, *tabella_download_parziale, *scrolledwindow_download_parziale; GtkWidget *textview_console, *scrolledwindow_console; GtkTextBuffer *textview_console_buffer; GtkWidget *combobox_proxy, *combobox_proc; GError **thread_error, **command_error; int console_book_size = 100; char *console_booking, **console_book; int book_manager(); void textview_printf(char *string); void crea_finestra_main(); //finestra_inizio GtkWidget *finestra_inizio; GtkWidget * inizio_entry_mvid; GtkWidget * inizio_entry_processi_num; GtkWidget * inizio_entry_download_buffer_size; GtkWidget * inizio_entry_connect_timeout; void crea_finestra_inizio(); void finestra_inizio_button_start(); //***************** variabili globali char main_grafica_uploader_start = 0; double global_speed = 0; double global_percentage = 0; long global_video_size = 0; long global_processi_terminati = 0; long global_processi_scaricanti = 0; GTimeVal global_time_start, global_time_end; double dglobal_time_start, dglobal_time_end; long global_tempo_trascorso; connection_data *global_dati; char * global_mv_id; //*********************************************// //******************* MAIN ********************// //*********************************************// int main(int argc, char *argv[]){ #ifndef LINUX_VERSION WORD wVersion; WSADATA wsaData; wVersion = MAKEWORD(2, 2); WSAStartup(wVersion, &wsaData); //winsock startup #endif long x=0; GError ** thread_error = NULL; g_type_init(); /* Secure glib */ if( ! g_thread_supported() ) g_thread_init( NULL ); /* Secure gtk */ gdk_threads_init(); /* Obtain gtk's global lock */ gdk_threads_enter(); gtk_init (&argc, &argv);//inizializzo l'ambiente gtk crea_finestra_inizio(); gtk_widget_show_all(finestra_inizio); gtk_main(); /* Release gtk's global lock */ gdk_threads_leave(); #ifndef LINUX_VERSION WSACleanup(); #endif return 0; } void crea_finestra_inizio(){ char *buffer; buffer = (char *) malloc(100 * sizeof(char)); char *mv_id; mv_id = read_clipboard(); //creo finestra finestra_inizio = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(finestra_inizio), VERSIONE_PROGRAMMA); gtk_container_set_border_width(GTK_CONTAINER(finestra_inizio), 3); gtk_window_set_resizable(GTK_WINDOW(finestra_inizio), FALSE); gtk_window_set_position(GTK_WINDOW(finestra_inizio), GTK_WIN_POS_CENTER); g_signal_connect(G_OBJECT(finestra_inizio), "delete_event", G_CALLBACK(gtk_main_quit), NULL); //creo tabella GtkWidget *tabella; tabella = gtk_table_new(10, 2, TRUE); gtk_container_add(GTK_CONTAINER(finestra_inizio), tabella); //labels GtkWidget *lab_title = gtk_label_new("Inserire dati per avviare il download:"); gtk_table_attach_defaults(GTK_TABLE(tabella), lab_title, 0, 2, 0, 1); //entry: megavideo id GtkWidget *lab_1 = gtk_label_new("MegaVideo ID:"); gtk_table_attach_defaults(GTK_TABLE(tabella), lab_1, 0, 1, 1, 2); inizio_entry_mvid = gtk_entry_new_with_max_length(8); if(mv_id != NULL) if(strlen(mv_id) == 8) gtk_entry_set_text(GTK_ENTRY(inizio_entry_mvid), mv_id); gtk_table_attach_defaults(GTK_TABLE(tabella), inizio_entry_mvid, 1, 2, 1, 2); //entry: processi_num GtkWidget *lab_2 = gtk_label_new("Numero di segmenti:"); gtk_table_attach_defaults(GTK_TABLE(tabella), lab_2, 0, 1, 2, 3); inizio_entry_processi_num = gtk_entry_new(); itoa(processi_num, buffer, 10); gtk_entry_set_text(GTK_ENTRY(inizio_entry_processi_num), buffer); gtk_table_attach_defaults(GTK_TABLE(tabella), inizio_entry_processi_num, 1, 2, 2, 3); //entry: download_buffer_size GtkWidget *lab_3 = gtk_label_new("Buffer di download (in bytes):"); gtk_table_attach_defaults(GTK_TABLE(tabella), lab_3, 0, 1, 3, 4); inizio_entry_download_buffer_size = gtk_entry_new(); itoa(download_buffer_size, buffer, 10); gtk_entry_set_text(GTK_ENTRY(inizio_entry_download_buffer_size), buffer); gtk_table_attach_defaults(GTK_TABLE(tabella), inizio_entry_download_buffer_size, 1, 2, 3, 4); //entry: connect_timeout GtkWidget *lab_4 = gtk_label_new("Timeout di connessione ai proxy (in sec):"); gtk_table_attach_defaults(GTK_TABLE(tabella), lab_4, 0, 1, 4, 5); inizio_entry_connect_timeout = gtk_entry_new(); itoa(connect_timeout, buffer, 10); gtk_entry_set_text(GTK_ENTRY(inizio_entry_connect_timeout), buffer); gtk_table_attach_defaults(GTK_TABLE(tabella), inizio_entry_connect_timeout, 1, 2, 4, 5); //bottone GtkWidget * button_start = gtk_button_new_with_label("Start"); gtk_table_attach_defaults(GTK_TABLE(tabella), button_start, 1, 2, 6, 7); g_signal_connect(G_OBJECT(button_start), "clicked", G_CALLBACK(finestra_inizio_button_start), NULL); free(buffer); } void finestra_inizio_button_start(){ gtk_widget_hide_all(finestra_inizio); char *buffer; //prendiamo i dati //mv_id char *mv_id = (char *) gtk_entry_get_text(GTK_ENTRY(inizio_entry_mvid)); global_mv_id = (char *) malloc(10 * sizeof(char)); sprintf(global_mv_id, "%s", mv_id); //processi_num buffer = (char *) gtk_entry_get_text(GTK_ENTRY(inizio_entry_processi_num)); if(atoi(buffer) > 0) processi_num = atoi(buffer); //download_buffer_size buffer = (char *) gtk_entry_get_text(GTK_ENTRY(inizio_entry_download_buffer_size)); if(atoi(buffer) > 0) download_buffer_size = atoi(buffer); //connect_timeout buffer = (char *) gtk_entry_get_text(GTK_ENTRY(inizio_entry_connect_timeout)); if(atoi(buffer) > 0) connect_timeout = atoi(buffer); //creiamo e visualizziamo finestra crea_finestra_main(); gtk_widget_show_all(finestra1); //thread di download principale g_thread_create((GThreadFunc) main_thread, NULL, 0, thread_error); //thread che gestisce aggiornamento grafica g_timeout_add(100, (GSourceFunc) main_grafica_uploader, NULL); } void crea_finestra_main(){ long x; GError ** thread_error = NULL; char *buffer; buffer = (char *) malloc(1000*sizeof(char)); gdk_threads_enter(); //********** FINESTRA1 *************// finestra1 = gtk_window_new(GTK_WINDOW_TOPLEVEL); //creo la finestra principale gtk_window_set_title(GTK_WINDOW(finestra1), VERSIONE_PROGRAMMA); //setto il titolo della finestra principale gtk_container_set_border_width(GTK_CONTAINER(finestra1), 3); //setto il bordo della finestra principale gtk_window_set_resizable(GTK_WINDOW(finestra1), FALSE); //rendo non resizable la finestra principale gtk_window_set_position(GTK_WINDOW(finestra1), GTK_WIN_POS_CENTER); //posizione iniziale finestra g_signal_connect(G_OBJECT(finestra1), "delete_event", G_CALLBACK(gtk_main_quit), NULL); //evento chiusura finestra princ //********** TABELLA1 *************// tabella1 = gtk_table_new(25, 10, TRUE); //creo la tabella principale gtk_container_add(GTK_CONTAINER(finestra1), tabella1); //inserisco la tabella princ. nella finestra princ. //label_mvid, label_processi_scaricanti, label_processi_terminati label_mvid = gtk_label_new("Waiting for MegaVideo ID..."); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_mvid, 0, 2, 0, 1); label_processi_scaricanti = gtk_label_new("processi_scaricanti"); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_processi_scaricanti, 8, 10, 3, 4); label_processi_terminati = gtk_label_new("processi_terminati"); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_processi_terminati, 8, 10, 4, 5); //label_time g_get_current_time(&global_time_start); dglobal_time_start = (double) global_time_start.tv_sec + (double) global_time_start.tv_usec/G_USEC_PER_SEC; label_time = gtk_label_new("tempo_trascorso"); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_time, 8, 10, 0, 1); //label_global_speed label_global_speed= gtk_label_new("Velocita' di download:"); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_global_speed, 4, 6, 3, 4); label_global_speed_value = gtk_label_new("0"); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_global_speed_value, 6, 8, 3, 4); //label_global_average_speed label_global_average_speed = gtk_label_new("Velocita' media:"); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_global_average_speed, 4, 6, 4, 5); label_global_average_speed_value = gtk_label_new("0"); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_global_average_speed_value, 6, 8, 4, 5); //label_global_time_to_end label_global_time_to_end = gtk_label_new("Tempo alla fine:"); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_global_time_to_end, 4, 6, 5, 6); label_global_time_to_end_value = gtk_label_new("0"); gtk_table_attach_defaults(GTK_TABLE(tabella1), label_global_time_to_end_value, 6, 8, 5, 6); //gestore proxy combobox_proxy = gtk_combo_box_new_text(); gtk_table_attach_defaults(GTK_TABLE(tabella1), combobox_proxy, 6, 9, 16, 18); combobox_proc = gtk_combo_box_new_text(); gtk_table_attach_defaults(GTK_TABLE(tabella1), combobox_proc, 5, 6, 16, 18); for(x=0;x0) average_speed = downloaded_bytes/(global_tempo_trascorso*1024); else average_speed = 0; if(average_speed > 0 && global_percentage > 0) time_left = (long) (((double)global_video_size-downloaded_bytes)/1024/average_speed); else time_left = 0; gdk_threads_enter(); //titolo finestra sprintf(console_string,"%.2f%% %s", global_percentage*100, VERSIONE_PROGRAMMA); gtk_window_set_title(GTK_WINDOW(finestra1), console_string); //labels sprintf(console_string,"%d su %d scaricanti", global_processi_scaricanti, (processi_num-global_processi_terminati)); gtk_label_set_text(GTK_LABEL(label_processi_scaricanti), console_string); sprintf(console_string,"%d su %d terminati", global_processi_terminati, processi_num); gtk_label_set_text(GTK_LABEL(label_processi_terminati), console_string); sprintf(console_string,"%02d:%02d:%02d", (global_tempo_trascorso/60/60),(global_tempo_trascorso/60)%60, global_tempo_trascorso%60); gtk_label_set_text(GTK_LABEL(label_time), console_string); sprintf(console_string,"%.2f KB/sec", global_speed); gtk_label_set_text(GTK_LABEL(label_global_speed_value), console_string); sprintf(console_string,"%.2f KB/sec", average_speed); gtk_label_set_text(GTK_LABEL(label_global_average_speed_value), console_string); sprintf(console_string,"%02d:%02d:%02d", (time_left/60/60),(time_left/60)%60, time_left%60); gtk_label_set_text(GTK_LABEL(label_global_time_to_end_value), console_string); //progressbar_main if(global_percentage >= 0 && global_percentage <=1) gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar_main),((gdouble)global_percentage)); else{ global_percentage = 0; gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar_main),((gdouble)0)); } sprintf(console_string,"%.2f%% (%.2f KB/sec)",global_percentage*100,global_speed); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar_main),console_string); for(x=0;x1 || global_percentage>=1) global_dati[x].percentage = 1; if(global_dati[x].percentage >= 0 && global_dati[x].percentage <=1) gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar_parziale[x]),((gdouble)global_dati[x].percentage)); else{ global_dati[x].percentage = 0; gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar_parziale[x]),((gdouble)0)); } sprintf(console_string,"%d: proxy %d (%.2f KB/sec)",global_dati[x].processo_id,global_dati[x].proxy_point, global_dati[x].proxy_speed); gtk_label_set_text(GTK_LABEL(label_download_parziale[x]), console_string); //sprintf(console_string,"%.2f%%",global_dati[x].percentage*100); //gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar_parziale[x]),console_string); } while(gtk_events_pending()) gtk_main_iteration(); gdk_threads_leave(); free(console_string); return 1; } int main_thread(){ FILE *stream; long x, y, proxy_num, video_bytes=0; char **proxylist; char *video_buffer; gboolean wait=1; int processi_terminati; float overall_speed = 0; float download_percentage = 0; float tot_download_percentage = 0; int download_attivi = 0; char *console_string; console_string = (char *) malloc(1000 * sizeof(char)); char *video_id; //********* VARIABILI *********// video_id = global_mv_id; if(video_id == 0 || strlen(video_id) != 8){ #ifdef console_mode printf("La stringa che hai in memoria non č un ID megavideo valido!\n"); #endif gtk_label_set_text(GTK_LABEL(label_mvid), "ID megavideo non valido..."); textview_printf("ID megavideo non valido...\n"); return 0; } else{ #ifdef console_mode printf("ID video letto dalla clipboard: %s\n",video_id); #endif sprintf(console_string, "MegaVideo ID: %s",video_id); gtk_label_set_text(GTK_LABEL(label_mvid), console_string); sprintf(console_string, "MegaVideo ID: %s\n",video_id); textview_printf(console_string); } //******************************// //*** CARICAMENTO PROXY LIST ***// //******************************// #ifdef console_mode printf("PROXYLIST: caricamento proxylist...\n"); #endif textview_printf("PROXYLIST: caricamento proxylist...\n"); proxy_num = proxylist_counter(proxylist_file); if(proxy_num < 0){ #ifdef console_mode printf("PROXYLIST: file %s non trovato!\n",proxylist_file); #endif sprintf(console_string, "PROXYLIST: file %s non trovato!\n",proxylist_file); textview_printf(console_string); Sleep(100); return 0; } #ifdef console_mode printf("PROXYLIST: numero dei proxy: %d\n",proxy_num); #endif sprintf(console_string, "PROXYLIST: numero dei proxy: %d\n",proxy_num); textview_printf(console_string); proxylist = (char **) malloc(proxy_num * sizeof(char *)); for(x=0;x 1000000000 || video_bytes < 100){ video_bytes = 0; video_bytes = mv_video_lunghezza(video_id, proxylist[x]); x++; } #ifdef console_mode printf("\n"); #endif textview_printf("\n"); global_video_size = video_bytes; //******************************// //*** CREAZIONE BUFFER VIDEO ***// //******************************// video_buffer = (char *) calloc (video_bytes, sizeof(char)); for(x=0;x0) download_attivi++; //****************************// //***** DOWNLOAD GRAFICA *****// //****************************// #ifdef console_mode_grafica if(dati[x].processo_id < 10) printf(" "); printf("%d: ",dati[x].processo_id); #endif download_percentage = (float)100*(dati[x].video_current_point-dati[x].video_starting_point)/dati[1].video_starting_point; if(dati[x].processo_status == 0) download_percentage = 100; else if(download_percentage >= 100) download_percentage = 100; else if(download_percentage <= 0) download_percentage = 0; tot_download_percentage = tot_download_percentage+download_percentage/processi_num; dati[x].percentage = (float) download_percentage/100; #ifdef console_mode_grafica printf("|"); for(y=0;y<33;y++) if (download_percentage == 100) printf("X"); else if(y*100/33 < download_percentage) printf("x"); else printf("-"); printf("| %.2f%%\x09%.3f\x09proxy %d\n", download_percentage, dati[x].proxy_speed,dati[x].proxy_point); #endif } #ifdef console_mode_grafica printf("\nCONNECTION MANAGER: %.2f%% SPEED: %.3f kbs (%d su %d scaricanti)\n\n",tot_download_percentage, overall_speed,download_attivi,(processi_num-processi_terminati)); #endif if(tot_download_percentage>=100) tot_download_percentage = 100; else if(tot_download_percentage <= 0) tot_download_percentage = 0; //salvo i dati nelle variabili globali global_speed = overall_speed; global_percentage = ((double)tot_download_percentage/100); global_processi_scaricanti = download_attivi; global_processi_terminati = processi_terminati; #ifdef console_mode_grafica printf("\ntell me:\n"); #endif } #ifdef console_mode printf("CONNECTION MANAGER: Tutti i processi sono terminati.\n\n"); #endif textview_printf("CONNECTION MANAGER: Tutti i processi sono terminati.\n\n"); //********************************// //*** SCRITTURA FILE SCARICATO ***// //********************************// #ifdef console_mode printf("BUFFER: scrittura buffer su file in corso...\n"); #endif textview_printf("BUFFER: scrittura buffer su file in corso...\n"); sprintf(console_string, "%s.flv", video_id); stream = fopen(console_string,"wb"); fwrite(video_buffer,1,video_bytes,stream); fclose(stream); #ifdef console_mode printf("BUFFER: buffer scritto!\n\n"); #endif textview_printf("BUFFER: buffer scritto!\n\n"); return 1; } //********************************************************************// #ifdef console_mode int tell_me(LPVOID param){ connection_data *dati = (connection_data *) param; int proc, proxy; char comando; while(1){ printf(">"); scanf("%c",&comando); if(comando == 'r'){ //chiude connessione del processo e la riapre con il proxy selezionato printf("RESET "); printf("processo:"); scanf("%d",&proc); printf("proxy:",proc); scanf("%d",&proxy); printf("\nRESET OK: processo %d proxy %d\n",proc,proxy); if(proxy>0)proxy=proxy-1; dati[proc].reset = 1; dati[proc].proxy_point = proxy; } } return 1; } #endif int cambia_proxy_processo(){ int proc, proxy; proxy = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_proxy)); proc = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_proc)); if(proc < 0 || proc >= processi_num || proxy < 0) return 0; global_dati[proc].reset = 1; global_dati[proc].proxy_point = proxy-1; return 1; } //********************************************************************// int funzione(LPVOID param){ long video_point_now; connection_data *dati = (connection_data *) param; char *console_string; console_string = (char *) malloc(1000 * sizeof(char)); video_point_now = dati->video_point; #ifdef console_mode printf("PROCESSO %d: inizializzazione in corso...\n", dati->processo_id); printf("PROCESSO %d: video id: %s starting point: %d\n", dati->processo_id, dati->video_id, video_point_now); printf("PROCESSO %d: proxy point: %d\n", dati->processo_id, dati->proxy_point); #endif sprintf(console_string, "PROCESSO %d: inizializzazione in corso...\n", dati->processo_id); textview_printf(console_string); sprintf(console_string, "PROCESSO %d: video id: %s starting point: %d\n", dati->processo_id, dati->video_id, video_point_now); textview_printf(console_string); sprintf(console_string, "PROCESSO %d: proxy point: %d\n", dati->processo_id, dati->proxy_point); textview_printf(console_string); while(1){ if(video_point_now < 0) break; if(video_point_now >= dati->video_lunghezza) break; #ifdef console_mode printf("PROCESSO %d: start download, point %d, proxy %d -> %s\n", dati->processo_id,video_point_now,dati->proxy_point, dati->proxylist[dati->proxy_point]); #endif sprintf(console_string, "PROCESSO %d: start download, point %d, proxy %d -> %s\n", dati->processo_id,video_point_now,dati->proxy_point, dati->proxylist[dati->proxy_point]); textview_printf(console_string); if(dati->proxy_point < 0 || dati->proxy_point >= dati->proxy_num) dati->proxy_point = 0; video_point_now = scarica_mv_video(dati->video_id, video_point_now, dati->video_lunghezza, dati->proxylist[dati->proxy_point], dati->video_buffer, &dati->proxy_speed, &dati->video_current_point, &dati->reset); if(video_point_now >= 0) dati->proxy_point++; if(dati->proxy_point >= dati->proxy_num) dati->proxy_point = 0;//riavvolgi lista proxy } dati->processo_status = 0; //segnalo chiusura processo #ifdef console_mode printf("PROCESSO %d: terminato!\n", dati->processo_id); #endif sprintf(console_string, "PROCESSO %d: terminato!\n", dati->processo_id); textview_printf(console_string); return 1; } /****************** PROXYLIST_COUNTER *****************/ int proxylist_counter(char *file){ FILE *in; long in_size; in = fopen(file,"rb"); if(in == NULL) return -1; fseek(in,0,SEEK_END); in_size = ftell(in); rewind(in); char *buffer; buffer = (char *) malloc(in_size * sizeof(char)); fread(buffer,1,in_size,in); int numero_proxy=0,x,y=0,z=0,c1=0; for(x=0;x26)printf("ERRORE! Sintassi proxylist non corretta...\n"); if(y>=numero_proxy) break; if(buffer[x]=='\x0a'){y++;c1=0;z=0;} else if( buffer[x] > 58 || buffer[x]< 46 ) c1=1; else if(c1==0){ proxylist[y][z] = buffer[x]; proxylist[y][z+1] = '\0'; z++; } } gdk_threads_enter(); for(x=0;x0) itoa(video_time,svideo_time,10); else svideo_time[0]='\0'; time_t itempo; char stempo[20]; itempo = time(NULL); itoa(itempo,stempo,10); //printf("time: %s\n",stempo); char *url; url = (char *)malloc(1000*sizeof(char)); sprintf(url, "http://www.megavideo.com/xml/videolink.php?v=%s&width=1278&id=%s&u=", video_id, stempo); char *url_myip; url_myip = (char *)malloc(1000*sizeof(char)); sprintf(url_myip,"/xml/videolink.php?v=%s&width=1278&id=%s&u=",video_id,stempo); int risp = 0; if(strcmp(proxy_ip, "127.0.0.1:80") != 0) risp = proxy_scarica_su_stringa(url,"www.megavideo.com",mv_xml_file,proxy_ip,15); else risp = proxy_scarica_su_stringa(url_myip,"www.megavideo.com",mv_xml_file,proxy_ip,15); if(risp == 0){ #ifdef console_mode printf("proxy_scarica_su_stringa timeout!\n"); #endif return video_time; } #ifdef console_mode printf("%s\n\n",mv_xml_file); printf("xml strlen: %d\n",strlen(mv_xml_file)); #endif if(strlen(mv_xml_file) < 100) return video_time; #ifdef console_mode printf("inizio analisi xml file...\n"); #endif int x,ap_counter=0,i=0, key1,key2; for(x=0;x0 && i<20)ckey1[i-1]=mv_xml_file[x]; i++; } if(ap_counter == 18){ if(i<20)ckey1[i-1] = '\0'; i=0; if(i<20)key1=atoi(ckey1); } if(ap_counter == 19){ //caricamento key2 if(i>0 && i<20)ckey2[i-1]=mv_xml_file[x]; i++; } if(ap_counter == 20){ if(i<20)ckey2[i-1] = '\0'; i=0; if(i<20)key2=atoi(ckey2); } if(ap_counter == 21){ //caricamento hash if(i>0 && i<40)hash[i-1]=mv_xml_file[x]; i++; } if(ap_counter == 22){ if(i<40)hash[i-1] = '\0'; i=0; } if(ap_counter == 23){ //caricamento serverid if(i>0 && i<20)serverid[i-1]=mv_xml_file[x]; i++; } if(ap_counter == 24){ if(i<20)serverid[i-1] = '\0'; i=0; } } //printf("key1: %d key2: %d serverid: %s\nhash: %s %d\n",key1,key2,serverid,hash,strlen(hash)); if(strlen(hash)!=32){ #ifdef console_mode printf("errore estrazione dati per decoding...\n"); #endif return video_time; } #ifdef console_mode printf("decoding in: %s\n",hash); #endif mv_decode(hash, key1, key2); #ifdef console_mode printf("decoding ok: %s\n",hash); #endif char *furl; furl = (char *) malloc(1000*sizeof(char)); sprintf(furl,"http://www%s.megavideo.com/files/%s/%s", serverid, hash, svideo_time); char *furl_myip; furl_myip = (char *) malloc(1000*sizeof(char)); sprintf(furl_myip,"/files/%s/%s", hash, svideo_time); char *fhost; fhost = (char *) malloc(1000*sizeof(char)); sprintf(fhost, "www%s.megavideo.com", serverid); #ifdef console_mode printf("FINAL DOWNLOAD URL: %s\n",furl); #endif if(strcmp(proxy_ip, "127.0.0.1:80") != 0) video_time = proxy_scarica(furl, fhost,video_buffer, proxy_ip, 15, video_time, video_lunghezza, proxy_speed, video_current_point, reset); else video_time = proxy_scarica(furl_myip, fhost,video_buffer, proxy_ip, 15, video_time, video_lunghezza, proxy_speed, video_current_point, reset); free(mv_xml_file); free(ckey1); free(ckey2); free(hash); free(serverid); free(url); free(furl); free(fhost); return video_time; } /******************* MV_VIDEO_LUNGHEZZA *******************/ long mv_video_lunghezza(char *video_id, char *proxy_ip){ char *mv_xml_file; char *console_string; char *ckey1; mv_xml_file = (char *) malloc(10000 * sizeof(char)); mv_xml_file[0] = '\0'; ckey1 = (char *) malloc(10*sizeof(char)); console_string = (char *) malloc(1000 * sizeof(char)); ckey1[0] = '\0'; time_t itempo; char stempo[20]; itempo = time(NULL); itoa(itempo,stempo,10); //printf("time: %s\n",stempo); char *url, *url_myip; url = (char *) malloc(1000*sizeof(char)); url_myip = (char *) malloc(1000*sizeof(char)); sprintf(url,"http://www.megavideo.com/xml/videolink.php?v=%s&width=1278&id=%s&u=",video_id,stempo); sprintf(url_myip,"/xml/videolink.php?v=%s&width=1278&id=%s&u=",video_id,stempo); #ifdef console_mode printf("VIDEO: %s\n",url); #endif sprintf(console_string, "VIDEO: %s\n",url); textview_printf(console_string); if(strcmp(proxy_ip, "127.0.0.1:80") != 0) proxy_scarica_su_stringa(url,"www.megavideo.com",mv_xml_file,proxy_ip,15); //ricevo file di configurazione megavideo else proxy_scarica_su_stringa(url_myip,"www.megavideo.com",mv_xml_file,proxy_ip,15); //ricevo file di configurazione megavideo #ifdef console_mode printf("%s\n\n",mv_xml_file); printf("xml strlen: %d\n",strlen(mv_xml_file)); #endif if(strlen(mv_xml_file) < 10) return 0; int x,ap_counter=0,i=0, key1; for(x=0;x0)ckey1[i-1]=mv_xml_file[x]; i++; } if(ap_counter == 12){ ckey1[i-1] = '\0'; i=0; key1=atoi(ckey1); } } #ifdef console_mode printf("VIDEO: bytes: %d\n",key1); #endif sprintf(console_string, "VIDEO: bytes: %d\n",key1); textview_printf(console_string); return key1; } /************************* PROXY_SCARICA_SU_STRINGA *************************/ int proxy_scarica_su_stringa(char *fileremoto, char *host,char *stringa, char *proxy_ip, int timeout_sec){ gboolean header = TRUE; //variabili per header gboolean invio = FALSE; //variabili per header char ultimo_carattere = '\0'; char msg_response[] = "\0"; //proxy ip char ipn[10]; int k = 0, i = 0, nip = 0; int ip1 = 0, ip2 = 0, ip3 = 0, ip4 = 0, ipport = 0; for(k = 0; k < (strlen(proxy_ip)+1); k++){ if(proxy_ip[k] != 46 && proxy_ip[k] != 58 && k!=strlen(proxy_ip)){ ipn[i] = proxy_ip[k]; ipn[i+1] = '\0'; i++; } else{ if(nip == 0) ip1 = atoi(ipn); if(nip == 1) ip2 = atoi(ipn); if(nip == 2) ip3 = atoi(ipn); if(nip == 3) ip4 = atoi(ipn); if(nip == 4) ipport = atoi(ipn); nip++; i = 0; } } #ifdef console_mode printf("risoluzione indirizzo ip: %d.%d.%d.%d:%d\n",ip1,ip2,ip3,ip4,ipport); #endif //********* CONNESSIONE *********// #ifdef LINUX_VERSION struct sockaddr_in sock; //la struttura per il socket int s; fd_set fds; struct timeval timeout; struct hostent *h; s = socket(AF_INET, SOCK_STREAM, 0); //fcntl(s, F_SETFL, O_NONBLOCK); // funzione linux socket non bloccanti //dati per Select timeout.tv_sec = timeout_sec; // numero di secondi per il timeout timeout.tv_usec = 0; FD_ZERO(&fds); FD_SET(s, &fds); //aggiungo sd all'elenco dei socket gestiti da select int res; char indirizzo[15]; if(ip1==127 && ip2==0 && ip3==0 && ip4==1){ //se vogliamo utilizzare il nostro ip h = gethostbyname(host); sock.sin_family = h->h_addrtype; memcpy((char *)&sock.sin_addr.s_addr, h->h_addr_list[0], h->h_length); sock.sin_port = htons(ipport); } else{ sock.sin_family = AF_INET; sock.sin_port = htons(ipport); sprintf(indirizzo, "%d.%d.%d.%d\0", ip1, ip2, ip3, ip4); res = inet_pton(AF_INET, indirizzo, &sock.sin_addr); } if (res < 0){ printf("errore: il primo parametro non č una family address valida\n"); } else if (res == 0){ printf("errore: il secondo parametro non č un indirizzo ip valido\n"); } else printf("tutto ok\n"); #else struct sockaddr_in sock; //la struttura per il socket int s; fd_set fds; struct timeval timeout; struct hostent ip; //la struttura per l'indirizzo unsigned long cmd; s = socket(AF_INET, SOCK_STREAM, 0); cmd=1; // imposto modalitā socket non boccante (andrā gestita con select()) ioctlsocket( s, FIONBIO, &cmd); // dati per Select timeout.tv_sec = connect_timeout; // numero di secondi per il timeout timeout.tv_usec = 0; // numero di microsecondi per il timeout FD_ZERO(&fds); FD_SET(s, &fds); // aggiungo s all'elenco dei socket gestiti da select sock.sin_addr.S_un.S_un_b.s_b1=ip1; // indico l'indirizzo IP sock.sin_addr.S_un.S_un_b.s_b2=ip2; sock.sin_addr.S_un.S_un_b.s_b3=ip3; sock.sin_addr.S_un.S_un_b.s_b4=ip4; sock.sin_port = htons(ipport); //porta if(ip1==127 && ip2==0 && ip3==0 && ip4==1){ //se vogliamo utilizzare il nostro ip ip = *(gethostbyname(host)); // indico l'indirizzo memcpy(&sock.sin_addr, ip.h_addr, ip.h_length); //copia l'indirizzo nella struttura socket } sock.sin_family = AF_INET; #endif connect(s, (struct sockaddr *)&sock, sizeof(sock)); //ci connettiamo if (select(s+1, 0, &fds, 0, &timeout)>0){ //riusciamo a stabilire la connessione #ifdef LINUX_VERSION fcntl(s, F_SETFL, 0); // risetto il socket bloccante #else cmd=0;//ripristino socket bloccante ioctlsocket( s, FIONBIO, &cmd); #endif struct timeval tv; tv.tv_sec = socket_timeout; tv.tv_usec = 0; setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv) ); setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv) ); //********* MESSAGGIO *********// //messaggio per il server... char msg_enter[600] = "GET "; char protocollo[] = " HTTP/1.1\r\n"; char protocollo2[] = "Host: "; char protocollo3[] = "\r\n"; //char dettagli1[] = "Range: bytes=0-20\r\n"; strcat(msg_enter,fileremoto); strcat(msg_enter,protocollo); strcat(msg_enter,protocollo2); strcat(msg_enter,host); strcat(msg_enter,protocollo3); //strcat(msg_enter,dettagli1); //header strcat(msg_enter,"\r\n"); //printf("HTTP PROTOCOL: %s\n", msg_enter); send(s, msg_enter, strlen(msg_enter), 0); //invia dati //printf("Download in corso...\n\n"); k = 0; stringa[0] = '\0'; while(recv(s, msg_response, 1, 0) > 0) { if (!header){ stringa[k] = msg_response[0]; k++; } //else printf("%c",msg_response[0]); //controllo per non scrivere header nel file. if (ultimo_carattere == 13 && msg_response[0] == 10 && invio==true) header=false; ((ultimo_carattere == 13 && msg_response[0] == 10) || (ultimo_carattere==10 && invio))?invio=true:invio=false; ultimo_carattere = msg_response[0]; //fprintf(fo,"%c",msg_response[0]); } //printf("recv fine!\n"); stringa[k] = '\0'; //printf("File Ricevuto\n"); }//fine if(select()) else{ //timeout //printf("Connessione timeout!\n"); return 0; } //operazioni di chiusura! #ifdef LINUX_VERSION shutdown(s, 2); close(s); #else shutdown(s, 2); closesocket(s); #endif return 1; } /************* PROXY_SCARICA **************/ long proxy_scarica(char *fileremoto, char *host,char *video_buffer, char *proxy_ip, int timeout_sec, long video_time, long video_lunghezza, float *proxy_speed, long *video_current_point, gboolean *reset){ long vid_byte_count = video_time; long x; gboolean header = true; //variabili per header gboolean invio = false; char ultimo_carattere = '\0'; char msg_response[] = "\0"; //proxy ip char ipn[10]; int k=0,i=0,nip=0; int ip1=0,ip2=0,ip3=0,ip4=0,ipport=0; for(k=0;k<(strlen(proxy_ip)+1);k++){ if(proxy_ip[k] != 46 && proxy_ip[k] != 58 && k!=strlen(proxy_ip)){ ipn[i]=proxy_ip[k]; ipn[i+1]='\0'; i++; } else{ if(nip==0)ip1=atoi(ipn); if(nip==1)ip2=atoi(ipn); if(nip==2)ip3=atoi(ipn); if(nip==3)ip4=atoi(ipn); if(nip==4)ipport=atoi(ipn); nip++; i=0; } } #ifdef console_mode printf("risoluzione indirizzo ip: %d.%d.%d.%d:%d\n",ip1,ip2,ip3,ip4,ipport); #endif //********* CONNESSIONE *********// #ifdef LINUX_VERSION struct sockaddr_in sock; //la struttura per il socket struct hostent *h; int s; fd_set fds; struct timeval timeout; s = socket(AF_INET, SOCK_STREAM, 0); //fcntl(s, F_SETFL, O_NONBLOCK); // funzione linux socket non bloccanti //dati per Select timeout.tv_sec = timeout_sec; // numero di secondi per il timeout timeout.tv_usec = 0; FD_ZERO(&fds); FD_SET(s, &fds); //aggiungo sd all'elenco dei socket gestiti da select char indirizzo[15]; int res; if(ip1==127 && ip2==0 && ip3==0 && ip4==1){ //se vogliamo utilizzare il nostro ip h = gethostbyname(host); sock.sin_family = h->h_addrtype; memcpy((char *)&sock.sin_addr.s_addr, h->h_addr_list[0], h->h_length); sock.sin_port = htons(ipport); } else{ sock.sin_family = AF_INET; sock.sin_port = htons(ipport); sprintf(indirizzo, "%d.%d.%d.%d\0", ip1, ip2, ip3, ip4); printf("INDIRIZZO FINALE PROXY: %s\n", indirizzo); res = inet_pton(AF_INET, indirizzo, &sock.sin_addr); } if (res < 0){ printf("errore: il primo parametro non č una family address valida\n"); } else if (res == 0){ printf("errore: il secondo parametro non č un indirizzo ip valido\n"); } else printf("tutto ok\n"); #else struct sockaddr_in sock; //la struttura per il socket int s; fd_set fds; struct timeval timeout; struct hostent ip; //la struttura per l'indirizzo unsigned long cmd; s = socket(AF_INET, SOCK_STREAM, 0); cmd=1; // imposto modalitā socket non boccante (andrā gestita con select()) ioctlsocket( s, FIONBIO, &cmd); // dati per Select timeout.tv_sec = connect_timeout; // numero di secondi per il timeout timeout.tv_usec = 0; // numero di microsecondi per il timeout FD_ZERO(&fds); FD_SET(s, &fds); // aggiungo s all'elenco dei socket gestiti da select sock.sin_addr.S_un.S_un_b.s_b1=ip1; // indico l'indirizzo IP sock.sin_addr.S_un.S_un_b.s_b2=ip2; sock.sin_addr.S_un.S_un_b.s_b3=ip3; sock.sin_addr.S_un.S_un_b.s_b4=ip4; sock.sin_port = htons(ipport); //porta if(ip1==127 && ip2==0 && ip3==0 && ip4==1){ //se vogliamo utilizzare il nostro ip ip = *(gethostbyname(host)); // indico l'indirizzo memcpy(&sock.sin_addr, ip.h_addr, ip.h_length); //copia l'indirizzo nella struttura socket } sock.sin_family = AF_INET; #endif connect(s, (struct sockaddr *)&sock, sizeof(sock)); //ci connettiamo if (select(s+1, 0, &fds, 0, &timeout)>0){ //riusciamo a stabilire la connessione #ifdef LINUX_VERSION fcntl(s, F_SETFL, 0); // risetto il socket bloccante #else cmd=0;//ripristino socket bloccante ioctlsocket( s, FIONBIO, &cmd); #endif struct timeval tv; tv.tv_sec = socket_timeout; tv.tv_usec = 0; setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv) ); setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv) ); //********* MESSAGGIO *********// //messaggio per il server... char msg_enter[600] = "GET "; char protocollo[] = " HTTP/1.1\r\n"; char protocollo2[] = "Host: "; char protocollo3[] = "\r\n"; //char dettagli1[] = "Range: bytes=0-20\r\n"; strcat(msg_enter,fileremoto); strcat(msg_enter,protocollo); strcat(msg_enter,protocollo2); strcat(msg_enter,host); strcat(msg_enter,protocollo3); //strcat(msg_enter,dettagli1); //header strcat(msg_enter,"\r\n"); #ifdef console_mode printf("Invio al server:\n\n%s\n", msg_enter); #endif send(s, msg_enter, strlen(msg_enter), 0); //invia dati //orologio GTimeVal start,end; double tempo_trascorso = 0, dstart, dend; long cicli=0; long cicli2 = 0; int possib = 0; gboolean lentezza = 0; long downloaded_bytes = 0; char *download_buffer; download_buffer = (char *) malloc(download_buffer_size * sizeof(char)); char *http_header; long lhead = 0; http_header = (char *) malloc(10000*sizeof(char)); while(downloaded_bytes = recv(s, msg_response, 1, 0) > 0){ http_header[lhead] = msg_response[0]; lhead++; //controllo per non scrivere header nel file. if (ultimo_carattere == 13 && msg_response[0] == 10 && invio==true) header=false; ((ultimo_carattere == 13 && msg_response[0] == 10) || (ultimo_carattere==10 && invio))?invio=true:invio=false; ultimo_carattere = msg_response[0]; if(!header) break; //ricevuto header esci dal ciclo } http_header[lhead] = '\0'; #ifdef console_mode printf("Header risposta:\n\n%s\n", http_header); #endif free(http_header); if(downloaded_bytes > 0) while(downloaded_bytes = recv(s, msg_response, 1, 0) > 0){ if(cicli == 0 && msg_response[0] != '\x46'){ break; }//se non ricevo header flv chiudo download if( cicli>=9 || video_time == 0 ){ video_buffer[vid_byte_count] = msg_response[0]; vid_byte_count++; break; } cicli++; } g_get_current_time(&start); if(downloaded_bytes > 0){ if(cicli>=9 || video_time == 0) { while(1){ downloaded_bytes = recv(s, download_buffer, download_buffer_size, 0); #ifndef LINUX_VERSION if(downloaded_bytes < 0){ int wsaerrore = WSAGetLastError(); #ifdef console_mode printf("recv %d error code: %d\n", downloaded_bytes, wsaerrore); #endif } #endif if(downloaded_bytes <= 0) break; if(video_buffer[vid_byte_count] != '\0'){ vid_byte_count = -1; //disattivo processo break; //se i dati sono gia stati scritti mi fermo } for(x=0;x speed_production_time){ *proxy_speed = ((double)(cicli-cicli2)/(tempo_trascorso*1024)); g_get_current_time(&start); cicli2 = cicli; } *video_current_point = vid_byte_count; //reset control if(*reset == 1){ *reset = 0; break; } } } } //printf("recv fine!\n"); *proxy_speed = 0; //azzero la velocitā //cancello ultimi 200 byte long j,bersaglio; if(video_lunghezza > vid_byte_count && vid_byte_count>=0){ if(vid_byte_count-200 < video_time) bersaglio = video_time; else bersaglio = vid_byte_count-200; for(j=vid_byte_count;j>=bersaglio;j--) video_buffer[j] = '\0'; vid_byte_count=bersaglio; } }//fine if(select()) else{ //timeout #ifdef console_mode printf("Connessione timeout!\n"); #endif return vid_byte_count; } //operazioni di chiusura! #ifdef LINUX_VERSION shutdown(s, 2); close(s); #else shutdown(s, 2); closesocket(s); #endif return vid_byte_count; } /********** MV_DECODE ***********/ int mv_decode(char *string, long key1, long key2){ int string_len = strlen(string); char *decoded; decoded = (char *) malloc(200 * sizeof(char)); char *binblock; binblock = (char *) malloc(200); binblock[0] = '\0'; int i; for( i=0; i < string_len; ++i ){ switch( string[i] ){ case '0': strcat(binblock,"0000"); break; case '1': strcat(binblock,"0001"); break; case '2': strcat(binblock,"0010"); break; case '3': strcat(binblock,"0011"); break; case '4': strcat(binblock,"0100"); break; case '5': strcat(binblock,"0101"); break; case '6': strcat(binblock,"0110"); break; case '7': strcat(binblock,"0111"); break; case '8': strcat(binblock,"1000"); break; case '9': strcat(binblock,"1001"); break; case 'a': strcat(binblock,"1010"); break; case 'b': strcat(binblock,"1011"); break; case 'c': strcat(binblock,"1100"); break; case 'd': strcat(binblock,"1101"); break; case 'e': strcat(binblock,"1110"); break; case 'f': strcat(binblock,"1111"); break; } } long *ciphers; ciphers = (long *) malloc(384 * sizeof(long)); for( i = 0; i < 384; ++i ){ key1 = (key1 * 11 + 77213) % 81371; key2 = (key2 * 17 + 92717) % 192811; ciphers[i] = (key1 + key2) % 128; } long cipher,offset,tmp; for( i = 256; i >= 0; --i ){ cipher = ciphers[i]; offset = i % 128; tmp = binblock[cipher]; binblock[cipher] = binblock[offset]; binblock[offset] = tmp; } for( i = 0; i < 128; ++i ){ binblock[i] = binblock[i] ^ ciphers[i + 256] & 1; } int a=0; for(i=0;i < string_len*4 ; i=i+4 ){ if(binblock[i]== '0' && binblock[i+1]== '0' && binblock[i+2]== '0' && binblock[i+3]== '0' ) decoded[a] = '0'; else if(binblock[i]== '0' && binblock[i+1]== '0' && binblock[i+2]== '0' && binblock[i+3]== '1' ) decoded[a] = '1'; else if(binblock[i]== '0' && binblock[i+1]== '0' && binblock[i+2]== '1' && binblock[i+3]== '0' ) decoded[a] = '2'; else if(binblock[i]== '0' && binblock[i+1]== '0' && binblock[i+2]== '1' && binblock[i+3]== '1' ) decoded[a] = '3'; else if(binblock[i]== '0' && binblock[i+1]== '1' && binblock[i+2]== '0' && binblock[i+3]== '0' ) decoded[a] = '4'; else if(binblock[i]== '0' && binblock[i+1]== '1' && binblock[i+2]== '0' && binblock[i+3]== '1' ) decoded[a] = '5'; else if(binblock[i]== '0' && binblock[i+1]== '1' && binblock[i+2]== '1' && binblock[i+3]== '0' ) decoded[a] = '6'; else if(binblock[i]== '0' && binblock[i+1]== '1' && binblock[i+2]== '1' && binblock[i+3]== '1' ) decoded[a] = '7'; else if(binblock[i]== '1' && binblock[i+1]== '0' && binblock[i+2]== '0' && binblock[i+3]== '0' ) decoded[a] = '8'; else if(binblock[i]== '1' && binblock[i+1]== '0' && binblock[i+2]== '0' && binblock[i+3]== '1' ) decoded[a] = '9'; else if(binblock[i]== '1' && binblock[i+1]== '0' && binblock[i+2]== '1' && binblock[i+3]== '0' ) decoded[a] = 'a'; else if(binblock[i]== '1' && binblock[i+1]== '0' && binblock[i+2]== '1' && binblock[i+3]== '1' ) decoded[a] = 'b'; else if(binblock[i]== '1' && binblock[i+1]== '1' && binblock[i+2]== '0' && binblock[i+3]== '0' ) decoded[a] = 'c'; else if(binblock[i]== '1' && binblock[i+1]== '1' && binblock[i+2]== '0' && binblock[i+3]== '1' ) decoded[a] = 'd'; else if(binblock[i]== '1' && binblock[i+1]== '1' && binblock[i+2]== '1' && binblock[i+3]== '0' ) decoded[a] = 'e'; else if(binblock[i]== '1' && binblock[i+1]== '1' && binblock[i+2]== '1' && binblock[i+3]== '1' ) decoded[a] = 'f'; else return 0; decoded[a+1] = '\0'; a++; } for(i=0;i 36 || radix <= 1){ return 0; } sign = (radix == 10 && value < 0); if (sign) v = -value; else v = (unsigned)value; while (v || tp == tmp){ i = v % radix; v = v / radix; if (i < 10) *tp++ = i+'0'; else *tp++ = i + 'a' - 10; } if (string == 0) string = (char *)malloc((tp-tmp)+sign+1); sp = string; if (sign) *sp++ = '-'; while (tp > tmp) *sp++ = *--tp; *sp = 0; return string; } #endif