c# - C# & ASM - 跳转到地址
问题描述
我正在使用 C# 编写代码注入来分析潜在的恶意软件。
为此,我跳转到未分配的内存,写入该未分配的内存并跳回/返回。代码注入/分配部分工作得很好,没有问题,但跳转部分很困难。
我为 32 位进程获取了示例代码,但我的是 64 位,所以我将其转换为 64 位,这样做时我可能会破坏某些东西,因为跳转地址不是它应该跳转到的正确地址。
作为示例,我想在地址:7FF95BBD0000 进行代码注入。
我的代码如下所示:
public void injection()
{
_oMemory.Alloc(out _newmem, 0x300); //Allocate 300 Bytes of unallocated Memory for the code Injection (This part works)
var CodeBaseAddress = ModuleBaseAddress + 0x36652EE; //I want to jump from this Address (7FFBA13F52EE output = 140718718800622) to (7FF95BBD0000)
var CodeInjectionAddress = (ulong)_newmem; //This is the Address of the Code Injection that I want to jump to (7FF95BBD0000 output = 140708962697216)
var Jumpbytes = Jmp(ConeInjectionAddress, CodeBaseAddress, false); //this should give me the byte[] Byte Decimal for the Jump from the CodeBaseAddress to the CodeInjectionAddress but it gives me a slightly wrong output (outputs = {233, 13, 173, 192, 94, 4, 128, 255, 255}, in Hex = {0xE9, 0x0D, 0xAD, 0x7D, 0xBA, 0xFD, 0xFF, 0xFF, 0xFF}, in OPCode = "jmp 7FFB5BBD0000")
_oMemory.Write((IntPtr)ad1, bv1); //This writes the Jumpbytes to the CodeBaseAddress which works
_oMemory.CloseHandle(); //Closes Handle which also works
}
public static byte[] Jmp(ulong jmpto, ulong jmpfrom, bool nop)
{
var test = jmpto - jmpfrom;
var test2 = test - 5;
var dump = test2.ToString("x"); //Get original bytes
if (dump.Length == 7) //Make sure we have 4 bytes
dump = "0" + dump;
dump += "E9"; //Add JMP
if (nop)
dump = "90" + dump; //Add NOP if needed
var hex = new byte[dump.Length / 2];
for (var i = 0; i < hex.Length; i++)
hex[i] = Convert.ToByte(dump.Substring(i * 2, 2), 16); //Set each byte to 2 chars
Array.Reverse(hex); //Reverse byte array for use with Write()
return hex;
}
请注意 Jmp 方法如何返回“7FFB5BBD0000”而不是“7FF95BBD0000”。它将 95 更改为 B5,从而导致错误的跳转地址。
如果我使用作弊引擎将跳转更改为我想要的地址,它看起来像这样:
我猜我的 Jump 使用 E9 跳转太“大”了,所以它给我的方法提供了错误的跳转地址?我怎么能解决这个问题?
感谢任何人帮助我或指出我正确的方向。
解决方案
推荐阅读
- javascript - 创建两个数组来计算 JavaScript 中 1 到 25 之间随机数的出现次数
- firebase - Twitter OAuth request_token:错误代码 32,无法进行身份验证
- java - 询问队列中是否有代理(AnyLogic Simulation)
- python - 继承视图的问题 - Odoo 模块
- list - 如果包含 x 或 -x,如何修改列表列表?
- image - Flutter PUT 来自文件的 HTTP 请求
- php - 仅插入嵌入代码来代替不在 href 中的 url
- reactjs - 添加滑动删除以拖放组件
- python - 如何存储在使用 Python 从 CSV 文件中检索的数据库中
- reactjs - 强制 React 重新渲染使用 React.createElement 创建的子组件