Since people have recently been releasing various tools/libraries to help with hack development. . . why not throw another interpreter in the mix. The most interesting thing of this is probably the regex - other than that, its not that different from what people have done before. . .
Interpreter.cpp
Interpreter.hCode:/* Game-Deception Property License 1.0 2005-2008 Game-Deception( www.gamedeception.net ) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR Copyright HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN REGARD TO THE SOFTWARE. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge and publish copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The Software must be redistributed free of charge to third parties. */ /***************************************\ \ HackTools Library / / By Absolution \ \ Source / / Version 1.0.0.171 \ \ / / © Absolution 2003 - 2010 \ \ http://www.game-deception.org / /***************************************/ #include "../Includes.h" //======================================================================================== // Interpreter //---------------------------------------------------------------------------------------- void aui::Interpreter::AddCommand( const std::string &commandName, const commandType_t command ) { commandList[ commandName ] = command; } //---------------------------------------------------------------------------------------- bool aui::Interpreter::Execute( const std::string &rawCommand ) { argumentDeque.clear(); std::string::const_iterator cSartIter = rawCommand.begin(); std::string::const_iterator cEndIter = rawCommand.end(); std::tr1::regex pattern( "(\")(.+?)\\1|(\\S+)" ); std::tr1::smatch res; while( regex_search( cSartIter, cEndIter, res, pattern ) ) { if( res[2].matched ) { argumentDeque.push_back( res[2].str() ); cSartIter = res[2].second; ++cSartIter; } else if( res[3].matched ) { argumentDeque.push_back( res[3].str() ); cSartIter = res[3].second; } else break; } if( !argumentDeque.empty() ) { return ExecuteCommand(); } return false; } //---------------------------------------------------------------------------------------- bool aui::Interpreter::ExecuteCommand() const { commandList_t::const_iterator cCommandIter = commandList.find( argumentDeque.at( COMMAND_POSITION ) ); if( cCommandIter != commandList.end() ) { cCommandIter->second(); return true; } return false; } //---------------------------------------------------------------------------------------- size_t aui::Interpreter::ArgumentSize() const { return argumentDeque.size(); } //---------------------------------------------------------------------------------------- std::string aui::Interpreter::Argument( const std::size_t index ) const { return argumentDeque.at( index ); }
FunctionalityCode:namespace aui { class Interpreter { public: enum { COMMAND_POSITION = 0 }; typedef void ( *commandType_t )(); typedef std::map< std::string, commandType_t > commandList_t; typedef std::deque< std::string > argumentDeque_t; void AddCommand( const std::string &commandName, const commandType_t command ); bool Execute( const std::string &rawCommand ); std::size_t ArgumentSize() const; // argument size template< class T > void Argument( const std::size_t index, T &value ) const { std::istringstream buf( argumentDeque.at( index ) ); buf >> value; if( buf.fail() ) { } } template< class T, class Default > void ArgumentOrDefault( const std::size_t index, T &value, const Default &defaultValue ) const { try { std::istringstream buf( argumentDeque.at( index ) ); buf >> value; if( buf.fail() ) { } } catch ( std::out_of_range ) { value = defaultValue; } } std::string Argument( const std::size_t index ) const; protected: bool ExecuteCommand() const; argumentDeque_t argumentDeque; commandList_t commandList; }; }
This will function just like typing commands into a linux shell/windows cmd prompt. Quotes will group spaced characters/words together.
Example Program
C# VersionCode:Interpreter interpreter; void test() { cout << "blah" << endl; string test = interpreter.Argument( 1 ); int i = 0; interpreter.Argument( 3, &i ); interpreter.ArgumentOrDefault( 99, &i, 300 ); } int _tmain(int argc, _TCHAR* argv[]) { interpreter.AddCommand( "test", &test ); string command = "test BALLS BALS2 3 4 5 LOLOL \"hey thar\""; interpreter.Execute( command ); while( true ) { string keyIn; cin >> keyIn; interpreter.Execute( keyIn ); } return 0; }
Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace Lab_4 { class Interpreter { // Interpreter - basically calls a function based on a string, arguments to the call are available to the function // via the instance of this class (argumentList) public const int COMMAND_POSITION = 0; public delegate void commandType_t(); Dictionary<string, commandType_t> commandList = new Dictionary<string, commandType_t>(); List<string> argumentList = new List<string>(); public void AddCommand( string commandName, commandType_t command ) { commandList[commandName] = command; } public bool Execute( string rawCommand ) { argumentList.Clear(); const int quotesGroup = 2, nonQuotesGroup = 3; Regex regex = new Regex( "\\s+(\")(.+?)\\1|(\\S+)" ); MatchCollection matches = regex.Matches( rawCommand ); for( int i = 0; i != matches.Count; ++i ) { Group QuotesGroup = matches[i].Groups[quotesGroup]; Group NonQuotesGroup = matches[i].Groups[nonQuotesGroup]; if( QuotesGroup.Success ) argumentList.Add( QuotesGroup.Value ); else if( NonQuotesGroup.Success ) argumentList.Add( NonQuotesGroup.Value ); else break; } if( argumentList.Count != 0 ) { return ExecuteCommand(); } return false; } bool ExecuteCommand() { commandType_t command = null; if( commandList.TryGetValue( argumentList[COMMAND_POSITION], out command ) ) { command(); return true; } return false; } public int ArgumentSize() { return argumentList.Count; } public string Argument( int index ) { return argumentList[index]; } } }



Reply With Quote.gif)


