首页
社区
课程
招聘
[旧帖] [求助]我的Ring0监控程序源代码,VC++ 代码转 Delphi !!! 0.00雪花
发表于: 2008-5-10 18:04 6842

[旧帖] [求助]我的Ring0监控程序源代码,VC++ 代码转 Delphi !!! 0.00雪花

2008-5-10 18:04
6842
下面的代码搞了一个星期了,一运行,系统就忙到没响应,今晚老板就回来了, 再搞不好的就......

原文:偶写的Ring0监控程序PRMonitor源代码(ddk+sdk)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, WinSvc, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  DeviceHandle : THandle;
  IsLoadDevice, LoopWhile : Boolean;
  DisableEventThread : Thandle;//定义一个句柄
  outputbuff : array[0..256] of char;
  controlbuff : array[0..64] of DWORD;
  stringcount : DWORD;
implementation

{$R *.dfm}

function SteupDevice : Boolean;
var
  I : Integer;
        ServiceBinaryPathName : String;
  sch, scm : SC_Handle;
  ss : TServiceStatus;
  dwNumServiceArgs : DWORD;
  lpServiceArgVectors: PChar;
  CurrentDirectory : array[0..260] of char;

begin
  Result:=False;
  ss.dwCurrentState := 0;
  GetCurrentDirectory(260, @CurrentDirectory);
  ServiceBinaryPathName:=CurrentDirectory +  '\PRMonitor.sys';
        sch := OpenSCManager(nil,   
                                                      nil,
                                                      SC_MANAGER_ALL_ACCESS);
  scm:=OpenService(sch, 'PRMonitor', SERVICE_ALL_ACCESS);
    if scm = 0 then
      scm := CreateService(sch,
                                        Pchar('PRMonitor'),
                                        Pchar('PRMonitor'),
                                        SERVICE_ALL_ACCESS,
                                        SERVICE_KERNEL_DRIVER,
                                        SERVICE_DEMAND_START,
                                        SERVICE_ERROR_NORMAL,
                                        Pchar(ServiceBinaryPathName),
                                        nil,
                                        nil,
                                        nil,                             
                                        nil,
                                        nil);                        

  if sch > 0 then CloseServiceHandle(sch);

  QueryServiceStatus(scm,  SS);
  if SS.dwCurrentState <> SERVICE_RUNNING then
    Result:=StartService(scm,
                         0,
                         lpServiceArgVectors);
  else Result:=True;
        if scm > 0 then CloseServiceHandle(scm);
end;

function CloseSrv : boolean;
var
        sch, scm : SC_HANDLE;
  ss : TServiceStatus;
begin
        sch := OpenSCManager(nil, 0, 0);
        scm := OpenService(sch, 'PRMonitor', SERVICE_ALL_ACCESS);
  if scm > 0 then
  begin
        ControlService(scm, SERVICE_CONTROL_STOP, ss);
        DeleteService(scm);
  CloseServiceHandle(scm);
  end;
  if sch > 0 then CloseServiceHandle(sch);
end;

procedure DisableEvent{(P : Pointer) : LongInt; stdcall};
var
  A, X : DWORD;
  msgbuff : array[0..511] of char;
  pdest, name : pChar;
  _result : Integer;
  label skip;
{
  VC++  声明
        DWORD a,x; char msgbuff[512];
        char *pdest;
        int  result;

}
begin
  while LoopWhile do
  begin
  MOVE(a, outputbuff[0],4);   //  memmove(&a,&outputbuff[0],4);
    if (a=0) then    // if(!a){Sleep(10);continue;}
    begin
      Sleep(10);
      continue;
    end;
  name := pChar(@outputbuff[8]);   // char*name=(char*)&outputbuff[8];    一直未执行到这句

    for x := 0 to stringcount - 1 do
    begin
      if BOOL(not(lstrcmpi(name,PChar(string(x))))) then
      begin
        a := 1;
        Goto skip;
      end;
    end;
    pdest :=  pChar(Integer(name) + pos('##',name));
    if pdest <> nil then
    begin
      _result := Integer(DWORD(pdest) - DWORD(name));
      lstrcpy(msgbuff,'是否允许');
      lstrcat(msgbuff,pChar(copy(outputbuff,8,_result)));
      lstrcat(msgbuff,'运行');
      lstrcat(msgbuff,pChar(@outputbuff[10+_result]));
    end else if pos('$$',name) <> 0 then
    begin
    {
      pdest := pChar(DWORD(name) + pos('$$',name));
      _result := Integer(DWORD(pdest) - DWORD(name));
      lstrcpy(msgbuff,'是否允许');
      lstrcat(msgbuff,pChar(copy(outputbuff,8,_result)));
      lstrcat(msgbuff,'设置注册表');
      lstrcat(msgbuff,pChar(@outputbuff[10+_result]));  }
    end else
    begin
      pdest := pChar(DWORD(name) + pos('&&',name));
      _result := Integer(DWORD(pdest) - DWORD(name));
      lstrcpy(msgbuff,'是否允许');
      lstrcat(msgbuff,pChar(copy(outputbuff,8,_result)));
      lstrcat(msgbuff,'加载驱动');
      lstrcat(msgbuff,pChar(@outputbuff[10+_result]));
    end;
    if MessageBox(0, msgbuff,'WARNING',MB_YESNO or MB_ICONQUESTION or $00200000) = IDYES then
    begin
      a := 1;
      string(stringcount) := pChar(copy(name,0,lstrlen(name)-1));
      inc(stringcount);
    end else
      a := 0;
    skip:
    move(a,outputbuff[4],4);
    a := 0;
    move(a,outputbuff,4);
  end;
       
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  TempThreadID, lpBytesReturnedA, lpBytesReturnedB : DWORD;
  Str : String;
  addr : Pointer;

