Bump capstone, sdb and add node readme

This commit is contained in:
pancake 2015-03-31 01:31:35 +02:00
parent ddbffe4f9d
commit 35baae988e
8 changed files with 130 additions and 40 deletions

32
doc/node.js/README.md Normal file
View File

@ -0,0 +1,32 @@
Node.JS express based webserver
===============================
Author : pancake <pancake@nopcode.org>
Date: 2015-03-31
Description
-----------
This is the nodejs implementation of a websever
for radare2. This script can be executed from
inside r2 by using the following commnad:
> #!pipe node .
If you don't have any other .js handler (like duktape)
you can run it directly like this:
$ . index.js
From the shell you can run the script like this:
$ r2 -c '#!pipe node index.js' /bin/ls
Or just run it from nodejs:
$ node .
Or specify a different file to open
$ node . /bin/awk

View File

@ -204,6 +204,8 @@ int sdb_array_insert (Sdb* s, const char *key, int idx, const char *val, ut32 ca
int sdb_array_insert_num (Sdb* s, const char *key, int idx, ut64 val, ut32 cas);
int sdb_array_unset (Sdb* s, const char *key, int n, ut32 cas); // leaves empty bucket
int sdb_array_delete (Sdb* s, const char *key, int n, ut32 cas);
void sdb_array_sort (Sdb* s, const char *key, ut32 cas);
void sdb_array_sort_num (Sdb* s, const char *key, ut32 cas);
// set
int sdb_array_add (Sdb* s, const char *key, const char *val, ut32 cas);
int sdb_array_add_num (Sdb* s, const char *key, ut64 val, ut32 cas);

View File

@ -6,9 +6,9 @@ CS_VER=3.0
CS_TAR=http://capstone-engine.org/download/$(CS_VER)/capstone-$(CS_VER).tgz
CS_TAR=
CS_URL=https://www.github.com/aquynh/capstone.git
CS_UPD=20150327
CS_UPD=20150331
CS_BRA=next
CS_TIP=3a99bc697707cf9605fd79090b750c89dc1a5f0d
CS_TIP=87d754dc3acc21e44f0c6597bc6705902069677e
.PHONY: capstone-sync capstone-build all clean mrproper libgdbr libwind

View File

@ -37,8 +37,6 @@ EMCCFLAGS=-O2 -s EXPORTED_FUNCTIONS="['_sdb_querys','_sdb_new0']"
sdb.js: src/sdb-version.h
cd src ; emcc ${EMCCFLAGS} -I. -o ../sdb.js ${CFILES}
#json/api.c json/js0n.c json/json.c json/rangstr.c
clean:
rm -f src/sdb-version.h
cd src && ${MAKE} clean
@ -128,7 +126,6 @@ ifneq (${HAVE_VALA},)
cd ${VALADIR}/types && ${MAKE} symstall PFX=${PFX}
endif
# windows compiler prefix
WCP=i386-mingw32
WCP=i686-pc-mingw32
@ -137,5 +134,12 @@ w32: src/sdb-version.h
cd src ; \
${MAKE} OS=w32 WCP=${WCP} CC=${WCP}-gcc AR=${WCP}-ar RANLIB=${WCP}-ranlib sdb.exe
.PHONY: all ${VALADIR} clean dist w32
# ios toolchain
IOS_CC=$(shell xcrun --sdk iphoneos --find clang) -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) -arch armv7 -arch arm64
IOS_AR=$(shell xcrun --sdk iphoneos --find ar)
IOS_RL=$(shell xcrun --sdk iphoneos --find ranlib)
ios: src/sdb-version.h
${MAKE} OS=Darwin ARCH=arm CC="${IOS_CC}" AR="${IOS_AR}" RANLIB="${IOS_RL}" HAVE_VALA= all
.PHONY: all ${VALADIR} clean dist w32 ios
.PHONY: install-dirs install uninstall deinstall symstall

View File

