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

Merge branch 'sierra'

This commit is contained in:
Markus F.X.J. Oberhumer 2016-09-20 01:54:33 +02:00
commit acf2f2ffc4
14 changed files with 2830 additions and 677 deletions

View File

@ -184,23 +184,25 @@ void ElfLinker::init(const void *pdata_v, int plen)
}
input[inputlen] = 0; // NUL terminate
output = new upx_byte[inputlen];
output = new upx_byte[inputlen ? inputlen : 0x4000];
outputlen = 0;
int pos = find(input, inputlen, "Sections:\n", 10);
assert(pos != -1);
char *psections = (char *) input + pos;
if ((int)strlen("Sections:\n" "SYMBOL TABLE:\n" "RELOCATION RECORDS FOR ") < inputlen) {
int pos = find(input, inputlen, "Sections:\n", 10);
assert(pos != -1);
char *psections = (char *) input + pos;
char *psymbols = strstr(psections, "SYMBOL TABLE:\n");
assert(psymbols != NULL);
char *psymbols = strstr(psections, "SYMBOL TABLE:\n");
assert(psymbols != NULL);
char *prelocs = strstr(psymbols, "RELOCATION RECORDS FOR ");
assert(prelocs != NULL);
char *prelocs = strstr(psymbols, "RELOCATION RECORDS FOR ");
assert(prelocs != NULL);
preprocessSections(psections, psymbols);
preprocessSymbols(psymbols, prelocs);
preprocessRelocations(prelocs, (char*) input + inputlen);
addLoader("*UND*");
preprocessSections(psections, psymbols);
preprocessSymbols(psymbols, prelocs);
preprocessRelocations(prelocs, (char*) input + inputlen);
addLoader("*UND*");
}
}
void ElfLinker::preprocessSections(char *start, char *end)

View File

