Fix meson build and proper use of cgen ##build (#18920)

This commit is contained in:
pancake 2021-07-21 17:22:39 +02:00 committed by GitHub
parent 0dbcdc8945
commit 3c416c54cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 120 additions and 58 deletions

View File

@ -10,7 +10,7 @@ extern SdbGperf gperf_cc_arm_16;
extern SdbGperf gperf_cc_arm_32;
extern SdbGperf gperf_cc_arm_64;
extern SdbGperf gperf_cc_avr_8;
extern SdbGperf gperf_cc_hexagon_32;
// extern SdbGperf gperf_cc_hexagon_32;
extern SdbGperf gperf_cc_m68k_32;
extern SdbGperf gperf_cc_mips_32;
extern SdbGperf gperf_cc_mips_64;
@ -23,7 +23,7 @@ extern SdbGperf gperf_cc_v850_32;
extern SdbGperf gperf_cc_x86_16;
extern SdbGperf gperf_cc_x86_32;
extern SdbGperf gperf_cc_x86_64;
extern SdbGperf gperf_cc_xtensa_32;
//extern SdbGperf gperf_cc_xtensa_32;
extern SdbGperf gperf_spec;
extern SdbGperf gperf_types_16;
extern SdbGperf gperf_types_32;
@ -45,7 +45,7 @@ static const SdbGperf *gperfs_cc[] = {
&gperf_cc_arm_32,
&gperf_cc_arm_64,
&gperf_cc_avr_8,
&gperf_cc_hexagon_32,
// &gperf_cc_hexagon_32,
&gperf_cc_m68k_32,
&gperf_cc_mips_32,
&gperf_cc_mips_64,
@ -58,7 +58,7 @@ static const SdbGperf *gperfs_cc[] = {
&gperf_cc_x86_16,
&gperf_cc_x86_32,
&gperf_cc_x86_64,
&gperf_cc_xtensa_32,
// &gperf_cc_xtensa_32,
NULL
};
static const SdbGperf *gperfs_types[] = {
@ -79,13 +79,16 @@ static const SdbGperf *gperfs_types[] = {
R_API SdbGperf *r_anal_get_gperf_cc(const char *k) {
SdbGperf **gp = (SdbGperf**)gperfs_cc;
char *kk = strdup (k);
r_str_replace_char (kk, '_', '-');
while (*gp) {
SdbGperf *g = *gp;
if (!strcmp (k, g->name)) {
if (!strcmp (kk, g->name)) {
return *gp;
}
gp++;
}
free (kk);
return NULL;
}

View File

@ -10,7 +10,7 @@ extern SdbGperf gperf_z80;
extern SdbGperf gperf_6502;
extern SdbGperf gperf_i4004;
extern SdbGperf gperf_avr;
extern SdbGperf gperf_chip8;
//extern SdbGperf gperf_chip8;
extern SdbGperf gperf_i8080;
extern SdbGperf gperf_java;
extern SdbGperf gperf_lm32;
@ -37,7 +37,7 @@ static const SdbGperf *gperfs[] = {
&gperf_6502,
&gperf_i4004,
&gperf_avr,
&gperf_chip8,
// &gperf_chip8,
&gperf_i8080,
&gperf_java,
&gperf_lm32,

View File

@ -1,9 +1,6 @@
#ifndef _INCLUDE_CONFIG_H_
#define _INCLUDE_CONFIG_H_
#ifndef HAVE_GPERF
#define HAVE_GPERF 0
#endif
#define R_DEBUG 0
#define R_RTDEBUG 1
#define WANT_THREADS 1

View File

@ -730,10 +730,8 @@ R_API void r_core_anal_type_init(RCore *core) {
}
R_API void r_core_anal_cc_init(RCore *core) {
const char *dir_prefix = r_config_get (core->config, "dir.prefix");
const char *anal_arch = r_config_get (core->config, "anal.arch");
int bits = core->anal->bits;
Sdb *cc = core->anal->sdb_cc;
if (!anal_arch) {
return;
}
@ -748,13 +746,26 @@ R_API void r_core_anal_cc_init(RCore *core) {
sdb_merge (core->anal->sdb_cc, gd);
sdb_close (gd);
sdb_free (gd);
return;
}
#endif
{
// same as "tcc `arcc`"
char *s = r_reg_profile_to_cc (core->anal->reg);
if (s) {
if (!r_anal_cc_set (core->anal, s)) {
eprintf ("Warning: Invalid CC from reg profile.\n");
}
free (s);
} else {
eprintf ("Warning: Cannot derive CC from reg profile.\n");
}
}
#else
const char *dir_prefix = r_config_get (core->config, "dir.prefix");
char *dbpath = r_str_newf (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "cc-%s-%d.sdb"),
dir_prefix, anal_arch, bits);
char *dbhomepath = r_str_newf (R_JOIN_3_PATHS ("~", R2_HOME_SDB_FCNSIGN, "cc-%s-%d.sdb"),
anal_arch, bits);
Sdb *cc = core->anal->sdb_cc;
// Avoid sdb reloading
if (cc->path && (!strcmp (cc->path, dbpath) || !strcmp (cc->path, dbhomepath))) {
free (dbpath);
@ -788,6 +799,7 @@ R_API void r_core_anal_cc_init(RCore *core) {
}
free (dbpath);
free (dbhomepath);
#endif
}
static int bin_info(RCore *r, PJ *pj, int mode, ut64 laddr) {

View File

@ -4737,9 +4737,11 @@ static ut8 *decode_text(RCore *core, ut64 offset, size_t len, bool zeroend) {
size_t out_len = len * 10;
ut8 *data = out;
out = calloc (len, 10);
r_io_read_at (core->io, core->offset, data, len);
r_charset_encode_str (core->print->charset, out, out_len, data, len);
free (data);
if (out) {
r_io_read_at (core->io, core->offset, data, len);
r_charset_encode_str (core->print->charset, out, out_len, data, len);
free (data);
}
}
}
return out;
@ -6073,7 +6075,7 @@ static int cmd_print(void *data, const char *input) {
ut8 *data = malloc (len);
if (data) {
r_io_read_at (core->io, core->offset, data, len);
r_charset_encode_str (core->print->charset, out, out_len, data, len);
(void)r_charset_encode_str (core->print->charset, out, out_len, data, len);
r_print_string (core->print, core->offset,
out, len, R_PRINT_STRING_ZEROEND);
free (data);

View File

@ -2174,9 +2174,11 @@ static int cmd_write(void *data, const char *input) {
if (len > 0) {
size_t in_len = strlen (str + 1);
int max = core->print->charset->encode_maxkeylen;
int out_len = in_len * max;
ut8 *out = malloc (in_len * max); //suppose in len = out len TODO: change it
if (out) {
r_charset_decode_str (core->print->charset, out, in_len, (const unsigned char *) str + 1, in_len);
*out = 0;
r_charset_decode_str (core->print->charset, out, out_len, (const ut8*) str + 1, in_len);
w_handler_old (core, (const char *)out);
free (out);
}

View File

@ -14,6 +14,7 @@
#define WANT_THREADS @WANT_THREADS@
#define WANT_CAPSTONE @WANT_CAPSTONE@
#define HAVE_GPERF @HAVE_GPERF@
#if (HAVE_GPERF) == 1
#define HAVE_GPERF @HAVE_GPERF@
#else

View File

@ -81,8 +81,9 @@ else
@-if [ -f d/Makefile ] ; then (echo "DIR ${NAME}/d"; ${MAKE} -C d) ; fi
endif
$(OBJS): $(EXTRA_TARGETS)
ifeq ($(WITH_LIBS),1)
$(LIBSO): $(EXTRA_TARGETS) ${WFD} ${OBJS} ${SHARED_OBJ}
$(LIBSO): ${WFD} ${OBJS} ${SHARED_OBJ}
@for a in ${OBJS} ${SHARED_OBJ} ${SRC}; do \
do=0 ; [ ! -e "${LIBSO}" ] && do=1 ; \
test "$$a" -nt "${LIBSO}" && do=1 ; \

View File

@ -6,6 +6,30 @@ R2DEPS=r_util
OBJS=syscall.o ioports.o splugs.o
CFLAGS+=-D__UNIX__ -Wall
ifeq (${HAVE_GPERF},1)
OBJS+=d/darwin-arm-32.o
OBJS+=d/darwin-arm-64.o
OBJS+=d/darwin-x86-32.o
OBJS+=d/darwin-x86-64.o
OBJS+=d/dos-x86-16.o
OBJS+=d/freebsd-x86-32.o
OBJS+=d/ios-arm-32.o
OBJS+=d/ios-arm-64.o
OBJS+=d/ios-x86-32.o
OBJS+=d/linux-arm-32.o
OBJS+=d/linux-arm-64.o
OBJS+=d/linux-mips-32.o
OBJS+=d/linux-sparc-32.o
OBJS+=d/linux-x86-32.o
OBJS+=d/linux-x86-64.o
OBJS+=d/netbsd-x86-32.o
OBJS+=d/openbsd-x86-32.o
OBJS+=d/openbsd-x86-64.o
OBJS+=d/s110-arm-16.o
OBJS+=d/windows-x86-32.o
OBJS+=d/windows-x86-64.o
endif
EXTRA_TARGETS+=do
EXTRA_CLEAN=doclean

View File

@ -51,6 +51,7 @@ else
endif
test -f $@
${SDB} -t -C $@
$(CC) $(CFLAGS) -c `echo $@ | sed -e s,sdb,c,`
clean:
rm -f *.sdb

View File

@ -6,27 +6,27 @@
#include <r_syscall.h>
#if HAVE_GPERF
extern GdbGperf gperf_darwin_arm_32;
extern GdbGperf gperf_darwin_arm_64;
extern GdbGperf gperf_darwin_x86_32;
extern GdbGperf gperf_darwin_x86_64;
extern GdbGperf gperf_dos_x86_16;
extern GdbGperf gperf_freebsd_x86_32;
extern GdbGperf gperf_ios_arm_32;
extern GdbGperf gperf_ios_arm_64;
extern GdbGperf gperf_ios_x86_32;
extern GdbGperf gperf_linux_arm_32;
extern GdbGperf gperf_linux_arm_64;
extern GdbGperf gperf_linux_mips_32;
extern GdbGperf gperf_linux_sparc_32;
extern GdbGperf gperf_linux_x86_32;
extern GdbGperf gperf_linux_x86_64;
extern GdbGperf gperf_netbsd_x86_32;
extern GdbGperf gperf_openbsd_x86_32;
extern GdbGperf gperf_openbsd_x86_64;
extern GdbGperf gperf_s110_arm_16;
extern GdbGperf gperf_windows_x86_32;
extern GdbGperf gperf_windows_x86_64;
extern SdbGperf gperf_darwin_arm_32;
extern SdbGperf gperf_darwin_arm_64;
extern SdbGperf gperf_darwin_x86_32;
extern SdbGperf gperf_darwin_x86_64;
extern SdbGperf gperf_dos_x86_16;
extern SdbGperf gperf_freebsd_x86_32;
extern SdbGperf gperf_ios_arm_32;
extern SdbGperf gperf_ios_arm_64;
extern SdbGperf gperf_ios_x86_32;
extern SdbGperf gperf_linux_arm_32;
extern SdbGperf gperf_linux_arm_64;
extern SdbGperf gperf_linux_mips_32;
extern SdbGperf gperf_linux_sparc_32;
extern SdbGperf gperf_linux_x86_32;
extern SdbGperf gperf_linux_x86_64;
extern SdbGperf gperf_netbsd_x86_32;
extern SdbGperf gperf_openbsd_x86_32;
extern SdbGperf gperf_openbsd_x86_64;
extern SdbGperf gperf_s110_arm_16;
extern SdbGperf gperf_windows_x86_32;
extern SdbGperf gperf_windows_x86_64;
static const SdbGperf *gperfs[] = {
&gperf_darwin_arm_32,

View File

@ -73,6 +73,7 @@ endif
EXTRA_PRE+=spp_config
EXTRA_PRE+=charsets
EXTRA_TARGETS=$(EXTRA_PRE)
EXTRA_CLEAN=doclean
include ../rules.mk

View File

@ -62,8 +62,10 @@ R_API RList *r_charset_list(RCharset *ch) {
R_API RCharset *r_charset_new(void) {
RCharset *ch = R_NEW0 (RCharset);
ch->db = sdb_new0 ();
ch->db_char_to_hex = sdb_new0 ();
if (ch) {
ch->db = sdb_new0 ();
ch->db_char_to_hex = sdb_new0 ();
}
return ch;
}
@ -80,12 +82,14 @@ R_API void r_charset_close(RCharset *c) {
}
R_API bool r_charset_use(RCharset *c, const char *cf) {
r_return_val_if_fail (c && cf, false);
bool rc = false;
SdbGperf *gp = r_charset_get_gperf (cf);
if (gp) {
sdb_free (c->db);
c->db = sdb_new0 ();
if (sdb_open_gperf (c->db, gp) != -1) {
rc = r_charset_open (c, NULL);
r_sys_setenv ("RABIN2_CHARSET", cf);
rc = true;
}
@ -102,12 +106,14 @@ R_API bool r_charset_use(RCharset *c, const char *cf) {
}
R_API bool r_charset_open(RCharset *c, const char *cs) {
r_return_val_if_fail (c && cs, false);
sdb_reset (c->db);
sdb_open (c->db, cs);
r_return_val_if_fail (c, false);
if (cs) {
sdb_reset (c->db);
sdb_open (c->db, cs);
sdb_free (c->db_char_to_hex);
c->db_char_to_hex = sdb_new0 ();
sdb_free (c->db_char_to_hex);
c->db_char_to_hex = sdb_new0 ();
}
SdbListIter *iter;
SdbKv *kv;
@ -148,11 +154,14 @@ R_API RCharsetRune *r_charset_rune_new(const ut8 *ch, const ut8 *hx) {
}
R_API void r_charset_rune_free(RCharsetRune *c) {
free (c->ch);
free (c->hx);
free (c);
if (c) {
free (c->ch);
free (c->hx);
free (c);
}
}
#if 0
R_API RCharsetRune *add_rune(RCharsetRune *r, const ut8 *ch, const ut8 *hx) {
if (!r) {
r = r_charset_rune_new (ch, hx);
@ -183,6 +192,7 @@ R_API RCharsetRune *search_from_hex(RCharsetRune *r, const ut8 *hx) {
RCharsetRune *left = search_from_hex (r->left, hx);
return left? left: search_from_hex (r->right, hx);
}
#endif
R_API size_t r_charset_encode_str(RCharset *rc, ut8 *out, size_t out_len, const ut8 *in, size_t in_len) {
if (!rc->loaded) {
@ -192,6 +202,7 @@ R_API size_t r_charset_encode_str(RCharset *rc, ut8 *out, size_t out_len, const
char *o = (char*)out;
size_t i;
char *o_end = o + out_len;
bool fine = false;
for (i = 0; i < in_len && o < o_end; i++) {
ut8 ch_in = in[i];
snprintf (k, sizeof (k), "0x%02x", ch_in);
@ -199,17 +210,20 @@ R_API size_t r_charset_encode_str(RCharset *rc, ut8 *out, size_t out_len, const
const char *ret = r_str_get_fail (v, "?");
char *res = strdup (ret);
if (res) {
int reslen = strlen (res);
size_t reslen = strlen (res);
if (reslen >= o_end - o) {
break;
}
fine = true;
r_str_unescape (res);
r_str_ncpy (o, res, out_len - i);
free (res);
}
o += strlen (o);
}
if (!fine) {
return 0;
}
return o - (char*)out;
}
@ -226,10 +240,13 @@ R_API size_t r_charset_decode_str(RCharset *rc, ut8 *out, size_t out_len, const
size_t left = in_len - cur;
size_t toread = R_MIN (left + 1, maxkeylen);
char *str = calloc (toread + 128, 1);
if (!str) {
break;
}
r_str_ncpy (str, (char *)in + cur, toread);
bool found = false;
for (j = toread; cur < in_len && j > 0; j--) {
left = in_len - cur +1;
left = in_len - cur + 1;
toread = R_MIN (left, maxkeylen);
//zero terminate the string
str[j] = '\0';

View File

@ -1,5 +1,4 @@
# http://www.longpelaexpertise.com/toolsCode.php
0x00=\\x00
0x0d=\r
0x15=\n
0x21=!

View File

@ -1272,6 +1272,8 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
size_t len = r_charset_encode_str (p->charset, output, sizeof (output), input, 1);
if (len > 0) {
ch = *output;
} else {
ch = '?';
}
}
r_print_byte (p, "%c", j, ch);

View File

@ -348,10 +348,10 @@ userconf.set('BINDINGS', r2_bindings)
userconf.set10('HAVE_OPENSSL', use_sys_openssl)
userconf.set10('HAVE_LIBUV', use_libuv)
userconf.set10('HAVE_FORK', use_fork)
userconf.set10('HAVE_GPERF', get_option('sdb_cgen'))
userconf.set10('WANT_DYLINK', use_dylink)
userconf.set10('WANT_THREADS', get_option('want_threads'))
userconf.set10('WANT_CAPSTONE', get_option('want_capstone'))
userconf.set10('HAVE_GPERF', get_option('sdb_cgen'))
userconf.set10('HAVE_PTRACE', have_ptrace)
userconf.set10('USE_PTRACE_WRAP', use_ptrace_wrap)
userconf.set10('WITH_GPL', not get_option('nogpl'))

View File

@ -801,10 +801,10 @@ SDB_API bool sdb_foreach(Sdb* s, SdbForeachCallback cb, void *user) {
if (!s) {
return false;
}
s->depth++;
if (s->gp) {
return s->gp->foreach ((GperfForeachCallback)cb, user);
}
s->depth++;
bool result = sdb_foreach_cdb (s, cb, NULL, user);
if (!result) {
return sdb_foreach_end (s, false);

View File

@ -41,7 +41,7 @@ EXPECT=<<EOF
0x000019a8 c896 9381 4094 a495 8496 1500 0000 0000 ....@...........
\xc8\x96\x93\x81@\x94\xa4\x95\x84\x96\x15
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x000019a8 c896 9381 4094 a495 8496 1500 0000 0000 Hola_mundo......
0x000019a8 c896 9381 4094 a495 8496 1500 0000 0000 Hola_mundo.?????
Hola_mundo
EOF
RUN