Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions un7zip/src/main/cpp/src/7zDec.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define k_ARM 0x3030501
#define k_ARMT 0x3030701
#define k_SPARC 0x3030805
#define k_ARM64 0xA


#ifdef _7ZIP_PPMD_SUPPPORT
Expand Down Expand Up @@ -333,6 +334,7 @@ static SRes CheckSupportedFolder(const CSzFolder *f)
case k_SPARC:
case k_ARM:
case k_ARMT:
case k_ARM64:
break;
default:
return SZ_ERROR_UNSUPPORTED;
Expand Down Expand Up @@ -532,6 +534,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
CASE_BRA_CONV(SPARC)
CASE_BRA_CONV(ARM)
CASE_BRA_CONV(ARMT)
CASE_BRA_CONV(ARM64)
default:
return SZ_ERROR_UNSUPPORTED;
}
Expand Down
59 changes: 59 additions & 0 deletions un7zip/src/main/cpp/src/Bra.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,65 @@ SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
}


SizeT ARM64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
{
/*
* ARM64 Branch/Call/Jump (BCJ) filter decoder
* Adapted from xz-embedded project by Lasse Collin and Igor Pavlov
* This file has been put into the public domain.
*/

SizeT i;
UInt32 instr;
UInt32 addr;

size &= ~(SizeT)3; /* Align to 4 bytes */

for (i = 0; i + 4 <= size; i += 4)
{
instr = GetUi32(data + i);

if ((instr >> 26) == 0x25)
{
/* BL (Branch with Link) instruction */
addr = instr & 0x03FFFFFF;

if (encoding)
addr += (ip + (UInt32)i) >> 2;
else
addr -= (ip + (UInt32)i) >> 2;

instr = 0x94000000 | (addr & 0x03FFFFFF);

SetUi32(data + i, instr);
}
else if ((instr & 0x9F000000) == 0x90000000)
{
/* ADRP (Address of a Page) instruction */
addr = ((instr >> 29) & 3) | ((instr >> 3) & 0x1FFFFC);

/* Only convert values in the range +/-512 MiB */
if ((addr + 0x020000) & 0x1C0000)
continue;

if (encoding)
addr += (ip + (UInt32)i) >> 12;
else
addr -= (ip + (UInt32)i) >> 12;

instr &= 0x9000001F;
instr |= (addr & 3) << 29;
instr |= (addr & 0x03FFFC) << 3;
instr |= (0U - (addr & 0x020000)) & 0xE00000;

SetUi32(data + i, instr);
}
}

return i;
}


SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
{
Byte *p;
Expand Down
1 change: 1 addition & 0 deletions un7zip/src/main/cpp/src/Bra.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT ARM64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);

EXTERN_C_END

Expand Down