美文网首页
二进制程序的格式学习

二进制程序的格式学习

作者: 心印印心 | 来源:发表于2018-04-27 16:29 被阅读0次
  1. 写一段源程序
; ----------------------------------------------------------------------------------------
; Writes "Hello, World" to the console using only system calls. Runs on 64-bit Linux only.
; To assemble and run:
;
;     nasm -felf64 hello.asm && ld hello.o && ./a.out
; ----------------------------------------------------------------------------------------

          global    _start

          section   .text
_start:   mov       rax, 1                  ; system call for write
          mov       rdi, 1                  ; file handle 1 is stdout
          mov       rsi, message            ; address of string to output
          mov       rdx, 13                 ; number of bytes
          syscall                           ; invoke operating system to do the write
          mov       rax, 60                 ; system call for exit
          xor       rdi, rdi                ; exit code 0
          syscall                           ; invoke operating system to exit

          section   .data
message:  db        "Hello, World", 10      ; note the newline at the end

查看64位ELF文件的Header格式。

image.png
; ----------------------------------------------------------------------------------------
; Writes "Hello, World" to the console using only system calls. Runs on 32-bit Linux only.
; To assemble and run:
;
;     nasm -felf hello.asm && ld  -m elf_i386 -s -o  a.out hello.o 
; ----------------------------------------------------------------------------------------

          global    _start

          section   .text
_start:   mov       eax, 1                  ; system call for write
          mov       edi, 1                  ; file handle 1 is stdout
          mov       esi, message            ; address of string to output
          mov       edx, 13                 ; number of bytes
          syscall                           ; invoke operating system to do the write
          mov       eax, 60                 ; system call for exit
          xor       edi, edi                ; exit code 0
          syscall                           ; invoke operating system to exit

          section   .data
message:  db        "Hello, World", 10      ; note the newline at the end

(此文件能编译链接,但在86-64运行时报错:)

fht@ubuntu:~$ ./hello32
Illegal instruction (core dumped)

查看32位ELF文件的Header格式。

image.png

32为的程序起始位置为0x08048000,64位为0x0000000000400000。 程序的开始真正执行的入口地址,32位的为偏移地址0x80处。64位的为偏移地址0xb0

相关文章

  • 二进制程序的格式学习

    写一段源程序 查看64位ELF文件的Header格式。 (此文件能编译链接,但在86-64运行时报错:) 查看32...

  • http2的多路复用笔记

    学习笔记 HTTP2采用二进制格式传输,取代了HTTP1.x的文本格式,二进制格式解析更高效。多路复用代替了HTT...

  • angr 文档翻译(1-7):分析

    分析 angr的目标是使得对二进制程序的分析更加简单。学习至此,angr允许你将分析代码打包为一个通用的格式,以便...

  • Mach-O文件格式解析

    Mach-o文件 Mach-O 是iOS/macOS系统上应用程序的格式 通用二进制文件(胖二进制文件) 因为Ma...

  • ch 1: 程序的生命周期

    1.2 把程序转化为 低级机器语言指令。然后把 指令 打包为 可执行目标程序 的格式打包, 并以二进制的磁盘文件...

  • Unity高级-数据序列化-BinaryFormatter

    BinaryFormatter BinaryFormatter使用二进制格式化程序进行序列化。您只需创建一个要使用...

  • mysql binlog的日志格式

    Binlog 的日志格式 记录在二进制日志中的事件的格式取决于二进制记录格式。支持三种格式类型: STATEMEN...

  • Mac OS X ABI Mach-O File Format

    概述   本文档描述了Mach-O文件格式的结构,它被用来存储程序和库到硬盘中,作为Mac OS X程序的二进制接...

  • HTTP2 协议前瞻

    HTTP/2 优势 HTTP/2 采用二进制格式传输数据,而非 HTTP/1.x 的文本格式。二进制格式在协议的解...

  • TI DSP6657—Nand Flash 程序固化

    前言 开发嵌入式DSP程序的时候,最终生成的可执行程序格式为.out , .out是TI CCS中一种二进制可执行...

网友评论

      本文标题:二进制程序的格式学习

      本文链接:https://www.haomeiwen.com/subject/okzblftx.html