我知道每个 x86 指令都有一个操作码,但我不知道数据类型和变量如何转换为机器代码。所以我试图弄清楚。我写了一个简单的 C 程序并将其转换为汇编:
#include<stdio.h>
int variable1=1;
int variable2=1;
char variable3='A';
char variable4='A';
char name[20]="naveen prakash";
int main(int argc, char const *argv[])
{
char g[4]="hell";
int local_variable1=1;
int local_variable2=2;
int local_variable3;
variable1=0;
variable2=1;
variable3='B';
variable4='A';
printf("HeLLO wORLD\n");
getch();
}
上述程序的汇编(使用编译gcc -S hello.c):
.file "hello.c"
.globl _variable1
.data
.align 4
_variable1:
.long 1
.globl _variable2
.align 4
_variable2:
.long 1
.globl _variable3
_variable3:
.byte 65
.globl _variable4
_variable4:
.byte 65
.globl _name
_name:
.ascii "naveen prakash\0"
.space 5
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC1:
.ascii "HeLLO wORLD\0"
LC0:
.ascii "hell\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
call ___main
movl LC0, %eax
movl %eax, 16(%esp)
movl $1, 20(%esp)
movl $2, 24(%esp)
movl $0, _variable1
movl $1, _variable2
movb $66, _variable3
movb $65, _variable4
movl $LC1, (%esp)
call _puts
call _getch
leave
ret
.def _puts; .scl 2; .type 32; .endef
.def _getch; .scl 2; .type 32; .endef
我只能找出全局变量而找不到局部变量。然后我创建了上述程序的可执行文件并使用IDA,ollyDBG,PE Explorer并试图找到变量的位置,但我找不到。
当它转换成机器语言时,变量和数据类型声明会发生什么变化?
我读到那个.data段包含初始化数据,然后我试图找到我的初始化数据,但我找不到任何东西。我有一个文本“naveen prakash”,但在可执行文件的任何地方都找不到它。我使用十六进制编辑器查看二进制文件。
所以我的问题是,变量和数据类型如何在机器代码中表示,我们如何使用调试器找到它?