summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am18
-rw-r--r--src/editor.c662
2 files changed, 680 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..07af7b5
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,18 @@
+
+bin_PROGRAMS=openida
+
+openida_SOURCES = \
+ editor.c
+
+
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/intl $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) `pkg-config --cflags gthread-2.0`
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS)
+
+
+openida_LDFLAGS = $(LIBGTK_LIBS) -L/usr/X11R6/lib -ldl $(LIBXML_LIBS) `pkg-config --libs gthread-2.0`
+
+
+openida_LDADD = $(LIBINTL)
diff --git a/src/editor.c b/src/editor.c
new file mode 100644
index 0000000..3614379
--- /dev/null
+++ b/src/editor.c
@@ -0,0 +1,662 @@
+
+/* Firebox Tools - Outils de configurations pour le WM Firebox
+ * editor.c - fichier principal de l'éditeur de configuration
+ *
+ * Copyright (C) 2006-2007 Cyrille Bagard
+ *
+ * This file is part of Firebox Tools.
+ *
+ * Firebox Tools is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Firebox Tools is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <locale.h>/* Fonction main() */
+#include <config.h> /* idem */
+#include <stdlib.h> /* ... */
+
+
+#include <gtk/gtk.h>
+
+
+/** exemple GTK **/
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+/** exemple GTK **/
+
+/** Partie ptrace() **/
+#include <sys/ptrace.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <linux/user.h>
+#include <sys/syscall.h> /* For SYS_write etc */
+/** Partie ptrace() **/
+
+
+#define _(str) str
+
+
+void sigchld_handler(int num);
+
+
+
+/* Construit la fenêtre de l'éditeur. */
+GtkWidget *create_editor(void);
+
+/* Quitte le programme en sortie de la boucle de GTK. */
+void destroy_editor(GtkWidget *, gpointer);
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : argc = nombre d'arguments dans la ligne de commande. *
+* argv = arguments de la ligne de commande. *
+* *
+* Description : Point d'entrée du programme. *
+* *
+* Retour : EXIT_SUCCESS si le prgm s'est déroulé sans encombres. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int main(int argc, char **argv)
+{
+ GtkWidget *editor; /* Fenêtre graphique */
+
+ setlocale(LC_ALL, "");
+ /*
+ bindtextdomain(PACKAGE, LOCALE_DIR);
+ textdomain(PACKAGE);
+ */
+
+ /* init threads */
+ g_thread_init(NULL);
+ gdk_threads_init();
+
+ /* Initialisation de GTK */
+ gtk_set_locale();
+ gtk_init(&argc, &argv);
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ /*LIBXML_TEST_VERSION*/
+
+ /* Initialisation du programme */
+ editor = create_editor();
+ gtk_widget_show(editor);
+
+
+ gdk_threads_enter();
+ gtk_main();
+ gdk_threads_leave();
+
+ return EXIT_SUCCESS;
+
+}
+
+
+
+
+
+
+
+GCond* data_cond = NULL; /* Must be initialized somewhere */
+GMutex* data_mutex = NULL; /* Must be initialized somewhere */
+gboolean run_again = FALSE;
+
+
+
+
+void
+on_button1_clicked (GtkButton *button,
+ gpointer user_data);
+
+
+
+
+GtkLabel *lbl_eax;
+GtkLabel *lbl_ebx;
+GtkLabel *lbl_ecx;
+GtkLabel *lbl_edx;
+
+
+
+
+typedef struct _th_info
+{
+ pid_t child;
+ GtkTextBuffer *buffer;
+
+
+
+} th_info;
+
+
+
+#include <asm/ptrace-abi.h>
+#include <sys/reg.h>
+
+#include <error.h>
+#include <errno.h>
+
+extern int errno;
+
+
+void *argument_thread(void *args)
+{
+ th_info *info;
+ long orig_eax, eax;
+ long params;
+ int status;
+
+ char buffer[12];
+
+ pid_t pid;
+
+
+
+
+ pid = fork();
+
+
+
+ if (pid > 0)
+ {
+ /*****/
+
+ }
+ else ptrace(PTRACE_TRACEME, 0, NULL, NULL);
+
+ sleep(1);
+
+
+ if(pid == -1)
+ {
+ /* ouch, fork() failed */
+ perror("fork");
+ exit(-1);
+ }
+ else if(pid == 0)
+ {
+ // ptrace(PTRACE_TRACEME, 0, NULL, NULL);
+ execlp("ls", "ls", "-CF", "/", NULL);
+
+ /* if exec() returns, there is something wrong */
+ perror("execlp");
+
+ /* exit child. note the use of _exit() instead of exit() */
+ _exit(-1);
+ }
+ else
+ {
+ info = (th_info *)args;
+ info->child = pid;
+
+ /* parent */
+ gtk_text_buffer_insert_at_cursor (info->buffer, "#PARENT# Fork() succeed !\n", -1);
+
+
+ while(1)
+ {
+ pid = waitpid(info->child, &status, 0/*WNOHANG*/);
+ //wait(&status);
+
+ if(WIFEXITED(status))
+ break;
+
+ orig_eax = ptrace(PTRACE_PEEKUSER,
+ info->child, 4 * ORIG_EAX, NULL);
+ if (orig_eax == -1)
+ {
+ printf("errno :: %d vs %d\n", errno, ESRCH);
+ perror("ptrace()");
+ }
+
+ /* get GTK thread lock */
+ gdk_threads_enter();
+
+ params = ptrace(PTRACE_PEEKUSER, info->child, 4 * EAX, NULL);
+ snprintf(buffer, 11, "0x%08lx", params);
+ gtk_label_set_text(lbl_eax, buffer);
+
+ params = ptrace(PTRACE_PEEKUSER, info->child, 4 * EBX, NULL);
+ snprintf(buffer, 11, "0x%08lx", params);
+ gtk_label_set_text(lbl_ebx, buffer);
+
+ params = ptrace(PTRACE_PEEKUSER, info->child, 4 * ECX, NULL);
+ snprintf(buffer, 11, "0x%08lx", params);
+ gtk_label_set_text(lbl_ecx, buffer);
+
+ params = ptrace(PTRACE_PEEKUSER, info->child, 4 * EDX, NULL);
+ snprintf(buffer, 11, "0x%08lx", params);
+ gtk_label_set_text(lbl_edx, buffer);
+
+ gtk_text_buffer_insert_at_cursor (info->buffer, "Thread waiting for resume...\n", -1);
+
+ gdk_flush ();
+
+ /* release GTK thread lock */
+ gdk_threads_leave();
+
+ g_mutex_lock (data_mutex);
+ while (!run_again)
+ g_cond_wait (data_cond, data_mutex);
+ run_again = FALSE;
+ g_mutex_unlock (data_mutex);
+
+ ptrace(PTRACE_SYSCALL,
+ info->child, NULL, NULL);
+ }
+
+
+
+ }
+
+
+
+ return NULL;
+
+}
+
+
+
+
+void
+on_button1_clicked (GtkButton *button,
+ gpointer data)
+{
+ GtkTextBuffer *buffer;
+ th_info *info;
+ GError *error = NULL;
+
+ gtk_widget_set_state(GTK_WIDGET(button), GTK_STATE_INSENSITIVE);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (data));
+ gtk_text_buffer_insert_at_cursor (buffer, "Hello, this is some text\n", -1);
+
+
+ info = (th_info *)calloc(1, sizeof(th_info));
+ info->child = 0/*pid*/;
+ info->buffer = buffer;
+
+ data_cond = g_cond_new ();
+ data_mutex = g_mutex_new ();
+
+ if (!g_thread_create(argument_thread, info, FALSE, &error))
+ {
+ printf ("Failed to create YES thread: %s\n", error->message);
+ }
+
+
+
+
+}
+
+
+void
+on_button2_clicked (GtkButton *button,
+ gpointer data)
+{
+
+ g_mutex_lock (data_mutex);
+ run_again = TRUE;
+ g_cond_signal (data_cond);
+ g_mutex_unlock (data_mutex);
+
+}
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit la fenêtre de l'éditeur. *
+* *
+* Retour : Adresse de la fenêtre mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GtkWidget *create_editor(void)
+{
+ GtkWidget *result; /* Fenêtre à renvoyer */
+
+ GtkWidget *vbox1;
+ GtkWidget *vpaned1;
+ GtkWidget *hpaned1;
+ GtkWidget *scrolledwindow2;
+ GtkWidget *textview2;
+ GtkWidget *fixed1;
+ GtkWidget *label1;
+ GtkWidget *button2;
+ GtkWidget *image1;
+ GtkWidget *button1;
+ GtkWidget *table1;
+ GtkWidget *label3;
+ GtkWidget *label4;
+ GtkWidget *label5;
+ GtkWidget *label6;
+ GtkWidget *label7;
+ GtkWidget *label8;
+ GtkWidget *label9;
+ GtkWidget *label10;
+ GtkWidget *label11;
+ GtkWidget *label12;
+ GtkWidget *label14;
+ GtkWidget *label15;
+ GtkWidget *label16;
+ GtkWidget *label17;
+ GtkWidget *label18;
+ GtkWidget *label19;
+ GtkWidget *label20;
+ GtkWidget *label21;
+ GtkWidget *scrolledwindow1;
+ GtkWidget *textview1;
+ GtkWidget *statusbar1;
+
+
+#if 0
+ GtkWidget *vbox; /* Support à divisions vert. */
+ GtkWidget *notebook; /* Support à onglets */
+ GtkWidget *panel; /* Panneau de configuration */
+ GtkWidget *label; /* Etiquette pour onglet */
+ GtkWidget *hseparator; /* Barre de séparation */
+ GtkWidget *hbuttonbox; /* Support horizontal de btns. */
+ GtkWidget *button; /* Btn. de commande inférieur */
+#endif
+
+
+ result = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_size_request(result, 600, 600);
+ gtk_window_set_position(GTK_WINDOW(result), GTK_WIN_POS_CENTER);
+ gtk_container_set_border_width(GTK_CONTAINER(result), 4);
+ gtk_window_set_title(GTK_WINDOW(result), _("OpenIDA"));
+
+ g_signal_connect(G_OBJECT(result), "destroy", G_CALLBACK(destroy_editor), NULL);
+
+
+
+
+
+ vbox1 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_show (vbox1);
+ gtk_container_add (GTK_CONTAINER (result), vbox1);
+
+ vpaned1 = gtk_vpaned_new ();
+ gtk_widget_show (vpaned1);
+ gtk_box_pack_start (GTK_BOX (vbox1), vpaned1, TRUE, TRUE, 0);
+ gtk_paned_set_position (GTK_PANED (vpaned1), 400);
+
+ hpaned1 = gtk_hpaned_new ();
+ gtk_widget_show (hpaned1);
+ gtk_paned_pack1 (GTK_PANED (vpaned1), hpaned1, FALSE, TRUE);
+ gtk_paned_set_position (GTK_PANED (hpaned1), 400);
+
+ scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_show (scrolledwindow2);
+ gtk_paned_pack1 (GTK_PANED (hpaned1), scrolledwindow2, FALSE, TRUE);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_SHADOW_IN);
+
+ textview2 = gtk_text_view_new ();
+ gtk_widget_show (textview2);
+ gtk_container_add (GTK_CONTAINER (scrolledwindow2), textview2);
+
+ fixed1 = gtk_fixed_new ();
+ gtk_widget_show (fixed1);
+ gtk_paned_pack2 (GTK_PANED (hpaned1), fixed1, TRUE, TRUE);
+
+ label1 = gtk_label_new (_("Registres :"));
+ gtk_widget_show (label1);
+ gtk_fixed_put (GTK_FIXED (fixed1), label1, 16, 48);
+ gtk_widget_set_size_request (label1, 128, 16);
+ gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
+
+ button2 = gtk_button_new ();
+ gtk_widget_show (button2);
+ gtk_fixed_put (GTK_FIXED (fixed1), button2, 80, 8);
+ gtk_widget_set_size_request (button2, 62, 29);
+
+ image1 = gtk_image_new_from_stock ("gtk-media-play", GTK_ICON_SIZE_BUTTON);
+ gtk_widget_show (image1);
+ gtk_container_add (GTK_CONTAINER (button2), image1);
+
+ button1 = gtk_button_new_with_mnemonic (_("Run"));
+ gtk_widget_show (button1);
+ gtk_fixed_put (GTK_FIXED (fixed1), button1, 8, 8);
+ gtk_widget_set_size_request (button1, 62, 29);
+
+ table1 = gtk_table_new (9, 2, FALSE);
+ gtk_widget_show (table1);
+ gtk_fixed_put (GTK_FIXED (fixed1), table1, 8, 64);
+ gtk_widget_set_size_request (table1, 160, 176);
+ gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
+
+ label3 = gtk_label_new (_("eax :"));
+ gtk_widget_show (label3);
+ gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);
+
+ label4 = gtk_label_new (_("ebx :"));
+ gtk_widget_show (label4);
+ gtk_table_attach (GTK_TABLE (table1), label4, 0, 1, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5);
+
+ label5 = gtk_label_new (_("ecx :"));
+ gtk_widget_show (label5);
+ gtk_table_attach (GTK_TABLE (table1), label5, 0, 1, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label5), 0, 0.5);
+
+ label6 = gtk_label_new (_("edx :"));
+ gtk_widget_show (label6);
+ gtk_table_attach (GTK_TABLE (table1), label6, 0, 1, 3, 4,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label6), 0, 0.5);
+
+ label7 = gtk_label_new (_("esp :"));
+ gtk_widget_show (label7);
+ gtk_table_attach (GTK_TABLE (table1), label7, 0, 1, 4, 5,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label7), 0, 0.5);
+
+ label8 = gtk_label_new (_("ebp :"));
+ gtk_widget_show (label8);
+ gtk_table_attach (GTK_TABLE (table1), label8, 0, 1, 5, 6,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label8), 0, 0.5);
+
+ label9 = gtk_label_new (_("esi :"));
+ gtk_widget_show (label9);
+ gtk_table_attach (GTK_TABLE (table1), label9, 0, 1, 6, 7,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label9), 0, 0.5);
+
+ label10 = gtk_label_new (_("edi :"));
+ gtk_widget_show (label10);
+ gtk_table_attach (GTK_TABLE (table1), label10, 0, 1, 7, 8,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label10), 0, 0.5);
+
+ label11 = gtk_label_new (_("eip :"));
+ gtk_widget_show (label11);
+ gtk_table_attach (GTK_TABLE (table1), label11, 0, 1, 8, 9,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label11), 0, 0.5);
+
+ label12 = gtk_label_new (_("0x00000000"));
+ gtk_widget_show (label12);
+ gtk_table_attach (GTK_TABLE (table1), label12, 1, 2, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label12), 0, 0.5);
+
+ lbl_eax = label12;
+
+ label14 = gtk_label_new (_("0x00000000"));
+ gtk_widget_show (label14);
+ gtk_table_attach (GTK_TABLE (table1), label14, 1, 2, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label14), 0, 0.5);
+
+ lbl_ebx = label14;
+
+ label15 = gtk_label_new (_("0x00000000"));
+ gtk_widget_show (label15);
+ gtk_table_attach (GTK_TABLE (table1), label15, 1, 2, 3, 4,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label15), 0, 0.5);
+
+ lbl_ecx = label15;
+
+ label16 = gtk_label_new (_("0x00000000"));
+ gtk_widget_show (label16);
+ gtk_table_attach (GTK_TABLE (table1), label16, 1, 2, 4, 5,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label16), 0, 0.5);
+
+ lbl_edx = label16;
+
+ label17 = gtk_label_new (_("0x00000000"));
+ gtk_widget_show (label17);
+ gtk_table_attach (GTK_TABLE (table1), label17, 1, 2, 5, 6,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label17), 0, 0.5);
+
+ label18 = gtk_label_new (_("0x00000000"));
+ gtk_widget_show (label18);
+ gtk_table_attach (GTK_TABLE (table1), label18, 1, 2, 6, 7,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label18), 0, 0.5);
+
+ label19 = gtk_label_new (_("0x00000000"));
+ gtk_widget_show (label19);
+ gtk_table_attach (GTK_TABLE (table1), label19, 1, 2, 7, 8,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label19), 0, 0.5);
+
+ label20 = gtk_label_new (_("0x00000000"));
+ gtk_widget_show (label20);
+ gtk_table_attach (GTK_TABLE (table1), label20, 1, 2, 8, 9,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label20), 0, 0.5);
+
+ label21 = gtk_label_new (_("0x00000000"));
+ gtk_widget_show (label21);
+ gtk_table_attach (GTK_TABLE (table1), label21, 1, 2, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label21), 0, 0.5);
+
+ scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_show (scrolledwindow1);
+ gtk_paned_pack2 (GTK_PANED (vpaned1), scrolledwindow1, TRUE, TRUE);
+
+ textview1 = gtk_text_view_new ();
+ gtk_widget_show (textview1);
+ gtk_container_add (GTK_CONTAINER (scrolledwindow1), textview1);
+
+ statusbar1 = gtk_statusbar_new ();
+ gtk_widget_show (statusbar1);
+ gtk_box_pack_start (GTK_BOX (vbox1), statusbar1, FALSE, FALSE, 0);
+
+
+
+
+
+
+
+
+ g_signal_connect ((gpointer) button1, "clicked",
+ G_CALLBACK (on_button1_clicked),
+ textview1);
+
+
+
+
+
+ g_signal_connect ((gpointer) button2, "clicked",
+ G_CALLBACK (on_button2_clicked),
+ NULL);
+
+
+
+
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : widget = fenêtre de l'éditeur de préférences. *
+* data = adresse non utilisée ici. *
+* *
+* Description : Quitte le programme en sortie de la boucle de GTK. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void destroy_editor(GtkWidget *widget, gpointer data)
+{
+ gtk_main_quit();
+
+}
+
+
+
+
+
+
+
+