科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网网络频道UNIX系统 目标文件初探

UNIX系统 目标文件初探

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

UNIX(R) 系统中运行的程序遵守一种称为目标文件格式的精心设计。了解更多关于目标文件格式的内容,以及可以用来研究系统中目标文件的工具。

来源:chinaitlab 2007年12月27日

关键字:

  • 评论
  • 分享微博
  • 分享邮件

在本页阅读全文(共8页)

Opcodes:
  Opcode 1 has 0 args
  Opcode 2 has 1 args
  Opcode 3 has 1 args
  Opcode 4 has 1 args
  Opcode 5 has 1 args
  Opcode 6 has 0 args
  Opcode 7 has 0 args
  Opcode 8 has 0 args
  Opcode 9 has 1 args
  Opcode 10 has 0 args
  Opcode 11 has 0 args
  Opcode 12 has 1 args

The Directory Table:
  /build/buildd/glibc-2.3.6/build-tree/i386-libc/csu

The File Name Table:
  Entry Dir     Time    Size    Name
  1     1       0       0       crti.S

Line Number Statements:
  Extended opcode 2: set Address to 0x8048308
  Advance Line by 64 to 65
  Copy
  Special opcode 48: advance Address by 3 to 0x804830b and Line by 1 to 66
  Advance PC by 1 to 0x804830c
  Extended opcode 1: End of Sequence

  Extended opcode 2: set Address to 0x8048458
  Advance Line by 46 to 47
  Copy
  Special opcode 20: advance Address by 1 to 0x8048459 and Line by 1 to 48
  Special opcode 34: advance Address by 2 to 0x804845b and Line by 1 to 49
  Special opcode 20: advance Address by 1 to 0x804845c and Line by 1 to 50
  Special opcode 76: advance Address by 5 to 0x8048461 and Line by 1 to 51
  Special opcode 90: advance Address by 6 to 0x8048467 and Line by 1 to 52
  Advance PC by 3 to 0x804846a
  Extended opcode 1: End of Sequence

  Extended opcode 2: set Address to 0x8048278
  Advance Line by 31 to 32
  Copy
  Special opcode 20: advance Address by 1 to 0x8048279 and Line by 1 to 33
  Special opcode 34: advance Address by 2 to 0x804827b and Line by 1 to 34
  Special opcode 48: advance Address by 3 to 0x804827e and Line by 1 to 35
  Advance PC by 5 to 0x8048283
  Extended opcode 1: End of Sequence

  Extended opcode 2: set Address to 0x80482e4
  Advance Line by 10 to 11
  Copy
  Special opcode 20: advance Address by 1 to 0x80482e5 and Line by 1 to 12
  Special opcode 34: advance Address by 2 to 0x80482e7 and Line by 1 to 13
  Special opcode 20: advance Address by 1 to 0x80482e8 and Line by 1 to 14
  Special opcode 76: advance Address by 5 to 0x80482ed and Line by 1 to 15
  Special opcode 90: advance Address by 6 to 0x80482f3 and Line by 1 to 16
  Special opcode 48: advance Address by 3 to 0x80482f6 and Line by 1 to 17
  Special opcode 90: advance Address by 6 to 0x80482fc and Line by 1 to 18
  Special opcode 34: advance Address by 2 to 0x80482fe and Line by 1 to 19
  Special opcode 34: advance Address by 2 to 0x8048300 and Line by 1 to 20
  Special opcode 35: advance Address by 2 to 0x8048302 and Line by 2 to 22
  Special opcode 48: advance Address by 3 to 0x8048305 and Line by 1 to 23
  Special opcode 20: advance Address by 1 to 0x8048306 and Line by 1 to 24
  Special opcode 20: advance Address by 1 to 0x8048307 and Line by 1 to 25
  Advance PC by 1 to 0x8048308
  Extended opcode 1: End of Sequence


  Length:                      136
  DWARF Version:               2
  Prologue Length:             80
  Minimum Instruction Length:  1
  Initial value of 'is_stmt':  1
  Line Base:                   -5
  Line Range:                  14
  Opcode Base:                 13
  (Pointer size:               4)

