|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(true) { // Search for our startup string or get out. |
|
|
while(true) { // Search for our startup string or get out. |
|
|
|
|
|
|
|
|
try { // Try this...
|
|
|
|
|
|
|
|
|
try { // Try this... |
|
|
ValidBuffer = false; // No valid buffer yet. |
|
|
ValidBuffer = false; // No valid buffer yet. |
|
|
x=FilterChain::GetByte(); // Get the next byte from source. |
|
|
x=FilterChain::GetByte(); // Get the next byte from source. |
|
|
} // If we get the empty signal |
|
|
} // If we get the empty signal |
|
|
// here, we've failed to match. |
|
|
// here, we've failed to match. |
|
|
catch(Empty) { // If so - and we haven't |
|
|
|
|
|
if(0==ScanIx) throw Empty("FilterChainBase64: No more data"); // started then just throw Empty.
|
|
|
|
|
|
State=DEQUEING;DequeIx=0; // If we have then we'll dequeue
|
|
|
|
|
|
|
|
|
catch(const Empty&) { // If so - and we haven't |
|
|
|
|
|
if(0==ScanIx) throw Empty("FilterChainBase64: No more data"); // started then just throw Empty. |
|
|
|
|
|
State=DEQUEING;DequeIx=0; // If we have then we'll dequeue |
|
|
return GetByte(); // it and throw when that's done |
|
|
return GetByte(); // it and throw when that's done |
|
|
} // because Buffer is not valid. |
|
|
} // because Buffer is not valid. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { // When we're done with that part, |
|
|
} else { // When we're done with that part, |
|
|
State=SCANNING; // we set our mode back to scanning, |
|
|
State=SCANNING; // we set our mode back to scanning, |
|
|
ScanIx=DequeIx=0; // reset our indexes to start again,
|
|
|
|
|
|
|
|
|
|
|
|
// Here we either have a buffered byte to dequeue, or we ran out
|
|
|
|
|
|
// of data while attempting to match our startup sequence. If we
|
|
|
|
|
|
// have a vaild byte we return it. If not, we throw No More Data!
|
|
|
|
|
|
|
|
|
|
|
|
if(ValidBuffer) return Buffer;
|
|
|
|
|
|
|
|
|
ScanIx=DequeIx=0; // reset our indexes to start again, |
|
|
|
|
|
|
|
|
|
|
|
// Here we either have a buffered byte to dequeue, or we ran out |
|
|
|
|
|
// of data while attempting to match our startup sequence. If we |
|
|
|
|
|
// have a vaild byte we return it. If not, we throw No More Data! |
|
|
|
|
|
|
|
|
|
|
|
if(ValidBuffer) return Buffer; |
|
|
else throw Empty("FilterChainBase64: No more data"); |
|
|
else throw Empty("FilterChainBase64: No more data"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////// |
|
|
///////////////////////////////////////////////////////////////////////////////////////// |
|
|
// FilterChainDefunker |
|
|
// FilterChainDefunker |
|
|
///////////////////////////////////////////////////////////////////////////////////////// |
|
|
///////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
const char* DefunkerPreamble = " ----[DEFUNKER]---- ";
|
|
|
|
|
|
|
|
|
|
|
|
// Patterns to match
|
|
|
|
|
|
|
|
|
|
|
|
const char* patMatchBR = "<br>";
|
|
|
|
|
|
const char* patMatchP = "<p>";
|
|
|
|
|
|
const char* patNBSP = " ";
|
|
|
|
|
|
const char* patAMP = "&";
|
|
|
|
|
|
const char* patAPOS = "'";
|
|
|
|
|
|
const char* patLT = "<";
|
|
|
|
|
|
const char* patGT = ">";
|
|
|
|
|
|
const char* patQUOT = """;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char* DefunkerPreamble = " ----[DEFUNKER]---- "; |
|
|
|
|
|
|
|
|
|
|
|
// Patterns to match |
|
|
|
|
|
|
|
|
|
|
|
const char* patMatchBR = "<br>"; |
|
|
|
|
|
const char* patMatchP = "<p>"; |
|
|
|
|
|
const char* patNBSP = " "; |
|
|
|
|
|
const char* patAMP = "&"; |
|
|
|
|
|
const char* patAPOS = "'"; |
|
|
|
|
|
const char* patLT = "<"; |
|
|
|
|
|
const char* patGT = ">"; |
|
|
|
|
|
const char* patQUOT = """; |
|
|
|
|
|
|
|
|
// SkipHeaders() waits for the headers to go by before launching Store(). |
|
|
// SkipHeaders() waits for the headers to go by before launching Store(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StoreBuffer[InputPosition++] = x; // and storing it. |
|
|
StoreBuffer[InputPosition++] = x; // and storing it. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
catch(Empty) { // When we get the Empty |
|
|
|
|
|
|
|
|
catch(const Empty&) { // When we get the Empty |
|
|
Master = &FilterChainDefunker::ReadOut; // signal it is time for us |
|
|
Master = &FilterChainDefunker::ReadOut; // signal it is time for us |
|
|
return GetByte(); // to read out our data. |
|
|
return GetByte(); // to read out our data. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return GetInternal(); // and return the next byte. |
|
|
return GetInternal(); // and return the next byte. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
unsigned char FilterChainDefunker::DefunkRoot() { // While in DefunkRoot state...
|
|
|
|
|
|
unsigned char x = 0; // One byte at a time via x.
|
|
|
|
|
|
|
|
|
|
|
|
do { // Loop through any emptiness.
|
|
|
|
|
|
ReturnNothing = false; // Be ready to return a byte.
|
|
|
|
|
|
x = GetStore(); // Grab the next byte to process.
|
|
|
|
|
|
|
|
|
unsigned char FilterChainDefunker::DefunkRoot() { // While in DefunkRoot state... |
|
|
|
|
|
unsigned char x = 0; // One byte at a time via x. |
|
|
|
|
|
|
|
|
|
|
|
do { // Loop through any emptiness. |
|
|
|
|
|
ReturnNothing = false; // Be ready to return a byte. |
|
|
|
|
|
x = GetStore(); // Grab the next byte to process. |
|
|
|
|
|
|
|
|
if(x == '<') { // If it matches < then |
|
|
if(x == '<') { // If it matches < then |
|
|
Internal = &FilterChainDefunker::OpenTag; // go to OpenTag state and |
|
|
Internal = &FilterChainDefunker::OpenTag; // go to OpenTag state and |
|
|
x = GetInternal(); // return the converted byte. |
|
|
x = GetInternal(); // return the converted byte. |
|
|
} else |
|
|
} else |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(x == '&') { // If it matches & then |
|
|
if(x == '&') { // If it matches & then |
|
|
Internal = &FilterChainDefunker::OpenAmp; // go to OpenAnd state and |
|
|
Internal = &FilterChainDefunker::OpenAmp; // go to OpenAnd state and |
|
|
EnQueue(x); // push in the amphersand. |
|
|
EnQueue(x); // push in the amphersand. |
|
|
x = GetInternal(); // return the converted byte. |
|
|
x = GetInternal(); // return the converted byte. |
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If x is none of the above then x is just x.
|
|
|
|
|
|
|
|
|
|
|
|
} while (true == ReturnNothing); // Returning nothing? Go again!
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If x is none of the above then x is just x. |
|
|
|
|
|
|
|
|
|
|
|
} while (true == ReturnNothing); // Returning nothing? Go again! |
|
|
return x; // otherwise return a funkless x. |
|
|
return x; // otherwise return a funkless x. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char FilterChainDefunker::EatTag() { // If our mode is EatTag |
|
|
unsigned char FilterChainDefunker::EatTag() { // If our mode is EatTag |
|
|
if(LastGetStore != '>') { // and our last byte was not |
|
|
if(LastGetStore != '>') { // and our last byte was not |
|
|
while(GetStore()!='>')continue; // endtag then eat through |
|
|
while(GetStore()!='>')continue; // endtag then eat through |
|
|
} // the end tag. Then set our
|
|
|
|
|
|
|
|
|
} // the end tag. Then set our |
|
|
ReturnNothing = true; // ReturnNothing flag, set our |
|
|
ReturnNothing = true; // ReturnNothing flag, set our |
|
|
Internal = &FilterChainDefunker::DefunkRoot; // mode to DefunkRoot and |
|
|
Internal = &FilterChainDefunker::DefunkRoot; // mode to DefunkRoot and |
|
|
return 0; // return 0 (nothing, really). |
|
|
return 0; // return 0 (nothing, really). |