@ -53,6 +53,8 @@ static const
#include "stub/arm-darwin.macho-entry.h"
static const
#include "stub/arm-darwin.macho-fold.h"
static const
#include "stub/amd64-darwin.macho-upxmain.h"
static const
#include "stub/arm64-darwin.macho-entry.h"
@ -100,6 +102,9 @@ PackMachBase<T>::PackMachBase(InputFile *f, unsigned cputype, unsigned filetype,
{
MachClass::compileTimeAssertions();
bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL);
memset(&cmdUUID, 0, sizeof(cmdUUID));
memset(&cmdSRCVER, 0, sizeof(cmdSRCVER));
memset(&cmdVERMIN, 0, sizeof(cmdVERMIN));
}
template <class T>
@ -323,7 +328,13 @@ void PackMachI386::addStubEntrySections(Filter const *ft)
void PackMachAMD64::addStubEntrySections(Filter const * /*ft*/)
{
addLoader("MACHMAINX", NULL);
if (my_filetype!=Mach_header::MH_EXECUTE) {
addLoader("MACHMAINX", NULL);
}
else {
addLoader("AMD64BXX", NULL);
}
addLoader("MACH_UNC", NULL);
//addLoader(getDecompressorSections(), NULL);
addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
@ -333,7 +344,10 @@ void PackMachAMD64::addStubEntrySections(Filter const * /*ft*/)
: NULL), NULL);
if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH");
addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", NULL);
addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ", NULL);
if (my_filetype!=Mach_header::MH_EXECUTE) {
addLoader("FOLDEXEC", NULL);
}
}
void PackMachARMEL::addStubEntrySections(Filter const * /*ft*/)
@ -452,9 +466,35 @@ PackMachI386::buildLoader(const Filter *ft)
void
PackMachAMD64::buildLoader(const Filter *ft)
{
buildMachLoader(
stub_amd64_darwin_macho_entry, sizeof(stub_amd64_darwin_macho_entry),
stub_amd64_darwin_macho_fold, sizeof(stub_amd64_darwin_macho_fold), ft );
if (0 && my_filetype==Mach_header::MH_EXECUTE) {
initLoader(NULL, 0);
addStubEntrySections(ft);
defineSymbols(ft);
relocateLoader();
if (0) {
Mach_command const *ptr1 = (Mach_command const *)(1+
(Mach_header const *)stub_amd64_darwin_macho_upxmain_exe);
for (unsigned j = 0; j < mhdro.ncmds; ++j,
ptr1 = (Mach_command const *)(ptr1->cmdsize + (char const *)ptr1))
switch (ptr1->cmd) {
case Mach_segment_command::LC_SEGMENT_64: {
Mach_segment_command const *const segptr = (Mach_segment_command const *)ptr1;
if (!strcmp("__TEXT", segptr->segname)) {
Mach_section_command const *const secptr = (Mach_section_command const *)(1+ segptr);
linker->addSection("UPXMAIN", &stub_amd64_darwin_macho_upxmain_exe[secptr->offset],
secptr->size, 0);
addLoader("UPXMAIN", NULL);
}
} break;
} // end switch
}
}
else {
buildMachLoader(
stub_amd64_darwin_macho_entry, sizeof(stub_amd64_darwin_macho_entry),
stub_amd64_darwin_macho_fold, sizeof(stub_amd64_darwin_macho_fold), ft );
}
}
void
@ -574,9 +614,10 @@ void PackMachPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(cmdUUID)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
overlay_offset += sizeof(linkitem);
}
super::pack4(fo, ft);
@ -588,7 +629,7 @@ void PackMachPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader
secTEXT.size = segTEXT.filesize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
secXHDR.offset -= sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
@ -603,10 +644,10 @@ void PackMachPPC32::pack4(OutputFile *fo, Filter &ft) // append PackHeader
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&cmdUUID, sizeof(cmdUUID));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo));
@ -618,9 +659,10 @@ void PackMachPPC64LE::pack4(OutputFile *fo, Filter &ft) // append PackHeader
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(cmdUUID)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
overlay_offset += sizeof(linkitem);
}
super::pack4(fo, ft);
@ -632,7 +674,7 @@ void PackMachPPC64LE::pack4(OutputFile *fo, Filter &ft) // append PackHeader
secTEXT.size = segTEXT.filesize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
secXHDR.offset -= sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
@ -647,10 +689,10 @@ void PackMachPPC64LE::pack4(OutputFile *fo, Filter &ft) // append PackHeader
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&cmdUUID, sizeof(cmdUUID));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo));
@ -666,9 +708,10 @@ void PackMachI386::pack4(OutputFile *fo, Filter &ft) // append PackHeader
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(cmdUUID)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
overlay_offset += sizeof(linkitem);
}
super::pack4(fo, ft);
@ -680,7 +723,7 @@ void PackMachI386::pack4(OutputFile *fo, Filter &ft) // append PackHeader
secTEXT.size = segTEXT.filesize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
secXHDR.offset -= sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
@ -695,10 +738,10 @@ void PackMachI386::pack4(OutputFile *fo, Filter &ft) // append PackHeader
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&cmdUUID, sizeof(cmdUUID));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo));
@ -706,56 +749,242 @@ void PackMachI386::pack4(OutputFile *fo, Filter &ft) // append PackHeader
void PackMachAMD64::pack4(OutputFile *fo, Filter &ft) // append PackHeader
{
N_Mach::Mach_main_command cmdMAIN;
// offset of p_info in compressed file
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
+ sizeof(cmdUUID) + sizeof(cmdSRCVER) + sizeof(cmdVERMIN) + sizeof(cmdMAIN)
+ sizeof(N_Mach::Mach_dyld_info_only_command) + sizeof(Mach_dysymtab_command)
+ sizeof(N_Mach::Mach_load_dylinker_command) + sizeof(N_Mach::Mach_load_dylib_command)
+ sizeof(N_Mach::Mach_function_starts_command) + sizeof(N_Mach::Mach_data_in_code_command)
+ sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
overlay_offset = PAGE_SIZE; // FIXME
overlay_offset += sizeof(linfo);
}
super::pack4(fo, ft);
unsigned const t = fo->getBytesWritten();
segTEXT.filesize = t;
segTEXT.vmsize += t; // utilize GAP + NO_LAP + sz_unc - sz_cpr
if (my_filetype == Mach_header::MH_EXECUTE) {
unsigned long const zero = 0;
unsigned const len = fo->getBytesWritten();
fo->write(&zero, 7& (0u-len));
}
unsigned const eofcmpr = fo->getBytesWritten();
segTEXT.vmaddr = segZERO.vmaddr + segZERO.vmsize;
segTEXT.filesize = eofcmpr;
segTEXT.vmsize += eofcmpr; // utilize GAP + NO_LAP + sz_unc - sz_cpr
secTEXT.offset = overlay_offset - sizeof(linfo);
secTEXT.addr = segTEXT.vmaddr + secTEXT.offset;
secTEXT.size = segTEXT.filesize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
secXHDR.offset -= sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
if (foff1 < segTEXT.vmsize)
foff1 += PAGE_SIZE; // codesign disallows overhang
segLINK.fileoff = foff1;
segLINK.vmaddr = segTEXT.vmaddr + foff1;
segTEXT.vmsize = 0x1000;
secTEXT.size = 0x1000;
segXHDR.vmaddr = PAGE_MASK64 & (~PAGE_MASK64 + segTEXT.vmsize + segTEXT.vmaddr);
segXHDR.vmsize = 0x1000;
secXHDR.size = 0x1000;
segLINK.vmaddr = PAGE_MASK64 & (~PAGE_MASK64 + segXHDR.vmsize + segXHDR.vmaddr);
segLINK.vmsize = 0x1000;
fo->seek(-1+ 0x4000, SEEK_SET); fo->write("", 1);
fo->seek(sizeof(mhdro), SEEK_SET);
fo->rewrite(&segZERO, sizeof(segZERO));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&segXHDR, sizeof(segXHDR));
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
unsigned offLINK = segLINK.fileoff;
segLINK.vmaddr = segTEXT.vmaddr + offLINK;
if (my_filetype != Mach_header::MH_EXECUTE) {
fo->seek(offLINK - 1, SEEK_SET); fo->write("", 1);
fo->seek(sizeof(mhdro), SEEK_SET);
fo->rewrite(&segZERO, sizeof(segZERO));
fo->rewrite(&segXHDR, sizeof(segXHDR));
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&cmdUUID, sizeof(cmdUUID));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo));
}
if (my_filetype == Mach_header::MH_EXECUTE) {
// Get a writeable copy of the stub to make editing easier.
unsigned char upxstub[sizeof(stub_amd64_darwin_macho_upxmain_exe)];
memcpy(upxstub, stub_amd64_darwin_macho_upxmain_exe, sizeof(upxstub));
Mach_header *const ptr0 = (Mach_header *)upxstub;
Mach_command *ptr1 = (Mach_command *)(1+ ptr0);
unsigned cmdsize = mhdro.sizeofcmds - sizeof(segXHDR);
unsigned const ncmds = mhdro.ncmds;
unsigned delta = 0;
for (unsigned j = 0; j < ncmds -1; ++j,
(cmdsize -= ptr1->cmdsize),
ptr1 = (Mach_command *)(ptr1->cmdsize + (char *)ptr1))
next:
switch (ptr1->cmd) {
case Mach_segment_command::LC_SEGMENT_64: {
Mach_segment_command const *const segptr = (Mach_segment_command const *)ptr1;
if (!strcmp("__TEXT", segptr->segname)) {
memcpy(&segTEXT, segptr, sizeof(segTEXT));
Mach_section_command const *const secptr = (Mach_section_command const *)(1+ segptr);
memcpy(&secTEXT, secptr, sizeof(secTEXT));
// // Put f_unf and f_exp before compiled C code:
// // steal space from -Wl,-headerpadsize
//secTEXT.align = 0;
//unsigned const d = getLoaderSize();
//secTEXT.addr -= d;
//secTEXT.size += d;
//secTEXT.offset -= d;
fo->seek((char const *)secptr - (char const *)ptr0, SEEK_SET);
fo->rewrite(&secTEXT, sizeof(secTEXT));
//fo->seek(secTEXT.offset, SEEK_SET);
//fo->rewrite(getLoader(), d);
fo->seek(0, SEEK_END);
}
if (!strcmp("__DATA", segptr->segname) && !segptr->vmsize) {
goto omit;
}
if (!strcmp("__LINKEDIT", segptr->segname)) {
segLINK.initprot = Mach_segment_command::VM_PROT_READ
| Mach_segment_command::VM_PROT_EXECUTE;
delta = offLINK - segptr->fileoff; // relocation constant
//// The contents for __LINKEDIT remain the same,
//// but move to a different offset in the file
//fo->seek(offLINK, SEEK_SET);
//fo->write(&stub_amd64_darwin_macho_upxmain_exe[segLINK.fileoff], segLINK.filesize);
// Mach_segment_command for new segXHDR
segXHDR.cmdsize = sizeof(segXHDR); // no need for sections
segXHDR.vmaddr = segTEXT.vmsize + segTEXT.vmaddr; // XXX FIXME
segXHDR.vmsize = offLINK - segTEXT.vmsize;
segXHDR.fileoff = segTEXT.filesize + segTEXT.fileoff; // XXX FIXME: assumes no __DATA in stub
segXHDR.filesize = offLINK - segTEXT.filesize; // XXX FIXME: assumes no __DATA in stub;
segXHDR.maxprot = Mach_segment_command::VM_PROT_READ;
segXHDR.nsects = 0;
fo->seek((char const *)ptr1 - (char const *)ptr0, SEEK_SET);
fo->rewrite(&segXHDR, sizeof(segXHDR));
// Update the __LINKEDIT header
segLINK.filesize = eofcmpr - offLINK;
segLINK.vmsize = PAGE_MASK64 & (~PAGE_MASK64 + eofcmpr - offLINK);
segLINK.fileoff = segXHDR.filesize + segXHDR.fileoff;
segLINK.vmaddr = segXHDR.vmsize + segXHDR.vmaddr;
fo->rewrite(&segLINK, sizeof(segLINK));
}
} break;
case Mach_segment_command::LC_DYLD_INFO_ONLY: {
N_Mach::Mach_dyld_info_only_command blk; memcpy(&blk, ptr1, sizeof(blk));
if (blk.rebase_off) blk.rebase_off += delta;
if (blk.bind_off) blk.bind_off += delta;
if (blk.lazy_bind_off) blk.lazy_bind_off += delta;
if (blk.export_off) blk.export_off += delta;
// But we don't want any exported symbols.
blk.export_off = 0;
blk.export_size = 0;
fo->seek(sizeof(segXHDR) + ((char const *)ptr1 - (char const *)ptr0), SEEK_SET);
fo->rewrite(&blk, sizeof(blk));
goto omit; // try omitting this
} break;
case Mach_segment_command::LC_SYMTAB: {
Mach_symtab_command blk; memcpy(&blk, ptr1, sizeof(blk));
if (blk.symoff) blk.symoff += delta;
if (blk.stroff) blk.stroff += delta;
fo->seek(sizeof(segXHDR) + ((char const *)ptr1 - (char const *)ptr0), SEEK_SET);
fo->rewrite(&blk, sizeof(blk));
goto omit; // try omitting this
} break;
case Mach_segment_command::LC_DYSYMTAB: {
Mach_dysymtab_command blk; memcpy(&blk, ptr1, sizeof(blk));
if (blk.tocoff) blk.tocoff += delta;
if (blk.modtaboff) blk.modtaboff += delta;
if (blk.extrefsymoff) blk.extrefsymoff += delta;
if (blk.indirectsymoff) blk.indirectsymoff += delta;
if (blk.extreloff) blk.extreloff += delta;
if (blk.locreloff) blk.locreloff += delta;
// But we don't want any symbols.
blk.ilocalsym = 0;
blk.nlocalsym = 0;
blk.iextdefsym = 0;
blk.nextdefsym = 0;
blk.iundefsym = 0;
blk.nundefsym = 0;
fo->seek(sizeof(segXHDR) + ((char const *)ptr1 - (char const *)ptr0), SEEK_SET);
fo->rewrite(&blk, sizeof(blk));
goto omit; // adds full path as another agrument?
} break;
case Mach_segment_command::LC_FUNCTION_STARTS: {
N_Mach::Mach_function_starts_command blk; memcpy(&blk, ptr1, sizeof(blk));
if (blk.dataoff) blk.dataoff += delta;
fo->seek(sizeof(segXHDR) + ((char const *)ptr1 - (char const *)ptr0), SEEK_SET);
fo->rewrite(&blk, sizeof(blk));
} break;
case Mach_segment_command::LC_MAIN: {
// Change to LC_UNIX_THREAD; known to be contiguous with last
// LC_MAIN requires libSystem.B.dylib to provide the environment for main(), and CALLs the entryoff.
// LC_UNIXTHREAD does not need libSystem.B.dylib, and JMPs to the .rip with %rsp/argc and argv= 8+%rsp
threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
threado.cmdsize = sizeof(threado);
threado.flavor = my_thread_flavor;
threado.count = my_thread_state_word_count;
memset(&threado.state, 0, sizeof(threado.state));
threado.state.rip = ((N_Mach::Mach_main_command const *)ptr1)->entryoff + segTEXT.vmaddr;
fo->seek(sizeof(segXHDR) + ((char const *)ptr1 - (char const *)ptr0), SEEK_SET);
fo->rewrite(&threado, sizeof(threado));
mhdro.sizeofcmds += sizeof(threado) - ((Mach_command const *)ptr1)->cmdsize;
fo->seek(0, SEEK_SET);
fo->rewrite(&mhdro, sizeof(mhdro));
} break;
case Mach_segment_command::LC_LOAD_DYLIB: {
// Remove this command; known to be contiguous with last
N_Mach::Mach_load_dylib_command blk; memset(&blk, 0, sizeof(blk));
fo->seek(sizeof(segXHDR) + ((char const *)ptr1 - (char const *)ptr0), SEEK_SET);
fo->rewrite(&blk, sizeof(blk));
mhdro.ncmds -= 1;
mhdro.sizeofcmds -= ((Mach_command const *)ptr1)->cmdsize;
fo->seek(0, SEEK_SET);
fo->rewrite(&mhdro, sizeof(mhdro));
} break;
case Mach_segment_command::LC_DATA_IN_CODE: {
N_Mach::Mach_data_in_code_command blk; memcpy(&blk, ptr1, sizeof(blk));
if (blk.dataoff) blk.dataoff += delta;
memset(&blk, 0, sizeof(blk));
fo->seek(sizeof(segXHDR) + ((char const *)ptr1 - (char const *)ptr0), SEEK_SET);
fo->rewrite(&blk, sizeof(blk));
// Temporary test: remove this command; known to be last
mhdro.ncmds -= 1;
mhdro.sizeofcmds -= ((Mach_command const *)ptr1)->cmdsize;
fo->seek(0, SEEK_SET);
fo->rewrite(&mhdro, sizeof(mhdro));
} break;
case Mach_segment_command::LC_LOAD_DYLINKER: {
// Try omitting this
omit:
fo->seek(sizeof(mhdro) + mhdro.sizeofcmds - cmdsize, SEEK_SET);
Mach_command *ptr2 = ptr1;
unsigned const sz_omit = ptr1->cmdsize;
ptr1 = (Mach_command *)(sz_omit + (char *)ptr1);
cmdsize -= sz_omit;
fo->rewrite(ptr1, cmdsize); // slide in file TODO: clear the garbage
memmove(ptr2, ptr1, cmdsize); // overlapping slide lower
ptr1 = ptr2;
mhdro.ncmds -= 1;
mhdro.sizeofcmds -= sz_omit;
fo->seek(0, SEEK_SET);
fo->rewrite(&mhdro, sizeof(mhdro));
if (++j < (ncmds -1))
goto next;
goto done;
} break;
case Mach_segment_command::LC_SOURCE_VERSION: { // copy from saved original
fo->seek(sizeof(segXHDR) + ((char const *)ptr1 - (char const *)ptr0), SEEK_SET);
fo->rewrite(&cmdSRCVER, sizeof(cmdSRCVER));
memcpy(ptr1, &cmdSRCVER, sizeof(cmdSRCVER));
goto omit;
} break;
case Mach_segment_command::LC_VERSION_MIN_MACOSX: { // copy from saved original
fo->seek(sizeof(segXHDR) + ((char const *)ptr1 - (char const *)ptr0), SEEK_SET);
fo->rewrite(&cmdVERMIN, sizeof(cmdVERMIN));
memcpy(ptr1, &cmdVERMIN, sizeof(cmdVERMIN));
} break;
} // end switch
done:
fo->seek(0, SEEK_END);
}
fo->rewrite(&linfo, sizeof(linfo));
}
void PackMachARMEL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
@ -764,9 +993,10 @@ void PackMachARMEL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(cmdUUID)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
overlay_offset += sizeof(linkitem);
}
super::pack4(fo, ft);
@ -778,7 +1008,7 @@ void PackMachARMEL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
secTEXT.size = segTEXT.filesize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
secXHDR.offset -= sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
@ -793,10 +1023,10 @@ void PackMachARMEL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&cmdUUID, sizeof(cmdUUID));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo));
@ -808,9 +1038,10 @@ void PackMachARM64EL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
overlay_offset = sizeof(mhdro) + sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT)
+ sizeof(cmdUUID)
+ sizeof(segLINK) + sizeof(threado) + sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
overlay_offset += sizeof(uuid_cmd) + sizeof(linkitem);
overlay_offset += sizeof(linkitem);
}
super::pack4(fo, ft);
@ -822,7 +1053,7 @@ void PackMachARM64EL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
secTEXT.size = segTEXT.filesize - secTEXT.offset;
secXHDR.offset = overlay_offset - sizeof(linfo);
if (my_filetype==Mach_header::MH_EXECUTE) {
secXHDR.offset -= sizeof(uuid_cmd) + sizeof(linkitem);
secXHDR.offset -= sizeof(linkitem);
}
secXHDR.addr += secXHDR.offset;
unsigned foff1 = (PAGE_MASK & (~PAGE_MASK + segTEXT.filesize));
@ -837,10 +1068,10 @@ void PackMachARM64EL::pack4(OutputFile *fo, Filter &ft) // append PackHeader
fo->rewrite(&secXHDR, sizeof(secXHDR));
fo->rewrite(&segTEXT, sizeof(segTEXT));
fo->rewrite(&secTEXT, sizeof(secTEXT));
fo->rewrite(&cmdUUID, sizeof(cmdUUID));
fo->rewrite(&segLINK, sizeof(segLINK));
fo->rewrite(&threado, sizeof(threado));
if (my_filetype==Mach_header::MH_EXECUTE) {
fo->rewrite(&uuid_cmd, sizeof(uuid_cmd));
fo->rewrite(&linkitem, sizeof(linkitem));
}
fo->rewrite(&linfo, sizeof(linfo));
@ -1094,15 +1325,24 @@ void PackMachI386::pack3(OutputFile *fo, Filter &ft) // append loader
void PackMachAMD64::pack3(OutputFile *fo, Filter &ft) // append loader
{
TE32 disp;
unsigned const zero = 0;
unsigned long const zero = 0;
unsigned len = fo->getBytesWritten();
fo->write(&zero, 3& (0u-len));
len += (3& (0u-len));
len += (3& (0u-len)); // 0 mod 4
disp = len - sz_mach_headers;
fo->write(&disp, sizeof(disp));
len += sizeof(disp);
threado.state.rip = len + sizeof(disp) + segTEXT.vmaddr; /* entry address */
char page[~PAGE_MASK]; memset(page, 0, sizeof(page));
fo->write(page, ~PAGE_MASK & -len);
len += ~PAGE_MASK & -len;
segLINK.fileoff = len;
threado.state.rip = len + segTEXT.vmaddr; /* entry address */
super::pack3(fo, ft);
len = fo->getBytesWritten();
fo->write(&zero, 7& (0u-len));
}
void PackMachARMEL::pack3(OutputFile *fo, Filter &ft) // append loader
@ -1431,12 +1671,11 @@ void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e
unsigned const lc_seg = lc_segment[sizeof(Addr)>>3];
mhdro = mhdri;
if (my_filetype==Mach_header::MH_EXECUTE) {
mhdro.ncmds = 5; // __ZERO, __XHDR, __TEXT, __LINKEDIT, THREAD_STATE
mhdro.sizeofcmds = sizeof(segZERO)
+ sizeof(segXHDR) + sizeof(secXHDR)
+ sizeof(segTEXT) + sizeof(secTEXT) + sizeof(segLINK) +
my_thread_command_size /* + sizeof(uuid_cmd) + sizeof(linkitem) */ ;
mhdro.flags = Mach_header::MH_NOUNDEFS | Mach_header::MH_DYLDLINK;
memcpy(&mhdro, stub_amd64_darwin_macho_upxmain_exe, sizeof(mhdro));
mhdro.ncmds += 1; // we add LC_SEGMENT{,_64} for UPX_DATA
mhdro.sizeofcmds += sizeof(segXHDR);
mhdro.flags &= ~Mach_header::MH_PIE; // we require fixed address
mhdro.flags |= Mach_header::MH_BINDATLOAD; // DT_BIND_NOW
}
fo->write(&mhdro, sizeof(mhdro));
@ -1445,6 +1684,11 @@ void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e
segZERO.cmdsize = sizeof(segZERO);
strncpy((char *)segZERO.segname, "__PAGEZERO", sizeof(segZERO.segname));
segZERO.vmsize = PAGE_SIZE;
if (sizeof(segZERO.vmsize) == 8
&& mhdro.filetype == Mach_header::MH_EXECUTE
&& mhdro.cputype == Mach_header::CPU_TYPE_X86_64) {
segZERO.vmsize <<= 20; // (1ul<<32)
}
segTEXT.cmd = lc_seg;
segTEXT.cmdsize = sizeof(segTEXT) + sizeof(secTEXT);
@ -1477,17 +1721,22 @@ void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e
strncpy((char *)secTEXT.sectname, "__text", sizeof(secTEXT.sectname));
memcpy(secTEXT.segname, segTEXT.segname, sizeof(secTEXT.segname));
secTEXT.align = 2; // (1<<2) ==> 4
secTEXT.flags = Mach_section_command::S_REGULAR
| Mach_section_command::S_ATTR_SOME_INSTRUCTIONS
| Mach_section_command::S_ATTR_PURE_INSTRUCTIONS;
segXHDR = segTEXT;
segXHDR.vmaddr = PAGE_SIZE;
segXHDR.cmdsize = sizeof(segXHDR) + sizeof(secXHDR);
segXHDR.vmaddr = segZERO.vmsize;
segXHDR.vmsize = PAGE_SIZE;
segXHDR.filesize = PAGE_SIZE;
strncpy((char *)segXHDR.segname, "__XHDR", sizeof(segXHDR.segname));
segXHDR.nsects = 1;
strncpy((char *)segXHDR.segname, "UPX_DATA", sizeof(segXHDR.segname));
memset(&secXHDR, 0, sizeof(secXHDR));
strncpy((char *)secXHDR.sectname, "__xhdr", sizeof(secXHDR.sectname));
strncpy((char *)secXHDR.sectname, "upx_data", sizeof(secXHDR.sectname));
memcpy(secXHDR.segname, segXHDR.segname, sizeof(secXHDR.segname));
secXHDR.addr = PAGE_SIZE;
secXHDR.addr = segXHDR.vmaddr;
secXHDR.size = 0; // empty so far
secXHDR.align = 2; // (1<<2) ==> 4
@ -1495,23 +1744,51 @@ void PackMachBase<T>::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e
segLINK.cmdsize = sizeof(segLINK);
strncpy((char *)segLINK.segname, "__LINKEDIT", sizeof(segLINK.segname));
segLINK.nsects = 0;
segLINK.initprot = Mach_segment_command::VM_PROT_READ;
segLINK.initprot = Mach_segment_command::VM_PROT_READ
| Mach_segment_command::VM_PROT_EXECUTE;
// Adjust later: .vmaddr .vmsize .fileoff .filesize
if (my_filetype==Mach_header::MH_EXECUTE) {
if (my_filetype == Mach_header::MH_EXECUTE) {
unsigned cmdsize = mhdro.sizeofcmds - sizeof(segXHDR);
Mach_header const *const ptr0 = (Mach_header const *)stub_amd64_darwin_macho_upxmain_exe;
Mach_command const *ptr1 = (Mach_command const *)(1+ ptr0);
for (unsigned j = 0; j < mhdro.ncmds -1; ++j,
(cmdsize -= ptr1->cmdsize),
ptr1 = (Mach_command const *)(ptr1->cmdsize + (char const *)ptr1)) {
Mach_segment_command const *const segptr = (Mach_segment_command const *)ptr1;
if (lc_seg == ptr1->cmd) {
if (!strcmp("__LINKEDIT", segptr->segname)) {
// Mach_command before __LINKEDIT
fo->write((1+ ptr0), (char const *)ptr1 - (char const *)(1+ ptr0));
// LC_SEGMENT_64 for UPX_DATA; steal space from -Wl,-headerpadsize
segXHDR.cmdsize = sizeof(segXHDR);
segXHDR.vmaddr = 0;
segXHDR.fileoff = 0;
segXHDR.maxprot = Mach_segment_command::VM_PROT_READ;
segXHDR.initprot = Mach_segment_command::VM_PROT_READ;
segXHDR.nsects = 0;
fo->write(&segXHDR, sizeof(segXHDR));
// Mach_command __LINKEDIT and after
fo->write((char const *)ptr1, cmdsize);
// Contents before __LINKEDIT; put non-headers at same offset in file
unsigned pos = sizeof(mhdro) + mhdro.sizeofcmds; // includes sizeof(segXHDR)
fo->write(&stub_amd64_darwin_macho_upxmain_exe[pos], segptr->fileoff - pos);
break;
}
}
}
}
else { // not MH_EXECUTE; thus MH_DYLIB
fo->write(&segZERO, sizeof(segZERO));
fo->write(&segXHDR, sizeof(segXHDR));
fo->write(&secXHDR, sizeof(secXHDR));
fo->write(&segTEXT, sizeof(segTEXT));
fo->write(&secTEXT, sizeof(secTEXT));
fo->write(&cmdUUID, sizeof(cmdUUID));
fo->write(&segLINK, sizeof(segLINK));
pack1_setup_threado(fo);
memset(&uuid_cmd, 0, sizeof(uuid_cmd));
fo->write(&uuid_cmd, sizeof(uuid_cmd));
memset(&linkitem, 0, sizeof(linkitem));
fo->write(&linkitem, sizeof(linkitem));
}
if (my_filetype==Mach_header::MH_DYLIB) {
fo->write(rawmseg, mhdri.sizeofcmds);
}
sz_mach_headers = fo->getBytesWritten();
@ -1587,7 +1864,7 @@ void PackMachBase<T>::unpack(OutputFile *fo)
unsigned char const *ptr = (unsigned char const *)(1+mhdr);
for (unsigned j= 0; j < ncmds; ++j) {
memcpy(&msegcmd[j], ptr, umin(sizeof(Mach_segment_command),
((Mach_segment_command const *)ptr)->cmdsize));
((Mach_command const *)ptr)->cmdsize));
ptr += (unsigned) ((Mach_segment_command const *)ptr)->cmdsize;
if ((unsigned)(ptr - (unsigned char const *)mhdr) > ph.u_len) {
throwCantUnpack("cmdsize");
@ -1678,7 +1955,30 @@ bool PackMachBase<T>::canPack()
msegcmd = new Mach_segment_command[ncmds];
unsigned char const *ptr = (unsigned char const *)rawmseg;
for (unsigned j= 0; j < ncmds; ++j) {
msegcmd[j] = *(Mach_segment_command const *)ptr;
if (lc_seg == *(unsigned const *)ptr) {
msegcmd[j] = *(Mach_segment_command const *)ptr;
}
else {
memcpy(&msegcmd[j], ptr, 2*sizeof(unsigned)); // cmd and size
}
switch (((Mach_uuid_command const *)ptr)->cmd) {
default: break;
case Mach_segment_command::LC_UUID: {
memcpy(&cmdUUID, ptr, sizeof(cmdUUID)); // remember the UUID
// Set output UUID to be 1 more than the input UUID.
for (unsigned k = 0; k < sizeof(cmdUUID.uuid); ++k) {
if (0 != ++cmdUUID.uuid[k]) { // no Carry
break;
}
}
} break;
case Mach_segment_command::LC_VERSION_MIN_MACOSX: {
memcpy(&cmdVERMIN, ptr, sizeof(cmdVERMIN));
} break;
case Mach_segment_command::LC_SOURCE_VERSION: {
memcpy(&cmdSRCVER, ptr, sizeof(cmdSRCVER));
} break;
}
if (((Mach_segment_command const *)ptr)->cmd == lc_rout) {
o_routines_cmd = (const char *)ptr - (const char *)rawmseg;
prev_init_address =

View File

@ -47,6 +47,11 @@ __packed_struct(Mach_fat_arch)
BE32 align; /* shift count; log base 2 */
__packed_struct_end()
typedef struct {
uint32_t cmd;
uint32_t cmdsize;
uint32_t data[2]; // because cmdsize >= 16
} Mach_command; // generic prefix
/*************************************************************************
// Mach Mach Object executable; all structures are target-endian
@ -283,11 +288,79 @@ template <class TMachITypes>
__packed_struct(Mach_uuid_command)
typedef typename TMachITypes::Word Word;
Word cmd;
Word cmdsize;
Word cmd; // LC_UUID
Word cmdsize; // 24
unsigned char uuid[16];
__packed_struct_end()
typedef struct {
uint32_t cmd; // LC_MAIN; MH_EXECUTE only
uint32_t cmdsize; // 24
uint64_t entryoff; // file offset of main() [expected in __TEXT]
uint64_t stacksize; // non-default initial stack size
} Mach_main_command;
typedef struct {
uint32_t cmd; // LC_SOURCE_VERSION
uint32_t cmdsize; // 16
uint32_t long version;
} Mach_source_version_command;
typedef struct {
uint32_t cmd; // LC_VERSION_MIN_MACOSX
uint32_t cmdsize; // 16
uint32_t version; // X.Y.Z ==> xxxx.yy.zz
uint32_t sdk; // X.Y.Z ==> xxxx.yy.zz
} Mach_version_min_command;
typedef struct {
uint32_t cmd; // LC_DYLD_INFO_ONLY
uint32_t cmdsize; // 48
uint32_t rebase_off;
uint32_t rebase_size;
uint32_t bind_off;
uint32_t bind_size;
uint32_t weak_bind_off;
uint32_t weak_bind_size;
uint32_t lazy_bind_off;
uint32_t lazy_bind_size;
uint32_t export_off;
uint32_t export_size;
} Mach_dyld_info_only_command;
typedef struct {
uint32_t cmd;
uint32_t cmdsize;
uint32_t name;
} Mach_load_dylinker_command;
typedef struct {
uint32_t name; /* library's path name */
uint32_t timestamp; /* library's build time stamp */
uint32_t current_version; /* library's current version number */
uint32_t compatibility_version; /* library's compatibility vers number*/
} Mach_dylib;
typedef struct {
uint32_t cmd;
uint32_t cmdsize;
Mach_dylib dylib;
} Mach_load_dylib_command;
typedef struct {
uint32_t cmd;
uint32_t cmdsize;
uint32_t dataoff;
uint32_t datasize;
} Mach_function_starts_command;
typedef struct {
uint32_t cmd;
uint32_t cmdsize;
uint32_t dataoff;
uint32_t datasize;
} Mach_data_in_code_command;
template <class TMachITypes>
__packed_struct(Mach_ppc_thread_state)
typedef typename TMachITypes::Addr Addr;
@ -650,7 +723,9 @@ protected:
Mach_section_command secTEXT;
Mach_segment_command segLINK;
Mach_linkedit_data_command linkitem;
Mach_uuid_command uuid_cmd;
Mach_uuid_command cmdUUID; // copied from input, then incremented
N_Mach::Mach_source_version_command cmdSRCVER; // copied from input
N_Mach::Mach_version_min_command cmdVERMIN; // copied from input
__packed_struct(b_info) // 12-byte header before each compressed block
TE32 sz_unc; // uncompressed_size

View File

@ -58,13 +58,17 @@
};
enum { // flags
MH_NOUNDEFS = 1,
MH_DYLDLINK = 4 /* code signing demands this */
MH_DYLDLINK = 4, /* code signing demands this */
MH_BINDATLOAD = 0x8, // DT_BIND_NOW
MH_TWOLEVEL = 0x80,
MH_PIE = 0x200000 // ASLR
};
#endif /*}*/
#ifdef WANT_MACH_SEGMENT_ENUM /*{*/
#undef WANT_MACH_SEGMENT_ENUM
enum { // cmd
LC_REQ_DYLD = 0x80000000, // OR'ed ==> must not ignore
LC_SEGMENT = 0x1,
LC_SYMTAB = 0x2,
LC_THREAD = 0x4,
@ -85,10 +89,12 @@
LC_LAZY_LOAD_DYLIB= 0x20,
LC_ENCRYPTION_INFO= 0x21,
LC_DYLD_INFO = 0x22, // compressed dyld information (10.6.x)
LC_DYLD_INFO_ONLY = (0x22|LC_REQ_DYLD),
LC_VERSION_MIN_MACOSX= 0x24,
LC_FUNCTION_STARTS= 0x26,
LC_MAIN = (0x28|LC_REQ_DYLD),
LC_DATA_IN_CODE = 0x29,
LC_REQ_DYLD = 0x80000000 // OR'ed ==> must not ignore
LC_SOURCE_VERSION = 0x2a,
};
enum { // maxprot
VM_PROT_READ = 1,

View File

@ -51,6 +51,7 @@ ifndef STUBS
STUBS += amd64-darwin.dylib-entry.h
STUBS += amd64-darwin.macho-entry.h
STUBS += amd64-darwin.macho-fold.h
STUBS += amd64-darwin.macho-upxmain.h
STUBS += amd64-linux.elf-entry.h
STUBS += amd64-linux.elf-fold.h
STUBS += amd64-linux.kernel.vmlinux-head.h
@ -307,6 +308,9 @@ amd64-darwin.macho-fold.h : tmp/$$T.o tmp/amd64-darwin.macho-main.o
chmod a-x tmp/$T.bin
$(call tc,bin2h) tmp/$T.bin $@
amd64-darwin.macho-upxmain.h: amd64-darwin.macho-upxmain.exe
$(call tc,bin2h) $< $@
tmp/amd64-darwin.macho-fold.o : $(srcdir)/src/$$T.S
$(call tc,gcc) -c $< -o $@
$(call tc,f-objstrip,$@)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,354 @@
/* amd64-darwin.macho-upxmain.h
created from amd64-darwin.macho-upxmain.exe, 5032 (0x13a8) bytes
This file is part of the UPX executable compressor.
Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2015 Laszlo Molnar
Copyright (C) 2000-2015 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#define STUB_AMD64_DARWIN_MACHO_UPXMAIN_EXE_SIZE 5032
#define STUB_AMD64_DARWIN_MACHO_UPXMAIN_EXE_ADLER32 0x56d6c085
#define STUB_AMD64_DARWIN_MACHO_UPXMAIN_EXE_CRC32 0xefaad113
unsigned char stub_amd64_darwin_macho_upxmain_exe[5032] = {
/* 0x0000 */ 207,250,237,254, 7, 0, 0, 1, 3, 0, 0,128, 2, 0, 0, 0,
/* 0x0010 */ 13, 0, 0, 0,248, 2, 0, 0,133, 0, 0, 0, 0, 0, 0, 0,
/* 0x0020 */ 25, 0, 0, 0, 72, 0, 0, 0, 95, 95, 80, 65, 71, 69, 90, 69,
/* 0x0030 */ 82, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0040 */ 0, 0, 0,240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0050 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0060 */ 0, 0, 0, 0, 0, 0, 0, 0, 25, 0, 0, 0,232, 0, 0, 0,
/* 0x0070 */ 95, 95, 84, 69, 88, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0080 */ 0, 0, 0,240, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0,
/* 0x0090 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0,
/* 0x00a0 */ 7, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
/* 0x00b0 */ 95, 95,116,101,120,116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x00c0 */ 95, 95, 84, 69, 88, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x00d0 */ 253, 8, 0,240, 0, 0, 0, 0,171, 6, 0, 0, 0, 0, 0, 0,
/* 0x00e0 */ 253, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x00f0 */ 0, 4, 0,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0100 */ 95, 95,117,110,119,105,110,100, 95,105,110,102,111, 0, 0, 0,
/* 0x0110 */ 95, 95, 84, 69, 88, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0120 */ 168, 15, 0,240, 0, 0, 0, 0, 88, 0, 0, 0, 0, 0, 0, 0,
/* 0x0130 */ 168, 15, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0140 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0150 */ 25, 0, 0,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 0, 0, 0, 0, 0, 0,
/* 0x0270 */ 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 32, 0, 0, 0,
/* 0x0280 */ 12, 0, 0, 0, 47,117,115,114, 47,108,105, 98, 47,100,121,108,
/* 0x0290 */ 100, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 16, 0, 0, 0,
/* 0x02a0 */ 0, 12, 10, 0, 0, 12, 10, 0, 42, 0, 0, 0, 16, 0, 0, 0,
/* 0x02b0 */ 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0,128, 24, 0, 0, 0,
/* 0x02c0 */ 68, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x02d0 */ 12, 0, 0, 0, 56, 0, 0, 0, 24, 0, 0, 0, 2, 0, 0, 0,
/* 0x02e0 */ 0, 0,214, 4, 0, 0, 1, 0, 47,117,115,114, 47,108,105, 98,
/* 0x02f0 */ 47,108,105, 98, 83,121,115,116,101,109, 46, 66, 46,100,121,108,
/* 0x0300 */ 105, 98, 0, 0, 0, 0, 0, 0, 41, 0, 0, 0, 16, 0, 0, 0,
/* 0x0310 */ 224, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0320 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0330 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0340 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0350 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0360 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0370 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x0380 */ 0, 0, 0, 0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0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x08f0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 72,137,
/* 0x0900 */ 229, 65, 87, 65, 86, 65, 85, 65, 84, 83, 72,131,236, 72, 77,137,
/* 0x0910 */ 205, 76,137,195, 73,137,206, 73,137,212, 72,137,117,208, 72,141,
/* 0x0920 */ 71, 24, 72,137, 69,200, 72,139, 69,208, 72,131,192,232, 72,137,
/* 0x0930 */ 69,192, 76,137,101,184,139, 71, 24, 72,137, 69,176, 72,139, 69,
/* 0x0940 */ 192, 72,139, 77,200, 72,137, 77,168, 72,137, 69,160, 69, 49,255,
/* 0x0950 */ 72,141,125,192, 72,141,117,176, 49,201, 72,137,218,232, 27, 1,
/* 0x0960 */ 0, 0, 76,137, 44, 36, 72,141, 85,160,190, 0, 0, 0, 0,185,
/* 0x0970 */ 255,255,255,255, 76,137,231, 76,139, 69, 16, 73,137,217,232, 16,
/* 0x0980 */ 2, 0, 0, 72,137,195, 65,139, 76, 36, 16,133,201, 15,132,216,
/* 0x0990 */ 0, 0, 0, 73,141, 68, 36, 32,131, 56, 14,116, 19, 65,255,199,
/* 0x09a0 */ 139, 80, 4, 72, 1,208, 65, 57,207,114,237,233,187, 0, 0, 0,
/* 0x09b0 */ 139,120, 8, 72, 1,199, 49,246, 49,210,232,203, 5, 0, 0, 65,
/* 0x09c0 */ 137,199, 69,133,255,120,113, 77,141,108, 36, 16, 49,219, 68,137,
/* 0x09d0 */ 255, 76,137,230, 76,137,242, 72,137,217,232,163, 5, 0, 0, 76,
/* 0x09e0 */ 57,240,117, 84, 65,139, 4, 36, 61,190,186,254,202,116, 7, 61,
/* 0x09f0 */ 202,254,186,190,117, 76, 65, 15,182, 68, 36, 7,141, 4,128,141,
/* 0x0a00 */ 52,133, 8, 0, 0, 0, 76,137,231,232, 76, 5, 0, 0, 65,139,
/* 0x0a10 */ 68, 36, 4, 49,201,133,192, 76,137,234,116, 28,129,122,248, 7,
/* 0x0a20 */ 0, 0, 1,116, 12,255,193, 72,131,194, 20, 57,193,114,237,235,
/* 0x0a30 */ 7,139, 26, 72,133,219,117,150,191,127, 0, 0, 0,232, 52, 5,
/* 0x0a40 */ 0, 0, 72,199, 4, 36, 0, 0, 0, 0, 49,210, 69, 49,192, 69,
/* 0x0a50 */ 49,201, 76,137,231, 72,137,222, 68,137,249,232, 51, 1, 0, 0,
/* 0x0a60 */ 72,137,195, 68,137,255,232, 27, 5, 0, 0, 72,137,216, 72,131,
/* 0x0a70 */ 196, 72, 91, 65, 92, 65, 93, 65, 94, 65, 95, 93,195, 85, 72,137,
/* 0x0a80 */ 229, 65, 87, 65, 86, 65, 85, 65, 84, 83, 72,131,236, 56, 72,137,
/* 0x0a90 */ 77,176, 72,137, 85,168, 73,137,246, 72,137,125,184, 73,131, 62,
/* 0x0aa0 */ 0, 15,132,211, 0, 0, 0, 76,141,101,200,186, 12, 0, 0, 0,
/* 0x0ab0 */ 72,139,125,184, 76,137,230,232, 84, 4, 0, 0, 68,139,109,200,
/* 0x0ac0 */ 68,139,125,204, 77,133,237, 15,132,154, 0, 0, 0, 65,141, 71,
/* 0x0ad0 */ 255, 68, 57,232, 15,131,175, 0, 0, 0, 77, 59, 46, 15,135,166,
/* 0x0ae0 */ 0, 0, 0, 69, 57,239,115, 90, 68,137,109,196, 72,139, 69,184,
/* 0x0af0 */ 72,139,120, 8, 73,139, 86, 8,139, 93,208, 68, 15,182,195, 68,
/* 0x0b00 */ 137,254, 72,141, 77,196,255, 85,168,133,192,117,124, 68, 57,109,
/* 0x0b10 */ 196,117,118, 72,131,125,176, 0,116, 27, 15,182,199,102,133,192,
/* 0x0b20 */ 116, 19,193,235, 16, 15,183,200, 73,139,126, 8, 15,182,211, 68,
/* 0x0b30 */ 137,238,255, 85,176, 72,139, 69,184, 76, 1,120, 8, 76, 41, 56,
/* 0x0b40 */ 235, 16, 73,139,118, 8, 72,139,125,184, 76,137,250,232,190, 3,
/* 0x0b50 */ 0, 0, 77, 1,110, 8, 73,139, 6, 76, 41,232, 73,137, 6, 15,
/* 0x0b60 */ 133, 70,255,255,255,235, 19, 65,129,255, 85, 80, 88, 33,117, 25,
/* 0x0b70 */ 72,139, 69,184, 72,131, 56, 0,117, 15, 72,131,196, 56, 91, 65,
/* 0x0b80 */ 92, 65, 93, 65, 94, 65, 95, 93,195,191,127, 0, 0, 0,232,227,
/* 0x0b90 */ 3, 0, 0, 85, 72,137,229, 65, 87, 65, 86, 65, 85, 65, 84, 83,
/* 0x0ba0 */ 72,131,236,120, 76,137,141,112,255,255,255, 76,137,133,104,255,
/* 0x0bb0 */ 255,255,137, 77,140, 72,137, 85,192, 72,137,117,128, 72,137,125,
/* 0x0bc0 */ 144,139, 95, 16, 69, 49,255,133,219,184, 0, 0, 0, 0, 15,132,
/* 0x0bd0 */ 87, 2, 0, 0, 72,139, 77,144, 76,141,105, 32, 72,131,125,192,
/* 0x0be0 */ 0, 15,149,193, 15,182,201, 72,141, 12, 73, 72,137,141,120,255,
/* 0x0bf0 */ 255,255, 72,191, 4, 0, 0, 0, 42, 0, 0, 0, 69, 49,201, 49,
/* 0x0c00 */ 192, 69, 49,192, 73,139, 85, 0, 72,137,209, 72,193,233, 32,141,
/* 0x0c10 */ 114,252,131,254, 2, 15,130,205, 0, 0, 0,129,250, 40, 0, 0,
/* 0x0c20 */ 128, 15,132,218, 0, 0, 0,131,250, 25, 15,133,234, 1, 0, 0,
/* 0x0c30 */ 73,139, 85, 32, 72,133,210, 15,132,221, 1, 0, 0, 72,137, 85,
/* 0x0c40 */ 168, 76,137, 77,184, 72,137, 69,160, 73,139, 69, 48, 72,137, 69,
/* 0x0c50 */ 200, 77,139,101, 24, 77, 1,196, 76,137,101,176, 76,137,101,208,
/* 0x0c60 */ 69,137,230, 65,129,230,255, 15, 0, 0, 77, 41,244, 73, 1,198,
/* 0x0c70 */ 76,137,195, 15,132,169, 0, 0, 0, 72,139,141,120,255,255,255,
/* 0x0c80 */ 73,141, 52, 14, 77,133,228,186, 2, 0, 0, 0,185, 18, 0, 0,
/* 0x0c90 */ 0, 15, 69,209, 72,133,192, 15,148,193, 15,182,201,193,225, 12,
/* 0x0ca0 */ 72,131,125,192, 0,191, 0, 16, 0, 0, 15, 69,207, 9,209, 72,
/* 0x0cb0 */ 131,248, 1, 69, 25,192, 68, 11, 69,140, 77,139, 77, 40, 76, 3,
/* 0x0cc0 */ 77,128,186, 3, 0, 0, 0, 76,137,231,232,191, 2, 0, 0, 77,
/* 0x0cd0 */ 133,228, 72, 15, 68,216, 72,137, 93,152, 72,131,248,255, 73,137,
/* 0x0ce0 */ 196,117, 67,233, 82, 1, 0, 0, 73, 57,125, 8, 15,133, 40, 1,
/* 0x0cf0 */ 0, 0, 73,139,133,144, 0, 0, 0, 76, 1,192,233, 25, 1, 0,
/* 0x0d00 */ 0, 73,139, 69, 8, 73, 57, 65, 40, 15,135, 11, 1, 0, 0, 73,
/* 0x0d10 */ 59, 65, 48, 15,131, 1, 1, 0, 0, 73, 3, 65, 24,233,248, 0,
/* 0x0d20 */ 0, 0, 72,137, 93,152, 72,131,125,192, 0,116, 52, 73,131,125,
/* 0x0d30 */ 48, 0,116, 45, 73,131,125, 40, 0,117, 14, 72,139,133,104,255,
/* 0x0d40 */ 255,255, 76,137, 32, 76,137,109,184, 72,139,125,192, 72,141,117,
/* 0x0d50 */ 200, 72,139,149,112,255,255,255, 72,139, 77, 16,232, 28,253,255,
/* 0x0d60 */ 255, 68,137,243,247,219, 72,129,227,255, 15, 0, 0,116, 12, 75,
/* 0x0d70 */ 141, 60, 52, 72,137,222,232,240, 1, 0, 0, 77,133,246,116, 23,
/* 0x0d80 */ 65,139, 85, 60, 76,137,231, 76,137,246,232,235, 1, 0, 0,133,
/* 0x0d90 */ 192, 15,133,163, 0, 0, 0, 72,139, 69,176, 72, 3, 69,168, 76,
/* 0x0da0 */ 1,243, 73, 1,220, 73, 57,196,115, 44, 77,133,228,116, 74, 72,
/* 0x0db0 */ 137,198, 76, 41,230, 65,139, 85, 60,185, 18, 16, 0, 0, 65,184,
/* 0x0dc0 */ 255,255,255,255, 69, 49,201, 76,137,231,232,191, 1, 0, 0, 73,
/* 0x0dd0 */ 57,196,116, 37,235,100, 72,131,125,192, 0,116, 28, 65,131,198,
/* 0x0de0 */ 3, 65,129,230,255, 15, 0, 0, 73,131,254, 3,119, 11, 76,137,
/* 0x0df0 */ 231, 76,137,246,232,133, 1, 0, 0, 65,139, 77, 4, 72,139, 69,
/* 0x0e00 */ 144,139, 88, 16, 72,191, 4, 0, 0, 0, 42, 0, 0, 0, 72,139,
/* 0x0e10 */ 69,160, 76,139, 69,152, 76,139, 77,184, 65,255,199,137,201, 73,
/* 0x0e20 */ 1,205, 65, 57,223, 15,130,217,253,255,255, 72,131,196,120, 91,
/* 0x0e30 */ 65, 92, 65, 93, 65, 94, 65, 95, 93,195,191,127, 0, 0, 0,232,
/* 0x0e40 */ 50, 1, 0, 0, 85, 72,137,229, 65, 87, 65, 86, 65, 85, 65, 84,
/* 0x0e50 */ 83, 72,129,236, 24, 8, 0, 0, 68,139,109, 8, 76,141,101, 16,
/* 0x0e60 */ 72,141, 5,221,255,255,255, 72, 37, 0, 0,255,255,139, 72, 16,
/* 0x0e70 */ 133,201,116, 72, 72,131,200, 32, 49,210, 72,190, 76, 73, 78, 75,
/* 0x0e80 */ 69, 68, 73, 84,131, 56, 25,117, 6, 72, 57,112, 10,116, 14,255,
/* 0x0e90 */ 194,139,120, 4, 72, 1,248, 57,202,114,233,235, 31, 72,139, 88,
/* 0x0ea0 */ 24, 68, 15,183, 3, 73, 1,216, 76,141, 75, 2, 68,139,115,252,
/* 0x0eb0 */ 72,131,195,252, 77,133,246,116,243, 76, 41,243, 76,137,224, 72,
/* 0x0ec0 */ 131,192,240, 72,137, 4, 36, 72,141,149,208,247,255,255,185, 0,
/* 0x0ed0 */ 8, 0, 0, 72,137,223, 76,137,246,232, 31,250,255,255, 73,137,
/* 0x0ee0 */ 199, 72,137,223, 76,137,246,232,146, 0, 0, 0, 73, 99,197, 73,
/* 0x0ef0 */ 137, 68, 36,248, 73,141,100, 36,240, 65,255,231, 49,192, 72,129,
/* 0x0f00 */ 196, 24, 8, 0, 0, 91, 65, 92, 65, 93, 65, 94, 65, 95, 93,195,
/* 0x0f10 */ 72,139, 15, 72, 57,209,114, 52, 72,139, 71, 8, 72,133,210,116,
/* 0x0f20 */ 29, 72,137,209, 72,255,201, 68,138, 0, 72,141, 64, 1, 68,136,
/* 0x0f30 */ 6, 72,141,118, 1,117,237, 72,139, 15, 72,139, 71, 8, 72, 1,
/* 0x0f40 */ 208, 72,137, 71, 8, 72, 41,209, 72,137, 15,195, 85, 72,137,229,
/* 0x0f50 */ 191,127, 0, 0, 0,232, 28, 0, 0, 0,139, 7, 15,200,137, 7,
/* 0x0f60 */ 72,131,238, 4, 72,141,127, 4,119,240,195, 49,192,137,241,243,
/* 0x0f70 */ 170,195,176, 4,235, 2,176, 1,235, 2,176, 74,235, 2,176, 73,
/* 0x0f80 */ 235, 2,176,153,235, 2,176, 6,235, 2,176, 5,235, 2,176,197,
/* 0x0f90 */ 235, 2,176, 3, 15,182,192, 13, 0, 0, 0, 2, 73,137,202, 15,
/* 0x0fa0 */ 5,115, 4, 72,131,200,255,195, 1, 0, 0, 0, 28, 0, 0, 0,
/* 0x0fb0 */ 0, 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 28, 0, 0, 0,
/* 0x0fc0 */ 2, 0, 0, 0,253, 8, 0, 0, 52, 0, 0, 0, 52, 0, 0, 0,
/* 0x0fd0 */ 169, 15, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, 3, 0, 0, 0,
/* 0x0fe0 */ 12, 0, 3, 0, 24, 0, 3, 0, 0, 0, 0, 2, 19, 6, 0, 1,
/* 0x0ff0 */ 93, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,209, 88, 5, 1,
/* 0x1000 */ 0, 1, 95, 0, 5, 0, 10, 95, 0, 72,117,112,120, 95,109, 97,
/* 0x1010 */ 105,110, 0,106,109, 0,111, 98, 0,148, 1,119,114,105,116,101,
/* 0x1020 */ 0,179, 1,101,120,105,116, 0,184, 1,112,114,101, 97,100, 0,
/* 0x1030 */ 199, 1, 99,108,111,115,101, 0,204, 1,111,112,101,110, 0,209,
/* 0x1040 */ 1,114,101, 97,100, 0,219, 1, 0, 2,109,104, 95,101,120,101,
/* 0x1050 */ 99,117,116,101, 95,104,101, 97,100,101,114, 0,102, 95, 98,122,
/* 0x1060 */ 101,114,111, 0,169, 1, 2, 0, 0, 0, 3, 0,253, 17, 0, 0,
/* 0x1070 */ 4, 97,105,110, 0,143, 1,112,114,111,116,101, 99,116, 0,189,
/* 0x1080 */ 1,117,110,109, 97,112, 0,194, 1,109, 97,112, 0,214, 1, 3,
/* 0x1090 */ 0,196, 28, 0, 0, 2,115,119, 97,112, 0,164, 1,122,101,114,
/* 0x10a0 */ 111, 0,174, 1, 3, 0,218, 30, 0, 3, 0,235, 30, 0, 3, 0,
/* 0x10b0 */ 235, 30, 0, 3, 0,242, 30, 0, 3, 0,246, 30, 0, 3, 0,250,
/* 0x10c0 */ 30, 0, 3, 0,254, 30, 0, 3, 0,130, 31, 0, 3, 0,134, 31,
/* 0x10d0 */ 0, 3, 0,138, 31, 0, 3, 0,142, 31, 0, 3, 0,146, 31, 0,
/* 0x10e0 */ 141, 0, 0, 0, 14, 1, 0, 0,125, 10, 0,240, 0, 0, 0, 0,
/* 0x10f0 */ 155, 0, 0, 0, 14, 1, 0, 0,147, 11, 0,240, 0, 0, 0, 0,
/* 0x1100 */ 164, 0, 0, 0, 14, 1, 0, 0, 16, 15, 0,240, 0, 0, 0, 0,
/* 0x1110 */ 171, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
/* 0x1120 */ 180, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0,
/* 0x1130 */ 189, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0,
/* 0x1140 */ 199, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
/* 0x1150 */ 208, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0,
/* 0x1160 */ 218, 0, 0, 0, 2, 0, 0, 0, 73, 0, 0, 0, 0, 0, 0, 0,
/* 0x1170 */ 229, 0, 0, 0, 2, 0, 0, 0, 74, 0, 0, 0, 0, 0, 0, 0,
/* 0x1180 */ 242, 0, 0, 0, 2, 0, 0, 0,153, 0, 0, 0, 0, 0, 0, 0,
/* 0x1190 */ 252, 0, 0, 0, 2, 0, 0, 0,197, 0, 0, 0, 0, 0, 0, 0,
/* 0x11a0 */ 2, 0, 0, 0, 15, 1, 0, 0,107, 15, 0,240, 0, 0, 0, 0,
/* 0x11b0 */ 11, 0, 0, 0, 3, 1, 16, 0, 0, 0, 0,240, 0, 0, 0, 0,
/* 0x11c0 */ 31, 0, 0, 0, 15, 1, 0, 0, 90, 15, 0,240, 0, 0, 0, 0,
/* 0x11d0 */ 38, 0, 0, 0, 15, 1, 0, 0,107, 15, 0,240, 0, 0, 0, 0,
/* 0x11e0 */ 45, 0, 0, 0, 15, 1, 0, 0,134, 15, 0,240, 0, 0, 0, 0,
/* 0x11f0 */ 52, 0, 0, 0, 15, 1, 0, 0,118, 15, 0,240, 0, 0, 0, 0,
/* 0x1200 */ 58, 0, 0, 0, 15, 1, 0, 0, 68, 14, 0,240, 0, 0, 0, 0,
/* 0x1210 */ 64, 0, 0, 0, 15, 1, 0, 0,142, 15, 0,240, 0, 0, 0, 0,
/* 0x1220 */ 70, 0, 0, 0, 15, 1, 0, 0,122, 15, 0,240, 0, 0, 0, 0,
/* 0x1230 */ 80, 0, 0, 0, 15, 1, 0, 0,126, 15, 0,240, 0, 0, 0, 0,
/* 0x1240 */ 88, 0, 0, 0, 15, 1, 0, 0,138, 15, 0,240, 0, 0, 0, 0,
/* 0x1250 */ 94, 0, 0, 0, 15, 1, 0, 0,130, 15, 0,240, 0, 0, 0, 0,
/* 0x1260 */ 101, 0, 0, 0, 15, 1, 0, 0,146, 15, 0,240, 0, 0, 0, 0,
/* 0x1270 */ 107, 0, 0, 0, 15, 1, 0, 0,253, 8, 0,240, 0, 0, 0, 0,
/* 0x1280 */ 117, 0, 0, 0, 15, 1, 0, 0,114, 15, 0,240, 0, 0, 0, 0,
/* 0x1290 */ 124, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x12a0 */ 32, 0, 95, 95, 95, 98,122,101,114,111, 0, 95, 95,109,104, 95,
/* 0x12b0 */ 101,120,101, 99,117,116,101, 95,104,101, 97,100,101,114, 0, 95,
/* 0x12c0 */ 98,115,119, 97,112, 0, 95, 98,122,101,114,111, 0, 95, 99,108,
/* 0x12d0 */ 111,115,101, 0, 95,101,120,105,116, 0, 95,109, 97,105,110, 0,
/* 0x12e0 */ 95,109,109, 97,112, 0, 95,109,112,114,111,116,101, 99,116, 0,
/* 0x12f0 */ 95,109,117,110,109, 97,112, 0, 95,111,112,101,110, 0, 95,112,
/* 0x1300 */ 114,101, 97,100, 0, 95,114,101, 97,100, 0, 95,117,112,120, 95,
/* 0x1310 */ 109, 97,105,110, 0, 95,119,114,105,116,101, 0,100,121,108,100,
/* 0x1320 */ 95,115,116,117, 98, 95, 98,105,110,100,101,114, 0, 95,117,110,
/* 0x1330 */ 112, 97, 99,107, 69,120,116,101,110,116, 0, 95,100,111, 95,120,
/* 0x1340 */ 109, 97,112, 0, 95,120,114,101, 97,100, 0, 83, 89, 83, 95,101,
/* 0x1350 */ 120,105,116, 0, 83, 89, 83, 95,114,101, 97,100, 0, 83, 89, 83,
/* 0x1360 */ 95,119,114,105,116,101, 0, 83, 89, 83, 95,111,112,101,110, 0,
/* 0x1370 */ 83, 89, 83, 95, 99,108,111,115,101, 0, 83, 89, 83, 95,109,117,
/* 0x1380 */ 110,109, 97,112, 0, 83, 89, 83, 95,109,112,114,111,116,101, 99,
/* 0x1390 */ 116, 0, 83, 89, 83, 95,112,114,101, 97,100, 0, 83, 89, 83, 95,
/* 0x13a0 */ 109,109, 97,112, 0, 0, 0, 0
};

View File

@ -40,12 +40,18 @@
// see glibc/sysdeps/amd64/elf/start.S
**************************************************************************/
section AMD64BXX
0: .word 9f - 0b
#include "arch/amd64/bxx.S"
9:
section MACHMAINX
_start: .globl _start
// int3
call main // push &decompress
ret_main:
section MACH_UNC
/* Returns 0 on success; non-zero on failure. */
decompress: // (uchar const *src, size_t lsrc, uchar *dst, u32 &ldst, uint method)
@ -136,7 +142,7 @@ copy4:
movl %edx,(%rdi); leaq 4(%rdi),%rdi; jnc copy4
addl $4,len; movb (%rax),%dl; jz copy0
copy1:
incq %rax; movb %dl,(%rdi); subl $1,len
addq $1,%rax; movb %dl,(%rdi); subl $1,len
movb (%rax),%dl
leaq 1(%rdi),%rdi; jnz copy1
copy0:

View File

@ -423,6 +423,13 @@ typedef struct {
VM_PROT_EXECUTE = 4
};
typedef struct {
uint32_t cmd; // LC_MAIN; MH_EXECUTE only
uint32_t cmdsize; // 24
uint64_t entryoff; // file offset of main() [expected in __TEXT]
uint64_t stacksize; // non-default initial stack size
} Mach_main_command;
typedef struct {
uint64_t rax, rbx, rcx, rdx;
uint64_t rdi, rsi, rbp, rsp;
@ -538,7 +545,7 @@ ERR_LAB
else if (xi) { // cleanup if decompressor overrun crosses page boundary
mlen = ~PAGE_MASK & (3+ mlen);
if (mlen<=3) { // page fragment was overrun buffer only
munmap(addr, mlen);
munmap((char *)addr, mlen);
}
}
}

View File

@ -0,0 +1 @@
*

View File

@ -0,0 +1,754 @@
/* amd64-darwin.macho-upxmain.c -- loader hack for Mach-o AMD64
This file is part of the UPX executable compressor.
Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2015 Laszlo Molnar
Copyright (C) 2000-2015 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
John F. Reiser
<jreiser@users.sourceforge.net>
*/
#include <stdio.h>
#include <stdlib.h>
#include "include/darwin.h"
#ifndef DEBUG /*{*/
#define DEBUG 0
#endif /*}*/
/*************************************************************************
// configuration section
**************************************************************************/
// In order to make it much easier to move this code at runtime and execute
// it at an address different from it load address: there must be no
// static data, and no string constants.
#if !DEBUG /*{*/
#define DPRINTF(a) /* empty: no debug drivel */
#define DEBUG_STRCON(name, value) /* empty */
#else /*}{ DEBUG */
extern int write(int, void const *, size_t);
#if 0
#include "stdarg.h"
#else
#define va_arg __builtin_va_arg
#define va_end __builtin_va_end
#define va_list __builtin_va_list
#define va_start __builtin_va_start
#endif
#if defined(__i386__) || defined(__x86_64__) /*{*/
#define PIC_STRING(value, var) \
__asm__ __volatile__ ( \
"call 0f; .asciz \"" value "\"; \
0: pop %0;" : "=r"(var) : \
)
#elif defined(__arm__) /*}{*/
#define PIC_STRING(value, var) \
__asm__ __volatile__ ( \
"mov %0,pc; b 0f; \
.asciz \"" value "\"; .balign 4; \
0: " : "=r"(var) \
)
#elif defined(__mips__) /*}{*/
#define PIC_STRING(value, var) \
__asm__ __volatile__ ( \
".set noreorder; bal 0f; move %0,$31; .set reorder; \
.asciz \"" value "\"; .balign 4; \
0: " \
: "=r"(var) : : "ra" \
)
#endif /*}*/
#define DEBUG_STRCON(name, strcon) \
static char const *name(void) { \
register char const *rv; PIC_STRING(strcon, rv); \
return rv; \
}
#ifdef __arm__ /*{*/
extern unsigned div10(unsigned);
#else /*}{*/
static unsigned
div10(unsigned x)
{
return x / 10u;
}
#endif /*}*/
static int
unsimal(unsigned x, char *ptr, int n)
{
if (10<=x) {
unsigned const q = div10(x);
x -= 10 * q;
n = unsimal(q, ptr, n);
}
ptr[n] = '0' + x;
return 1+ n;
}
static int
decimal(int x, char *ptr, int n)
{
if (x < 0) {
x = -x;
ptr[n++] = '-';
}
return unsimal(x, ptr, n);
}
DEBUG_STRCON(STR_hex, "0123456789abcdef");
static int
heximal(unsigned long x, char *ptr, int n)
{
if (16<=x) {
n = heximal(x>>4, ptr, n);
x &= 0xf;
}
ptr[n] = STR_hex()[x];
return 1+ n;
}
#define DPRINTF(a) my_printf a
static int
my_printf(char const *fmt, ...)
{
char c;
int n= 0;
char *ptr;
char buf[20];
va_list va; va_start(va, fmt);
ptr= &buf[0];
while (0!=(c= *fmt++)) if ('%'!=c) goto literal;
else switch (c= *fmt++) {
default: {
literal:
n+= write(2, fmt-1, 1);
} break;
case 0: goto done; /* early */
case 'u': {
n+= write(2, buf, unsimal(va_arg(va, unsigned), buf, 0));
} break;
case 'd': {
n+= write(2, buf, decimal(va_arg(va, int), buf, 0));
} break;
case 'p': {
buf[0] = '0';
buf[1] = 'x';
n+= write(2, buf, heximal((unsigned long)va_arg(va, void *), buf, 2));
} break;
case 'x': {
buf[0] = '0';
buf[1] = 'x';
n+= write(2, buf, heximal(va_arg(va, int), buf, 2));
} break;
}
done:
va_end(va);
return n;
}
#endif /*}*/
/*************************************************************************
// "file" util
**************************************************************************/
typedef struct {
size_t size; // must be first to match size[0] uncompressed size
void *buf;
} Extent;
DEBUG_STRCON(STR_xread, "xread %%p(%%x %%p) %%p %%x\\n")
DEBUG_STRCON(STR_xreadfail, "xreadfail %%p(%%x %%p) %%p %%x\\n")
static void
xread(Extent *x, void *buf, size_t count)
{
unsigned char *p=x->buf, *q=buf;
size_t j;
DPRINTF((STR_xread(), x, x->size, x->buf, buf, count));
if (x->size < count) {
DPRINTF((STR_xreadfail(), x, x->size, x->buf, buf, count));
exit(127);
}
for (j = count; 0!=j--; ++p, ++q) {
*q = *p;
}
x->buf += count;
x->size -= count;
}
/*************************************************************************
// util
**************************************************************************/
#if 1 //{ save space
#define ERR_LAB error: exit(127);
#define err_exit(a) goto error
#else //}{ save debugging time
#define ERR_LAB /*empty*/
DEBUG_STRCON(STR_exit, "err_exit %%x\\n");
static void
err_exit(int a)
{
DPRINTF((STR_exit(), a));
(void)a; // debugging convenience
exit(127);
}
#endif //}
/*************************************************************************
// UPX & NRV stuff
**************************************************************************/
struct l_info { // 12-byte trailer for loader (after macho headers)
unsigned l_checksum;
unsigned l_magic; // UPX_MAGIC_LE32
unsigned short l_lsize;
unsigned char l_version;
unsigned char l_format;
};
struct p_info { // 12-byte packed program header
unsigned p_progid;
unsigned p_filesize;
unsigned p_blocksize;
};
struct b_info { // 12-byte header before each compressed block
unsigned sz_unc; // uncompressed_size
unsigned sz_cpr; // compressed_size
unsigned char b_method; // compression algorithm
unsigned char b_ftid; // filter id
unsigned char b_cto8; // filter parameter
unsigned char b_unused;
};
typedef void f_unfilter(
nrv_byte *, // also addvalue
nrv_uint,
unsigned cto8, // junk in high 24 bits
unsigned ftid
);
typedef int f_expand(
const nrv_byte *, nrv_uint,
nrv_byte *, nrv_uint *, unsigned );
DEBUG_STRCON(STR_unpackExtent,
"unpackExtent in=%%p(%%x %%p) out=%%p(%%x %%p) %%p %%p\\n");
DEBUG_STRCON(STR_err5, "sz_cpr=%%x sz_unc=%%x xo->size=%%x\\n");
static void
unpackExtent(
Extent *const xi, // input
Extent *const xo, // output
f_expand *const f_decompress,
f_unfilter *f_unf
)
{
DPRINTF((STR_unpackExtent(),
xi, xi->size, xi->buf, xo, xo->size, xo->buf, f_decompress, f_unf));
while (xo->size) {
struct b_info h;
// Note: if h.sz_unc == h.sz_cpr then the block was not
// compressible and is stored in its uncompressed form.
// Read and check block sizes.
xread(xi, (unsigned char *)&h, sizeof(h));
if (h.sz_unc == 0) { // uncompressed size 0 -> EOF
if (h.sz_cpr != UPX_MAGIC_LE32) // h.sz_cpr must be h->magic
err_exit(2);
if (xi->size != 0) // all bytes must be written
err_exit(3);
break;
}
if (h.sz_cpr <= 0) {
err_exit(4);
ERR_LAB
}
if (h.sz_cpr > h.sz_unc
|| h.sz_unc > xo->size ) {
DPRINTF((STR_err5(), h.sz_cpr, h.sz_unc, xo->size));
err_exit(5);
}
// Now we have:
// assert(h.sz_cpr <= h.sz_unc);
// assert(h.sz_unc > 0 && h.sz_unc <= blocksize);
// assert(h.sz_cpr > 0 && h.sz_cpr <= blocksize);
if (h.sz_cpr < h.sz_unc) { // Decompress block
nrv_uint out_len = h.sz_unc; // EOF for lzma
int const j = (*f_decompress)(xi->buf, h.sz_cpr,
xo->buf, &out_len, h.b_method);
if (j != 0 || out_len != (nrv_uint)h.sz_unc)
err_exit(7);
if (h.b_ftid!=0 && f_unf) { // have filter
(*f_unf)(xo->buf, out_len, h.b_cto8, h.b_ftid);
}
xi->buf += h.sz_cpr;
xi->size -= h.sz_cpr;
}
else { // copy literal block
xread(xi, xo->buf, h.sz_cpr);
}
xo->buf += h.sz_unc;
xo->size -= h.sz_unc;
}
}
static void
upx_bzero(unsigned char *p, size_t len)
{
if (len) do {
*p++= 0;
} while (--len);
}
#define bzero upx_bzero
// The PF_* and PROT_* bits are {1,2,4}; the conversion table fits in 32 bits.
#define REP8(x) \
((x)|((x)<<4)|((x)<<8)|((x)<<12)|((x)<<16)|((x)<<20)|((x)<<24)|((x)<<28))
#define EXP8(y) \
((1&(y)) ? 0xf0f0f0f0 : (2&(y)) ? 0xff00ff00 : (4&(y)) ? 0xffff0000 : 0)
#define PF_TO_PROT(pf) \
((PROT_READ|PROT_WRITE|PROT_EXEC) & ( \
( (REP8(PROT_EXEC ) & EXP8(PF_X)) \
|(REP8(PROT_READ ) & EXP8(PF_R)) \
|(REP8(PROT_WRITE) & EXP8(PF_W)) \
) >> ((pf & (PF_R|PF_W|PF_X))<<2) ))
typedef struct {
unsigned magic;
unsigned nfat_arch;
} Fat_header;
typedef struct {
unsigned cputype;
unsigned cpusubtype;
unsigned offset;
unsigned size;
unsigned align; /* shift count (log base 2) */
} Fat_arch;
enum e8 {
FAT_MAGIC = 0xcafebabe,
FAT_CIGAM = 0xbebafeca
};
enum e9 {
CPU_TYPE_I386 = 7,
CPU_TYPE_AMD64 = 0x01000007,
CPU_TYPE_ARM = 12,
CPU_TYPE_POWERPC = 0x00000012,
CPU_TYPE_POWERPC64 = 0x01000012
};
typedef struct {
unsigned magic;
unsigned cputype;
unsigned cpysubtype;
unsigned filetype;
unsigned ncmds;
unsigned sizeofcmds;
unsigned flags;
unsigned reserved;
} Mach_header64;
enum e0 {
MH_MAGIC = 0xfeedface,
MH_MAGIC64 = 1+0xfeedface
};
enum e2 {
MH_EXECUTE = 2
};
enum e3 {
MH_NOUNDEFS = 1
};
typedef struct {
unsigned cmd;
unsigned cmdsize;
} Mach_load_command;
enum e4 {
LC_REQ_DYLD = 0x80000000, // OR'ed ==> must not ignore
LC_SEGMENT = 0x1,
LC_SEGMENT_64 = 0x19,
LC_THREAD = 0x4,
LC_UNIXTHREAD = 0x5,
LC_LOAD_DYLINKER = 0xe,
LC_MAIN = (0x28|LC_REQ_DYLD)
};
typedef struct {
unsigned cmd;
unsigned cmdsize;
char segname[16];
uint64_t vmaddr;
uint64_t vmsize;
uint64_t fileoff;
uint64_t filesize;
unsigned maxprot;
unsigned initprot;
unsigned nsects;
unsigned flags;
} Mach_segment_command;
enum e5 {
VM_PROT_READ = 1,
VM_PROT_WRITE = 2,
VM_PROT_EXECUTE = 4
};
typedef struct {
char sectname[16];
char segname[16];
uint64_t addr; /* memory address */
uint64_t size; /* size in bytes */
unsigned offset; /* file offset */
unsigned align; /* power of 2 */
unsigned reloff; /* file offset of relocation entries */
unsigned nreloc; /* number of relocation entries */
unsigned flags; /* section type and attributes */
unsigned reserved1; /* for offset or index */
unsigned reserved2; /* for count or sizeof */
} Mach_section_command;
typedef struct {
uint32_t cmd; // LC_MAIN; MH_EXECUTE only
uint32_t cmdsize; // 24
uint64_t entryoff; // file offset of main() [expected in __TEXT]
uint64_t stacksize; // non-default initial stack size
} Mach_main_command;
typedef struct {
uint64_t rax, rbx, rcx, rdx;
uint64_t rdi, rsi, rbp, rsp;
uint64_t r8, r9, r10, r11;
uint64_t r12, r13, r14, r15;
uint64_t rip, rflags;
uint64_t cs, fs, gs;
} Mach_AMD64_thread_state;
typedef struct {
unsigned cmd; /* LC_THREAD or LC_UNIXTHREAD */
unsigned cmdsize; /* total size of this command */
unsigned flavor;
unsigned count; /* sizeof(following_thread_state)/4 */
Mach_AMD64_thread_state state;
} Mach_thread_command;
enum e6 {
AMD64_THREAD_STATE = 4 // x86_THREAD_STATE64
};
enum e7 {
AMD64_THREAD_STATE_COUNT = sizeof(Mach_AMD64_thread_state)/4
};
typedef union {
unsigned offset; /* from start of load command to string */
} Mach_lc_str;
#define MAP_FIXED 0x10
#define MAP_PRIVATE 0x02
#define MAP_ANON 0x1000
//#define MAP_ANON 0x20 // x86 DEBUG ONLY
#define PROT_READ 1
#define PROT_WRITE 2
#define PROT_EXEC 4
#define MAP_ANON_FD -1
#define MAP_FAILED ((void *) -1)
extern void *mmap(void *, size_t, unsigned, unsigned, int, off_t);
ssize_t pread(int, void *, size_t, off_t);
extern void bswap(void *, unsigned);
DEBUG_STRCON(STR_mmap,
"mmap addr=%%p len=%%p prot=%%x flags=%%x fd=%%d off=%%p\\n");
DEBUG_STRCON(STR_do_xmap,
"do_xmap fdi=%%x mhdr=%%p xi=%%p(%%x %%p) f_unf=%%p\\n")
static uint64_t // entry address
do_xmap(
Mach_header64 const *const mhdr,
off_t const fat_offset,
Extent *const xi,
int const fdi,
Mach_header64 **mhdrpp,
f_expand *const f_decompress,
f_unfilter *const f_unf
)
{
Mach_segment_command const *sc = (Mach_segment_command const *)(1+ mhdr);
Mach_segment_command const *segTEXT = 0;
uint64_t entry = 0;
unsigned long base = 0;
unsigned j;
DPRINTF((STR_do_xmap(),
fdi, mhdr, xi, (xi? xi->size: 0), (xi? xi->buf: 0), f_unf));
for ( j=0; j < mhdr->ncmds; ++j,
(sc = (Mach_segment_command const *)(sc->cmdsize + (void const *)sc))
) if (LC_SEGMENT_64==sc->cmd && sc->vmsize!=0) {
Extent xo;
size_t mlen = xo.size = sc->filesize;
unsigned char *addr = xo.buf = base + (unsigned char *)sc->vmaddr;
unsigned char *haddr = sc->vmsize + addr;
size_t frag = (int)(uint64_t)addr &~ PAGE_MASK;
addr -= frag;
mlen += frag;
if (0!=mlen) { // In particular, omitted for __PAGEZERO
// Decompressor can overrun the destination by 3 bytes. [x86 only]
size_t const mlen3 = mlen + (xi ? 3 : 0);
unsigned const prot = VM_PROT_READ | VM_PROT_WRITE;
unsigned const flags = (addr ? MAP_FIXED : 0) | MAP_PRIVATE |
((xi || 0==sc->filesize) ? MAP_ANON : 0);
int const fdm = ((0==sc->filesize) ? MAP_ANON_FD : fdi);
off_t const offset = sc->fileoff + fat_offset;
DPRINTF((STR_mmap(), addr, mlen3, prot, flags, fdm, offset));
unsigned char *mapa = mmap(addr, mlen3, prot, flags, fdm, offset);
if (MAP_FAILED == mapa) {
err_exit(8);
}
if (0 == addr) { // dyld auto-relocate
base = (unsigned long)mapa; // relocation constant
}
addr = mapa;
}
if (xi && 0!=sc->filesize) {
if (0==sc->fileoff /*&& 0!=mhdrpp*/) {
segTEXT = sc;
*mhdrpp = (Mach_header64 *)(void *)addr;
}
unpackExtent(xi, &xo, f_decompress, f_unf);
}
/*bzero(addr, frag);*/ // fragment at lo end
frag = (-mlen) &~ PAGE_MASK; // distance to next page boundary
bzero(mlen+addr, frag); // fragment at hi end
if (0!=mlen && 0!=mprotect(addr, mlen, sc->initprot)) {
err_exit(10);
ERR_LAB
}
addr += mlen + frag; /* page boundary on hi end */
if (
#if defined(SIMULATE_ON_DEBIAN_EABI4) /*{*/
0!=addr &&
#endif /*}*/
addr < haddr) { // need pages for .bss
if (0!=addr && addr != mmap(addr, haddr - addr, sc->initprot,
MAP_FIXED | MAP_PRIVATE | MAP_ANON, MAP_ANON_FD, 0 ) ) {
err_exit(9);
}
}
else if (xi) { // cleanup if decompressor overrun crosses page boundary
mlen = ~PAGE_MASK & (3+ mlen);
if (mlen<=3) { // page fragment was overrun buffer only
munmap((char *)addr, mlen);
}
}
}
else if (LC_UNIXTHREAD==sc->cmd || LC_THREAD==sc->cmd) {
Mach_thread_command const *const thrc = (Mach_thread_command const *)sc;
if (AMD64_THREAD_STATE ==thrc->flavor
&& AMD64_THREAD_STATE_COUNT==thrc->count ) {
entry = thrc->state.rip + base; // JMP
}
}
else if (LC_MAIN==sc->cmd) {
entry = ((Mach_main_command const *)sc)->entryoff;
if (segTEXT->fileoff <= entry && entry < segTEXT->filesize) {
entry += segTEXT->vmaddr; // CALL
}
// XXX FIXME TODO: if entry not in segTEXT?
// XXX FIXME TODO: LC_MAIN is a CALL; LC_*THREAD is a JMP
}
return entry;
}
static off_t
fat_find(Fat_header *fh) // *fh suffers bswap()
{
Fat_arch *fa = (Fat_arch *)(1+ fh);
bswap(fh, sizeof(*fh) + (fh->nfat_arch>>24)*sizeof(*fa));
unsigned j;
for (j= 0; j < fh->nfat_arch; ++j, ++fa) {
if (CPU_TYPE_AMD64==fa->cputype) {
return fa->offset; // should not be 0 because of header
}
}
return 0;
}
/*************************************************************************
// upx_main - called by our entry code
//
**************************************************************************/
DEBUG_STRCON(STR_upx_main,
"upx_main szc=%%x f_dec=%%p f_unf=%%p "
" xo=%%p(%%x %%p) xi=%%p(%%x %%p) mhdrpp=%%p\\n")
uint64_t // entry address
upx_main(
struct l_info const *const li,
size_t volatile sz_compressed, // total length
Mach_header64 *const mhdr, // temp char[sz_mhdr] for decompressing
size_t const sz_mhdr,
f_expand *const f_decompress,
f_unfilter *const f_unf,
Mach_header64 **const mhdrpp // Out: *mhdrpp= &real Mach_header64
)
{
uint64_t entry;
off_t fat_offset = 0;
Extent xi, xo, xi0;
xi.buf = CONST_CAST(unsigned char *, 1+ (struct p_info const *)(1+ li)); // &b_info
xi.size = sz_compressed - (sizeof(struct l_info) + sizeof(struct p_info));
xo.buf = (unsigned char *)mhdr;
xo.size = ((struct b_info const *)(void const *)xi.buf)->sz_unc;
xi0 = xi;
DPRINTF((STR_upx_main(),
sz_compressed, f_decompress, f_unf, &xo, xo.size, xo.buf,
&xi, xi.size, xi.buf, mhdrpp));
// Uncompress Macho headers
unpackExtent(&xi, &xo, f_decompress, 0); // never filtered?
entry = do_xmap(mhdr, fat_offset, &xi0, MAP_ANON_FD, mhdrpp, f_decompress, f_unf);
{ // Map dyld dynamic loader
Mach_load_command const *lc = (Mach_load_command const *)(1+ mhdr);
unsigned j;
for (j=0; j < mhdr->ncmds; ++j,
(lc = (Mach_load_command const *)(lc->cmdsize + (void const *)lc))
) if (LC_LOAD_DYLINKER==lc->cmd) {
char const *const dyld_name = ((Mach_lc_str const *)(1+ lc))->offset +
(char const *)lc;
int const fdi = open(dyld_name, O_RDONLY, 0);
if (0 > fdi) {
err_exit(18);
}
for (;;) { // possibly 2 times for 'fat' binary
if ((ssize_t)sz_mhdr!=pread(fdi, (void *)mhdr, sz_mhdr, fat_offset)) {
ERR_LAB
err_exit(19);
}
switch (mhdr->magic) {
case MH_MAGIC: break; // i686 on x86_64 ?
case MH_MAGIC64: break;
case FAT_CIGAM:
case FAT_MAGIC: {
// stupid Apple: waste code and a page fault on EVERY execve
fat_offset = fat_find((Fat_header *)mhdr);
if (fat_offset) {
continue; // the 'for' loop
}
err_exit(20); // no other choice
} break;
} // switch
break;
}
entry = do_xmap(mhdr, fat_offset, 0, fdi, 0, 0, 0);
close(fdi);
break;
}
}
return entry;
}
typedef struct {
uint32_t cmd;
uint32_t cmdsize;
uint32_t data[2]; // because cmdsize >= 16
} Mach_command; // generic prefix
//
// Build on Mac OS X: (where gcc is really clang)
// gcc -o amd64-darwin.macho-upxmain.exe \
// -Os -fPIC -fno-stack-protector \
// amd64-darwin.macho-upxmain.c \
// amd64-darwin.macho-upxsubr.S \
// -Wl,-pagezero_size,0xf0000000 \
// -Wl,-no_pie \
// -Wl,-no_uuid \
// -Wl,-no_function_starts \
// -Wl,-bind_at_load \
// -Wl,-headerpad,0x400 \
//
//# -Wl,-unexported_symbols_list unexport-upxload.txt \
//# strip -u -r amd64-darwin.macho-upxmain.exe
int
main(int argc, char *argv[])
{
// Entry via JMP (with no parameters) instead of CALL
asm("movl 1*8(%%rbp),%0; leaq 2*8(%%rbp),%1" : "=r" (argc), "=r" (argv) : );
Mach_header64 const *mhdr0 = (Mach_header64 const *)((~0ul<<16) & (unsigned long)&main);
Mach_command const *ptr = (Mach_command const *)(1+ mhdr0);
f_unfilter *f_unf;
f_expand *f_exp;
char *payload;
size_t paysize;
unsigned j;
for (j=0; j < mhdr0->ncmds; ++j,
ptr = (Mach_command const *)(ptr->cmdsize + (char const *)ptr))
if (LC_SEGMENT_64==ptr->cmd) {
Mach_segment_command const *const seg = (Mach_segment_command const *)ptr;
// Compare 8 characters
if (*(long const *)(&"__LINKEDIT"[2]) == *(long const *)(&seg->segname[2])) {
f_unf = (f_unfilter *)(sizeof(unsigned short) + seg->vmaddr);
f_exp = (f_expand *)(*(unsigned short const *)seg->vmaddr + seg->vmaddr);
unsigned const *q = (unsigned const *)seg->vmaddr;
while (!(paysize = *--q)) /*empty*/ ;
payload = (char *)(-paysize + (char const *)q);
break;
}
}
char mhdr[2048];
uint64_t entry = upx_main((struct l_info const *)payload, paysize,
(Mach_header64 *)mhdr, sizeof(mhdr),
f_exp, f_unf, (Mach_header64 **)&argv[-2]);
munmap(payload, paysize); // leaving __LINKEDIT
argv[-1] = (char *)(long)argc;
asm("lea -2*8(%1),%%rsp; jmp *%0" : : "r" (entry), "r" (argv));
return 0;
}
/*
vi:ts=4:et:nowrap
*/

View File

@ -0,0 +1,90 @@
/*
; amd64-darwin.macho-upxsubr.S -- system calls, bswap, bzero (amd64 Mach-o)
;
; This file is part of the UPX executable compressor.
;
; Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
; Copyright (C) 1996-2015 Laszlo Molnar
; Copyright (C) 2000-2015 John F. Reiser
; All Rights Reserved.
;
; UPX and the UCL library are free software; you can redistribute them
; and/or modify them under the terms of the GNU General Public License as
; published by the Free Software Foundation; either version 2 of
; the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; see the file COPYING.
; If not, write to the Free Software Foundation, Inc.,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;
; Markus F.X.J. Oberhumer Laszlo Molnar
; <markus@oberhumer.com> <ml1050@users.sourceforge.net>
;
; John F. Reiser
; <jreiser@users.sourceforge.net>
;
*/
// Prepend one underscore
#define GLOBAL(sym) _##sym: .globl _##sym
GLOBAL(bswap)
0:
mov (%rdi),%eax
.byte 0x0f,0xc8 // bswap eax
mov %eax,(%rdi)
sub $4,%rsi
lea 4(%rdi),%rdi
ja 0b
ret
GLOBAL(bzero)
GLOBAL(__bzero)
xor %eax,%eax // the value
mov %esi,%ecx // the count
rep; stosb // *rdi++ = %al
ret
SYS_exit =1
SYS_read =3
SYS_write =4
SYS_open =5
SYS_close =6
SYS_pread =0x99
SYS_mmap =0xc5
SYS_munmap =0x49
SYS_mprotect =0x4a
// lazy jmps enable compression of this code
GLOBAL(write)
mov $SYS_write,%al; .word 0x02eb
GLOBAL(exit)
mov $SYS_exit,%al; .word 0x02eb
GLOBAL(mprotect)
mov $SYS_mprotect,%al; .word 0x02eb
GLOBAL(munmap)
mov $SYS_munmap,%al; .word 0x02eb
GLOBAL(pread)
mov $SYS_pread,%al; .word 0x02eb
GLOBAL(close)
mov $SYS_close,%al; .word 0x02eb
GLOBAL(open)
mov $SYS_open,%al; .word 0x02eb
GLOBAL(mmap)
mov $SYS_mmap,%al; .word 0x02eb
GLOBAL(read)
mov $SYS_read,%al
movzbl %al,%eax; or $0x02000000,%eax
mov %rcx,%r10
syscall // .byte 0x0f,0x05
jnc 0f
or $~0,%rax //mov errno,eax
0:
ret

View File

@ -0,0 +1,525 @@
// In LZMA SDK 4.63 file lzma.txt (2008-12-30):
// LZMA SDK is written and placed in the public domain by Igor Pavlov.
// The creative expression of this hand compilation into assembly language,
// including (but not limited to) code organization and register assignment,
// remains copyright by John F. Reiser and licensed under GNU Lesser General
// Public License (GNU LGPL).
// Hand compiled Copyright (c) 2006-2015 John F. Reiser (2007-06-18)
// from modified LzmaDecode.c.
// LZMA SDK 4.40 Copyright (c) 1999-2015 Igor Pavlov (2006-05-01)
//
// This file is licensed under either of these two licenses:
// 1) GNU Lesser General Public License (GNU LGPL)
// 2) Common Public License (CPL)
// See files LGPL.txt and CPL.html for the text of the licenses.
#include "macros.S"
kLzmaStreamWasFinishedId= (-1)
kNumTopBits= 24
kTopValue= 1<<kNumTopBits
kNumBitModelTotalBits= 11
kBitModelTotal= (1 << kNumBitModelTotalBits)
kNumMoveBits= 5
kNumPosBitsMax= 4
kNumPosStatesMax= (1 << kNumPosBitsMax)
kLenNumLowBits= 3
kLenNumLowSymbols= (1 << kLenNumLowBits)
kLenNumMidBits= 3
kLenNumMidSymbols= (1 << kLenNumMidBits)
kLenNumHighBits= 8
kLenNumHighSymbols= (1 << kLenNumHighBits)
LenChoice= 0
LenChoice2= (LenChoice + 1)
LenLow= (LenChoice2 + 1)
LenMid= (LenLow + (kNumPosStatesMax << kLenNumLowBits))
LenHigh= (LenMid + (kNumPosStatesMax << kLenNumMidBits))
kNumLenProbs= (LenHigh + kLenNumHighSymbols)
kNumStates= 12
kNumLitStates= 7
kStartPosModelIndex= 4
kEndPosModelIndex= 14
kNumFullDistances= (1 << (kEndPosModelIndex >> 1))
kNumPosSlotBits= 6
kNumLenToPosStates= 4
kNumAlignBits= 4
kAlignTableSize= (1 << kNumAlignBits)
kMatchMinLen= 2
IsMatch= 0
IsRep= (IsMatch + (kNumStates << kNumPosBitsMax))
IsRepG0= (IsRep + kNumStates)
IsRepG1= (IsRepG0 + kNumStates)
IsRepG2= (IsRepG1 + kNumStates)
IsRep0Long= (IsRepG2 + kNumStates)
PosSlot= (IsRep0Long + (kNumStates << kNumPosBitsMax))
SpecPos= (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
Align= (SpecPos + kNumFullDistances - kEndPosModelIndex)
LenCoder= (Align + kAlignTableSize)
RepLenCoder= (LenCoder + kNumLenProbs)
Literal= (RepLenCoder + kNumLenProbs)
LZMA_BASE_SIZE= Literal /* 1846 */
LZMA_LIT_SIZE= 768
#define call bl /* subroutine call */
#define symbol mi
#define mo mi
#define mi w0
#define p_in x1
#define t1 w2
#define t1x x2
#define t0 w3
#define t0x x3
#define bit w4
#define bitx x4
#define i w5
#define ix x5
#define state w6
#define Range w7
#define inPtr x8
#define outPtr x9
#define prob x10
#define p x11
#define Code w12
#define inLim x13
#define outLim x14
#define rep0 w15
#define t2x x17
#define nowPos bit /* temporary only */
#define nowPosx bitx /* temporary only */
#define distance bit
#define numDirectBits bit
#define hibit bit
#define matchB i
#define probLen ix
#define probLit ix
#define posSlot posState
#define r_posSlot t0
#define r_len i
#define vs x0
vs_ps= 2
vs_lp= 1
vs_lc= 0
#if !defined(PARAMETER_STYLE) /*{*/
#define PARAMETER_STYLE 1
// Possible choices:
// 1 /* 0 bytes; 1-byte encoding of pb,lp,lc [default] */
// 2 /* -24 bytes; 2-byte encoding requires no division */
// 3 /* -32 bytes; separate bytes lc,lp,pb,xx at -4+ probs */
#endif /*}*/
/* LzmaDecode(x0=vs, x1=inStream, w2=inSize, x3= &inSizeProcessed,
x4= outStream, w5= outSize, x6= &outSizeProcessed)
*/
LzmaDecode: .globl LzmaDecode
// save &inSizeProcesesed and caller registers
PUSH5(x3,x4,x5,x6, x30)
mov inPtr,x1
add inLim,x1,w2, uxtw
mov outPtr,x4
add outLim,x4,w5, uxtw
#if 1==PARAMETER_STYLE /*{ [0]: pb*45 + lp*9 + lc */
mov p,vs
ldrb w6,[inPtr],#1
mov w0,#45; udiv w4,w6,w0 // w4 = quo(w6, 45) = pb
mul w0,w0,w4; sub w6,w6,w0 // w6 = rem(w6, 45)
mov w0,#9; udiv w5,w6,w0 // w5 = quo(w6, 9) = lp
mul w0,w0,w5; sub w6,w6,w0 // w6 = rem(w6, 9) = lc
#endif /*}*/
#if 2==PARAMETER_STYLE /*{ [0]: ((lc + lp)<<3) | pb; [1]: (lp<<4) | lc */
mov p,vs
ldrb w4,[inPtr],#1; and w4,w4,#7 // pb
ldrb w6,[inPtr],#1; mov w5,w6,lsr #4 // lp
and w6,w6,#0xf // lc
#endif /*}*/
#if 3==PARAMETER_STYLE /*{ lc,lp,pb,xx in separate bytes before probs[] */
add p,vs,#4
ldrb w6,[vs, #vs_lc]
ldrb w5,[vs, #vs_lp]
ldrb w4,[vs, #vs_ps]
#endif /*}*/
#undef vs
add w14,w5,w6 // lp + lc
mov Range,#~0
lsl w5,Range,w5; mvn w5,w5 // ~(~0<<lp) == litPosMask
lsl w4,Range,w4; mvn w4,w4 // ~(~0<<ps) == posStateMask
mov w3,#1
mov w2,#1
mov w1,#1
mov w0,#1
// FIXME stmdb sp!,{r0,r1,r2,r3, r4,r5,r6,r7, r8,r9,r10,r11, r12,r14}
//#define rep0 [sp, #0*4]
#define rep1 [sp, #1*4]
#define rep2 [sp, #2*4]
#define rep3 [sp, #3*4]
#define posStateMask [sp, #4*4]
#define litPosMask [sp, #5*4]
#define lc [sp, #6*4]
#define prevB [sp, #7*4]
#define inBuf [sp, #8*4]
#define outBuf [sp, #9*4]
//#define outLim [sp, #10*4]
#define posState [sp, #11*4]
//#define inLim [sp, #12*4]
#define m_len [sp, #13*4]
#define inSizeProcessed [sp, #(14 )*4]
#define outSizeProcessed [sp, #(14+10+2)*4]
mov state,#0
str state,prevB
mov w2,#LZMA_LIT_SIZE
mov w0,#LZMA_BASE_SIZE
lsl w2,w2,w14 // LZMA_LIT_SIZE << (lp + lc)
add w2,w2,w0
mov x0,#(kBitModelTotal>>1) // 0.5 starting probability
mov x1,p
orr x0,x0,x0,lsl #16
orr x0,x0,x0,lsl #32
L10:
str x0,[x1],#4*2 // 4 at a time
subs w2,w2,#4; bgt L10
add x0,inPtr,#5 // sentinel
L14:
call rcInit2; cmp x0,inPtr; bne L14
L200: // main loop
ldr t0x,outBuf
ldr t1,posStateMask
sub nowPosx,outPtr,t0x
and mi,nowPos,t1
str mi,posState
add mi,mi,state, lsl #kNumPosBitsMax
add p_in,p,#IsMatch<<1
call rcGetBit_mi0; bne L270
ldr t0,litPosMask
ldr t1,lc
and t0,t0,nowPos
ldrb mi,prevB
lsl t0,t0,t1 // (nowPos & litPosMask)<<lc
neg t1,t1; add t1,t1,#8 // rsb t1,t1,#8
lsr t1,mi,t1 // prevB >> (8- lc)
add t0,t0,t1
add prob, p,#Literal<<1
add t0,t0,t0,lsl #1 // *3
uxtw t0x,t0
mov symbol,#1
add prob,prob,t0x,lsl #1+ 8 // *768 *2
cmp state,#kNumLitStates; blo L240
L205:
sxtw t0x,rep0
neg t0x,t0x
ldrb matchB,[outPtr,t0x]
L210: // symbol === mi === mo
lsl matchB,matchB,#1
add p_in,prob,#0x100<<1
and bit,matchB,#0x100
uxtw t0x,bit
add p_in,p_in,t0x,lsl #1
call rcGetBit_mi
and t0,symbol,#1
cmp t0,bit,lsr #8; bne L243 // break
cmp symbol,#0x100; blo L210
b L245
L240: // symbol === mi === mo
mov p_in,prob
call rcGetBit_mi
L243:
cmp symbol,#0x100; blo L240
L245:
mov t1,#3; mov t0,#6
cmp state,#10; csel t0,t1, t0,lo
cmp state,# 4; csel t0,state,t0,lo
sub state,state,t0
b L298 // assumes symbol===w0
L270:
add p_in,p,#IsRep<<1
call rcGetBit_state0; bne L290
ldr t0,rep2
ldr t1,rep1
str t0,rep3
str t1,rep2
str rep0,rep1
mov t0,#0
cmp state,#kNumLitStates
mov state,#3
csel state,t0,state,lo
add prob, p,#LenCoder<<1
b L350
L290:
add p_in,p,#IsRepG0<<1
call rcGetBit_state0; bne L300
L293:
ldr t0,posState
add p_in,p,#IsRep0Long<<1
add mi,t0,state,lsl #kNumPosBitsMax
call rcGetBit_mi0; bne L340
L295:
mov t0,#9
cmp state,#kNumLitStates
mov state,#11
csel state,t0,state,lo
L297:
ldr t0x,outBuf
sub nowPosx,outPtr,t0x
cmp nowPos,rep0; blo lzmaDataError
sxtw t0x,rep0
neg t0x,t0x
ldrb w0,[outPtr,t0x]
L298:
strb w0,[outPtr],#1
b L519
L300:
add p_in,p,#IsRepG1<<1
call rcGetBit_state0; ldr distance,rep1; beq L330
L310:
add p_in,p,#IsRepG2<<1
call rcGetBit_state0; ldr distance,rep2; beq L325
L320:
ldr t0,rep2
ldr distance,rep3
str t0,rep3
L325:
ldr t0,rep1
str t0,rep2
L330:
str rep0,rep1
mov rep0,distance
L340:
mov t0,#8
cmp state,#kNumLitStates
mov state,#11
csel state,t0,state,lo
add prob, p,#RepLenCoder<<1
L350:
add p_in,prob,#LenChoice<<1
call rcGetBit_0; bne L360
ldr t0,posState
add probLen,prob,#LenLow<<1
uxtw t0x,t0
mov t1,#0
add probLen,probLen,t0x,lsl #1+ kLenNumLowBits
mov hibit,#1<<kLenNumLowBits
b L390
L360:
add p_in,prob,#LenChoice2<<1
call rcGetBit_0; bne L370
ldr t0,posState
add probLen,prob,#LenMid<<1
uxtw t0x,t0
mov t1,#kLenNumLowSymbols
add probLen,probLen,t0x,lsl #1+ kLenNumMidBits
mov hibit,#1<<kLenNumMidBits
b L390
L370:
add probLen,prob,#LenHigh<<1
mov t1,#kLenNumLowSymbols + kLenNumMidSymbols
mov hibit,#1<<kLenNumHighBits
L390:
str t1,m_len
mov mi,#1
L395: // RangeDecoderBitTreeDecode
mov p_in,probLen
call rcGetBit_mi; subs t0,mo,hibit; blo L395
ldr r_len,m_len
add r_len,r_len,t0
str r_len,m_len
cmp state,#4; bhs L500
/*L400:*/
add state,state,#kNumLitStates
mov t0,#kNumLenToPosStates -1
cmp r_len,#kNumLenToPosStates
csel r_len,t0,r_len,hs
uxtw t0x,r_len
add probLit,p,t0x,lsl #1+ kNumPosSlotBits
add probLit,probLit,#PosSlot<<1
mov mi,#1
mov hibit,#1<<kNumPosSlotBits
L403: // RangeDecoderBitTreeDecode
mov p_in,probLit
call rcGetBit_mi; subs r_posSlot,mo,hibit; blo L403
str r_posSlot,posSlot
cmp r_posSlot,#kStartPosModelIndex; blo L460
L405:
lsr numDirectBits,r_posSlot,#1
sub numDirectBits,numDirectBits,#1
and rep0,r_posSlot,#1
orr rep0,rep0,#2
cmp r_posSlot,#kEndPosModelIndex; bhs L410
L407:
lsl rep0,rep0,numDirectBits
add prob,p, #(SpecPos -1)<<1
sub t0,rep0,r_posSlot // r_posSlot dies
uxtw t0x,t0
add prob,prob,t0x,lsl #1
b L438
L410:
sub numDirectBits,numDirectBits,#kNumAlignBits
L420:
call rcNormalize
lsr Range,Range,#1
subs t0,Code,Range
csel Code,t0,Code,hs // if (Code>=Range) Code-=Range;
adc rep0,rep0,rep0 // rep0 = (rep0<<1) + (Code>=Range)
L430:
subs numDirectBits,numDirectBits,#1; bne L420
add prob,p, #Align<<1
lsl rep0,rep0,#kNumAlignBits
mov numDirectBits,#kNumAlignBits
L438:
mov i,#1
mov mi,#1
L440:
mov p_in,prob; call rcGetBit_mi
tst mo,#1; beq L445
orr rep0,rep0,i
L445:
lsl i,i,#1
subs numDirectBits,numDirectBits,#1; bne L440
b L465
L450:
L460:
ldr rep0,posSlot
L465:
adds rep0,rep0,#1
#if 0 /*{ only for the stream version */
bne L470
mov t0,#kLzmaStreamWasFinishedId
str t0,m_len
b L530
L470:
#endif /*}*/
ldr r_len,m_len
L500:
ldr t0x,outBuf
add r_len,r_len,#kMatchMinLen
sub t0x,outPtr,t0x // nowPos
cmp rep0,t0; bhi lzmaDataError
sxtw t0x,rep0
neg t0x,t0x
L510: // const t0x= -rep0;
ldrb w0,[outPtr,t0x]
strb w0,[outPtr],#1
cmp outPtr,outLim; bhs L530
subs r_len,r_len,#1; bne L510
// FIXME: prfm PLDL1KEEP,outPtr,#32 // fetch next cache line
L519:
strb w0,prevB // implicit &0xFF
L520: // bottom of while loop
cmp outPtr,outLim; blo L200
L530:
call rcNormalize
mov w0,#0 // success
lzmaExit:
ldr t1x,inBuf
sub t0x,inPtr,t1x
ldr t1x,inSizeProcessed
str t0,[t1x]
ldr t1x,outBuf
sub t0x,outPtr,t1x
ldr t1x,outSizeProcessed
str t0,[t1x]
add sp,sp,#(14+1)*4
// FIXME ldmia sp!,{r4,r5,r6,r7, r8,r9,r10,r11, pc}
lzmaDataError:
mov w0,#1 // failure
b lzmaExit
rcNormalize:
lsr t0,Range,#kNumTopBits
cbnz t0,retNorm
rcLoad:
cmp inPtr,inLim
lsl Range,Range,#8
bhs lzmaDataError
rcInit2:
ldrb t0,[inPtr],#1
orr Code,t0,Code, lsl #8
retNorm:
ret
rcGetBit_state0: // rcGetBit(0, state + p_in)
mov mi,state
rcGetBit_mi0: // rcGetBit(0, mi + p_in)
add p_in,p_in,mi, uxtw #1
rcGetBit_0: // rcGetBit(0, p_in)
mov mi,#0
rcGetBit_mi: // rcGetBit(mi, mi + p_in)
add p_in,p_in,mi, uxtw #1
rcGetBit: // Out: CC set on mo
lsr t0,Range,#kNumTopBits
mov t2x,x30 // save lr if need rcLoad
adr x30,rcGetBitCont; cbz t0,rcLoad // conditional subroutine call
rcGetBitCont:
#define starp t0
#define bound t1
#define y0tmp t1
ldrh starp,[p_in]
lsr y0tmp,Range,#kNumBitModelTotalBits
mul bound,starp,y0tmp
cmp Code,bound; bhs rcGB1
rcGB0: // Code < bound
mov y0tmp,#kBitModelTotal
mov Range,bound
sub y0tmp,y0tmp,starp
adcs mo,mi,mi // mo = (mi<<1) | (Code >= bound); set CC
add starp,starp,y0tmp, lsr #kNumMoveBits
strh starp,[p_in]
ret t2x
rcGB1: // Code >= bound
sub Code,Code,bound
sub Range,Range,bound
sub starp,starp,starp, lsr #kNumMoveBits
adcs mo,mi,mi // mo = (mi<<1) | (Code >= bound); set CC
strh starp,[p_in]
ret t2x
#undef y0tmp
#undef bound
#undef starp
#undef t1x
#undef t1
#undef t0x
#undef t0
// vi:ts=8:et

View File

@ -2,24 +2,28 @@ file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn Flags
0 MACHMAINX 0000000d 0000000000000000 0000000000000000 00000040 2**0 CONTENTS, RELOC, READONLY
1 NRV_HEAD 00000066 0000000000000000 0000000000000000 0000004d 2**0 CONTENTS, READONLY
2 NRV2E 000000b7 0000000000000000 0000000000000000 000000b3 2**0 CONTENTS, RELOC, READONLY
3 NRV2D 0000009e 0000000000000000 0000000000000000 0000016a 2**0 CONTENTS, RELOC, READONLY
4 NRV2B 00000090 0000000000000000 0000000000000000 00000208 2**0 CONTENTS, RELOC, READONLY
5 LZMA_ELF00 00000064 0000000000000000 0000000000000000 00000298 2**0 CONTENTS, RELOC, READONLY
6 LZMA_DEC10 000009f7 0000000000000000 0000000000000000 000002fc 2**0 CONTENTS, READONLY
7 LZMA_DEC20 000009f7 0000000000000000 0000000000000000 00000cf3 2**0 CONTENTS, READONLY
8 LZMA_DEC30 00000014 0000000000000000 0000000000000000 000016ea 2**0 CONTENTS, READONLY
9 NRV_TAIL 00000000 0000000000000000 0000000000000000 000016fe 2**0 CONTENTS, READONLY
10 MACHMAINY 00000011 0000000000000000 0000000000000000 000016fe 2**0 CONTENTS, READONLY
11 MACHMAINZ 00000041 0000000000000000 0000000000000000 0000170f 2**0 CONTENTS, READONLY
0 AMD64BXX 00000052 0000000000000000 0000000000000000 00000040 2**0 CONTENTS, READONLY
1 MACHMAINX 00000005 0000000000000000 0000000000000000 00000092 2**0 CONTENTS, RELOC, READONLY
2 MACH_UNC 00000008 0000000000000000 0000000000000000 00000097 2**0 CONTENTS, READONLY
3 NRV_HEAD 00000067 0000000000000000 0000000000000000 0000009f 2**0 CONTENTS, READONLY
4 NRV2E 000000b7 0000000000000000 0000000000000000 00000106 2**0 CONTENTS, RELOC, READONLY
5 NRV2D 0000009e 0000000000000000 0000000000000000 000001bd 2**0 CONTENTS, RELOC, READONLY
6 NRV2B 00000090 0000000000000000 0000000000000000 0000025b 2**0 CONTENTS, RELOC, READONLY
7 LZMA_ELF00 00000064 0000000000000000 0000000000000000 000002eb 2**0 CONTENTS, RELOC, READONLY
8 LZMA_DEC10 000009f7 0000000000000000 0000000000000000 0000034f 2**0 CONTENTS, READONLY
9 LZMA_DEC20 000009f7 0000000000000000 0000000000000000 00000d46 2**0 CONTENTS, READONLY
10 LZMA_DEC30 00000014 0000000000000000 0000000000000000 0000173d 2**0 CONTENTS, READONLY
11 NRV_TAIL 00000000 0000000000000000 0000000000000000 00001751 2**0 CONTENTS, READONLY
12 MACHMAINY 00000011 0000000000000000 0000000000000000 00001751 2**0 CONTENTS, READONLY
13 MACHMAINZ 00000041 0000000000000000 0000000000000000 00001762 2**0 CONTENTS, READONLY
SYMBOL TABLE:
0000000000000000 l d NRV_HEAD 0000000000000000 NRV_HEAD
0000000000000000 l d LZMA_DEC30 0000000000000000 LZMA_DEC30
0000000000000000 l d MACHMAINY 0000000000000000 MACHMAINY
0000000000000000 l d MACHMAINZ 0000000000000000 MACHMAINZ
0000000000000000 l d AMD64BXX 0000000000000000 AMD64BXX
0000000000000000 l d MACHMAINX 0000000000000000 MACHMAINX
0000000000000000 l d MACH_UNC 0000000000000000 MACH_UNC
0000000000000000 l d NRV2E 0000000000000000 NRV2E
0000000000000000 l d NRV2D 0000000000000000 NRV2D
0000000000000000 l d NRV2B 0000000000000000 NRV2B