|
|
@@ -26,8 +26,7 @@ |
|
|
|
|
|
|
|
// 20021030 _M - Created. |
|
|
|
|
|
|
|
#ifndef _MN_SNF_ENGINE |
|
|
|
#define _MN_SNF_ENGINE |
|
|
|
#pragma once |
|
|
|
|
|
|
|
#include <cassert> |
|
|
|
#include <stdexcept> |
|
|
@@ -38,14 +37,14 @@ |
|
|
|
#include <cstdlib> |
|
|
|
#include <fstream> |
|
|
|
#include <iostream> |
|
|
|
#include <string>
|
|
|
|
#include <string> |
|
|
|
#include <vector> |
|
|
|
#include <exception>
|
|
|
|
#include <exception> |
|
|
|
#include "../CodeDweller/faults.hpp" |
|
|
|
#include "../CodeDweller/mangler.hpp" |
|
|
|
//#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 |
|
|
|
// capability of a match record. Match records now can decode themselves. |
|
|
@@ -123,17 +122,17 @@ class TokenMatrix { |
|
|
|
|
|
|
|
// 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... |
|
|
@@ -187,13 +186,13 @@ class TokenMatrix { |
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
@@ -203,7 +202,7 @@ class TokenMatrix { |
|
|
|
Matrix(NULL), |
|
|
|
MatrixSize(0) { } |
|
|
|
|
|
|
|
TokenMatrix(ifstream& F) : |
|
|
|
TokenMatrix(std::ifstream& F) : |
|
|
|
Matrix(NULL), |
|
|
|
MatrixSize(0) { |
|
|
|
Load(F); |
|
|
@@ -261,15 +260,15 @@ class Evaluator { // Evaluator class for following threads through the matrix. |
|
|
|
unsigned int PositionLimit; // Largest CurrentPosition. |
|
|
|
|
|
|
|
// 20030216 _M Optimization conversions |
|
|
|
|
|
|
|
|
|
|
|
// 20140119 _M Deprecated by jump table in evaluator |
|
|
|
// inline int i_lower(); // { return myEvaluationMatrix->i_lower; } |
|
|
|
// inline bool i_isDigit(); // { return myEvaluationMatrix->i_isDigit; } |
|
|
|
// 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 xDigit(); // Match Any digit. |
|
|
|
int xNonWhite(); // Match Any non-whitespace. |
|
|
@@ -277,16 +276,16 @@ class Evaluator { // Evaluator class for following threads through the matrix. |
|
|
|
int xAnyInline(); // Match Any byte but new line. |
|
|
|
int xAnything(); // Match Any character at all. |
|
|
|
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); |
|
|
|
|
|
|
|
public: |
|
|
@@ -409,22 +408,22 @@ class EvaluationMatrix { |
|
|
|
// evaluator node if it exists. Therefore, the caller should skip it's normal |
|
|
|
// list itteration code when this function has been called. |
|
|
|
|
|
|
|
void DropEvaluator();
|
|
|
|
|
|
|
|
void DropEvaluator(); |
|
|
|
|
|
|
|
void dropAllEvaluators(); |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
// 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... |
|
|
@@ -438,7 +437,7 @@ class EvaluationMatrix { |
|
|
|
|
|
|
|
// 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. |
|
|
|
// bool i_isDigit; // true if i is a digit. |
|
|
|
// bool i_isSpace; // true if i is whitespace. |
|
|
@@ -477,10 +476,10 @@ class EvaluationMatrix { |
|
|
|
// 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. |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
EvaluationMatrix(TokenMatrix* m) { // Constructor w/ pointer to Token Matrix... |
|
|
@@ -573,5 +572,6 @@ inline void EvaluationMatrix::CacheEvaluator(Evaluator* e) { |
|
|
|
// 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. |
|
|
|
|
|
|
|
#endif |
|
|
|
} // End namespace codedweller |
|
|
|
|
|
|
|
|