Is it possible to get the value of a class attribute from a running application?

Viewed 30

There is a simulator. In this simulator we have to pass a corridor. In the corridor there is a door and a puzzle, the solution of which opens this door. As soon as we solve the puzzle, the value of the boolean attribute of the class (something like isOpen) changes to true

This corridor needs to be traversed several times. The corridor itself doesn't change, but the puzzle is random each time.

So, I decided to create a macro application that reaches the puzzle and waits until I solve it

And since the simulation has the boolean variable I need, I was wondering: can I get it, in order to then create a delay in the macro until it is true?

The main problem here is that the two programs are not connected in any way.

I also want to note that I have an understanding that all variables lose their names after compilation, and that variable values subsequently occupy a random place in memory

Also, I have experience with programs like CheatEngine, which is to find the address of a value by its value

But I may just not know all the details, thinking that it's impossible, even if in reality there are ways to do it.

For this reason, I would appreciate it if you could explain to me how this can be done, or, if it is not possible, explain why.

Also, I wouldn't mind a response like "Read this "

1 Answers

I understand that you want to inspect one or more properties of an instance of an object at runtime and this can be achieved by using the so-called Reflection.

The latter provides functionalities that allow you to examine objects at runtime, get their Type, read their properties and invoke their methods. It should be used carefully.

Using reflection you can do

// retrieves the value of the property "NameOfProperty" for the instance of object myobj

bool myFlag = myobj.GetType().GetProperty("NameOfProperty").GetValue(myobj, null);
Related