确定剥离的Linux内核映像的加载地址和入口点 [英] Determine load address and entry point of stripped Linux Kernel image
问题描述
我在x86 Linux上有一个用于嵌入式系统(mipsel)的交叉编译工具链.我知道如何为其构建自定义内核(我们将其称为"vmlinux"映像)以及如何通过
I have a crosscompiling toolchain for an embedded system (mipsel) on my x86 Linux. I know how to build a custom kernel (let's call the image "vmlinux") for it and how to strip that image via
objcopy -S -O binary vmlinux vmlinux.bin
为了进一步处理,我还需要图像的加载地址和入口点. 在之前,通过scripts/mksysmap
或更明确地通过
For further processing I also need the load address and entry point of the image. Before stripping it is no problem to determine them via scripts/mksysmap
or, more explicitly, via
nm -n vmlinux | grep -v '\( [aNUw] \)\|\(__crc_\)\|\( \$[adt]\)' > System.map
然后我可以通过确定加载地址和入口点
Then I can determine the load address and entry point via
awk '/A _text/ { print "0x"$1; }' < _System.map
awk '/T kernel_entry/ { print "0x"$1; }' < System.map
现在的挑战是,有时我不是自己构建内核,而是在之后获得一个预构建的内核,该内核已经通过 objcopy 删除了其符号. .有人可以告诉我该怎么做吗?我不太精通内核构建和工具链使用. nm 和 objdump 都不喜欢剥离的图像,说
Now the challenge is that sometimes I do not build the kernel by myself, but get a pre-built kernel after it has already been stripped of its symbols via objcopy. Can anybody tell me how to do this? I am not very proficient in kernel building and toolchain usage. Both nm and objdump do not like the stripped image, saying
vmlinux.bin: File format not recognized
推荐答案
objcopy can be used to generate a raw binary file by using an output target of binary (e.g., use -O binary). When objcopy generates a raw binary file, it will essentially produce a memory dump of the contents of the input object file. All symbols and relocation information will be discarded. The memory dump will start at the virtual address of the lowest section copied into the output file.
以下是可以在PowerPC架构上使用的示例:
Here is an example that could be used on the PowerPC architecture:
原始vmlinux
bash-3.2$ file vmlinux
vmlinux: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, not stripped
剥离的vmlinux被视为数据"文件
bash-3.2$ file vmlinux.bin
vmlinux.bin: data
将PowerPC的二进制文件转换为ELF格式
bash-3.2$ powerpc-440fp-linux-objcopy -I binary vmlinux.bin -B powerpc -O elf32-powerpc vmlinux.bin.x
vmlinux的输出现在被视为ELF文件
bash-3.2$ file vmlinux.bin.x
vmlinux.bin.x: ELF 32-bit MSB relocatable, PowerPC or cisco 4500, version 1 (SYSV), not stripped
您必须传递 -I , -B 和 -O 参数.您可以从objcopy文档中获取此参数.
You must pass the -I, -B and -O parameter. You can get this parameters from your objcopy documentation.
但是由于您的二进制文件已经被剥离,因此已经尝试反编译,因为该节信息不可用,因此可能不值得.文件中的所有数据都将转储到.data部分.
But since your binary is stripped already trying to decompile it might not be worthwhile since the section information is not available. All of the data in the file will be dumped into the .data secion.
这篇关于确定剥离的Linux内核映像的加载地址和入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!