Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.30 KB | None | 0 0
  1. #include <gtk/gtk.h>
  2.  
  3. GtkTextBuffer *loggingBuffer;
  4.  
  5. struct data {
  6.     char* queuedHashes[100][101];
  7.     int queuedHashTypes[100];
  8.     int hashCount;
  9.     GtkWidget *hash;
  10.     GtkWidget *hashType;
  11.     GtkWidget *hashEntryLabel;
  12.     GtkTreeSelection *selectedHash;
  13. };
  14.  
  15. enum {
  16.     LIST_ITEM = 0,
  17.     N_COLUMNS
  18. };
  19.  
  20. GtkWidget *list;
  21.  
  22. ////////////////////////////
  23.  
  24. void test_queue(char* queuedHashes[100][101], int hashCount) {
  25.  
  26.     for (int i = 1; i <= hashCount; i++) {
  27.         g_print("%i: %s\n", i, queuedHashes[i][0]);
  28.     }
  29.  
  30. }
  31.  
  32. ////////////////////////////
  33.  
  34. static void queue_hash (GtkButton *button, gpointer user_data) {
  35.  
  36.     struct data *dataStruct = user_data;
  37.  
  38.     GtkWidget *hashWid = dataStruct->hash;
  39.     GtkWidget *hashTypeWid = dataStruct->hashType;
  40.     GtkWidget *hashEntryLabel = dataStruct->hashEntryLabel;
  41.     GtkListStore *store;
  42.     GtkTreeIter iter;
  43.  
  44.     const char* hash = gtk_entry_get_text(GTK_ENTRY(hashWid));
  45.     int hashLen = gtk_entry_get_text_length(GTK_ENTRY(hashWid));
  46.     int hashTypeIndex = gtk_combo_box_get_active(GTK_COMBO_BOX(hashTypeWid));
  47.  
  48.     store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
  49.  
  50.     // TODO: Update max length to 128
  51.  
  52.     if (hashLen > 100) {
  53.         gtk_widget_set_name(hashWid, "fieldsError");
  54.         gtk_label_set_text(GTK_LABEL(hashEntryLabel), "Hash exceeds max length of 100");
  55.         g_print("Hash length exceeds 100: Exiting.");
  56.  
  57.         return;
  58.     }
  59.  
  60.     gtk_widget_set_name(hashWid, "");
  61.     gtk_widget_set_name(hashTypeWid, "");
  62.     gtk_widget_set_name(hashEntryLabel, "");
  63.     gtk_label_set_text(GTK_LABEL(hashEntryLabel), "Hash to be cracked:");
  64.  
  65.     if ((strcmp(hash, "") == 0) || (hashTypeIndex == -1)) {
  66.  
  67.         if (strcmp(hash, "") == 0) {
  68.             gtk_widget_set_name(hashWid, "fieldsError");
  69.         }
  70.  
  71.         if (hashTypeIndex == -1) {
  72.             gtk_widget_set_name(hashTypeWid, "fieldsError");
  73.         }
  74.  
  75.         g_print("Invalid Entry \n");
  76.  
  77.     } else {
  78.  
  79.         // Check for spaces in hash - return if found
  80.         // TODO: Check for other non-alphabetical chars/symbols
  81.  
  82.         for (int i = 0; i < hashLen; i++) {
  83.             if (hash[i] == ' ') {
  84.                 gtk_widget_set_name(hashWid, "fieldsError");
  85.                 gtk_widget_set_name(hashEntryLabel, "errorLabel");
  86.                 gtk_label_set_text(GTK_LABEL(hashEntryLabel), "Please remove all spaces");
  87.                 g_print("Space found in hash: Exiting\n");
  88.                 return;
  89.             }
  90.         }
  91.  
  92.         g_print("//////////////////////////////\n");
  93.         g_print("Before: (HashCount: %i)\n", dataStruct->hashCount);
  94.         //test_queue(dataStruct->queuedHashes, dataStruct->hashCount);
  95.  
  96.         for (int i = 1; i <= dataStruct->hashCount; i++) {
  97.             g_print("%i: %s\n", i, dataStruct->queuedHashes[i][0]);
  98.         }
  99.  
  100.         sleep(1);
  101.  
  102.         // Save hash to array
  103.         ++dataStruct->hashCount;
  104.         g_print("After Int: %i\n", dataStruct->hashCount);
  105.         g_print("Hash: %s\n", hash);
  106.         dataStruct->queuedHashes[dataStruct->hashCount][0] = hash;
  107.         dataStruct->queuedHashTypes[dataStruct->hashCount] = hashTypeIndex;
  108.  
  109.         g_print ("Queue Hash: %s    %i\n", dataStruct->queuedHashes[dataStruct->hashCount][0], dataStruct->queuedHashTypes[dataStruct->hashCount]);
  110.  
  111.         sleep(1);
  112.  
  113.         g_print("After: (HashCount: %i)\n", dataStruct->hashCount);
  114.         //test_queue(dataStruct->queuedHashes, dataStruct->hashCount);
  115.  
  116.         g_print("Manual 1: %s, 2: %s\n", dataStruct->queuedHashes[1][0], dataStruct->queuedHashes[2][0]);
  117.  
  118.         for (int i = 1; i <= dataStruct->hashCount; i++) {
  119.             g_print("%i: %s\n", i, dataStruct->queuedHashes[i][0]);
  120.         }
  121.  
  122.         const gchar *str = gtk_entry_get_text(GTK_ENTRY(hashWid));
  123.         gtk_list_store_append(store, &iter);
  124.         gtk_list_store_set(store, &iter, LIST_ITEM, str, -1);
  125.  
  126.         char* strToLog;
  127.  
  128.         // TODO: Is this not adding to array properly?
  129.         // TODO: Move queue array to local variable?
  130.  
  131.         if((strToLog = malloc(strlen(strToLog)+strlen(hash)+2)) != NULL){
  132.             strToLog[0] = '\0';
  133.             strcat(strToLog,"Queued Hash: ");
  134.             strcat(strToLog, dataStruct->queuedHashes[dataStruct->hashCount][0]);
  135.             strcat(strToLog, "\n");
  136.         } else {
  137.  
  138.         }
  139.  
  140.         append_to_log(strToLog);
  141.  
  142.         //test_queue(dataStruct->queuedHashes, dataStruct->hashCount);
  143.  
  144.         gtk_combo_box_set_active(GTK_COMBO_BOX(hashTypeWid), -1);
  145.         gtk_entry_set_text(GTK_ENTRY(hashWid), "");
  146.  
  147.     }
  148. }
  149.  
  150. static void init(GtkApplication* app, gpointer user_data) {
  151.     GtkWidget *window;
  152.     GtkWidget *window_fixed;
  153.     GtkWidget *queueButtonBox;
  154.     GtkWidget *queueButton;
  155.     GtkWidget *hashEntry;
  156.     GtkWidget *hashSelect;
  157.     GtkWidget *remHashButton;
  158.     GtkWidget *remHashButtonBox;
  159.     GtkWidget *logBox;
  160.     GtkWidget *nodesLabel;
  161.     GtkWidget *hashLabel;
  162.     GtkWidget *hashEntryLabel;
  163.     GtkWidget *hashTypeLabel;
  164.  
  165.     GtkWidget *listScrollWin;
  166.     GtkWidget *queuedHashBox;
  167.  
  168.     // TODO: Set up system time retrieval for logging to text file - Only time to be show in GUI
  169.     // TODO: Set up logging .txt file
  170.  
  171.     window = gtk_application_window_new (app);
  172.     gtk_window_set_title (GTK_WINDOW (window), "HashCrack Server");
  173.     gtk_window_set_default_size (GTK_WINDOW (window), 1000, 435);
  174.     gtk_window_set_resizable (GTK_WINDOW(window), FALSE);
  175.  
  176.     window_fixed = gtk_fixed_new();
  177.     gtk_container_add(GTK_CONTAINER(window), window_fixed);
  178.  
  179.     GtkCssProvider *cssProvider = gtk_css_provider_new();
  180.     gtk_css_provider_load_from_path(cssProvider,"stylesheet.css",NULL);
  181.     gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_USER);
  182.  
  183.     queueButtonBox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
  184.     queueButton = gtk_button_new_with_label("Queue Hash");
  185.     gtk_widget_set_name(queueButton, "queueButton");
  186.     remHashButtonBox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
  187.     remHashButton = gtk_button_new_with_label("Remove Selected Hash");
  188.  
  189.     listScrollWin = gtk_scrolled_window_new(NULL, NULL);
  190.     list = gtk_tree_view_new();
  191.     gtk_container_add(GTK_CONTAINER(listScrollWin), list);
  192.  
  193.     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(listScrollWin),
  194.                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  195.  
  196.     gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(listScrollWin),
  197.                                         GTK_SHADOW_ETCHED_IN);
  198.  
  199.     gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE);
  200.  
  201.     queuedHashBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
  202.  
  203.     gtk_box_pack_start(GTK_BOX(queuedHashBox), listScrollWin, TRUE, TRUE, 5);
  204.     gtk_widget_set_size_request(queuedHashBox, 250, 325);
  205.     gtk_fixed_put(GTK_FIXED(window_fixed), queuedHashBox, 725, 50);
  206.  
  207.     nodesLabel = gtk_label_new("Connected Nodes");
  208.     gtk_label_set_markup(GTK_LABEL(nodesLabel), "<span font_desc=\"20.0\">Connected Nodes</span>");
  209.     gtk_fixed_put(GTK_FIXED(window_fixed), nodesLabel, 40, 15);
  210.  
  211.     hashLabel = gtk_label_new("Connected Nodes");
  212.     gtk_label_set_markup(GTK_LABEL(hashLabel), "<span font_desc=\"20.0\">Queued Hashes</span>");
  213.     gtk_fixed_put(GTK_FIXED(window_fixed), hashLabel, 755, 15);
  214.  
  215.     hashEntry = gtk_entry_new();
  216.     gtk_widget_set_size_request(hashEntry, 290, 33);
  217.     gtk_entry_set_max_length(GTK_ENTRY(hashEntry), 100);
  218.     gtk_widget_set_name(hashEntry, "fieldsNormal");
  219.     gtk_entry_set_placeholder_text(GTK_ENTRY(hashEntry), "Enter Hash (Max Length 100)");
  220.     gtk_fixed_put(GTK_FIXED(window_fixed), hashEntry, 300, 75);
  221.  
  222.     hashSelect = gtk_combo_box_text_new();
  223.     gtk_widget_set_size_request(hashSelect, 102, 25);
  224.     gtk_fixed_put(GTK_FIXED(window_fixed), hashSelect, 595, 75);
  225.     gtk_widget_set_name(hashSelect, "fieldsNormal");
  226.     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hashSelect), "MD5");
  227.     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hashSelect), "SHA1");
  228.     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hashSelect), "ROT16");
  229.     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hashSelect), "###");
  230.  
  231.     hashTypeLabel = gtk_label_new("Hash Type:");
  232.     gtk_fixed_put(GTK_FIXED(window_fixed), hashTypeLabel, 598, 55);
  233.  
  234.     hashEntryLabel = gtk_label_new("Hash to be cracked:");
  235.     gtk_widget_set_name(hashEntryLabel, "");
  236.     gtk_fixed_put(GTK_FIXED(window_fixed), hashEntryLabel, 303, 55);
  237.     gtk_widget_set_size_request(queueButtonBox, 390, 25);
  238.     gtk_widget_set_size_request(queueButton, 390, 25);
  239.     gtk_fixed_put(GTK_FIXED(window_fixed), queueButtonBox, 300, 120);
  240.  
  241.     struct data *hash_data = g_new0(struct data, 1);
  242.     hash_data->hash = hashEntry;
  243.     hash_data->hashType = hashSelect;
  244.     hash_data->hashEntryLabel = hashEntryLabel;
  245.     g_signal_connect(queueButton, "clicked", G_CALLBACK (queue_hash), hash_data);
  246.  
  247.     loggingBuffer = gtk_text_buffer_new(NULL);
  248.  
  249.     logBox = gtk_text_view_new_with_buffer(loggingBuffer);
  250.     gtk_widget_set_size_request(logBox, 400, 240);
  251.     gtk_text_view_set_editable(GTK_TEXT_VIEW(logBox), FALSE);
  252.     gtk_fixed_put(GTK_FIXED(window_fixed), logBox, 300, 175);
  253.  
  254.     gtk_widget_set_size_request(remHashButtonBox, 200, 25);
  255.     gtk_widget_set_size_request(remHashButton, 200, 25);
  256.     gtk_fixed_put(GTK_FIXED(window_fixed), remHashButtonBox, 750, 390);
  257.  
  258.     append_to_log("Logging started... \n");
  259.  
  260.     // TODO: Write logging line to logfile?
  261.  
  262.     gtk_container_add(GTK_CONTAINER(queueButtonBox), queueButton);
  263.     gtk_container_add(GTK_CONTAINER(remHashButtonBox), remHashButton);
  264.  
  265.     init_list(list);
  266.  
  267.     hash_data->selectedHash = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
  268.  
  269.     g_signal_connect(remHashButton, "clicked",G_CALLBACK(remove_hash), hash_data);
  270.  
  271.     gtk_widget_grab_focus(queueButton);
  272.  
  273.     gtk_widget_show_all(window);
  274. }
  275.  
  276. int main(int argc, char **argv) {
  277.     GtkApplication *app;
  278.     int status;
  279.  
  280.     app = gtk_application_new ("com.sds.hashcrack", G_APPLICATION_FLAGS_NONE);
  281.     g_signal_connect (app, "activate", G_CALLBACK (init), NULL);
  282.     status = g_application_run (G_APPLICATION (app), argc, argv);
  283.     g_object_unref (app);
  284.  
  285.     return status;
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement