看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) C語言 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) Gcc 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) N 問題(Question): 最近想利用指標寫dll修改程式 目標是想要主程式進行到一半進行數值修改 步驟: 1.編譯dll檔案,指令:gcc -shared -o change.dll change.c #include <stdio.h> #include <stdlib.h> _declspec(dllexport) void change() { int *p = (int *)0x28ff2c; *p = 500; } 2.連結以及編譯主程式,指令:gcc -o target.exe target.c -L. -lchange #include <stdio.h> #include <stdlib.h> int main (void) { int num = 0; printf("%x\n", &num); while(1) { num++; printf("\n%d", num); Sleep(6000); } return 0; } 最後我的num並沒有被修改,請問是為甚麼呢@@ -- Sent from my Android -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.72.32.166 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1495194406.A.E67.html
littleshan: google mingw dll05/19 23:10
hpyhacking: 我發現我誤會了……05/19 23:23
※ 編輯: hpyhacking (42.72.32.166), 05/19/2017 23:23:29 ※ 編輯: hpyhacking (42.72.32.166), 05/19/2017 23:24:30
littleshan: 看你是要 dynamic linking 還是 dynamic loading05/19 23:40
littleshan: 編出 DLL 的時候一定會同時產生 imp library (XXX.a)05/19 23:40
littleshan: 在編 exe 時一起 link,就會是 dynamic linking05/19 23:41
littleshan: dynamic loading 則是用 LoadLibrary 執行時才載入05/19 23:42
littleshan: 這些都和 IDE 沒什麼關係啦,IDE 只是幫你把指令填好05/19 23:43
hpyhacking: 我沒有產生那個.a檔誒…難怪失敗05/20 00:09
hpyhacking: 另外我找到有dll注入工具?那是再瞭解dll另外寫的程05/20 00:10
hpyhacking: 式對不對?那個也是dynamic loading囉?05/20 00:10
※ 編輯: hpyhacking (42.72.32.166), 05/20/2017 00:19:11 ※ 編輯: hpyhacking (220.134.65.240), 05/20/2017 00:27:30 ※ 編輯: hpyhacking (220.134.65.240), 05/20/2017 00:31:57
hpyhacking: 然後不知道為什麼我的電腦開機後每次執行exe他的位址 05/20 00:35
hpyhacking: 都會一樣,所以程式碼中的位址就直接給了 05/20 00:35
vaio8937: 請問你要LoadLibrary,讓主程式呼叫DLL的函式。還是你要 05/20 01:00
vaio8937: DLLInjection 05/20 01:00
vaio8937: 兩個做法完全不一樣 05/20 01:01
vaio8937: 你是想要DLL附在主程式上,去hack主程式的變數嗎? 05/20 01:03
hpyhacking: Dllinjection!!!! 05/20 01:34
hpyhacking: 我要的是dll injection 05/20 01:35
vaio8937: 那我再另回一篇文 05/20 01:40
hpyhacking: 感謝妳,我也還在爬文章看觀念 05/20 01:58
TobyH4cker: 因為change()並沒有被呼叫過啊 05/20 02:08
hpyhacking: 我也在想怎麼呼叫rrr 05/20 10:30
TobyH4cker: 在你的主程式宣告dllimport 然後自己呼叫 05/20 18:35
hpyhacking: 那請問一般其他的程式並沒有辦法有原始碼,還是要做這 05/20 19:01
hpyhacking: 哥動作怎麼辦 05/20 19:01