From 54176fb2c008a7ea00a07f4baa89db922f489b33 Mon Sep 17 00:00:00 2001 From: pancake Date: Sat, 11 Feb 2017 12:50:38 +0100 Subject: [PATCH] Update spp and build it with -fPIC --- libr/bin/format/objc/mach0_classes.c | 25 +++++++------------------ libr/bin/p/bin_mach0.c | 2 +- shlr/Makefile | 2 +- shlr/spp/p/spp.h | 4 ++-- shlr/spp/r_api.h | 4 ++-- shlr/spp/spp.c | 2 +- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git a/libr/bin/format/objc/mach0_classes.c b/libr/bin/format/objc/mach0_classes.c index f1e818644b..574271d89e 100644 --- a/libr/bin/format/objc/mach0_classes.c +++ b/libr/bin/format/objc/mach0_classes.c @@ -81,7 +81,6 @@ struct MACH0_(SObjcPropertyList) { /* struct SObjcProperty first; These structures follow inline */ }; -/////////////////////////////////////////////////////////////////////////////// static mach0_ut get_pointer(mach0_ut p, ut32 *offset, ut32 *left, RBinFile *arch); static void copy_sym_name_with_namespace(char *class_name, char *read_name, RBinSymbol *sym); static void get_ivar_list_t(mach0_ut p, RBinFile *arch, RBinClass *klass); @@ -92,17 +91,16 @@ static void get_class_ro_t(mach0_ut p, RBinFile *arch, ut32 *is_meta_class, RBin static void get_class_t(mach0_ut p, RBinFile *arch, RBinClass *klass, bool dupe); static void __r_bin_class_free(RBinClass *p); -static int is_thumb(RBinFile *arch) { +static bool is_thumb(RBinFile *arch) { struct MACH0_(obj_t) *bin = (struct MACH0_(obj_t) *)arch->o->bin_obj; if (bin->hdr.cputype == 12) { if (bin->hdr.cpusubtype == 9) { - return 1; + return true; } } - return 0; + return false; } -/////////////////////////////////////////////////////////////////////////////// static mach0_ut get_pointer(mach0_ut p, ut32 *offset, ut32 *left, RBinFile *arch) { mach0_ut r; mach0_ut addr; @@ -147,7 +145,6 @@ static mach0_ut get_pointer(mach0_ut p, ut32 *offset, ut32 *left, RBinFile *arch return 0; } -/////////////////////////////////////////////////////////////////////////////// static void copy_sym_name_with_namespace(char *class_name, char *read_name, RBinSymbol *sym) { if (!class_name) { class_name = ""; @@ -156,7 +153,6 @@ static void copy_sym_name_with_namespace(char *class_name, char *read_name, RBin sym->name = strdup (read_name); } -/////////////////////////////////////////////////////////////////////////////// static void get_ivar_list_t(mach0_ut p, RBinFile *arch, RBinClass *klass) { struct MACH0_(SIVarList) il; struct MACH0_(SIVar) i; @@ -598,9 +594,7 @@ static void get_method_list_t(mach0_ut p, RBinFile *arch, char *class_name, RBin } #endif method->vaddr = m.imp; - method->type = is_static - ? "FUNC" - : "METH"; + method->type = is_static ? "FUNC" : "METH"; if (is_thumb (arch)) { if (method->vaddr & 1) { method->vaddr >>= 1; @@ -640,7 +634,6 @@ static void get_protocol_list_t(mach0_ut p, RBinFile *arch, RBinClass *klass) { if (!(r = get_pointer (p, &offset, &left, arch))) { return; } - if (r + left < r || r + sizeof (struct MACH0_(SProtocolList)) < r) { return; } @@ -924,7 +917,6 @@ static mach0_ut get_isa_value() { return 0; } -/////////////////////////////////////////////////////////////////////////////// static void get_class_t(mach0_ut p, RBinFile *arch, RBinClass *klass, bool dupe) { struct MACH0_(SClass) c = { 0 }; const int size = sizeof (struct MACH0_(SClass)); @@ -940,7 +932,6 @@ static void get_class_t(mach0_ut p, RBinFile *arch, RBinClass *klass, bool dupe) return; } bigendian = arch->o->info->big_endian; - if (!(r = get_pointer (p, &offset, &left, arch))) { return; } @@ -953,7 +944,6 @@ static void get_class_t(mach0_ut p, RBinFile *arch, RBinClass *klass, bool dupe) if (r + size > arch->size) { return; } - if (left < size) { eprintf ("Cannot parse obj class info out of bounds\n"); return; @@ -1061,7 +1051,8 @@ RList *MACH0_(parse_classes)(RBinFile *arch) { bool is_found = false; mach0_ut p = 0; ut32 left = 0; - int len, paddr; + int len; + ut64 paddr; bool bigendian; ut8 pp[sizeof (mach0_ut)] = {0}; @@ -1071,7 +1062,7 @@ RList *MACH0_(parse_classes)(RBinFile *arch) { bigendian = obj->info->big_endian; /* check if it's Swift */ - //ret = parse_swift_classes (arch); + // ret = parse_swift_classes (arch); // searching of section with name __objc_classlist if (!(sctns = r_bin_plugin_mach.sections (arch))) { @@ -1112,13 +1103,11 @@ RList *MACH0_(parse_classes)(RBinFile *arch) { // eprintf ("RBinClass allocation error\n"); goto get_classes_error; } - if (!(klass->methods = r_list_new ())) { // retain just for debug // eprintf ("RList allocation error\n"); goto get_classes_error; } - if (!(klass->fields = r_list_new ())) { // retain just for debug // eprintf ("RList allocation error\n"); diff --git a/libr/bin/p/bin_mach0.c b/libr/bin/p/bin_mach0.c index b8556fa524..07acb0d036 100644 --- a/libr/bin/p/bin_mach0.c +++ b/libr/bin/p/bin_mach0.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2016 - pancake */ +/* radare - LGPL - Copyright 2009-2017 - pancake */ #include #include diff --git a/shlr/Makefile b/shlr/Makefile index 3b15cc994f..ab26469baa 100644 --- a/shlr/Makefile +++ b/shlr/Makefile @@ -291,6 +291,6 @@ spp-sync sync-spp: git add spp spp: spp-sync - cd spp ; $(MAKE) + CFLAGS=-fPIC $(MAKE) -C spp .PHONY: spp diff --git a/shlr/spp/p/spp.h b/shlr/spp/p/spp.h index 6bc4260f9b..b7266eee1f 100644 --- a/shlr/spp/p/spp.h +++ b/shlr/spp/p/spp.h @@ -131,7 +131,7 @@ TAG_CALLBACK(spp_trace) { char b[1024]; if (!echo[ifl]) return 0; - snprintf(b, 1023, "echo '%s' >&2", buf); + snprintf(b, 1023, "echo '%s' >&2 ", buf); system(b); return 0; } @@ -199,7 +199,7 @@ TAG_CALLBACK(spp_include) TAG_CALLBACK(spp_if) { char *var = spp_var_get(buf); - echo[ifl + 1] = (var && *var!='0' && *var != '\0')? 1: 0; + echo[ifl + 1] = (var && *var != '0' && *var != '\0') ? 1 : 0; return 1; } diff --git a/shlr/spp/r_api.h b/shlr/spp/r_api.h index dd773e804c..4414bfeadf 100644 --- a/shlr/spp/r_api.h +++ b/shlr/spp/r_api.h @@ -17,11 +17,11 @@ #define __BSD__ 1 #define __UNIX__ 1 #endif -#if _WIN32 || __CYGWIN__ || MINGW32 +#if __WIN32__ || __CYGWIN__ || MINGW32 #define __addr_t_defined #include #endif -#if _WIN32 || MINGW32 && !__CYGWIN__ +#if __WIN32__ || MINGW32 && !__CYGWIN__ #include typedef int socklen_t; #undef USE_SOCKETS diff --git a/shlr/spp/spp.c b/shlr/spp/spp.c index a77768bd39..49578457c9 100644 --- a/shlr/spp/spp.c +++ b/shlr/spp/spp.c @@ -216,7 +216,7 @@ retry: if (buf[0] == '\n' && printed) { buf++; } - D printf (" ==> 2.1: continue(%s)\n", ptr2 + delta); + D printf (" ==> 2.1: continue(%s)\n", buf); goto retry; } else { do_fputs (out, "\n");