binutils 工具: strings 简单分析
来源:互联网 发布:三岛由纪夫 禁色 知乎 编辑:程序博客网 时间:2024/06/07 07:27
binutils 工具: strings 简单分析
strings 是查看二进制代码中ascii 字符串的工具,默认4个字符连在一起即为字符串。
阅读源码,可以加深一下理解,理解其工作过程:
1. 下载源码, 配置,编译。 编译的时候倒是直接有编译log 输出,不过是-g -O2 形式。
$cp Makefile Makefile.bak
先备份一下Makefile,把 -g -O2 改成 -g -O0 试试。
CFLAGS = -g -O0
CXXFLAGS = -g -O0
$touch binutils/strings.c
$make
有如下输出: 编译成功。
gcc -DHAVE_CONFIG_H -I. -I. -I. -I../bfd -I./../bfd -I./../include -DLOCALEDIR="\"/usr/local/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O0 -MT strings.o -MD -MP -MF .deps/strings.Tpo -c -o strings.o strings.c
mv -f .deps/strings.Tpo .deps/strings.P
/bin/sh ./libtool --tag=CC --mode=link gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O0 -static-libstdc++ -static-libgcc -o strings strings.o bucomm.o version.o filemode.o ../bfd/libbfd.la ../libiberty/libiberty.a -lz
阅读源码,也并不是那么简单, 下面看看关键部分。
显然,不特别指明,是仅导出obj 数据部分字符串,此处的数据部分
#define DATA_FLAGS (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS)
即有ALLOC 属性,可加载,有内容。
非obj文件或特别指明,导出整个文件字符串,
判断几个ascii字符为字符串? 默认为4, 可以由命令行指定。
具体是怎样实现的呢?
#0 strings_a_section (abfd=0x720f40, sect=0x722130, arg=0x7fffffffdb20) at strings.c:313
#1 0x00000000004112bb in bfd_map_over_sections (abfd=0x720f40, operation=0x4029fc <strings_a_section>, user_storage=0x7fffffffdb20) at section.c:1330
#2 0x0000000000402c00 in strings_object_file (file=0x7fffffffe16b "hello") at strings.c:385
#3 0x0000000000402ce2 in strings_file (file=0x7fffffffe16b "hello") at strings.c:419
strings_file 调用 strings_object_file,
strings_object_file 调用 bfd_map_over_sections, 传递给一个描述符, 一个函数指针,一个文件特性指针.
bfd_map_over_sections 函数, 从描述符可以找到每一个sect, 依次送给函数做处理就可以了。
----------------------------------------
strings_a_section: 处理一个section.
----------------------------------------
1. 调用 (bfd_get_section_contents (abfd, sect, mem, (file_ptr) 0, sectsize))
获取section 内容, 到 mem 中, (file_ptr) 0, 指的是offset.
即先要seek 到文件位置, 再读出内容。
bfd_seek (abfd, section->filepos + offset, SEEK_SET)
bfd_bread (location, count, abfd)
可见关键还是abfd 表述符,它是把一个section映射到内存的handle。
readelf -S 可以看到每个节信息, flags 带A 为有数据属性.
.interp, .dynsym, .dynstr .data .text 等都有数据属性。
.debug_info, .symtab, .strtab 都没有数据属性。
strings 是查看二进制代码中ascii 字符串的工具,默认4个字符连在一起即为字符串。
阅读源码,可以加深一下理解,理解其工作过程:
1. 下载源码, 配置,编译。 编译的时候倒是直接有编译log 输出,不过是-g -O2 形式。
$cp Makefile Makefile.bak
先备份一下Makefile,把 -g -O2 改成 -g -O0 试试。
CFLAGS = -g -O0
CXXFLAGS = -g -O0
$touch binutils/strings.c
$make
有如下输出: 编译成功。
gcc -DHAVE_CONFIG_H -I. -I. -I. -I../bfd -I./../bfd -I./../include -DLOCALEDIR="\"/usr/local/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O0 -MT strings.o -MD -MP -MF .deps/strings.Tpo -c -o strings.o strings.c
mv -f .deps/strings.Tpo .deps/strings.P
/bin/sh ./libtool --tag=CC --mode=link gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O0 -static-libstdc++ -static-libgcc -o strings strings.o bucomm.o version.o filemode.o ../bfd/libbfd.la ../libiberty/libiberty.a -lz
阅读源码,也并不是那么简单, 下面看看关键部分。
显然,不特别指明,是仅导出obj 数据部分字符串,此处的数据部分
#define DATA_FLAGS (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS)
即有ALLOC 属性,可加载,有内容。
非obj文件或特别指明,导出整个文件字符串,
判断几个ascii字符为字符串? 默认为4, 可以由命令行指定。
具体是怎样实现的呢?
#0 strings_a_section (abfd=0x720f40, sect=0x722130, arg=0x7fffffffdb20) at strings.c:313
#1 0x00000000004112bb in bfd_map_over_sections (abfd=0x720f40, operation=0x4029fc <strings_a_section>, user_storage=0x7fffffffdb20) at section.c:1330
#2 0x0000000000402c00 in strings_object_file (file=0x7fffffffe16b "hello") at strings.c:385
#3 0x0000000000402ce2 in strings_file (file=0x7fffffffe16b "hello") at strings.c:419
strings_file 调用 strings_object_file,
strings_object_file 调用 bfd_map_over_sections, 传递给一个描述符, 一个函数指针,一个文件特性指针.
bfd_map_over_sections 函数, 从描述符可以找到每一个sect, 依次送给函数做处理就可以了。
----------------------------------------
strings_a_section: 处理一个section.
----------------------------------------
1. 调用 (bfd_get_section_contents (abfd, sect, mem, (file_ptr) 0, sectsize))
获取section 内容, 到 mem 中, (file_ptr) 0, 指的是offset.
即先要seek 到文件位置, 再读出内容。
bfd_seek (abfd, section->filepos + offset, SEEK_SET)
bfd_bread (location, count, abfd)
可见关键还是abfd 表述符,它是把一个section映射到内存的handle。
readelf -S 可以看到每个节信息, flags 带A 为有数据属性.
.interp, .dynsym, .dynstr .data .text 等都有数据属性。
.debug_info, .symtab, .strtab 都没有数据属性。
0 0
- binutils 工具: strings 简单分析
- binutils-2.18/binutils/Makefile分析
- GNU binutils工具使用
- GNU binutils工具使用
- GNU Binutils工具介绍
- GNU binutils工具集
- GNU binutils工具使用
- binutils工具集1
- binutils工具集2
- GNU Binutils工具简介
- Binutils工具集 解析
- Binutils工具集 解析
- Binutils 工具集
- Binutils简单介绍
- binutils简单使用
- 分析binutils之addr2line
- binutils中strings.exe的生成
- 我的binutils工具集
- angularjs 验证(w5cValidator 2.0 验证信息框架的封装)
- Hibernate3中持久化对象的状态
- 为什么adrl r2,mem_cfg_val这里不用ldr r2,=mem_cfg_val
- Android进阶系列1—View的事件分发体系
- logback 配置详解
- binutils 工具: strings 简单分析
- NSTimer
- 【PAT】(乙级)1013. 数素数 (20)
- UML解惑:图说UML中的六大关系
- LeetCode #349
- Can't call rollback when autocommit=true
- 如何通过maven库查找pom中dependency
- OJ------超长整数相加
- POJ 2481Cows 树状数组