int process(uint64_t pos, char* buf, int max) { /* If callback isn't finished yet, ask it for more data * and store it in our buffer */ if (!callback_finished_) { std::string::size_type prev_buf_size = buffer_.size(); /* Expand buffer to fit new data */ buffer_.resize(prev_buf_size + max); int rc = callback_write_(callback_data_, 0, &buffer_[prev_buf_size], max); if (rc == -1) { /* Callback is finished producing data */ callback_finished_ = true; buffer_.resize(prev_buf_size); } else { /* Trim buffer to size of data actually produced */ buffer_.resize(prev_buf_size + rc); } } /* Produce output data. These functions internally remove * written data from the buffer. */ if (gzip_) return process_gzip(pos, buf, max); else return process_normal(pos, buf, max); }
int main(int argc, char **argv) { int count, status, goal = argc; state *s; TCHAR *fn, *cwd; #ifndef __GLIBC__ __progname = basename(argv[0]); #endif s = (state *)malloc(sizeof(state)); if (NULL == s) fatal_error("%s: Unable to allocate state variable", __progname); if (initialize_state(s)) fatal_error("%s: Unable to initialize state variable", __progname); process_cmd_line(s,argc,argv); #ifdef _WIN32 if (prepare_windows_command_line(s)) fatal_error("%s: Unable to process command line arguments", __progname); #else s->argc = argc; s->argv = argv; #endif // Anything left on the command line at this point is a file // or directory we're supposed to process. If there's nothing // specified, we should tackle standard input if (optind == argc) { status = process_stdin(s); } else { MD5DEEP_ALLOC(TCHAR,fn,PATH_MAX); MD5DEEP_ALLOC(TCHAR,cwd,PATH_MAX); cwd = _tgetcwd(cwd,PATH_MAX); if (NULL == cwd) fatal_error("%s: %s", __progname, strerror(errno)); count = optind; // The signature comparsion mode needs to use the command line // arguments and argument count. We don't do wildcard expansion // on it on Win32 (i.e. where it matters). The setting of 'goal' // to the original argc occured at the start of main(), so we just // need to update it if we're *not* in signature compare mode. if (!(s->mode & mode_sigcompare)) { goal = s->argc; } while (count < goal) { if (MODE(mode_sigcompare)) match_load(s,argv[count]); else if (MODE(mode_compare_unknown)) match_compare_unknown(s,argv[count]); else { generate_filename(s,fn,cwd,s->argv[count]); #ifdef _WIN32 status = process_win32(s,fn); #else status = process_normal(s,fn); #endif } ++count; } // If we processed files, but didn't find anything large enough // to be meaningful, we should display a warning message to the user. // This happens mostly when people are testing very small files // e.g. $ echo "hello world" > foo && ssdeep foo if ( ! s->found_meaningful_file && s->processed_file) { print_error(s,"%s: Did not process files large enough to produce meaningful results", __progname); } } // If the user has requested us to compare signature files, use // our existng code to pretty-print directory matching to do the // work for us. if (s->mode & mode_sigcompare) s->mode |= mode_match_pretty; if (s->mode & mode_match_pretty) match_pretty(s); return (EXIT_SUCCESS); }
int main(int argc, char **argv) { TCHAR *fn, *cwd; state *s; int count, status = STATUS_OK; /* Because the main() function can handle wchar_t arguments on Win32, we need a way to reference those values. Thus we make a duplciate of the argc and argv values. */ #ifndef __GLIBC__ __progname = basename(argv[0]); #endif s = (state *)malloc(sizeof(state)); if (NULL == s) { // We can't use fatal_error because it requires a valid state print_status("%s: Unable to allocate state variable", __progname); return STATUS_INTERNAL_ERROR; } if (initialize_state(s)) { print_status("%s: Unable to initialize state variable", __progname); return STATUS_INTERNAL_ERROR; } if (process_command_line(s,argc,argv)) { print_status("%s: Unable to process command line arguments", __progname); return STATUS_INTERNAL_ERROR; } #ifdef _WIN32 if (prepare_windows_command_line(s)) fatal_error(s,"%s: Unable to process command line arguments", __progname); #else s->argc = argc; s->argv = argv; #endif /* Anything left on the command line at this point is a file or directory we're supposed to process. If there's nothing specified, we should tackle standard input */ if (optind == argc) hash_stdin(s); else { MD5DEEP_ALLOC(TCHAR,fn,PATH_MAX); MD5DEEP_ALLOC(TCHAR,cwd,PATH_MAX); cwd = _tgetcwd(cwd,PATH_MAX); if (NULL == cwd) fatal_error(s,"%s: %s", __progname, strerror(errno)); count = optind; while (count < s->argc) { generate_filename(s,fn,cwd,s->argv[count]); #ifdef _WIN32 status = process_win32(s,fn); #else status = process_normal(s,fn); #endif // if (status != STATUS_OK) // return status; ++count; } free(fn); free(cwd); } /* We only have to worry about checking for unused hashes if one of the matching modes was enabled. We let the display_not_matched function determine if it needs to display anything. The function also sets our return values in terms of inputs not being matched or known hashes not being used */ if ((s->mode & mode_match) || (s->mode & mode_match_neg)) s->return_value = finalize_matching(s); return s->return_value; }
int main(int argc, char **argv) { int count, status = EXIT_SUCCESS; TCHAR *fn; state *s; /* Because the main() function can handle wchar_t arguments on Win32, we need a way to reference those values. Thus we make a duplciate of the argc and argv values. */ #ifndef __GLIBC__ __progname = basename(argv[0]); #endif s = (state *)malloc(sizeof(state)); if (NULL == s) { // We can't use fatal_error because it requires a valid state print_status("%s: Unable to allocate state variable", __progname); return EXIT_FAILURE; } if (initialize_state(s)) { print_status("%s: Unable to initialize state variable", __progname); return EXIT_FAILURE; } process_command_line(s,argc,argv); if (initialize_hashing_algorithms(s)) return EXIT_FAILURE; if (primary_audit == s->primary_function) setup_audit(s); #ifdef _WIN32 if (prepare_windows_command_line(s)) fatal_error(s,"%s: Unable to process command line arguments", __progname); check_wow64(s); #else s->argc = argc; s->argv = argv; #endif MD5DEEP_ALLOC(TCHAR,s->cwd,PATH_MAX); s->cwd = _tgetcwd(s->cwd,PATH_MAX); if (NULL == s->cwd) fatal_error(s,"%s: %s", __progname, strerror(errno)); /* Anything left on the command line at this point is a file or directory we're supposed to process. If there's nothing specified, we should tackle standard input */ if (optind == argc) hash_stdin(s); else { MD5DEEP_ALLOC(TCHAR,fn,PATH_MAX); count = optind; while (count < s->argc) { generate_filename(s,fn,s->cwd,s->argv[count]); #ifdef _WIN32 status = process_win32(s,fn); #else status = process_normal(s,fn); #endif ++count; } free(fn); } if (primary_audit == s->primary_function) status = display_audit_results(s); return status; }