@ -18,33 +18,33 @@ static const char *Aindexof(const char *str, int idx) {
return NULL;
}
static const char *Aconst_index(const char *str, int idx) {
int len = 0;
const char *n, *p = str;
for (len=0; ; len++) {
if (len == idx)
return p;
n = strchr (p, SDB_RS);
if (n) p = n+1;
else break;
static int astrcmp (const char *a, const char *b) {
register char va = *a;
register char vb = *b;
for (;;) {
if (va == '\0' || va == SDB_RS) {
if (vb == '\0' || vb == SDB_RS)
return 0;
return -1;
}
if (vb == '\0' || vb == SDB_RS)
return 1;
if (va != vb) return (va>vb)?1:-1;
va = *(++a);
vb = *(++b);
}
return NULL;
}
static int astrcmp (const char *a, const char *b) {
for (;;) {
if (*a == '\0' || *a == SDB_RS) {
if (*b == '\0' || *b == SDB_RS)
return 0;
return 1;
static inline int cstring_cmp(const void *a, const void *b) {
const char **va = (const char **)a;
const char **vb = (const char **)b;
return astrcmp(*va, *vb);
}
if (*b == '\0' || *b == SDB_RS)
return 1;
if (*a != *b) return 1;
a++;
b++;
}
return 1;
static inline int int_cmp(const void *a, const void *b) {
const int *va = (const int *)a;
const int *vb = (const int *)b;
return *va - *vb;
}
SDB_API ut64 sdb_array_get_num(Sdb *s, const char *key, int idx, ut32 *cas) {
@ -211,7 +211,7 @@ SDB_API int sdb_array_set(Sdb *s, const char *key, int idx, const char *val, ut3
//memcpy (nstr, str, lstr+1);
memcpy (nstr, str, diff);
memcpy (ptr, val, lval+1);
usr = Aconst_index (str, idx+1);
usr = Aindexof (str, idx+1);
if (usr) {
ptr[lval] = SDB_RS;
strcpy (ptr+lval+1, usr);
@ -414,3 +414,44 @@ SDB_API char *sdb_array_pop(Sdb *s, const char *key, ut32 *cas) {
#endif
}
SDB_API void sdb_array_sort(Sdb *s, const char *key, ut32 cas) {
int lstr, j, i;
char *nstr, *str = sdb_get_len (s, key, &lstr, 0);
char **strs;
if (!str || !*str)
return;
strs = sdb_fmt_array (str);
for(i=0; strs[i]; i++);
qsort(strs, i, sizeof(void*), cstring_cmp);
nstr = str;
for(i=0; strs[i]; i++) {
j = strlen(strs[i]);
memcpy(nstr, strs[i], j);
nstr += j;
*(nstr++) = SDB_RS;
}
*(--nstr) = '\0';
sdb_set_owned(s, key, str, cas);
free(strs);
return;
}
SDB_API void sdb_array_sort_num(Sdb *s, const char *key, ut32 cas) {
int lstr, i;
char *ret, *nstr, *str = sdb_get_len (s, key, &lstr, 0);
ut64 *nums;
if (!str || !*str)
return;
nums = sdb_fmt_array_num (str);
qsort(nums+1, *nums, sizeof(void*), int_cmp);
nstr = str;
for(i=0; i<*nums; i++)
*(nstr++)='d';
*nstr='\0';
ret = sdb_fmt_tostr(nums+1, str);
sdb_set_owned(s, key, ret, cas);
free(str);
free(nums);
return;
}

View File

@ -179,12 +179,20 @@ repeat:
is_ref = 0;
quot = NULL;
json = NULL;
if (*p == '#') {
p++;
next = strchr (p, ';');
if (next) *next = 0;
out_concat (sdb_fmt(0, "0x%08x\n", sdb_hash (p)));
if (next) *next = ';';
goto runNext;
} else
if (*p == '%') {
encode = 1;
cmd++;
p++;
}
if (next) *next = ';';
eq = strchr (p, '=');
if (eq) {
d = 1;
@ -663,6 +671,7 @@ next_quote:
}
}
}
runNext:
if (next) {
if (bufset) {
free (buf);

View File

@ -204,6 +204,8 @@ int sdb_array_insert (Sdb* s, const char *key, int idx, const char *val, ut32 ca
int sdb_array_insert_num (Sdb* s, const char *key, int idx, ut64 val, ut32 cas);
int sdb_array_unset (Sdb* s, const char *key, int n, ut32 cas); // leaves empty bucket
int sdb_array_delete (Sdb* s, const char *key, int n, ut32 cas);
void sdb_array_sort (Sdb* s, const char *key, ut32 cas);
void sdb_array_sort_num (Sdb* s, const char *key, ut32 cas);
// set
int sdb_array_add (Sdb* s, const char *key, const char *val, ut32 cas);
int sdb_array_add_num (Sdb* s, const char *key, ut64 val, ut32 cas);