简体   繁体   English

在反汇编的二进制文件中HIGHLOW的含义是什么?

[英]What's the meaning of HIGHLOW in a disassembled binary file?

I just used DUMPBIN for the first time and I see the term HIGHLOW repeatedly in the output file: 我刚刚第一次使用DUMPBIN,我在输出文件中反复看到术语HIGHLOW:

BASE RELOCATIONS #7
   11000 RVA,       E0 SizeOfBlock
    ...
         3B5  HIGHLOW            2001753D  ___onexitbegin
         3C1  HIGHLOW            2001753D  ___onexitbegin
    ...

I'm curious what this term stands for. 我很好奇这个词的意思。 I didn't find anything on Google or Stackoverflow about it. 我没有在Google或Stackoverflow上找到任何关于它的内容。

To apply a fixup, a delta is calculated as the difference between the preferred base address, and the base where the image is actually loaded. 要应用修正,请将delta计算为首选基址与实际加载图像的基础之间的差异。

The basic idea is that when doing a fixup at some address, we must know 基本的想法是,在某个地址进行修正时,我们必须知道

  1. what memory must be changed ("offset" field) 什么内存必须改变(“偏移”字段)
  2. what value is needed for its relocation ("delta" value) 重定位需要什么值(“delta”值)
  3. which parts of relocated data and delta value to use ("type" field) 要使用的重定位数据和增量值的哪些部分(“类型”字段)

Here are some possible values of the "type" field 以下是“类型”字段的一些可能值

  • HIGH - add higher word (16 bits) of delta to the 16-bit value at "offset" HIGH -三角的较高字(16位)的16位值在“偏移”添加
  • LOW - add lower word of delta to the value at "offset" LOW - 将delta的低位字添加到“offset”处的值
  • HIGHLOW - add full delta to the 32-bit value at "offset" HIGHLOW - 在“offset”处将32位值的完整增量添加

In other words, HIGHLOW type tells the program that it's doing a fix-up on offset "offset" from the page of this relocation block*, and that there is a doubleword that needs to be modified in order to have properly working executable. 换句话说, HIGHLOW类型告诉程序它正在对此重定位块*的页面偏移“偏移”进行修复,并且存在需要修改的双字以便具有正确工作的可执行文件。

* all of the relocation entries are grouped into blocks, and every block has a page on which its entries are applied *所有重定位条目都分组为块,每个块都有一个应用其条目的页面

Let's say that you have this instruction in your code: 假设你的代码中有这条指令:

section .data
message: "Hello World!", 0

section .code
...
mov eax, message
...

You run assembler and immediately after it you run disassembler. 你运行汇编程序,然后运行反汇编程序。 Now your code looks like this: 现在您的代码如下所示:

mov eax, dword [0x702000]

You're now curious why is it 0x700000 , and when you look into file dump, you see that 你现在很好奇为什么它是0x700000 ,当你研究文件转储时,你会看到它

ImageBase:      0x00700000

Now you understand where did this number come from and you'e ready to run the executable. 现在,您了解此数字的来源,并准备好运行可执行文件。 Loader which loads executable files into memory and creates address space for them finds out, that memory 0x700000 is unavailable and it needs to place that file somewhere else. 将可执行文件加载到内存并为它们创建地址空间的Loader发现,内存0x700000不可用,需要将该文件放在其他位置。 It decides that 0xf00000 will be OK and copies the file contents there. 它决定0xf00000是否正常并在那里复制文件内容。

