-
Angry Penguin
GreyMagic - The best of both worlds, and then some
Download: https://dl.dropbox.com/u/2068143/GreyMagic.7z
So, I wrote this a while back for our bots (Honorbuddy, Demonbuddy, BuddyWing, etc). It's a full-featured memory lib for both in and out of process memory handling. Performance tests show that it's barely a tick slower than calling ReadProcessMemory directly on simple data types, and slightly over a tick slower than reading structures. (Write speeds have not been tested, as writing is not done nearly as often)
The following are for perf tests over 1 million iterations:
Read<int>(addr, relative: true) - 4.57 ticks
ReadProcessMemory (direct) - 3.54 ticks
Deref on ReadBytes(addr, relative: true) - 3.90 ticks
Read<NonMarshalStruct>(addr, relative: true) - 5.06 ticks
Read<MarshalStruct>(addr, relative: true) - 6.48 ticks
The library itself implements a neat little trick to avoid using the marshaler wherever possible. MarshalCache<T> provides a way to cache certain data for types (size, typeof(), whether the type needs to be run through the marshaler, etc), as well as implements a way for C# to take a pointer to a generic type. (You can't do &T in C#... well... at least you couldn't)
The lib itself takes into account quite a few things, and should hopefully be plug-and-play ready. It includes a few other things that aren't really useful (but tossed in for the sake of tossing it in). I will be adding more features in the future (it lacks a pattern scanner). Feel free to use and abuse, please let me know of any bugs you run into.
In-process memory class: InProcessMemoryReader
OOP memory class: ExternalProcessMemoryReader
Enjoy folks!
-
Post Thanks / Like - 1 Thanks
Parog (1 members gave Thanks to Apoc for this useful post)
-
Banned
-
Active Member
-
Sergeant
-
Good job. Well done.
-
Sweet, thanks for sharing.
-
Contributor
ah sweet! I have been waiting since you mentioned it in the WhiteMagic thread. Thanks for the work as always!
-
Banned
Apoc I read a post a few months(maybe a year + ago? ) where you spoke about grey magic and possibly releasing it. Since that day I decided to halt my wow development... but since you just released this, I guess I can start again since I have an active account at the moment (:
Thank you so much!
-
Banned
Originally Posted by
z0m
Haha, thanks, as always!
Working great. Thanks again, also for the info you gave in a PM some time ago.
Last edited by z0m; 10-02-2012 at 11:24 PM.
-
Sergeant
Thanks starting to learn Memory Editing now!
Last edited by Require; 10-03-2012 at 01:03 PM.
-
Corporal
-
Originally Posted by
Apoc
The library itself implements a neat little trick to avoid using the marshaler wherever possible. MarshalCache<T> provides a way to cache certain data for types (size, typeof(), whether the type needs to be run through the marshaler, etc), as well as implements a way for C# to take a pointer to a generic type. (You can't do &T in C#... well... at least you couldn't)
I've downloaded this, because of this ^ and then I found some basic C# stuff I didn't even knew about like the double question mark operator or the fact that classes can have a static constructor ._. I feel realy noobish right now.
Thanks for sharing! It's realy instructive
Edit:
Do you mind giving us a short example how to use the DetourManager?
Last edited by xalcon; 10-03-2012 at 06:41 PM.
"Threads should always commit suicide - they should never be murdered" - DirectX SDK
-
Angry Penguin
Originally Posted by
xalcon
I've downloaded this, because of this ^ and then I found some basic C# stuff I didn't even knew about like the double question mark operator or the fact that classes can have a static constructor ._. I feel realy noobish right now.
Thanks for sharing! It's realy instructive
Edit:
Do you mind giving us a short example how to use the DetourManager?
Code:
if (_canTrackUnitOriginal == null) _canTrackUnitOriginal = Memory.CreateFunction<PlayerCanTrack>((IntPtr)GlobalOffsets.CGPlayer_C__CanTrackUnit, true);
if (_canTrackObjectOriginal == null)
_canTrackObjectOriginal = Memory.CreateFunction<PlayerCanTrack>((IntPtr)GlobalOffsets.CGPlayer_C__CanTrackObject, true);
if (_myCanTrackUnit == null)
_myCanTrackUnit = CanTrackUnitDetour;
if (_myCanTrackObject == null)
_myCanTrackObject = CanTrackObjectDetour;
Memory.Detours.CreateAndApply(_canTrackUnitOriginal, _myCanTrackUnit, "CanTrackUnitDetour");
Memory.Detours.CreateAndApply(_canTrackObjectOriginal, _myCanTrackObject, "CanTrackObjectDetour");
Code:
private bool CanTrackUnitDetour(IntPtr pUnit, IntPtr unk)
{
if (_trackedUnits.Count > 0)
{
var unit = new WoWUnit(pUnit);
return unit.IsValid &&
(_trackedUnits.Contains(unit.Name.ToLower()) ||
_trackedUnits.Any(s => !string.IsNullOrEmpty(s) && unit.Name.ToLower().Contains(s.ToLower())));
}
return (bool)Memory.Detours["CanTrackUnitDetour"].CallOriginal(pUnit, unk);
}
-
@Apoc: awesome! It all makes sense now, thank you!
"Threads should always commit suicide - they should never be murdered" - DirectX SDK
-
★ Elder ★