M
me555555
Unregistered / Unconfirmed
GUEST, unregistred user!
有代码如下
var
i:integer;
pot0, pot1,pot2,pot3, pot4,pot5,pot6: Pointer; //指针
pby1,pby2, pby3, pby4, pby5: PBYTE; //指针
///[?]问题1: Pointer 和 PBYTE 不同吗?
ms1,ms2:TMemoryStream; //内存流
begin
ms1 := TMemoryStream.Create;
ms2 := TMemoryStream.Create;
Getmem(pot0, 307200);
Getmem(pot1, 307200);
GetMem(pot4, 307200);
try
ms1.LoadFromFile('c:/m.bmp');
ms1.Seek(0, soFromBeginning);
ms1.ReadBuffer(pot1^, 307200); //
CopyMemory(pot0, pot1, 307200);
pot2 := Pointer(DWORD(pot0) + 8);
pot3 := Pointer(DWORD(pot0) + 1032);
//[?]问题2 pot2 是 pot0 偏移 8 pot3 是 pot0 偏移 1024 吗?
ms1.Seek(0, soFromBeginning);
ms1.ReadBuffer(pot2^, 1024);
Getmem(pby1, 27000);
Getmem(pby2, 27000);
ms1.ReadBuffer(pby1^, 1024);
pby3 := pby1;
//[?]问题3:为什么pby3 := pby1;而不用 ms1.ReadBuffer(pby3^, 1024); 呢?
for i := 0 to 5 do
begin
ms1.ReadBuffer(pby3^, 300);
pby3 := PBYTE(DWORD(pby3) + 300);
//[?]问题4 pby3 := PBYTE(DWORD(pby3) + 300) 此句什么意思?
end;
pby3 := pby1;
for i := 1 to 27000 do
begin
pby3^ := pby3^ and $7F;
//[?]问题5 pby3^ := pby3^ and $7F 此句什么意思?
pby3 := PBYTE(DWORD(pby3) + 1);
end;
pby4 := PBYTE(DWORD(pby1) + 27000 );
pby5 := pby2;
for i := 1 to 90 do
begin
pby4 :=PBYTE(DWORD(pby4) - 300);
CopyMemory(pby5, pby4, 300);
pby5 := PBYTE(DWORD(pby5) + 300);
end;
CopyMemory(pby1, pby2, 27000);
ms2.WriteBuffer(pby1^, 27000);
ms2.Seek(0, soFromBeginning);
ms2.ReadBuffer(pot4^, 27000);
//[?]问题6 :pot4^ 到pby1^ 为什么要通过 ms2
pot5 := pot4;
pot6 := Ptr(DWORD(pot3) + 57900);
//[?]问题7:这里为什么用 pty 而不用 PBYTE 呢
for i := 1 to 90 do
begin
CopyMemory(pot6, pot5, 300);
pot5 := Ptr(DWORD(pot5) + 300);
pot6 := Ptr(DWORD(pot6) + 640);
end;
finally
FreeMem(pby1);
FreeMem(pby2);
FreeMem(pot0);
FreeMem(pot1);
FreeMem(pot4);
ms1.Free;
ms2.Free;
end;
end;
var
i:integer;
pot0, pot1,pot2,pot3, pot4,pot5,pot6: Pointer; //指针
pby1,pby2, pby3, pby4, pby5: PBYTE; //指针
///[?]问题1: Pointer 和 PBYTE 不同吗?
ms1,ms2:TMemoryStream; //内存流
begin
ms1 := TMemoryStream.Create;
ms2 := TMemoryStream.Create;
Getmem(pot0, 307200);
Getmem(pot1, 307200);
GetMem(pot4, 307200);
try
ms1.LoadFromFile('c:/m.bmp');
ms1.Seek(0, soFromBeginning);
ms1.ReadBuffer(pot1^, 307200); //
CopyMemory(pot0, pot1, 307200);
pot2 := Pointer(DWORD(pot0) + 8);
pot3 := Pointer(DWORD(pot0) + 1032);
//[?]问题2 pot2 是 pot0 偏移 8 pot3 是 pot0 偏移 1024 吗?
ms1.Seek(0, soFromBeginning);
ms1.ReadBuffer(pot2^, 1024);
Getmem(pby1, 27000);
Getmem(pby2, 27000);
ms1.ReadBuffer(pby1^, 1024);
pby3 := pby1;
//[?]问题3:为什么pby3 := pby1;而不用 ms1.ReadBuffer(pby3^, 1024); 呢?
for i := 0 to 5 do
begin
ms1.ReadBuffer(pby3^, 300);
pby3 := PBYTE(DWORD(pby3) + 300);
//[?]问题4 pby3 := PBYTE(DWORD(pby3) + 300) 此句什么意思?
end;
pby3 := pby1;
for i := 1 to 27000 do
begin
pby3^ := pby3^ and $7F;
//[?]问题5 pby3^ := pby3^ and $7F 此句什么意思?
pby3 := PBYTE(DWORD(pby3) + 1);
end;
pby4 := PBYTE(DWORD(pby1) + 27000 );
pby5 := pby2;
for i := 1 to 90 do
begin
pby4 :=PBYTE(DWORD(pby4) - 300);
CopyMemory(pby5, pby4, 300);
pby5 := PBYTE(DWORD(pby5) + 300);
end;
CopyMemory(pby1, pby2, 27000);
ms2.WriteBuffer(pby1^, 27000);
ms2.Seek(0, soFromBeginning);
ms2.ReadBuffer(pot4^, 27000);
//[?]问题6 :pot4^ 到pby1^ 为什么要通过 ms2
pot5 := pot4;
pot6 := Ptr(DWORD(pot3) + 57900);
//[?]问题7:这里为什么用 pty 而不用 PBYTE 呢
for i := 1 to 90 do
begin
CopyMemory(pot6, pot5, 300);
pot5 := Ptr(DWORD(pot5) + 300);
pot6 := Ptr(DWORD(pot6) + 640);
end;
finally
FreeMem(pby1);
FreeMem(pby2);
FreeMem(pot0);
FreeMem(pot1);
FreeMem(pot4);
ms1.Free;
ms2.Free;
end;
end;