void detect_cdimage(SECTION *section, int level) { int mode, off; unsigned char *buf; SOURCE *s; if (get_buffer(section, 0, 2352, (void **)&buf) < 2352) return; /* check sync bytes as signature */ if (memcmp(buf, syncbytes, 12) != 0) return; /* get mode of the track -- this determines sector layout */ mode = buf[15]; if (mode == 1) { /* standard data track */ print_line(level, "Raw CD image, Mode 1"); off = 16; } else if (mode == 2) { /* free-form track, assume XA form 1 */ print_line(level, "Raw CD image, Mode 2, assuming Form 1"); off = 24; } else return; /* create and analyze wrapped source */ s = init_cdimage_source(section->source, section->pos + off); analyze_source(s, level); close_source(s); /* don't run other analyzers */ stop_detect(); }
void source_accept_cb(uv_stream_t *server, int status) { struct source_context *source = new_source(); struct target_context *target = new_target(); source->target = target; target->source = source; uv_tcp_init(server->loop, &source->handle.tcp); uv_tcp_init(server->loop, &target->handle.tcp); uv_tcp_nodelay(&source->handle.tcp, 0); uv_tcp_nodelay(&target->handle.tcp, 0); uv_tcp_keepalive(&source->handle.tcp, 1, 60); uv_tcp_keepalive(&target->handle.tcp, 1, 60); int rc = uv_accept(server, &source->handle.stream); if (rc == 0) { connect_to_target(target); } else { logger_log(LOG_ERR, "accept error: %s", uv_strerror(rc)); close_source(source); close_target(target); } }
static void source_recv_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { struct source_context *source = stream->data; struct target_context *target = source->target; if (nread > 0) { if (mode == TUNNEL_MODE_CLIENT) { int clen = nread + PRIMITIVE_BYTES; uint8_t *c = source->packet.buf + HEADER_BYTES; int rc = crypto_encrypt(c, (uint8_t*)buf->base, nread); if (rc) { goto error; } forward_to_target(target, c, clen); } else { struct packet *packet = &source->packet; int rc = packet_filter(packet, buf->base, nread); if (rc == PACKET_COMPLETED) { uint8_t *m = packet->buf; int mlen = packet->size - PRIMITIVE_BYTES; int err = crypto_decrypt(m, packet->buf, packet->size); if (err) { goto error; } forward_to_target(target, m, mlen); } else if (rc == PACKET_INVALID) { goto error; } } } else if (nread < 0){ close_source(source); close_target(target); } return; error: logger_log(LOG_ERR, "invalid packet"); close_source(source); close_target(target); }
static void analyze_file(const char *filename) { int fd, filekind; u8 filesize; struct stat sb; char *reason; SOURCE *s; print_line(0, "--- %s", filename); /* stat check */ if (stat(filename, &sb) < 0) { errore("Can't stat %.300s", filename); return; } filekind = 0; filesize = 0; reason = NULL; if (S_ISREG(sb.st_mode)) { filesize = sb.st_size; print_kind(filekind, filesize, 1); } else if (S_ISBLK(sb.st_mode)) filekind = 1; else if (S_ISCHR(sb.st_mode)) filekind = 2; else if (S_ISDIR(sb.st_mode)) reason = "Is a directory"; else if (S_ISFIFO(sb.st_mode)) reason = "Is a FIFO"; #ifdef S_ISSOCK else if (S_ISSOCK(sb.st_mode)) reason = "Is a socket"; #endif else reason = "Is an unknown kind of special file"; if (reason != NULL) { error("%.300s: %s", filename, reason); return; } /* Mac OS type & creator code (if running on Mac OS X) */ #ifdef USE_MACOS_TYPE if (filekind == 0) show_macos_type(filename); #endif /* empty regular files need no further analysis */ if (filekind == 0 && filesize == 0) return; /* open for reading */ fd = open(filename, O_RDONLY); if (fd < 0) { errore("Can't open %.300s", filename); return; } /* (try to) guard against TTY character devices */ if (filekind == 2) { if (isatty(fd)) { error("%.300s: Is a TTY device", filename); return; } } /* create a source */ s = init_file_source(fd, filekind); /* tell the user what it is */ if (filekind != 0) print_kind(filekind, s->size, s->size_known); /* now analyze it */ analyze_source(s, 0); /* finish it up */ close_source(s); }