* Fix build of r_magic on !BSD (strlcpy)

* Initial import of sys/ui
This commit is contained in:
pancake 2011-09-10 20:08:25 +02:00
parent df72d33e4e
commit 3fc44b6e6a
7 changed files with 229 additions and 9 deletions

View file

@ -202,7 +202,7 @@ typedef struct r_bin_create_t {
static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, int datalen) {
ut32 filesize, codeva, datava;
ut32 ncmds, cmdsize, magiclen, headerlen;
ut32 ncmds, cmdsize, magiclen;
ut32 p_codefsz, p_codeva, p_codesz, p_codepa;
ut32 p_datafsz, p_datava, p_datasz, p_datapa;
ut32 p_cmdsize, p_entry, p_tmp;
@ -327,15 +327,15 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data,
Z (16 * sizeof (ut32));
}
headerlen = buf->length - magiclen;
cmdsize = buf->length - magiclen;
codeva = buf->length + baddr;
datava = buf->length + codelen + baddr;
W (p_entry, &codeva, 4); // set PC
/* fill header variables */
W (p_cmdsize, &headerlen, 4);
filesize = magiclen + headerlen + codelen + datalen;
W (p_cmdsize, &cmdsize, 4);
filesize = magiclen + cmdsize + codelen + datalen;
// TEXT SEGMENT //
W (p_codefsz, &filesize, 4);
W (p_codeva, &codeva, 4);

View file

@ -233,8 +233,8 @@ file_pipe2file(struct r_magic_set *ms, int fd, const void *startbuf,
char buf[4096];
int r, tfd;
(void)strlcpy(buf, "/tmp/file.XXXXXX", sizeof buf);
tfd = mkstemp(buf);
strncpy (buf, "/tmp/file.XXXXXX", sizeof (buf));
tfd = mkstemp (buf);
r = errno;
(void)unlink(buf);
errno = r;

View file

@ -247,9 +247,11 @@ file_fsmagic(struct r_magic_set *ms, const char *fn, struct stat *sb)
return -1;
return 1;
}
(void)strlcpy(buf2, fn, sizeof buf2); /* take dir part */
//(void)strlcpy(buf2, fn, sizeof buf2); /* take dir part */
strncpy (buf2, fn, sizeof (buf2));
buf2[tmp - fn + 1] = '\0';
(void)strlcat(buf2, buf, sizeof buf2); /* plus (rel) link */
//(void)strlcat(buf2, buf, sizeof buf2); /* plus (rel) link */
strncpy (buf2, buf, sizeof (buf2));
tmp = buf2;
}
if (stat(tmp, &tstatbuf) < 0)

View file

