本帖最后由 冥界3大法王 于 2019-12-5 07:24 编辑
@bester
亲爱的楼楼,这个怎么玩耍?
Checking project dependencies...
Compiling Project2.dproj (Debug, Win32)
[dcc32 Error] Unit1.pas(29): E2003 Undeclared identifier: 'de'
[dcc32 Warning] Unit1.pas(29): W1023 Comparing signed and unsigned types - widened both operands
[dcc32 Error] Unit1.pas(29): E2029 'THEN' expected but identifier 'dwDebugEventCode' found
[dcc32 Error] Unit1.pas(31): E2003 Undeclared identifier: 'excinfo'
[dcc32 Error] Unit1.pas(31): E2029 ')' expected but identifier 'Exception' found
[dcc32 Error] Unit1.pas(32): E2066 Missing operator or semicolon
[dcc32 Warning] Unit1.pas(32): W1021 Comparison always evaluates to False
[dcc32 Error] Unit1.pas(32): E2029 'THEN' expected but identifier 'ExceptionRecord' found
[dcc32 Error] Unit1.pas(34): E2003 Undeclared identifier: 'apiaddr'
[dcc32 Warning] Unit1.pas(34): W1023 Comparing signed and unsigned types - widened both operands
[dcc32 Error] Unit1.pas(34): E2029 'THEN' expected but identifier 'ExceptionRecord' found
[dcc32 Error] Unit1.pas(36): E2003 Undeclared identifier: 'deinfo'
[dcc32 Error] Unit1.pas(36): E2029 'END' expected but ',' found
[dcc32 Error] Unit1.pas(63): E2029 '.' expected but 'END' found
[dcc32 Warning] Unit1.pas(63): W1011 Text after final 'END.' - ignored by compiler
[dcc32 Fatal Error] Project2.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
Failed
Elapsed time: 00:00:00.6
求Delphi完整的工程文件打包,谢谢。这么高级的玩法没有学过。
[Delphi] 纯文本查看 复制代码 unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if EXCEPTION_DEBUG_EVENT = de.dwDebugEventCode then //判断是否为异常事件
begin
CopyMemory(Pointer(@excinfo), Pointer(@de.Exception), SizeOf(EXCEPTION_DEBUG_INFO)); //将调试结构中的异常结构复制出来
if EXCEPTION_BREAKPOINT = excinfo.ExceptionRecord.ExceptionCode then //异常代码是否为断点异常
begin
if apiaddr = excinfo.ExceptionRecord.ExceptionAddress then //异常位置是否为api地址处 apiaddr=excinfo.ExceptionAddress
begin
WriteProcessMemory(deinfo.hProcess, apiaddr, pointer(@yuan), 1, wd); //将CC断点恢复成原来的字节 unhook
//1、CONTEXT_DEBUG_REGISTERS,查询调式寄存器 {DR0-DR3(4个硬件断点所用) Dr6-Dr7}
//
//2、CONTEXT_FLOATING_POINT,查询浮点寄存器 { 387 state }
//
//3、CONTEXT_SEGMENTS,查询段寄存器 { DS, ES, FS, GS }
//
//4、CONTEXT_INTEGER,查询通用数据寄存器 { AX, BX, CX, DX, SI, DI }
//
//5、CONTEXT_CONTROL,查询控制寄存器组 { SS:SP, CS:IP, FLAGS, BP }
//
//6、CONTEXT_EXTENDED_REGISTERS,扩展寄存器组
//
//7、CONTEXT_FULL,CONTEXT_CONTROL+CONTEXT_SEGMENTS+ CONTEXT_SEGMENTS 三者合一
GetThreadContext(deinfo.hThread, ctx); //获得线程的上下文
ShowMessage('当前寄存器Esp的值:' + IntToHex(ctx.Esp + 8)); //这里可以对寄存器进行操作 可以读写等等
ctx.Eip := Integer(apiaddr) - 1; //ctx.Eip-1; //因为断在CC处,此时EIP会在当前CC处的地址+1的位置,故需要减一,否则一开始被CC覆盖的那个字节就不会被执行,会报错的
SetThreadContext(deinfo.hThread, ctx); //设置线程的上下文
ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE); //继续等待是否有调试事件的产生
Sleep(0); //每个线程有20毫秒的时间片运行,用完则切换其他线程,当运行完时,在context结构中取出保存的第一个线程执行结束时的状态,继续执行
//调用Sleep函数,可以释放当前线程的剩余时间片,即放弃当前线程执行的CPU时间片,也就是说,调用Sleep(0)函数后,CPU会立即执行其他线程
//否则可能引发当调试器写入CC时与被调试程序同时调用api导致内存访问异常.
//如果有需要继续hook,则在这里用WriteProcessMemory继续改CC
end;
end;
end
end;
end.
|