首页
社区
课程
招聘
[旧帖] [求助]DLL中 WriteProcessMemory写法 0.00雪花
发表于: 2011-1-9 03:30 1128

[旧帖] [求助]DLL中 WriteProcessMemory写法 0.00雪花

2011-1-9 03:30
1128
最近爱上了逆向了,买了一本看雪第三版本的书。
我用DLPHI写了一个带窗口的DLL程序。
当然里面很多东西都是我东借一个西借一个的。编程有点差。
当我再DLL窗口中使用WriteProcessMemory函数的时候就无法写入内存地址。
但当我重新建立一个不带DLL窗口的应用程序时WriteProcessMemory就能写入这个内存地址。
原型如下:

procedure TForm1.Button1Click(Sender: TObject); // 修改内存值
var
p:pinteger;
a:integer;
ProcessHandle,PID:longword;
num:cardinal;
begin
a:=8792151275;
new(p);
p^:=a;
GetWindowThreadProcessId(FindWindow('MediaPlayerClassicW','Media Player Classic');//获取c的PID   
ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS,False,PID);//打开进程
WriteProcessMemory(ProcessHandle,Pointer($007063C4),p,4,num);
CloseHandle(ProcessHandle);
end;

我估计就是下面的程序错误所造成的
因为我DLL注入了进程就因该说明这个进程已经被我打开了吧。
如果我在这里又一次获取PID 然后又打开是不是就重复了一个操作?
不知道我说的对不对。。只是一个猜测。毕竟我接触编程不是很长时间。

GetWindowThreadProcessId(FindWindow('MediaPlayerClassicW','Media Player Classic');//获取c的PID   
ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS,False,PID);//打开进程

那么如果以上我的猜测是成立的那么我的这个
WriteProcessMemory(ProcessHandle,Pointer($007063C4),p,4,num);
因该怎么写呢?
我贴出我的DLL源码希望朋友们看了能帮帮忙。。

library hook;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  windows,
  SysUtils,
  Classes,
  hookform1 in 'hookform1.pas' {Form1};

{$R *.res}
var
gamehook:HHOOK ;  // 定义钩子全局变量

Function huidiaohanshu(xiaoxi,sky,dao:integer):DWORD;stdcall;  //回调函数
//拦截键盘消息。。。
begin

if (xiaoxi=HC_ACTION) and ((1 shl 31)and dao=0) then
                                                begin

                                                        if (sky=VK_HOME)   then  // 判断按下HOME键时呼出窗口
              begin
      if form1=nil then  Form1:=Tform1.Create(nil);
                form1.Visible:=not form1.Visible;
              end;
            end;
huidiaohanshu:=CallNextHookEx(gamehook,xiaoxi,sky,dao); //将函数的返回值返回给回调函数
end;
var

tid:THandle;
Function WndThreadHook(hwndx:HWND):boolean;stdcall;     //构建线程钩子函数
begin
                Result:=false;
tid:=GetWindowThreadProcessId(hwndx);  //返回的就是这个线程的id号
        gamehook:=SetWindowsHookEx(WH_KEYBOARD,@huidiaohanshu,GetModuleHandle('hook.dll'),Tid);   //安装线程勾子

if gamehook>0 then Result:=true;
end;
var
        ckCaption:Pchar;
Function EnumWinproc(hwndx:HWND ; lParam:LPARAM ):boolean; stdcall;
//枚举所有窗口函数获取所有顶层窗口的句柄
begin

windows.GetWindowText(hwndx,ckCaption,256); // 获取窗口的标题文本

if (StrLComp(ckCaption,youxibiaoti,13)=0)  then //比较窗口标题是否为游戏窗口标题

        begin
         WndThreadHook(hwndx);//执行钩子函数。。。
         SetWindowText(hwndx,pchar(intTostr(hwndx)));//修改安装后钩子的窗口标题。。
   end;
result:=true;  //返回真
end;

Function diaoyongchuangkou():boolean;stdcall;
begin
//调用枚举所有窗口
ckCaption:=Allocmem(256);//分配内存空间。。。为256
        result:=windows.EnumWindows(@EnumWinproc,1);  //返回枚举窗口
end;
procedure tuichuchuli(reason:integer); //构建处理函数
begin
   case reason of
   windows.DLL_PROCESS_ATTACH: begin end;
   windows.DLL_PROCESS_DETACH:
   begin Form1.Free;form1:=nil; end;
   end;  //释放内存并赋值为空
end;
exports   //套出函数
diaoyongchuangkou;

begin
dllProc:=@tuichuchuli;   //用于卸载时的过程处理函数
end.

或者可以给出另一种方法也可以。不用WriteProcessMemory来修改这个地址也可以。

这是一个汇编地址 007863A4  /7A 35  JPE SHORT luxiang.007263DB  
我就是想用delphi编程来实现 我已将DLL已经注入到进程了。
将这个JPE改为jmp的一个形式。 如何在delphi里实现?
我不想用WriteProcessMemory 想问问有没有别的办法? 在网上搜遍了。都没有准确的说出此类办法。。所以才来请教朋友们帮帮忙的。。
我还是想以一个指针的形式来修改修改。但是看了好多文章还是没个头绪。

[课程]Android-CTF解题方法汇总!

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 5
活跃值: (41)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
一般来说,如果是DLL注入进程序,读写内存可以直接用指针操作或是用汇编来读取就方便得多了
2011-1-9 14:07
0
雪    币: 27
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
感觉Delphi不太适合编这种,还是C比较好
2011-1-9 14:52
0
雪    币: 10
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
各位老大能给点提示不??我真的很着急。。
2011-1-9 19:44
0
雪    币: 5
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
看看~~~~~~~~~
2011-1-9 21:36
0
游客
登录 | 注册 方可回帖
返回
//