Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gtk/gtk.h>
- GtkTextBuffer *loggingBuffer;
- struct data {
- char* queuedHashes[100][101];
- int queuedHashTypes[100];
- int hashCount;
- GtkWidget *hash;
- GtkWidget *hashType;
- GtkWidget *hashEntryLabel;
- GtkTreeSelection *selectedHash;
- };
- enum {
- LIST_ITEM = 0,
- N_COLUMNS
- };
- GtkWidget *list;
- ////////////////////////////
- void test_queue(char* queuedHashes[100][101], int hashCount) {
- for (int i = 1; i <= hashCount; i++) {
- g_print("%i: %s\n", i, queuedHashes[i][0]);
- }
- }
- ////////////////////////////
- static void queue_hash (GtkButton *button, gpointer user_data) {
- struct data *dataStruct = user_data;
- GtkWidget *hashWid = dataStruct->hash;
- GtkWidget *hashTypeWid = dataStruct->hashType;
- GtkWidget *hashEntryLabel = dataStruct->hashEntryLabel;
- GtkListStore *store;
- GtkTreeIter iter;
- const char* hash = gtk_entry_get_text(GTK_ENTRY(hashWid));
- int hashLen = gtk_entry_get_text_length(GTK_ENTRY(hashWid));
- int hashTypeIndex = gtk_combo_box_get_active(GTK_COMBO_BOX(hashTypeWid));
- store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
- // TODO: Update max length to 128
- if (hashLen > 100) {
- gtk_widget_set_name(hashWid, "fieldsError");
- gtk_label_set_text(GTK_LABEL(hashEntryLabel), "Hash exceeds max length of 100");
- g_print("Hash length exceeds 100: Exiting.");
- return;
- }
- gtk_widget_set_name(hashWid, "");
- gtk_widget_set_name(hashTypeWid, "");
- gtk_widget_set_name(hashEntryLabel, "");
- gtk_label_set_text(GTK_LABEL(hashEntryLabel), "Hash to be cracked:");
- if ((strcmp(hash, "") == 0) || (hashTypeIndex == -1)) {
- if (strcmp(hash, "") == 0) {
- gtk_widget_set_name(hashWid, "fieldsError");
- }
- if (hashTypeIndex == -1) {
- gtk_widget_set_name(hashTypeWid, "fieldsError");
- }
- g_print("Invalid Entry \n");
- } else {
- // Check for spaces in hash - return if found
- // TODO: Check for other non-alphabetical chars/symbols
- for (int i = 0; i < hashLen; i++) {
- if (hash[i] == ' ') {
- gtk_widget_set_name(hashWid, "fieldsError");
- gtk_widget_set_name(hashEntryLabel, "errorLabel");
- gtk_label_set_text(GTK_LABEL(hashEntryLabel), "Please remove all spaces");
- g_print("Space found in hash: Exiting\n");
- return;
- }
- }
- g_print("//////////////////////////////\n");
- g_print("Before: (HashCount: %i)\n", dataStruct->hashCount);
- //test_queue(dataStruct->queuedHashes, dataStruct->hashCount);
- for (int i = 1; i <= dataStruct->hashCount; i++) {
- g_print("%i: %s\n", i, dataStruct->queuedHashes[i][0]);
- }
- sleep(1);
- // Save hash to array
- ++dataStruct->hashCount;
- g_print("After Int: %i\n", dataStruct->hashCount);
- g_print("Hash: %s\n", hash);
- dataStruct->queuedHashes[dataStruct->hashCount][0] = hash;
- dataStruct->queuedHashTypes[dataStruct->hashCount] = hashTypeIndex;
- g_print ("Queue Hash: %s %i\n", dataStruct->queuedHashes[dataStruct->hashCount][0], dataStruct->queuedHashTypes[dataStruct->hashCount]);
- sleep(1);
- g_print("After: (HashCount: %i)\n", dataStruct->hashCount);
- //test_queue(dataStruct->queuedHashes, dataStruct->hashCount);
- g_print("Manual 1: %s, 2: %s\n", dataStruct->queuedHashes[1][0], dataStruct->queuedHashes[2][0]);
- for (int i = 1; i <= dataStruct->hashCount; i++) {
- g_print("%i: %s\n", i, dataStruct->queuedHashes[i][0]);
- }
- const gchar *str = gtk_entry_get_text(GTK_ENTRY(hashWid));
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter, LIST_ITEM, str, -1);
- char* strToLog;
- // TODO: Is this not adding to array properly?
- // TODO: Move queue array to local variable?
- if((strToLog = malloc(strlen(strToLog)+strlen(hash)+2)) != NULL){
- strToLog[0] = '\0';
- strcat(strToLog,"Queued Hash: ");
- strcat(strToLog, dataStruct->queuedHashes[dataStruct->hashCount][0]);
- strcat(strToLog, "\n");
- } else {
- }
- append_to_log(strToLog);
- //test_queue(dataStruct->queuedHashes, dataStruct->hashCount);
- gtk_combo_box_set_active(GTK_COMBO_BOX(hashTypeWid), -1);
- gtk_entry_set_text(GTK_ENTRY(hashWid), "");
- }
- }
- static void init(GtkApplication* app, gpointer user_data) {
- GtkWidget *window;
- GtkWidget *window_fixed;
- GtkWidget *queueButtonBox;
- GtkWidget *queueButton;
- GtkWidget *hashEntry;
- GtkWidget *hashSelect;
- GtkWidget *remHashButton;
- GtkWidget *remHashButtonBox;
- GtkWidget *logBox;
- GtkWidget *nodesLabel;
- GtkWidget *hashLabel;
- GtkWidget *hashEntryLabel;
- GtkWidget *hashTypeLabel;
- GtkWidget *listScrollWin;
- GtkWidget *queuedHashBox;
- // TODO: Set up system time retrieval for logging to text file - Only time to be show in GUI
- // TODO: Set up logging .txt file
- window = gtk_application_window_new (app);
- gtk_window_set_title (GTK_WINDOW (window), "HashCrack Server");
- gtk_window_set_default_size (GTK_WINDOW (window), 1000, 435);
- gtk_window_set_resizable (GTK_WINDOW(window), FALSE);
- window_fixed = gtk_fixed_new();
- gtk_container_add(GTK_CONTAINER(window), window_fixed);
- GtkCssProvider *cssProvider = gtk_css_provider_new();
- gtk_css_provider_load_from_path(cssProvider,"stylesheet.css",NULL);
- gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_USER);
- queueButtonBox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
- queueButton = gtk_button_new_with_label("Queue Hash");
- gtk_widget_set_name(queueButton, "queueButton");
- remHashButtonBox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
- remHashButton = gtk_button_new_with_label("Remove Selected Hash");
- listScrollWin = gtk_scrolled_window_new(NULL, NULL);
- list = gtk_tree_view_new();
- gtk_container_add(GTK_CONTAINER(listScrollWin), list);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(listScrollWin),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(listScrollWin),
- GTK_SHADOW_ETCHED_IN);
- gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE);
- queuedHashBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
- gtk_box_pack_start(GTK_BOX(queuedHashBox), listScrollWin, TRUE, TRUE, 5);
- gtk_widget_set_size_request(queuedHashBox, 250, 325);
- gtk_fixed_put(GTK_FIXED(window_fixed), queuedHashBox, 725, 50);
- nodesLabel = gtk_label_new("Connected Nodes");
- gtk_label_set_markup(GTK_LABEL(nodesLabel), "<span font_desc=\"20.0\">Connected Nodes</span>");
- gtk_fixed_put(GTK_FIXED(window_fixed), nodesLabel, 40, 15);
- hashLabel = gtk_label_new("Connected Nodes");
- gtk_label_set_markup(GTK_LABEL(hashLabel), "<span font_desc=\"20.0\">Queued Hashes</span>");
- gtk_fixed_put(GTK_FIXED(window_fixed), hashLabel, 755, 15);
- hashEntry = gtk_entry_new();
- gtk_widget_set_size_request(hashEntry, 290, 33);
- gtk_entry_set_max_length(GTK_ENTRY(hashEntry), 100);
- gtk_widget_set_name(hashEntry, "fieldsNormal");
- gtk_entry_set_placeholder_text(GTK_ENTRY(hashEntry), "Enter Hash (Max Length 100)");
- gtk_fixed_put(GTK_FIXED(window_fixed), hashEntry, 300, 75);
- hashSelect = gtk_combo_box_text_new();
- gtk_widget_set_size_request(hashSelect, 102, 25);
- gtk_fixed_put(GTK_FIXED(window_fixed), hashSelect, 595, 75);
- gtk_widget_set_name(hashSelect, "fieldsNormal");
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hashSelect), "MD5");
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hashSelect), "SHA1");
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hashSelect), "ROT16");
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(hashSelect), "###");
- hashTypeLabel = gtk_label_new("Hash Type:");
- gtk_fixed_put(GTK_FIXED(window_fixed), hashTypeLabel, 598, 55);
- hashEntryLabel = gtk_label_new("Hash to be cracked:");
- gtk_widget_set_name(hashEntryLabel, "");
- gtk_fixed_put(GTK_FIXED(window_fixed), hashEntryLabel, 303, 55);
- gtk_widget_set_size_request(queueButtonBox, 390, 25);
- gtk_widget_set_size_request(queueButton, 390, 25);
- gtk_fixed_put(GTK_FIXED(window_fixed), queueButtonBox, 300, 120);
- struct data *hash_data = g_new0(struct data, 1);
- hash_data->hash = hashEntry;
- hash_data->hashType = hashSelect;
- hash_data->hashEntryLabel = hashEntryLabel;
- g_signal_connect(queueButton, "clicked", G_CALLBACK (queue_hash), hash_data);
- loggingBuffer = gtk_text_buffer_new(NULL);
- logBox = gtk_text_view_new_with_buffer(loggingBuffer);
- gtk_widget_set_size_request(logBox, 400, 240);
- gtk_text_view_set_editable(GTK_TEXT_VIEW(logBox), FALSE);
- gtk_fixed_put(GTK_FIXED(window_fixed), logBox, 300, 175);
- gtk_widget_set_size_request(remHashButtonBox, 200, 25);
- gtk_widget_set_size_request(remHashButton, 200, 25);
- gtk_fixed_put(GTK_FIXED(window_fixed), remHashButtonBox, 750, 390);
- append_to_log("Logging started... \n");
- // TODO: Write logging line to logfile?
- gtk_container_add(GTK_CONTAINER(queueButtonBox), queueButton);
- gtk_container_add(GTK_CONTAINER(remHashButtonBox), remHashButton);
- init_list(list);
- hash_data->selectedHash = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
- g_signal_connect(remHashButton, "clicked",G_CALLBACK(remove_hash), hash_data);
- gtk_widget_grab_focus(queueButton);
- gtk_widget_show_all(window);
- }
- int main(int argc, char **argv) {
- GtkApplication *app;
- int status;
- app = gtk_application_new ("com.sds.hashcrack", G_APPLICATION_FLAGS_NONE);
- g_signal_connect (app, "activate", G_CALLBACK (init), NULL);
- status = g_application_run (G_APPLICATION (app), argc, argv);
- g_object_unref (app);
- return status;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement