c - x86 中 stat 结构的布局

标签 c linux linux-kernel x86

当我遇到一个关于查看 linux 的 struct stat 的问题时,我正在进行逆向工程练习。当我出于某种原因编译我的代码时,字段没有按照我的预期对齐。 st_dev 和 st_ino 之间似乎有两个是两个 0 字的差距,我不明白为什么这只是用它编译的。

gcc -m32 struct.c

结构.c

#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) 
{
    struct stat sb;

    sb.st_dev=0xbeef;
    sb.st_ino=0xdead;
    sb.st_mode=0xfeed;
    sb.st_nlink=0xffff;
    sb.st_uid=0x888f;
}

相关程序集

08048374 <main>:
 8048374:   8d 4c 24 04             lea    0x4(%esp),%ecx
 8048378:   83 e4 f0                and    $0xfffffff0,%esp
 804837b:   ff 71 fc                pushl  0xfffffffc(%ecx)
 804837e:   55                      push   %ebp
 804837f:   89 e5                   mov    %esp,%ebp
 8048381:   51                      push   %ecx
 8048382:   83 ec 60                sub    $0x60,%esp
 8048385:   c7 45 a4 ef be 00 00    movl   $0xbeef,0xffffffa4(%ebp)
 804838c:   c7 45 a8 00 00 00 00    movl   $0x0,0xffffffa8(%ebp)
 8048393:   c7 45 b0 ed be 00 00    movl   $0xdead,0xffffffb0(%ebp)
 804839a:   c7 45 b4 ed fe 00 00    movl   $0xfeed,0xffffffb4(%ebp)
 80483a1:   c7 45 b8 ff ff 00 00    movl   $0xffff,0xffffffb8(%ebp)
 80483a8:   c7 45 bc 8f 88 00 00    movl   $0x888f,0xffffffbc(%ebp)
 80483af:   83 c4 60                add    $0x60,%esp

我预计 0xdead 在 0xffffffa8(%ebp) 但不明白为什么不是这样。

作为引用,我查看了这个二进制文件,它打印的字段代表 http://beginners.re/exercises/per_chapter/struct_exercise_Linux86.tar来自 http://beginners.re/ 20.7.1 练习#1 tar

最佳答案

真实stat结构在 /usr/include/bits/stat.h 中定义(包含在 <sys/stat.h> 中)。您将了解那里的偏移量。

关于c - x86 中 stat 结构的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25921593/

相关文章:

linux - awk 查找两个字符串之间的第二条记录/awk 在文件中搜索

linux - 无法使用 find -exec 运行源命令

linux - 如何将文件保存到 ramdisk 文件系统中的闪存?

C-Linux 内核 : Closing two kthreads freezes machine

linux - linux内核的of_clk_init中的__clk_of_table符号是什么

c - 权威 C 书籍指南和 list

c - For循环在执行条件为false后仍然递增

c - fgets 只获取我文件的最后一行

c - 我该如何处理这个段错误

linux - 有什么方法可以跟踪网络数据包如何通过进程?