Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT load .dll but not calling resolve returns false
Forum Updated to NodeBB v4.3 + New Features

QT load .dll but not calling resolve returns false

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 5 Posters 7.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sunfluxgames
    wrote on last edited by
    #14

    DWORD dwReserved[10];

    Just points to the BOOL WINAPI DllMain. Msvc 2015 (QT create). As for the lib and dll its already been done and was used in the other project.

    I was making a GUI/QT project out of this so i was converting a lot of c/C++ code to pure C++ QT. Ran into problems came here to ask.

    Sorry for my wording as explaining from my brain to paper i'm not very good at.

    kshegunovK 1 Reply Last reply
    0
    • S Sunfluxgames

      DWORD dwReserved[10];

      Just points to the BOOL WINAPI DllMain. Msvc 2015 (QT create). As for the lib and dll its already been done and was used in the other project.

      I was making a GUI/QT project out of this so i was converting a lot of c/C++ code to pure C++ QT. Ran into problems came here to ask.

      Sorry for my wording as explaining from my brain to paper i'm not very good at.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #15

      @Sunfluxgames said in QT load .dll but not calling resolve returns false:

      Just points to the BOOL WINAPI DllMain.

      I don't follow how's the DllMain involved. This is a member of your class, meaning that it's a memory you've allocated for your object so it can be used by the class to place its data in.

      As for the lib and dll its already been done and was used in the other project.

      Excellent. You can use that lib the same way you have used it before - by linking, and everything should be working just normally, you don't actually need to resolve the methods at runtime. Is it that you're unsure how to link the library using QtCreator?

      Sorry for my wording as explaining from my brain to paper i'm not very good at.

      Not a big issue, I'm trying to understand what's been done and how, and how to assist you.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sunfluxgames
        wrote on last edited by
        #16

        @kshegunov

        SetKeyType SetKey = reinterpret_cast<SetKeyType>(resolvedAddress);
        error: C2440: 'reinterpret_cast': cannot convert from SetKeyType *' to 'void

        so still something wrong with your code

        But there still should be no reason I can't load the dll get the proccess create a function that points to the address and use the function in my application. Why its not working I have no idea?

        kshegunovK 1 Reply Last reply
        0
        • S Sunfluxgames

          @kshegunov

          SetKeyType SetKey = reinterpret_cast<SetKeyType>(resolvedAddress);
          error: C2440: 'reinterpret_cast': cannot convert from SetKeyType *' to 'void

          so still something wrong with your code

          But there still should be no reason I can't load the dll get the proccess create a function that points to the address and use the function in my application. Why its not working I have no idea?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #17

          @Sunfluxgames said in QT load .dll but not calling resolve returns false:

          so still something wrong with your code

          No idea, should be working. Can you post the whole snippet that generated this error?

          But there still should be no reason I can't load the dll get the proccess create a function that points to the address and use the function in my application.

          Yes, it should be possible.

          Why its not working I have no idea?

          I don't know either.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sunfluxgames
            wrote on last edited by
            #18

            @kshegunov

            In my header i add the typedef

            // crypt.h
            typedef void (Crypt::*SetKeyType)(const char *, const char *, const char *, const char *);
            

            Now inside my .cpp file create the function and arguments like this.

            void Crypt::DecSetKey()
            {
            	void * resolvedAddress = library.resolve("?SetKey@CRockCrypto@RockBase@@QAEXPBD000@Z");
            	SetKeyType SetKey = reinterpret_cast<SetKeyType>(resolvedAddress);
            	if (!SetKey)
            	{
            		//Unable to load RockBase::CRockCrypto::SetKey Decrypt function
            		return;
            	}
            	else
            	{
            		//Successful loading of RockBase::CRockCrypto::SetKey Decrypt function
            	}
            
            	quint8 decKey1[] = { 0x7D, 0x44, 0x01, 0x00, 0x83, 0xEC, 0x24, 0x83, 0x25, 0xB8, 0x8C, 0x4A, 0x0D, 0x56, 0x8B, 0x75 };
            	quint8 decKey2[] = { 0x1C, 0x8D, 0x1C, 0x57, 0x50, 0xCE, 0xE8, 0x6F, 0x85, 0xFE, 0xFF, 0x8B };
            	quint8 decKey3[] = { 0x76, 0x0C, 0x50, 0x45, 0x14, 0x83, 0x65, 0xFC, 0x56, 0x50, 0x7D, 0xD1, 0x74, 0x03, 0xB8, 0x43 };
            	quint8 decKey4[] = { 0x8B, 0x47, 0xDD, 0x6A, 0xE8, 0x14, 0x83, 0xC4, 0xBC, 0xF3, 0x7F, 0x75 };
            
            	(crypto->*SetKey)(0, (const char*)decKey1, 0, 0);
            	(crypto->*SetKey)((const char*)decKey2, 0, 0, 0);
            	(crypto->*SetKey)(0, (const char*)decKey3, 0, 0);
            	(crypto->*SetKey)((const char*)decKey4, 0, 0, 0);
            
                //void __thiscall RockBase::CRockCrypto::SetKey(RockBase::CRockCrypto *this, const char *, const char *, const char *, const char *)
            }
            

            The error it gives is this.

            error C2440: 'reinterpret_cast': cannot convert from 'void *' to 'SetKeyType'
            

            So if i got this right sorry if i'm wrong. Your createing a void base class with a function called setkeytype with a pointer of setkey that your trying to reinterpret_cast the pointer to the fucntion with the resolved address?

            And the error is because you can't covert a void to function call.

            kshegunovK 1 Reply Last reply
            0
            • S Sunfluxgames

              @kshegunov

              In my header i add the typedef

              // crypt.h
              typedef void (Crypt::*SetKeyType)(const char *, const char *, const char *, const char *);
              

              Now inside my .cpp file create the function and arguments like this.

              void Crypt::DecSetKey()
              {
              	void * resolvedAddress = library.resolve("?SetKey@CRockCrypto@RockBase@@QAEXPBD000@Z");
              	SetKeyType SetKey = reinterpret_cast<SetKeyType>(resolvedAddress);
              	if (!SetKey)
              	{
              		//Unable to load RockBase::CRockCrypto::SetKey Decrypt function
              		return;
              	}
              	else
              	{
              		//Successful loading of RockBase::CRockCrypto::SetKey Decrypt function
              	}
              
              	quint8 decKey1[] = { 0x7D, 0x44, 0x01, 0x00, 0x83, 0xEC, 0x24, 0x83, 0x25, 0xB8, 0x8C, 0x4A, 0x0D, 0x56, 0x8B, 0x75 };
              	quint8 decKey2[] = { 0x1C, 0x8D, 0x1C, 0x57, 0x50, 0xCE, 0xE8, 0x6F, 0x85, 0xFE, 0xFF, 0x8B };
              	quint8 decKey3[] = { 0x76, 0x0C, 0x50, 0x45, 0x14, 0x83, 0x65, 0xFC, 0x56, 0x50, 0x7D, 0xD1, 0x74, 0x03, 0xB8, 0x43 };
              	quint8 decKey4[] = { 0x8B, 0x47, 0xDD, 0x6A, 0xE8, 0x14, 0x83, 0xC4, 0xBC, 0xF3, 0x7F, 0x75 };
              
              	(crypto->*SetKey)(0, (const char*)decKey1, 0, 0);
              	(crypto->*SetKey)((const char*)decKey2, 0, 0, 0);
              	(crypto->*SetKey)(0, (const char*)decKey3, 0, 0);
              	(crypto->*SetKey)((const char*)decKey4, 0, 0, 0);
              
                  //void __thiscall RockBase::CRockCrypto::SetKey(RockBase::CRockCrypto *this, const char *, const char *, const char *, const char *)
              }
              

              The error it gives is this.

              error C2440: 'reinterpret_cast': cannot convert from 'void *' to 'SetKeyType'
              

              So if i got this right sorry if i'm wrong. Your createing a void base class with a function called setkeytype with a pointer of setkey that your trying to reinterpret_cast the pointer to the fucntion with the resolved address?

              And the error is because you can't covert a void to function call.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #19

              Nope, it looks correct. Very odd.

              Your createing a void base class with a function called setkeytype with a pointer of setkey that your trying to reinterpret_cast the pointer to the fucntion with the resolved address?

              Yes, approximately.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sunfluxgames
                wrote on last edited by
                #20

                Here are the 2 dll's maybe you can get them to work for me? Thanks for your help.

                http://s000.tinyupload.com/?file_id=87880318125036589695

                kshegunovK 1 Reply Last reply
                0
                • hskoglundH Online
                  hskoglundH Online
                  hskoglund
                  wrote on last edited by
                  #21

                  Hi, was curious and l looked at your .DLLs, 2 problems I saw:

                  After doing a library.resolve("?SetKey@CRockCrypto@RockBase@@QAEXPBD000@Z") you end up with a function pointer that works fine for calling that function directly. However you want to cast it into non-static pointer-to-member function and a reinterpret_cast<> of it I think will not suffice, it's still only a GetProcAddress() type of function pointer :-( A pointer-to-member function pointer is usually just an offset into a vtable or something similar, also compiler dependent.

                  Another problem: if you disassemble the loaded functions you'll see that the first thing that the "SetKey..." function does is trash its this pointer (move ecx,esi) and call another Crypto function. Not very C++ friendly, most likely this is some kind of assembly obfuscation going on. It's a game library after all...

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Sunfluxgames
                    wrote on last edited by
                    #22

                    I created a fake lib and header with my console app, and just called the functions normally and was able to get the application to do what i want.

                    The Dll calls a function called Cleanup which trash the this pointer. To bypass this if you setkey to the decKey2 and it doesn't call this function keeping it in tacked. After you call SetKey you call the RockBase::CRockCrypto::Decrypt(void*, int) function that runs through aes cryto that decrypted a encrypted buffer base on size of buffer.

                    This is just a old old game (2007) .dll that uses aes encryption decryption on packets.

                    1 Reply Last reply
                    0
                    • S Sunfluxgames

                      Here are the 2 dll's maybe you can get them to work for me? Thanks for your help.

                      http://s000.tinyupload.com/?file_id=87880318125036589695

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #23

                      @Sunfluxgames said in QT load .dll but not calling resolve returns false:

                      Here are the 2 dll's maybe you can get them to work for me?

                      I can't, sorry. I don't have windows currently, nor do I use MSVC when building on windows, besides I have a lot of work of my own currently.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Adhitya1978
                        wrote on last edited by
                        #24

                        Qloadlib working properly as load library.
                        as i know dll without header can't use exported function directly,need to look the function & how to use exported function properly.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved