今、リバースエンジニアリングのスキルを上げるために
テストプログラムのステータス(メモリ)を書き換える解析プログラムを制作しております。
テストプログラムのメモリなどのサーチはCheatEngine6.4というデバッガで行っております。
開発の流れとしましては、このデバッガでテストプログラムの
メモリをサーチしてメモリアドレスを特定して、そのメモリアドレスを基に
解析プログラムの方からWin32APIのWriteProcessMemory関数で
テストプログラムの方を書き換えるといった流れです。
開発工程としては
1、ターゲットのプロセスIDを取得する(ProcessGetByName関数)
2、ターゲットのプロセスハンドルを取得する(OpenProcess関数)
3、ターゲットのメモリを書き換えるので書き換えなければならないターゲットのメモリ領域を確保する
(ReadProcessMemory関数)
4、実際にターゲットのメモリを書き換える(WriteProcessMemory関数)
この、1から4までの開発工程で
3までは問題ないのですが
4の箇所で問題が起きております。
といいますのも
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 27 28 [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] 29 static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, 30 IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect); 31 32 [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] 33 static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, 34 int dwSize, FreeType dwFreeType); 35 36 37 38 [DllImport("kernel32.dll")] 39 public static extern bool ReadProcessMemory(IntPtr hProcess, 40 int lpBaseAddress, int lpBuffer, int dwSize, ref int lpNumberOfBytesRead); 41 42 43 44 45 [DllImport("kernel32.dll", SetLastError = true)] 46 static extern bool WriteProcessMemory(IntPtr hProcess, int lpBaseAddress, 47 int lpBuffer, int dwSize, ref int lpNumberOfBytesWritten); 48 49 50 51 private enum ProcessAccessFlags : uint 52 { 53 All = 0x001F0FFF, 54 Terminate = 0x00000001, 55 CreateThread = 0x00000002, 56 VMOperation = 0x00000008, 57 PROCESS_VM_READ = 0x10, 58 VMWrite = 0x00000020, 59 DupHandle = 0x00000040, 60 SetInformation = 0x00000200, 61 QueryInformation = 0x00000400, 62 Synchronize = 0x00100000 63 } 64 65 66 [Flags] 67 public enum AllocationType 68 { 69 Commit = 0x1000, 70 Reserve = 0x2000, 71 Decommit = 0x4000, 72 Release = 0x8000, 73 Reset = 0x80000, 74 Physical = 0x400000, 75 TopDown = 0x100000, 76 WriteWatch = 0x200000, 77 LargePages = 0x20000000 78 } 79 80 [Flags] 81 public enum MemoryProtection 82 { 83 Execute = 0x10, 84 ExecuteRead = 0x20, 85 ExecuteReadWrite = 0x40, 86 ExecuteWriteCopy = 0x80, 87 NoAccess = 0x01, 88 ReadOnly = 0x02, 89 ReadWrite = 0x04, 90 WriteCopy = 0x08, 91 GuardModifierflag = 0x100, 92 NoCacheModifierflag = 0x200, 93 WriteCombineModifierflag = 0x400 94 } 95 96 97 98 [Flags] 99 public enum FreeType 100 { 101 Decommit = 0x4000, 102 Release = 0x8000, 103 } 104 105 106 107 108 int faste = 0; 109 int aaa; 110 byte[] newvalue3 = { 0x64, 0x00, 0x00, 0x00 }; 111 int newvalue2 = 600; 112 IntPtr aPtr; 113 System.Diagnostics.Process[] ps = 114 System.Diagnostics.Process.GetProcessesByName("Tutorial-x86_64"); 115 116 117 118 119 public Form1(){ 120 InitializeComponent(); 121 foreach (System.Diagnostics.Process p in ps) 122 { 123 Console.WriteLine("{0}/{1}", p.Id, p.MainWindowTitle); 124 aaa = p.Id; 125 } 126 127 128 129 if ((aPtr = OpenProcess(ProcessAccessFlags.All, false, aaa)) == null) 130 { 131 Console.WriteLine("ハンドルが取得されませんでした"); 132 } 133 else 134 { 135 Console.WriteLine("ハンドルが取得されました"); 136 Console.WriteLine(aPtr); 137 } 138 139 140 141 } 142 143 private void button1_Click(object sender, EventArgs e) 144 { 145 Console.WriteLine("コマンドオン"); 146 147 VirtualAllocEx(aPtr, (IntPtr)0x15C0E70, (IntPtr)4, AllocationType.Commit, MemoryProtection.ExecuteReadWrite); 148 VirtualFreeEx((IntPtr)aPtr, (IntPtr)0x15C0E70, 0, FreeType.Decommit); 149 150 151 152 ReadProcessMemory((IntPtr)aPtr, 0x15C0E70, newvalue2, 4, ref faste); 153 if ((WriteProcessMemory((IntPtr)aPtr, 0x15C0E70, newvalue2, 4, ref faste)) == false) 154 { 155 156 157 Console.WriteLine("プログラム改ざん失敗!"); 158 } 159 160 else 161 { 162 163 164 Console.WriteLine("プログラム改ざん成功!"); 165 166 } 167 168 169 170 171 } 172 } 173} 174 175
こちらがソースコードですが
こちらの解析プログラムで
WriteProdessMemory関数を使って
テストプログラムのメモリを実際に書き換えるべく
アドバイス頂けたらと思います。
それでは、宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/21 09:09