Hack Forums
[C] Reflection in C++ - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Reflection in C++ (/showthread.php?tid=5534778)



Reflection in C++ - poke1103 - Jan 26, 2017

Hey!

So I know it is possible in Java to take a bunch of classes and load them into a ClassLoader object and use reflection to call methods, or get variables. I know you could also use this to inject mouse events into a program and I'm wondering if it is possible to do something like this for games or programs made in C++?

How can I read the variables of a program during runtime?

Thanks


* - Infamia - Jan 26, 2017

There is a C++ section, use it please.


* - 0xDEAD10CC - Jan 28, 2017

ReadProcessMemory (Windows). Reflection is not a thing with real C++.


* - clrlslwi - Jan 28, 2017

Pretty much all meta data is destroyed when compiling. There might be some due to RTTI, but not enough to do what you're asking.


* - Hoody - Jan 28, 2017

Using vc++ you can reflect .net payloads...

Code
array<byte>^ managedPayload = gcnew array<byte>(Settings->payloadSize);
Marshal::Copy(IntPtr(Settings->payload), managedPayload, 0, Settings->payloadSize);
Assembly^ a = Assembly::Load(managedPayload);
MethodInfo^ m = a->EntryPoint;
Object^ i;
if (m->Name[0] == 0x200b)
{
    i = a->CreateInstance(L"Main");
}
else
{
    i = a->CreateInstance(m->Name);
}
if (m->GetParameters()->Length == 1)
{
    m->Invoke(i, gcnew array <System::Object^> { gcnew array<System::String^> {L""} });
}
else if (m->GetParameters()->Length == 0)
{
        m->Invoke(i, nullptr);
}
else
{
    MessageBoxW(NULL, L"Your .net payload has a parameter count that is not support currently. Please report this error!", L"Error", MB_OK | MB_ICONERROR);
}
m->Invoke(i, nullptr);