Status update and some code
Been quiet the last week because I’ve just moved house. Got everything sorted and up and running now though so I should be able to get some stuff done. I still plan to take a look at some of the bots on the market currently, but have just been so busy lately, and with Mimic already being half-way into their grave I didn’t really think it was urgent to push them in all the way, I think they can take care of that themselves.
Anyway, I figured I may as well post something of use so here’s a C++ logging class I posted on GD that may be of use to people*:
* I’ll post a version with some of the outlined problems fixed Soon. Just gotta get back into the swing of things, moving always shakes me up for a few days.
This is a C++ logging class designed to be both generic and portable. Currently needs fixes in order to be truly portable but I havn’t had time to reinstall G++ or Intel to test, I’ve outlined the minor issues though. If you want to fix the issues it’s a 10 minute job at most, I’m just lazy.
The idea is that you can redirect the standard output streams to a file using a generic class template (so when new character types are added like the ones in C++0x it will be much easier to add support).
This should work across operating systems (Linux, Mac, etc).. Anything with Boost support (which is all major OS’s) SHOULD work, but is untested. Obviously you’ll need to remove the MSVC specific pragmas.
Notes:
* Boost dependency. This will not work without Boost. No I will not help you install Boost, it’s not hard, just read the documentation. If you can’t get it working you probably shouldn’t be using C++.
* Minor modifications needed for it to be truly portable. (See below)
* Relative log file path is hardcoded to “../Logs/Hades-%s.log”. Simply change that to a relative path from your module.
* Compiler is assumed to be MSVC. I am using VS 2008 Team Edition with code analysis enabled. If you get an error about warning “6328″ not being valid simply remove the pragma line with that in it.
* If you are using a compiler other than MSVC you’ll want to remove the ‘pragma warning’ stuff, I’ll fix that later.
* Makes heavy use of templates. Unless you know what you’re doing its probably best to just leave all the typedefs and template stuff alone.Usage:
Makes use of templates and the standard output streams.
For example:
// Logging objects
Logger<char>::Stream m_AnsiStream;
Logger<wchar_t>::Stream m_WideStream;
// Initialize logger
m_AnsiStream.open(Logger<char>());
std::cout.rdbuf(m_AnsiStream.rdbuf());
m_WideStream.open(Logger<wchar_t>());
std::wcout.rdbuf(m_WideStream.rdbuf());Now, whenever you use cout or wcout like so:
std::cout << “Look ma, I’m using the standard output stream!” << std::endl;
std::wcout << L”Wide output too!”"<< std::endl;The output will be redirected to your file rather than to the screen or wherever the standard output was aimed at previously.
Obviously your Logger objects need to remain valid whilst ever your program is running unless you manually reset the standard output stream buffers. This means that you should store them as static objects somewhere. If you store them as a local object then they will be destructed when they move out of scope and you’ll get an access violation.
An alternative to the above is to just heap-allocate the object. Its destructor will never be called but this is probably not a problem. The reason this may be better is that you avoid race conditions implicit in the order of destruction of static objects. Obviously do NOT use a smart pointer because at that point it WILL be deleted and you’re back where you started.
Misc:
You are free to use this for whatever, as long as you agree that Kynox’s sister is a nympho.
Code:
// Preprocessor header guard to stop multiple includes
#ifndef HADES__LOGGER_H
#define HADES__LOGGER_H
// C++ Standard Library
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
// Boost C++ Libraries
#pragma warning(push, 1)
#pragma warning(disable: 6328)
#pragma warning(disable: 4996)
#pragma warning(disable: 4702)
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/format.hpp>
#include <boost/filesystem.hpp>
#pragma warning(pop)
// Logging class
template <typename _charT>
class Logger
{
public:
// Sink information
typedef _charT char_type;
typedef boost::iostreams::sink_tag category;
// STL typedefs
typedef std::basic_ofstream<char_type> tofstream;
typedef std::basic_string<char_type> tstring;
// Boost typedefs
typedef boost::basic_format<char_type> tformat;
struct path_traits;
typedef boost::filesystem::basic_path<tstring, path_traits> tpath;
struct path_traits
{
typedef tstring internal_string_type;
typedef tstring external_string_type;
static external_string_type to_external( const tpath &,
const internal_string_type & src ) { return src; }
static internal_string_type to_internal(
const external_string_type & src ) { return src; }
};
// Stream typedef
typedef boost::iostreams::stream< Logger<_charT> > Stream;
// Constructor
Logger() : m_LogPath(GeneratePath())
{ }
// Generate path to log file.
tstring GeneratePath()
{
// For boost
using namespace boost::posix_time;
using namespace boost::filesystem;
using boost::str;
// For STL
using std::string;
using std::wstring;
// Get local time
ptime Time(second_clock::local_time());
// Convert time to string YYYY-MM-DDTHH:MM:SS
tstring TimeStr(to_iso_extended_string_type<char_type>(Time));
// Reformat time YYYY-MM-DD_HH-MM-SS
TimeStr[10] = ‘_’;
TimeStr[13] = ‘-’;
TimeStr[16] = ‘-’;
// Generate file path relative to initial directory
wstring WideFormat(L”../Logs/Hades-%s.log”);
tstring AnyFormat(WideFormat.begin(), WideFormat.end());
tstring RelPath(str(tformat(AnyFormat) %TimeStr));
// Make full path to log file
tpath Current(initial_path<tpath>());
Current /= RelPath;
// Return path to log file
return Current.string();
}
// Writes n characters from s
std::streamsize write(const char_type* s, std::streamsize n)
{
// For boost
using namespace boost::posix_time;
// Get time
ptime Time(second_clock::local_time());
tstring TimeStr = to_simple_string_type<char_type>(Time);
// Open file
tofstream Out(m_LogPath.c_str(), tofstream::out | tofstream::app );
if(Out.is_open() && Out.good())
{
// Write time as string
Out << ‘[' << TimeStr << "]: “;
// Write data
Out.write(s, n);
}
// Return size
return n;
}
private:
// Path to log file
tstring m_LogPath;
};
#endif // HADES__LOGGER_H
// Preprocessor header guard to stop multiple includes#ifndef HADES__LOGGER_H#define HADES__LOGGER_H// C++ Standard Library#include <iostream>#include <string>#include <vector>#include <fstream>// Boost C++ Libraries#pragma warning(push, 1)#pragma warning(disable: 6328)#pragma warning(disable: 4996)#pragma warning(disable: 4702)#include <boost/iostreams/categories.hpp>#include <boost/iostreams/stream.hpp>#include <boost/date_time/posix_time/posix_time.hpp>#include <boost/format.hpp>#include <boost/filesystem.hpp>#pragma warning(pop)// Logging classtemplate <typename _charT>class Logger{public:// Sink informationtypedef _charT char_type;typedef boost::iostreams::sink_tag category;// STL typedefstypedef std::basic_ofstream<char_type> tofstream;typedef std::basic_string<char_type> tstring;// Boost typedefstypedef boost::basic_format<char_type> tformat;struct path_traits;typedef boost::filesystem::basic_path<tstring, path_traits> tpath;struct path_traits{typedef tstring internal_string_type;typedef tstring external_string_type;static external_string_type to_external( const tpath &,const internal_string_type & src ) { return src; }static internal_string_type to_internal(const external_string_type & src ) { return src; }};// Stream typedeftypedef boost::iostreams::stream< Logger<_charT> > Stream;// ConstructorLogger() : m_LogPath(GeneratePath()){ }// Generate path to log file.tstring GeneratePath(){// For boostusing namespace boost::posix_time;using namespace boost::filesystem;using boost::str;// For STLusing std::string;using std::wstring;// Get local timeptime Time(second_clock::local_time());// Convert time to string YYYY-MM-DDTHH:MM:SStstring TimeStr(to_iso_extended_string_type<char_type>(Time));// Reformat time YYYY-MM-DD_HH-MM-SSTimeStr[10] = ‘_’;TimeStr[13] = ‘-’;TimeStr[16] = ‘-’;// Generate file path relative to initial directorywstring WideFormat(L”../Logs/Hades-%s.log”);tstring AnyFormat(WideFormat.begin(), WideFormat.end());tstring RelPath(str(tformat(AnyFormat) %TimeStr));// Make full path to log filetpath Current(initial_path<tpath>());Current /= RelPath;// Return path to log filereturn Current.string();}// Writes n characters from sstd::streamsize write(const char_type* s, std::streamsize n){// For boostusing namespace boost::posix_time;// Get timeptime Time(second_clock::local_time());tstring TimeStr = to_simple_string_type<char_type>(Time);// Open filetofstream Out(m_LogPath.c_str(), tofstream::out | tofstream::app );if(Out.is_open() && Out.good()){// Write time as stringOut << ‘[' << TimeStr << "]: “;// Write dataOut.write(s, n);}// Return sizereturn n;}private:// Path to log filetstring m_LogPath;};#endif // HADES__LOGGER_H
Got another question for you, i’m also putting it on Kynox’s last post as well- How is WoWInfinity? Has it ever been detected? Can Warden detect it? If not, is that because of whoever wrote it, or just because of the Warden developer?
look forward for your updates on other bots available in the market.
@Eradicator
WoWInfinity in its current form is highly detectable. As far as I know though it has a Glider style tripwire system and is taken down when warden is updated, then checked for detection.
It would be easy to bypass such a system by simply implementing a change into a patch though, like the one that detected ISXWoW.
Great to see some more of your stuff Cypher. I’ve gotta say, I’ve been lving your blog since I stumbled on it a few weeks ago. Being only an entry level programer, about 75% of your code goes over my head, but I still live looking it over and figuring out what snippets of it do. It’s really helped me out a lot on some of my little projects. Just wanted to saythanks for sharing your work with all of us, keep it coming