嗨,伙计们,我有一个奇怪的问题,我不知道我在哪里做错了…
var IDH:PImageDosHeader; INH:PImageNtHeaders; ISH:PImageSectionHeader; buf:Pointer; FS:TFileStream; ep,tmp1,tmp2:DWORD; i:Word; begin if OpenDialog1.Execute then begin FS:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead or fmShareDenyNone); GetMem(buf,FS.size); FS.Read(buf^,FS.Size); FS.Free; IDH:=PImageDosHeader(buf); INH:=PImageNtHeaders(DWORD(buf) + DWORD(IDH^._lfanew)); ep:=INH^.OptionalHeader.AddressOfEntryPoint; for i:=0 to INH^.FileHeader.NumberOfSections - 1 do begin ISH:=PimageSectionHeader(DWORD(INH) + sizeof(TImageNtHeaders) + i * sizeof(TImageSectionHeader)); tmp1:=ISH^.VirtualAddress; tmp2:=ISH^.VirtualAddress + ISH^.Misc.VirtualSize; ShowMessageFmt('%d -> %d .. %d',[ep,tmp2]); if ep in [tmp1..tmp2] then ShowMessage('Got it'); //This fails even if ep is in the defined interval. Why? end; end; end;
当然我可以替换那条线
if (ep>=tmp1) and (ep<=tmp2)
但我想知道我做错了什么.
解决方法
集合是相同类型的值的集合.此类型必须是序数,并且此类型的变量必须最多具有256个可能的值. (
Official documentation)因此,一个集合不能包含整数,因为有超过256个可能的整数.
您可以使用InRange函数:
if InRange(ep,tmp2) then
(使用数学).