|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 20021030 _M - Created. |
|
|
// 20021030 _M - Created. |
|
|
|
|
|
|
|
|
#ifndef _MN_SNF_ENGINE |
|
|
|
|
|
#define _MN_SNF_ENGINE |
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
|
|
|
|
|
#include <cassert> |
|
|
#include <cassert> |
|
|
#include <stdexcept> |
|
|
#include <stdexcept> |
|
|
|
|
|
|
|
|
#include <cstdlib> |
|
|
#include <cstdlib> |
|
|
#include <fstream> |
|
|
#include <fstream> |
|
|
#include <iostream> |
|
|
#include <iostream> |
|
|
#include <string>
|
|
|
|
|
|
|
|
|
#include <string> |
|
|
#include <vector> |
|
|
#include <vector> |
|
|
#include <exception>
|
|
|
|
|
|
|
|
|
#include <exception> |
|
|
#include "../CodeDweller/faults.hpp" |
|
|
#include "../CodeDweller/faults.hpp" |
|
|
#include "../CodeDweller/mangler.hpp" |
|
|
#include "../CodeDweller/mangler.hpp" |
|
|
//#include "../nvwa-0.6/nvwa/debug_new.h" |
|
|
//#include "../nvwa-0.6/nvwa/debug_new.h" |
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
namespace codedweller { |
|
|
|
|
|
|
|
|
// 20030929 _M SYMBOL_RANGE moved to snf_engine.hpp as part of augmenting the |
|
|
// 20030929 _M SYMBOL_RANGE moved to snf_engine.hpp as part of augmenting the |
|
|
// capability of a match record. Match records now can decode themselves. |
|
|
// capability of a match record. Match records now can decode themselves. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Exceptions... |
|
|
// Exceptions... |
|
|
|
|
|
|
|
|
class BadAllocation : public runtime_error { // Exception for a bad memory allocation. |
|
|
|
|
|
public: BadAllocation(const string& w):runtime_error(w) {} |
|
|
|
|
|
|
|
|
class BadAllocation : public std::runtime_error { // Exception for a bad memory allocation. |
|
|
|
|
|
public: BadAllocation(const std::string& w):runtime_error(w) {} |
|
|
}; |
|
|
}; |
|
|
class BadMatrix : public runtime_error { // Exception for invalid matrix loads. |
|
|
|
|
|
public: BadMatrix(const string& w):runtime_error(w) {} |
|
|
|
|
|
|
|
|
class BadMatrix : public std::runtime_error { // Exception for invalid matrix loads. |
|
|
|
|
|
public: BadMatrix(const std::string& w):runtime_error(w) {} |
|
|
}; |
|
|
}; |
|
|
class BadFile : public runtime_error { // Exception for missing rulebase files. |
|
|
|
|
|
public: BadFile(const string& w):runtime_error(w) {} |
|
|
|
|
|
|
|
|
class BadFile : public std::runtime_error { // Exception for missing rulebase files. |
|
|
|
|
|
public: BadFile(const std::string& w):runtime_error(w) {} |
|
|
}; |
|
|
}; |
|
|
class OutOfRange : public runtime_error { // Exception for indexes out of range. |
|
|
|
|
|
public: OutOfRange(const string& w):runtime_error(w) {} |
|
|
|
|
|
|
|
|
class OutOfRange : public std::runtime_error { // Exception for indexes out of range. |
|
|
|
|
|
public: OutOfRange(const std::string& w):runtime_error(w) {} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// Standards... |
|
|
// Standards... |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Load(const char* FileName); // Loads the matrix from a file name. |
|
|
void Load(const char* FileName); // Loads the matrix from a file name. |
|
|
|
|
|
|
|
|
void Load(string& FileName); // Loads the matrix from a file name string. |
|
|
|
|
|
|
|
|
void Load(std::string& FileName); // Loads the matrix from a file name string. |
|
|
|
|
|
|
|
|
void Load(ifstream& F); // Loads the token matrix from the file. |
|
|
|
|
|
|
|
|
void Load(std::ifstream& F); // Loads the token matrix from the file. |
|
|
|
|
|
|
|
|
void Validate(string& SecurityKey); // Validates the matrix with a key string. |
|
|
|
|
|
|
|
|
void Validate(std::string& SecurityKey); // Validates the matrix with a key string. |
|
|
|
|
|
|
|
|
void Verify(string& SecurityKey); // Verifies the matrix digest. |
|
|
|
|
|
|
|
|
void Verify(std::string& SecurityKey); // Verifies the matrix digest. |
|
|
|
|
|
|
|
|
void FlipEndian(); // Converts big/little endian tokens. |
|
|
void FlipEndian(); // Converts big/little endian tokens. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Matrix(NULL), |
|
|
Matrix(NULL), |
|
|
MatrixSize(0) { } |
|
|
MatrixSize(0) { } |
|
|
|
|
|
|
|
|
TokenMatrix(ifstream& F) : |
|
|
|
|
|
|
|
|
TokenMatrix(std::ifstream& F) : |
|
|
Matrix(NULL), |
|
|
Matrix(NULL), |
|
|
MatrixSize(0) { |
|
|
MatrixSize(0) { |
|
|
Load(F); |
|
|
Load(F); |
|
|
|
|
|
|
|
|
unsigned int PositionLimit; // Largest CurrentPosition. |
|
|
unsigned int PositionLimit; // Largest CurrentPosition. |
|
|
|
|
|
|
|
|
// 20030216 _M Optimization conversions |
|
|
// 20030216 _M Optimization conversions |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 20140119 _M Deprecated by jump table in evaluator |
|
|
// 20140119 _M Deprecated by jump table in evaluator |
|
|
// inline int i_lower(); // { return myEvaluationMatrix->i_lower; } |
|
|
// inline int i_lower(); // { return myEvaluationMatrix->i_lower; } |
|
|
// inline bool i_isDigit(); // { return myEvaluationMatrix->i_isDigit; } |
|
|
// inline bool i_isDigit(); // { return myEvaluationMatrix->i_isDigit; } |
|
|
// inline bool i_isSpace(); // { return myEvaluationMatrix->i_isSpace; } |
|
|
// inline bool i_isSpace(); // { return myEvaluationMatrix->i_isSpace; } |
|
|
// inline bool i_isAlpha(); // { return myEvaluationMatrix->i_isAphpa; }
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int JumpPoint;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// inline bool i_isAlpha(); // { return myEvaluationMatrix->i_isAphpa; } |
|
|
|
|
|
|
|
|
|
|
|
unsigned int JumpPoint; |
|
|
|
|
|
|
|
|
int xLetter(); // Match Any letter. |
|
|
int xLetter(); // Match Any letter. |
|
|
int xDigit(); // Match Any digit. |
|
|
int xDigit(); // Match Any digit. |
|
|
int xNonWhite(); // Match Any non-whitespace. |
|
|
int xNonWhite(); // Match Any non-whitespace. |
|
|
|
|
|
|
|
|
int xAnyInline(); // Match Any byte but new line. |
|
|
int xAnyInline(); // Match Any byte but new line. |
|
|
int xAnything(); // Match Any character at all. |
|
|
int xAnything(); // Match Any character at all. |
|
|
int xRunGateway(); // Match the run-loop gateway. |
|
|
int xRunGateway(); // Match the run-loop gateway. |
|
|
|
|
|
|
|
|
void doFollowOrMakeBuddy(int keyVector); // Follow and divide algorithm.
|
|
|
|
|
|
void tryFollowingPrecisePath(unsigned short int i);
|
|
|
|
|
|
void tryFollowingNoCasePath(unsigned short int i);
|
|
|
|
|
|
void tryFollowingWildAlphaPath();
|
|
|
|
|
|
void tryFollowingWildDigitPath();
|
|
|
|
|
|
void tryFollowingWildNonWhitePath();
|
|
|
|
|
|
void tryFollowingWildWhitePath();
|
|
|
|
|
|
void tryFollowingWildInlinePath();
|
|
|
|
|
|
void tryFollowingWildAnythingPath();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void doFollowOrMakeBuddy(int keyVector); // Follow and divide algorithm. |
|
|
|
|
|
void tryFollowingPrecisePath(unsigned short int i); |
|
|
|
|
|
void tryFollowingNoCasePath(unsigned short int i); |
|
|
|
|
|
void tryFollowingWildAlphaPath(); |
|
|
|
|
|
void tryFollowingWildDigitPath(); |
|
|
|
|
|
void tryFollowingWildNonWhitePath(); |
|
|
|
|
|
void tryFollowingWildWhitePath(); |
|
|
|
|
|
void tryFollowingWildInlinePath(); |
|
|
|
|
|
void tryFollowingWildAnythingPath(); |
|
|
void doFollowerJumpTable(unsigned short int i); |
|
|
void doFollowerJumpTable(unsigned short int i); |
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
// evaluator node if it exists. Therefore, the caller should skip it's normal |
|
|
// evaluator node if it exists. Therefore, the caller should skip it's normal |
|
|
// list itteration code when this function has been called. |
|
|
// list itteration code when this function has been called. |
|
|
|
|
|
|
|
|
void DropEvaluator();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DropEvaluator(); |
|
|
|
|
|
|
|
|
void dropAllEvaluators(); |
|
|
void dropAllEvaluators(); |
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
// Exception classes... |
|
|
// Exception classes... |
|
|
|
|
|
|
|
|
class BadAllocation : public runtime_error { // Allocation failed exception. |
|
|
|
|
|
public: BadAllocation(const string& w):runtime_error(w) {} |
|
|
|
|
|
|
|
|
class BadAllocation : public std::runtime_error { // Allocation failed exception. |
|
|
|
|
|
public: BadAllocation(const std::string& w):runtime_error(w) {} |
|
|
}; |
|
|
}; |
|
|
class MaxEvalsExceeded : public runtime_error { // Too many evaluators exception. |
|
|
|
|
|
public: MaxEvalsExceeded(const string& w):runtime_error(w) {} |
|
|
|
|
|
|
|
|
class MaxEvalsExceeded : public std::runtime_error { // Too many evaluators exception. |
|
|
|
|
|
public: MaxEvalsExceeded(const std::string& w):runtime_error(w) {} |
|
|
}; |
|
|
}; |
|
|
class OutOfRange : public runtime_error { // Out of range exception. |
|
|
|
|
|
public: OutOfRange(const string& w):runtime_error(w) {} |
|
|
|
|
|
|
|
|
class OutOfRange : public std::runtime_error { // Out of range exception. |
|
|
|
|
|
public: OutOfRange(const std::string& w):runtime_error(w) {} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// Attributes... |
|
|
// Attributes... |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 20030216 _M High Level Conversion Optimizers... |
|
|
// 20030216 _M High Level Conversion Optimizers... |
|
|
|
|
|
|
|
|
// 20140119 _M Deprecated by jump table in evaluator
|
|
|
|
|
|
|
|
|
// 20140119 _M Deprecated by jump table in evaluator |
|
|
// int i_lower; // Lower case version of byte under test. |
|
|
// int i_lower; // Lower case version of byte under test. |
|
|
// bool i_isDigit; // true if i is a digit. |
|
|
// bool i_isDigit; // true if i is a digit. |
|
|
// bool i_isSpace; // true if i is whitespace. |
|
|
// bool i_isSpace; // true if i is whitespace. |
|
|
|
|
|
|
|
|
// EvaluateThis() Moves each evaluator with the current character and creates a new |
|
|
// EvaluateThis() Moves each evaluator with the current character and creates a new |
|
|
// evaluator for the current spot in the input file to make all rules global. |
|
|
// evaluator for the current spot in the input file to make all rules global. |
|
|
|
|
|
|
|
|
int EvaluateThis(unsigned short int i);
|
|
|
|
|
|
|
|
|
|
|
|
void evaluateSegment(vector<unsigned char>& data, unsigned int start, unsigned int finish);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int EvaluateThis(unsigned short int i); |
|
|
|
|
|
|
|
|
|
|
|
void evaluateSegment(std::vector<unsigned char>& data, unsigned int start, unsigned int finish); |
|
|
|
|
|
|
|
|
void restartEngineAt(int newCharacterCount); |
|
|
void restartEngineAt(int newCharacterCount); |
|
|
|
|
|
|
|
|
EvaluationMatrix(TokenMatrix* m) { // Constructor w/ pointer to Token Matrix... |
|
|
EvaluationMatrix(TokenMatrix* m) { // Constructor w/ pointer to Token Matrix... |
|
|
|
|
|
|
|
|
// When that first evaulator is used, the NULL pointer will return to the root |
|
|
// When that first evaulator is used, the NULL pointer will return to the root |
|
|
// of the EvaluatorCache list. In this regard the cache acts like a stack. |
|
|
// of the EvaluatorCache list. In this regard the cache acts like a stack. |
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
} // End namespace codedweller |
|
|
|
|
|
|
|
|
|
|
|
|