📄 p_vmlinx.cpp
字号:
stxt->sh_addralign = 4; stxt->sh_size += sizeof(stub_arm_linux_kernel_vmlinux_head); return sizeof(stub_arm_linux_kernel_vmlinux_head);}unsigned PackVmlinuxARMEB::write_vmlinux_head( OutputFile *const fo, Shdr *const stxt){ // First word from vmlinux-head.S fo->write(&stub_armeb_linux_kernel_vmlinux_head[0], 4); // Second word U32 tmp_u32; unsigned const t = (0xff000000 & BeLePolicy::get32(&stub_armeb_linux_kernel_vmlinux_head[4])) | (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2))); tmp_u32 = t; fo->write(&tmp_u32, 4); stxt->sh_addralign = 4; stxt->sh_size += sizeof(stub_armeb_linux_kernel_vmlinux_head); return sizeof(stub_armeb_linux_kernel_vmlinux_head);}unsigned PackVmlinuxPPC32::write_vmlinux_head( OutputFile * /*const fo*/, Shdr * /*const stxt*/){ return 0;}bool PackVmlinuxARMEL::has_valid_vmlinux_head(){ U32 buf[2]; fi->seek(p_text->sh_offset + sizeof(stub_arm_linux_kernel_vmlinux_head) -8, SEEK_SET); fi->readx(buf, sizeof(buf)); //unsigned const word0 = buf[0]; unsigned const word1 = buf[1]; if (0xeb==(word1>>24) && (0x00ffffff& word1)==(0u - 1 + ((3+ ph.c_len)>>2))) { return true; } return false;}bool PackVmlinuxARMEB::has_valid_vmlinux_head(){ U32 buf[2]; fi->seek(p_text->sh_offset + sizeof(stub_armeb_linux_kernel_vmlinux_head) -8, SEEK_SET); fi->readx(buf, sizeof(buf)); //unsigned const word0 = buf[0]; unsigned const word1 = buf[1]; if (0xeb==(word1>>24) && (0x00ffffff& word1)==(0u - 1 + ((3+ ph.c_len)>>2))) { return true; } return false;}bool PackVmlinuxPPC32::has_valid_vmlinux_head(){ U32 buf[2]; fi->seek(p_text->sh_offset + sizeof(stub_powerpc_linux_kernel_vmlinux_head) -8, SEEK_SET); fi->readx(buf, sizeof(buf)); //unsigned const word0 = buf[0]; unsigned const word1 = buf[1]; if (0xeb==(word1>>24) && (0x00ffffff& word1)==(0u - 1 + ((3+ ph.c_len)>>2))) { return true; } return false;}bool PackVmlinuxI386::has_valid_vmlinux_head(){ unsigned char buf[5]; fi->seek(p_text->sh_offset + sizeof(stub_i386_linux_kernel_vmlinux_head) -5, SEEK_SET); fi->readx(&buf[0], 5); if (0xE8!=buf[0] || BeLePolicy::get32(&buf[1]) != ph.c_len) { return false; } return true;}bool PackVmlinuxAMD64::has_valid_vmlinux_head(){ unsigned char buf[5]; fi->seek(p_text->sh_offset + sizeof(stub_amd64_linux_kernel_vmlinux_head) -5, SEEK_SET); fi->readx(&buf[0], 5); if (0xE8!=buf[0] || BeLePolicy::get32(&buf[1]) != ph.c_len) { return false; } return true;}//// Example usage within build system of Linux kernel-2.6.18:////----- arch/i386/boot/compressed/Makefile//#//# linux/arch/i386/boot/compressed/Makefile//#//# create a compressed vmlinux image from the original vmlinux//#////targets := vmlinux upx-piggy.o////LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32////$(obj)/vmlinux: $(obj)/upx-piggy.o FORCE// $(call if_changed,ld)// @:////$(obj)/upx-piggy.o: vmlinux FORCE// upx --lzma -f -o $@ $<; touch $@////#//# The ORIGINAL build sequence using gzip is://# vmlinux Elf executable at top level in tree//# (in same directory as MAINTAINERS)//# In arch/i386://# boot/compressed/vmlinux.bin by objcopy -O binary//# boot/compressed/vmlinux.bin.gz by gzip//# boot/compressed/piggy.o by ld --format binary --oformat elf32-i386//#//# The 3 steps above create a linkable//# compressed blob.//# In arch/i386://# boot/compressed/vmlinux by ld head.o misc.o piggy.o//# boot/vmlinux.bin by objcopy//# boot/bzImage by arch/i386/boot/tools/build with//# bootsect and setup//#//#//# The MODIFIED build sequence using upx is://# vmlinux Elf executable at top level in tree//# (in same directory as MAINTAINERS)//# In arch/i386://# boot/compressed/upx-piggy.o by upx format vmlinux/386//#//# In arch/i386/boot://# boot/compressed/vmlinux by ld upx-piggy.o//# boot/vmlinux.bin by objcopy//# boot/bzImage by arch/i386/boot/tools/build with//# bootsect and setup//#//-----#if 0 /*{*/// For Debian nslu2-linux (2.6.19), only this Makefile changes:--- ./debian/build/build-arm-none-ixp4xx/arch/arm/boot/compressed/Makefile.orig 2006-11-29 13:57:37.000000000 -0800+++ ./debian/build/build-arm-none-ixp4xx/arch/arm/boot/compressed/Makefile 2006-12-16 02:39:38.000000000 -0800@@ -5,7 +5,7 @@ # HEAD = head.o-OBJS = misc.o+OBJS = FONTC = drivers/video/console/font_acorn_8x8.c FONT = $(addprefix ../../../../drivers/video/console/, font_acorn_8x8.o)@@ -73,8 +73,8 @@ SEDFLAGS = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/-targets := vmlinux vmlinux.lds piggy.gz piggy.o $(FONT) \- head.o misc.o $(OBJS)+targets := vmlinux vmlinux.lds upx-piggy.o $(FONT) \+ head.o $(OBJS) EXTRA_CFLAGS := -fpic EXTRA_AFLAGS :=@@ -95,20 +95,16 @@ # would otherwise mess up our GOT table CFLAGS_misc.o := -Dstatic=-$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.o \- $(addprefix $(obj)/, $(OBJS)) FORCE+$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) \+ $(addprefix $(obj)/, $(OBJS)) $(obj)/upx-piggy.o FORCE $(call if_changed,ld) @:-$(obj)/piggy.gz: $(obj)/../Image FORCE- $(call if_changed,gzip)--$(obj)/piggy.o: $(obj)/piggy.gz FORCE+$(obj)/upx-piggy.o: vmlinux FORCE+ upx --lzma -f -o $@ $<; touch $@ CFLAGS_font_acorn_8x8.o := -Dstatic= $(obj)/vmlinux.lds: $(obj)/vmlinux.lds.in arch/arm/boot/Makefile .config @sed "$(SEDFLAGS)" < $< > $@-$(obj)/misc.o: $(obj)/misc.c include/asm/arch/uncompress.h lib/inflate.c-#endif /*}*/// Approximate translation for Linux 2.4.x:// - - -// arch/i386/Makefile: LD_FLAGS=-e startup_32//----- arch/i386/boot/compressed/Makefile//# linux/arch/i386/boot/compressed/Makefile//#//# create a compressed vmlinux image from the original vmlinux//#////HEAD =//SYSTEM = $(TOPDIR)/vmlinux////OBJECTS = $(HEAD)////ZLDFLAGS = -e startup_32////#//# ZIMAGE_OFFSET is the load offset of the compression loader//# BZIMAGE_OFFSET is the load offset of the high loaded compression loader//#//ZIMAGE_OFFSET = 0x1000//BZIMAGE_OFFSET = 0x100000////ZLINKFLAGS = -Ttext $(ZIMAGE_OFFSET) $(ZLDFLAGS)//BZLINKFLAGS = -Ttext $(BZIMAGE_OFFSET) $(ZLDFLAGS)////all: vmlinux////vmlinux: upx-piggy.o $(OBJECTS)// $(LD) $(ZLINKFLAGS) -o vmlinux $(OBJECTS) upx-piggy.o////bvmlinux: upx-piggy.o $(OBJECTS)// $(LD) $(BZLINKFLAGS) -o bvmlinux $(OBJECTS) upx-piggy.o////upx-piggy.o: $(SYSTEM)// $(RM) -f $@// upx --best -o $@ $<// touch $@////clean:// rm -f vmlinux bvmlinux _tmp_*//-----//// Example test jig:// $ gcc -m32 -o test-piggy -nostartfiles -nostdlib test-piggy.o piggy.o// $ gdb test-piggy// (gdb) run >dumped// (gdb) /* Execute [single step, etc.; the decompressor+unfilter moves!]// * until reaching the 'lret' at the end of unfilter.// */// (gdb) set $pc= &dump// (gdb) stepi// (gdb) set $edx=<actual_uncompressed_length>// (gdb) continue// (gdb) q// $ # Compare file 'dumped' with the portion of vmlinux that made piggy.o.// $ dd if=vmlinux bs=<leader_size> skip=1 | cmp - dumped// cmp: EOF on dumped// $//----- test-piggy.S//#include <asm/mman.h>//#include <asm/unistd.h>////dump:// movl $0x456789,%edx # length MODIFY THIS VALUE TO SUIT YOUR CASE// movl $0x100000,%ecx # base// movl $1,%ebx # stdout// movl $ __NR_write,%eax// int $0x80// nop// hlt//mmap:// pushl %ebx// leal 2*4(%esp),%ebx// pushl $ __NR_mmap; popl %eax// int $0x80// popl %ebx// ret $6*4////_start: .globl _start// nop// int3 # enter debugger!// pushl $0// pushl $0// pushl $ MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED// pushl $ PROT_EXEC | PROT_WRITE | PROT_READ// pushl $0x600000 # 6MB length// pushl $0x100000 # 1MB address// call mmap// leal -0x9000(%esp),%esi # expect "lea 0x9000(%esi),%esp" later///* Fall into .text of upx-compressed vmlinux. *///-----// Example test jig for ARM://-----main.c//unsigned work[(1<<16)/sizeof(unsigned)];//unsigned kernel[(3<<20)/sizeof(unsigned)];/////* In order to avoid complaints such as// /usr/bin/ld: ERROR: libgcc_s.so uses hardware FP, whereas main uses software FP// when building this test program, then you must change the .e_flags// in the header of the compressed, relocatble output from upx, from// Flags: 0x202, has entry point, GNU EABI, software FP// to// Flags: 0x0//*/////main()//{// char *const end = decompress_kernel(kernel, work, (1<<(16-2))+work, 0x1234);// write(1, kernel, (char *)end - (char *)kernel);// return 0;//}//-----/*************************************************************************//**************************************************************************/const int *PackVmlinuxAMD64::getCompressionMethods(int method, int level) const{ return Packer::getDefaultCompressionMethods_le32(method, level);}const int *PackVmlinuxAMD64::getFilters() const{ static const int filters[] = { 0x49, 0x46, -1 }; return filters;}bool PackVmlinuxAMD64::is_valid_e_entry(Addr e_entry){ return 0x200000<=e_entry; // 2MB}Linker* PackVmlinuxAMD64::newLinker() const{ return new ElfLinkerX86;}// instantiate instancestemplate class PackVmlinuxBase<ElfClass_LE32>;template class PackVmlinuxBase<ElfClass_BE32>;template class PackVmlinuxBase<ElfClass_LE64>;/*vi:ts=4:et*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -