mirror of https://github.com/987123879113/pcsx2
parent
d535331b4b
commit
2587cf3b95
74 changed files with 26324 additions and 0 deletions
@ -0,0 +1,77 @@ |
||||
add_library(pcsx2-lzma STATIC |
||||
include/7z.h |
||||
include/7zAlloc.h |
||||
include/7zBuf.h |
||||
include/7zCrc.h |
||||
include/7zFile.h |
||||
include/7zTypes.h |
||||
include/7zVersion.h |
||||
include/Alloc.h |
||||
include/Bcj2.h |
||||
include/Bra.h |
||||
include/Compiler.h |
||||
include/CpuArch.h |
||||
include/Delta.h |
||||
include/LzFind.h |
||||
include/LzHash.h |
||||
include/Lzma2Dec.h |
||||
include/Lzma2DecMt.h |
||||
include/Lzma2Enc.h |
||||
include/Lzma86.h |
||||
include/LzmaDec.h |
||||
include/LzmaEnc.h |
||||
include/LzmaLib.h |
||||
include/Ppmd.h |
||||
include/Ppmd7.h |
||||
include/Precomp.h |
||||
include/RotateDefs.h |
||||
include/Sha256.h |
||||
include/Xz.h |
||||
include/XzCrc64.h |
||||
include/XzEnc.h |
||||
src/7zAlloc.c |
||||
src/7zArcIn.c |
||||
src/7zBuf.c |
||||
src/7zBuf2.c |
||||
src/7zCrc.c |
||||
src/7zCrcOpt.c |
||||
src/7zDec.c |
||||
src/7zFile.c |
||||
src/7zStream.c |
||||
src/Alloc.c |
||||
src/Bcj2.c |
||||
src/Bcj2Enc.c |
||||
src/Bra.c |
||||
src/Bra86.c |
||||
src/BraIA64.c |
||||
src/CpuArch.c |
||||
src/Delta.c |
||||
src/LzFind.c |
||||
src/LzFindOpt.c |
||||
src/Lzma2Dec.c |
||||
src/Lzma2DecMt.c |
||||
src/Lzma2Enc.c |
||||
src/Lzma86Dec.c |
||||
src/Lzma86Enc.c |
||||
src/LzmaDec.c |
||||
src/LzmaEnc.c |
||||
src/LzmaLib.c |
||||
src/Ppmd7.c |
||||
src/Ppmd7Dec.c |
||||
src/Ppmd7Enc.c |
||||
src/Sha256.c |
||||
src/Sha256Opt.c |
||||
src/Xz.c |
||||
src/XzCrc64.c |
||||
src/XzCrc64Opt.c |
||||
src/XzDec.c |
||||
src/XzEnc.c |
||||
src/XzIn.c |
||||
) |
||||
|
||||
target_compile_definitions(pcsx2-lzma PRIVATE _7ZIP_ST) |
||||
|
||||
target_include_directories(pcsx2-lzma PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include") |
||||
target_include_directories(pcsx2-lzma INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") |
||||
|
||||
add_library(LZMA::LZMA ALIAS pcsx2-lzma) |
@ -0,0 +1,5 @@ |
||||
https://www.7-zip.org/sdk.html |
||||
|
||||
LZMA SDK is placed in the public domain. |
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute the original LZMA SDK code, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. |
@ -0,0 +1,204 @@ |
||||
/* 7z.h -- 7z interface
|
||||
2018-07-02 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __7Z_H |
||||
#define __7Z_H |
||||
|
||||
#include "7zTypes.h" |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
#define k7zStartHeaderSize 0x20 |
||||
#define k7zSignatureSize 6 |
||||
|
||||
extern const Byte k7zSignature[k7zSignatureSize]; |
||||
|
||||
typedef struct |
||||
{ |
||||
const Byte *Data; |
||||
size_t Size; |
||||
} CSzData; |
||||
|
||||
/* CSzCoderInfo & CSzFolder support only default methods */ |
||||
|
||||
typedef struct |
||||
{ |
||||
size_t PropsOffset; |
||||
UInt32 MethodID; |
||||
Byte NumStreams; |
||||
Byte PropsSize; |
||||
} CSzCoderInfo; |
||||
|
||||
typedef struct |
||||
{ |
||||
UInt32 InIndex; |
||||
UInt32 OutIndex; |
||||
} CSzBond; |
||||
|
||||
#define SZ_NUM_CODERS_IN_FOLDER_MAX 4 |
||||
#define SZ_NUM_BONDS_IN_FOLDER_MAX 3 |
||||
#define SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX 4 |
||||
|
||||
typedef struct |
||||
{ |
||||
UInt32 NumCoders; |
||||
UInt32 NumBonds; |
||||
UInt32 NumPackStreams; |
||||
UInt32 UnpackStream; |
||||
UInt32 PackStreams[SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX]; |
||||
CSzBond Bonds[SZ_NUM_BONDS_IN_FOLDER_MAX]; |
||||
CSzCoderInfo Coders[SZ_NUM_CODERS_IN_FOLDER_MAX]; |
||||
} CSzFolder; |
||||
|
||||
|
||||
SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd); |
||||
|
||||
typedef struct |
||||
{ |
||||
UInt32 Low; |
||||
UInt32 High; |
||||
} CNtfsFileTime; |
||||
|
||||
typedef struct |
||||
{ |
||||
Byte *Defs; /* MSB 0 bit numbering */ |
||||
UInt32 *Vals; |
||||
} CSzBitUi32s; |
||||
|
||||
typedef struct |
||||
{ |
||||
Byte *Defs; /* MSB 0 bit numbering */ |
||||
// UInt64 *Vals;
|
||||
CNtfsFileTime *Vals; |
||||
} CSzBitUi64s; |
||||
|
||||
#define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0) |
||||
|
||||
#define SzBitWithVals_Check(p, i) ((p)->Defs && ((p)->Defs[(i) >> 3] & (0x80 >> ((i) & 7))) != 0) |
||||
|
||||
typedef struct |
||||
{ |
||||
UInt32 NumPackStreams; |
||||
UInt32 NumFolders; |
||||
|
||||
UInt64 *PackPositions; // NumPackStreams + 1
|
||||
CSzBitUi32s FolderCRCs; // NumFolders
|
||||
|
||||
size_t *FoCodersOffsets; // NumFolders + 1
|
||||
UInt32 *FoStartPackStreamIndex; // NumFolders + 1
|
||||
UInt32 *FoToCoderUnpackSizes; // NumFolders + 1
|
||||
Byte *FoToMainUnpackSizeIndex; // NumFolders
|
||||
UInt64 *CoderUnpackSizes; // for all coders in all folders
|
||||
|
||||
Byte *CodersData; |
||||
|
||||
UInt64 RangeLimit; |
||||
} CSzAr; |
||||
|
||||
UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex); |
||||
|
||||
SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex, |
||||
ILookInStream *stream, UInt64 startPos, |
||||
Byte *outBuffer, size_t outSize, |
||||
ISzAllocPtr allocMain); |
||||
|
||||
typedef struct |
||||
{ |
||||
CSzAr db; |
||||
|
||||
UInt64 startPosAfterHeader; |
||||
UInt64 dataPos; |
||||
|
||||
UInt32 NumFiles; |
||||
|
||||
UInt64 *UnpackPositions; // NumFiles + 1
|
||||
// Byte *IsEmptyFiles;
|
||||
Byte *IsDirs; |
||||
CSzBitUi32s CRCs; |
||||
|
||||
CSzBitUi32s Attribs; |
||||
// CSzBitUi32s Parents;
|
||||
CSzBitUi64s MTime; |
||||
CSzBitUi64s CTime; |
||||
|
||||
UInt32 *FolderToFile; // NumFolders + 1
|
||||
UInt32 *FileToFolder; // NumFiles
|
||||
|
||||
size_t *FileNameOffsets; /* in 2-byte steps */ |
||||
Byte *FileNames; /* UTF-16-LE */ |
||||
} CSzArEx; |
||||
|
||||
#define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i)) |
||||
|
||||
#define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i]) |
||||
|
||||
void SzArEx_Init(CSzArEx *p); |
||||
void SzArEx_Free(CSzArEx *p, ISzAllocPtr alloc); |
||||
UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder); |
||||
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize); |
||||
|
||||
/*
|
||||
if dest == NULL, the return value specifies the required size of the buffer, |
||||
in 16-bit characters, including the null-terminating character. |
||||
if dest != NULL, the return value specifies the number of 16-bit characters that |
||||
are written to the dest, including the null-terminating character. */ |
||||
|
||||
size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest); |
||||
|
||||
/*
|
||||
size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex); |
||||
UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest); |
||||
*/ |
||||
|
||||
|
||||
|
||||
/*
|
||||
SzArEx_Extract extracts file from archive |
||||
|
||||
*outBuffer must be 0 before first call for each new archive. |
||||
|
||||
Extracting cache: |
||||
If you need to decompress more than one file, you can send |
||||
these values from previous call: |
||||
*blockIndex, |
||||
*outBuffer, |
||||
*outBufferSize |
||||
You can consider "*outBuffer" as cache of solid block. If your archive is solid, |
||||
it will increase decompression speed. |
||||
|
||||
If you use external function, you can declare these 3 cache variables |
||||
(blockIndex, outBuffer, outBufferSize) as static in that external function. |
||||
|
||||
Free *outBuffer and set *outBuffer to 0, if you want to flush cache. |
||||
*/ |
||||
|
||||
SRes SzArEx_Extract( |
||||
const CSzArEx *db, |
||||
ILookInStream *inStream, |
||||
UInt32 fileIndex, /* index of file */ |
||||
UInt32 *blockIndex, /* index of solid block */ |
||||
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */ |
||||
size_t *outBufferSize, /* buffer size for output buffer */ |
||||
size_t *offset, /* offset of stream for required file in *outBuffer */ |
||||
size_t *outSizeProcessed, /* size of file in *outBuffer */ |
||||
ISzAllocPtr allocMain, |
||||
ISzAllocPtr allocTemp); |
||||
|
||||
|
||||
/*
|
||||
SzArEx_Open Errors: |
||||
SZ_ERROR_NO_ARCHIVE |
||||
SZ_ERROR_ARCHIVE |
||||
SZ_ERROR_UNSUPPORTED |
||||
SZ_ERROR_MEM |
||||
SZ_ERROR_CRC |
||||
SZ_ERROR_INPUT_EOF |
||||
SZ_ERROR_FAIL |
||||
*/ |
||||
|
||||
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, |
||||
ISzAllocPtr allocMain, ISzAllocPtr allocTemp); |
||||
|
||||
EXTERN_C_END |
||||
|
||||
#endif |
@ -0,0 +1,19 @@ |
||||
/* 7zAlloc.h -- Allocation functions
|
||||
2017-04-03 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __7Z_ALLOC_H |
||||
#define __7Z_ALLOC_H |
||||
|
||||
#include "7zTypes.h" |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
void *SzAlloc(ISzAllocPtr p, size_t size); |
||||
void SzFree(ISzAllocPtr p, void *address); |
||||
|
||||
void *SzAllocTemp(ISzAllocPtr p, size_t size); |
||||
void SzFreeTemp(ISzAllocPtr p, void *address); |
||||
|
||||
EXTERN_C_END |
||||
|
||||
#endif |
@ -0,0 +1,35 @@ |
||||
/* 7zBuf.h -- Byte Buffer
|
||||
2017-04-03 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __7Z_BUF_H |
||||
#define __7Z_BUF_H |
||||
|
||||
#include "7zTypes.h" |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
typedef struct |
||||
{ |
||||
Byte *data; |
||||
size_t size; |
||||
} CBuf; |
||||
|
||||
void Buf_Init(CBuf *p); |
||||
int Buf_Create(CBuf *p, size_t size, ISzAllocPtr alloc); |
||||
void Buf_Free(CBuf *p, ISzAllocPtr alloc); |
||||
|
||||
typedef struct |
||||
{ |
||||
Byte *data; |
||||
size_t size; |
||||
size_t pos; |
||||
} CDynBuf; |
||||
|
||||
void DynBuf_Construct(CDynBuf *p); |
||||
void DynBuf_SeekToBeg(CDynBuf *p); |
||||
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAllocPtr alloc); |
||||
void DynBuf_Free(CDynBuf *p, ISzAllocPtr alloc); |
||||
|
||||
EXTERN_C_END |
||||
|
||||
#endif |
@ -0,0 +1,25 @@ |
||||
/* 7zCrc.h -- CRC32 calculation
|
||||
2013-01-18 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __7Z_CRC_H |
||||
#define __7Z_CRC_H |
||||
|
||||
#include "7zTypes.h" |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
extern UInt32 g_CrcTable[]; |
||||
|
||||
/* Call CrcGenerateTable one time before other CRC functions */ |
||||
void MY_FAST_CALL CrcGenerateTable(void); |
||||
|
||||
#define CRC_INIT_VAL 0xFFFFFFFF |
||||
#define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL) |
||||
#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) |
||||
|
||||
UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size); |
||||
UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size); |
||||
|
||||
EXTERN_C_END |
||||
|
||||
#endif |
@ -0,0 +1,91 @@ |
||||
/* 7zFile.h -- File IO
|
||||
2021-02-15 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __7Z_FILE_H |
||||
#define __7Z_FILE_H |
||||
|
||||
#ifdef _WIN32 |
||||
#define USE_WINDOWS_FILE |
||||
// #include <windows.h>
|
||||
#endif |
||||
|
||||
#ifdef USE_WINDOWS_FILE |
||||
#include <windows.h> |
||||
#else |
||||
// note: USE_FOPEN mode is limited to 32-bit file size
|
||||
// #define USE_FOPEN
|
||||
// #include <stdio.h>
|
||||
#endif |
||||
|
||||
#include "7zTypes.h" |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
/* ---------- File ---------- */ |
||||
|
||||
typedef struct |
||||
{ |
||||
#ifdef USE_WINDOWS_FILE |
||||
HANDLE handle; |
||||
#elif defined(USE_FOPEN) |
||||
FILE *file; |
||||
#else |
||||
int fd; |
||||
#endif |
||||
} CSzFile; |
||||
|
||||
void File_Construct(CSzFile *p); |
||||
#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) |
||||
WRes InFile_Open(CSzFile *p, const char *name); |
||||
WRes OutFile_Open(CSzFile *p, const char *name); |
||||
#endif |
||||
#ifdef USE_WINDOWS_FILE |
||||
WRes InFile_OpenW(CSzFile *p, const WCHAR *name); |
||||
WRes OutFile_OpenW(CSzFile *p, const WCHAR *name); |
||||
#endif |
||||
WRes File_Close(CSzFile *p); |
||||
|
||||
/* reads max(*size, remain file's size) bytes */ |
||||
WRes File_Read(CSzFile *p, void *data, size_t *size); |
||||
|
||||
/* writes *size bytes */ |
||||
WRes File_Write(CSzFile *p, const void *data, size_t *size); |
||||
|
||||
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin); |
||||
WRes File_GetLength(CSzFile *p, UInt64 *length); |
||||
|
||||
|
||||
/* ---------- FileInStream ---------- */ |
||||
|
||||
typedef struct |
||||
{ |
||||
ISeqInStream vt; |
||||
CSzFile file; |
||||
WRes wres; |
||||
} CFileSeqInStream; |
||||
|
||||
void FileSeqInStream_CreateVTable(CFileSeqInStream *p); |
||||
|
||||
|
||||
typedef struct |
||||
{ |
||||
ISeekInStream vt; |
||||
CSzFile file; |
||||
WRes wres; |
||||
} CFileInStream; |
||||
|
||||
void FileInStream_CreateVTable(CFileInStream *p); |
||||
|
||||
|
||||
typedef struct |
||||
{ |
||||
ISeqOutStream vt; |
||||
CSzFile file; |
||||
WRes wres; |
||||
} CFileOutStream; |
||||
|
||||
void FileOutStream_CreateVTable(CFileOutStream *p); |
||||
|
||||
EXTERN_C_END |
||||
|
||||
#endif |
@ -0,0 +1,525 @@ |
||||
/* 7zTypes.h -- Basic types
|
||||
2021-12-25 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __7Z_TYPES_H |
||||
#define __7Z_TYPES_H |
||||
|
||||
#ifdef _WIN32 |
||||
/* #include <windows.h> */ |
||||
#else |
||||
#include <errno.h> |
||||
#endif |
||||
|
||||
#include <stddef.h> |
||||
|
||||
#ifndef EXTERN_C_BEGIN |
||||
#ifdef __cplusplus |
||||
#define EXTERN_C_BEGIN extern "C" { |
||||
#define EXTERN_C_END } |
||||
#else |
||||
#define EXTERN_C_BEGIN |
||||
#define EXTERN_C_END |
||||
#endif |
||||
#endif |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
#define SZ_OK 0 |
||||
|
||||
#define SZ_ERROR_DATA 1 |
||||
#define SZ_ERROR_MEM 2 |
||||
#define SZ_ERROR_CRC 3 |
||||
#define SZ_ERROR_UNSUPPORTED 4 |
||||
#define SZ_ERROR_PARAM 5 |
||||
#define SZ_ERROR_INPUT_EOF 6 |
||||
#define SZ_ERROR_OUTPUT_EOF 7 |
||||
#define SZ_ERROR_READ 8 |
||||
#define SZ_ERROR_WRITE 9 |
||||
#define SZ_ERROR_PROGRESS 10 |
||||
#define SZ_ERROR_FAIL 11 |
||||
#define SZ_ERROR_THREAD 12 |
||||
|
||||
#define SZ_ERROR_ARCHIVE 16 |
||||
#define SZ_ERROR_NO_ARCHIVE 17 |
||||
|
||||
typedef int SRes; |
||||
|
||||
|
||||
#ifdef _MSC_VER |
||||
#if _MSC_VER > 1200 |
||||
#define MY_ALIGN(n) __declspec(align(n)) |
||||
#else |
||||
#define MY_ALIGN(n) |
||||
#endif |
||||
#else |
||||
#define MY_ALIGN(n) __attribute__ ((aligned(n))) |
||||
#endif |
||||
|
||||
|
||||
#ifdef _WIN32 |
||||
|
||||
/* typedef DWORD WRes; */ |
||||
typedef unsigned WRes; |
||||
#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x) |
||||
|
||||
// #define MY_HRES_ERROR__INTERNAL_ERROR MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR)
|
||||
|
||||
#else // _WIN32
|
||||
|
||||
// #define ENV_HAVE_LSTAT
|
||||
typedef int WRes; |
||||
|
||||
// (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT
|
||||
#define MY__FACILITY_ERRNO 0x800 |
||||
#define MY__FACILITY_WIN32 7 |
||||
#define MY__FACILITY__WRes MY__FACILITY_ERRNO |
||||
|
||||
#define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \ |
||||
( (HRESULT)(x) & 0x0000FFFF) \
|
||||
| (MY__FACILITY__WRes << 16) \
|
||||
| (HRESULT)0x80000000 )) |
||||
|
||||
#define MY_SRes_HRESULT_FROM_WRes(x) \ |
||||
((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : MY_HRESULT_FROM_errno_CONST_ERROR(x)) |
||||
|
||||
// we call macro HRESULT_FROM_WIN32 for system errors (WRes) that are (errno)
|
||||
#define HRESULT_FROM_WIN32(x) MY_SRes_HRESULT_FROM_WRes(x) |
||||
|
||||
/*
|
||||
#define ERROR_FILE_NOT_FOUND 2L |
||||
#define ERROR_ACCESS_DENIED 5L |
||||
#define ERROR_NO_MORE_FILES 18L |
||||
#define ERROR_LOCK_VIOLATION 33L |
||||
#define ERROR_FILE_EXISTS 80L |
||||
#define ERROR_DISK_FULL 112L |
||||
#define ERROR_NEGATIVE_SEEK 131L |
||||
#define ERROR_ALREADY_EXISTS 183L |
||||
#define ERROR_DIRECTORY 267L |
||||
#define ERROR_TOO_MANY_POSTS 298L |
||||
|
||||
#define ERROR_INTERNAL_ERROR 1359L |
||||
#define ERROR_INVALID_REPARSE_DATA 4392L |
||||
#define ERROR_REPARSE_TAG_INVALID 4393L |
||||
#define ERROR_REPARSE_TAG_MISMATCH 4394L |
||||
*/ |
||||
|
||||
// we use errno equivalents for some WIN32 errors:
|
||||
|
||||
#define ERROR_INVALID_PARAMETER EINVAL |
||||
#define ERROR_INVALID_FUNCTION EINVAL |
||||
#define ERROR_ALREADY_EXISTS EEXIST |
||||
#define ERROR_FILE_EXISTS EEXIST |
||||
#define ERROR_PATH_NOT_FOUND ENOENT |
||||
#define ERROR_FILE_NOT_FOUND ENOENT |
||||
#define ERROR_DISK_FULL ENOSPC |
||||
// #define ERROR_INVALID_HANDLE EBADF
|
||||
|
||||
// we use FACILITY_WIN32 for errors that has no errno equivalent
|
||||
// Too many posts were made to a semaphore.
|
||||
#define ERROR_TOO_MANY_POSTS ((HRESULT)0x8007012AL) |
||||
#define ERROR_INVALID_REPARSE_DATA ((HRESULT)0x80071128L) |
||||
#define ERROR_REPARSE_TAG_INVALID ((HRESULT)0x80071129L) |
||||
|
||||
// if (MY__FACILITY__WRes != FACILITY_WIN32),
|
||||
// we use FACILITY_WIN32 for COM errors:
|
||||
#define E_OUTOFMEMORY ((HRESULT)0x8007000EL) |
||||
#define E_INVALIDARG ((HRESULT)0x80070057L) |
||||
#define MY__E_ERROR_NEGATIVE_SEEK ((HRESULT)0x80070083L) |
||||
|
||||
/*
|
||||
// we can use FACILITY_ERRNO for some COM errors, that have errno equivalents:
|
||||
#define E_OUTOFMEMORY MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM) |
||||
#define E_INVALIDARG MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL) |
||||
#define MY__E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL) |
||||
*/ |
||||
|
||||
// gcc / clang : (sizeof(long) == sizeof(void*)) in 32/64 bits
|
||||
typedef long INT_PTR; |
||||
typedef unsigned long UINT_PTR; |
||||
|
||||
#define TEXT(quote) quote |
||||
|
||||
#define FILE_ATTRIBUTE_READONLY 0x0001 |
||||
#define FILE_ATTRIBUTE_HIDDEN 0x0002 |
||||
#define FILE_ATTRIBUTE_SYSTEM 0x0004 |
||||
#define FILE_ATTRIBUTE_DIRECTORY 0x0010 |
||||
#define FILE_ATTRIBUTE_ARCHIVE 0x0020 |
||||
#define FILE_ATTRIBUTE_DEVICE 0x0040 |
||||
#define FILE_ATTRIBUTE_NORMAL 0x0080 |
||||
#define FILE_ATTRIBUTE_TEMPORARY 0x0100 |
||||
#define FILE_ATTRIBUTE_SPARSE_FILE 0x0200 |
||||
#define FILE_ATTRIBUTE_REPARSE_POINT 0x0400 |
||||
#define FILE_ATTRIBUTE_COMPRESSED 0x0800 |
||||
#define FILE_ATTRIBUTE_OFFLINE 0x1000 |
||||
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000 |
||||
#define FILE_ATTRIBUTE_ENCRYPTED 0x4000 |
||||
|
||||
#define FILE_ATTRIBUTE_UNIX_EXTENSION 0x8000 /* trick for Unix */ |
||||
|
||||
#endif |
||||
|
||||
|
||||
#ifndef RINOK |
||||
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } |
||||
#endif |
||||
|
||||
#ifndef RINOK_WRes |
||||
#define RINOK_WRes(x) { WRes __result__ = (x); if (__result__ != 0) return __result__; } |
||||
#endif |
||||
|
||||
typedef unsigned char Byte; |
||||
typedef short Int16; |
||||
typedef unsigned short UInt16; |
||||
|
||||
#ifdef _LZMA_UINT32_IS_ULONG |
||||
typedef long Int32; |
||||
typedef unsigned long UInt32; |
||||
#else |
||||
typedef int Int32; |
||||
typedef unsigned int UInt32; |
||||
#endif |
||||
|
||||
|
||||
#ifndef _WIN32 |
||||
|
||||
typedef int INT; |
||||
typedef Int32 INT32; |
||||
typedef unsigned int UINT; |
||||
typedef UInt32 UINT32; |
||||
typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit for _WIN32 compatibility
|
||||
typedef UINT32 ULONG; |
||||
|
||||
#undef DWORD |
||||
typedef UINT32 DWORD; |
||||
|
||||
#define VOID void |
||||
|
||||
#define HRESULT LONG |
||||
|
||||
typedef void *LPVOID; |
||||
// typedef void VOID;
|
||||
// typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
|
||||
// gcc / clang on Unix : sizeof(long==sizeof(void*) in 32 or 64 bits)
|
||||
typedef long INT_PTR; |
||||
typedef unsigned long UINT_PTR; |
||||
typedef long LONG_PTR; |
||||
typedef unsigned long DWORD_PTR; |
||||
|
||||
typedef size_t SIZE_T; |
||||
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
#define MY_HRES_ERROR__INTERNAL_ERROR ((HRESULT)0x8007054FL) |
||||
|
||||
|
||||
#ifdef _SZ_NO_INT_64 |
||||
|
||||
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
|
||||
NOTES: Some code will work incorrectly in that case! */ |
||||
|
||||
typedef long Int64; |
||||
typedef unsigned long UInt64; |
||||
|
||||
#else |
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__) |
||||
typedef __int64 Int64; |
||||
typedef unsigned __int64 UInt64; |
||||
#define UINT64_CONST(n) n |
||||
#else |
||||
typedef long long int Int64; |
||||
typedef unsigned long long int UInt64; |
||||
#define UINT64_CONST(n) n ## ULL |
||||
#endif |
||||
|
||||
#endif |
||||
|
||||
#ifdef _LZMA_NO_SYSTEM_SIZE_T |
||||
typedef UInt32 SizeT; |
||||
#else |
||||
typedef size_t SizeT; |
||||
#endif |
||||
|
||||
typedef int BoolInt; |
||||
/* typedef BoolInt Bool; */ |
||||
#define True 1 |
||||
#define False 0 |
||||
|
||||
|
||||
#ifdef _WIN32 |
||||
#define MY_STD_CALL __stdcall |
||||
#else |
||||
#define MY_STD_CALL |
||||
#endif |
||||
|
||||
#ifdef _MSC_VER |
||||
|
||||
#if _MSC_VER >= 1300 |
||||
#define MY_NO_INLINE __declspec(noinline) |
||||
#else |
||||
#define MY_NO_INLINE |
||||
#endif |
||||
|
||||
#define MY_FORCE_INLINE __forceinline |
||||
|
||||
#define MY_CDECL __cdecl |
||||
#define MY_FAST_CALL __fastcall |
||||
|
||||
#else // _MSC_VER
|
||||
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 4)) \ |
||||
|| (defined(__clang__) && (__clang_major__ >= 4)) \
|
||||
|| defined(__INTEL_COMPILER) \
|
||||
|| defined(__xlC__) |
||||
#define MY_NO_INLINE __attribute__((noinline)) |
||||
// #define MY_FORCE_INLINE __attribute__((always_inline)) inline
|
||||
#else |
||||
#define MY_NO_INLINE |
||||
#endif |
||||
|
||||
#define MY_FORCE_INLINE |
||||
|
||||
|
||||
#define MY_CDECL |
||||
|
||||
#if defined(_M_IX86) \ |
||||
|| defined(__i386__) |
||||
// #define MY_FAST_CALL __attribute__((fastcall))
|
||||
// #define MY_FAST_CALL __attribute__((cdecl))
|
||||
#define MY_FAST_CALL |
||||
#elif defined(MY_CPU_AMD64) |
||||
// #define MY_FAST_CALL __attribute__((ms_abi))
|
||||
#define MY_FAST_CALL |
||||
#else |
||||
#define MY_FAST_CALL |
||||
#endif |
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
|
||||
/* The following interfaces use first parameter as pointer to structure */ |
||||
|
||||
typedef struct IByteIn IByteIn; |
||||
struct IByteIn |
||||
{ |
||||
Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */ |
||||
}; |
||||
#define IByteIn_Read(p) (p)->Read(p) |
||||
|
||||
|
||||
typedef struct IByteOut IByteOut; |
||||
struct IByteOut |
||||
{ |
||||
void (*Write)(const IByteOut *p, Byte b); |
||||
}; |
||||
#define IByteOut_Write(p, b) (p)->Write(p, b) |
||||
|
||||
|
||||
typedef struct ISeqInStream ISeqInStream; |
||||
struct ISeqInStream |
||||
{ |
||||
SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size); |
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) < input(*size)) is allowed */ |
||||
}; |
||||
#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size) |
||||
|
||||
/* it can return SZ_ERROR_INPUT_EOF */ |
||||
SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size); |
||||
SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType); |
||||
SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf); |
||||
|
||||
|
||||
typedef struct ISeqOutStream ISeqOutStream; |
||||
struct ISeqOutStream |
||||
{ |
||||
size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size); |
||||
/* Returns: result - the number of actually written bytes.
|
||||
(result < size) means error */ |
||||
}; |
||||
#define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size) |
||||
|
||||
typedef enum |
||||
{ |
||||
SZ_SEEK_SET = 0, |
||||
SZ_SEEK_CUR = 1, |
||||
SZ_SEEK_END = 2 |
||||
} ESzSeek; |
||||
|
||||
|
||||
typedef struct ISeekInStream ISeekInStream; |
||||
struct ISeekInStream |
||||
{ |
||||
SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ |
||||
SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin); |
||||
}; |
||||
#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size) |
||||
#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin) |
||||
|
||||
|
||||
typedef struct ILookInStream ILookInStream; |
||||
struct ILookInStream |
||||
{ |
||||
SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size); |
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) > input(*size)) is not allowed |
||||
(output(*size) < input(*size)) is allowed */ |
||||
SRes (*Skip)(const ILookInStream *p, size_t offset); |
||||
/* offset must be <= output(*size) of Look */ |
||||
|
||||
SRes (*Read)(const ILookInStream *p, void *buf, size_t *size); |
||||
/* reads directly (without buffer). It's same as ISeqInStream::Read */ |
||||
SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin); |
||||
}; |
||||
|
||||
#define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size) |
||||
#define ILookInStream_Skip(p, offset) (p)->Skip(p, offset) |
||||
#define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size) |
||||
#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin) |
||||
|
||||
|
||||
SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size); |
||||
SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset); |
||||
|
||||
/* reads via ILookInStream::Read */ |
||||
SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType); |
||||
SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size); |
||||
|
||||
|
||||
|
||||
typedef struct |
||||
{ |
||||
ILookInStream vt; |
||||
const ISeekInStream *realStream; |
||||
|
||||
size_t pos; |
||||
size_t size; /* it's data size */ |
||||
|
||||
/* the following variables must be set outside */ |
||||
Byte *buf; |
||||
size_t bufSize; |
||||
} CLookToRead2; |
||||
|
||||
void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead); |
||||
|
||||
#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; } |
||||
|
||||
|
||||
typedef struct |
||||
{ |
||||
ISeqInStream vt; |
||||
const ILookInStream *realStream; |
||||
} CSecToLook; |
||||
|
||||
void SecToLook_CreateVTable(CSecToLook *p); |
||||
|
||||
|
||||
|
||||
typedef struct |
||||
{ |
||||
ISeqInStream vt; |
||||
const ILookInStream *realStream; |
||||
} CSecToRead; |
||||
|
||||
void SecToRead_CreateVTable(CSecToRead *p); |
||||
|
||||
|
||||
typedef struct ICompressProgress ICompressProgress; |
||||
|
||||
struct ICompressProgress |
||||
{ |
||||
SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize); |
||||
/* Returns: result. (result != SZ_OK) means break.
|
||||
Value (UInt64)(Int64)-1 for size means unknown value. */ |
||||
}; |
||||
#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize) |
||||
|
||||
|
||||
|
||||
typedef struct ISzAlloc ISzAlloc; |
||||
typedef const ISzAlloc * ISzAllocPtr; |
||||
|
||||
struct ISzAlloc |
||||
{ |
||||
void *(*Alloc)(ISzAllocPtr p, size_t size); |
||||
void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */ |
||||
}; |
||||
|
||||
#define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size) |
||||
#define ISzAlloc_Free(p, a) (p)->Free(p, a) |
||||
|
||||
/* deprecated */ |
||||
#define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size) |
||||
#define IAlloc_Free(p, a) ISzAlloc_Free(p, a) |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef MY_offsetof |
||||
#ifdef offsetof |
||||
#define MY_offsetof(type, m) offsetof(type, m) |
||||
/*
|
||||
#define MY_offsetof(type, m) FIELD_OFFSET(type, m) |
||||
*/ |
||||
#else |
||||
#define MY_offsetof(type, m) ((size_t)&(((type *)0)->m)) |
||||
#endif |
||||
#endif |
||||
|
||||
|
||||
|
||||
#ifndef MY_container_of |
||||
|
||||
/*
|
||||
#define MY_container_of(ptr, type, m) container_of(ptr, type, m) |
||||
#define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m) |
||||
#define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m))) |
||||
#define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m)))) |
||||
*/ |
||||
|
||||
/*
|
||||
GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly" |
||||
GCC 3.4.4 : classes with constructor |
||||
GCC 4.8.1 : classes with non-public variable members" |
||||
*/ |
||||
|
||||
#define MY_container_of(ptr, type, m) ((type *)(void *)((char *)(void *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m))) |
||||
|
||||
#endif |
||||
|
||||
#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr)) |
||||
|
||||
/*
|
||||
#define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) |
||||
*/ |
||||
#define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m) |
||||
|
||||
#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) |
||||
/*
|
||||
#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m) |
||||
*/ |
||||
|
||||
|
||||
#define MY_memset_0_ARRAY(a) memset((a), 0, sizeof(a)) |
||||
|
||||
#ifdef _WIN32 |
||||
|
||||
#define CHAR_PATH_SEPARATOR '\\' |
||||
#define WCHAR_PATH_SEPARATOR L'\\' |
||||
#define STRING_PATH_SEPARATOR "\\" |
||||
#define WSTRING_PATH_SEPARATOR L"\\" |
||||
|
||||
#else |
||||
|
||||
#define CHAR_PATH_SEPARATOR '/' |
||||
#define WCHAR_PATH_SEPARATOR L'/' |
||||
#define STRING_PATH_SEPARATOR "/" |
||||
#define WSTRING_PATH_SEPARATOR L"/" |
||||
|
||||
#endif |
||||
|
||||
EXTERN_C_END |
||||
|
||||
#endif |
@ -0,0 +1,27 @@ |
||||
#define MY_VER_MAJOR 21 |
||||
#define MY_VER_MINOR 07 |
||||
#define MY_VER_BUILD 0 |
||||
#define MY_VERSION_NUMBERS "21.07" |
||||
#define MY_VERSION MY_VERSION_NUMBERS |
||||
|
||||
#ifdef MY_CPU_NAME |
||||
#define MY_VERSION_CPU MY_VERSION " (" MY_CPU_NAME ")" |
||||
#else |
||||
#define MY_VERSION_CPU MY_VERSION |
||||
#endif |
||||
|
||||
#define MY_DATE "2021-12-26" |
||||
#undef MY_COPYRIGHT |
||||
#undef MY_VERSION_COPYRIGHT_DATE |
||||
#define MY_AUTHOR_NAME "Igor Pavlov" |
||||
#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain" |
||||
#define MY_COPYRIGHT_CR "Copyright (c) 1999-2021 Igor Pavlov" |
||||
|
||||
#ifdef USE_COPYRIGHT_CR |
||||
#define MY_COPYRIGHT MY_COPYRIGHT_CR |
||||
#else |
||||
#define MY_COPYRIGHT MY_COPYRIGHT_PD |
||||
#endif |
||||
|
||||
#define MY_COPYRIGHT_DATE MY_COPYRIGHT " : " MY_DATE |
||||
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION_CPU " : " MY_COPYRIGHT " : " MY_DATE |
@ -0,0 +1,58 @@ |
||||
/* Alloc.h -- Memory allocation functions
|
||||
2021-07-13 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __COMMON_ALLOC_H |
||||
#define __COMMON_ALLOC_H |
||||
|
||||
#include "7zTypes.h" |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
void *MyAlloc(size_t size); |
||||
void MyFree(void *address); |
||||
|
||||
#ifdef _WIN32 |
||||
|
||||
void SetLargePageSize(void); |
||||
|
||||
void *MidAlloc(size_t size); |
||||
void MidFree(void *address); |
||||
void *BigAlloc(size_t size); |
||||
void BigFree(void *address); |
||||
|
||||
#else |
||||
|
||||
#define MidAlloc(size) MyAlloc(size) |
||||
#define MidFree(address) MyFree(address) |
||||
#define BigAlloc(size) MyAlloc(size) |
||||
#define BigFree(address) MyFree(address) |
||||
|
||||
#endif |
||||
|
||||
extern const ISzAlloc g_Alloc; |
||||
|
||||
#ifdef _WIN32 |
||||
extern const ISzAlloc g_BigAlloc; |
||||
extern const ISzAlloc g_MidAlloc; |
||||
#else |
||||
#define g_BigAlloc g_AlignedAlloc |
||||
#define g_MidAlloc g_AlignedAlloc |
||||
#endif |
||||
|
||||
extern const ISzAlloc g_AlignedAlloc; |
||||
|
||||
|
||||
typedef struct |
||||
{ |
||||
ISzAlloc vt; |
||||
ISzAllocPtr baseAlloc; |
||||
unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */ |
||||
size_t offset; /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */ |
||||
} CAlignOffsetAlloc; |
||||
|
||||
void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p); |
||||
|
||||
|
||||
EXTERN_C_END |
||||
|
||||
#endif |
@ -0,0 +1,146 @@ |
||||
/* Bcj2.h -- BCJ2 Converter for x86 code
|
||||
2014-11-10 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __BCJ2_H |
||||
#define __BCJ2_H |
||||
|
||||
#include "7zTypes.h" |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
#define BCJ2_NUM_STREAMS 4 |
||||
|
||||
enum |
||||
{ |
||||
BCJ2_STREAM_MAIN, |
||||
BCJ2_STREAM_CALL, |
||||
BCJ2_STREAM_JUMP, |
||||
BCJ2_STREAM_RC |
||||
}; |
||||
|
||||
enum |
||||
{ |
||||
BCJ2_DEC_STATE_ORIG_0 = BCJ2_NUM_STREAMS, |
||||
BCJ2_DEC_STATE_ORIG_1, |
||||
BCJ2_DEC_STATE_ORIG_2, |
||||
BCJ2_DEC_STATE_ORIG_3, |
||||
|
||||
BCJ2_DEC_STATE_ORIG, |
||||
BCJ2_DEC_STATE_OK |
||||
}; |
||||
|
||||
enum |
||||
{ |
||||
BCJ2_ENC_STATE_ORIG = BCJ2_NUM_STREAMS, |
||||
BCJ2_ENC_STATE_OK |
||||
}; |
||||
|
||||
|
||||
#define BCJ2_IS_32BIT_STREAM(s) ((s) == BCJ2_STREAM_CALL || (s) == BCJ2_STREAM_JUMP) |
||||
|
||||
/*
|
||||
CBcj2Dec / CBcj2Enc |
||||
bufs sizes: |
||||
BUF_SIZE(n) = lims[n] - bufs[n] |
||||
bufs sizes for BCJ2_STREAM_CALL and BCJ2_STREAM_JUMP must be mutliply of 4: |
||||
(BUF_SIZE(BCJ2_STREAM_CALL) & 3) == 0 |
||||
(BUF_SIZE(BCJ2_STREAM_JUMP) & 3) == 0 |
||||
*/ |
||||
|
||||
/*
|
||||
CBcj2Dec: |
||||
dest is allowed to overlap with bufs[BCJ2_STREAM_MAIN], with the following conditions: |
||||
bufs[BCJ2_STREAM_MAIN] >= dest && |
||||
bufs[BCJ2_STREAM_MAIN] - dest >= tempReserv + |
||||
BUF_SIZE(BCJ2_STREAM_CALL) + |
||||
BUF_SIZE(BCJ2_STREAM_JUMP) |
||||
tempReserv = 0 : for first call of Bcj2Dec_Decode |
||||
tempReserv = 4 : for any other calls of Bcj2Dec_Decode |
||||
overlap with offset = 1 is not allowed |
||||
*/ |
||||
|
||||
typedef struct |
||||
{ |
||||
const Byte *bufs[BCJ2_NUM_STREAMS]; |
||||
const Byte *lims[BCJ2_NUM_STREAMS]; |
||||
Byte *dest; |
||||
const Byte *destLim; |
||||
|
||||
unsigned state; /* BCJ2_STREAM_MAIN has more priority than BCJ2_STATE_ORIG */ |
||||
|
||||
UInt32 ip; |
||||
Byte temp[4]; |
||||
UInt32 range; |
||||
UInt32 code; |
||||
UInt16 probs[2 + 256]; |
||||
} CBcj2Dec; |
||||
|
||||
void Bcj2Dec_Init(CBcj2Dec *p); |
||||
|
||||
/* Returns: SZ_OK or SZ_ERROR_DATA */ |
||||
SRes Bcj2Dec_Decode(CBcj2Dec *p); |
||||
|
||||
#define Bcj2Dec_IsFinished(_p_) ((_p_)->code == 0) |
||||
|
||||
|
||||
|
||||
typedef enum |
||||
{ |
||||
BCJ2_ENC_FINISH_MODE_CONTINUE, |
||||
BCJ2_ENC_FINISH_MODE_END_BLOCK, |
||||
BCJ2_ENC_FINISH_MODE_END_STREAM |
||||
} EBcj2Enc_FinishMode; |
||||
|
||||
typedef struct |
||||
{ |
||||
Byte *bufs[BCJ2_NUM_STREAMS]; |
||||
const Byte *lims[BCJ2_NUM_STREAMS]; |
||||
const Byte *src; |
||||
const Byte *srcLim; |
||||
|
||||
unsigned state; |
||||
EBcj2Enc_FinishMode finishMode; |
||||
|
||||
Byte prevByte; |
||||
|
||||
Byte cache; |
||||
UInt32 range; |
||||
UInt64 low; |
||||
UInt64 cacheSize; |
||||
|
||||
UInt32 ip; |
||||
|
||||
/* 32-bit ralative offset in JUMP/CALL commands is
|
||||
- (mod 4 GB) in 32-bit mode |
||||
- signed Int32 in 64-bit mode |
||||
We use (mod 4 GB) check for fileSize. |
||||
Use fileSize up to 2 GB, if you want to support 32-bit and 64-bit code conversion. */ |
||||
UInt32 fileIp; |
||||
UInt32 fileSize; /* (fileSize <= ((UInt32)1 << 31)), 0 means no_limit */ |
||||
UInt32 relatLimit; /* (relatLimit <= ((UInt32)1 << 31)), 0 means desable_conversion */ |
||||
|
||||
UInt32 tempTarget; |
||||
unsigned tempPos; |
||||
Byte temp[4 * 2]; |
||||
|
||||
unsigned flushPos; |
||||
|
||||
UInt16 probs[2 + 256]; |
||||
} CBcj2Enc; |
||||
|
||||
void Bcj2Enc_Init(CBcj2Enc *p); |
||||
void Bcj2Enc_Encode(CBcj2Enc *p); |
||||
|
||||
#define Bcj2Enc_Get_InputData_Size(p) ((SizeT)((p)->srcLim - (p)->src) + (p)->tempPos) |
||||
#define Bcj2Enc_IsFinished(p) ((p)->flushPos == 5) |
||||
|
||||
|
||||
#define BCJ2_RELAT_LIMIT_NUM_BITS 26 |
||||
#define BCJ2_RELAT_LIMIT ((UInt32)1 << BCJ2_RELAT_LIMIT_NUM_BITS) |
||||
|
||||
/* limit for CBcj2Enc::fileSize variable */ |
||||
#define BCJ2_FileSize_MAX ((UInt32)1 << 31) |
||||
|
||||
EXTERN_C_END |
||||
|
||||
#endif |
@ -0,0 +1,64 @@ |
||||
/* Bra.h -- Branch converters for executables
|
||||
2013-01-18 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __BRA_H |
||||
#define __BRA_H |
||||
|
||||
#include "7zTypes.h" |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
/*
|
||||
These functions convert relative addresses to absolute addresses |
||||
in CALL instructions to increase the compression ratio. |
||||
|
||||
In: |
||||
data - data buffer |
||||
size - size of data |
||||
ip - current virtual Instruction Pinter (IP) value |
||||
state - state variable for x86 converter |
||||
encoding - 0 (for decoding), 1 (for encoding) |
||||
|
||||
Out: |
||||
state - state variable for x86 converter |
||||
|
||||
Returns: |
||||
The number of processed bytes. If you call these functions with multiple calls, |
||||
you must start next call with first byte after block of processed bytes. |
||||
|
||||
Type Endian Alignment LookAhead |
||||
|
||||
x86 little 1 4 |
||||
ARMT little 2 2 |
||||
ARM little 4 0 |
||||
PPC big 4 0 |
||||
SPARC big 4 0 |
||||
IA64 little 16 0 |
||||
|
||||
size must be >= Alignment + LookAhead, if it's not last block. |
||||
If (size < Alignment + LookAhead), converter returns 0. |
||||
|
||||
Example: |
||||
|
||||
UInt32 ip = 0; |
||||
for () |
||||
{ |
||||
; size must be >= Alignment + LookAhead, if it's not last block |
||||
SizeT processed = Convert(data, size, ip, 1); |
||||
data += processed; |
||||
size -= processed; |
||||
ip += processed; |
||||
} |
||||
*/ |
||||
|
||||
#define x86_Convert_Init(state) { state = 0; } |
||||
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding); |
||||
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); |
||||
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); |
||||
|
||||
EXTERN_C_END |
||||
|
||||
#endif |
@ -0,0 +1,43 @@ |
||||
/* Compiler.h
|
||||
2021-01-05 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __7Z_COMPILER_H |
||||
#define __7Z_COMPILER_H |
||||
|
||||
#ifdef __clang__ |
||||
#pragma clang diagnostic ignored "-Wunused-private-field" |
||||
#endif |
||||
|
||||
#ifdef _MSC_VER |
||||
|
||||
#ifdef UNDER_CE |
||||
#define RPC_NO_WINDOWS_H |
||||
/* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */ |
||||
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
|
||||
#pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int
|
||||
#endif |
||||
|
||||
#if _MSC_VER >= 1300 |
||||
#pragma warning(disable : 4996) // This function or variable may be unsafe
|
||||
#else |
||||
#pragma warning(disable : 4511) // copy constructor could not be generated
|
||||
#pragma warning(disable : 4512) // assignment operator could not be generated
|
||||
#pragma warning(disable : 4514) // unreferenced inline function has been removed
|
||||
#pragma warning(disable : 4702) // unreachable code
|
||||
#pragma warning(disable : 4710) // not inlined
|
||||
#pragma warning(disable : 4714) // function marked as __forceinline not inlined
|
||||
#pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information
|
||||
#endif |
||||
|
||||
#ifdef __clang__ |
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations" |
||||
#pragma clang diagnostic ignored "-Wmicrosoft-exception-spec" |
||||
// #pragma clang diagnostic ignored "-Wreserved-id-macro"
|
||||
#endif |
||||
|
||||
#endif |
||||
|
||||
#define UNUSED_VAR(x) (void)x; |
||||
/* #define UNUSED_VAR(x) x=x; */ |
||||
|
||||
#endif |
@ -0,0 +1,442 @@ |
||||
/* CpuArch.h -- CPU specific code
|
||||
2021-07-13 : Igor Pavlov : Public domain */ |
||||
|
||||
#ifndef __CPU_ARCH_H |
||||
#define __CPU_ARCH_H |
||||
|
||||
#include "7zTypes.h" |
||||
|
||||
EXTERN_C_BEGIN |
||||
|
||||
/*
|
||||
MY_CPU_LE means that CPU is LITTLE ENDIAN. |
||||
MY_CPU_BE means that CPU is BIG ENDIAN. |
||||
If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform. |
||||
|
||||
MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses. |
||||
|
||||
MY_CPU_64BIT means that processor can work with 64-bit registers. |
||||
MY_CPU_64BIT can be used to select fast code branch |
||||
MY_CPU_64BIT doesn't mean that (sizeof(void *) == 8) |
||||
*/ |
||||
|
||||
#if defined(_M_X64) \ |
||||
|| defined(_M_AMD64) \
|
||||
|| defined(__x86_64__) \
|
||||
|| defined(__AMD64__) \
|
||||
|| defined(__amd64__) |
||||
#define MY_CPU_AMD64 |
||||
#ifdef __ILP32__ |
||||
#define MY_CPU_NAME "x32" |
||||
#define MY_CPU_SIZEOF_POINTER 4 |
||||
#else |
||||
#define MY_CPU_NAME "x64" |
||||
#define MY_CPU_SIZEOF_POINTER 8 |
||||
#endif |
||||
#define MY_CPU_64BIT |
||||
#endif |
||||
|
||||
|
||||
#if defined(_M_IX86) \ |
||||
|| defined(__i386__) |
||||
#define MY_CPU_X86 |
||||
#define MY_CPU_NAME "x86" |
||||
/* #define MY_CPU_32BIT */ |
||||
#define MY_CPU_SIZEOF_POINTER 4 |
||||
#endif |
||||
|
||||
|
||||
#if defined(_M_ARM64) \ |
||||
|| defined(__AARCH64EL__) \
|
||||
|| defined(__AARCH64EB__) \
|
||||
|| defined(__aarch64__) |
||||
#define MY_CPU_ARM64 |
||||
#define MY_CPU_NAME "arm64" |
||||
#define MY_CPU_64BIT |
||||
#endif |
||||
|
||||
|
||||
#if defined(_M_ARM) \ |
||||
|| defined(_M_ARM_NT) \
|
||||
|| defined(_M_ARMT) \
|
||||
|| defined(__arm__) \
|
||||
|| defined(__thumb__) \
|
||||
|| defined(__ARMEL__) \
|
||||
|| defined(__ARMEB__) \
|
||||
|| defined(__THUMBEL__) \
|
||||
|| defined(__THUMBEB__) |
||||
#define MY_CPU_ARM |
||||
|
||||
#if defined(__thumb__) || defined(__THUMBEL__) || defined(_M_ARMT) |
||||
#define MY_CPU_NAME "armt" |
||||
#else |
||||
#define MY_CPU_NAME "arm" |
||||
#endif |
||||
/* #define MY_CPU_32BIT */ |
||||
#define MY_CPU_SIZEOF_POINTER 4 |
||||
#endif |
||||
|
||||
|
||||
#if defined(_M_IA64) \ |
||||
|| defined(__ia64__) |
||||
#define MY_CPU_IA64 |
||||
#define MY_CPU_NAME "ia64" |
||||
#define MY_CPU_64BIT |
||||
#endif |
||||
|
||||
|
||||
#if defined(__mips64) \ |
||||
|| defined(__mips64__) \
|
||||
|| (defined(__mips) && (__mips == 64 || __mips == 4 || __mips == 3)) |
||||
#define MY_CPU_NAME "mips64" |
||||
#define MY_CPU_64BIT |
||||
#elif defined(__mips__) |
||||
#define MY_CPU_NAME "mips" |
||||
/* #define MY_CPU_32BIT */ |
||||
#endif |
||||
|
||||
|
||||
#if defined(__ppc64__) \ |
||||
|| defined(__powerpc64__) \
|
||||
|| defined(__ppc__) \
|
||||
|| defined(__powerpc__) \
|
||||
|| defined(__PPC__) \
|
||||
|| defined(_POWER) |
||||
|
||||
#if defined(__ppc64__) \ |
||||
|| defined(__powerpc64__) \
|
||||
|| defined(_LP64) \
|
||||
|| defined(__64BIT__) |
||||
#ifdef __ILP32__ |
||||
#define MY_CPU_NAME "ppc64-32" |
||||
#define MY_CPU_SIZEOF_POINTER 4 |
||||
#else |
||||
#define MY_CPU_NAME "ppc64" |
||||
#define MY_CPU_SIZEOF_POINTER 8 |
||||
#endif |
||||
#define MY_CPU_64BIT |
||||
#else |
||||
#define MY_CPU_NAME "ppc" |
||||
#define MY_CPU_SIZEOF_POINTER 4 |
||||
/* #define MY_CPU_32BIT */ |
||||
#endif |
||||
#endif |
||||