Esempio n. 1
0
static int rabin_delegate(RThread *th) {
	if (rabin_cmd && r_file_exists (r.file->desc->name)) {
		char *nptr, *ptr, *cmd = r_sys_cmd_str (rabin_cmd, NULL, NULL);
		ptr = cmd;
		if (ptr) {
			do {
				if (th) {
					r_th_lock_enter (th->user);
				}
				nptr = strchr (ptr, '\n');
				if (nptr) {
					*nptr = 0;
				}
				r_core_cmd (&r, ptr, 0);
				if (nptr) {
					ptr = nptr + 1;
				}
				if (th) {
					r_th_lock_leave (th->user);
				}
			} while (nptr);
		}
		//r_core_cmd (&r, cmd, 0);
		r_str_free (rabin_cmd);
		rabin_cmd = NULL;
	}
	if (th) eprintf ("rabin2: done\n");
	return 0;
}
Esempio n. 2
0
static RThreadFunctionRet rabin_delegate(RThread *th) {
	RIODesc *d = r_io_desc_get (r.io, r.file->fd);
	if (rabin_cmd && r_file_exists (d->name)) {
		char *nptr, *ptr, *cmd = r_sys_cmd_str (rabin_cmd, NULL, NULL);
		ptr = cmd;
		if (ptr) {
			do {
				if (th) {
					r_th_lock_enter (th->user);
				}
				nptr = strchr (ptr, '\n');
				if (nptr) {
					*nptr = 0;
				}
				r_core_cmd (&r, ptr, 0);
				if (nptr) {
					ptr = nptr + 1;
				}
				if (th) {
					r_th_lock_leave (th->user);
				}
			} while (nptr);
		}
		//r_core_cmd (&r, cmd, 0);
		free (rabin_cmd);
		rabin_cmd = NULL;
	}
	if (th) {
		eprintf ("rabin2: done\n");
	}
	return R_TH_STOP;
}
Esempio n. 3
0
File: sys.c Progetto: futex/radare2
R_API char *r_sys_cmd_strf(const char *fmt, ...) {
	char *ret, cmd[4096];
	va_list ap;
	va_start (ap, fmt);
	vsnprintf (cmd, sizeof (cmd), fmt, ap);
	ret = r_sys_cmd_str (cmd, NULL, NULL);
	va_end (ap);
	return ret;
}
Esempio n. 4
0
File: nasm.c Progetto: 111X/radare
int rasm_nasm_x86(ut64 offset, const char *str, u8 *data)
{
	int len;
	char cmd[1024];
	u8 *out;
	sprintf(cmd, "nasm /dev/stdin -o /dev/stdout <<__\nBITS 64\nORG 0x%llx\n%s\n__", offset, str);
	out = (u8 *)r_sys_cmd_str(cmd, "", &len);
	if (out) {
		memcpy(data, out, len);
		free(out);
	} else return -1;
	return len;
}
Esempio n. 5
0
int main(int argc, char *argv[]) {
       int len = 0;
       char *sterr;
       char *output = r_sys_cmd_str("find /etc", 0, &len);
       int result = r_sys_cmd_str_full("find /etc", 0, &output, &len, &sterr);
       printf("RESULT: %d\n", result);
       printf("STDOUT\n");
       printf("%s", output);
       printf("STDERR\n");
       printf("%s", sterr);
       printf("bytes in STDOUT: %d\n", len);
       return 0;
}
Esempio n. 6
0
// XXX: TODO Implement
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
	int len = 0;
	char cmd[R_ASM_BUFSIZE];
	ut8 *out;
	snprintf (cmd, sizeof (cmd),
		"gas /dev/stdin -o /dev/stdout <<__\n"
		"BITS %i\nORG 0x%"PFMT64x"\n%s\n__",
		a->bits, a->pc, buf);
	out = (ut8 *)r_sys_cmd_str (cmd, "", &len);
	if (out) {
		memcpy (op->buf, out, len<=R_ASM_BUFSIZE?len:R_ASM_BUFSIZE);
		free (out);
	}
	op->size = len;
	return len;
}
Esempio n. 7
0
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
	int len = 0;
	ut8 *out;
	char *cmd = r_str_newf (
		"gas /dev/stdin -o /dev/stdout <<__\n"
		"BITS %i\nORG 0x%"PFMT64x"\n%s\n__",
		a->bits, a->pc, buf);
	ut8 *out = (ut8 *)r_sys_cmd_str (cmd, "", &len);
	if (out) {
		r_asm_op_set_buf (op, out, len);
		free (out);
	}
	op->size = len;
	free (cmd);
	return len;
}
Esempio n. 8
0
static char *getstr(const char *src) {
	int len;
	char *ret = NULL;

	switch (*src) {
	case '\'':
		ret = strdup (src+1);
		if (ret) {
			len = strlen (ret);
			if (len>0) {
				len--;
				if (ret[len]=='\'') {
					ret[len] = 0;
					return ret;
				} else eprintf ("Missing \"\n");
			}
			free (ret);
		}
		return NULL;
	case '"':
		ret = strdup (src+1);
		if (ret) {
			len = strlen (ret);
			if (len>0) {
				len--;
				if (ret[len]=='"') {
					ret[len] = 0;
					r_str_unescape (ret);
					return ret;
				} else eprintf ("Missing \"\n");
			}
			free (ret);
		}
		return NULL;
	case '@':
		{
			char *pat = strchr (src+1, '@');
			if (pat) {
				*pat++ = 0;
				int i, rep = atoi (src+1);
				int len = strlen (pat);
				if (rep>0) {
					char *buf = malloc (rep);
					for(i=0;i<rep;i++) {
						buf[i] = pat[i%len];
					}
					return buf;
				}
			}
			// slurp file
			return r_file_slurp (src+1, NULL);
		}
	case '!':
		return r_str_trim_tail (r_sys_cmd_str (src+1, NULL, NULL));
	case ':':
		if (src[1]=='!') {
			ret = r_str_trim_tail (r_sys_cmd_str (src+1, NULL, NULL));
		} else {
			ret = strdup (src);
		}
		len = r_hex_str2bin (src+1, (ut8*)ret);
		if (len>0) {
			ret[len] = 0;
			return ret;
		} else {
			eprintf ("Invalid hexpair string\n");
			free (ret);
			return NULL;
		}
	}
	r_str_unescape ((ret = strdup (src)));
	return ret;
}
Esempio n. 9
0
File: run.c Progetto: f0829/radare2
static char *getstr(const char *src) {
	int len;
	char *ret = NULL;

	switch (*src) {
	case '\'':
		ret = strdup (src+1);
		if (ret) {
			len = strlen (ret);
			if (len > 0) {
				len--;
				if (ret[len] == '\'') {
					ret[len] = 0;
					return ret;
				}
				eprintf ("Missing \"\n");
			}
			free (ret);
		}
		return NULL;
	case '"':
		ret = strdup (src + 1);
		if (ret) {
			len = strlen (ret);
			if (len > 0) {
				len--;
				if (ret[len] == '"') {
					ret[len] = 0;
					r_str_unescape (ret);
					return ret;
				}
				eprintf ("Missing \"\n");
			}
			free (ret);
		}
		return NULL;
	case '@':
		{
			char *pat = strchr (src + 1, '@');
			if (pat) {
				int i, len, rep;
				*pat++ = 0;
				rep = atoi (src + 1);
				len = strlen (pat);
				if (rep > 0) {
					char *buf = malloc (rep);
					if (buf) {
						for (i = 0; i < rep; i++) {
							buf[i] = pat[i%len];
						}
					}
					return buf;
				}
			}
			// slurp file
			return r_file_slurp (src + 1, NULL);
		}
	case '`':
		{
		char *msg = strdup (src + 1);
		int msg_len = strlen (msg);
		if (msg_len > 0) {
			msg [msg_len - 1] = 0;
			char *ret = r_str_trim_tail (r_sys_cmd_str (msg, NULL, NULL));
			free (msg);
			return ret;
		}
		free (msg);
		return strdup ("");
		}
	case '!':
		return r_str_trim_tail (r_sys_cmd_str (src + 1, NULL, NULL));
	case ':':
		if (src[1] == '!') {
			ret = r_str_trim_tail (r_sys_cmd_str (src + 1, NULL, NULL));
		} else {
			ret = strdup (src);
		}
		len = r_hex_str2bin (src + 1, (ut8*)ret);
		if (len > 0) {
			ret[len] = 0;
			return ret;
		}
		eprintf ("Invalid hexpair string\n");
		free (ret);
		return NULL;
#if 0
	// what is this for??
	case '%':
		return (char *) strtoul (src + 1, NULL, 0);
#endif
	}
	r_str_unescape ((ret = strdup (src)));
	return ret;
}
Esempio n. 10
0
int main(){
	int out;
	printf ("%s\n", r_sys_cmd_str("less","hello world\nhow are you\n", &out));
	printf ("out=%d\n", out);
	return 0;
}