@ -131,7 +131,7 @@ free_mlist(struct mlist *mlist)
for (ml = mlist->next; ml != mlist;) {
struct mlist *next = ml->next;
struct magic *mg = ml->magic;
struct r_magic *mg = ml->magic;
file_delmagic(mg, ml->mapped, ml->nmagic);
free(ml);
ml = next;

11
sys/ui/Makefile Normal file
View file

@ -0,0 +1,11 @@
all:
gcc -o r2-install r2-install.c `pkg-config --cflags --libs gtk+-2.0`
g:
gtkamlc --pkg gtk+-2.0 r2-install.gtkon
c:
gtkamlc --pkg gtk+-2.0 -C r2-install.gtkon
clean:
rm -f r2-install

189
sys/ui/r2-install.c Normal file
View file

@ -0,0 +1,189 @@
/* r2-install.c generated by valac 0.13.3.41-7d9f, the Vala compiler
* generated from r2-install.vala, do not modify */
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#define TYPE_MAIN (main_get_type ())
#define MAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN, Main))
#define MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN, MainClass))
#define IS_MAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN))
#define IS_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN))
#define MAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN, MainClass))
typedef struct _Main Main;
typedef struct _MainClass MainClass;
typedef struct _MainPrivate MainPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
struct _Main {
GtkWindow parent_instance;
MainPrivate * priv;
};
struct _MainClass {
GtkWindowClass parent_class;
};
static gpointer main_parent_class = NULL;
GType main_get_type (void) G_GNUC_CONST;
enum {
MAIN_DUMMY_PROPERTY
};
void main_main (gchar** args, int args_length1);
Main* main_new (void);
Main* main_construct (GType object_type);
static GObject * main_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
void main_main (gchar** args, int args_length1) {
Main* _tmp0_;
Main* _tmp1_;
Main* m;
gtk_init (&args_length1, &args);
_tmp0_ = main_new ();
_tmp1_ = g_object_ref_sink (_tmp0_);
m = _tmp1_;
gtk_widget_show_all ((GtkWidget*) m);
gtk_main ();
_g_object_unref0 (m);
}
int main (int argc, char ** argv) {
g_type_init ();
main_main (argv, argc);
return 0;
}
Main* main_construct (GType object_type) {
Main * self = NULL;
self = (Main*) g_object_new (object_type, NULL);
return self;
}
Main* main_new (void) {
return main_construct (TYPE_MAIN);
}
static GObject * main_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
GObject * obj;
GObjectClass * parent_class;
Main * self;
GtkVBox* _vbox0 = NULL;
GtkLabel* _label0 = NULL;
GtkHBox* _hbox0 = NULL;
GtkButton* _button0 = NULL;
GtkButton* _button1 = NULL;
GtkButton* _button2 = NULL;
GtkVBox* _tmp0_;
GtkVBox* _tmp1_;
GtkLabel* _tmp2_;
GtkLabel* _tmp3_;
GtkHBox* _tmp4_;
GtkHBox* _tmp5_;
GtkButton* _tmp6_;
GtkButton* _tmp7_;
GtkButton* _tmp8_;
GtkButton* _tmp9_;
GtkButton* _tmp10_;
GtkButton* _tmp11_;
GtkVBox* _tmp12_;
GtkLabel* _tmp13_;
GtkHBox* _tmp14_;
GtkButton* _tmp15_;
GtkHBox* _tmp16_;
GtkButton* _tmp17_;
GtkHBox* _tmp18_;
GtkButton* _tmp19_;
GtkVBox* _tmp20_;
GtkHBox* _tmp21_;
GtkVBox* _tmp22_;
parent_class = G_OBJECT_CLASS (main_parent_class);
obj = parent_class->constructor (type, n_construct_properties, construct_properties);
self = MAIN (obj);
_tmp0_ = (GtkVBox*) gtk_vbox_new (FALSE, 0);
_tmp1_ = g_object_ref_sink (_tmp0_);
_g_object_unref0 (_vbox0);
_vbox0 = _tmp1_;
_tmp2_ = (GtkLabel*) gtk_label_new ("hello world");
_tmp3_ = g_object_ref_sink (_tmp2_);
_g_object_unref0 (_label0);
_label0 = _tmp3_;
_tmp4_ = (GtkHBox*) gtk_hbox_new (FALSE, 0);
_tmp5_ = g_object_ref_sink (_tmp4_);
_g_object_unref0 (_hbox0);
_hbox0 = _tmp5_;
_tmp6_ = (GtkButton*) gtk_button_new_with_label ("Install");
_tmp7_ = g_object_ref_sink (_tmp6_);
_g_object_unref0 (_button0);
_button0 = _tmp7_;
_tmp8_ = (GtkButton*) gtk_button_new_with_label ("Update");
_tmp9_ = g_object_ref_sink (_tmp8_);
_g_object_unref0 (_button1);
_button1 = _tmp9_;
_tmp10_ = (GtkButton*) gtk_button_new_with_label ("Deinstall");
_tmp11_ = g_object_ref_sink (_tmp10_);
_g_object_unref0 (_button2);
_button2 = _tmp11_;
g_object_set ((GtkWindow*) self, "type", GTK_WINDOW_TOPLEVEL, NULL);
_tmp12_ = _vbox0;
_tmp13_ = _label0;
gtk_container_add ((GtkContainer*) _tmp12_, (GtkWidget*) _tmp13_);
_tmp14_ = _hbox0;
_tmp15_ = _button0;
gtk_container_add ((GtkContainer*) _tmp14_, (GtkWidget*) _tmp15_);
_tmp16_ = _hbox0;
_tmp17_ = _button1;
gtk_container_add ((GtkContainer*) _tmp16_, (GtkWidget*) _tmp17_);
_tmp18_ = _hbox0;
_tmp19_ = _button2;
gtk_container_add ((GtkContainer*) _tmp18_, (GtkWidget*) _tmp19_);
_tmp20_ = _vbox0;
_tmp21_ = _hbox0;
gtk_container_add ((GtkContainer*) _tmp20_, (GtkWidget*) _tmp21_);
_tmp22_ = _vbox0;
gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp22_);
_g_object_unref0 (_button2);
_g_object_unref0 (_button1);
_g_object_unref0 (_button0);
_g_object_unref0 (_hbox0);
_g_object_unref0 (_label0);
_g_object_unref0 (_vbox0);
return obj;
}
static void main_class_init (MainClass * klass) {
main_parent_class = g_type_class_peek_parent (klass);
G_OBJECT_CLASS (klass)->constructor = main_constructor;
}
static void main_instance_init (Main * self) {
}
GType main_get_type (void) {
static volatile gsize main_type_id__volatile = 0;
if (g_once_init_enter (&main_type_id__volatile)) {
static const GTypeInfo g_define_type_info = { sizeof (MainClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) main_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Main), 0, (GInstanceInitFunc) main_instance_init, NULL };
GType main_type_id;
main_type_id = g_type_register_static (GTK_TYPE_WINDOW, "Main", &g_define_type_info, 0);
g_once_init_leave (&main_type_id__volatile, main_type_id);
}
return main_type_id__volatile;
}

18
sys/ui/r2-install.gtkon Normal file
View file

@ -0,0 +1,18 @@
Window $Main using=Gtk {
VBox {
Label label="hello world";
HBox {
Button label="Install";
Button label="Update";
Button label="Deinstall";
}
}
-{
public static void main(string[] args) {
Gtk.init (ref args);
var m = new Main ();
m.show_all();
Gtk.main();
}
}-
}