示例#1
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;
}
示例#2
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;
}