gpt4 book ai didi

c - x86 中 stat 结构的布局

转载 作者:太空宇宙 更新时间:2023-11-04 07:14:35 27 4
gpt4 key购买 nike

当我遇到一个关于查看 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com