Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DictionaryGuesser
- Loading branch information
Showing
10 changed files
with
190 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,6 @@ | |
#define CHARSETGUESSER_H_ | ||
|
||
|
||
#include "main.h" | ||
|
||
#include "guessers.h" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* pgpry alpha - PGP private key password recovery | ||
* Copyright (C) 2010 Jonas Gehring | ||
* | ||
* file: dictguesser.cpp | ||
* Simple dictionary guesser | ||
*/ | ||
|
||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
#include "dictguesser.h" | ||
|
||
|
||
namespace Guessers | ||
{ | ||
|
||
// Constructor | ||
DictionaryGuesser::DictionaryGuesser(Buffer *buffer) | ||
: Guesser(buffer), m_index(0) | ||
{ | ||
|
||
} | ||
|
||
void DictionaryGuesser::setup(const std::map<std::string, std::string> &options) | ||
{ | ||
std::map<std::string, std::string>::const_iterator it; | ||
|
||
m_dictfile = std::string(); | ||
it = options.find("dictionary"); | ||
if (it != options.end()) { | ||
m_dictfile = (*it).second; | ||
} | ||
|
||
m_index = 0; | ||
m_phrases.clear(); | ||
} | ||
|
||
bool DictionaryGuesser::init() | ||
{ | ||
std::ifstream in(m_dictfile.c_str()); | ||
if (in.fail()) { | ||
std::cerr << "Error: Unable to open file " << m_dictfile << std::endl; | ||
return false; | ||
} | ||
|
||
std::string str; | ||
while (in.good()) { | ||
getline(in, str); | ||
|
||
if (!str.empty()) { | ||
m_phrases.push_back(Memblock(str.c_str())); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool DictionaryGuesser::guess(Memblock *m) | ||
{ | ||
if (m_index >= m_phrases.size()) { | ||
return false; | ||
} | ||
|
||
*m = m_phrases[m_index++]; | ||
return true; | ||
} | ||
|
||
} // namespace Guessers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* pgpry alpha - PGP private key password recovery | ||
* Copyright (C) 2010 Jonas Gehring | ||
* | ||
* file: dictguesser.h | ||
* Simple dictionary guesser | ||
*/ | ||
|
||
|
||
#ifndef DICTGUESSER_H_ | ||
#define DICTGUESSER_H_ | ||
|
||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "guessers.h" | ||
|
||
#include "memblock.h" | ||
|
||
|
||
namespace Guessers | ||
{ | ||
|
||
class DictionaryGuesser : public Guesser | ||
{ | ||
public: | ||
DictionaryGuesser(Buffer *buffer); | ||
|
||
void setup(const std::map<std::string, std::string> &options); | ||
|
||
protected: | ||
bool init(); | ||
bool guess(Memblock *m); | ||
|
||
protected: | ||
std::string m_dictfile; | ||
uint32_t m_index; | ||
std::vector<Memblock> m_phrases; | ||
}; | ||
|
||
} // namespace Guessers | ||
|
||
|
||
#endif // DICTGUESSER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
#define GUESSERS_H_ | ||
|
||
|
||
#include "main.h" | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters