📄 p_vmlinx.cpp
字号:
obuf.allocForUncompression(ph.u_len); decompress(ibuf, obuf); Filter ft(ph.level); ft.init(ph.filter, 0); ft.cto = (unsigned char) ph.filter_cto; ft.unfilter(obuf, ph.u_len); fo->write(obuf, ph.u_len); obuf.dealloc(); ibuf.dealloc(); fi->seek(p_note1->sh_offset, SEEK_SET); fi->readx(&word, sizeof(word)); ph.u_len = word; ph.c_len = p_note1->sh_size - sizeof(word); ibuf.alloc(ph.c_len); fi->readx(ibuf, p_note1->sh_size - sizeof(ph.u_len)); obuf.allocForUncompression(ph.u_len); decompress(ibuf, obuf, false); fo->write(obuf, ph.u_len); obuf.dealloc(); ibuf.dealloc(); ph = ph_tmp;}/*************************************************************************//**************************************************************************/const int *PackVmlinuxI386::getCompressionMethods(int method, int level) const{ return Packer::getDefaultCompressionMethods_le32(method, level);}const int *PackVmlinuxI386::getFilters() const{ static const int filters[] = { 0x49, 0x46, FT_END }; return filters;}const int *PackVmlinuxARMEL::getCompressionMethods(int method, int level) const{ return Packer::getDefaultCompressionMethods_8(method, level);}const int *PackVmlinuxARMEB::getCompressionMethods(int method, int level) const{ return Packer::getDefaultCompressionMethods_8(method, level);}const int *PackVmlinuxPPC32::getCompressionMethods(int method, int level) const{ // No real dependency on LE32. return Packer::getDefaultCompressionMethods_le32(method, level);}const int *PackVmlinuxARMEL::getFilters() const{ static const int f50[] = { 0x50, FT_END }; return f50;}const int *PackVmlinuxARMEB::getFilters() const{ static const int f51[] = { 0x51, FT_END }; return f51;}const int *PackVmlinuxPPC32::getFilters() const{ static const int fd0[] = { 0xd0, FT_END }; return fd0;}//// Examples as of 2004-07-16 [readelf --segments vmlinux # before fiddling]:////----- kernel-2.6.7 plain [defconfig?]//Program Headers(2):// Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align// LOAD 0x001000 0x00100000 0x00100000 0x1c7e61 0x1c7e61 R E 0x1000// LOAD 0x1c8e64 0x002c8e64 0x002c8e64 0x00000 0x00000 RW 0x1000////----- kernel-2.6.7-1.488 Fedora Core 3 test 1//Program Headers(5):// Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align// LOAD 0x001000 0x02100000 0x02100000 0x202246 0x202246 R E 0x1000// LOAD 0x204000 0xffff3000 0x02303000 0x00664 0x00664 R E 0x1000// LOAD 0x205000 0x02304000 0x02304000 0x43562 0x43562 R 0x1000// LOAD 0x249000 0x02348000 0x02348000 0x81800 0xcb0fc RWE 0x1000// STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4////----- kernel-2.6.18-1.2778 Fedora Core 6 test 3//Program Headers(3)// Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align// LOAD 0x001000 0xc0400000 0x00400000 0x279820 0x279820 R E 0x1000// LOAD 0x27b000 0xc067a000 0x0067a000 0x10ee64 0x1b07e8 RWE 0x1000// NOTE 0x000000 0x00000000 0x00000000 0x00000 0x00000 R 0x4bool PackVmlinuxI386::is_valid_e_entry(Addr e_entry){ return 0==(0x000fffff & e_entry); // entry on whole 1MB}Linker* PackVmlinuxI386::newLinker() const{ return new ElfLinkerX86;}void PackVmlinuxI386::buildLoader(const Filter *ft){ // prepare loader initLoader(stub_i386_linux_kernel_vmlinux, sizeof(stub_i386_linux_kernel_vmlinux)); addLoader("LINUX000", (0x40==(0xf0 & ft->id)) ? "LXCKLLT1" : (ft->id ? "LXCALLT1" : ""), "LXMOVEUP", getDecompressorSections(), NULL ); if (ft->id) { assert(ft->calls > 0); if (0x40==(0xf0 & ft->id)) { addLoader("LXCKLLT9", NULL); } else { addLoader("LXCALLT9", NULL); } addFilter32(ft->id); } addLoader("LINUX990", ((ph.first_offset_found == 1) ? "LINUX991" : ""), "LINUX992,IDENTSTR,UPX1HEAD", NULL);}void PackVmlinuxAMD64::buildLoader(const Filter *ft){ // prepare loader initLoader(stub_amd64_linux_kernel_vmlinux, sizeof(stub_amd64_linux_kernel_vmlinux)); addLoader("LINUX000", (0x40==(0xf0 & ft->id)) ? "LXCKLLT1" : (ft->id ? "LXCALLT1" : ""), "LXMOVEUP", getDecompressorSections(), NULL ); if (ft->id) { assert(ft->calls > 0); if (0x40==(0xf0 & ft->id)) { addLoader("LXCKLLT9", NULL); } else { addLoader("LXCALLT9", NULL); } addFilter32(ft->id); } addLoader("LINUX990", ((ph.first_offset_found == 1) ? "LINUX991" : ""), "LINUX992,IDENTSTR,UPX1HEAD", NULL);}bool PackVmlinuxARMEL::is_valid_e_entry(Addr e_entry){ return 0xc0008000==e_entry;}bool PackVmlinuxARMEB::is_valid_e_entry(Addr e_entry){ return 0xc0008000==e_entry;}bool PackVmlinuxPPC32::is_valid_e_entry(Addr e_entry){ return 0xc0000000==e_entry;}Linker* PackVmlinuxARMEL::newLinker() const{ return new ElfLinkerArmLE;}Linker* PackVmlinuxARMEB::newLinker() const{ return new ElfLinkerArmBE;}Linker* PackVmlinuxPPC32::newLinker() const{ return new ElfLinkerPpc32;}void PackVmlinuxARMEL::buildLoader(const Filter *ft){ // prepare loader initLoader(stub_arm_linux_kernel_vmlinux, sizeof(stub_arm_linux_kernel_vmlinux)); addLoader("LINUX000", NULL); if (ft->id) { assert(ft->calls > 0); addLoader("LINUX010", NULL); } addLoader("LINUX020", NULL); if (ft->id) { addFilter32(ft->id); } addLoader("LINUX030", NULL); if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL); else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL); else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL); else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL); else throwBadLoader(); addLoader("IDENTSTR,UPX1HEAD", NULL);}void PackVmlinuxARMEB::buildLoader(const Filter *ft){ // prepare loader initLoader(stub_armeb_linux_kernel_vmlinux, sizeof(stub_armeb_linux_kernel_vmlinux)); addLoader("LINUX000", NULL); if (ft->id) { assert(ft->calls > 0); addLoader("LINUX010", NULL); } addLoader("LINUX020", NULL); if (ft->id) { addFilter32(ft->id); } addLoader("LINUX030", NULL); if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL); else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL); else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL); else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL); else throwBadLoader(); addLoader("IDENTSTR,UPX1HEAD", NULL);}void PackVmlinuxPPC32::buildLoader(const Filter *ft){ // prepare loader initLoader(stub_powerpc_linux_kernel_vmlinux, sizeof(stub_powerpc_linux_kernel_vmlinux)); addLoader("LINUX000", NULL); if (ft->id) { assert(ft->calls > 0); addLoader("LINUX010", NULL); } addLoader("LINUX020", NULL); if (ft->id) { addFilter32(ft->id); } addLoader("LINUX030", NULL); if (ph.method == M_NRV2E_LE32) addLoader("NRV2E", NULL); else if (ph.method == M_NRV2B_LE32) addLoader("NRV2B", NULL); else if (ph.method == M_NRV2D_LE32) addLoader("NRV2D", NULL); else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL); else throwBadLoader(); addLoader("IDENTSTR,UPX1HEAD", NULL);}static const#include "stub/i386-linux.kernel.vmlinux-head.h"static const#include "stub/amd64-linux.kernel.vmlinux-head.h"static const#include "stub/arm-linux.kernel.vmlinux-head.h"static const#include "stub/armeb-linux.kernel.vmlinux-head.h"static const#include "stub/powerpc-linux.kernel.vmlinux-head.h"unsigned PackVmlinuxI386::write_vmlinux_head( OutputFile *const fo, Shdr *const stxt){ // COMPRESSED_LENGTH fo->write(&stub_i386_linux_kernel_vmlinux_head[0], sizeof(stub_i386_linux_kernel_vmlinux_head)-(1+ 4) +1); U32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4); stxt->sh_size += sizeof(stub_i386_linux_kernel_vmlinux_head); return sizeof(stub_i386_linux_kernel_vmlinux_head);}unsigned PackVmlinuxAMD64::write_vmlinux_head( OutputFile *const fo, Shdr *const stxt){ // COMPRESSED_LENGTH fo->write(&stub_amd64_linux_kernel_vmlinux_head[0], sizeof(stub_amd64_linux_kernel_vmlinux_head)-(1+ 4) +1); U32 tmp_u32; tmp_u32 = ph.c_len; fo->write(&tmp_u32, 4);printf(" Compressed length=0x%x\n", ph.c_len);printf("UnCompressed length=0x%x\n", ph.u_len); stxt->sh_size += sizeof(stub_amd64_linux_kernel_vmlinux_head); return sizeof(stub_amd64_linux_kernel_vmlinux_head);}void PackVmlinuxARMEL::defineDecompressorSymbols(){ super::defineDecompressorSymbols(); linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len); linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len); linker->defineSymbol("METHOD", ph.method);}void PackVmlinuxARMEB::defineDecompressorSymbols(){ super::defineDecompressorSymbols(); linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len); linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len); linker->defineSymbol("METHOD", ph.method);}void PackVmlinuxPPC32::defineDecompressorSymbols(){ super::defineDecompressorSymbols(); // linker->defineSymbol( "COMPRESSED_LENGTH", ph.c_len); // linker->defineSymbol("UNCOMPRESSED_LENGTH", ph.u_len); // linker->defineSymbol("METHOD", ph.method);}void PackVmlinuxI386::defineDecompressorSymbols(){ super::defineDecompressorSymbols(); linker->defineSymbol("ENTRY_POINT", phdri[0].p_paddr); linker->defineSymbol("PHYSICAL_START", phdri[0].p_paddr);}void PackVmlinuxAMD64::defineDecompressorSymbols(){ super::defineDecompressorSymbols(); // We assume a 32-bit boot loader, so we use the 32-bit convention // of "enter at the beginning" (startup_32). The 64-bit convention // would be to use ehdri.e_entry (startup_64). linker->defineSymbol("ENTRY_POINT", phdri[0].p_paddr); linker->defineSymbol("PHYSICAL_START", phdri[0].p_paddr);}unsigned PackVmlinuxARMEL::write_vmlinux_head( OutputFile *const fo, Shdr *const stxt){ // First word from vmlinux-head.S fo->write(&stub_arm_linux_kernel_vmlinux_head[0], 4); // Second word U32 tmp_u32; unsigned const t = (0xff000000 & BeLePolicy::get32(&stub_arm_linux_kernel_vmlinux_head[4])) | (0x00ffffff & (0u - 1 + ((3+ ph.c_len)>>2))); tmp_u32 = t; fo->write(&tmp_u32, 4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -