Delphi 7的WriteProcessMemory [英] Delphi 7 WriteProcessMemory

查看:258
本文介绍了Delphi 7的WriteProcessMemory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的工作代码

  DriftMul:=99;
  WriteProcessMemory(HandleWindow, ptr($4E709C), @DriftMul, 2, Write);

我想在不使用变量的情况下进行转换,但无法使用
下面只是一个我想做的例子。

I want to Convert it without using a variable but it wont work Below is just an Example of what i want to do.

WriteProcessMemory(HandleWindow, ptr($4E709C),  ptr(99), 2, Write);

有人知道使用变量来完成这项工作的方法吗???
我能够用几种语言编程,而我使用的每种语言都是
的实现方式。我之所以想这样做,是因为我要编写一个大型程序,该程序可以编写许多不同的值,并且可以为我节省300多行。下面是我使用的c ++示例。

Does anyone know a way to make this work with using a variable??? I am able to program in a few languages and every language i use their is a way to to do this. The reason i want to do this is because i am gonna be making a big program that does alot of writing of different values and it will save me around 300+ lines. Below is an Example in c++ i was using.

WriteProcessMemory(hProcess, (void*)0x4E709C, (void*)(PBYTE)"\x20", 1, NULL);

更新:
解决它
Im使用4我调用的程序取决于我要写多少字节。

Update: Solved it Im using 4 Procedures that i call depending on how many bytes i want to write.

procedure Wpm(Address: Cardinal; ChangeValues: Byte);
Begin
 WriteProcessMemory(HandleWindow, Pointer(Address), @ChangeValues, 1, Write);
End;
procedure Wpm2(Address: Cardinal; ChangeValues: Word);
Begin
 WriteProcessMemory(HandleWindow, Pointer(Address), @ChangeValues, 2, Write);
End;
procedure Wpm3(Address: Cardinal; ChangeValues: Word);
Begin
 WriteProcessMemory(HandleWindow, Pointer(Address), @ChangeValues, 3, Write);
End;
procedure Wpm4(Address: Cardinal; ChangeValues: Cardinal);
Begin
 WriteProcessMemory(HandleWindow, Pointer(Address), @ChangeValues, 4, Write);
End;

示例写入

 Wpm($477343,$EB);
 Wpm2($40A889,$37EB);
 Wpm3($416E34,$0086E9);

Pchar是我发现无需程序即可编译的唯一方法,尽管我不想使用assci。 / p>

Pchar is the only method i found to compile without procedures, i dont want to use assci though.

WriteProcessMemory(HandleWindow, Pointer($449A17), PChar('90'), 1, Write);


推荐答案

您必须存储单词的内容在某处写作。 WriteProcessMemory 需要一个指向进程空间中某些内存的指针。

You have to store the contents of the word that you are writing somewhere. WriteProcessMemory expects a pointer to some memory in your process space. If you don't want to use a variable, use a constant.

const
  DriftMul: word=99;
....
WriteProcessMemory(HandleWindow, ptr($4E709C),  @DriftMul, 2, Write);

通过 ptr(99)失败,因为 ptr(99)不是指向包含值 99 的单词的指针。它是指向地址99的指针。我想您正在尝试编写 @Word(99),但是您不能使用真正常量的地址。

Passing ptr(99) fails because ptr(99) is not a pointer to a word containing the value 99. It is a pointer to address 99. I think you were trying to write @Word(99) but you cannot take the address of a true constant.

通过在辅助方法中包装对 WriteProcessMemory 的调用,可以使此操作更加方便。尽管您的问题表明您想编写 Word 值,但在漫长的聊天中很明显您实际上想编写字节序列。写入整数数据类型将导致机器字节序混乱。因此,相反,我会使用 Byte 的开放数组来做到这一点,以便在呼叫站点获得灵活性。

You can make this more convenient by wrapping up the call to WriteProcessMemory in a helper methods. Although your question suggests that you want to write Word values, it became apparent in out lengthy chat that you actually want to write byte sequences. Writing integer data types will lead to machine endianness confusion. So instead I would do it using an open array of Byte to give the flexibility at the call site.

procedure WriteBytes(hProcess: THandle; Address: Pointer;
  const Buffer: array of Byte);
var
  NumberOfBytesWritten: DWORD;
begin
  if not WriteProcessMemory(hProcess, Address, @Buffer[0], Length(Buffer),
    NumberOfBytesWritten) then RaiseLastOSError;
end;

然后可以调用该代码

WriteBytes(Handle, Pointer($523328), [$42]);//single byte
WriteBytes(Handle, Pointer($523328), [$CC, $90, $03]);//3 bytes

这篇关于Delphi 7的WriteProcessMemory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