Delphi で、Portable Executable ファイルにコード (.text, CODE) を含むセクションの sha-256 ハッシュを取得したいと考えています。
ここまで、AddressOfEntryPoint が指すセクションの開始アドレスと終了アドレスを取得しようとしましたが、同じファイルを何度もロードすると、異なる開始アドレスと終了アドレスが取得されます。
誰でも私を助けてもらえますか?
これはコードです:
procedure TForm1.Button1Click(Sender: TObject);
var x:TJCLPEImage;
aoep,cs,ce: cardinal;
pise: Pimagesectionheader;
nos : integer;
i : integer;
begin
x := TJCLPEImage.Create();
x.FileName:=edit1.Text;
aoep := x.OptionalHeader32.AddressOfEntryPoint;
pise := Pointer(PByte(@(x.LoadedImage.FileHeader.OptionalHeader)) + x.LoadedImage.FileHeader.FileHeader.SizeOfOptionalHeader);
for i:=0 to x.ImageSectionCount-1 do
begin
if (pise.VirtualAddress <= aoep) and (aoep < (pise.VirtualAddress + pise.Misc.VirtualSize)) then
break;
end;
inc(pise);
cs := DWORD(x.LoadedImage.MappedAddress) + DWORD(pise.PointerToRawData);
ce := cs + pise.Misc.VirtualSize;
Label1.caption:='Code start: '+Inttostr(cs);
Label2.caption:='Code end: '+inttostr(ce);
end;
ありがとうございました。