Opcodes:
  Opcode 1 has 0 args
  Opcode 2 has 1 args
  Opcode 3 has 1 args
  Opcode 4 has 1 args
  Opcode 5 has 1 args
  Opcode 6 has 0 args
  Opcode 7 has 0 args
  Opcode 8 has 0 args
  Opcode 9 has 1 args
  Opcode 10 has 0 args
  Opcode 11 has 0 args
  Opcode 12 has 1 args

The Directory Table:
  /build/buildd/glibc-2.3.6/build-tree/i386-libc/csu

The File Name Table:
  Entry Dir     Time    Size    Name
  1     1       0       0       crtn.S

Line Number Statements:
  Extended opcode 2: set Address to 0x8048308
  Advance Line by 33 to 34
  Copy
  Special opcode 48: advance Address by 3 to 0x804830b and Line by 1 to 35
  Advance PC by 1 to 0x804830c
  Extended opcode 1: End of Sequence

  Extended opcode 2: set Address to 0x804846f
  Advance Line by 18 to 19
  Copy
  Special opcode 48: advance Address by 3 to 0x8048472 and Line by 1 to 20
  Special opcode 20: advance Address by 1 to 0x8048473 and Line by 1 to 21
  Special opcode 20: advance Address by 1 to 0x8048474 and Line by 1 to 22
  Advance PC by 1 to 0x8048475
  Extended opcode 1: End of Sequence

  Extended opcode 2: set Address to 0x804828d
  Advance Line by 9 to 10
  Copy
  Special opcode 20: advance Address by 1 to 0x804828e and Line by 1 to 11
  Advance PC by 1 to 0x804828f
  Extended opcode 1: End of Sequence


Contents of the .debug_str section:

  0x00000000 696e6974 2e630073 686f7274 20696e74 init.c.short int
  0x00000010 002f6275 696c642f 6275696c 64642f67 ./build/buildd/g
  0x00000020 6c696263 2d322e33 2e362f62 75696c64 libc-2.3.6/build
  0x00000030 2d747265 652f676c 6962632d 322e332e -tree/glibc-2.3.
  0x00000040 362f6373 75006c6f 6e67206c 6f6e6720 6/csu.long long
  0x00000050 696e7400 756e7369 676e6564 20636861 int.unsigned cha
  0x00000060 7200474e 55204320 332e342e 36202855 r.GNU C 3.4.6 (U
  0x00000070 62756e74 7520332e 342e362d 31756275 buntu 3.4.6-1ubu
  0x00000080 6e747532 29006c6f 6e67206c 6f6e6720 ntu2).long long
  0x00000090 756e7369 676e6564 20696e74 0073686f unsigned int.sho
  0x000000a0 72742075 6e736967 6e656420 696e7400 rt unsigned int.
  0x000000b0 5f494f5f 73746469 6e5f7573 656400   _IO_stdin_used.

可执行文件是目标文件

    在 UNIX 中,可执行文件是 目标文件,并且您可以像对 a.out 文件那样对它们进行分析。可以进行一次有益的练习,更改到 /bin 或 /local/bin 目录,然后针对一些您最常用的命令,如 pwd、ps、cat 或 rm,运行 nm、objdump 和 readelf。通常,在您编写需要某种功能的程序时,如果标准的工具已经提供了这个功能,那么通过运行 objdump -d <command>,可以查看这些工具究竟如何完成这项任务。

    如果您倾向于使用编译器和其他的语言工具,那么您可以对组成计算机系统的各种目标文件进行仔细研究,并且您将会发现这项工作是非常值得的。UNIX 操作系统具有许多层次,那些通过工具查看目标文件所公开的层次,非常接近底层硬件。通过这种方式,您可以真实地接触到系统。

结束语

    研究目标文件可以极大地加深您对 UNIX 操作系统的认识,并且可以更深入地了解如何对软件的源代码进行汇编。我鼓励您使用本文中介绍的目标文件工具对系统中 /bin 或 /local/bin 目录中的程序进行分析,仔细研究其输出结果,并找出您的硬件制造商所提供的系统文档。

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章