C 製作記憶體修改器

2021-06-09 05:33:48 字數 2605 閱讀 6584

先看效果圖

其實 搞這個東西 主要是因為 不久前看到乙個c#寫的外掛程式 頓時就來了興趣

當時看了之後 覺得不爽的就是 那個位址是寫死在程式裡面的是固定的 而且是用其他東西掃出來的位址 頓時就覺得不爽了 要這個位址也是自己寫的程式掃出來的那才有成就感

於是呼這東西就這樣誕生了、、、

在做之前 我感覺這東西 應該很簡單的 結果 尼瑪還是搞了半天 途中總是遇到一些糾結的問題 比如什麼記憶體溢位的  現在都還沒解決 不過出現的機率不大 還有搜尋效率問題

其實 想一下這東西是挺簡單的 也就那麼三個函式

virtualqueryex()

readprocessmemory()

writeprocessmemory()

先用 virtualqueryex 去掃瞄記憶體塊 遇到已經物理分配的記憶體 以及 是可讀寫記憶體 那麼就把該區域的資料用readprocessmemory讀取出來 然後與要查詢的值比較

如果要修改值的話 就用writeprocesmemory去修改相應位址的資料

public class win32

public const int mem_commit = 0x1000; //已物理分配

public const int page_readwrite = 0x04; //可讀寫記憶體

[dllimport("kernel32.dll")] //查詢記憶體塊資訊

public static extern int virtualqueryex(

intptr hprocess, intptr lpaddress, out memory_basic_information lpbuffer, int dwlength);

[dllimport("kernel32.dll")]

public static extern bool readprocessmemory(

intptr hprocess, intptr lpbaseaddress, byte lpbuffer, int size, out int numbytesread);

[dllimport("kernel32.dll")]

public static extern bool writeprocessmemory(

intptr hprocess, intptr lpbaseaddress, byte lpbuffer, int size, out int numbyteswrite);

}

如果要掃瞄記憶體塊 做乙個 0 - 0x7fffffff 的迴圈就行了

win32.memory_basic_information stmbi = new win32.memory_basic_information();

int searchlen = marshal.sizeof(stmbi);

nbaseaddr = 0x000000;

int nreadsize = 0; //實際讀取位元組數

while (nbaseaddr >= 0 && nbaseaddr <= 0x7fffffff && stmbi.regionsize >= 0)

} else

nbaseaddr += stmbi.regionsize; //設定基位址偏移

}

對於 readprocessmemory 和 writeprocessmemory 兩者都相當簡單 簽名也都一樣

read / writeprocessmemory(程序控制代碼, 要操作的位址, 寫入或者讀取快取區, 要操作的位元組數, 實際操作的位元組數)

哦 還有乙個就是 把 資料 於 byte 陣列進行轉換的問題

把陣列轉換成數到十方便 可以用 bitconvert.tointxx(byte,startindex)

如果是要把 乙個 int 轉換成 byte 那麼幾個位移操作 就搞定比如

int ntest = 65535;

byte bytest = new byte[4];

bytest[0] = (byte)(ntest & 0x000000ff); //從低8位開始存入

bytest[1] = (byte)((ntest & 0x0000ff00) >> 8); //意思就是要倒過來 小端模式

bytest[2] = (byte)((ntest & 0x00ff0000) >> 16);

bytest[3] = (byte)((ntest & 0xff000000) >> 24);

bytest = //在記憶體中就是這樣的 低位地直接高位高位元組

當然也可以用迴圈的方式

int ntest = 65535

byte bytest = new bytest[4];

for(int i = 0; i < 4; i ++)

差不多 也就將這麼多 想想上去 的確很簡單

尼瑪實際動手操作的時候 總是遇到一些糾結的問題 唉!、、

可以的話 大家一起討論

記憶體修改器實現原始碼

include stdafx.h include include include includeusing namespace std dword g arlist 1024 int g nlistcnt handle g hprocess bool writememory dword dwaddr...

記憶體理解之簡單的記憶體修改器

前段日子因為學習記憶體把王艷平老師的書看了一遍綜合了其他書籍,簡單學習做了乙個記憶體修改器,下面是我覺得比較重要的知識,從書上摳了下來 類的形式寫的 hellogame.cpp 定義控制台應用程式的入口點。include stdafx.h include hellogame.h game game ...

Win32 實現記憶體修改器

在遊戲執行中啟動修改器,輸入遊戲當前想要修改的金幣 礦石 木材 的數值 找到程式執行時的程序id,windows為每個程序都分配4gb的虛擬位址空間,我們只需要在虛擬位址空間去遍歷儲存數值與遊戲中數值相同的位址,去修改它即可,但需要注意僅搜尋一次得到的儲存此數值的位址極可能不唯一,故在得到多個位址時...