Exemple #1
0
WZMRTD_LIB BOOL WZMRTD_LINK MrtdSaveToFilesEx(MRTD_CTX_ST * ctx, const char *out_directory, const char *file_name_prefix, BOOL sep_text, BOOL sep_images, BOOL overwrite)
{
  BYTE dg;
  LONG rc;
  char filename[MAX_PATH];

  if (ctx == NULL)
    return FALSE;

  if (out_directory != NULL)
#ifdef WIN32
    mkdir(out_directory);
#else
     mkdir(out_directory, S_IRWXU);
#endif

  for (dg = 0; dg <= 16; dg++)
  {
    if ((ctx->DgData[dg] == NULL) || (ctx->DgSize[dg] == 0))
      continue;

    prepare_filename(filename, out_directory, file_name_prefix);
    if (dg == 0)
      strcat(filename, "ef_com");
    else
      sprintf(filename + strlen(filename), "dg%d", dg);
    strcat(filename, ".raw");

    /* Write the file */
    rc = MrtdWriteFile(filename, ctx->DgData[dg], ctx->DgSize[dg], overwrite);
    if (rc != MRTD_SUCCESS)
    {
      MrtdVerbose("Failed to write DG%d as '%s'", dg, filename);
      MrtdSetLastError(ctx, rc);
      return FALSE;
    }
  }

  return TRUE;
}
Exemple #2
0
int hash_file(state *s, TCHAR *fn)
{
  size_t fn_length;
  char *sum;
  TCHAR *my_filename, *msg;
  FILE *handle;
  
  handle = _tfopen(fn,_TEXT("rb"));
  if (NULL == handle)
  {
    print_error_unicode(s,fn,"%s", strerror(errno));
    return TRUE;
  }
 
  if ((sum = (char *)malloc(sizeof(char) * FUZZY_MAX_RESULT)) == NULL)
  {
    fclose(handle);
    print_error_unicode(s,fn,"%s", strerror(errno));
    return TRUE;
  }

  if ((msg = (TCHAR *)malloc(sizeof(TCHAR) * (MAX_STATUS_MSG + 2))) == NULL)
  {
    free(sum);
    fclose(handle);
    print_error_unicode(s,fn,"%s", strerror(errno));
    return TRUE;
  }

  if (MODE(mode_verbose))
  {
    fn_length = _tcslen(fn);
    if (fn_length > MAX_STATUS_MSG)
    {
      // We have to make a duplicate of the string to call basename on it
      // We need the original name for the output later on
      my_filename = _tcsdup(fn);
      my_basename(my_filename);
    }
    else
      my_filename = fn;

    _sntprintf(msg,
	       MAX_STATUS_MSG-1,
	       _TEXT("Hashing: %s%s"), 
	       my_filename, 
	       _TEXT(BLANK_LINE));
    _ftprintf(stderr,_TEXT("%s\r"), msg);

    if (fn_length > MAX_STATUS_MSG)
      free(my_filename);
  }

  fuzzy_hash_file(handle,sum);
  prepare_filename(s,fn);
  display_result(s,fn,sum);

  if (find_file_size(handle) > SSDEEP_MIN_FILE_SIZE)
    s->found_meaningful_file = true;
  s->processed_file = true;

  fclose(handle);
  free(sum);
  free(msg);
  return FALSE;
}