示例#1
0
文件: main.c 项目: kona4kona/md5deep
static int initialize_state(state *s)
{
    if (NULL == s)
        return TRUE;

    if (setup_hashing_algorithms(s))
        return TRUE;

    MD5DEEP_ALLOC(file_data_t,s->current_file,1);
    MD5DEEP_ALLOC(TCHAR,s->full_name,PATH_MAX);
    MD5DEEP_ALLOC(TCHAR,s->short_name,PATH_MAX);
    MD5DEEP_ALLOC(TCHAR,s->msg,PATH_MAX);
    MD5DEEP_ALLOC(unsigned char,s->buffer,MD5DEEP_IDEAL_BLOCK_SIZE);

    s->known            = NULL;
    s->last             = NULL;
    s->piecewise_size   = 0;
    s->hash_round       = 0;
    s->primary_function = primary_compute;
    s->mode             = mode_none;
    s->hashes_loaded    = FALSE;
    s->banner_displayed = FALSE;
    s->block_size       = MD5DEEP_IDEAL_BLOCK_SIZE;
    s->size_threshold   = 0;
    s->expected_columns = 0;

    return FALSE;
}
示例#2
0
static int initialize_state(state *s)
{
  /* We use PATH_MAX as a handy constant for working with strings
     It may be overkill, but it keeps us out of trouble */
  MD5DEEP_ALLOC(TCHAR,s->msg,PATH_MAX);
  MD5DEEP_ALLOC(TCHAR,s->full_name,PATH_MAX);
  MD5DEEP_ALLOC(TCHAR,s->short_name,PATH_MAX);

  MD5DEEP_ALLOC(unsigned char,s->hash_sum,PATH_MAX);
  MD5DEEP_ALLOC(char,s->hash_result,PATH_MAX);
  MD5DEEP_ALLOC(char,s->known_fn,PATH_MAX);

  s->mode            = mode_none;
  s->hashes_loaded   = FALSE;
  s->return_value    = STATUS_OK;
  s->piecewise_size  = 0;
  s->size_threshold  = 0;
  s->block_size      = MD5DEEP_IDEAL_BLOCK_SIZE;

  if (setup_hashing_algorithm(s))
    return TRUE;

  return FALSE;
}
示例#3
0
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);
}
示例#4
0
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;
}
示例#5
0
文件: main.c 项目: kona4kona/md5deep
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;
}