mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
386-darwin.dylib decompressor chains to user .init_address
This commit is contained in:
parent
7d38f0e234
commit
d7ed2412f6
|
@ -68,7 +68,8 @@ PackMachBase<T>::PackMachBase(InputFile *f, unsigned cputype, unsigned filetype,
|
||||||
unsigned flavor, unsigned count, unsigned size) :
|
unsigned flavor, unsigned count, unsigned size) :
|
||||||
super(f), my_cputype(cputype), my_filetype(filetype), my_thread_flavor(flavor),
|
super(f), my_cputype(cputype), my_filetype(filetype), my_thread_flavor(flavor),
|
||||||
my_thread_state_word_count(count), my_thread_command_size(size),
|
my_thread_state_word_count(count), my_thread_command_size(size),
|
||||||
n_segment(0), rawmseg(NULL), msegcmd(NULL), o_routines_cmd(0)
|
n_segment(0), rawmseg(NULL), msegcmd(NULL), o_routines_cmd(0),
|
||||||
|
prev_init_address(0)
|
||||||
{
|
{
|
||||||
MachClass::compileTimeAssertions();
|
MachClass::compileTimeAssertions();
|
||||||
bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL);
|
bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL);
|
||||||
|
@ -570,7 +571,10 @@ void PackDylibI386::pack3(OutputFile *fo, Filter &ft) // append loader
|
||||||
unsigned const zero = 0;
|
unsigned const zero = 0;
|
||||||
unsigned len = fo->getBytesWritten();
|
unsigned len = fo->getBytesWritten();
|
||||||
fo->write(&zero, 3& (0u-len));
|
fo->write(&zero, 3& (0u-len));
|
||||||
len += (3& (0u-len)) + 3*sizeof(disp);
|
len += (3& (0u-len)) + 4*sizeof(disp);
|
||||||
|
|
||||||
|
disp = prev_init_address;
|
||||||
|
fo->write(&disp, sizeof(disp)); // user .init_address
|
||||||
|
|
||||||
disp = sizeof(mhdro) + mhdro.sizeofcmds + sizeof(l_info) + sizeof(p_info);
|
disp = sizeof(mhdro) + mhdro.sizeofcmds + sizeof(l_info) + sizeof(p_info);
|
||||||
fo->write(&disp, sizeof(disp)); // src offset(compressed __TEXT)
|
fo->write(&disp, sizeof(disp)); // src offset(compressed __TEXT)
|
||||||
|
@ -915,6 +919,7 @@ bool PackMachBase<T>::canPack()
|
||||||
if (((Mach_segment_command const *)ptr)->cmd ==
|
if (((Mach_segment_command const *)ptr)->cmd ==
|
||||||
Mach_segment_command::LC_ROUTINES) {
|
Mach_segment_command::LC_ROUTINES) {
|
||||||
o_routines_cmd = (char *)ptr - (char *)rawmseg;
|
o_routines_cmd = (char *)ptr - (char *)rawmseg;
|
||||||
|
prev_init_address = ((Mach_routines_command const *)ptr)->init_address;
|
||||||
}
|
}
|
||||||
ptr += (unsigned) ((Mach_segment_command *)ptr)->cmdsize;
|
ptr += (unsigned) ((Mach_segment_command *)ptr)->cmdsize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -501,6 +501,7 @@ protected:
|
||||||
Mach_segment_command *rawmseg; // as input, with sections
|
Mach_segment_command *rawmseg; // as input, with sections
|
||||||
Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections
|
Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections
|
||||||
unsigned o_routines_cmd; // file offset to LC_ROUINTES
|
unsigned o_routines_cmd; // file offset to LC_ROUINTES
|
||||||
|
unsigned prev_init_address;
|
||||||
Mach_header mhdri;
|
Mach_header mhdri;
|
||||||
|
|
||||||
Mach_header mhdro;
|
Mach_header mhdro;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// We have been CALLed as a subroutine from dyld; C-language rules apply.
|
// We have been CALLed as a subroutine from dyld; C-language rules apply.
|
||||||
|
// -4*4+_start: .long offset(user_init_function)
|
||||||
// -3*4+_start: .long offset(&b_info of compressed Mach_headers)
|
// -3*4+_start: .long offset(&b_info of compressed Mach_headers)
|
||||||
// -2*4+_start: .long length(compressed __TEXT)
|
// -2*4+_start: .long length(compressed __TEXT)
|
||||||
// -1*4+_start: .long total_length # of preceding bytes in file
|
// -1*4+_start: .long total_length # of preceding bytes in file
|
||||||
|
@ -44,6 +45,7 @@
|
||||||
section LEXEC000
|
section LEXEC000
|
||||||
_start: .globl _start
|
_start: .globl _start
|
||||||
//// int3 # for debug only
|
//// int3 # for debug only
|
||||||
|
push eax # space for &user_init_function
|
||||||
pusha
|
pusha
|
||||||
call main // push address of decompress subroutine
|
call main // push address of decompress subroutine
|
||||||
decompress:
|
decompress:
|
||||||
|
@ -172,7 +174,9 @@ dy_reloc:
|
||||||
// Copy compressed __TEXT.
|
// Copy compressed __TEXT.
|
||||||
push edi # remember start of compressed __TEXT
|
push edi # remember start of compressed __TEXT
|
||||||
mov edx,ebx # &total_length
|
mov edx,ebx # &total_length
|
||||||
|
mov eax,[-3*4+ebx] # offset(user_init_function)
|
||||||
sub edx,[ebx] # runtime base address
|
sub edx,[ebx] # runtime base address
|
||||||
|
add eax,edx; mov [(1+2+8)*4 + esp],eax # relocate &user_init_function
|
||||||
mov esi,[-2*4 + ebx]; add esi,edx
|
mov esi,[-2*4 + ebx]; add esi,edx
|
||||||
mov ecx,[-1*4 + ebx]
|
mov ecx,[-1*4 + ebx]
|
||||||
rep movsb
|
rep movsb
|
||||||
|
|
Loading…
Reference in New Issue
Block a user