using
System;
using
System.Collections.Generic;
using
System.Diagnostics;
using
System.Linq;
using
System.Runtime.InteropServices;
using
System.Text;
namespace
Net内存特征码搜索
{
internal
class
Program
{
private
static
void
Main(
string
[] args)
{
//// 打印模块信息
Console.WriteLine(
"程序最小地址:0x"
+ PatchPattern.Get_Application_MinAddress().ToString(
"X"
));
Console.WriteLine(
"程序最大地址:0x"
+ PatchPattern.Get_Application_MaxAddress().ToString(
"X"
));
var
systemAssembly = PatchPattern.Get_Assembly_Module_BaseAddress(
"System.dll"
);
Console.WriteLine(
"System模块基址:0x"
+ systemAssembly.ToString(
"X"
));
Console.WriteLine(
"System模块大小:0x"
+ PatchPattern.Get_Moule_SizeOfImage(systemAssembly).ToString(
"X"
));
Console.WriteLine(
"ntdll模块基址:0x"
+ PatchPattern.Get_C_Module_BaseAddress(
"ntdll.dll"
).ToString(
"X"
));
Console.WriteLine(
"ntdll模块大小:0x"
+ PatchPattern.Get_C_Module_SizeOfImage(
"ntdll.dll"
).ToString(
"X"
));
string
testStr =
"Hello World!"
;
string
patternStr =
"48 00 65 00 6C 00 6C ?? 6F 00 20 00 ?7 00 6F ?? 72 00 6C 00 64 00 21 00"
;
IntPtr hProcess = PatchPattern.Get_Process_Handle();
ulong
baseAddress = (
ulong
)Process.GetCurrentProcess().MainModule.BaseAddress;
ulong
size = (
ulong
)Process.GetCurrentProcess().MainModule.ModuleMemorySize;
Console.WriteLine(
"模块基址:0x"
+ baseAddress.ToString(
"X"
) +
"----模块大小:0x"
+ size.ToString(
"X"
));
Stopwatch stopwatch =
new
Stopwatch();
stopwatch.Start();
List<
ulong
> result = PatchPattern.PatternFind(hProcess,
"MainModule"
, patternStr);
stopwatch.Stop();
Console.WriteLine(
"搜索用时: "
+ stopwatch.ElapsedMilliseconds +
" 毫秒"
);
Console.WriteLine(
"搜索到特征码:"
+ result.Count +
"个"
);
result.ForEach(x => Console.WriteLine(
"特征码地址:0x"
+ x.ToString(
"X"
)));
Encoding.Unicode.GetBytes(
"你好,世界!"
).ToList().ForEach(x => Console.Write(x.ToString(
"X2"
) +
" "
));
Console.WriteLine();
if
(result.Count > 0)
if
(PatchPattern.WriteMemoryData(result[0],
"60 4F 7D 59 0C FF 16 4E 4C 75 01 FF"
+
"0000"
))
{
Console.WriteLine(
"修改内存数据成功"
);
Console.WriteLine(
"修改为:"
+ Marshal.PtrToStringAuto((IntPtr)result[0]));
}
else
Console.WriteLine(
"修改内存数据失败"
);
Console.ReadKey();
}
}
}