Parcourir la source

cleaned up namespace in SNFMulti

master
Pete McNeil il y a 4 ans
Parent
révision
cb4666686f
2 fichiers modifiés avec 59 ajouts et 57 suppressions
  1. 12
    10
      snf_engine.cpp
  2. 47
    47
      snf_engine.hpp

+ 12
- 10
snf_engine.cpp Voir le fichier

@@ -38,7 +38,7 @@
#include "../CodeDweller/mangler.hpp"
#include "snf_engine.hpp"

namespace cd = codedweller;
namespace codedweller {

///////////////////////////////////////////////////////////////////////////////////////////
// BEGIN IMPLEMENTATIONS //////////////////////////////////////////////////////////////////
@@ -50,13 +50,13 @@ namespace cd = codedweller;

// TokenMatrix::Load(filename)

void TokenMatrix::Load(string& FileName) { // Initialize using a string for file name.
void TokenMatrix::Load(std::string& FileName) { // Initialize using a string for file name.
Load(FileName.c_str()); // Convert the string to a null terminated
} // char* and call the function below.

void TokenMatrix::Load(const char* FileName) { // Initializes the token matrix by file name.

ifstream MatrixFile(FileName,ios::binary); // Open the file.
std::ifstream MatrixFile(FileName,std::ios::binary); // Open the file.
if(MatrixFile.bad()) // If anything is wrong with the file
throw BadFile("TokenMatrix::Load() finds MatrixFile.bad()"); // then throw a bad file exception.

@@ -66,15 +66,15 @@ void TokenMatrix::Load(const char* FileName) {

// TokenMatrix::Load(stream)

const cd::AbortCheck CompatibleIntSizeCheck("TokenMatrix::Load():CompatibleIntSizeCheck(sizeof(unsigned int)==4)");
const AbortCheck CompatibleIntSizeCheck("TokenMatrix::Load():CompatibleIntSizeCheck(sizeof(unsigned int)==4)");

void TokenMatrix::Load(ifstream& F) { // Initializes the token matrix from a file.
void TokenMatrix::Load(std::ifstream& F) { // Initializes the token matrix from a file.
CompatibleIntSizeCheck(sizeof(unsigned int)==4); // Check our assumptions.

MatrixSize = 0; // Clear out the old Matrix Size and array.
if(Matrix) delete Matrix; // that is, if there is an array.

F.seekg(0,ios::end); // Find the end of the file.
F.seekg(0,std::ios::end); // Find the end of the file.
MatrixSize = F.tellg() / sizeof(Token); // Calculate how many tokens.
F.seekg(0); // Go back to the beginning.

@@ -96,7 +96,7 @@ void TokenMatrix::Load(ifstream& F) {

// TokenMatrix::Validate(key)

void TokenMatrix::Validate(string& SecurityKey) { // Decrypts and validates the matrix.
void TokenMatrix::Validate(std::string& SecurityKey) { // Decrypts and validates the matrix.

MANGLER ValidationChecker; // Create a mangler engine for validation.

@@ -149,7 +149,7 @@ void TokenMatrix::Validate(string& SecurityKey) {

SecurityCheckKey[SecurityKeyBufferSize-1] = 0; // Add a safety null just in case.

string SecurityCheck((char*)SecurityCheckKey); // Make a string.
std::string SecurityCheck((char*)SecurityCheckKey); // Make a string.

// By now we should have a SecurityCheck string to compare to our SecurityKey.
// If they match then we know everything worked out and that our token matrix has
@@ -165,7 +165,7 @@ void TokenMatrix::Validate(string& SecurityKey) {

// TokenMatrix::Verify(key)

void TokenMatrix::Verify(string& SecurityKey) { // Builds and verifies a file digest.
void TokenMatrix::Verify(std::string& SecurityKey) { // Builds and verifies a file digest.

MANGLER DigestChecker; // Create a mangler for the digest.

@@ -800,8 +800,10 @@ int EvaluationMatrix::EvaluateThis(unsigned short int i) {
return PassResult; // When we're finished, return the last known result.
}

void EvaluationMatrix::evaluateSegment(vector<unsigned char>& data, unsigned int start, unsigned int finish) {
void EvaluationMatrix::evaluateSegment(std::vector<unsigned char>& data, unsigned int start, unsigned int finish) {
restartEngineAt(start);
finish = (finish < data.size()) ? finish : data.size();
for(unsigned int a = start; a < finish; a++) EvaluateThis(data[a]);
}

} // End namespace codedweller

+ 47
- 47
snf_engine.hpp Voir le fichier

@@ -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



Chargement…
Annuler
Enregistrer