一个工程文件,一个窗体form1,窗体上有timer及其它控件
工程文件去掉了
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
并加入了
Procedure WinMain(); stdcall;
end;
再加注入代码运行后注入到SVCHOST,并执行到winMain()部分
问题是:
如何写代码,可以使form1建立消息循环,使timer事件得以执行

解决方案 »

  1.   

    可能是本人太莱,现重新说明一下:
    1、用DELPHI7新建一个应用程序;
    2、在form1上加上Timer;事件代码如下:
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
     timer1.Interval:=5000;
     showmessage(PChar('Timer事件发生了。'));
    end;
    按F9运行后,每5秒弹出提示。
    现在,在菜单点工程——查看源代码,
    将工程文件program Project1的内容换成以下内容:program Project1;uses
      Forms,Windows,messages,
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}Procedure WinMain(); stdcall;
     begin
      begin
          while   True  do
              begin
                sleep(1000);        //注入SVCHOST后到这里循环
              end;
      end;
     //ExitProcess(0);
    end;//以下为网上抄来的注入SVHOST代码
    var
    St: TStartupInfo;
    Pr: TProcessInformation;
    InjectSize: dword;
    Code: pointer;
    Injected: pointer; 
    BytesWritten: dword;
    Context: _CONTEXT;
    const
    injectprocess='svchost.exe';begin  
    ZeroMemory(@St, SizeOf(TStartupInfo));
    St.cb := SizeOf(TStartupInfo);
    St.wShowWindow := SW_SHOW;
    if CreateProcess(nil, injectprocess, nil, nil, false, Create_SUSPENDED, nil, nil, St, Pr) then
    begin
    Code := pointer(GetModuleHandle(nil));
    InjectSize := PImageOptionalHeader(pointer(integer(Code) + PImageDosHeader(Code)._lfanew +
                 SizeOf(dword) + SizeOf(TImageFileHeader))).SizeOfImage;
    Injected := VirtualAllocEx(Pr.hProcess, Code, InjectSize, MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);
    WriteProcessMemory(Pr.hProcess, Injected, Code, InjectSize, BytesWritten);
    Context.ContextFlags := CONTEXT_FULL;
    GetThreadContext(Pr.hThread, Context);
    Context.Eip := dword(@WinMain);
    SetThreadContext(Pr.hThread, Context);
    ResumeThread(Pr.hThread);end;end.重新F9运行后,可以在windows的任务管理器中看到新产生了svchost.exe进程。
    但是,要怎样才能让FORM1上Timer事件发生,显示出showmessage(PChar('Timer事件发生了。'));这一句的效果?
      

  2.   

    你想做什么?
    怎么看都没明白
    注入 是DLL注入EXE 
    EXE 代码 注入 EXE 我还没见过
    WinMain 应该写在DLL 里 
    让Svchost 加载这DLL 就可以了Context.Eip := dword(@WinMain);
    //WinMain是你的 Project1的地址 不可能 让Svchost 执行到 Project 里 
    //每个进程都有独立的代码数据空间
      

  3.   

    你要注入,要生成一个dll,不要用exe工程,
    如果你只是要定时做些事情,可以在dll
    的begin end 写个循环就ok了