Update sdb and capstone

This commit is contained in:
pancake 2017-03-13 14:59:00 +01:00
parent d301ff28b4
commit 9a4a014e3c
8 changed files with 60 additions and 51 deletions

View File

@ -25,6 +25,7 @@ typedef char* (*DupValue)(void *);
typedef size_t (*CalcSize)(void *);
typedef ut32 (*HashFunction)(const char*);
typedef int (*ListComparator)(const char *a, const char *b);
typedef bool (*HtForeachCallback)(void *user, const char *k, void *v);
/** ht **/
@ -66,4 +67,6 @@ bool ht_delete(SdbHash* ht, const char* key);
// Find the value corresponding to the matching key.
void* ht_find(SdbHash* ht, const char* key, bool* found);
HtKv* ht_find_kv(SdbHash* ht, const char* key, bool* found);
void ht_foreach(SdbHash *ht, HtForeachCallback cb, void *user);
SdbList* ht_foreach_list(SdbHash *ht, bool sorted);
#endif // __HT_H

View File

@ -16,6 +16,9 @@ extern "C" {
#include "cdb_make.h"
#include "sdb_version.h"
#undef r_offsetof
#define r_offsetof(type, member) ((unsigned long) &((type*)0)->member)
/* Key value sizes */
#define SDB_MIN_VALUE 1
#define SDB_MAX_VALUE 0xffffff

View File

@ -41,14 +41,10 @@
#endif
#include <inttypes.h>
#if __CYGWIN__
#define HAVE_MMAN 1
#define ULLFMT "ll"
#elif __SDB_WINDOWS__
#if __SDB_WINDOWS__ && !__CYGWIN__
#define HAVE_MMAN 0
#define ULLFMT "I64"
#else
#define ULLFMT "ll"
#define HAVE_MMAN 1
#endif

View File

@ -23,9 +23,9 @@ CS_PATCHES=0
else
CS_TAR=
CS_URL=$(GIT_PREFIX)github.com/aquynh/capstone.git
CS_UPD=20170227
CS_UPD=20170313
CS_BRA=next
CS_TIP=5b84c691784b5f0adc3c100d6ec5d5bb71ec8532
CS_TIP=f7a3cc25965e4d7d4f3488394b24f1d4650de905
# REVERT THIS COMMIT BECAUSE ITS WRONG
CS_REV=
CS_PATCHES=1

View File

@ -11,7 +11,9 @@
SDB_API char *sdb_json_get (Sdb *s, const char *k, const char *p, ut32 *cas) {
Rangstr rs;
char *u, *v = sdb_get (s, k, cas);
if (!v) return NULL;
if (!v) {
return NULL;
}
rs = json_get (v, p);
u = rangstr_dup (&rs);
free (v);
@ -61,7 +63,7 @@ static int findkey(Rangstr *rs) {
return -1;
}
static bool isstring (const char *s) {
static bool isstring(const char *s) {
if (!strcmp (s, "true")) {
return false;
}
@ -106,7 +108,7 @@ SDB_API bool sdb_json_set (Sdb *s, const char *k, const char *p, const char *v,
b = malloc (p_len + v_len + 8);
if (b) {
int is_str = isstring (v);
const char *q = is_str ? "\"" : "";
const char *q = is_str? "\"": "";
sprintf (b, "{\"%s\":%s%s%s}", p, q, v, q);
#if 0
/* disabled because it memleaks */
@ -129,7 +131,7 @@ SDB_API bool sdb_json_set (Sdb *s, const char *k, const char *p, const char *v,
char *b = malloc (b_len);
if (b) {
int curlen, is_str = isstring (v);
const char *q = is_str?"\"":"";
const char *q = is_str? "\"": "";
const char *e = ""; // XX: or comma
if (js[0] && js[1] != '}') {
e = ",";
@ -143,8 +145,8 @@ SDB_API bool sdb_json_set (Sdb *s, const char *k, const char *p, const char *v,
}
// invalid json?
return false;
}
#define WLEN(x) (int)(size_t)(end[x]-beg[x])
}
#define WLEN(x) (int) (size_t) (end[x] - beg[x])
beg[0] = js;
end[0] = rs.p + rs.f;
@ -188,7 +190,7 @@ SDB_API bool sdb_json_set (Sdb *s, const char *k, const char *p, const char *v,
idx += len[1];
if (is_str) {
// TODO: add quotes
if (beg[2][0]!='"') {
if (beg[2][0] != '"') {
str[idx] = '"';
idx++;
}
@ -206,14 +208,14 @@ SDB_API bool sdb_json_set (Sdb *s, const char *k, const char *p, const char *v,
rs.f -= 2;
kidx = findkey (&rs);
len[0] = R_MAX (1, kidx - 1);
if (kidx == 1){
if (kidx == 1) {
if (beg[2][0] == '"') {
beg[2]++;
}
beg[2]++;
len[2]--;
}
str = malloc (len[0] + len[2]+1);
str = malloc (len[0] + len[2] + 1);
if (!str) {
return false;
}
@ -228,18 +230,18 @@ SDB_API bool sdb_json_set (Sdb *s, const char *k, const char *p, const char *v,
return true;
}
SDB_API const char *sdb_json_format(SdbJsonString* s, const char *fmt, ...) {
SDB_API const char *sdb_json_format(SdbJsonString *s, const char *fmt, ...) {
char *arg_s, *x, tmp[128];
ut64 arg_l;
int i, arg_i;
float arg_f;
va_list ap;
#define JSONSTR_ALLOCATE(y) \
if (s->len+y>s->blen) {\
#define JSONSTR_ALLOCATE(y)\
if (s->len + y > s->blen) {\
s->blen *= 2;\
x = realloc (s->buf, s->blen);\
if (!x) { \
va_end (ap); \
if (!x) {\
va_end (ap);\
return NULL;\
}\
s->buf = x;\
@ -274,14 +276,14 @@ SDB_API const char *sdb_json_format(SdbJsonString* s, const char *fmt, ...) {
JSONSTR_ALLOCATE (32);
arg_f = va_arg (ap, double);
snprintf (tmp, sizeof (tmp), "%f", arg_f);
memcpy (s->buf+s->len, tmp, strlen (tmp));
memcpy (s->buf + s->len, tmp, strlen (tmp));
s->len += strlen (tmp);
break;
case 'l':
JSONSTR_ALLOCATE (32);
arg_l = va_arg (ap, ut64);
snprintf (tmp, sizeof (tmp), "0x%"ULLFMT"x", arg_l);
memcpy (s->buf+s->len, tmp, strlen (tmp));
snprintf (tmp, sizeof (tmp), "0x%"ULLFMT "x", arg_l);
memcpy (s->buf + s->len, tmp, strlen (tmp));
s->len += strlen (tmp);
break;
case 'd':
@ -289,16 +291,17 @@ SDB_API const char *sdb_json_format(SdbJsonString* s, const char *fmt, ...) {
JSONSTR_ALLOCATE (32);
arg_i = va_arg (ap, int);
snprintf (tmp, sizeof (tmp), "%d", arg_i);
memcpy (s->buf+s->len, tmp, strlen (tmp));
memcpy (s->buf + s->len, tmp, strlen (tmp));
s->len += strlen (tmp);
break;
case 's':
arg_s = va_arg (ap, char *);
JSONSTR_ALLOCATE (strlen (arg_s)+3);
JSONSTR_ALLOCATE (strlen (arg_s) + 3);
s->buf[s->len++] = '"';
for (i=0; arg_s[i]; i++) {
if (arg_s[i]=='"')
for (i = 0; arg_s[i]; i++) {
if (arg_s[i] == '"') {
s->buf[s->len++] = '\\';
}
s->buf[s->len++] = arg_s[i];
}
s->buf[s->len++] = '"';
@ -316,7 +319,9 @@ SDB_API const char *sdb_json_format(SdbJsonString* s, const char *fmt, ...) {
#if 0
int main () {
SdbJsonString s = {0};
SdbJsonString s = {
0
};
sdb_json_format (&s, "[{%s:%d},%b]", "Hello \"world\"", 1024, 3);
printf ("%s\n", sdb_json_format (&s, 0));
sdb_json_format_free (&s);

View File

@ -112,7 +112,7 @@ static char *stdin_slurp(int *sz) {
if (!*next) {
next = NULL;
} else {
// continue;
// continue;
}
} else {
next = NULL;
@ -157,9 +157,11 @@ static void synchronize(int sig UNUSED) {
}
#endif
static int sdb_grep_dump(const char *db, int fmt, bool grep,
const char *expgrep) {
const char *expgrep) {
char *v;
char k[SDB_MAX_KEY] = {0};
char k[SDB_MAX_KEY] = {
0
};
const char *comma = "";
Sdb *s = sdb_new (NULL, db, 0);
if (!s) {
@ -180,7 +182,7 @@ static int sdb_grep_dump(const char *db, int fmt, bool grep,
printf ("%s\"%s\":%s", comma, k, v);
} else if (sdb_isnum (v)) {
printf ("%s\"%s\":%llu", comma, k, sdb_atoi (v));
} else if (*v=='{' || *v=='[') {
} else if (*v == '{' || *v == '[') {
printf ("%s\"%s\":%s", comma, k, v);
} else {
printf ("%s\"%s\":\"%s\"", comma, k, v);
@ -189,7 +191,7 @@ static int sdb_grep_dump(const char *db, int fmt, bool grep,
break;
case MODE_ZERO:
printf ("%s=%s", k, v);
fwrite ("", 1,1, stdout);
fwrite ("", 1, 1, stdout);
break;
default:
printf ("%s=%s\n", k, v);
@ -228,7 +230,7 @@ static int insertkeys(Sdb *s, const char **args, int nargs, int mode) {
break;
case '=':
if (strchr (args[i], '=')) {
char *v, *kv = (char *)strdup (args[i]);
char *v, *kv = (char *) strdup (args[i]);
v = strchr (kv, '=');
if (v) {
*v++ = 0;
@ -252,7 +254,7 @@ static int createdb(const char *f, const char **args, int nargs) {
}
insertkeys (s, args, nargs, '=');
sdb_config (s, options);
for (;(line = stdin_slurp (NULL));) {
for (; (line = stdin_slurp (NULL));) {
if ((eq = strchr (line, '='))) {
*eq++ = 0;
sdb_disk_insert (s, line, eq);
@ -266,7 +268,7 @@ static int createdb(const char *f, const char **args, int nargs) {
static int showusage(int o) {
printf ("usage: sdb [-0cdehjJv|-D A B] [-|db] "
"[.file]|[-=]|[-+][(idx)key[:json|=value] ..]\n");
if (o==2) {
if (o == 2) {
printf (" -0 terminate results with \\x00\n"
" -c count the number of keys database\n"
" -d decode base64 from stdin\n"
@ -282,7 +284,7 @@ static int showusage(int o) {
}
static int showversion(void) {
printf ("sdb "SDB_VERSION"\n");
printf ("sdb "SDB_VERSION "\n");
fflush (stdout);
return 0;
}
@ -308,7 +310,7 @@ static int jsonIndent() {
static int base64encode() {
char *out;
int len = 0;
ut8 *in = (ut8*)stdin_slurp (&len);
ut8 *in = (ut8 *) stdin_slurp (&len);
if (!in) {
return 0;
}
@ -326,7 +328,7 @@ static int base64encode() {
static int base64decode() {
ut8 *out;
int len, ret = 1;
char *in = (char*)stdin_slurp (&len);
char *in = (char *) stdin_slurp (&len);
if (in) {
out = sdb_decode (in, &len);
if (out) {
@ -341,10 +343,12 @@ static int base64decode() {
return ret;
}
static int dbdiff (const char *a, const char *b) {
static int dbdiff(const char *a, const char *b) {
int n = 0;
char *v;
char k[SDB_MAX_KEY] = {0};
char k[SDB_MAX_KEY] = {
0
};
const char *v2;
Sdb *A = sdb_new (NULL, a, 0);
Sdb *B = sdb_new (NULL, b, 0);
@ -426,7 +430,7 @@ int main(int argc, const char **argv) {
return showusage (1);
}
break;
case 'c': return (argc < 3)? showusage (1) : showcount (argv[2]);
case 'c': return (argc < 3)? showusage (1): showcount (argv[2]);
case 'v': return showversion ();
case 'h': return showusage (2);
case 'e': return base64encode ();
@ -440,7 +444,7 @@ int main(int argc, const char **argv) {
if (argc > 2) {
return sdb_dump (argv[db0 + 1], MODE_JSON);
}
return jsonIndent();
return jsonIndent ();
default:
eprintf ("Invalid flag %s\n", arg);
break;
@ -478,7 +482,7 @@ int main(int argc, const char **argv) {
if (kvs < argc) {
save |= insertkeys (s, argv + argi + 2, argc - kvs, '-');
}
for (;(line = stdin_slurp (NULL));) {
for (; (line = stdin_slurp (NULL));) {
save |= sdb_query (s, line);
if (fmt) {
fflush (stdout);

View File

@ -32,8 +32,10 @@ extern "C" {
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
extern void *__cdecl _aligned_malloc(size_t, size_t);
extern __attribute__((dllimport)) void *__cdecl _aligned_malloc(size_t, size_t);
extern char *strdup (const char *);
#undef r_offsetof
#define r_offsetof(type, member) ((unsigned long) (ut64)&((type*)0)->member)
//#define SDB_MODE 0
#define SDB_MODE _S_IWRITE | _S_IREAD
#else

View File

@ -41,14 +41,10 @@
#endif
#include <inttypes.h>
#if __CYGWIN__
#define HAVE_MMAN 1
#define ULLFMT "ll"
#elif __SDB_WINDOWS__
#if __SDB_WINDOWS__ && !__CYGWIN__
#define HAVE_MMAN 0
#define ULLFMT "I64"
#else
#define ULLFMT "ll"
#define HAVE_MMAN 1
#endif