Re: Fastcode CharPosRev B&V 0.7.0
- From: "John O'Harrow" <john@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 16:43:09 -0000
Here's the validation routines to ensure that memory before the RefCount
address or on the next Windows page is never accessed.
function TMainForm.Validate17 : Boolean;
const
PAGE_SIZE : Cardinal = 4096;
var
I, J : Cardinal;
MemBlock, Page1: Pointer;
Page2: Pointer;
C,Dummy: Cardinal;
begin
GetMem(MemBlock, PAGE_SIZE * 3);
try
Result := False;
Page1 := Pointer((Cardinal(MemBlock) or (PAGE_SIZE-1))+1);
Page2 := Pointer(Cardinal(Page1) + PAGE_SIZE);
for J := 1 to 255 do
begin
PInteger(Cardinal(Page2))^ := 1; //RefCount
PInteger(Cardinal(Page2)+4)^ := J; //Len
for I := 0 to J do
PChar(Cardinal(Page2) + 8 + I)^ := #0;
try
Win32Check(VirtualProtect(Page1, PAGE_SIZE, PAGE_NOACCESS,
Dummy));
try
Result := True;
C := Cardinal(Page2) + 8;
CharPosRevFunction(#0, String(C));
CharPosRevFunction(#1, String(C));
CharPosRevFunction(#2, String(C));
CharPosRevFunction(#3, String(C));
CharPosRevFunction(#4, String(C));
CharPosRevFunction(#5, String(C));
CharPosRevFunction(#6, String(C));
CharPosRevFunction(#7, String(C));
CharPosRevFunction(#8, String(C));
except
Result := False;
Exit;
end;
finally
Win32Check(VirtualProtect(Page1, PAGE_SIZE,
PAGE_EXECUTE_READWRITE, Dummy));
end;
end;
finally
FreeMem(MemBlock);
end;
end;
function TMainForm.Validate18 : Boolean;
const
PAGE_SIZE : Cardinal = 4096;
var
I, J : Cardinal;
MemBlock, Page1: Pointer;
Page2: Pointer;
C,Dummy: Cardinal;
begin
GetMem(MemBlock, PAGE_SIZE * 3);
try
Result := False;
Page1 := Pointer((Cardinal(MemBlock) or (PAGE_SIZE-1))+1);
Page2 := Pointer(Cardinal(Page1) + PAGE_SIZE);
for J := 1 to 255 do
begin
PInteger(Cardinal(Page2)-J-9)^ := 1; //RefCount
PInteger(Cardinal(Page2)-J-5)^ := J; //Len
for I := 0 to J do
PChar(Cardinal(Page2)-I-1)^ := #0;
try
Win32Check(VirtualProtect(Page2, PAGE_SIZE, PAGE_NOACCESS,
Dummy));
try
Result := True;
C := Cardinal(Page2)-J-1;
CharPosRevFunction(#1, String(C));
except
Result := False;
Exit;
end;
finally
Win32Check(VirtualProtect(Page2, PAGE_SIZE,
PAGE_EXECUTE_READWRITE, Dummy));
end;
end;
finally
FreeMem(MemBlock);
end;
end;
--
regards,
John
The Fastcode Project:
http://www.fastcodeproject.org/
.
- Follow-Ups:
- Re: Fastcode CharPosRev B&V 0.7.0
- From: Dennis
- Re: Fastcode CharPosRev B&V 0.7.0
- References:
- Fastcode CharPosRev B&V 0.7.0
- From: Dennis
- Fastcode CharPosRev B&V 0.7.0
- Prev by Date: Re: Fastcode CharPosRev B&V 0.6.2
- Next by Date: Re: Fastcode SpreadsheetCreator 0.9.8
- Previous by thread: Fastcode CharPosRev B&V 0.7.0
- Next by thread: Re: Fastcode CharPosRev B&V 0.7.0
- Index(es):