Due to the impossibility of implicit conversion from type char * to type int * in the project, an error occurs during compilation:

... \ ProcMem.cpp In-file included from ProcMem.cpp
... \ ProcMem.h In member function 'cData ProcMem :: Read (DWORD, char *, BOOL)':
... \ ProcMem.h [Error] no matching function for call to 'ProcMem :: iSizeOfArray (char * &)'
... \ ProcMem.h [Note] candidate is:
... \ ProcMem.cpp In-file included from ProcMem.cpp
... \ ProcMem.h [Note] int ProcMem :: iSizeOfArray (int *)
... \ ProcMem.h [Note] from 'char *' to 'int *'

What do I need to change in ProcMem.h?

#ifndef PROCMEM_H //If Not Defined #define PROCMEM_H //Define Now #define WIN32_LEAN_AND_MEAN //Excludes Headers We Wont Use (Increase Compile Time) #include <assert.h> #include <windows.h> //Standard Windows Functions/Data Types #include <iostream> //Constains Input/Output Functions (cin/cout etc..) #include <TlHelp32.h> //Contains Read/Write Functions #include <string> //Support For Strings #include <sstream> //Supports Data Conversion using namespace std; class ProcMem{ protected: //STORAGE HANDLE hProcess; DWORD dwPID, dwProtection, dwCaveAddress; //MISC BOOL bPOn, bIOn, bProt; public: //MISC FUNCTIONS ProcMem(); ~ProcMem(); int chSizeOfArray(char *chArray); //Return Size Of External Char Array int iSizeOfArray(int *iArray); //Return Size Of External Int Array bool iFind(int *iAry, int iVal); //Return Boolean Value To Find A Value Inside An Int Array #pragma region TEMPLATE MEMORY FUNCTIONS //REMOVE READ/WRITE PROTECTION template <class cData> void Protection(DWORD dwAddress) { if (!bProt) VirtualProtectEx(hProcess, (LPVOID)dwAddress, sizeof(cData), PAGE_EXECUTE_READWRITE, &dwProtection); //Remove Read/Write Protection By Giving It New Permissions else VirtualProtectEx(hProcess, (LPVOID)dwAddress, sizeof(cData), dwProtection, &dwProtection); //Restore The Old Permissions After You Have Red The dwAddress bProt = !bProt; } //READ MEMORY template <class cData> cData Read(DWORD dwAddress) { cData cRead; //Generic Variable To Store Data ReadProcessMemory(hProcess, (LPVOID)dwAddress, &cRead, sizeof(cData), NULL); //Win API - Reads Data At Specified Location return cRead; //Returns Value At Specified dwAddress } //READ MEMORY - Pointer template <class cData> cData Read(DWORD dwAddress, char *Offset, BOOL Type) { //Variables int iSize = iSizeOfArray(Offset) - 1; //Size Of *Array Of Offsets dwAddress = Read<DWORD>(dwAddress); //HEX VAL //Loop Through Each Offset & Store Hex Value (Address) for (int i = 0; i < iSize; i++) dwAddress = Read<DWORD>(dwAddress + Offset[i]); if (!Type) return dwAddress + Offset[iSize]; //FALSE - Return Address else return Read<cData>(dwAddress + Offset[iSize]); //TRUE - Return Value } // WRITE MEMORY template <class cData> void Write(DWORD dwAddress, cData Value) { WriteProcessMemory(hProcess, (LPVOID)dwAddress, &Value, sizeof(cData), NULL); } // WRITE MEMORY - Pointer template <class cData> void Write(DWORD dwAddress, char *Offset, cData Value) { Write<cData>(Read<cData>(dwAddress, Offset, false), Value); } // Base read template <typename TYPE> TYPE RPM(LPVOID lpBaseAddress, SIZE_T nSize) { TYPE data = TYPE(); ReadProcessMemory(hProcess, lpBaseAddress, &data, nSize, NULL); return data; } // Base write void WPM(LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize) { WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, NULL); } // MEMORY FUNCTION PROTOTYPES virtual bool Process(char* ProcessName); // Return Handle To The Process virtual void Patch(DWORD dwAddress, char *chPatch_Bts, char *chDefault_Bts); // Write Bytes To Specified Address virtual void Inject(DWORD dwAddress, char *chInj_Bts, char *chDef_Bts, BOOL Type); // Jump To A Codecave And Write Memory virtual DWORD AOB_Scan(DWORD dwAddress, DWORD dwEnd, char *chPattern); // Find A Byte Pattern virtual bool Module(LPSTR ModuleName, DWORD &output); // Return Module Base Address #pragma endregion }; #endif 

    2 answers 2

    You can use the coercion type reinterpret_cast , provided that the value of the source pointer of the char * type is aligned with the boundary for the int type accordingly.

    For example,

     int a[10]; char *cp = reinterpret_cast<char *>( a ); int *ip = reinterpret_cast<int *>( cp ); 

    But I think your question is irrelevant to your problem. Most likely you are misunderstanding trying to do something wrong either in the design of your classes or in dealing with them.

      First you need to understand in what context this function is called:

       //READ MEMORY - Pointer template <class cData> cData Read(DWORD dwAddress, char *Offset, BOOL Type) { //Variables int iSize = iSizeOfArray(Offset) - 1; //Size Of *Array Of Offsets 

      If a pointer to char * actually passed there, then it is necessary to call forth not iSizeOfArray() , but chSizeOfArray() .

      Or vice versa, according to the architecture of the task, you need to pass int * to this function, then the iSizeOfArray() call is correct, but the Read() prototype is not.

      More precisely, you can only answer the person who designed all this functionality. And / or one that has a good understanding of it, plus a complete set of source codes before your eyes.

      • The fact is that if I change iSizeOfArray () to chSizeOfArray (), then an error occurs ... \ collect2.exe [Error] ld returned 1 exit status. Although there is no collect2 file in the specified directory. And if you replace cData Read (DWORD dwAddress, char * Offset, BOOL Type) with int * Offset, then porridge starts in messages from the compiler, with different warnings and errors - Order_By
      • one
        And you do not change blindly, try to think: what this code should do and what the call here will be more correct. Do not try to program "random method". And even more so for us telepathically difficult to guess how exactly your code should work. ld returned 1 exit status - and? Surely there are some other words that need to be read and comprehended. For example (this is already a guess) about the fact that "symbol chSizeOfArray undefined". - PinkTux
      • The solution to this problem is important first of all for me, respectively, I would not miss such details. But the fact of the matter is that Error: ld returned 1 exit is all the information about my error, there is no continuation there. And the error refers to the above-mentioned collect2.exe, which is not on the specified path - Order_By