【问题标题】:What would happen if a system executes a part of the file that is zero-padded?如果系统执行文件的一部分是零填充的,会发生什么?
【发布时间】:2018-10-13 12:34:04
【问题描述】:

我在一些帖子/视频/文件中看到它们被零填充以看起来比实际更大,或者符合某些文件系统实用程序用于移动文件的“相同文件大小”标准,主要是它们要么是恶作剧程序,或恶意软件。

但我经常想知道,如果文件损坏会发生什么情况,并且会“加载”文件末尾大的零填充空间中的下一组“指令”?

会发生什么事吗? 0x0的指令集是什么?

【问题讨论】:

  • 这取决于程序是为什么架构编写的。
  • 在 x86-64 上 00 00add [rax],aladd [eax],al 在 32b 模式下)。在 Z80 上 00nop 等等...(每个 CPU 可能有不同的指令集和操作码)。
  • 可执行文件通常用 NOP 填充,which are not zeros in x86。在调试模式下,它可能会被填充other values
  • @prl:OP 正在谈论他们看到的帖子和视频,其中说有时会填充“假”可执行文件。
  • 一个视频甚至可以在十六进制编辑器中打开其中一个文件并显示大量 0

标签: file assembly machine-language zero-padding


【解决方案1】:

0 字节的解码完全取决于 CPU 架构。在许多架构上,指令是固定长度的(例如 32 位),因此相关的内容是 00 00 00 00(使用 hexdump 表示法)。

在大多数 Linux 发行版上,clang/llvm 支持内置的多个目标架构(clang -targetllvm-objdump),这与 gcc / gas / binutils 不同,因此我能够使用它来检查某些架构我没有安装 cross-gcc / binutils 。使用llvm-objdump --version 查看支持的列表。 (但我不知道如何让它反汇编像 binutils objdump -b binary 这样的原始二进制文件,而且我的 clang 不会自行创建 SPARC 二进制文件。)


在 x86 上,00 00(2 个字节)将 (http://ref.x86asm.net/coder32.html) 解码为 8-bit add with a memory destination。第一个字节是操作码,第二个字节是指定操作数的 ModR/M。

这通常会立即发生段错误(如果eax/rax 不是有效指针),或者一旦执行从零填充部分的末尾落入未映射的页面中,就会发生段错误。 (这种情况在现实生活中会发生,因为 falling off the end of _start 等错误而没有进行退出系统调用),尽管在这些情况下,以下字节并不总是全为零。例如数据或 ELF 元数据。)


x86 64 位模式ndisasm -b64 /dev/zero | head

address   machine code      disassembly
00000000  0000              add [rax],al

x86 32 位模式 (-b32):

00000000  0000              add [eax],al

x86 16 位模式:(-b16):

00000000  0000              add [bx+si],al

AArch32 ARM 模式cd /tmp && dd if=/dev/zero of=zero bs=16 count=1 && arm-none-eabi-objdump -z -D -b binary -marm zero。 (没有-z,objdump 会跳过大块的全零并显示...

addr   machine code   disassembly
0:   00000000        andeq   r0, r0, r0

ARM Thumb/Thumb2arm-none-eabi-objdump -z -D -b binary -marm --disassembler-options=force-thumb zero

0:   0000            movs    r0, r0
2:   0000            movs    r0, r0

AArch64aarch64-linux-gnu-objdump -z -D -b binary -maarch64 zero

 0:   00000000        .inst   0x00000000 ; undefined

MIPS32echo .long 0 > zero.S && clang -c -target mips zero.S && llvm-objdump -d zero.o

zero.o: file format ELF32-mips
Disassembly of section .text:
   0:       00 00 00 00     nop

PowerPC 32 位和 64 位-target powerpc-target powerpc64。如果 PowerPC 的任何扩展使用 00 00 00 00 指令编码,或者它仍然是现代 IBM POWER 芯片上的非法指令,则 IDK。

zero.o: file format ELF32-ppc   (or ELF64-ppc64)
Disassembly of section .text:
   0:       00 00 00 00  <unknown>

IBM S390clang -c -target systemz zero.S

zero.o: file format ELF64-s390
Disassembly of section .text:
   0:       00 00  <unknown>
   2:       00 00  <unknown>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 2021-04-15
    • 1970-01-01
    相关资源
    最近更新 更多