Sample Code - Another way of getting the EndScene address menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sample Code - Another way of getting the EndScene address

    No binaries provided because
    1) It would be pointless; This is just some proof of concept code.
    2) I don't want to deal with all the retards yelling keylogger! because it makes http connections to the MS symbol server.

    Uses dbghelp.dll and symsrv.dll from Hardware Developer Debugging Tools for Windows 32-bit version
    You probably want to change the symbol search path to your own preference..

    Credits:
    Cypher - Stole his exception handling code from HadesMem
    MSDN

    SymbolHandler.h
    Code:
    #pragma once
    
    #include <Windows.h>
    // Set DbgHelp to use unicode strings
    #define DBGHELP_TRANSLATE_TCHAR
    #include <DbgHelp.h>
    #include <string>
    #include <boost/exception/all.hpp>
    
    namespace MSoft
    {
    	// Exception handling code stolen from HadesMem
    	typedef boost::error_info<struct TagErrorString, std::string> ErrorString;
    	typedef boost::error_info<struct TagErrorCode, DWORD> ErrorCode;
    
    	class SHError : public virtual std::exception, public virtual boost::exception
    	{
    	};
    
    	class SymbolHandler
    	{
    	public:
    		SymbolHandler();
    		SymbolHandler(HANDLE process);
    		SymbolHandler(HANDLE process, const std::wstring& searchPath);
    		~SymbolHandler();
    
    		void LoadSymbolsForModule(const std::wstring& moduleName);
    		LPVOID GetAddressFromSymbol(const std::wstring& name, bool throwOnFailure = true);
    
    	private:
    		void Init(HANDLE process, const std::wstring& searchPath);
    		void Cleanup();
    
    		HANDLE _process;
    	};
    }
    SymbolHandler.cpp
    Code:
    #include "SymbolHandler.h"
    #include <vector>
    
    #pragma comment(lib, "dbghelp")
    
    namespace MSoft
    {
    	SymbolHandler::SymbolHandler()
    	{
    		_process = NULL;
    		Init(GetCurrentProcess(), NULL);
    	}
    
    	SymbolHandler::SymbolHandler(HANDLE process)
    	{
    		_process = NULL;
    		Init(process, NULL);
    	}
    
    	SymbolHandler::SymbolHandler(HANDLE process, const std::wstring& searchPath)
    	{
    		_process = NULL;
    		Init(process, searchPath);
    	}
    
    	SymbolHandler::~SymbolHandler()
    	{
    		Cleanup();
    	}
    
    	void SymbolHandler::Init(HANDLE process, const std::wstring& searchPath)
    	{
    		if(_process)
    			Cleanup();
    
    		// SYMOPT_DEBUG is not really needed, but debug output is always good
    		// if something goes wrong
    		SymSetOptions(SYMOPT_DEBUG | SYMOPT_DEFERRED_LOADS | SYMOPT_UNDNAME);
    		if(!SymInitialize(process, searchPath.c_str(), FALSE))
    			BOOST_THROW_EXCEPTION(SHError() << ErrorString("SymInitialize() failed") << ErrorCode(GetLastError()));
    		_process = process;
    	}
    
    	void SymbolHandler::Cleanup()
    	{
    		if(_process)
    		{
    			if(!SymCleanup(_process))
    				BOOST_THROW_EXCEPTION(SHError() << ErrorString("SymCleanup() failed") << ErrorCode(GetLastError()));
    			_process = NULL;
    		}
    	}
    
    	void SymbolHandler::LoadSymbolsForModule(const std::wstring& moduleName)
    	{
    		HMODULE h = GetModuleHandle(moduleName.c_str());
    		if(!SymLoadModuleEx(_process, NULL, moduleName.c_str(), NULL, (DWORD64)h, 0, NULL, 0))
    			BOOST_THROW_EXCEPTION(SHError() << ErrorString("SymLoadModuleEx() failed") << ErrorCode(GetLastError()));
    	}
    
    	LPVOID SymbolHandler::GetAddressFromSymbol(const std::wstring& name, bool throwOnFailure)
    	{
    		std::vector<char> buffer;
    		buffer.resize(sizeof(SYMBOL_INFO) + name.length() * sizeof(wchar_t) + 1);
    		PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer.data();
    		pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
    		pSymbol->MaxNameLen = name.length() * sizeof(wchar_t) + 1;
    		LPVOID ret = NULL;
    		if(!SymFromName(_process, name.c_str(), pSymbol))
    		{
    			// If you know your symbol name is valid then this most likely happens
    			// because symsrv.dll isn't loaded.
    			if(throwOnFailure)
    				BOOST_THROW_EXCEPTION(SHError() << ErrorString("SymFromName() failed") << ErrorCode(GetLastError()));
    			else
    				return NULL;
    		}
    		return (LPVOID)pSymbol->Address;
    	}
    }
    DllMain.cpp
    Code:
    #include "SymbolHandler.h"
    
    using MSoft::SymbolHandler;
    
    BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID)
    {
    	return TRUE;
    }
    
    void __declspec(dllexport) Load(const char* str)
    {
    	std::wstring searchPath = L"SRV*C:\\ProgramData\\Symbols*http://msdl.microsoft.com/download/symbols";
    	try
    	{
    		SymbolHandler sh(GetCurrentProcess(), searchPath);
    		sh.LoadSymbolsForModule(L"d3d9");
    		LPVOID address = sh.GetAddressFromSymbol(L"CD3DBase::EndScene");
    		std::wostringstream str;
    		str << "EndScene address: 0x" << std::hex << address;
    		MessageBox(NULL, str.str().c_str(), L"Info", MB_ICONINFORMATION);
    	}
    	catch(std::exception const& e)
    	{
    		MessageBoxA(NULL, boost::diagnostic_information(e).c_str(), "Error!", MB_ICONERROR);
    	}
    }
    Last edited by _Mike; 11-13-2010 at 04:58 PM.

    Sample Code - Another way of getting the EndScene address
  2. #2
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice job! (Totally gonna steal your idea for HadesMem )

  3. #3
    Shenlok's Avatar Active Member
    Reputation
    15
    Join Date
    Jul 2008
    Posts
    42
    Thanks G/R
    6/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems like quite a nice solution, thanks for sharing _Mike.

  4. #4
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh btw, for reading the symbol path, you should try checking the '_NT_SYMBOL_PATH' environmental var.

  5. #5
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I know, that's why I have the SymbolHandler::SymbolHandler(HANDLE process) constructor.
    SymInitialize Function (Windows)
    UserSearchPath [in, optional]
    The path, or series of paths separated by a semicolon (;), that is used to search for symbol files. If this parameter is NULL, the library attempts to form a symbol path from the following sources:

    The current working directory of the application
    The _NT_SYMBOL_PATH environment variable
    The _NT_ALTERNATE_SYMBOL_PATH environment variable
    The explicit path in the op was just there to demonstrate usage.

    Also, if anyone is having problems with the dbghelp library functions failing; You need to have matching versions of dbghelp.dll and symsrv.dll in the same directory. symsrv.dll will NOT be loaded from the standard search path.
    Calling the DbgHelp Library (Windows)
    Last edited by _Mike; 11-13-2010 at 10:18 PM.

  6. #6
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah right, didn't read closely enough. Cool.

  7. #7
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Update:
    Serious bug in the original code.. (Note to self; Test before posting) NULL references are baad.
    Replacement methods
    Code:
    SymbolHandler::SymbolHandler(HANDLE process, const std::wstring& searchPath)
    {
    	_process = NULL;
    	Init(process, &searchPath);
    }
    
    void SymbolHandler::Init(HANDLE process, const std::wstring* searchPath)
    {
    	if(_process)
    		Cleanup();
    
    	const wchar_t* path = searchPath ? searchPath->c_str() : NULL;
    
    	SymSetOptions(SYMOPT_DEBUG | SYMOPT_DEFERRED_LOADS | SYMOPT_UNDNAME);
    	if(!SymInitialize(process, path, FALSE))
    		BOOST_THROW_EXCEPTION(SHError() << ErrorString("SymInitialize() failed") << ErrorCode(GetLastError()));
    	_process = process;
    }

  8. #8
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool. This way looks much better than creating a new device and getting it like that, much less invasive. Still, the 2 offsets required for this particular address (in WoW) seems much easier. I guess this would be useful for a generic EndScene hook though.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  9. #9
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by MaiN View Post
    Cool. This way looks much better than creating a new device and getting it like that, much less invasive. Still, the 2 offsets required for this particular address (in WoW) seems much easier. I guess this would be useful for a generic EndScene hook though.
    Yeah you won't have the same issues as if you happen to create a device that has parameters incompatible with the original d3d device so it works on any d3d* game. (There might be issues if the game uses a custom wrapper with the same module name as the d3d dlls; I haven't tested)
    It's also not limited to EndScene hooking obviously. Microsoft has symbol libraries for almost all of the public windows apis, and lots of the undocumented internals as well. For example, ntdll!ShowSnaps is a variable I found very useful when debugging my dll injector.
    But then there's the drawback of needing an internet connection, or having the relevant symbols pre-downloaded. And then there's all the "experts" who will claim that your dll is a keylogger because their firewall tells them it tries to connect to microsoft.com

    As to using static offsets being easier or not; I guess that depends on how you define easier.
    It would make the code a lot less complicated and less sources for errors. But for someone like me, who isn't that good at reverse engineering, this method would be a lot easier. I could probably find the device pointers myself, but it would take a lot longer than it took for me writing this class.
    I guess I could always just come here and look through the info dump threads after a patch, but that would be cheating And I'd be to dependent on others to do the work for me.

  10. #10
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I always prefer generic solutions over game-specific ones because whilst it's more work up-front it's less work overall if you're working on a lot of targets.

    The fact that an internet connection is required for this is definitely a downside, but it's not like it needs to download it every time, after the first download it'll usually just be able to pull it from your symbol cache (unless of course the DLL is updated). Besides, who doesn't have an always-on internet connection nowadays?

  11. #11
    Greyman's Avatar Active Member
    Reputation
    61
    Join Date
    Oct 2006
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    Besides, who doesn't have an always-on internet connection nowadays?
    People who let the Blizzard Downloader bork their internet download limits leap to mind :P

  12. #12
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Greyman View Post
    People who let the Blizzard Downloader bork their internet download limits leap to mind :P
    As if that's my fault. I was asleep! >.<

    That's one of the downsides of having a fast internet connection. When something like that happens you're pretty much ****ed in regards to your monthly usage quota.

  13. #13
    adaephon's Avatar Active Member
    Reputation
    76
    Join Date
    May 2009
    Posts
    167
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    That's one of the downsides of having a fast internet connection. When something like that happens you're pretty much ****ed in regards to your monthly usage quota.
    Fast internet connection and low download quota....that sounds like Telstra....

  14. #14
    jjaa's Avatar Contributor
    Reputation
    245
    Join Date
    Dec 2006
    Posts
    562
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ewwww telstra, i'll stick with iinet, reasonably fast connection, large quota . However, i wonder do Americans know what a download quota is? i hear they have it pretty good over there.

  15. #15
    dook123's Avatar Active Member
    Reputation
    21
    Join Date
    Oct 2008
    Posts
    115
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    iconnection

    30Meg Connection and no Quota
    Aka- America

Page 1 of 2 12 LastLast

Similar Threads

  1. Another Way To Get On Top Of The WG Fortress
    By Rollet in forum World of Warcraft Exploration
    Replies: 4
    Last Post: 05-11-2009, 06:41 PM
  2. Another way to get unbanned.
    By JoeBiden in forum World of Warcraft Guides
    Replies: 8
    Last Post: 08-16-2008, 02:21 PM
  3. A New way to get the s_curMgr pointer
    By kynox in forum WoW Memory Editing
    Replies: 5
    Last Post: 04-01-2008, 09:39 AM
  4. A way of getting the last name
    By Nomiss in forum WoW Scam Prevention
    Replies: 3
    Last Post: 11-10-2007, 12:58 PM
  5. Another way to get money
    By Xzillios in forum WoW Scam Prevention
    Replies: 5
    Last Post: 01-28-2007, 02:38 AM
All times are GMT -5. The time now is 04:36 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search