24 #define RZP_PID(x) (((RzPipe *)(x)->data)->pid)
25 #define RZP_INPUT(x) (((RzPipe *)(x)->data)->input[0])
26 #define RZP_OUTPUT(x) (((RzPipe *)(x)->data)->output[1])
29 static void env(
const char *
s,
int f) {
39 if (!rzpipe || !
str) {
48 strcpy(
cmd +
len - 2,
"\n");
51 WriteFile(rzpipe->pipe,
cmd,
len, &dwWritten,
NULL);
52 ret = (dwWritten ==
len);
73 BOOL bSuccess =
FALSE;
76 bSuccess = ReadFile(rzpipe->pipe,
buf, bufsz, &dwRead,
NULL);
77 if (!bSuccess || !
buf[0]) {
87 for (
i = 0;
i < bufsz;
i++) {
98 if (rv != 1 || !
buf[
i]) {
103 int zpos = (
i < bufsz) ?
i :
i - 1;
124 CloseHandle(rzpipe->pipe);
128 if (rzpipe->
input[0] != -1) {
130 rzpipe->
input[0] = -1;
132 if (rzpipe->
input[1] != -1) {
134 rzpipe->
input[1] = -1;
136 if (rzpipe->
output[0] != -1) {
140 if (rzpipe->
output[1] != -1) {
144 if (rzpipe->
child != -1) {
155 static int w32_createPipe(
RzPipe *rzpipe,
const char *
cmd) {
157 rzpipe->pipe = CreateNamedPipe(TEXT(
"\\\\.\\pipe\\RZ_PIPE_IN"),
158 PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
161 if (ConnectNamedPipe(rzpipe->pipe,
NULL)) {
171 #if __UNIX__ || defined(__CYGWIN__)
177 int i_out = atoi(
out);
178 if (i_in >= 0 && i_out >= 0) {
185 eprintf(
"Cannot find RZ_PIPE_IN or RZ_PIPE_OUT environment\n");
192 eprintf(
"rzpipe_open(NULL) not supported on windows\n");
220 char *(*rcmd)(
void *
c,
const char *
cmd) =
rz_lib_dl_sym(librz,
"rz_core_cmd_str");
231 eprintf(
"Cannot resolve rz_core_cmd, rz_core_cmd_str, rz_core_free\n");
245 w32_createPipe(rzp,
cmd);
250 eprintf(
"pipe failed on input\n");
256 eprintf(
"pipe failed on output\n");
261 if (rzp->
child == -1) {
272 eprintf(
"Failed to read 1 byte\n");
277 eprintf(
"[+] rzpipe link error.\n");
319 perror(
"rzpipe_write");
327 char *
p,
string[1024];
331 ret =
vsnprintf(
string,
sizeof(
string) - 1, fmt, ap);
332 if (ret < 1 || ret >=
sizeof(
string)) {
340 if (ret2 < 1 || ret2 > ret + 1) {
const lzma_allocator const uint8_t * in
const lzma_allocator const uint8_t size_t uint8_t * out
static static fork const void static count close
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc kill
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
#define rz_return_val_if_fail(expr, val)
RZ_API void * rz_lib_dl_sym(void *handler, const char *name)
RZ_API void * rz_lib_dl_open(const char *libname)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_STR_ISEMPTY(x)
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
RZ_API int rz_sys_setenv(const char *key, const char *value)
Set an environment variable in the calling process.
RZ_API int rz_sys_pipe(int pipefd[2], bool close_on_exec)
RZ_API int rz_sys_fork(void)
RZ_API int rz_sys_pipe_close(int fd)
RZ_API int rz_sys_system(const char *command)
#define rz_xwrite(fd, buf, count)
static RzPipe * rzpipe_new(void)
RZ_API int rzpipe_close(RzPipe *rzpipe)
RZ_API RzPipe * rzpipe_open(const char *cmd)
RZ_API RzPipe * rzpipe_open_corebind(RzCoreBind *coreb)
RZ_API char * rzpipe_cmdf(RzPipe *rzp, const char *fmt,...)
RZ_API char * rzpipe_read(RzPipe *rzpipe)
RZ_API int rzpipe_write(RzPipe *rzpipe, const char *str)
RZ_API char * rzpipe_cmd(RzPipe *rzp, const char *str)
RZ_API RzPipe * rzpipe_open_dl(const char *libr_path)
static void env(const char *s, int f)
static RzPipe * rzp_open_spawn(RzPipe *rzp, const char *cmd)
int read(izstream &zs, T *x, Items items)