“在”中即使在定义的时间间隔内,运算符也会失败

发布于 2024-11-30 19:20:19 字数 1181 浏览 0 评论 0原文

我有一个奇怪的问题,我不知道我哪里做错了。

我有以下代码。请看它的结尾,这就是它失败的地方我评论了它:

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,tmp1,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) 

但我想知道我做错了什么。

I have a weird problem and I don't know where I am doing wrong.

I have the following code. Please look at the end of it that's where it fails I commented it:

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,tmp1,tmp2]);
          if ep in [tmp1..tmp2] then ShowMessage('Got it'); //This fails even if ep is in the defined interval. Why?
        end;
    end;
end;

Of course I can replace that line with

if (ep>=tmp1) and (ep<=tmp2) 

but I want to know what I am doing wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疧_╮線 2024-12-07 19:20:19

集合是相同类型的值的集合。该类型必须是有序的,并且该类型的变量最多有 256 个可能的值。 (官方文档)因此,集合不能包含整数,因为有超过 256 个可能的整数。

您可以使用 InRange 函数:(

if InRange(ep, tmp1, tmp2) then

使用 Math)。

A set is a collection of values of the same type. This type must be ordinal, and a variable of this type must have at most 256 possible values. (Official documentation) Hence, a set cannot contain integers, since there are more than 256 possible integers.

You could use the InRange function:

if InRange(ep, tmp1, tmp2) then

(uses Math).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文