void main ( void ) { List black_list_checks; List black_list; List processes; List uptimes; unsigned int cont; /* Intro message */ printf ( "\n*** Embarcadero-Workaround PoC ***\n" ); printf ( "Created by Nicolas A. Economou\n" ); printf ( "Special thanks to Marcos Accossatto\n" ); printf ( "Core Security Technologies, Buenos Aires, Argentina (2014)\n" ); printf ( "\n" ); Sleep ( 2000 ); /* Monitoreo la lista de procesos todo el tiempo */ for ( cont = 0 ; cont < 0xffffffff ; cont ++ ) { /* Getting processes */ get_processes ( processes , uptimes ); /* Merging list */ refresh_processes ( black_list , black_list_checks , processes ); /* Looking for new vulnerable programs */ protect_processes ( black_list , black_list_checks , processes , uptimes ); /* If it's the first time */ if ( cont == 0 ) { /* No more scannings for black listed processes */ block_processes ( black_list , black_list_checks ); } /* A delay for the next try */ Sleep ( 1000 ); } }
int main(int argc, char **argv) { if (argc < 3) { fprintf(stderr, "Please enter a time quantums . . . . \n"); exit(1); } time_slice = atoi(argv[1]); time_slice_1 = atoi(argv[2]); if (time_slice <= 0 || time_slice_1 <= 0) { fprintf(stderr, "Error! program usage rr < positive time quantum> < data file . . .\n"); exit(1); } init_(); clock_t ticks; time_t start_time, end_time; time(&start_time); int i; int status = 0; log_file = fopen("log_file.txt", "w+"); if (log_file == NULL) { fprintf(stderr, "LOG FILE CANNOT BE OPEN\n"); } //initialize cpu's for (i = 0; i < NUMBER_OF_PROCESSORS; i++) { CPU[i] = NULL; } initializeProcessQueue(&readyQueue); initializeProcessQueue(&waitingQueue); initializeProcessQueue(&level_one); initializeProcessQueue(&second_level); //initializeProcessQueue(&promoted); // read in process and initialize process values while ((status = (readProcess(&processes[number_of_processes])))) { if (status == 1) { number_of_processes++; } } if (number_of_processes > MAX_PROCESSES) { return -2; } if (number_of_processes == 0) { return -1; } int remaining_process = 0; //sort process by their arrival times qsort(processes, number_of_processes, sizeof (process), compareByArrival); // main execution loop while (TRUE) { ticks = clock(); waiting_to_ready(); incoming_process_init(); running_process_to_waiting(); most_ready_running_in_cpu(); refresh_processes(); increase_io_work(); increase_cpu_work(); cpu_utilized_time += runningProcesses(); remaining_process = ex(); // break when there are no more running or incoming processes, and the waiting queue is empty if (remaining_process == 0 && runningProcesses() == 0 && waitingQueue.size == 0) { break; } simulation_time++; } int total_waiting_time = 0; int turn_around_time = 0; for (i = 0; i < number_of_processes; i++) { turn_around_time += processes[i].endTime - processes[i].arrivalTime; total_waiting_time += processes[i].waitingTime; } printf(">>>>>>>>>>>>> FBQ with Q1 :%d\tQ2 :%d <<<<<<<<<<<<<<<\n", time_slice, time_slice_1); printf("********************************************************************\n"); printf("Average Waiting Time\t\t\t:%.2f\n", total_waiting_time / (double) number_of_processes); printf("Average Turn Around Time\t\t:%.2f\n", turn_around_time / (double) number_of_processes); printf("Time all for all CPU processes\t\t:%d\n", simulation_time); printf("CPU Utilization Time\t\t\t:%.2f%c\n", (double) (cpu_utilized_time * 100.0) / (double) (simulation_time), (int) 37); printf("Total Number of Context Switches\t:%d\n", context_switches); printf("Last Process to finish "); for (i = 0; i < number_of_processes; i++) { if (processes[i].endTime == simulation_time) { printf("PID\t\t:%d\n", processes[i].pid); } } printf("********************************************************************\n"); time(&end_time); double prg_time = (end_time - start_time) * 0.001; double cpu_time = (double) ticks / CLOCKS_PER_SEC; fprintf(log_file, "Program Time\t:%.2fsecs\n", prg_time); fprintf(log_file, "CPU Time\t:%.2fsecs\n", cpu_time); fclose(log_file); return 0; }
int main() { clock_t ticks; time_t start_time, end_time; time(&start_time); int i; int status = 0; log_file = fopen("log_file.txt", "w+"); if (log_file == NULL) { fprintf(stderr, "LOG FILE CANNOT BE OPEN\n"); } // initialize cpus for (i = 0; i < NUMBER_OF_PROCESSORS; i++) { CPU[i] = NULL; } init_(); initializeProcessQueue(&readyQueue); initializeProcessQueue(&waitingQueue); // read in process and initialize process values while ((status = (readProcess(&processes[number_of_processes])))) { if (status == 1) { number_of_processes++; } if (number_of_processes > MAX_PROCESSES || number_of_processes == 0) { break; } } //sort process by their arrival times qsort(processes, number_of_processes, sizeof (process), compareByArrival); // main execution loop while (TRUE) { ticks = clock(); incoming_process_init(); running_process_to_waiting(); most_ready_running_in_cpu(); waiting_to_ready(); refresh_processes(); cpu_utilized_time += runningProcesses(); simulation_time++; // break when there are no more running or incoming processes, and the waiting queue is empty if (runningProcesses() == 0 && (number_of_processes - nextProcess) == 0 && waitingQueue.size == 0) { break; } } // calculations based on CPU simulations int total_waiting_time = 0; int turn_around_time = 0; for (i = 0; i < number_of_processes; i++) { turn_around_time += processes[i].endTime - processes[i].arrivalTime; total_waiting_time += processes[i].waitingTime; } printf("********************************************************************\n"); printf("Average Waiting Time\t\t\t:%.2f\n", total_waiting_time / (double) number_of_processes); printf("Average Turn Around Time\t\t:%.2f\n", turn_around_time / (double) number_of_processes); printf("Time all for all CPU processes\t\t:%d\n", simulation_time); printf("CPU Utilization Time\t\t\t:%.2f%c\n", (double) (cpu_utilized_time * 100.0) / (double) (simulation_time), (int) 37); printf("Total Number of Context Switches\t:%d\n", context_switches); printf("Last Process to finish "); for (i = 0; i < number_of_processes; i++) { if (processes[i].endTime == last_process_end_time) { printf("PID\t\t:%d\n", processes[i].pid); } } //printf("%d\n" , processes[number_of_processes].pid); printf("********************************************************************\n"); time(&end_time); double prg_time = (end_time - start_time) * 0.001; double cpu_time = (double) ticks / CLOCKS_PER_SEC; fprintf(log_file, "Program Time\t:%.2fsecs\n", prg_time); fprintf(log_file, "CPU Time\t:%.2fsecs\n", cpu_time); fclose(log_file); return 0; }