2016-03-08 21 views
0

我是新來的這個領域的專家,所以我不完全確定......我知道externaly你有兩個函數:WriteProcessMemory和ReadProcessMemory,但內部的東西是不同的......我也不夠熟悉指針還沒有成爲我自己 - 但如果你可以爲我發表評論,我想我會沒事的:)。C++:什麼是從注入DLL中讀取內存的好方法?

那麼,什麼是最好的方式來閱讀記憶?

順便說一句,這是我寫記憶功能:

void WriteToMemory(DWORD addressToWrite, char* valueToWrite, int byteNum) 
{ 
    //used to change our file access type, stores the old 
    //access type and restores it after memory is written 
    unsigned long OldProtection; 
    //give that address read and write permissions and store the old permissions at oldProtection 
    VirtualProtect((LPVOID)(addressToWrite), byteNum, PAGE_EXECUTE_READWRITE, &OldProtection); 

    //write the memory into the program and overwrite previous value 
    memcpy((LPVOID)addressToWrite, valueToWrite, byteNum); 

    //reset the permissions of the address back to oldProtection after writting memory 
    VirtualProtect((LPVOID)(addressToWrite), byteNum, OldProtection, NULL); 
} 
+0

不知道你在問什麼。 「內部」=從正在運行的進程讀取內存?不需要任何API,只需訪問內存。也許你在問枚舉加載的DLL並訪問映射到特定內存區域的內存區域? –

+0

就像我剛纔說的那樣,所以我的術語並不好,對不起:P我開始使用的是外部控制檯程序,它使用WriteProcessMemory將內存寫入另一個程序。現在我已經有了一個注入到程序中的DLL。我認爲它被稱爲內部變化的內存或者類似的...... – Naltamer14

+0

「對指針還不夠熟悉」 - 雖然在C++中這不一定是壞事,但這對於你在這裏嘗試的類型是不利的。在嘗試這些事情之前,您應該對普通指針非常適應。 – MSalters

回答

0

下面是做這件事的一種方法:

void ReadFromMemory(DWORD addressToRead, float value) 
{ 
    value = *(float*)addressToRead; 
} 

任何其他建議?

+3

你至少要通過引用傳遞值 –

相關問題