Advertisement
Guest User

Ethonmem example code

a guest
Jul 7th, 2011
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. // C++ Standard Library:
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdint>
  5.  
  6. // Ethonmem:
  7. #include <Ethonmem.hpp>
  8.  
  9. static std::uintptr_t const CHARACTER_NAME = 0xD7DA88; // WoW ver. 4.20
  10.  
  11. int main()
  12. {
  13.     try
  14.     {
  15.         // First, lets search for the Wow process.
  16.         auto process = Ethon::getProcessByName("Wow.exe");
  17.         if(!process)
  18.         {
  19.             std::cerr << "No process called 'Wow.exe' found.";
  20.             return 1;
  21.         }
  22.  
  23.         // Attach the debugger to the process.
  24.         Ethon::Debugger::get().attach(*process);
  25.  
  26.         // Create a MemoryEditor to read/write memory.
  27.         Ethon::MemoryEditor editor(*process);
  28.  
  29.         // What about our character's name?
  30.         std::string name = editor.read<std::string>(CHARACTER_NAME);
  31.         std::cout << "Currently logged in character: " << name << "\n";
  32.  
  33.         // But maybe we want to update that address later?
  34.         // So let's pattern scan for ClientServices__GetCharacterName function!
  35.         char const pattern_[] =
  36.           "\x0F\xBE\x05\x88\xDA\xD7\x00\xF7\xD8\x1B\xC0\x25\x88\xDA\xD7\x00"
  37.           "\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC";
  38.         std::string pattern(pattern_, sizeof(pattern_) - 1);
  39.         std::string mask("xxx****xxxxx****xxxxxxxxxxxxxxxx");
  40.  
  41.         // Create a scanner object to scan memory.
  42.         Ethon::Scanner scanner(editor);
  43.  
  44.         // Search for pattern in memory regions which are
  45.         // read/executable and not shared
  46.         std::uintptr_t address = scanner.findPattern(pattern, mask, "r-xp");
  47.         std::cout << "Found ClientServices__GetCharacterName at 0x" <<
  48.           std::hex << address << std::dec << std::endl;
  49.         // Ok, this was a bad example as this pattern matches to another
  50.         // function earliert in memory. But you get it, huh? ;)
  51.  
  52.  
  53.         // Let's search for some random value in private data.
  54.         int bla = 1234;
  55.         std::uintptr_t found = scanner.find(bla, "rw-p");
  56.         if(found)
  57.             std::cout << "Found " << editor.read<int>(found) << " at 0x" << found << std::endl;
  58.         else
  59.             std::cout << bla << " was not found" << std::endl;
  60.     }
  61.     catch(Ethon::EthonError const& e)
  62.     {
  63.         Ethon::printError(e, std::cerr);
  64.     }
  65.  
  66.     // Detach the debugger. This should be done automatically,
  67.     // but I consider it good practise.
  68.     Ethon::Debugger::get().detach();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement