1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Detabify.

This commit is contained in:
Markus F.X.J. Oberhumer 2007-12-17 06:00:33 +01:00
parent e4f4eace1c
commit 1cb1427050
3 changed files with 86 additions and 86 deletions

View File

@ -141,13 +141,13 @@
enum { // d_tag enum { // d_tag
DT_NULL = 0, /* End flag */ DT_NULL = 0, /* End flag */
DT_NEEDED = 1, /* Name of needed library */ DT_NEEDED = 1, /* Name of needed library */
DT_PLTRELSZ = 2, /* Size in bytes of PLT relocs */ DT_PLTRELSZ = 2, /* Size in bytes of PLT relocs */
DT_HASH = 4, /* Hash table of symbol names */ DT_HASH = 4, /* Hash table of symbol names */
DT_STRTAB = 5, /* String table */ DT_STRTAB = 5, /* String table */
DT_SYMTAB = 6, /* Symbol table */ DT_SYMTAB = 6, /* Symbol table */
DT_STRSZ = 10, /* Sizeof string table */ DT_STRSZ = 10, /* Sizeof string table */
DT_PLTREL = 20, /* Type of reloc in PLT */ DT_PLTREL = 20, /* Type of reloc in PLT */
DT_JMPREL = 23, /* Address of PLT relocs */ DT_JMPREL = 23, /* Address of PLT relocs */
DT_GNU_HASH = 0x6ffffef5 /* GNU-style hash table */ DT_GNU_HASH = 0x6ffffef5 /* GNU-style hash table */
}; };
#endif #endif

View File

@ -131,19 +131,19 @@ protected:
protected: protected:
Elf32_Ehdr ehdri; // from input file Elf32_Ehdr ehdri; // from input file
Elf32_Phdr *phdri; // for input file Elf32_Phdr *phdri; // for input file
Elf32_Shdr const *shdri; // from input file Elf32_Shdr const *shdri; // from input file
unsigned page_mask; // AND clears the offset-within-page unsigned page_mask; // AND clears the offset-within-page
Elf32_Dyn const *dynseg; // from PT_DYNAMIC Elf32_Dyn const *dynseg; // from PT_DYNAMIC
unsigned int const *hashtab; // from DT_HASH unsigned int const *hashtab; // from DT_HASH
unsigned int const *gashtab; // from DT_GNU_HASH unsigned int const *gashtab; // from DT_GNU_HASH
Elf32_Sym const *dynsym; // from DT_SYMTAB Elf32_Sym const *dynsym; // from DT_SYMTAB
char const *shstrtab; // via Elf32_Shdr char const *shstrtab; // via Elf32_Shdr
int n_elf_shnum; // via e_shnum int n_elf_shnum; // via e_shnum
Elf32_Shdr const *sec_strndx; Elf32_Shdr const *sec_strndx;
Elf32_Shdr const *sec_dynsym; Elf32_Shdr const *sec_dynsym;
Elf32_Shdr const *sec_dynstr; Elf32_Shdr const *sec_dynstr;
struct cprElfHdr1 { struct cprElfHdr1 {
Elf32_Ehdr ehdr; Elf32_Ehdr ehdr;

View File

@ -376,102 +376,102 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
#if 0 /*{ Documentation: changes to arch/powerpc/boot/main.c */ #if 0 /*{ Documentation: changes to arch/powerpc/boot/main.c */
struct b_info { struct b_info {
unsigned sz_unc; unsigned sz_unc;
unsigned sz_cpr; unsigned sz_cpr;
unsigned char b_method; unsigned char b_method;
unsigned char b_ftid; unsigned char b_ftid;
unsigned char b_cto8; unsigned char b_cto8;
unsigned char b_unused; unsigned char b_unused;
}; };
typedef int (*upx_f_unc)( /* uncompress */ typedef int (*upx_f_unc)( /* uncompress */
unsigned char const *src, unsigned src_len, unsigned char const *src, unsigned src_len,
unsigned char *dst, unsigned *dst_len, unsigned char *dst, unsigned *dst_len,
int method int method
); );
typedef int (*upx_f_unf)( /* unfilter */ typedef int (*upx_f_unf)( /* unfilter */
unsigned char *buf, unsigned char *buf,
unsigned len, unsigned len,
unsigned cto8, unsigned cto8,
unsigned ftid unsigned ftid
); );
unsigned char const *upx_expand( // return updated src [aligned, too] unsigned char const *upx_expand( // return updated src [aligned, too]
unsigned char const *src, unsigned char const *src,
unsigned char *dst, unsigned char *dst,
unsigned *const dst_len, unsigned *const dst_len,
upx_f_unc const f_unc upx_f_unc const f_unc
) )
{ {
if (0==*dst_len) { if (0==*dst_len) {
*dst_len = ((struct b_info const *)src)->sz_unc; *dst_len = ((struct b_info const *)src)->sz_unc;
} }
upx_f_unf const f_unf = (upx_f_unf)(sizeof(int) + (char *)f_unc); upx_f_unf const f_unf = (upx_f_unf)(sizeof(int) + (char *)f_unc);
unsigned total_len = 0; unsigned total_len = 0;
unsigned need = *dst_len; unsigned need = *dst_len;
while (0 < need) { while (0 < need) {
struct b_info const *const b_hdr = (struct b_info const *)src; struct b_info const *const b_hdr = (struct b_info const *)src;
src = (unsigned char const *)(1+ b_hdr); src = (unsigned char const *)(1+ b_hdr);
unsigned blk_len = b_hdr->sz_unc; unsigned blk_len = b_hdr->sz_unc;
int const rv = (*f_unc)(src, b_hdr->sz_cpr, dst, &blk_len, b_hdr->b_method); int const rv = (*f_unc)(src, b_hdr->sz_cpr, dst, &blk_len, b_hdr->b_method);
if (0!=rv) { if (0!=rv) {
printf("decompress error %d\n\r", rv); printf("decompress error %d\n\r", rv);
exit(); exit();
} }
if (b_hdr->b_ftid) { if (b_hdr->b_ftid) {
(*f_unf)(dst, b_hdr->sz_unc, b_hdr->b_cto8, b_hdr->b_ftid); (*f_unf)(dst, b_hdr->sz_unc, b_hdr->b_cto8, b_hdr->b_ftid);
} }
src += b_hdr->sz_cpr; src += b_hdr->sz_cpr;
src += (3& -(int)src); // 4-byte align src += (3& -(int)src); // 4-byte align
dst += b_hdr->sz_unc; dst += b_hdr->sz_unc;
total_len += b_hdr->sz_unc; total_len += b_hdr->sz_unc;
need -= b_hdr->sz_unc; need -= b_hdr->sz_unc;
} }
*dst_len = total_len; *dst_len = total_len;
return src; return src;
} }
void prep_kernel(unsigned long a1, unsigned long a2) void prep_kernel(unsigned long a1, unsigned long a2)
{ {
upx_f_unc f_unc = (upx_f_unc)0; upx_f_unc f_unc = (upx_f_unc)0;
vmlinuz.addr = (unsigned long)_vmlinux_start; vmlinuz.addr = (unsigned long)_vmlinux_start;
vmlinuz.size = (unsigned long)(_vmlinux_end - _vmlinux_start); vmlinuz.size = (unsigned long)(_vmlinux_end - _vmlinux_start);
if (0x55505821 == *(unsigned *)vmlinuz.addr) { if (0x55505821 == *(unsigned *)vmlinuz.addr) {
/* was compressed by upx */ /* was compressed by upx */
/* Uncompress elfheader */ /* Uncompress elfheader */
unsigned const *const fwa = (unsigned *)vmlinuz.addr; unsigned const *const fwa = (unsigned *)vmlinuz.addr;
f_unc = (upx_f_unc)((char *)&fwa[2] + fwa[1]); f_unc = (upx_f_unc)((char *)&fwa[2] + fwa[1]);
unsigned dst_len = 0; unsigned dst_len = 0;
unsigned char const *src = (unsigned char const *)&fwa[2]; unsigned char const *src = (unsigned char const *)&fwa[2];
src = upx_expand(src, (unsigned char *)elfheader, &dst_len, f_unc); src = upx_expand(src, (unsigned char *)elfheader, &dst_len, f_unc);
unsigned const src_len = src - (unsigned char const *)&fwa[0]; unsigned const src_len = src - (unsigned char const *)&fwa[0];
vmlinuz.addr += src_len; vmlinuz.addr += src_len;
vmlinuz.size -= src_len; vmlinuz.size -= src_len;
} else { } else {
memcpy(elfheader, (const void *)vmlinuz.addr, memcpy(elfheader, (const void *)vmlinuz.addr,
sizeof(elfheader)); sizeof(elfheader));
} }
===== =====
/* Eventually gunzip the kernel */ /* Eventually gunzip the kernel */
if (f_unc) { if (f_unc) {
/* was compressed by upx */ /* was compressed by upx */
printf("upx_expand (0x%lx <- 0x%lx:0x%0lx)...", printf("upx_expand (0x%lx <- 0x%lx:0x%0lx)...",
vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size); vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size);
unsigned dst_len = vmlinux.size - elfoffset; unsigned dst_len = vmlinux.size - elfoffset;
upx_expand((unsigned char const *)vmlinuz.addr, upx_expand((unsigned char const *)vmlinuz.addr,
(unsigned char *)vmlinux.addr, &dst_len, f_unc); (unsigned char *)vmlinux.addr, &dst_len, f_unc);
printf("done 0x%lx bytes\n\r", len); printf("done 0x%lx bytes\n\r", len);
} else { } else {
memmove((void *)vmlinux.addr,(void *)vmlinuz.addr, memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,
vmlinuz.size); vmlinuz.size);
/* Skip over the ELF header */ /* Skip over the ELF header */
#ifdef DEBUG #ifdef DEBUG
printf("... skipping 0x%lx bytes of ELF header\n\r", printf("... skipping 0x%lx bytes of ELF header\n\r",
elfoffset); elfoffset);
#endif #endif
vmlinux.addr += elfoffset; vmlinux.addr += elfoffset;
} }
===== =====
} }
#endif /*}*/ #endif /*}*/