File agent/ninedogs.c changed (mode: 100644) (index a54b4da..d1a322b) |
50 |
50 |
#include "ctools.h" |
#include "ctools.h" |
51 |
51 |
#include "process_core.h" |
#include "process_core.h" |
52 |
52 |
#include "process_db.h" |
#include "process_db.h" |
|
53 |
|
#include "process_url.h" |
53 |
54 |
#include "text2process.h" |
#include "text2process.h" |
54 |
55 |
#include "shared.h" |
#include "shared.h" |
55 |
56 |
#include "info.h" |
#include "info.h" |
|
... |
... |
static unsigned int my_trace_encode(unsigned char *buf, |
448 |
449 |
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // handle |
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // handle |
449 |
450 |
} else if (strcmp(func, "curl_easy_init") == 0) { |
} else if (strcmp(func, "curl_easy_init") == 0) { |
450 |
451 |
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // handle |
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // handle |
|
452 |
|
} else if (strcmp(func, "curl_init") == 0) { // php |
|
453 |
|
struct nd_url *u = va_arg(va, struct nd_url *); |
|
454 |
|
my_trace_put64(buf, &i, (uint64_t) u->handle); |
|
455 |
|
my_trace_put16(buf, &i, u->url_len); |
|
456 |
|
my_trace_put(buf, &i, u->url, u->url_len); |
|
457 |
|
} else if (strcmp(func, "curl_exec") == 0) { // php |
|
458 |
|
struct nd_url *u = va_arg(va, struct nd_url *); |
|
459 |
|
my_trace_put64(buf, &i, (uint64_t) u->handle); |
|
460 |
|
if (type == 'r') { |
|
461 |
|
my_trace_put_bool(buf, &i, u->ret); |
|
462 |
|
if (u->ret == 2) { |
|
463 |
|
my_trace_put16(buf, &i, u->sret_len); |
|
464 |
|
my_trace_put(buf, &i, u->sret, u->sret_len); |
|
465 |
|
} |
|
466 |
|
} |
451 |
467 |
} else if (strcmp(func, "curl_easy_perform") == 0) { |
} else if (strcmp(func, "curl_easy_perform") == 0) { |
452 |
|
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // handle |
|
|
468 |
|
if (type == 'm') { |
|
469 |
|
char *info = va_arg(va, char *); |
|
470 |
|
unsigned char len = strlen(info); |
|
471 |
|
my_trace_put8(buf, &i, len); |
|
472 |
|
my_trace_put(buf, &i, info, len); |
|
473 |
|
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // handle |
|
474 |
|
void *p = va_arg(va, void *); |
|
475 |
|
long p_len = va_arg(va, long); |
|
476 |
|
if (p_len > 64000) p_len = 64000; |
|
477 |
|
my_trace_put16(buf, &i, p_len); |
|
478 |
|
my_trace_put(buf, &i, p, p_len); |
|
479 |
|
} else { |
|
480 |
|
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // handle |
|
481 |
|
if (type == 'r') |
|
482 |
|
my_trace_put32(buf, &i, va_arg(va, int)); // ret |
|
483 |
|
} |
|
484 |
|
} else if (strcmp(func, "curl_setopt") == 0) { // php |
|
485 |
|
struct nd_url *u = va_arg(va, struct nd_url *); |
|
486 |
|
my_trace_put64(buf, &i, (uint64_t) u->handle); |
|
487 |
|
uint8_t oplen = strlen(u->op); |
|
488 |
|
my_trace_put8(buf, &i, oplen); |
|
489 |
|
my_trace_put(buf, &i, u->op, oplen); |
|
490 |
|
my_trace_put(buf, &i, u->op_value, u->op_value_len); |
453 |
491 |
if (type == 'r') |
if (type == 'r') |
454 |
|
my_trace_put32(buf, &i, va_arg(va, int)); // ret |
|
|
492 |
|
my_trace_put_bool(buf, &i, u->ret); |
455 |
493 |
} else if (strcmp(func, "curl_easy_setopt") == 0) { |
} else if (strcmp(func, "curl_easy_setopt") == 0) { |
456 |
494 |
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // handle |
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // handle |
457 |
495 |
uint8_t type = va_arg(va, int); |
uint8_t type = va_arg(va, int); |
|
... |
... |
static unsigned int my_trace_encode(unsigned char *buf, |
460 |
498 |
uint8_t option_len = strlen(option); |
uint8_t option_len = strlen(option); |
461 |
499 |
my_trace_put8(buf, &i, option_len); |
my_trace_put8(buf, &i, option_len); |
462 |
500 |
my_trace_put(buf, &i, option, option_len); |
my_trace_put(buf, &i, option, option_len); |
463 |
|
if ((type == 0) || (type == 2)) { |
|
464 |
|
my_trace_put64(buf, &i, va_arg(va, uint64_t)); |
|
465 |
|
} else if (type == 4) { // string |
|
466 |
|
char *s = va_arg(va, char *); |
|
467 |
|
xlog(1, " DEBUG: s=[%s]\n", s); |
|
468 |
|
uint16_t len = strlen(s); |
|
469 |
|
my_trace_put16(buf, &i, len); |
|
470 |
|
my_trace_put(buf, &i, s, len); |
|
|
501 |
|
if ((type == 0) || (type == 2)) { // long |
|
502 |
|
va_arg(va, long); // ignore len |
|
503 |
|
my_trace_put64(buf, &i, va_arg(va, long)); // a |
|
504 |
|
} else if ((type == 3) || (type == 4)) { // object or string |
|
505 |
|
long len = va_arg(va, long); |
|
506 |
|
my_trace_put64(buf, &i, len); |
|
507 |
|
if (len >= 0) { |
|
508 |
|
char *s = va_arg(va, char *); |
|
509 |
|
if (!s) { |
|
510 |
|
my_trace_put16(buf, &i, 0); |
|
511 |
|
} else { |
|
512 |
|
uint16_t len = strlen(s); |
|
513 |
|
my_trace_put16(buf, &i, len); |
|
514 |
|
my_trace_put(buf, &i, s, len); |
|
515 |
|
} |
|
516 |
|
} else { |
|
517 |
|
va_arg(va, long); // ignore 'a' |
|
518 |
|
} |
471 |
519 |
} else if (type == 5) { // slist |
} else if (type == 5) { // slist |
472 |
|
struct my_curl_slist *q, *q0 = va_arg(va, struct my_curl_slist *); |
|
473 |
|
q = q0; |
|
|
520 |
|
va_arg(va, long); // ignore len |
|
521 |
|
struct my_curl_slist *q = va_arg(va, struct my_curl_slist *); |
474 |
522 |
while (q) { |
while (q) { |
475 |
523 |
uint16_t len = strlen(q->data); |
uint16_t len = strlen(q->data); |
476 |
524 |
my_trace_put16(buf, &i, len); |
my_trace_put16(buf, &i, len); |
|
... |
... |
static unsigned int my_trace_encode(unsigned char *buf, |
479 |
527 |
} |
} |
480 |
528 |
my_trace_put16(buf, &i, 0); |
my_trace_put16(buf, &i, 0); |
481 |
529 |
} else { |
} else { |
482 |
|
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); |
|
|
530 |
|
va_arg(va, long); // ignore len |
|
531 |
|
my_trace_put64(buf, &i, (uint64_t) va_arg(va, void *)); // pointer |
483 |
532 |
} |
} |
484 |
|
my_trace_put32(buf, &i, va_arg(va, int)); // ret |
|
|
533 |
|
//my_trace_put32(buf, &i, va_arg(va, int)); // ret |
|
534 |
|
int ret = va_arg(va, int); |
|
535 |
|
my_trace_put32(buf, &i, ret); |
|
536 |
|
xlog(100, "%s: DEBUG: option=[%s] type=%hhu ret=%d\n", |
|
537 |
|
__func__, option, type, ret); |
485 |
538 |
} break; |
} break; |
486 |
539 |
|
|
487 |
540 |
case 'd': |
case 'd': |
|
... |
... |
static unsigned int my_trace_encode(unsigned char *buf, |
739 |
792 |
for (unsigned short j = 0; j < e->params.len; j++) { |
for (unsigned short j = 0; j < e->params.len; j++) { |
740 |
793 |
struct params_array_one *pa = &e->params.list[j]; |
struct params_array_one *pa = &e->params.list[j]; |
741 |
794 |
my_trace_put8(buf, &i, pa->type); |
my_trace_put8(buf, &i, pa->type); |
742 |
|
if (pa->type == ND_PARAMS_TYPE_LONG) { |
|
|
795 |
|
if (pa->type == ND_TYPE_LONG) { |
743 |
796 |
my_trace_put64(buf, &i, pa->l); |
my_trace_put64(buf, &i, pa->l); |
744 |
|
} else if (pa->type == ND_PARAMS_TYPE_DOUBLE) { |
|
|
797 |
|
} else if (pa->type == ND_TYPE_DOUBLE) { |
745 |
798 |
my_trace_put_double(buf, &i, pa->d); |
my_trace_put_double(buf, &i, pa->d); |
746 |
|
} else if (pa->type == ND_PARAMS_TYPE_STRING) { |
|
|
799 |
|
} else if (pa->type == ND_TYPE_STRING) { |
747 |
800 |
my_trace_put16(buf, &i, pa->length); |
my_trace_put16(buf, &i, pa->length); |
748 |
801 |
my_trace_put(buf, &i, pa->str, pa->length); |
my_trace_put(buf, &i, pa->str, pa->length); |
749 |
802 |
} |
} |
|
... |
... |
static unsigned int my_trace_encode(unsigned char *buf, |
925 |
978 |
for (unsigned short j = 0; j < q->params.len; j++) { |
for (unsigned short j = 0; j < q->params.len; j++) { |
926 |
979 |
struct params_array_one *pa = &q->params.list[j]; |
struct params_array_one *pa = &q->params.list[j]; |
927 |
980 |
my_trace_put8(buf, &i, pa->type); |
my_trace_put8(buf, &i, pa->type); |
928 |
|
if (pa->type == ND_PARAMS_TYPE_LONG) { |
|
|
981 |
|
if (pa->type == ND_TYPE_LONG) { |
929 |
982 |
my_trace_put64(buf, &i, pa->l); |
my_trace_put64(buf, &i, pa->l); |
930 |
|
} else if (pa->type == ND_PARAMS_TYPE_DOUBLE) { |
|
|
983 |
|
} else if (pa->type == ND_TYPE_DOUBLE) { |
931 |
984 |
my_trace_put_double(buf, &i, pa->d); |
my_trace_put_double(buf, &i, pa->d); |
932 |
|
} else if (pa->type == ND_PARAMS_TYPE_STRING) { |
|
|
985 |
|
} else if (pa->type == ND_TYPE_STRING) { |
933 |
986 |
my_trace_put16(buf, &i, pa->length); |
my_trace_put16(buf, &i, pa->length); |
934 |
987 |
my_trace_put(buf, &i, pa->str, pa->length); |
my_trace_put(buf, &i, pa->str, pa->length); |
935 |
988 |
} |
} |
|
... |
... |
static unsigned int my_trace_encode(unsigned char *buf, |
1063 |
1116 |
} |
} |
1064 |
1117 |
} else if (strcmp(func, "setsockopt") == 0) { |
} else if (strcmp(func, "setsockopt") == 0) { |
1065 |
1118 |
my_trace_put32(buf, &i, va_arg(va, int)); // sock |
my_trace_put32(buf, &i, va_arg(va, int)); // sock |
1066 |
|
if (type == 'c') { |
|
1067 |
|
my_trace_put32(buf, &i, va_arg(va, int)); // level |
|
1068 |
|
my_trace_put32(buf, &i, va_arg(va, int)); // optname |
|
1069 |
|
socklen_t optlen = va_arg(va, socklen_t); |
|
1070 |
|
my_trace_put32(buf, &i, optlen); |
|
1071 |
|
const void *optval = va_arg(va, void *); |
|
1072 |
|
my_trace_put(buf, &i, optval, optlen); |
|
1073 |
|
} else { |
|
1074 |
|
int ret = va_arg(va, int); |
|
1075 |
|
my_trace_put32(buf, &i, ret); |
|
1076 |
|
if (ret == -1) |
|
1077 |
|
my_trace_put32(buf, &i, save_errno); |
|
1078 |
|
} |
|
|
1119 |
|
my_trace_put32(buf, &i, va_arg(va, int)); // level |
|
1120 |
|
my_trace_put32(buf, &i, va_arg(va, int)); // optname |
|
1121 |
|
socklen_t optlen = va_arg(va, socklen_t); |
|
1122 |
|
my_trace_put32(buf, &i, optlen); |
|
1123 |
|
const void *optval = va_arg(va, void *); |
|
1124 |
|
my_trace_put(buf, &i, optval, optlen); |
|
1125 |
|
int ret = va_arg(va, int); |
|
1126 |
|
my_trace_put32(buf, &i, ret); |
|
1127 |
|
if (ret == -1) |
|
1128 |
|
my_trace_put32(buf, &i, save_errno); |
1079 |
1129 |
} else if (strcmp(func, "socket") == 0) { |
} else if (strcmp(func, "socket") == 0) { |
1080 |
1130 |
my_trace_put32(buf, &i, va_arg(va, int)); // domain |
my_trace_put32(buf, &i, va_arg(va, int)); // domain |
1081 |
1131 |
my_trace_put32(buf, &i, va_arg(va, int)); // type |
my_trace_put32(buf, &i, va_arg(va, int)); // type |
|
... |
... |
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) |
2037 |
2087 |
int setsockopt(int sockfd, int level, int optname, const void *optval, |
int setsockopt(int sockfd, int level, int optname, const void *optval, |
2038 |
2088 |
socklen_t optlen) |
socklen_t optlen) |
2039 |
2089 |
{ |
{ |
2040 |
|
my_trace(__func__, 'c', sockfd, level, optname, optlen, optval); |
|
2041 |
2090 |
int ret = old_setsockopt(sockfd, level, optname, optval, optlen); |
int ret = old_setsockopt(sockfd, level, optname, optval, optlen); |
2042 |
|
my_trace(__func__, 'r', sockfd, ret); |
|
|
2091 |
|
my_trace(__func__, 'R', sockfd, level, optname, optlen, optval, ret); |
2043 |
2092 |
|
|
2044 |
2093 |
return ret; |
return ret; |
2045 |
2094 |
} |
} |
File agent/php.c changed (mode: 100644) (index c52cd55..b6613e0) |
43 |
43 |
#include "tools.h" |
#include "tools.h" |
44 |
44 |
#include "ctools.h" |
#include "ctools.h" |
45 |
45 |
#include "process_db.h" |
#include "process_db.h" |
|
46 |
|
#include "process_url.h" |
|
47 |
|
#include "curl.h" |
46 |
48 |
|
|
47 |
49 |
|
|
48 |
50 |
extern void *(*old_malloc)(size_t size); |
extern void *(*old_malloc)(size_t size); |
|
... |
... |
static void php_zed_dump(const char *prefix, struct zend_execute_data *p) |
319 |
321 |
} |
} |
320 |
322 |
} |
} |
321 |
323 |
|
|
|
324 |
|
// TODO this is really not related to parameters - rename it |
|
325 |
|
// this is obsolete. Use 'zend_to_binary' |
322 |
326 |
static void zend_array_to_params_array(struct params_array *p, struct zend_array *za) |
static void zend_array_to_params_array(struct params_array *p, struct zend_array *za) |
323 |
327 |
{ |
{ |
324 |
328 |
unsigned int i = 0; |
unsigned int i = 0; |
325 |
329 |
|
|
326 |
|
xlog(100, " nTableMask=0x%x nNumUsed=%u nNumOfElements=%u nTableSize=%u" |
|
|
330 |
|
xlog(100, " %s: nTableMask=0x%x nNumUsed=%u nNumOfElements=%u nTableSize=%u" |
327 |
331 |
" nInternalPointer=%u flags=0x%x[%s]\n", |
" nInternalPointer=%u flags=0x%x[%s]\n", |
|
332 |
|
__func__, |
328 |
333 |
za->nTableMask, za->nNumUsed, za->nNumOfElements, za->nTableSize, |
za->nTableMask, za->nNumUsed, za->nNumOfElements, za->nTableSize, |
329 |
334 |
za->nInternalPointer, za->u.flags, za->u.flags & 4 ? "packed" : ""); |
za->nInternalPointer, za->u.flags, za->u.flags & 4 ? "packed" : ""); |
330 |
335 |
|
|
|
... |
... |
static void zend_array_to_params_array(struct params_array *p, struct zend_array |
354 |
359 |
bs, bs->h, zs, php_get_type(_z), php_get_value(_z)); |
bs, bs->h, zs, php_get_type(_z), php_get_value(_z)); |
355 |
360 |
|
|
356 |
361 |
if (_z->u1.v.type == 1) { |
if (_z->u1.v.type == 1) { |
357 |
|
p->list[i].type = ND_PARAMS_TYPE_NULL; |
|
|
362 |
|
p->list[i].type = ND_TYPE_NULL; |
358 |
363 |
} else if (_z->u1.v.type == 2) { |
} else if (_z->u1.v.type == 2) { |
359 |
|
p->list[i].type = ND_PARAMS_TYPE_STRING; |
|
|
364 |
|
p->list[i].type = ND_TYPE_STRING; |
360 |
365 |
p->list[i].str = "false"; |
p->list[i].str = "false"; |
361 |
366 |
p->list[i].length = 5; |
p->list[i].length = 5; |
362 |
367 |
} else if (_z->u1.v.type == 3) { |
} else if (_z->u1.v.type == 3) { |
363 |
|
p->list[i].type = ND_PARAMS_TYPE_STRING; |
|
|
368 |
|
p->list[i].type = ND_TYPE_STRING; |
364 |
369 |
p->list[i].str = "true"; |
p->list[i].str = "true"; |
365 |
370 |
p->list[i].length = 4; |
p->list[i].length = 4; |
366 |
371 |
} else if (_z->u1.v.type == 4) { |
} else if (_z->u1.v.type == 4) { |
367 |
|
p->list[i].type = ND_PARAMS_TYPE_LONG; |
|
|
372 |
|
p->list[i].type = ND_TYPE_LONG; |
368 |
373 |
p->list[i].l = _z->value.lval; |
p->list[i].l = _z->value.lval; |
369 |
374 |
} else if (_z->u1.v.type == 5) { |
} else if (_z->u1.v.type == 5) { |
370 |
|
p->list[i].type = ND_PARAMS_TYPE_DOUBLE; |
|
|
375 |
|
p->list[i].type = ND_TYPE_DOUBLE; |
371 |
376 |
p->list[i].d = _z->value.dval; |
p->list[i].d = _z->value.dval; |
372 |
377 |
} else if (_z->u1.v.type == 6) { |
} else if (_z->u1.v.type == 6) { |
373 |
|
p->list[i].type = ND_PARAMS_TYPE_STRING; |
|
|
378 |
|
p->list[i].type = ND_TYPE_STRING; |
374 |
379 |
struct zend_string *zs = _z->value.str; |
struct zend_string *zs = _z->value.str; |
375 |
380 |
p->list[i].str = zs->val; |
p->list[i].str = zs->val; |
376 |
381 |
p->list[i].length = zs->len; |
p->list[i].length = zs->len; |
377 |
382 |
} else { |
} else { |
378 |
|
p->list[i].type = ND_PARAMS_TYPE_NULL; |
|
379 |
|
xlog(1, " I do not how to encode this type!\n"); |
|
|
383 |
|
p->list[i].type = ND_TYPE_NULL; |
|
384 |
|
xlog(1, " %s: I do not how to encode %d type! Encode as NULL\n", |
|
385 |
|
__func__, _z->u1.v.type); |
380 |
386 |
} |
} |
381 |
387 |
|
|
382 |
388 |
i++; |
i++; |
|
... |
... |
static void zend_array_to_params_array(struct params_array *p, struct zend_array |
385 |
391 |
} |
} |
386 |
392 |
} |
} |
387 |
393 |
|
|
|
394 |
|
static unsigned int zend_simple_to_binary(unsigned char *out, const size_t out_size, |
|
395 |
|
struct zval *z) |
|
396 |
|
{ |
|
397 |
|
unsigned int off = 0; |
|
398 |
|
uint16_t u16; |
|
399 |
|
uint64_t u64; |
|
400 |
|
|
|
401 |
|
if (off + 1 + 8 > out_size) // 1+8 for a long |
|
402 |
|
return 0; |
|
403 |
|
|
|
404 |
|
if (z->u1.v.type == 1) { |
|
405 |
|
out[off++] = ND_TYPE_NULL; |
|
406 |
|
} else if (z->u1.v.type == 2) { |
|
407 |
|
out[off++] = ND_TYPE_FALSE; |
|
408 |
|
} else if (z->u1.v.type == 3) { |
|
409 |
|
out[off++] = ND_TYPE_TRUE; |
|
410 |
|
} else if (z->u1.v.type == 4) { |
|
411 |
|
out[off++] = ND_TYPE_LONG; |
|
412 |
|
u64 = htobe64(z->value.lval); |
|
413 |
|
memcpy(out + off, &u64, 8); off += 8; |
|
414 |
|
} else if (z->u1.v.type == 5) { |
|
415 |
|
out[off++] = ND_TYPE_DOUBLE; |
|
416 |
|
uint64_t u64 = htobe64(z->value.lval); |
|
417 |
|
memcpy(out + off, &u64, 8); off += 8; |
|
418 |
|
} else if (z->u1.v.type == 6) { |
|
419 |
|
out[off++] = ND_TYPE_STRING; |
|
420 |
|
struct zend_string *zs = z->value.str; |
|
421 |
|
if (off + 2 + zs->len > out_size) |
|
422 |
|
return 0; |
|
423 |
|
u16 = htobe16(zs->len); |
|
424 |
|
memcpy(out + off, &u16, 2); off += 2; |
|
425 |
|
memcpy(out + off, zs->val, zs->len); off += zs->len; |
|
426 |
|
} else if (z->u1.v.type == 8) { // object |
|
427 |
|
out[off++] = ND_TYPE_POINTER; |
|
428 |
|
u64 = htobe64(z->value.lval); |
|
429 |
|
memcpy(out + off, &u64, 8); off += 8; |
|
430 |
|
} else if (z->u1.v.type == 9) { // resource |
|
431 |
|
out[off++] = ND_TYPE_POINTER; |
|
432 |
|
u64 = htobe64(z->value.lval); |
|
433 |
|
memcpy(out + off, &u64, 8); off += 8; |
|
434 |
|
} else { |
|
435 |
|
out[off++] = ND_TYPE_UNK; |
|
436 |
|
xlog(1, " %s: I do not how to encode %d type! Encode as NULL\n", |
|
437 |
|
__func__, z->u1.v.type); |
|
438 |
|
} |
|
439 |
|
|
|
440 |
|
return off; |
|
441 |
|
} |
|
442 |
|
|
|
443 |
|
// Returns the number of bytes stored in 'out' |
|
444 |
|
static unsigned int zend_array_to_binary(unsigned char *out, const size_t out_size, |
|
445 |
|
struct zend_array *za) |
|
446 |
|
{ |
|
447 |
|
xlog(100, " %s: nTableMask=0x%x nNumUsed=%u nNumOfElements=%u nTableSize=%u" |
|
448 |
|
" nInternalPointer=%u flags=0x%x[%s]\n", |
|
449 |
|
__func__, |
|
450 |
|
za->nTableMask, za->nNumUsed, za->nNumOfElements, za->nTableSize, |
|
451 |
|
za->nInternalPointer, za->u.flags, za->u.flags & 4 ? "packed" : ""); |
|
452 |
|
|
|
453 |
|
unsigned int off = 0; |
|
454 |
|
out[off++] = ND_TYPE_ARRAY_START; |
|
455 |
|
|
|
456 |
|
struct Bucket *bs = za->arData, *be = za->arData + za->nNumUsed; |
|
457 |
|
for (; bs != be; bs++) { |
|
458 |
|
struct zval *_z = &bs->val; |
|
459 |
|
|
|
460 |
|
if (_z && (_z->u1.v.type == 12)) // 12=IS_INDIRECT |
|
461 |
|
_z = _z->value.zv; |
|
462 |
|
|
|
463 |
|
if (_z->u1.v.type == 0 /*IS_UNDEF*/) { |
|
464 |
|
xlog(101, " para h=%lu: type undef\n", bs->h); |
|
465 |
|
continue; |
|
466 |
|
} |
|
467 |
|
|
|
468 |
|
if (_z->u1.v.type == 10) { // REFERENCE |
|
469 |
|
xlog(101, " is a reference!\n"); |
|
470 |
|
_z = &_z->value.ref->val; |
|
471 |
|
} |
|
472 |
|
|
|
473 |
|
struct zend_string *zs = bs->key; |
|
474 |
|
xlog(101, " para: bs=%p h=%lu key=[%p] type %s: val: %s\n", |
|
475 |
|
bs, bs->h, zs, php_get_type(_z), php_get_value(_z)); |
|
476 |
|
|
|
477 |
|
unsigned int r = zend_simple_to_binary(out + off, out_size - off, _z); |
|
478 |
|
if (r == 0) |
|
479 |
|
break; |
|
480 |
|
off += r; |
|
481 |
|
} |
|
482 |
|
|
|
483 |
|
out[off++] = ND_TYPE_ARRAY_END; |
|
484 |
|
|
|
485 |
|
return off; |
|
486 |
|
} |
|
487 |
|
|
|
488 |
|
// Returns the number of bytes stored in 'out' |
|
489 |
|
static unsigned int zend_to_binary(unsigned char *out, const size_t out_size, |
|
490 |
|
struct zval *z) |
|
491 |
|
{ |
|
492 |
|
if (z->u1.v.type == 7) |
|
493 |
|
return zend_array_to_binary(out, out_size, z->value.arr); |
|
494 |
|
|
|
495 |
|
return zend_simple_to_binary(out, out_size, z); |
|
496 |
|
} |
|
497 |
|
|
388 |
498 |
static void php_set_para(struct zend_execute_data *e, const unsigned int i, |
static void php_set_para(struct zend_execute_data *e, const unsigned int i, |
389 |
499 |
const struct zval *para) |
const struct zval *para) |
390 |
500 |
{ |
{ |
|
... |
... |
static void *my_mysqli_stmt_bind_param(struct zend_execute_data *e, struct zval |
1581 |
1691 |
} |
} |
1582 |
1692 |
|
|
1583 |
1693 |
|
|
|
1694 |
|
//////////////////////////////////////// C U R L |
|
1695 |
|
void *(*old_curl_init)(struct zend_execute_data *, struct zval *); |
|
1696 |
|
static void *my_curl_init(struct zend_execute_data *e, struct zval *retv) |
|
1697 |
|
{ |
|
1698 |
|
struct nd_url b; |
|
1699 |
|
|
|
1700 |
|
unsigned int num_args = e->This.u2.num_args; |
|
1701 |
|
xlog(100, "%s: e=%p num_args=%hu\n", __func__, e, num_args); |
|
1702 |
|
|
|
1703 |
|
if (num_args > 0) { |
|
1704 |
|
unsigned int s = (sizeof(struct zend_execute_data) |
|
1705 |
|
+ sizeof(struct zval) - 1) / sizeof(struct zval); |
|
1706 |
|
|
|
1707 |
|
// url |
|
1708 |
|
struct zval *z = (struct zval *) e + s; s++; |
|
1709 |
|
php_zval_dump(" url: ", z); |
|
1710 |
|
struct zend_string *xs = z->value.str; |
|
1711 |
|
b.url = xs->val; |
|
1712 |
|
b.url_len = xs->len; |
|
1713 |
|
} else { |
|
1714 |
|
b.url = NULL; |
|
1715 |
|
b.url_len = 0; |
|
1716 |
|
} |
|
1717 |
|
|
|
1718 |
|
void *ret = old_curl_init(e, retv); |
|
1719 |
|
if (!retv) |
|
1720 |
|
return ret; |
|
1721 |
|
|
|
1722 |
|
if ((retv->u1.v.type == 7) || (retv->u1.v.type == 8)) { // resource or object |
|
1723 |
|
b.handle = retv->value.p; |
|
1724 |
|
} else if (retv->u1.v.type == 2) { // false |
|
1725 |
|
b.handle = NULL; |
|
1726 |
|
} |
|
1727 |
|
|
|
1728 |
|
ninedogs_process_url("curl_init", NINEDOGS_URL_INIT_END, &b); |
|
1729 |
|
|
|
1730 |
|
return ret; |
|
1731 |
|
} |
|
1732 |
|
|
|
1733 |
|
void *(*old_curl_exec)(struct zend_execute_data *, struct zval *); |
|
1734 |
|
static void *my_curl_exec(struct zend_execute_data *e, struct zval *retv) |
|
1735 |
|
{ |
|
1736 |
|
struct nd_url b = { .url_len = 0, .sret_len = 0 }; |
|
1737 |
|
|
|
1738 |
|
unsigned int num_args = e->This.u2.num_args; |
|
1739 |
|
xlog(100, "%s: e=%p num_args=%hu\n", __func__, e, num_args); |
|
1740 |
|
|
|
1741 |
|
unsigned int s = (sizeof(struct zend_execute_data) |
|
1742 |
|
+ sizeof(struct zval) - 1) / sizeof(struct zval); |
|
1743 |
|
|
|
1744 |
|
// handle |
|
1745 |
|
struct zval *z = (struct zval *) e + s; s++; |
|
1746 |
|
php_zval_dump(" handle: ", z); |
|
1747 |
|
b.handle = z->value.p; |
|
1748 |
|
|
|
1749 |
|
ninedogs_process_url("curl_exec", NINEDOGS_URL_START, &b); |
|
1750 |
|
void *ret = old_curl_exec(e, retv); |
|
1751 |
|
if (!retv) |
|
1752 |
|
return ret; |
|
1753 |
|
|
|
1754 |
|
if (retv->u1.v.type == 6) { // string |
|
1755 |
|
struct zend_string *xs = retv->value.str; |
|
1756 |
|
b.ret = 2; |
|
1757 |
|
b.sret = xs->val; |
|
1758 |
|
b.sret_len = xs->len; |
|
1759 |
|
} else if (retv->u1.v.type == 2) { // false |
|
1760 |
|
b.ret = 0; |
|
1761 |
|
} else if (retv->u1.v.type == 3) { // true |
|
1762 |
|
b.ret = 1; |
|
1763 |
|
} |
|
1764 |
|
// TODO: propagate errors |
|
1765 |
|
|
|
1766 |
|
ninedogs_process_url("curl_exec", NINEDOGS_URL_END, &b); |
|
1767 |
|
|
|
1768 |
|
return ret; |
|
1769 |
|
} |
|
1770 |
|
|
|
1771 |
|
void *(*old_curl_close)(struct zend_execute_data *, struct zval *); |
|
1772 |
|
static void *my_curl_close(struct zend_execute_data *e, struct zval *retv) |
|
1773 |
|
{ |
|
1774 |
|
struct nd_url b = { .url_len = 0, .sret_len = 0 }; |
|
1775 |
|
|
|
1776 |
|
unsigned int num_args = e->This.u2.num_args; |
|
1777 |
|
xlog(100, "%s: e=%p num_args=%hu\n", __func__, e, num_args); |
|
1778 |
|
|
|
1779 |
|
unsigned int s = (sizeof(struct zend_execute_data) |
|
1780 |
|
+ sizeof(struct zval) - 1) / sizeof(struct zval); |
|
1781 |
|
|
|
1782 |
|
// handle |
|
1783 |
|
struct zval *z = (struct zval *) e + s; s++; |
|
1784 |
|
php_zval_dump(" handle: ", z); |
|
1785 |
|
b.handle = z->value.p; |
|
1786 |
|
|
|
1787 |
|
void *ret = old_curl_close(e, retv); |
|
1788 |
|
if (!retv) |
|
1789 |
|
return ret; |
|
1790 |
|
|
|
1791 |
|
ninedogs_process_url("curl_close", NINEDOGS_URL_CLOSE_END, &b); |
|
1792 |
|
|
|
1793 |
|
return ret; |
|
1794 |
|
} |
|
1795 |
|
|
|
1796 |
|
void *(*old_curl_setopt)(struct zend_execute_data *, struct zval *); |
|
1797 |
|
static void *my_curl_setopt(struct zend_execute_data *e, struct zval *retv) |
|
1798 |
|
{ |
|
1799 |
|
struct nd_url b = { .url_len = 0, .sret_len = 0 }; |
|
1800 |
|
|
|
1801 |
|
unsigned int num_args = e->This.u2.num_args; |
|
1802 |
|
xlog(100, "%s: e=%p num_args=%hu\n", __func__, e, num_args); |
|
1803 |
|
|
|
1804 |
|
unsigned int s = (sizeof(struct zend_execute_data) |
|
1805 |
|
+ sizeof(struct zval) - 1) / sizeof(struct zval); |
|
1806 |
|
|
|
1807 |
|
// handle |
|
1808 |
|
struct zval *z = (struct zval *) e + s; s++; |
|
1809 |
|
php_zval_dump(" handle: ", z); |
|
1810 |
|
b.handle = z->value.p; |
|
1811 |
|
|
|
1812 |
|
// option |
|
1813 |
|
z = (struct zval *) e + s; s++; |
|
1814 |
|
php_zval_dump(" option: ", z); |
|
1815 |
|
const struct my_curl_easyoption *oi = curl_easy_option_by_id(z->value.lval); |
|
1816 |
|
if (oi) |
|
1817 |
|
snprintf(b.op, sizeof(b.op), "%s", oi->name); |
|
1818 |
|
else |
|
1819 |
|
snprintf(b.op, sizeof(b.op), "?%ld?", z->value.lval); |
|
1820 |
|
xlog(100, " option name = %s\n", b.op); |
|
1821 |
|
|
|
1822 |
|
// value |
|
1823 |
|
z = (struct zval *) e + s; s++; |
|
1824 |
|
php_zval_dump(" value: ", z); |
|
1825 |
|
b.op_value_len = zend_to_binary(b.op_value, sizeof(b.op_value), z); |
|
1826 |
|
|
|
1827 |
|
void *ret = old_curl_setopt(e, retv); |
|
1828 |
|
if (!retv) |
|
1829 |
|
return ret; |
|
1830 |
|
php_zval_dump(" retv: ", retv); |
|
1831 |
|
|
|
1832 |
|
if (retv->u1.v.type == 2) { // false |
|
1833 |
|
b.ret = 0; |
|
1834 |
|
} else if (retv->u1.v.type == 3) { // true |
|
1835 |
|
b.ret = 1; |
|
1836 |
|
} |
|
1837 |
|
// TODO: propagate errors |
|
1838 |
|
|
|
1839 |
|
ninedogs_process_url("curl_setopt", NINEDOGS_URL_SETOPT_END, &b); |
|
1840 |
|
|
|
1841 |
|
return ret; |
|
1842 |
|
} |
|
1843 |
|
|
1584 |
1844 |
|
|
1585 |
1845 |
|
|
1586 |
1846 |
struct zend_module_entry *(*old_get_module)(void); |
struct zend_module_entry *(*old_get_module)(void); |
|
... |
... |
static struct zend_module_entry *php_hook_get_module_func(void) |
1637 |
1897 |
fe = new->functions; |
fe = new->functions; |
1638 |
1898 |
while (fe && fe->fname) { |
while (fe && fe->fname) { |
1639 |
1899 |
xlog(100, " func %s handler=%p\n", fe->fname, fe->handler); |
xlog(100, " func %s handler=%p\n", fe->fname, fe->handler); |
1640 |
|
if (strncmp(fe->fname, "pg_", 3) == 0) { |
|
|
1900 |
|
if (strncmp(fe->fname, "curl_", 5) == 0) { |
|
1901 |
|
if (strcmp(fe->fname, "curl_close") == 0) { |
|
1902 |
|
old_curl_close = fe->handler; |
|
1903 |
|
fe->handler = my_curl_close; |
|
1904 |
|
} else if (strcmp(fe->fname, "curl_init") == 0) { |
|
1905 |
|
old_curl_init = fe->handler; |
|
1906 |
|
fe->handler = my_curl_init; |
|
1907 |
|
} else if (strcmp(fe->fname, "curl_exec") == 0) { |
|
1908 |
|
old_curl_exec = fe->handler; |
|
1909 |
|
fe->handler = my_curl_exec; |
|
1910 |
|
} else if (strcmp(fe->fname, "curl_setopt") == 0) { |
|
1911 |
|
old_curl_setopt = fe->handler; |
|
1912 |
|
fe->handler = my_curl_setopt; |
|
1913 |
|
} else { |
|
1914 |
|
//xlog(100, " %s: do not hook [%s]!\n", __func__, fe->fname); |
|
1915 |
|
} |
|
1916 |
|
} else if (strncmp(fe->fname, "pg_", 3) == 0) { |
1641 |
1917 |
if (strcmp(fe->fname, "pg_close") == 0) { |
if (strcmp(fe->fname, "pg_close") == 0) { |
1642 |
1918 |
old_pg_close = fe->handler; |
old_pg_close = fe->handler; |
1643 |
1919 |
fe->handler = my_pg_close; |
fe->handler = my_pg_close; |
|
... |
... |
static struct zend_module_entry *php_hook_get_module_func(void) |
1674 |
1950 |
old_pg_get_result = fe->handler; |
old_pg_get_result = fe->handler; |
1675 |
1951 |
fe->handler = my_pg_get_result; |
fe->handler = my_pg_get_result; |
1676 |
1952 |
} else { |
} else { |
1677 |
|
xlog(100, " %s: do not hook [%s]!\n", __func__, fe->fname); |
|
|
1953 |
|
//xlog(100, " %s: do not hook [%s]!\n", __func__, fe->fname); |
1678 |
1954 |
} |
} |
1679 |
1955 |
} else if (strncmp(fe->fname, "mysqli_", 7) == 0) { |
} else if (strncmp(fe->fname, "mysqli_", 7) == 0) { |
1680 |
1956 |
if (strcmp(fe->fname, "mysqli_autocommit") == 0) { |
if (strcmp(fe->fname, "mysqli_autocommit") == 0) { |
|
... |
... |
static struct zend_module_entry *php_hook_get_module_func(void) |
1724 |
2000 |
old_mysqli_stmt_prepare = fe->handler; |
old_mysqli_stmt_prepare = fe->handler; |
1725 |
2001 |
fe->handler = my_mysqli_stmt_prepare; |
fe->handler = my_mysqli_stmt_prepare; |
1726 |
2002 |
} else { |
} else { |
1727 |
|
xlog(100, " %s: do not hook [%s]!\n", __func__, fe->fname); |
|
|
2003 |
|
//xlog(100, " %s: do not hook [%s]!\n", __func__, fe->fname); |
1728 |
2004 |
} |
} |
1729 |
2005 |
} |
} |
1730 |
2006 |
fe++; |
fe++; |
File trace/nd-trace.c changed (mode: 100644) (index c2de1f5..2265606) |
24 |
24 |
#include <syslog.h> |
#include <syslog.h> |
25 |
25 |
#include <unistd.h> |
#include <unistd.h> |
26 |
26 |
|
|
|
27 |
|
#include "ids.h" |
27 |
28 |
#include "shared.h" |
#include "shared.h" |
28 |
29 |
#include "tools.h" |
#include "tools.h" |
29 |
30 |
#include "decode_text.h" |
#include "decode_text.h" |
|
... |
... |
static void usage(void) |
45 |
46 |
exit(1); |
exit(1); |
46 |
47 |
} |
} |
47 |
48 |
|
|
48 |
|
static FILE *out; |
|
|
49 |
|
static FILE *outf; |
49 |
50 |
static unsigned int do_exit; |
static unsigned int do_exit; |
50 |
51 |
|
|
51 |
52 |
static uint8_t decode8(unsigned char *d, unsigned int *i) |
static uint8_t decode8(unsigned char *d, unsigned int *i) |
|
... |
... |
static int decode_whence(char *out, const size_t out_size, unsigned char *d, uns |
821 |
822 |
return ret; |
return ret; |
822 |
823 |
} |
} |
823 |
824 |
|
|
|
825 |
|
// TODO: we need to check if out is large enough |
|
826 |
|
static void decode_types(char *out, const size_t out_size, |
|
827 |
|
unsigned char *buf, unsigned int *i) |
|
828 |
|
{ |
|
829 |
|
unsigned int off = 0; |
|
830 |
|
uint16_t u16; |
|
831 |
|
int64_t d64; |
|
832 |
|
uint64_t u64; |
|
833 |
|
char *add = ""; |
|
834 |
|
unsigned char depth = 0; |
|
835 |
|
char tmp[4096]; |
|
836 |
|
|
|
837 |
|
do { |
|
838 |
|
unsigned char type = buf[*i]; *i = *i + 1; |
|
839 |
|
switch (type) { |
|
840 |
|
case ND_TYPE_ARRAY_START: |
|
841 |
|
strcat(out + off, add); off += strlen(add); |
|
842 |
|
out[off++] = '{'; |
|
843 |
|
depth++; |
|
844 |
|
add = ""; |
|
845 |
|
break; |
|
846 |
|
|
|
847 |
|
case ND_TYPE_ARRAY_END: |
|
848 |
|
out[off++] = '}'; |
|
849 |
|
depth--; |
|
850 |
|
add = ", "; |
|
851 |
|
break; |
|
852 |
|
|
|
853 |
|
case ND_TYPE_STRING: |
|
854 |
|
memcpy(&u16, buf + *i, 2); *i = *i + 2; |
|
855 |
|
u16 = be16toh(u16); |
|
856 |
|
bin2hex_ascii(tmp, buf + *i, u16); *i = *i + u16; |
|
857 |
|
off += sprintf(out + off, "%s'%s'", add, tmp); |
|
858 |
|
add = ", "; |
|
859 |
|
break; |
|
860 |
|
|
|
861 |
|
case ND_TYPE_TRUE: |
|
862 |
|
off += sprintf(out + off, "%strue", add); |
|
863 |
|
add = ", "; |
|
864 |
|
break; |
|
865 |
|
|
|
866 |
|
case ND_TYPE_FALSE: |
|
867 |
|
off += sprintf(out + off, "%sfalse", add); |
|
868 |
|
add = ", "; |
|
869 |
|
break; |
|
870 |
|
|
|
871 |
|
case ND_TYPE_NULL: |
|
872 |
|
off += sprintf(out + off, "%snull", add); |
|
873 |
|
add = ", "; |
|
874 |
|
break; |
|
875 |
|
|
|
876 |
|
case ND_TYPE_UNK: |
|
877 |
|
off += sprintf(out + off, "%s?", add); |
|
878 |
|
add = ", "; |
|
879 |
|
break; |
|
880 |
|
|
|
881 |
|
case ND_TYPE_LONG: |
|
882 |
|
memcpy(&d64, buf + *i, 8); *i = *i + 8; |
|
883 |
|
d64 = be64toh(d64); |
|
884 |
|
off += sprintf(out + off, "%s%ld", add, d64); |
|
885 |
|
add = ", "; |
|
886 |
|
break; |
|
887 |
|
|
|
888 |
|
case ND_TYPE_DOUBLE: |
|
889 |
|
memcpy(&d64, buf + *i, 8); *i = *i + 8; |
|
890 |
|
d64 = be64toh(d64); |
|
891 |
|
double d; |
|
892 |
|
memcpy(&d, &d64, 8); |
|
893 |
|
off += sprintf(out + off, "%s%f", add, d); |
|
894 |
|
add = ", "; |
|
895 |
|
break; |
|
896 |
|
|
|
897 |
|
case ND_TYPE_POINTER: |
|
898 |
|
memcpy(&u64, buf + *i, 8); *i = *i + 8; |
|
899 |
|
u64 = be64toh(u64); |
|
900 |
|
off += sprintf(out + off, "%s0x%lx", add, u64); |
|
901 |
|
add = ", "; |
|
902 |
|
break; |
|
903 |
|
|
|
904 |
|
} |
|
905 |
|
} while (depth > 0); |
|
906 |
|
} |
|
907 |
|
|
824 |
908 |
static void decode_func(const uint32_t parent, unsigned char *d) |
static void decode_func(const uint32_t parent, unsigned char *d) |
825 |
909 |
{ |
{ |
826 |
910 |
unsigned int i = 0; |
unsigned int i = 0; |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
839 |
923 |
type = d[i++]; |
type = d[i++]; |
840 |
924 |
uint32_t pid = decode32(d, &i); |
uint32_t pid = decode32(d, &i); |
841 |
925 |
uint32_t tid = decode32(d, &i); |
uint32_t tid = decode32(d, &i); |
842 |
|
//fprintf(out, "%s: t=%lu func_len=%hu func=[%s] type=%c pid=%u tid=%u\n", |
|
|
926 |
|
//fprintf(outf, "%s: t=%lu func_len=%hu func=[%s] type=%c pid=%u tid=%u\n", |
843 |
927 |
// __func__, t, func_len, func, type, pid, tid); |
// __func__, t, func_len, func, type, pid, tid); |
844 |
928 |
|
|
845 |
929 |
switch (func[0]) { |
switch (func[0]) { |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
919 |
1003 |
} else if (strcmp(func, "curl_easy_cleanup") == 0) { |
} else if (strcmp(func, "curl_easy_cleanup") == 0) { |
920 |
1004 |
uint64_t handle = decode64(d, &i); |
uint64_t handle = decode64(d, &i); |
921 |
1005 |
sprintf(line, "(0x%lx)", handle); |
sprintf(line, "(0x%lx)", handle); |
|
1006 |
|
} else if (strcmp(func, "curl_init") == 0) { // php |
|
1007 |
|
uint64_t handle = decode64(d, &i); |
|
1008 |
|
uint16_t len = decode16(d, &i); |
|
1009 |
|
if (len == 0) { |
|
1010 |
|
sprintf(line, "() = 0x%lx", handle); |
|
1011 |
|
} else { |
|
1012 |
|
char url[len * 4 + 1]; |
|
1013 |
|
bin2hex_ascii(url, d + i, len); i += len; |
|
1014 |
|
sprintf(line, "('%s') = 0x%lx", url, handle); |
|
1015 |
|
} |
|
1016 |
|
} else if (strcmp(func, "curl_setopt") == 0) { // php |
|
1017 |
|
uint64_t handle = decode64(d, &i); |
|
1018 |
|
uint8_t oplen = decode8(d, &i); |
|
1019 |
|
char op[oplen * 4 + 1]; |
|
1020 |
|
bin2hex_ascii(op, d + i, oplen); i += oplen; |
|
1021 |
|
char types[4096]; |
|
1022 |
|
decode_types(types, sizeof(types), d, &i); |
|
1023 |
|
if (type == 'r') { |
|
1024 |
|
uint8_t ret = decode8(d, &i); |
|
1025 |
|
snprintf(rest, sizeof(rest), " = %s", ret == 1 ? "ok" : "nok"); |
|
1026 |
|
} |
|
1027 |
|
sprintf(line, "(0x%lx, %s, %s)%s", handle, op, types, rest); |
|
1028 |
|
} else if (strcmp(func, "curl_exec") == 0) { // php |
|
1029 |
|
uint64_t handle = decode64(d, &i); |
|
1030 |
|
if (type == 'r') { |
|
1031 |
|
uint8_t ret = decode8(d, &i); |
|
1032 |
|
if (ret == 2) { |
|
1033 |
|
uint16_t sret_len = decode16(d, &i); |
|
1034 |
|
char sret[sret_len * 4 + 1]; |
|
1035 |
|
bin2hex_ascii(sret, d + i, sret_len); i += sret_len; |
|
1036 |
|
snprintf(rest, sizeof(rest), " = '%s'", sret); |
|
1037 |
|
} else if (ret == 0) { |
|
1038 |
|
snprintf(rest, sizeof(rest), " = nok"); |
|
1039 |
|
} else { |
|
1040 |
|
snprintf(rest, sizeof(rest), " = ok"); |
|
1041 |
|
} |
|
1042 |
|
} |
|
1043 |
|
sprintf(line, "(0x%lx)%s", handle, rest); |
922 |
1044 |
} else if (strcmp(func, "curl_easy_init") == 0) { |
} else if (strcmp(func, "curl_easy_init") == 0) { |
923 |
1045 |
uint64_t handle = decode64(d, &i); |
uint64_t handle = decode64(d, &i); |
924 |
1046 |
sprintf(line, "() = 0x%lx", handle); |
sprintf(line, "() = 0x%lx", handle); |
925 |
1047 |
} else if (strcmp(func, "curl_easy_perform") == 0) { |
} else if (strcmp(func, "curl_easy_perform") == 0) { |
926 |
|
uint64_t handle = decode64(d, &i); |
|
927 |
|
if (type == 'r') { |
|
928 |
|
int ret = decode32(d, &i); |
|
929 |
|
nd_decode_curl_code(rest, sizeof(rest), ret); |
|
930 |
|
sprintf(line, "(0x%lx) = %s", handle, rest); |
|
|
1048 |
|
if (type == 'm') { |
|
1049 |
|
uint8_t len = decode8(d, &i); |
|
1050 |
|
char info[len * 4 + 1]; |
|
1051 |
|
bin2hex_ascii(info, d + i, len); i += len; |
|
1052 |
|
uint64_t handle = decode64(d, &i); |
|
1053 |
|
uint16_t post_len = decode16(d, &i); |
|
1054 |
|
char post[post_len * 4 + 1]; |
|
1055 |
|
bin2hex_ascii(post, d + i, post_len); i += post_len; |
|
1056 |
|
sprintf(line, "(0x%lx) %s: %s", handle, info, post); |
931 |
1057 |
} else { |
} else { |
932 |
|
sprintf(line, "(0x%lx)", handle); |
|
|
1058 |
|
uint64_t handle = decode64(d, &i); |
|
1059 |
|
if (type == 'r') { |
|
1060 |
|
int ret = decode32(d, &i); |
|
1061 |
|
nd_decode_curl_code(rest, sizeof(rest), ret); |
|
1062 |
|
sprintf(line, "(0x%lx) = %s", handle, rest); |
|
1063 |
|
} else { |
|
1064 |
|
sprintf(line, "(0x%lx)", handle); |
|
1065 |
|
} |
933 |
1066 |
} |
} |
934 |
1067 |
} else if (strcmp(func, "curl_easy_setopt") == 0) { |
} else if (strcmp(func, "curl_easy_setopt") == 0) { |
935 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1068 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
936 |
1069 |
uint64_t handle = decode64(d, &i); |
uint64_t handle = decode64(d, &i); |
937 |
1070 |
uint8_t type = decode8(d, &i); |
uint8_t type = decode8(d, &i); |
938 |
1071 |
uint8_t option_len = decode8(d, &i); |
uint8_t option_len = decode8(d, &i); |
939 |
1072 |
char option[option_len * 4 + 1]; |
char option[option_len * 4 + 1]; |
940 |
1073 |
bin2hex_ascii(option, d + i, option_len); i += option_len; |
bin2hex_ascii(option, d + i, option_len); i += option_len; |
941 |
|
if ((type == 0) || (type == 2)) { // long |
|
|
1074 |
|
if ((type == 0) || (type == 2)) { // long or off_t |
942 |
1075 |
snprintf(rest, sizeof(rest), "%ld", decode64(d, &i)); |
snprintf(rest, sizeof(rest), "%ld", decode64(d, &i)); |
943 |
|
} else if (type == 4) { // string |
|
944 |
|
uint16_t len = decode16(d, &i); |
|
945 |
|
char s[len * 4 + 1]; |
|
946 |
|
bin2hex_ascii(s, d + i, len); i += len; |
|
947 |
|
snprintf(rest, sizeof(rest), "'%s'", s); |
|
|
1076 |
|
} else if ((type == 3) || (type == 4)) { // object or string |
|
1077 |
|
long len = decode64(d, &i); |
|
1078 |
|
if (len >= 0) { |
|
1079 |
|
uint16_t s_len = decode16(d, &i); |
|
1080 |
|
char s[s_len * 4 + 1]; |
|
1081 |
|
bin2hex_ascii(s, d + i, len); i += s_len; |
|
1082 |
|
snprintf(rest, sizeof(rest), "'%s'", s); |
|
1083 |
|
} else { |
|
1084 |
|
snprintf(rest, sizeof(rest), |
|
1085 |
|
"[cannot dump yet because size was not set yet]"); |
|
1086 |
|
} |
948 |
1087 |
} else if (type == 5) { // slist |
} else if (type == 5) { // slist |
949 |
1088 |
decode_string_array(rest, sizeof(rest), d, &i); |
decode_string_array(rest, sizeof(rest), d, &i); |
950 |
1089 |
} else { |
} else { |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
953 |
1092 |
int ret = decode32(d, &i); |
int ret = decode32(d, &i); |
954 |
1093 |
char sret[32]; |
char sret[32]; |
955 |
1094 |
nd_decode_curl_code(sret, sizeof(sret), ret); |
nd_decode_curl_code(sret, sizeof(sret), ret); |
956 |
|
sprintf(line, "(0x%lx, CURLOPT_%s, %s) = %s", |
|
|
1095 |
|
sprintf(line, "(0x%lx, %s, %s) = %s", |
957 |
1096 |
handle, option, rest, sret); |
handle, option, rest, sret); |
958 |
1097 |
} break; |
} break; |
959 |
1098 |
|
|
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1082 |
1221 |
} |
} |
1083 |
1222 |
} |
} |
1084 |
1223 |
} else if (strcmp(func, "getsockopt") == 0) { |
} else if (strcmp(func, "getsockopt") == 0) { |
1085 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1224 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1086 |
1225 |
int sock = decode32(d, &i); |
int sock = decode32(d, &i); |
1087 |
1226 |
char level[32], optname[32]; |
char level[32], optname[32]; |
1088 |
1227 |
int ilevel = decode_sock_level(level, sizeof(level), d, &i); |
int ilevel = decode_sock_level(level, sizeof(level), d, &i); |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1097 |
1236 |
|
|
1098 |
1237 |
case 'l': |
case 'l': |
1099 |
1238 |
if (strcmp(func, "listen") == 0) { |
if (strcmp(func, "listen") == 0) { |
1100 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1239 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1101 |
1240 |
int sock = decode32(d, &i); |
int sock = decode32(d, &i); |
1102 |
1241 |
int backlog = decode32(d, &i); |
int backlog = decode32(d, &i); |
1103 |
1242 |
decode_ret_int(rest, sizeof(rest), d, &i); |
decode_ret_int(rest, sizeof(rest), d, &i); |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1136 |
1275 |
decode_bool(" = ", rest, sizeof(rest), d, &i); |
decode_bool(" = ", rest, sizeof(rest), d, &i); |
1137 |
1276 |
sprintf(line, "(link=0x%lx)%s", link, rest); |
sprintf(line, "(link=0x%lx)%s", link, rest); |
1138 |
1277 |
} else if (strcmp(func, "mysqli_connect") == 0) { |
} else if (strcmp(func, "mysqli_connect") == 0) { |
1139 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1278 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1140 |
1279 |
uint32_t cs_len = decode32(d, &i); |
uint32_t cs_len = decode32(d, &i); |
1141 |
1280 |
char cs[cs_len * 4 + 1]; |
char cs[cs_len * 4 + 1]; |
1142 |
1281 |
bin2hex_ascii(cs, d + i, cs_len); i += cs_len; |
bin2hex_ascii(cs, d + i, cs_len); i += cs_len; |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1208 |
1347 |
decode_bool(" = ", rest, sizeof(rest), d, &i); |
decode_bool(" = ", rest, sizeof(rest), d, &i); |
1209 |
1348 |
sprintf(line, "(link=0x%lx, '%s', flags='%s')%s", link, cs, flags, rest); |
sprintf(line, "(link=0x%lx, '%s', flags='%s')%s", link, cs, flags, rest); |
1210 |
1349 |
} else if (strcmp(func, "mysqli_stmt_bind_param") == 0) { |
} else if (strcmp(func, "mysqli_stmt_bind_param") == 0) { |
1211 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1350 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1212 |
1351 |
uint64_t stmt = decode64(d, &i); |
uint64_t stmt = decode64(d, &i); |
1213 |
1352 |
unsigned short types_len = decode16(d, &i); |
unsigned short types_len = decode16(d, &i); |
1214 |
1353 |
char types[types_len * 4 + 1]; |
char types[types_len * 4 + 1]; |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1218 |
1357 |
sprintf(line, "(stmt=0x%lx, types='%s', ...)%s", |
sprintf(line, "(stmt=0x%lx, types='%s', ...)%s", |
1219 |
1358 |
stmt, types, rest); |
stmt, types, rest); |
1220 |
1359 |
} else if (strcmp(func, "mysqli_stmt_execute") == 0) { |
} else if (strcmp(func, "mysqli_stmt_execute") == 0) { |
1221 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1360 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1222 |
1361 |
uint64_t stmt = decode64(d, &i); |
uint64_t stmt = decode64(d, &i); |
1223 |
1362 |
if (type == 'c') { |
if (type == 'c') { |
1224 |
1363 |
decode_query_params(rest, sizeof(rest), d, &i); |
decode_query_params(rest, sizeof(rest), d, &i); |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1352 |
1491 |
sprintf(line, "(0x%lx)", h); |
sprintf(line, "(0x%lx)", h); |
1353 |
1492 |
} else if ((strcmp(func, "pg_connect") == 0) |
} else if ((strcmp(func, "pg_connect") == 0) |
1354 |
1493 |
|| (strcmp(func, "pg_pconnect") == 0)) { |
|| (strcmp(func, "pg_pconnect") == 0)) { |
1355 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1494 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1356 |
1495 |
uint32_t cs_len = decode32(d, &i); |
uint32_t cs_len = decode32(d, &i); |
1357 |
1496 |
char cs[cs_len * 4 + 1]; |
char cs[cs_len * 4 + 1]; |
1358 |
1497 |
bin2hex_ascii(cs, d + i, cs_len); i += cs_len; |
bin2hex_ascii(cs, d + i, cs_len); i += cs_len; |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1369 |
1508 |
|| (strcmp(func, "pg_query_params") == 0) |
|| (strcmp(func, "pg_query_params") == 0) |
1370 |
1509 |
|| (strcmp(func, "pg_send_query") == 0) |
|| (strcmp(func, "pg_send_query") == 0) |
1371 |
1510 |
|| (strcmp(func, "pg_send_query_params") == 0)) { |
|| (strcmp(func, "pg_send_query_params") == 0)) { |
1372 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1511 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1373 |
1512 |
uint64_t dbh = decode64(d, &i); |
uint64_t dbh = decode64(d, &i); |
1374 |
1513 |
uint16_t q_len = decode16(d, &i); |
uint16_t q_len = decode16(d, &i); |
1375 |
1514 |
char q[q_len * 4 + 1]; |
char q[q_len * 4 + 1]; |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1393 |
1532 |
} |
} |
1394 |
1533 |
sprintf(line, "(h=0x%lx, '%s')%s", dbh, q, rest); |
sprintf(line, "(h=0x%lx, '%s')%s", dbh, q, rest); |
1395 |
1534 |
} else if (strcmp(func, "pg_get_result") == 0) { |
} else if (strcmp(func, "pg_get_result") == 0) { |
1396 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1535 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1397 |
1536 |
uint64_t dbh = decode64(d, &i); |
uint64_t dbh = decode64(d, &i); |
1398 |
1537 |
if (type == 'r') { |
if (type == 'r') { |
1399 |
1538 |
uint64_t res = decode64(d, &i); |
uint64_t res = decode64(d, &i); |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1404 |
1543 |
} |
} |
1405 |
1544 |
sprintf(line, "(h=0x%lx)%s", dbh, rest); |
sprintf(line, "(h=0x%lx)%s", dbh, rest); |
1406 |
1545 |
} else if (strcmp(func, "pthread_join") == 0) { |
} else if (strcmp(func, "pthread_join") == 0) { |
1407 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1546 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1408 |
1547 |
uint64_t thread = decode64(d, &i); |
uint64_t thread = decode64(d, &i); |
1409 |
1548 |
int ret = decode_ret_int(rest, sizeof(rest), d, &i); |
int ret = decode_ret_int(rest, sizeof(rest), d, &i); |
1410 |
1549 |
uint64_t retval = 0; |
uint64_t retval = 0; |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1413 |
1552 |
sprintf(line, "(thread=0x%lx, retval=0x%lx)%s", |
sprintf(line, "(thread=0x%lx, retval=0x%lx)%s", |
1414 |
1553 |
thread, retval, rest); |
thread, retval, rest); |
1415 |
1554 |
} else if (strcmp(func, "pthread_attr_setstacksize") == 0) { |
} else if (strcmp(func, "pthread_attr_setstacksize") == 0) { |
1416 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1555 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1417 |
1556 |
uint64_t attr = decode64(d, &i); |
uint64_t attr = decode64(d, &i); |
1418 |
1557 |
size_t stack_size = decode64(d, &i); |
size_t stack_size = decode64(d, &i); |
1419 |
1558 |
decode_ret_int(rest, sizeof(rest), d, &i); |
decode_ret_int(rest, sizeof(rest), d, &i); |
1420 |
1559 |
sprintf(line, "(attr=0x%lx, %zu)%s", |
sprintf(line, "(attr=0x%lx, %zu)%s", |
1421 |
1560 |
attr, stack_size, rest); |
attr, stack_size, rest); |
1422 |
1561 |
} else if (strcmp(func, "pthread_create") == 0) { |
} else if (strcmp(func, "pthread_create") == 0) { |
1423 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1562 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1424 |
1563 |
uint64_t thread = decode64(d, &i); |
uint64_t thread = decode64(d, &i); |
1425 |
1564 |
uint64_t attr = decode64(d, &i); |
uint64_t attr = decode64(d, &i); |
1426 |
1565 |
uint64_t arg = decode64(d, &i); |
uint64_t arg = decode64(d, &i); |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1428 |
1567 |
sprintf(line, "(thread=0x%lx, attr=0x%lx, arg=0x%lx)%s", |
sprintf(line, "(thread=0x%lx, attr=0x%lx, arg=0x%lx)%s", |
1429 |
1568 |
thread, attr, arg, rest); |
thread, attr, arg, rest); |
1430 |
1569 |
} else if (strcmp(func, "pthread_setname_np") == 0) { |
} else if (strcmp(func, "pthread_setname_np") == 0) { |
1431 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1570 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1432 |
1571 |
uint64_t thread = decode64(d, &i); |
uint64_t thread = decode64(d, &i); |
1433 |
1572 |
uint16_t len = decode16(d, &i); |
uint16_t len = decode16(d, &i); |
1434 |
1573 |
char name[len * 4 + 1]; |
char name[len * 4 + 1]; |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1545 |
1684 |
} |
} |
1546 |
1685 |
} else if (strcmp(func, "setsockopt") == 0) { |
} else if (strcmp(func, "setsockopt") == 0) { |
1547 |
1686 |
int sock = decode32(d, &i); |
int sock = decode32(d, &i); |
1548 |
|
if (type == 'c') { |
|
1549 |
|
char level[32], optname[32]; |
|
1550 |
|
int ilevel = decode_sock_level(level, sizeof(level), d, &i); |
|
1551 |
|
decode_sock_optname(optname, sizeof(optname), ilevel, d, &i); |
|
1552 |
|
socklen_t optlen = decode32(d, &i); |
|
1553 |
|
char optval[optlen * 2 + 1]; |
|
1554 |
|
bin2hex(optval, d + i, optlen); i+= optlen; |
|
1555 |
|
sprintf(line, "(%d, %s, %s, 0x%s, %u)", |
|
1556 |
|
sock, level, optname, optval, optlen); |
|
1557 |
|
} else { |
|
1558 |
|
decode_ret_int(rest, sizeof(rest), d, &i); |
|
1559 |
|
sprintf(line, "(%d)%s", sock, rest); |
|
1560 |
|
} |
|
|
1687 |
|
char level[32], optname[32]; |
|
1688 |
|
int ilevel = decode_sock_level(level, sizeof(level), d, &i); |
|
1689 |
|
decode_sock_optname(optname, sizeof(optname), ilevel, d, &i); |
|
1690 |
|
socklen_t optlen = decode32(d, &i); |
|
1691 |
|
char optval[optlen * 2 + 1]; |
|
1692 |
|
bin2hex(optval, d + i, optlen); i+= optlen; |
|
1693 |
|
decode_ret_int(rest, sizeof(rest), d, &i); |
|
1694 |
|
sprintf(line, "(%d, %s, %s, 0x%s, %u)%s", |
|
1695 |
|
sock, level, optname, optval, optlen, rest); |
1561 |
1696 |
} else if (strcmp(func, "socket") == 0) { |
} else if (strcmp(func, "socket") == 0) { |
1562 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1697 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1563 |
1698 |
int xdomain = decode32(d, &i); |
int xdomain = decode32(d, &i); |
1564 |
1699 |
int xtype = decode32(d, &i); |
int xtype = decode32(d, &i); |
1565 |
1700 |
int xprotocol = decode32(d, &i); |
int xprotocol = decode32(d, &i); |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1604 |
1739 |
decode_sqlite3_ret(rest, sizeof(rest), d, &i); |
decode_sqlite3_ret(rest, sizeof(rest), d, &i); |
1605 |
1740 |
sprintf(line, "(0x%lx)%s%s", stmt, rest[0] ? " = " : "", rest); |
sprintf(line, "(0x%lx)%s%s", stmt, rest[0] ? " = " : "", rest); |
1606 |
1741 |
} else if (strcmp(func, "sqlite3_open_v2") == 0) { |
} else if (strcmp(func, "sqlite3_open_v2") == 0) { |
1607 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1742 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1608 |
1743 |
uint16_t filename_len = decode16(d, &i); |
uint16_t filename_len = decode16(d, &i); |
1609 |
1744 |
char filename[filename_len * 4 + 1]; |
char filename[filename_len * 4 + 1]; |
1610 |
1745 |
bin2hex_ascii(filename, d + i, filename_len); i += filename_len; |
bin2hex_ascii(filename, d + i, filename_len); i += filename_len; |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1627 |
1762 |
filename, pdb, flags, vfs, err); |
filename, pdb, flags, vfs, err); |
1628 |
1763 |
} |
} |
1629 |
1764 |
} else if (strcmp(func, "sqlite3_prepare_v2") == 0) { |
} else if (strcmp(func, "sqlite3_prepare_v2") == 0) { |
1630 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1765 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1631 |
1766 |
uint64_t h = decode64(d, &i); |
uint64_t h = decode64(d, &i); |
1632 |
1767 |
uint32_t sql_len = decode32(d, &i); |
uint32_t sql_len = decode32(d, &i); |
1633 |
1768 |
char sql[sql_len * 4 + 1]; |
char sql[sql_len * 4 + 1]; |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1644 |
1779 |
h, sql, nByte, stmt, err); |
h, sql, nByte, stmt, err); |
1645 |
1780 |
} |
} |
1646 |
1781 |
} else if (strcmp(func, "sqlite3_step") == 0) { |
} else if (strcmp(func, "sqlite3_step") == 0) { |
1647 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1782 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1648 |
1783 |
uint64_t stmt = decode64(d, &i); |
uint64_t stmt = decode64(d, &i); |
1649 |
1784 |
if (type == 'c') { |
if (type == 'c') { |
1650 |
1785 |
sprintf(line, "(0x%lx)", stmt); |
sprintf(line, "(0x%lx)", stmt); |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1666 |
1801 |
sprintf(line, "('%s', {%s})%s", pathname, sstat, rest); |
sprintf(line, "('%s', {%s})%s", pathname, sstat, rest); |
1667 |
1802 |
} |
} |
1668 |
1803 |
} else if (strcmp(func, "syslog") == 0) { |
} else if (strcmp(func, "syslog") == 0) { |
1669 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); |
|
|
1804 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP[%s][%c]: %s\n", func, type, dump); |
1670 |
1805 |
char sprio[32]; |
char sprio[32]; |
1671 |
1806 |
decode_syslog_prio(sprio, sizeof(sprio), d, &i); |
decode_syslog_prio(sprio, sizeof(sprio), d, &i); |
1672 |
1807 |
int len = decode16(d, &i); |
int len = decode16(d, &i); |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1699 |
1834 |
|
|
1700 |
1835 |
case 'w': |
case 'w': |
1701 |
1836 |
if (strcmp(func, "write") == 0) { |
if (strcmp(func, "write") == 0) { |
1702 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP: %s\n", dump); |
|
|
1837 |
|
//char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(outf, "DUMP: %s\n", dump); |
1703 |
1838 |
int fd = decode32(d, &i); |
int fd = decode32(d, &i); |
1704 |
1839 |
size_t count = decode64(d, &i); |
size_t count = decode64(d, &i); |
1705 |
1840 |
if (type == 'c') { |
if (type == 'c') { |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1717 |
1852 |
} break; |
} break; |
1718 |
1853 |
} |
} |
1719 |
1854 |
if (line[0] == '\0') { |
if (line[0] == '\0') { |
1720 |
|
fprintf(out, "I do not know how to decode func [%s] type [%c]!\n", |
|
|
1855 |
|
fprintf(outf, "I do not know how to decode func [%s] type [%c]!\n", |
1721 |
1856 |
func, type); |
func, type); |
1722 |
1857 |
return; |
return; |
1723 |
1858 |
} |
} |
|
... |
... |
static void decode_func(const uint32_t parent, unsigned char *d) |
1730 |
1865 |
space[max] = '\0'; |
space[max] = '\0'; |
1731 |
1866 |
|
|
1732 |
1867 |
if (pid == tid) |
if (pid == tid) |
1733 |
|
fprintf(out, "%lu.%03lu %10u%s %s%s\n", |
|
|
1868 |
|
fprintf(outf, "%lu.%03lu %10u%s %s%s\n", |
1734 |
1869 |
t / 1000, t % 1000, pid, space, func, line); |
t / 1000, t % 1000, pid, space, func, line); |
1735 |
1870 |
else |
else |
1736 |
|
fprintf(out, "%lu.%03lu %10u %10u%s %s%s\n", |
|
|
1871 |
|
fprintf(outf, "%lu.%03lu %10u %10u%s %s%s\n", |
1737 |
1872 |
t / 1000, t % 1000, pid, tid, space, func, line); |
t / 1000, t % 1000, pid, tid, space, func, line); |
1738 |
1873 |
} |
} |
1739 |
1874 |
|
|
|
... |
... |
static void decode(const pid_t parent, unsigned char *d, size_t len) |
1746 |
1881 |
if (type == 'F') { |
if (type == 'F') { |
1747 |
1882 |
decode_func(parent, d + i); |
decode_func(parent, d + i); |
1748 |
1883 |
} else { |
} else { |
1749 |
|
fprintf(out, "I do not know how to decode type [%c]!\n", type); |
|
|
1884 |
|
fprintf(outf, "I do not know how to decode type [%c]!\n", type); |
1750 |
1885 |
char dump[len * 4 + 1]; |
char dump[len * 4 + 1]; |
1751 |
1886 |
bin2hex_ascii(dump, d, len); |
bin2hex_ascii(dump, d, len); |
1752 |
|
fprintf(out, "Decode %s\n", dump); |
|
|
1887 |
|
fprintf(outf, "Decode %s\n", dump); |
1753 |
1888 |
} |
} |
1754 |
1889 |
} |
} |
1755 |
1890 |
|
|
|
... |
... |
int main(int argc, char *argv[]) |
1792 |
1927 |
} |
} |
1793 |
1928 |
|
|
1794 |
1929 |
if (!out_file) { |
if (!out_file) { |
1795 |
|
out = stderr; |
|
|
1930 |
|
outf = stderr; |
1796 |
1931 |
} else { |
} else { |
1797 |
1932 |
fprintf(stderr, "Saving output to [%s]\n", out_file); |
fprintf(stderr, "Saving output to [%s]\n", out_file); |
1798 |
|
out = fopen(out_file, "w"); |
|
1799 |
|
if (!out) { |
|
|
1933 |
|
outf = fopen(out_file, "w"); |
|
1934 |
|
if (!outf) { |
1800 |
1935 |
fprintf(stderr, "Error: cannot open [%s]: %m\n", out_file); |
fprintf(stderr, "Error: cannot open [%s]: %m\n", out_file); |
1801 |
1936 |
return 1; |
return 1; |
1802 |
1937 |
} |
} |
1803 |
1938 |
} |
} |
1804 |
|
setlinebuf(out); |
|
|
1939 |
|
setlinebuf(outf); |
1805 |
1940 |
|
|
1806 |
1941 |
//pid_t my_pid = getpid(); |
//pid_t my_pid = getpid(); |
1807 |
1942 |
|
|
|
... |
... |
int main(int argc, char *argv[]) |
1858 |
1993 |
|
|
1859 |
1994 |
fstat(sm[i], &s); |
fstat(sm[i], &s); |
1860 |
1995 |
if (s.st_size == 0) { |
if (s.st_size == 0) { |
1861 |
|
//fprintf(out, "%u: Shared memory size is zero!\n", pids[i]); |
|
|
1996 |
|
//fprintf(outf, "%u: Shared memory size is zero!\n", pids[i]); |
1862 |
1997 |
continue; |
continue; |
1863 |
1998 |
} |
} |
1864 |
|
//fprintf(out, "%u: Shared memory size: %ld\n", pids[i], s.st_size); |
|
|
1999 |
|
//fprintf(outf, "%u: Shared memory size: %ld\n", pids[i], s.st_size); |
1865 |
2000 |
|
|
1866 |
2001 |
r = sem_wait(&shared[i]->sem1); |
r = sem_wait(&shared[i]->sem1); |
1867 |
2002 |
if (r == -1) { |
if (r == -1) { |
|
... |
... |
int main(int argc, char *argv[]) |
1877 |
2012 |
|
|
1878 |
2013 |
if (version[i] == 0) { |
if (version[i] == 0) { |
1879 |
2014 |
version[i] = shared[i]->version; |
version[i] = shared[i]->version; |
1880 |
|
fprintf(out, "%u: version is %hhu\n", pids[i], version[i]); |
|
|
2015 |
|
fprintf(outf, "%u: version is %hhu\n", pids[i], version[i]); |
1881 |
2016 |
} |
} |
1882 |
2017 |
|
|
1883 |
2018 |
// tail-1 points to last value available |
// tail-1 points to last value available |
|
... |
... |
int main(int argc, char *argv[]) |
1888 |
2023 |
else // 01t345h78 => ava = 2 + (9 - 6) = 5 |
else // 01t345h78 => ava = 2 + (9 - 6) = 5 |
1889 |
2024 |
ava = shared[i]->tail + (shared[i]->buf_size - shared[i]->head); |
ava = shared[i]->tail + (shared[i]->buf_size - shared[i]->head); |
1890 |
2025 |
|
|
1891 |
|
//fprintf(out, "RING[%u]: head=%u tail=%u new_tail=%u msgs_lost=%u [after lock]\n", |
|
|
2026 |
|
//fprintf(outf, "RING[%u]: head=%u tail=%u new_tail=%u msgs_lost=%u [after lock]\n", |
1892 |
2027 |
// i, shared[i]->head, shared[i]->tail, shared[i]->new_tail, shared[i]->msgs_lost); |
// i, shared[i]->head, shared[i]->tail, shared[i]->new_tail, shared[i]->msgs_lost); |
1893 |
2028 |
|
|
1894 |
2029 |
//char dump[ava * 4 + 1]; |
//char dump[ava * 4 + 1]; |
1895 |
2030 |
//bin2hex_ascii(dump, shared[i]->buf + shared[i]->head, ava); |
//bin2hex_ascii(dump, shared[i]->buf + shared[i]->head, ava); |
1896 |
|
//fprintf(out, "DUMP0[%hu]: %s\n", ava, dump); |
|
|
2031 |
|
//fprintf(outf, "DUMP0[%hu]: %s\n", ava, dump); |
1897 |
2032 |
|
|
1898 |
2033 |
while (ava >= 2) { |
while (ava >= 2) { |
1899 |
2034 |
unsigned short plen; |
unsigned short plen; |
|
... |
... |
int main(int argc, char *argv[]) |
1908 |
2043 |
plen = be16toh(plen); |
plen = be16toh(plen); |
1909 |
2044 |
} |
} |
1910 |
2045 |
if (plen > ava) { |
if (plen > ava) { |
1911 |
|
fprintf(out, "%u: Too short packet: plen=%hu > ava[%u]!\n", |
|
|
2046 |
|
fprintf(outf, "%u: Too short packet: plen=%hu > ava[%u]!\n", |
1912 |
2047 |
pids[i], plen, ava); |
pids[i], plen, ava); |
1913 |
2048 |
break; |
break; |
1914 |
2049 |
} |
} |
|
... |
... |
int main(int argc, char *argv[]) |
1918 |
2053 |
} else { // split data! dddt...hddd size=11, head=7, plen=8 => max=4 |
} else { // split data! dddt...hddd size=11, head=7, plen=8 => max=4 |
1919 |
2054 |
unsigned int max = shared[i]->buf_size - shared[i]->head; |
unsigned int max = shared[i]->buf_size - shared[i]->head; |
1920 |
2055 |
if (max > plen) max = plen; |
if (max > plen) max = plen; |
1921 |
|
//fprintf(out, " DEBUG: split data. max=%u\n", max); |
|
1922 |
|
//fprintf(out, " DEBUG: copy to buf from %p+%u, %u bytes\n", shared[i]->buf, shared[i]->head, max); |
|
|
2056 |
|
//fprintf(outf, " DEBUG: split data. max=%u\n", max); |
|
2057 |
|
//fprintf(outf, " DEBUG: copy to buf from %p+%u, %u bytes\n", shared[i]->buf, shared[i]->head, max); |
1923 |
2058 |
memcpy(buf, shared[i]->buf + shared[i]->head, max); |
memcpy(buf, shared[i]->buf + shared[i]->head, max); |
1924 |
|
//fprintf(out, " DEBUG: copy to buf+%u from %p, %u bytes\n", max, shared[i]->buf, plen - max); |
|
|
2059 |
|
//fprintf(outf, " DEBUG: copy to buf+%u from %p, %u bytes\n", max, shared[i]->buf, plen - max); |
1925 |
2060 |
memcpy(buf + max, shared[i]->buf, plen - max); |
memcpy(buf + max, shared[i]->buf, plen - max); |
1926 |
2061 |
p = buf; |
p = buf; |
1927 |
2062 |
} |
} |
|
... |
... |
int main(int argc, char *argv[]) |
1929 |
2064 |
if (0) { |
if (0) { |
1930 |
2065 |
char dump[plen * 4 + 1]; |
char dump[plen * 4 + 1]; |
1931 |
2066 |
bin2hex_ascii(dump, p, plen); |
bin2hex_ascii(dump, p, plen); |
1932 |
|
fprintf(out, "%u: DUMP[%hu] head=%u: %s\n", |
|
|
2067 |
|
fprintf(outf, "%u: DUMP[%hu] head=%u: %s\n", |
1933 |
2068 |
pids[i], plen, shared[i]->head, dump); |
pids[i], plen, shared[i]->head, dump); |
1934 |
2069 |
} |
} |
1935 |
2070 |
|
|
|
... |
... |
int main(int argc, char *argv[]) |
1937 |
2072 |
|
|
1938 |
2073 |
shared[i]->head = (shared[i]->head + plen) % shared[i]->buf_size; |
shared[i]->head = (shared[i]->head + plen) % shared[i]->buf_size; |
1939 |
2074 |
ava -= plen; |
ava -= plen; |
1940 |
|
//fprintf(out, " DEBUG: ava[%u] after substracting plen[%hu]; no_pids=%u\n", ava, plen, no_pids); |
|
|
2075 |
|
//fprintf(outf, " DEBUG: ava[%u] after substracting plen[%hu]; no_pids=%u\n", ava, plen, no_pids); |
1941 |
2076 |
} |
} |
1942 |
2077 |
} |
} |
1943 |
2078 |
|
|