📄 unit1.pas
字号:
unit Unit1;
interface
uses WINPROCS,SysUtils,Dialogs;
procedure SetSegment(DSegment,DOffset:longint);export;
function ReadPhysMemory(PhAddr:Pointer;ReadSize:longint):boolean;export;
function WritePhysMemory(PhAddr:Pointer;ReadSize:longint):boolean;export;
implementation
var
Segment,Offset:word;
function MapPhysicalToLinear(dwPhysical,dwLength:longint):longint;
label fine_return;
var
dwLinear:longint;
begin
dwLinear := 0;
asm
push di
push si
mov bx, WORD PTR [dwPhysical+2]
mov cx, WORD PTR [dwPhysical]
mov si, WORD PTR [dwLength+2]
mov di, WORD PTR [dwLength]
mov ax, 800h
int 31h
jnc fine_return
xor bx, bx
mov cx, bx
fine_return:
mov WORD PTR [dwLinear+2], bx
mov WORD PTR [dwLinear], cx
pop si
pop di
end;
result:=dwLinear;
end;
function DPMISetSelectorLimit (selector:word;dwLimit:longint):boolean;
label success;
var
r:boolean;
begin
r:=true;
asm
pusha
mov ax, 0008h
mov bx, selector
mov cx, word ptr [dwLimit+2]
mov dx, word ptr [dwLimit]
int 31h
jnc success
mov r, 0
success:
popa
end;
result:=r;
end;
function ReadPhysMemory(PhAddr:Pointer;ReadSize:longint):boolean;
var
codeSelector,tempSelector:word;
Linear:longint;
fMemoryPointer :Pointer;
begin
result:=false;
if ReadSize=0 then exit;
{分配新的选择器}
asm
push ax
mov ax,cs
mov CodeSelector,ax
pop ax
end;
tempSelector:=AllocSelector(codeSelector);
if tempSelector=0 then exit;
if PrestoChangoSelector (codeSelector, tempSelector)<>0 then
begin
{设置选择器的基地址}
Linear:=MapPhysicalToLinear(Segment*$10000+Offset,ReadSize);
SetSelectorBase(tempSelector, Linear);
DPMISetSelectorLimit(tempSelector, ReadSize-1);
fMemoryPointer:=Ptr(tempSelector,0);
{拷贝内存块数据}
move(fMemoryPointer^,Phaddr^,ReadSize);
DPMISetSelectorLimit(tempSelector, 0);
Result:=true;
end;
FreeSelector(tempSelector);
end;
function WritePhysMemory(PhAddr:Pointer;ReadSize:longint):boolean;
var
codeSelector,tempSelector:word;
Linear:longint;
fMemoryPointer :Pointer;
begin
result:=false;
if ReadSize=0 then exit;
{分配新的选择器}
asm
push ax
mov ax,cs
mov CodeSelector,ax
pop ax
end;
tempSelector:=AllocSelector(codeSelector);
if tempSelector=0 then exit;
if PrestoChangoSelector (codeSelector, tempSelector)<>0 then
begin
{设置选择器的基地址}
Linear:=MapPhysicalToLinear(Segment*$10000+Offset,ReadSize);
SetSelectorBase(tempSelector, Linear);
DPMISetSelectorLimit(tempSelector, ReadSize-1);
fMemoryPointer:=Ptr(tempSelector,0);
{拷贝内存块数据}
move(Phaddr^,fMemoryPointer^,ReadSize);
DPMISetSelectorLimit(tempSelector, 0);
Result:=true;
end;
FreeSelector(tempSelector);
end;
{设置段选择符}
procedure SetSegment(DSegment,DOffset:longint);
begin
Segment:=DSegment;
Offset:=DOffset;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -