Exemplo n.º 1
0
int
main (int argc, char *argv[])
{
  GHashTable * human_readable_keys;
  int i;

  if (argc < 2)
      {
	fprintf (stderr, _("Usage: wvSummary doc1 [... docN]\n"));
	return 1;
      }
  
  wvInit();
  human_readable_keys = g_hash_table_new (g_str_hash,
					  g_str_equal);

  for (i = 0; i < nr_metadata_names; i++)
    g_hash_table_insert (human_readable_keys,
			 metadata_names[i].metadata_key,
			 _(metadata_names[i].human_readable_key));

  for (i = 1 ; i < argc ; i++)
    {      
      GsfInput  *input;
      GsfInfile *msole;
      GError    *err = NULL;

      input = gsf_input_stdio_new (argv[i], &err);

      if(!input)
	{
	  fprintf (stderr, _("Problem with getting metadata from %s:%s\n"),
		   argv[i], err ? err->message : "");
	  g_error_free (err);
	  continue;
	}

      input = gsf_input_uncompress (input);
      msole = gsf_infile_msole_new (input, &err);
      if(!msole)
	{
	  fprintf (stderr, _("Problem with getting metadata from %s:%s\n"),
		   argv[i], err ? err->message : "");
	  g_error_free (err);
	  continue;
	}

      fprintf (stdout, _("Metadata for %s:\n"), argv[i]);      
      print_summary_stream (msole, argv[i], "\05SummaryInformation", human_readable_keys);
      print_summary_stream (msole, argv[i], "\05DocumentSummaryInformation", human_readable_keys);
      
      g_object_unref (G_OBJECT (msole));
      g_object_unref (G_OBJECT (input));
    }

  g_hash_table_destroy (human_readable_keys);
  wvShutdown();

  return 0;
}
int
main(int argc, char *argv[]) {
    FILE          *input;
    int           ret;
    wvParseStruct ps;

    if (argc < 2)
        usage();

    input = fopen(argv[1], "rb");
    if (!input) {
        GET_fprintf_HANDLER() (stderr, "Failed to open %s\n", argv[1]);
        return -1;
    }
    fclose(input);

    wvInit();
    ret = wvInitParser(&ps, argv[1]);

    if (ret == -1) {
        GET_fprintf_HANDLER() (stderr,
                               "%s couldn't be opened as any known word document\n",
                               argv[1]);
        return -1;
    }

    ret = wvQuerySupported(&ps.fib, NULL);

    GET_printf_HANDLER() ("Version: ");
    switch (ret & 0x7fff) {
        case WORD8:
            GET_printf_HANDLER() ("word8 or higher");
            break;

        case WORD7:
            GET_printf_HANDLER() ("word7");
            break;

        case WORD6:
            GET_printf_HANDLER() ("word6");
            break;

        case WORD5:
            GET_printf_HANDLER() ("word5");
            break;

        case WORD2:
            GET_printf_HANDLER() ("word2 (maybe)");
            break;

        default:
            GET_printf_HANDLER() ("unknown msword version");
            break;
    }

    GET_printf_HANDLER() (", Encrypted: ");
    if (ret & 0x8000)
        GET_printf_HANDLER() ("Yes\n");
    else
        GET_printf_HANDLER() ("No\n");

    wvOLEFree(&ps);
    return 0;
}
Exemplo n.º 3
0
int
main (int argc, char **argv)
{
    char *config = NULL;
    char *password = NULL;

    int ret;
    state_data myhandle;
    expand_data expandhandle;
    wvParseStruct ps;
    int c, index = 0;
    static struct option long_options[] = {
	{"config", 1, 0, 'x'},
	{"password", 1, 0, 'p'},
	{0, 0, 0, 0}
    };

    if (argc < 2)
	usage ();

    while (1)
      {
	  c = getopt_long (argc, argv, "x:p:", long_options, &index);
	  if (c == -1)
	      break;
	  switch (c)
	    {
	    case 'x':
		if (optarg)
		    config = optarg;
		else
		    wvError (("No config file given to config option"));
		break;
	    case 'p':
		if (optarg)
		    password = optarg;
		else
		    wvError (("No password given to password option"));
		break;
	    default:
		usage ();
		break;
	    }
      }

    wvInit ();
    ret = wvInitParser (&ps, argv[optind]);
    ps.filename = argv[optind];

    if (ret == 4)
      {
	  ret = 0;
	  if (password == NULL)
	    {
		wvError (
			 ("Password required, this is an encrypted document\n"));
		return (-1);
	    }
	  else
	    {
		wvSetPassword (password, &ps);
		if (wvDecrypt97 (&ps))
		  {
		      wvError (("Incorrect Password\n"));
		      return (-1);
		  }
	    }
      }
    else if (ret == 7)
      {
	  ret = 0;
	  if (password == NULL)
	    {
		wvError (
			 ("Password required, this is an encrypted document\n"));
		return (-1);
	    }
	  else
	    {
		wvSetPassword (password, &ps);
		if (wvDecrypt95 (&ps))
		  {
		      wvError (("Incorrect Password\n"));
		      return (-1);
		  }
	    }
      }

    if (ret)
      {
	  wvError (("startup error with file %s\n", argv[1]));
	  wvOLEFree (&ps);
	  return (2);
      }

    wvSetElementHandler (&ps, myelehandler);
    wvSetDocumentHandler (&ps, mydochandler);

    wvInitStateData (&myhandle);

    if (wvOpenConfig (&myhandle,config) == 0)
	wvError (("config file not found\n"));
    else
	ret = wvParseConfig (&myhandle);

    if (!ret)
      {
	  expandhandle.sd = &myhandle;
	  ps.userData = &expandhandle;
	  ret = wvText (&ps);
      }

    wvReleaseStateData (&myhandle);
    if (ret == 2)
	return (2);
    else if (ret != 0)
	ret = -1;
    wvOLEFree (&ps);
    return (ret);
}
Exemplo n.º 4
0
Arquivo: wvRTF.c Projeto: AbiWord/wv
int
main (int argc, char *argv[])
{
    FILE *input;
    char *fname, *password;
    int ret;

    wvParseStruct ps;
    char *dir = NULL;

    rtfUserData ud;

    static struct option long_options[] = {
	{"charset", 1, 0, 'c'},
	{"password", 1, 0, 'p'},
	{"dir", 1, 0, 'd'},
	{"version", 0, 0, 'v'},
	{"help", 0, 0, '?'},
	{0, 0, 0, 0}
    };

    int c, index = 0;

    if (argc < 2)
      {
	  do_help ();
	  return 1;
      }

    while (1)
      {
	  c = getopt_long (argc, argv, "?vc:p:d:", long_options, &index);
	  if (c == -1)
	      break;
	  switch (c)
	    {
	    case '?':
		do_help ();
		return 0;
	    case 'v':
		do_version ();
		return 0;
	    case 'c':
		if (optarg)
		    charset = optarg;
		else
		    wvError (("No argument given to charset"));
		break;
	    case 'p':
		if (optarg)
		    password = optarg;
		else
		    wvError (("No password given to password option"));
		break;
	    case 'd':
		if (optarg)
		    dir = optarg;
		else
		    wvError (("No directory given to dir option"));
		break;
	    default:
		do_help ();
		return -1;
	    }
      }

    if (optind >= argc)
      {
	  fprintf (stderr, "No file name given to open\n");
	  return -1;
      }

    fname = argv[optind];

    input = fopen (fname, "rb");
    if (!input)
      {
	fprintf (stderr, "Failed to open %s\n", fname);
	  return -1;
      }
    fclose (input);

    wvInit ();
    ret = wvInitParser (&ps, fname);
    ps.filename = fname;
    ps.dir = dir;

    /* set to 0 */
    memset (&ud, 1, sizeof (rtfUserData));
    ps.userData = &ud;

    if (ret & 0x8000)		/* Password protected? */
      {
	  if ((ret & 0x7fff) == WORD8)
	    {
		ret = 0;
		if (password == NULL)
		  {
		      fprintf (stderr,
			       "Password required, this is an encrypted document\n");
		      return -1;
		  }
		else
		  {
		      wvSetPassword (password, &ps);
		      if (wvDecrypt97 (&ps))
			{
			    wvError (("Incorrect Password\n"));
			    return -1;
			}
		  }
	    }
	  else if (((ret & 0x7fff) == WORD7) || ((ret & 0x7fff) == WORD6))
	    {
		ret = 0;
		if (password == NULL)
		  {
		      fprintf (stderr,
			       "Password required, this is an encrypted document\n");
		      return -1;
		  }
		else
		  {
		      wvSetPassword (password, &ps);
		      if (wvDecrypt95 (&ps))
			{
			    wvError (("Incorrect Password\n"));
			    return -1;
			}
		  }
	    }
      }

    if (ret)
      {
	  wvError (("startup error\n"));
	  wvOLEFree (&ps);
	  return -1;
      }

    wvSetElementHandler (&ps, eleProc);
    wvSetDocumentHandler (&ps, docProc);
    wvSetCharHandler (&ps, charProc);
    wvSetSpecialCharHandler (&ps, specCharProc);

    wvText (&ps);

    /* free associated memory */
    wvOLEFree (&ps);

    return 0;
}
Exemplo n.º 5
0
int main(int argc, char *argv[]) {
    wvInit();
    
    char action, opt;
    char *arg;
    while ((opt = getopt(argc, argv, "p:w:c:")) != -1) {
        switch (opt) {
            case 'p': case 'w': case 'c':
                action = opt;
                arg = optarg;
                break;
            default: usage();
        }
    }
    
    if (optind >= argc) usage();
    char *docfile = argv[optind];
    WordDoc doc(docfile);
    
    if (doc.exists == false) {
        std::cout << "Failed to parse file: " << docfile << std::endl;
    }
    else if (doc.password_protected == false) {
        std::cout << "Success? The document is not encrypted." << std::endl;
        return 1;
    }
    else if (doc.recognized_version == false) {
        std::cout << "File format not recognized" << std::endl;
        return 1;
    }
    else if (action == 'p') {
        if (doc.check_password(arg)) {
            std::cout << "Correct password" << std::endl;
            return 0;
        }
        else {
            std::cout << "Incorrect password" << std::endl;
            return 1;
        }
    }
    else if (action == 'w') {
        std::ifstream fh(arg);
        if (fh == NULL) {
            printf("Failed to open file: %s\n", arg);
            return 1;
        }
        
        std::string line;
        while (std::getline(fh, line)) {
            if (*line.end() == '\n')
                line.resize(line.size() - 1); // chomp
            if (*line.end() == '\r')
                line.resize(line.size() - 1); // chomp again
            
            if (doc.check_password((char *) line.c_str())) {
                std::cout << "The password is: " << line << std::endl;
                return 0;
            }
        }
        std::cout << "Wordlist exausted" << std::endl;
        return 1;
    }
    else if (action == 'c') {
        char *charset = arg;
        int charlen = strlen(charset);
        char offsets[16] = { 0 };
        char password[17] = { 0 };
        int level = 1;
        std::cout << "Entering level " << level << std::endl;
        while (1) {
            for (int i = 0; ++offsets[i] > charlen; i++) {
                offsets[i] = 1;
                if (i >= level - 1) {
                    std::cout << "Entering level " << ++level << std::endl;
                    if (level > 16) {
                        std::cout << "Passwords only go up to 16 characters "
                            "in Microsoft Word documents" << std::endl;
                        return 1;
                    }
                }
            }
            
            for (int i = 0; offsets[i]; i++)
                password[i] = charset[offsets[i] - 1];
            
            if (doc.check_password(password)) {
                std::cout << "The password is: " << password << std::endl;
                return 0;
            }
        }
        std::cout << "The impossible, it happened" << std::endl;
        return 1;
    }
}