| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,375 @@ | ||
| /* 7zTypes.h -- Basic types | ||
| 2018-08-04 : Igor Pavlov : Public domain */ | ||
|
|
||
| #ifndef __7Z_TYPES_H | ||
| #define __7Z_TYPES_H | ||
|
|
||
| #ifdef _WIN32 | ||
| /* #include <windows.h> */ | ||
| #endif | ||
|
|
||
| #include <stddef.h> | ||
| #include <zconf.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 _WIN32 | ||
|
|
||
| /* typedef DWORD WRes; */ | ||
| typedef unsigned WRes; | ||
| #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x) | ||
|
|
||
| #else | ||
|
|
||
| typedef int WRes; | ||
| #define MY__FACILITY_WIN32 7 | ||
| #define MY__FACILITY__WRes MY__FACILITY_WIN32 | ||
| #define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000))) | ||
|
|
||
| #endif | ||
|
|
||
|
|
||
| #ifndef RINOK | ||
| #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } | ||
| #endif | ||
|
|
||
| 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 | ||
|
|
||
| #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 | ||
|
|
||
| #define MY_NO_INLINE | ||
| #define MY_FORCE_INLINE | ||
| #define MY_CDECL | ||
| #define MY_FAST_CALL | ||
|
|
||
| /* inline keyword : for C++ / C99 */ | ||
|
|
||
| /* GCC, clang: */ | ||
| /* | ||
| #if defined (__GNUC__) && (__GNUC__ >= 4) | ||
| #define MY_FORCE_INLINE __attribute__((always_inline)) | ||
| #define MY_NO_INLINE __attribute__((noinline)) | ||
| #endif | ||
| */ | ||
|
|
||
| #endif | ||
|
|
||
|
|
||
| /* 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 *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m))) | ||
|
|
||
|
|
||
| #endif | ||
|
|
||
| #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(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) | ||
| */ | ||
|
|
||
|
|
||
|
|
||
| #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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* Compiler.h | ||
| 2017-04-03 : Igor Pavlov : Public domain */ | ||
|
|
||
| #ifndef __7Z_COMPILER_H | ||
| #define __7Z_COMPILER_H | ||
|
|
||
| #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 | ||
|
|
||
| #endif | ||
|
|
||
| #define UNUSED_VAR(x) (void)x; | ||
| /* #define UNUSED_VAR(x) x=x; */ | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* LzFind.h -- Match finder for LZ algorithms | ||
| 2017-06-10 : Igor Pavlov : Public domain */ | ||
|
|
||
| #ifndef __LZ_FIND_H | ||
| #define __LZ_FIND_H | ||
|
|
||
| #include "7zTypes.h" | ||
|
|
||
| EXTERN_C_BEGIN | ||
|
|
||
| typedef UInt32 CLzRef; | ||
|
|
||
| typedef struct _CMatchFinder | ||
| { | ||
| Byte *buffer; | ||
| UInt32 pos; | ||
| UInt32 posLimit; | ||
| UInt32 streamPos; | ||
| UInt32 lenLimit; | ||
|
|
||
| UInt32 cyclicBufferPos; | ||
| UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ | ||
|
|
||
| Byte streamEndWasReached; | ||
| Byte btMode; | ||
| Byte bigHash; | ||
| Byte directInput; | ||
|
|
||
| UInt32 matchMaxLen; | ||
| CLzRef *hash; | ||
| CLzRef *son; | ||
| UInt32 hashMask; | ||
| UInt32 cutValue; | ||
|
|
||
| Byte *bufferBase; | ||
| ISeqInStream *stream; | ||
|
|
||
| UInt32 blockSize; | ||
| UInt32 keepSizeBefore; | ||
| UInt32 keepSizeAfter; | ||
|
|
||
| UInt32 numHashBytes; | ||
| size_t directInputRem; | ||
| UInt32 historySize; | ||
| UInt32 fixedHashSize; | ||
| UInt32 hashSizeSum; | ||
| SRes result; | ||
| UInt32 crc[256]; | ||
| size_t numRefs; | ||
|
|
||
| UInt64 expectedDataSize; | ||
| } CMatchFinder; | ||
|
|
||
| #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer) | ||
|
|
||
| #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos) | ||
|
|
||
| #define Inline_MatchFinder_IsFinishedOK(p) \ | ||
| ((p)->streamEndWasReached \ | ||
| && (p)->streamPos == (p)->pos \ | ||
| && (!(p)->directInput || (p)->directInputRem == 0)) | ||
|
|
||
| int MatchFinder_NeedMove(CMatchFinder *p); | ||
| Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); | ||
| void MatchFinder_MoveBlock(CMatchFinder *p); | ||
| void MatchFinder_ReadIfRequired(CMatchFinder *p); | ||
|
|
||
| void MatchFinder_Construct(CMatchFinder *p); | ||
|
|
||
| /* Conditions: | ||
| historySize <= 3 GB | ||
| keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB | ||
| */ | ||
| int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, | ||
| UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, | ||
| ISzAllocPtr alloc); | ||
| void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc); | ||
| void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems); | ||
| void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); | ||
|
|
||
| UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, | ||
| UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, | ||
| UInt32 *distances, UInt32 maxLen); | ||
|
|
||
| /* | ||
| Conditions: | ||
| Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. | ||
| Mf_GetPointerToCurrentPos_Func's result must be used only before any other function | ||
| */ | ||
|
|
||
| typedef void (*Mf_Init_Func)(void *object); | ||
| typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); | ||
| typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); | ||
| typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances); | ||
| typedef void (*Mf_Skip_Func)(void *object, UInt32); | ||
|
|
||
| typedef struct _IMatchFinder | ||
| { | ||
| Mf_Init_Func Init; | ||
| Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; | ||
| Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; | ||
| Mf_GetMatches_Func GetMatches; | ||
| Mf_Skip_Func Skip; | ||
| } IMatchFinder; | ||
|
|
||
| void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); | ||
|
|
||
| void MatchFinder_Init_LowHash(CMatchFinder *p); | ||
| void MatchFinder_Init_HighHash(CMatchFinder *p); | ||
| void MatchFinder_Init_3(CMatchFinder *p, int readData); | ||
| void MatchFinder_Init(CMatchFinder *p); | ||
|
|
||
| UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); | ||
| UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); | ||
|
|
||
| void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); | ||
| void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); | ||
|
|
||
| EXTERN_C_END | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* LzHash.h -- HASH functions for LZ algorithms | ||
| 2015-04-12 : Igor Pavlov : Public domain */ | ||
|
|
||
| #ifndef __LZ_HASH_H | ||
| #define __LZ_HASH_H | ||
|
|
||
| #define kHash2Size (1 << 10) | ||
| #define kHash3Size (1 << 16) | ||
| #define kHash4Size (1 << 20) | ||
|
|
||
| #define kFix3HashSize (kHash2Size) | ||
| #define kFix4HashSize (kHash2Size + kHash3Size) | ||
| #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) | ||
|
|
||
| #define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8); | ||
|
|
||
| #define HASH3_CALC { \ | ||
| UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ | ||
| h2 = temp & (kHash2Size - 1); \ | ||
| hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } | ||
|
|
||
| #define HASH4_CALC { \ | ||
| UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ | ||
| h2 = temp & (kHash2Size - 1); \ | ||
| temp ^= ((UInt32)cur[2] << 8); \ | ||
| h3 = temp & (kHash3Size - 1); \ | ||
| hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; } | ||
|
|
||
| #define HASH5_CALC { \ | ||
| UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ | ||
| h2 = temp & (kHash2Size - 1); \ | ||
| temp ^= ((UInt32)cur[2] << 8); \ | ||
| h3 = temp & (kHash3Size - 1); \ | ||
| temp ^= (p->crc[cur[3]] << 5); \ | ||
| h4 = temp & (kHash4Size - 1); \ | ||
| hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; } | ||
|
|
||
| /* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */ | ||
| #define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; | ||
|
|
||
|
|
||
| #define MT_HASH2_CALC \ | ||
| h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1); | ||
|
|
||
| #define MT_HASH3_CALC { \ | ||
| UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ | ||
| h2 = temp & (kHash2Size - 1); \ | ||
| h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } | ||
|
|
||
| #define MT_HASH4_CALC { \ | ||
| UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ | ||
| h2 = temp & (kHash2Size - 1); \ | ||
| temp ^= ((UInt32)cur[2] << 8); \ | ||
| h3 = temp & (kHash3Size - 1); \ | ||
| h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| /* LzmaDec.h -- LZMA Decoder | ||
| 2018-04-21 : Igor Pavlov : Public domain */ | ||
|
|
||
| #ifndef __LZMA_DEC_H | ||
| #define __LZMA_DEC_H | ||
|
|
||
| #include "7zTypes.h" | ||
|
|
||
| EXTERN_C_BEGIN | ||
|
|
||
| /* #define _LZMA_PROB32 */ | ||
| /* _LZMA_PROB32 can increase the speed on some CPUs, | ||
| but memory usage for CLzmaDec::probs will be doubled in that case */ | ||
|
|
||
| typedef | ||
| #ifdef _LZMA_PROB32 | ||
| UInt32 | ||
| #else | ||
| UInt16 | ||
| #endif | ||
| CLzmaProb; | ||
|
|
||
|
|
||
| /* ---------- LZMA Properties ---------- */ | ||
|
|
||
| #define LZMA_PROPS_SIZE 5 | ||
|
|
||
| typedef struct _CLzmaProps | ||
| { | ||
| Byte lc; | ||
| Byte lp; | ||
| Byte pb; | ||
| Byte _pad_; | ||
| UInt32 dicSize; | ||
| } CLzmaProps; | ||
|
|
||
| /* LzmaProps_Decode - decodes properties | ||
| Returns: | ||
| SZ_OK | ||
| SZ_ERROR_UNSUPPORTED - Unsupported properties | ||
| */ | ||
|
|
||
| SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size); | ||
|
|
||
|
|
||
| /* ---------- LZMA Decoder state ---------- */ | ||
|
|
||
| /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case. | ||
| Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */ | ||
|
|
||
| #define LZMA_REQUIRED_INPUT_MAX 20 | ||
|
|
||
| typedef struct | ||
| { | ||
| /* Don't change this structure. ASM code can use it. */ | ||
| CLzmaProps prop; | ||
| CLzmaProb *probs; | ||
| CLzmaProb *probs_1664; | ||
| Byte *dic; | ||
| SizeT dicBufSize; | ||
| SizeT dicPos; | ||
| const Byte *buf; | ||
| UInt32 range; | ||
| UInt32 code; | ||
| UInt32 processedPos; | ||
| UInt32 checkDicSize; | ||
| UInt32 reps[4]; | ||
| UInt32 state; | ||
| UInt32 remainLen; | ||
|
|
||
| UInt32 numProbs; | ||
| unsigned tempBufSize; | ||
| Byte tempBuf[LZMA_REQUIRED_INPUT_MAX]; | ||
| } CLzmaDec; | ||
|
|
||
| #define LzmaDec_Construct(p) { (p)->dic = NULL; (p)->probs = NULL; } | ||
|
|
||
| void LzmaDec_Init(CLzmaDec *p); | ||
|
|
||
| /* There are two types of LZMA streams: | ||
| - Stream with end mark. That end mark adds about 6 bytes to compressed size. | ||
| - Stream without end mark. You must know exact uncompressed size to decompress such stream. */ | ||
|
|
||
| typedef enum | ||
| { | ||
| LZMA_FINISH_ANY, /* finish at any point */ | ||
| LZMA_FINISH_END /* block must be finished at the end */ | ||
| } ELzmaFinishMode; | ||
|
|
||
| /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!! | ||
| You must use LZMA_FINISH_END, when you know that current output buffer | ||
| covers last bytes of block. In other cases you must use LZMA_FINISH_ANY. | ||
| If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK, | ||
| and output value of destLen will be less than output buffer size limit. | ||
| You can check status result also. | ||
| You can use multiple checks to test data integrity after full decompression: | ||
| 1) Check Result and "status" variable. | ||
| 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. | ||
| 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. | ||
| You must use correct finish mode in that case. */ | ||
|
|
||
| typedef enum | ||
| { | ||
| LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */ | ||
| LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ | ||
| LZMA_STATUS_NOT_FINISHED, /* stream was not finished */ | ||
| LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */ | ||
| LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */ | ||
| } ELzmaStatus; | ||
|
|
||
| /* ELzmaStatus is used only as output value for function call */ | ||
|
|
||
|
|
||
| /* ---------- Interfaces ---------- */ | ||
|
|
||
| /* There are 3 levels of interfaces: | ||
| 1) Dictionary Interface | ||
| 2) Buffer Interface | ||
| 3) One Call Interface | ||
| You can select any of these interfaces, but don't mix functions from different | ||
| groups for same object. */ | ||
|
|
||
|
|
||
| /* There are two variants to allocate state for Dictionary Interface: | ||
| 1) LzmaDec_Allocate / LzmaDec_Free | ||
| 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs | ||
| You can use variant 2, if you set dictionary buffer manually. | ||
| For Buffer Interface you must always use variant 1. | ||
| LzmaDec_Allocate* can return: | ||
| SZ_OK | ||
| SZ_ERROR_MEM - Memory allocation error | ||
| SZ_ERROR_UNSUPPORTED - Unsupported properties | ||
| */ | ||
|
|
||
| SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc); | ||
| void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc); | ||
|
|
||
| SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc); | ||
| void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc); | ||
|
|
||
| /* ---------- Dictionary Interface ---------- */ | ||
|
|
||
| /* You can use it, if you want to eliminate the overhead for data copying from | ||
| dictionary to some other external buffer. | ||
| You must work with CLzmaDec variables directly in this interface. | ||
| STEPS: | ||
| LzmaDec_Construct() | ||
| LzmaDec_Allocate() | ||
| for (each new stream) | ||
| { | ||
| LzmaDec_Init() | ||
| while (it needs more decompression) | ||
| { | ||
| LzmaDec_DecodeToDic() | ||
| use data from CLzmaDec::dic and update CLzmaDec::dicPos | ||
| } | ||
| } | ||
| LzmaDec_Free() | ||
| */ | ||
|
|
||
| /* LzmaDec_DecodeToDic | ||
| The decoding to internal dictionary buffer (CLzmaDec::dic). | ||
| You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!! | ||
| finishMode: | ||
| It has meaning only if the decoding reaches output limit (dicLimit). | ||
| LZMA_FINISH_ANY - Decode just dicLimit bytes. | ||
| LZMA_FINISH_END - Stream must be finished after dicLimit. | ||
| Returns: | ||
| SZ_OK | ||
| status: | ||
| LZMA_STATUS_FINISHED_WITH_MARK | ||
| LZMA_STATUS_NOT_FINISHED | ||
| LZMA_STATUS_NEEDS_MORE_INPUT | ||
| LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK | ||
| SZ_ERROR_DATA - Data error | ||
| */ | ||
|
|
||
| SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, | ||
| const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status, SizeT memlimit); | ||
|
|
||
|
|
||
| /* ---------- Buffer Interface ---------- */ | ||
|
|
||
| /* It's zlib-like interface. | ||
| See LzmaDec_DecodeToDic description for information about STEPS and return results, | ||
| but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need | ||
| to work with CLzmaDec variables manually. | ||
| finishMode: | ||
| It has meaning only if the decoding reaches output limit (*destLen). | ||
| LZMA_FINISH_ANY - Decode just destLen bytes. | ||
| LZMA_FINISH_END - Stream must be finished after (*destLen). | ||
| */ | ||
|
|
||
| SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, | ||
| const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status, SizeT memlimit); | ||
|
|
||
|
|
||
| /* ---------- One Call Interface ---------- */ | ||
|
|
||
| /* LzmaDecode | ||
| finishMode: | ||
| It has meaning only if the decoding reaches output limit (*destLen). | ||
| LZMA_FINISH_ANY - Decode just destLen bytes. | ||
| LZMA_FINISH_END - Stream must be finished after (*destLen). | ||
| Returns: | ||
| SZ_OK | ||
| status: | ||
| LZMA_STATUS_FINISHED_WITH_MARK | ||
| LZMA_STATUS_NOT_FINISHED | ||
| LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK | ||
| SZ_ERROR_DATA - Data error | ||
| SZ_ERROR_MEM - Memory allocation error | ||
| SZ_ERROR_UNSUPPORTED - Unsupported properties | ||
| SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). | ||
| */ | ||
|
|
||
| SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, | ||
| const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, | ||
| ELzmaStatus *status, ISzAllocPtr alloc); | ||
|
|
||
| EXTERN_C_END | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
|
|
||
| h_sources = LzmaDec.h 7zTypes.h | ||
|
|
||
| h_sources_private = LzFind.h LzHash.h Compiler.h Precomp.h | ||
|
|
||
| c_sources = LzFind.c LzmaDec.c | ||
|
|
||
| AM_CFLAGS = -I$(top_srcdir) -D_GNU_SOURCE -g -Wall -Wextra -std=gnu99 -pedantic \ | ||
| -Wextra -Wno-missing-field-initializers -Wshadow -Wpointer-arith \ | ||
| -Wstrict-prototypes -Wmissing-prototypes -Wno-unused-parameter | ||
|
|
||
| library_includedir = $(includedir)/$(GENERIC_LIBRARY_NAME)/lzma | ||
| library_include_HEADERS = $(h_sources) | ||
|
|
||
| noinst_LTLIBRARIES = liblzma-c.la | ||
| liblzma_c_la_SOURCES = $(h_sources) $(h_sources_private) $(c_sources) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /* Precomp.h -- StdAfx | ||
| 2013-11-12 : Igor Pavlov : Public domain */ | ||
|
|
||
| #ifndef __7Z_PRECOMP_H | ||
| #define __7Z_PRECOMP_H | ||
|
|
||
| #include "Compiler.h" | ||
| /* #include "7zTypes.h" */ | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| >>> | ||
| POST / HTTP/1.1 | ||
| Host: localhost | ||
| Content-Type: application/x-www-form-urlencoded | ||
|
|
||
| login=foo&password=bar | ||
| <<< | ||
| HTTP/1.1 200 OK | ||
| Content-Length: 0 | ||
|
|
||
|
|
||
| >>> | ||
| GET / HTTP/1.1 | ||
| Host: localhost | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| >>> | ||
| GET / | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import sys | ||
| import binascii | ||
|
|
||
| # Transforms a pcap into a test file for libhtp | ||
| # tshark -Tfields -e tcp.dstport -e tcp.payload -r input.pcap > input.txt | ||
| # python pcaptohtp.py input.txt > input.t | ||
|
|
||
| f = open(sys.argv[1]) | ||
| for l in f.readlines(): | ||
| portAndPl=l.split() | ||
| if len(portAndPl) == 2: | ||
| # determine request or response based on port | ||
| if portAndPl[0] == "80": | ||
| print(">>>") | ||
| else: | ||
| print("<<<") | ||
| print(binascii.unhexlify(portAndPl[1].replace(":",""))) |