リバースエンジニアリングのスキルを上げるために
現在、自分でプログラムの解析ツールを作っております。
現在の開発段階としては
ターゲットプロセスのidを取得して
そのidを元にプロセスのハンドルも取得できました。
次はWin32のWriteProcessMemory();で
プロセスのハンドルを元にターゲットのプロセスのメモリを書き換える箇所ですが
この段階でハマりました。
C#
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Threading.Tasks; 9using System.Windows.Forms; 10using System.Diagnostics; 11using System.Runtime.InteropServices; 12 13namespace NUNS4{ 14 15 16 17 18 public partial class Form1 : Form{ 19 20 21 22 [DllImport("kernel32.dll")] 23 static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId); 24 25 26 [DllImport("kernel32.dll")] 27 public static extern bool ReadProcessMemory(int hProcess, 28 int lpBaseAddress, int lpBuffer, int dwSize, ref int lpNumberOfBytesRead); 29 30 31 32 33 [DllImport("kernel32.dll", SetLastError = true)] 34 static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, 35 int lpBuffer, int dwSize, ref int lpNumberOfBytesWritten); 36 37 38 39 private enum ProcessAccessFlags : uint 40 { 41 All = 0x001F0FFF, 42 Terminate = 0x00000001, 43 CreateThread = 0x00000002, 44 VMOperation = 0x00000008, 45 PROCESS_VM_READ = 0x10, 46 VMWrite = 0x00000020, 47 DupHandle = 0x00000040, 48 SetInformation = 0x00000200, 49 QueryInformation = 0x00000400, 50 Synchronize = 0x00100000 51 } 52 53 54 55 56 57 int faste = 0; 58 int aaa; 59 byte[] newvalue = { 0x90, 0x90, 0x90, 0x90, 0x90 }; 60 int newvalue2 = 600; 61 IntPtr aPtr; 62 System.Diagnostics.Process[] ps = 63 System.Diagnostics.Process.GetProcessesByName("Tutorial-x86_64"); 64 65 66 67 68 public Form1(){ 69 InitializeComponent(); 70 foreach (System.Diagnostics.Process p in ps) 71 { 72 Console.WriteLine("{0}/{1}", p.Id, p.MainWindowTitle); 73 aaa = p.Id; 74 } 75 76 77 78 if ((aPtr = OpenProcess(ProcessAccessFlags.All, false, aaa)) == null) 79 { 80 Console.WriteLine("ハンドルが取得されませんでした"); 81 } 82 else 83 { 84 Console.WriteLine("ハンドルが取得されました"); 85 Console.WriteLine(aPtr); 86 } 87 88 89 90 } 91 92 private void button1_Click(object sender, EventArgs e) 93 { 94 Console.WriteLine("コマンドオン"); 95 96 97 ReadProcessMemory((int)aPtr, 0x00121C80, newvalue2, 1, ref faste); 98 WriteProcessMemory((int)aPtr, 0x00121C80, newvalue2, 1, ref faste); 99 100 101 102 } 103 } 104} 105
こちらが、コードになりますが
WriteProcessMemory();が適用されません。
ハンドルも取得して
アクセス県もすべて得ております。
何が原因でWriteProcessMemory();が適用されないのでしょうか??
目的としては
WriteProcessMemory();で他プロセスのメモリを書き換える事です。
どなたか、目的を実現するべくアドバイス頂けたらと思います。
宜しくお願い致します。

回答1件
あなたの回答
tips
プレビュー