begin
  IsLoadDevice:=False;
  LoopWhile:=True;
  if SteupDevice then
  begin
          Sleep(100);
        //create processing thread
        DisableEventThread:=CreateThread(nil,
                                         0,
                                         @DisableEvent,                                                                              
                                        nil,
                                         0,
                                         TempThreadID);
        DeviceHandle:=CreateFile('\\.\PRMONITOR',
                                                         GENERIC_READ or GENERIC_WRITE,
                                                         0,
                                                         0,
                                                         OPEN_EXISTING,
                                                         FILE_ATTRIBUTE_SYSTEM,
                                                         0);

          if DeviceHandle = INVALID_HANDLE_VALUE then   
    begin
    IsLoadDevice:=False;
    Showmessage('加载驱动失败!!!');
    end
    else
    begin
    addr:=Pointer(1 + DWORD(GetProcAddress(GetModuleHandle('ntdll.dll'), 'NtCreateProcess')));   // 0x7c92d755
    // DWORD * addr=(DWORD *)(1+(DWORD)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtCreateProcess"));
    //ZeroMemory(outputbuff, 256);
    controlbuff[0]:=DWORD(addr);   //      // VC++的  controlbuff[0]=addr[0];
    controlbuff[1]:=DWORD(outputbuff[0]);    // // VC++的  controlbuff[1]=(DWORD)&outputbuff[0];
   // 问题可能出在上面的这二句, 但我不会转!!!

    DeviceIoControl(DeviceHandle,        // 禁止程序
                    1000,
                    @controlbuff,
                    256,
                    @controlbuff,
                    256,
                    lpBytesReturnedA,
                    0);

    DeviceIoControl(DeviceHandle,      // // 禁止驱动
                    1004,
                             @controlbuff,
                             256,
                             @controlbuff,
                             256,
                             lpBytesReturnedB,
                             0);
    IsLoadDevice:=True;
    Label1.Visible:=True;
    end;
  end;

end;

procedure TForm1.FormDestroy(Sender: TObject);
var
  lpBytesReturned : DWORD;
begin
  CloseSrv;
  if DeviceHandle > 0 then
  begin
  DeviceIoControl(DeviceHandle, 1005, nil, 0, nil, 0, lpBytesReturned, nil);
  CloseHandle(DeviceHandle);
  end;
end;

end.

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

上传的附件:
收藏
免费 0
支持
分享
最新回复 (11)
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
2
顶起!!!!!!!!!!!!!
2008-5-11 00:07
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
完全不懂,学习中,帮顶起来
2008-5-11 12:35
0
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
4
谢谢, 顶一下!!!!!!!!!!
2008-5-11 13:10
0
雪    币: 2067
活跃值: (82)
能力值: ( LV9,RANK:180 )
在线值:
发帖
回帖
粉丝
5
看不懂. 希望早日到达你的程度.

帮你顶.
2008-5-11 19:15
0
雪    币: 209
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
DELPHI怎么写驱动啊?
2008-5-11 20:00
0
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
7
使劲地, 用力地, 慢慢的, 写啊,写啊, 就写出来了, 不过不是我, 是版主
2008-5-11 23:20
0
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
8
晕, 我还未入门!!!
2008-5-11 23:21
0
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
9
顶起!!!!!!!!!
2008-5-14 03:46
0
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
10
顶起!!!!!!!!!
2008-5-18 01:16
0
雪    币: 2067
活跃值: (82)
能力值: ( LV9,RANK:180 )
在线值:
发帖
回帖
粉丝
11
可以在 Delphi 2.0 Compiler 吗?
2008-5-18 02:04
0
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
12
上面的代码可以
2008-5-18 16:12
0
游客
登录 | 注册 方可回帖
返回
//