I wonder how to declare the reference to a constructor to a reversed class, i.e. I have a class say Game and it has a constructor at a certain address.

It is declared like this:


namespace gladius {
    struct Game {
        //virtual int __thiscall main(gladius::Game* thisptr, int param_1, char** param_2, char** param_3);

        using GameConstructor = Game * (__fastcall*) (Game* thisptr);
        GameConstructor gameConstructor;




namespace gladius {
    static std::array<Game, 1> functions = { {

            (Game::GameConstructor)(AddressHelper::getInstance().GetBaseAddress() + 0x331b0 / (2 * sizeof(DWORD))),

Now let's imagine I want an instance of the Game object. How do I get one as something like this

Game gameObj = gameConstructor; 

is not going to work as gameObj and gameConstructor have different type. Without reversing the constructor is there any way to call it (by address) and assign the reversed class instance to it?


 namespace gladius {
        struct Game {
              using Game = Game * (__fastcall*) (Game* thisptr);
              Game gameConstructor;

doesn't work as a declaration as you can't declare type the same as the type of the class / structure and I don't know how to modify the above to keep it as a reference to the addressed method rather than a fully reversed function.

Basically the question is, how to do

Game objInst = new Game();

where new Game(); points to existing Game constructor (accessible by address offset)?

  • You've been asking similar questions for a while, and all of them are very confusing and don't demonstrate much in the way of understanding how C++ gets compiled into assembly language. Why don't you put this project down for now, get some C++ source code off the Internet, compile it, and inspect the binaries that result? You'll be able to see exactly what the source code for a constructor looks like, and what it looks like in a binary. Commented Nov 12, 2021 at 19:07
  • I suppose there are several points here from my point of view: a) You are right, I should learn more on how C++ works in general and in reversing in particular. On the course of this project I've learned by long short more about it though than was able to with just studying b) There is little to almost non-existent info on the subject. People who do presentations on class reversing often do it either on "Hello World" or are reversing the classes completely, which is impractical in this case
    – Irbis77
    Commented Nov 13, 2021 at 9:58
  • c) I learn better by asking questions. Sometimes simple case of asking question triggers my thought process better than sitting and looking at code or / and reading documentation. Also, this platform is not particularly developed. So, asking questions helps it (I hope). d) I don't have a particular motivation on learning c++ except for completing the project I am doing. As I said, I understand your point, but learning how C++ looks say in assembly might lead to the same problems as I am currently facing, i.e. luck of info on the subject and lack of general community support.
    – Irbis77
    Commented Nov 13, 2021 at 10:02
  • Do you learn better from asking, or from the answers? I could give advice, but it wouldn't be appropriate as an "answer", as the first line would say "stop doing what you are doing". I've written hundreds of thousands of lines of C++, and have never written anything similar to your snippets. Classes, member/virtual functions, constructors, etc. are less complicated as your questions indicate. I'd advise you to learn more about C++, or ask more generic questions, as there's no point in answering questions about an approach that will never work, and is unrelated to how anybody writes C++. Commented Nov 14, 2021 at 1:15
  • Anyway, you may want to read this: reverseengineering.stackexchange.com/questions/26006/… Commented Nov 14, 2021 at 1:15

2 Answers 2


A cleaner and safer(no mem leaks) solution to this problem would be:

struct Game {
    // Define fields so that the size matches the original struct size
    using ConstructorT = Game*(__fastcall)(Game* thisptr);
    static ConstructorT* Constructor = 0x1405A0F8;

    static Game Create() {
        Game Game{};
        return Game;

int main() {
    Game Game = Game::Create();

The difference between this solution and the one presented is that this one doesn't require you to manage memory by yourself and doesn't have any memory leaks.

        gladius::GameStruct* thisptr = (gladius::GameStruct*)malloc(sizeof(gladius::GameStruct));

If something here throws, you have a memory leak and you need to make sure you clean this memory. In my solution if something later throws, it will be automatically cleaned by the compiler once the scope ends, which is at the end of the function in this example. Also instead of returning an object, you can create and return unique or shared pointer and then do whatever you want with it, which is going to also be nice and safe:

    static std::shared_ptr<Game> Create() {
        std::shared_ptr<Game> Game = std::make_shared<Game>();
        return Game;
  • Thank you for sharing. It looks certainly better.
    – Irbis77
    Commented Apr 3 at 15:43

Here is the solution:

The constructor can be called like this:

    gladius::GameStruct* thisptr = (gladius::GameStruct*)malloc(sizeof(gladius::GameStruct));

where sizeof(GameStruct) must match the size of the original constructor. In my case the Game structure should be re-written to have something like:

struct GameStruct : Game{
        DWORD_PTR* unknownPtrA = 0;

        DWORD_PTR* unknownPtrB = 0;

        DWORD_PTR* unknownPtrC = 0;

        DWORD_PTR* unknownPtrD = 0;

        DWORD_PTR* guiObjPtr = 0;

        DWORD_PTR* unknownPtrE = 0;

        DWORD_PTR* unknownPtrF = 0;

        DWORD_PTR* unknownPtrG = 0;

        DWORD_PTR* unknownPtrH = 0;

        DWORD_PTR* unknownPtrI = 0;

        DWORD_PTR* unknownPtrJ = 0;


to bring the pointers in constructor outside of the Game struct. This way it matches the original constructor in what it does and in size (i.e. 11 members 8 bytes each = 88 bytes of size)

Or / and the pointers to the functions should be placed inside the standard C++ functions and be called from there as that way they won't occupy the additional memory space which needs to be allocated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.