But, your program was linked to work only with data on 0x700000 and there was no way for linker to know that its output would be relocated. 但是,您的程序仅与0x700000上的数据相关联,并且链接器无法知道其输出将被重定位。 Because of this, loader must do its magic. 因此,装载机必须发挥其魔力。 It

  1. calculates delta value - the old address (image base) is 0x700000 but it wants 0xf00000 (preferred address). 计算delta值 - 旧地址(图像库)是0x700000但它想要0xf00000 (首选地址)。 It subtracts one from another and gets 0x800000 as result. 它从另一个中减去一个并得到0x800000
  2. gets to the .reloc section of the file 到达文件的.reloc部分
  3. checks if there is still another page (4KB of data) to be relocated. 检查是否还有另一个要重新定位的页面(4KB数据)。 If no, it continues toward calling file´s entry point. 如果不是,它继续调用文件的入口点。 4.for every relocation for the current page, it 4.对于当前页面的每次重定位,它
  4. gets data at relocation offset 获取重定位偏移量的数据
  5. adds the delta value (in the way as type field states) 添加delta值(作为类型字段状态的方式)
  6. places the new value at relocation offset 将新值放在重定位偏移处
  7. continues on step 3 继续第3步

There are also more types of relocation entry and some of them are architecture-specific. 还有更多类型的重定位条目,其中一些是特定于体系结构的。 To see a full list, read the "Microsoft Portable Executable and Common Object File Format, section 6.6.2. Fixup Types" . 要查看完整列表,请阅读“Microsoft可移植可执行文件和通用目标文件格式,第6.6.2节”修复类型“

What you see here is the content of the "Base relocation table" in Microsoft Windows executable files. 您在此处看到的是Microsoft Windows可执行文件中“基本重定位表”的内容。

Base relocation tables are necessary in Windows for DLL files and they are optional for executable files; Windows中的DLL文件需要基本重定位表,它们对于可执行文件是可选的; they contain information about the location of address information in the EXE/DLL file that must be updated when the actual address of the DLL file in memory is known (when loading the DLL into memory). 它们包含有关EXE / DLL文件中地址信息位置的信息,当已知内存中DLL文件的实际地址(将DLL加载到内存中时)必须更新这些信息。 Windows uses the information stored in this table to update the address information. Windows使用此表中存储的信息来更新地址信息。

The table supports different types of addresses while the naming is Microsoft-specific: ABSOLUTE (= dummy), HIGH, LOW, HIGHLOW, HIGHADJ and MIPS_JMPADDR. 该表支持不同类型的地址,而命名是Microsoft特定的:ABSOLUTE(= dummy),HIGH,LOW,HIGHLOW,HIGHADJ和MIPS_JMPADDR。

The full name of the constant is "IMAGE_REL_BASED_HIGHLOW". 常量的全名是“IMAGE_REL_BASED_HIGHLOW”。

The "ABSOLUTE" type is typically a dummy entry inserted to ensure the parts of the table are a multiple of 4 (or 8) bytes long. “ABSOLUTE”类型通常是插入的虚拟条目,以确保表的各部分是4(或8)字节长的倍数。

On x86 CPUs only the "HIGHLOW" type is used: It tells Windows about the location of an absolute (32-bit) address in the file. 在x86 CPU上,仅使用“HIGHLOW”类型:它告诉Windows有关文件中绝对(32位)地址的位置。

Some background info: 一些背景信息:

In your example the "Image Base" could be 0x20000000 which means that the EXE/DLL file has been compiled to be loaded into address 0x20000000. 在您的示例中,“Image Base”可能是0x20000000,这意味着已编译EXE / DLL文件以加载到地址0x20000000。 At the addresses 0x200113B5 (0x20000000 + 0x11000 + 0x3B5) and 0x200113C1 there are absolute addresses. 在地址0x200113B5(0x20000000 + 0x11000 + 0x3B5)和0x200113C1处有绝对地址。

Let's say the memory at location 0x200113B5 contains the value 0x20012345 which is the address of a function or variable in the program. 假设位置0x200113B5的内存包含值0x20012345,它是程序中函数或变量的地址。

Maybe the memory at address 0x20000000 cannot be used and Windows decides to load the DLL into the memory at 0x50000000 instead. 可能无法使用地址0x20000000处的内存,Windows决定将DLL加载到0x50000000的内存中。 Then the 0x20012345 must be replaced by 0x50012345. 然后0x20012345必须替换为0x50012345。

The information in the base relocation table is used by Windows to find all addresses that must be replaced. Windows使用基本重定位表中的信息来查找必须替换的所有地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM