├── .gitattributes ├── .gitignore ├── .vscode └── settings.json ├── Config ├── Project_compile.props ├── Project_optimize.props ├── Project_paths.props └── WinPCK_Includes.props ├── Documents ├── test_script.txt ├── test_script8.txt └── test_scriptU.txt ├── MiscFuncs ├── AllocMemPool.cpp ├── AllocMemPool.h ├── COpenFileListener.cpp ├── COpenFileListener.h ├── CharsCodeConv.cpp ├── CharsCodeConv.h ├── GetDragPath.cpp ├── GetDragPath.h ├── OpenSaveDlg.cpp ├── OpenSaveDlg.h ├── Raw2HexString.cpp ├── Raw2HexString.h ├── StopWatch.cpp ├── StopWatch.h ├── TextLineSpliter.cpp └── TextLineSpliter.h ├── PckDll ├── DictHash │ ├── DictHash.cpp │ └── DictHash.h ├── MapViewFile │ ├── MapViewFile.cpp │ ├── MapViewFile.h │ ├── MapViewFileMulti.cpp │ ├── MapViewFileMulti.h │ ├── MapViewFileMultiPck.cpp │ ├── MapViewFileMultiPck.h │ ├── MapViewFileMultiPckRead.cpp │ ├── MapViewFileMultiPckWrite.cpp │ ├── MapViewFileMultiRead.cpp │ ├── MapViewFileMultiWrite.cpp │ ├── MapViewFileRead.cpp │ └── MapViewFileWrite.cpp ├── PckClass │ ├── PckAlgorithmId.cpp │ ├── PckAlgorithmId.h │ ├── PckClass.cpp │ ├── PckClass.h │ ├── PckClassAppendFiles.cpp │ ├── PckClassBaseFeatures.cpp │ ├── PckClassBaseFeatures.h │ ├── PckClassCodepage.cpp │ ├── PckClassCodepage.h │ ├── PckClassExtract.cpp │ ├── PckClassFileDisk.cpp │ ├── PckClassFileDisk.h │ ├── PckClassHeadTail.cpp │ ├── PckClassHeadTail.h │ ├── PckClassHeadTailWriter.cpp │ ├── PckClassHeadTailWriter.h │ ├── PckClassIndex.cpp │ ├── PckClassIndex.h │ ├── PckClassIndexRead.cpp │ ├── PckClassIndexWriter.cpp │ ├── PckClassIndexWriter.h │ ├── PckClassLog.cpp │ ├── PckClassLog.h │ ├── PckClassMount.cpp │ ├── PckClassNode.cpp │ ├── PckClassNode.h │ ├── PckClassRebuild.cpp │ ├── PckClassRebuildFilter.cpp │ ├── PckClassRebuildFilter.h │ ├── PckClassRenamer.cpp │ ├── PckClassVersionDetect.cpp │ ├── PckClassVersionDetect.h │ ├── PckClassVersionFillDataTemplate.h │ ├── PckClassWriteOperator.h │ ├── PckClassZlib.cpp │ ├── PckClassZlib.h │ ├── PckDefines.h │ ├── PckHeader.h │ ├── PckIndexCache.cpp │ ├── PckIndexCache.h │ ├── PckModelStrip.cpp │ ├── PckModelStrip.h │ ├── PckModelStripDefines.h │ ├── PckStructs.h │ ├── PckThreadRunner.cpp │ ├── PckThreadRunner.h │ ├── PckThreadRunnerData.cpp │ ├── PckThreadRunnerMemory.cpp │ └── PckThreadRunnerQueue.cpp ├── PckControlCenter │ ├── PckControlCenter.cpp │ ├── PckControlCenter.h │ ├── PckControlCenterAttribute.cpp │ ├── PckControlCenterInterface.cpp │ ├── PckControlCenterOperation.cpp │ └── PckControlCenterParams.cpp ├── WinPCK_dll - copy.vcxproj ├── WinPCK_dll.common.settings ├── WinPCK_dll.vcxproj ├── WinPCK_dll.vcxproj.filters ├── ZupClass │ ├── ZupClass.cpp │ ├── ZupClass.h │ ├── ZupClassExtract.cpp │ ├── ZupClassFunction.cpp │ └── ZupHeader.h ├── icons │ ├── Thumbs.db │ ├── chinaz1.png │ ├── chinaz1x.ico │ ├── filefind.ico │ ├── logerror.png │ ├── loginfo.png │ └── logwarning.png ├── include │ ├── compiler.h │ ├── compiler_gcc.h │ ├── compiler_msc.h │ ├── gccException.h │ ├── msvc_conf.h │ ├── pck_default_vars.h │ ├── pck_dependencies.h │ └── pck_handle.h ├── pckdll.rc ├── resource.h └── src │ └── pck_handle.cpp ├── README.md ├── Release └── pckdll_x64.lib ├── VC-LTL └── VC-LTL helper for Visual Studio.props ├── WinPCK ├── MenuButtonFuncs.cpp ├── ShowLogOnDlgListView.cpp ├── ShowLogOnDlgListView.h ├── WinPCK.rc ├── WinPCK_2022.common.settings ├── WinPCK_2022.vcxproj ├── WinPCK_2022.vcxproj.filters ├── X86-64.manifest ├── decode_dds │ ├── BlendPicture.cpp │ ├── DDS.h │ ├── DDSTextureLoader.cpp │ ├── DDSTextureLoader.h │ ├── DdsTgaDecoder.cpp │ ├── DdsTgaDecoder.h │ ├── DdsTgaDecoderBuildDIB.cpp │ ├── DdsTgaDecoderDefine.h │ ├── DdsTgaDecoderDetectFormat.cpp │ ├── DrawPicture.cpp │ ├── SavePicture.cpp │ ├── ShowPicture.cpp │ ├── ShowPicture.h │ ├── ShowPictureWithZoom.cpp │ ├── ShowPictureWithZoom.h │ └── dxgiformat.h ├── globals.h ├── guirelated.cpp ├── helpfunc.cpp ├── icons │ ├── DROP.cur │ ├── Thumbs.db │ ├── chinaz1.ico │ ├── chinaz1.png │ ├── chinaz1x.ico │ ├── dir.ico │ ├── edit.ico │ ├── edit_add.ico │ ├── exit.ico │ ├── file.ico │ ├── fileclose.ico │ ├── filenew.ico │ ├── fileopen.ico │ ├── filesave.ico │ ├── info.ico │ ├── lin_agt_wrench.ico │ ├── logdebug.ico │ ├── logerror.ico │ ├── logerror.png │ ├── loginfo.ico │ ├── loginfo.png │ ├── logwarning.ico │ ├── logwarning.png │ ├── rebuild.ico │ ├── save_all.ico │ ├── search.ico │ └── stop.ico ├── ini.h ├── listViewFunc.cpp ├── mainControlStatus.cpp ├── mainfunc.cpp ├── miscdlg.h ├── resource.h ├── tAttrDlg.cpp ├── tCompressOptDlg.cpp ├── tInfoDlg.cpp ├── tLogDlg.cpp ├── tLogDlg.h ├── tPicDlg.cpp ├── tPreviewDlg.cpp ├── tPreviewDlg.h ├── tRebuildOptDlg.cpp ├── tSearchDlg.cpp ├── tStripDlg.cpp ├── tViewDlg.cpp ├── threadproc.cpp ├── winmain.cpp └── winmain.h ├── WinPCK_2022.sln ├── base64 ├── base64.cpp ├── base64.h ├── base64_2022.vcxproj ├── base64_2022.vcxproj.filters ├── base64_decoder.cpp └── base64_encoder.cpp ├── dlltester ├── dlltester.cpp ├── dlltester.vcxproj ├── dlltester.vcxproj.filters ├── pch.cpp └── pch.h ├── libdeflate ├── .gitignore ├── COPYING ├── Makefile ├── Makefile.msc ├── NEWS ├── README.md ├── common │ ├── common_defs.h │ ├── compiler_gcc.h │ ├── compiler_msc.h │ └── msvc_conf.h ├── lib │ ├── adler32.c │ ├── adler32_vec_template.h │ ├── aligned_malloc.c │ ├── aligned_malloc.h │ ├── arm │ │ ├── adler32_impl.h │ │ ├── cpu_features.c │ │ ├── cpu_features.h │ │ ├── crc32_impl.h │ │ └── matchfinder_impl.h │ ├── bt_matchfinder.h │ ├── crc32.c │ ├── crc32_table.h │ ├── crc32_vec_template.h │ ├── decompress_template.h │ ├── deflate_compress.c │ ├── deflate_compress.h │ ├── deflate_constants.h │ ├── deflate_decompress.c │ ├── gzip_compress.c │ ├── gzip_constants.h │ ├── gzip_decompress.c │ ├── hc_matchfinder.h │ ├── lib_common.h │ ├── matchfinder_common.h │ ├── unaligned.h │ ├── x86 │ │ ├── adler32_impl.h │ │ ├── adler32_impl_msvc.h │ │ ├── cpu_features.c │ │ ├── cpu_features.h │ │ ├── crc32_impl.h │ │ ├── crc32_pclmul_template.h │ │ ├── decompress_impl.h │ │ └── matchfinder_impl.h │ ├── zlib_compress.c │ ├── zlib_constants.h │ └── zlib_decompress.c ├── libdeflate.h ├── libdeflate_2022.sln ├── libdeflate_2022.vcxproj ├── libdeflate_2022.vcxproj.filters ├── programs │ ├── benchmark.c │ ├── checksum.c │ ├── detect.sh │ ├── gzip.c │ ├── prog_util.c │ ├── prog_util.h │ ├── test_checksums.c │ ├── test_incomplete_codes.c │ ├── test_slow_decompression.c │ ├── test_util.c │ ├── test_util.h │ └── tgetopt.c └── tools │ ├── afl-fuzz │ ├── Makefile │ ├── deflate_compress │ │ ├── fuzz.c │ │ └── inputs │ │ │ └── 0 │ ├── deflate_decompress │ │ ├── fuzz.c │ │ └── inputs │ │ │ └── 0 │ ├── gzip_decompress │ │ ├── fuzz.c │ │ └── inputs │ │ │ └── 0 │ ├── prepare_for_fuzz.sh │ └── zlib_decompress │ │ ├── fuzz.c │ │ └── inputs │ │ └── 0 │ ├── android_build.sh │ ├── checksum_benchmarks.sh │ ├── exec_tests.sh │ ├── gen_crc32_multipliers.c │ ├── gen_crc32_table.c │ ├── gzip_tests.sh │ ├── make-windows-releases │ ├── mips_build.sh │ ├── msc_test.bat │ ├── pgo_build.sh │ ├── produce_gzip_benchmark_table.sh │ ├── run_tests.sh │ └── windows_build.sh ├── tlib ├── tDebug.h ├── tapi32ex.cpp ├── tapi32ex.h ├── tapi32u8.cpp ├── tapi32u8.h ├── tapp.cpp ├── tconf.h ├── tdlg.cpp ├── tini.cpp ├── tini.h ├── tlib.h ├── tlist.cpp ├── tlist.h ├── tmisc.cpp ├── tregist.cpp ├── tregist.h └── twin.cpp └── zlib ├── adler32.c ├── compress.c ├── contrib ├── README.contrib ├── amd64 │ └── amd64-match.S ├── asm686 │ ├── README.686 │ └── match.S ├── inflate86 │ ├── inffas86.c │ └── inffast.S ├── masmx64 │ ├── gvmat64.asm │ ├── inffas8664.c │ └── inffasx64.asm └── masmx86 │ ├── inffas32.asm │ └── match686.asm ├── crc32.c ├── crc32.h ├── deflate.c ├── deflate.h ├── gzguts.h ├── infback.c ├── inffast.c ├── inffast.h ├── inffixed.h ├── inflate.c ├── inflate.h ├── inftrees.c ├── inftrees.h ├── trees.c ├── trees.h ├── uncompr.c ├── zconf.h ├── zlib.h ├── zlib_2022.vcxproj ├── zlib_2022.vcxproj.filters ├── zutil.c └── zutil.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | 18 | # Fortran module files 19 | *.mod 20 | *.smod 21 | 22 | # Compiled Static libraries 23 | *.lai 24 | *.la 25 | *.a 26 | 27 | # Executables 28 | *.out 29 | *.app 30 | 31 | *.tlog 32 | *.lastbuildstate 33 | *.log 34 | *.idb 35 | *.VC.db 36 | *.ipch 37 | *.iobj 38 | *.ipdb 39 | 40 | *.aps 41 | .vs/* 42 | build/* 43 | Debug/* 44 | Release/*.pdb 45 | Release_static/*.pdb 46 | Release/libs/* 47 | Release_static/libs/* 48 | Release/dlltester_*.exe 49 | *.user 50 | *.exp 51 | *.rar 52 | *.pdb 53 | /Release/dlltester_x64.pdb 54 | /Release/pckdll_x64.dll 55 | /Release/pckdll_x64.pdb 56 | /Release/pckdll_x86.dll 57 | /Release/pckdll_x86.lib 58 | /Release/WinPCK_x64.exe 59 | /Release/WinPCK_x64.pdb 60 | /Release/WinPCK_x86.exe 61 | *.dll 62 | /Release_static/WinPCK_x64.exe 63 | /Release_static/WinPCK_x64.pdb 64 | *.exe 65 | /WinPCK/pck.ini 66 | pck.ini 67 | /Release/pck.ini 68 | /Release_static/pck.ini 69 | /Debug/pck.ini 70 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.embeddedhtml": "html", 4 | "vector": "cpp" 5 | } 6 | } -------------------------------------------------------------------------------- /Config/Project_compile.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | true 7 | 8 | NoListing 9 | 10 | ProgramDatabase 11 | 12 | MultiThreaded 13 | 14 | false 15 | 16 | 17 | 18 | false 19 | 20 | false 21 | 22 | true 23 | 24 | 25 | -------------------------------------------------------------------------------- /Config/Project_optimize.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | true 6 | false 7 | 8 | true 9 | 10 | 11 | 12 | true 13 | 14 | Full 15 | 16 | Speed 17 | 18 | true 19 | 20 | true 21 | 22 | true 23 | 24 | true 25 | 26 | true 27 | 28 | false 29 | 30 | false 31 | 32 | Fast 33 | 34 | 35 | 36 | true 37 | 38 | true 39 | 40 | 41 | 42 | 43 | 44 | StreamingSIMDExtensions2 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Config/Project_paths.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | false 5 | VS2022 6 | 7 | build 8 | 9 | true 10 | false 11 | 12 | 13 | $(SolutionDir)\$(Configuration)\$(VSPlatformName)\ 14 | $(SolutionDir)\$(Configuration)\$(VSPlatformName)\libs\$(PlatformShortName)\ 15 | $(SolutionDir)\$(IntDirName)\$(VSPlatformName)\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ 16 | $(ProjectName)_$(PlatformShortName) 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Config/WinPCK_Includes.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(SolutionDir)PckDll\include;$(SolutionDir)PckDll\PckClass;$(SolutionDir)MiscFuncs;$(ProjectDir)decode_dds;$(SolutionDir)tlib;$(ProjectDir); 5 | $(SolutionDir)MiscFuncs;$(ProjectDir)include;$(ProjectDir)DictHash;$(ProjectDir)PckClass;$(ProjectDir)PckControlCenter;$(ProjectDir)ZupClass;$(SolutionDir)zlib;$(ProjectDir)base64;$(ProjectDir)MapViewFile;$(ProjectDir);$(SolutionDir)libdeflate; 6 | 7 | $(IncludePath);$(WinPCK_Include) 8 | $(IncludePath);$(WinPCK_Include) 9 | $(IncludePath);$(PCKDLL_Include) 10 | 11 | 12 | 13 | 14 | 16Bytes 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Documents/test_script.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/Documents/test_script.txt -------------------------------------------------------------------------------- /Documents/test_scriptU.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/Documents/test_scriptU.txt -------------------------------------------------------------------------------- /MiscFuncs/AllocMemPool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "AllocMemPool.h" 3 | #include 4 | 5 | CAllocMemPool::CAllocMemPool(size_t _PoolSize) : 6 | m_EachPoolSize(_PoolSize) 7 | { 8 | m_pFirstNode = new_Node(); 9 | } 10 | 11 | CAllocMemPool::~CAllocMemPool() 12 | { 13 | Node* pNode = m_pFirstNode; 14 | Node* pNextNode = nullptr; 15 | // sequential release 16 | while (pNode) 17 | { 18 | pNextNode = pNode->next; 19 | free(pNode); 20 | pNode = pNextNode; 21 | } 22 | } 23 | 24 | // Apply for node 25 | CAllocMemPool::Node* CAllocMemPool::new_Node() 26 | { 27 | Node* pointer = reinterpret_cast(malloc(m_EachPoolSize)); 28 | //pointer->Node::Node(); 29 | memset(pointer, 0, m_EachPoolSize); 30 | 31 | return pointer; 32 | } 33 | 34 | 35 | void* CAllocMemPool::Alloc(size_t size, uint32_t align) { 36 | if (size > (m_EachPoolSize - sizeof(Node))) { 37 | #ifdef _DEBUG 38 | assert(!"::Alloc>:: Alloc too big"); 39 | #endif 40 | return nullptr; 41 | } 42 | // Get free position 43 | auto* now_pos = m_pFirstNode->buffer + m_pFirstNode->allocated; 44 | // Get the aligned position 45 | auto aligned = (reinterpret_cast(now_pos)& (align - 1)); 46 | if (aligned) aligned = align - aligned; 47 | now_pos += aligned; 48 | // increase count 49 | m_pFirstNode->allocated += size + aligned; 50 | // Check for overflow 51 | if (m_pFirstNode->allocated > (m_EachPoolSize - sizeof(Node))) { 52 | Node* node = new_Node(); 53 | if (!node) return nullptr; 54 | node->next = m_pFirstNode; 55 | m_pFirstNode = node; 56 | // Recursion (only once) 57 | return Alloc(size, align); 58 | } 59 | // Record the last release position 60 | m_pFirstNode->last_allocated = now_pos; 61 | return now_pos; 62 | } 63 | 64 | // free memory 65 | void CAllocMemPool::Free(void* address) { 66 | // This is what I applied for last time. 67 | if (address && m_pFirstNode->last_allocated == address) { 68 | m_pFirstNode->allocated = 69 | (m_pFirstNode->last_allocated - m_pFirstNode->buffer); 70 | m_pFirstNode->last_allocated = nullptr; 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /MiscFuncs/AllocMemPool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | source code from: 5 | https://blog.csdn.net/dustpg/article/details/38756241 6 | */ 7 | #pragma warning ( disable : 4200 ) 8 | #include 9 | 10 | class CAllocMemPool 11 | { 12 | // node 13 | struct Node { 14 | // posterior node 15 | Node* next = nullptr; 16 | // Allocated quantity 17 | size_t allocated = 0; 18 | // Last assigned position 19 | uint8_t* last_allocated = nullptr; 20 | // buffer 21 | uint8_t buffer[0]; 22 | }; 23 | 24 | public: 25 | CAllocMemPool(size_t _PoolSize); 26 | ~CAllocMemPool(); 27 | 28 | // Apply for memory 29 | void* Alloc(size_t size, uint32_t align = sizeof(size_t)); 30 | // free memory 31 | void Free(void* address); 32 | 33 | private: 34 | 35 | // Apply for node 36 | __forceinline Node* new_Node(); 37 | // first node 38 | Node* m_pFirstNode; 39 | 40 | size_t m_EachPoolSize; 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /MiscFuncs/COpenFileListener.cpp: -------------------------------------------------------------------------------- 1 | #include "COpenFileListener.h" 2 | 3 | STDMETHODIMP COpenFileListener::OnFileOk(IFileDialog* pfd) 4 | { 5 | IShellItemArray *psiaResults; 6 | HRESULT hr; 7 | IFileOpenDialog *fod; 8 | 9 | hr = pfd->QueryInterface(IID_PPV_ARGS(&fod)); 10 | 11 | if(SUCCEEDED(hr)) { 12 | hr = fod->GetSelectedItems(&psiaResults); 13 | 14 | if (SUCCEEDED(hr)) { 15 | DWORD fileCount; 16 | IShellItem *isi; 17 | LPWSTR pwsz = NULL; 18 | 19 | psiaResults->GetCount(&fileCount); 20 | for(DWORD i=0;iGetItemAt(i,&isi); 22 | isi->GetDisplayName(SIGDN_FILESYSPATH,&pwsz); 23 | isi->Release(); 24 | #ifdef UNICODE 25 | wcscpy_s(pFilePath, MAX_PATH, pwsz); 26 | #else 27 | WideCharToMultiByte(CP_ACP, 0, pwsz, -1, pFilePath, MAX_PATH, "_", 0); 28 | #endif 29 | CoTaskMemFree(pwsz); 30 | } 31 | psiaResults->Release(); 32 | } 33 | fod->Release(); 34 | } 35 | 36 | return S_OK; 37 | } 38 | 39 | 40 | COpenFileListener::COpenFileListener(TCHAR *pFilePath) 41 | { 42 | m_cRef = 0L; 43 | this->pFilePath = pFilePath; 44 | } 45 | 46 | COpenFileListener::~COpenFileListener() 47 | { 48 | } 49 | 50 | STDMETHODIMP COpenFileListener::QueryInterface(REFIID riid, LPVOID *ppv) 51 | { 52 | *ppv = NULL; 53 | 54 | if (IsEqualIID(riid, IID_IFileDialogEvents) || IsEqualIID(riid, IID_IUnknown)) 55 | { 56 | *ppv = (IFileDialogEvents *)this; 57 | } 58 | 59 | if (*ppv) 60 | { 61 | AddRef(); 62 | 63 | return NOERROR; 64 | } 65 | 66 | return E_NOINTERFACE; 67 | } 68 | 69 | STDMETHODIMP_(ULONG) COpenFileListener::AddRef() 70 | { 71 | return ++m_cRef; 72 | } 73 | 74 | STDMETHODIMP_(ULONG) COpenFileListener::Release() 75 | { 76 | if (--m_cRef) 77 | return m_cRef; 78 | 79 | delete this; 80 | 81 | return 0L; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /MiscFuncs/COpenFileListener.h: -------------------------------------------------------------------------------- 1 | #ifndef COPENFILELISTENER_H 2 | #define COPENFILELISTENER_H 3 | 4 | #include 5 | 6 | class COpenFileListener : public IFileDialogEvents 7 | { 8 | public: 9 | COpenFileListener(TCHAR *pFilePath); 10 | ~COpenFileListener(); 11 | 12 | STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *); 13 | STDMETHODIMP_(ULONG) AddRef(); 14 | STDMETHODIMP_(ULONG) Release(); 15 | 16 | TCHAR *pFilePath; 17 | 18 | // IFileDialogEvents 19 | 20 | STDMETHODIMP OnFileOk(IFileDialog* pfd); 21 | STDMETHODIMP OnFolderChanging(IFileDialog* pfd, IShellItem* psiFolder) {return E_NOTIMPL;} 22 | STDMETHODIMP OnFolderChange(IFileDialog* pfd) {return E_NOTIMPL;} 23 | STDMETHODIMP OnSelectionChange(IFileDialog* pfd) {return E_NOTIMPL;} 24 | STDMETHODIMP OnShareViolation(IFileDialog* pfd, IShellItem* psi, 25 | FDE_SHAREVIOLATION_RESPONSE* pResponse) {return E_NOTIMPL;} 26 | STDMETHODIMP OnTypeChange(IFileDialog* pfd) {return E_NOTIMPL;} 27 | STDMETHODIMP OnOverwrite(IFileDialog* pfd, IShellItem* psi, 28 | FDE_OVERWRITE_RESPONSE* pResponse) {return E_NOTIMPL;} 29 | private: 30 | ULONG m_cRef; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /MiscFuncs/GetDragPath.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | BOOL GetWndPath(HWND hWnd, wchar_t * szPath); -------------------------------------------------------------------------------- /MiscFuncs/OpenSaveDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/MiscFuncs/OpenSaveDlg.cpp -------------------------------------------------------------------------------- /MiscFuncs/OpenSaveDlg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | #ifdef _UNICODE 7 | #define tstring wstring 8 | #else 9 | #define tstring string 10 | #endif 11 | 12 | #define MAX_BUFFER_SIZE_OFN 0xFFFFF 13 | 14 | BOOL OpenFilesVistaUp(HWND hwnd, TCHAR lpszPathName[MAX_PATH]); 15 | BOOL OpenSingleFile(HWND hWnd, TCHAR * lpszFileName, LPCTSTR lpstrFilter = NULL, DWORD nFilterIndex = 1); 16 | BOOL OpenFiles(HWND hWnd, vector &lpszFilePathArray); 17 | int SaveFile(HWND hWnd, char * lpszFileName, LPCSTR lpszDefaultExt = NULL, LPCSTR lpstrFilter = NULL, DWORD nFilterIndex = 0); 18 | int SaveFile(HWND hWnd, wchar_t * lpszFileName, LPCWSTR lpszDefaultExt = NULL, LPCWSTR lpstrFilter = NULL, DWORD nFilterIndex = 0); 19 | 20 | #if 0 21 | BOOL BrowseForFolderByPath(HWND hWnd, TCHAR * lpszPathName); 22 | static int CALLBACK BFFCallBack(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData); 23 | #endif 24 | -------------------------------------------------------------------------------- /MiscFuncs/Raw2HexString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef int BOOL; 5 | 6 | #ifndef TRUE 7 | #define TRUE 1 8 | #define FALSE 0 9 | #endif 10 | 11 | class CRaw2HexString 12 | { 13 | //function 14 | public: 15 | //iShowStartAddr Change the starting value of the displayed address value 16 | CRaw2HexString(uint8_t* lpbuf, size_t rawlength, __int64 iShowStartAddr = 0); 17 | //CRaw2HexString(LPBYTE lpbuf, size_t rawlength, char *_dst, size_t _dstsize, __int64 iShowStartAddr = 0); 18 | //CRaw2HexString(LPBYTE lpbuf, size_t rawlength, wchar_t *_dst, size_t _dstsize, __int64 iShowStartAddr = 0); 19 | virtual ~CRaw2HexString(); 20 | 21 | const char *GetHexString(); 22 | private: 23 | 24 | char * m_buffer; 25 | BOOL m_ok; 26 | }; -------------------------------------------------------------------------------- /MiscFuncs/StopWatch.cpp: -------------------------------------------------------------------------------- 1 | #include "StopWatch.h" 2 | #include 3 | 4 | #define TIME_ELAPSED_STR "time %.2fms" 5 | #define TIME_ELAPSED_STRW L"time %.2fms" 6 | 7 | CStopWatch::CStopWatch() 8 | { 9 | m_start.QuadPart = 0; 10 | m_stop.QuadPart = 0; 11 | QueryPerformanceFrequency(&m_frequency); 12 | } 13 | 14 | void CStopWatch::start() 15 | { 16 | QueryPerformanceCounter(&m_start); 17 | } 18 | 19 | void CStopWatch::stop() 20 | { 21 | QueryPerformanceCounter(&m_stop); 22 | } 23 | 24 | double CStopWatch::getElapsedTime() 25 | { 26 | LARGE_INTEGER time; 27 | time.QuadPart = m_stop.QuadPart - m_start.QuadPart; 28 | return (double)time.QuadPart / (double)m_frequency.QuadPart * 1000; 29 | } 30 | 31 | #if 0 32 | const char * CStopWatch::getElapsedTimeStringA() 33 | { 34 | static char szTime[100]; 35 | sprintf_s(szTime, TIME_ELAPSED_STR, getElapsedTime()); 36 | return szTime; 37 | } 38 | 39 | const wchar_t * CStopWatch::getElapsedTimeStringW() 40 | { 41 | static wchar_t szTime[100]; 42 | swprintf_s(szTime, TIME_ELAPSED_STRW, getElapsedTime()); 43 | return szTime; 44 | } 45 | #endif -------------------------------------------------------------------------------- /MiscFuncs/StopWatch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #ifdef UNICODE 5 | #define getElapsedTimeString getElapsedTimeStringW 6 | #else 7 | #define getElapsedTimeString getElapsedTimeStringA 8 | #endif 9 | 10 | class CStopWatch 11 | { 12 | public: 13 | CStopWatch(); 14 | void start(); 15 | void stop(); 16 | double getElapsedTime(); //in s 17 | //const char * getElapsedTimeStringA(); 18 | //const wchar_t * getElapsedTimeStringW(); 19 | 20 | private: 21 | LARGE_INTEGER m_start; 22 | LARGE_INTEGER m_stop; 23 | LARGE_INTEGER m_frequency; 24 | }; 25 | -------------------------------------------------------------------------------- /MiscFuncs/TextLineSpliter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #define LINE_TRIM_LEFT 1 7 | #define LINE_TRIM_RIGHT 2 8 | #define LINE_EMPTY_DELETE 4 9 | 10 | template 11 | class CTextUnits 12 | { 13 | public: 14 | CTextUnits() {}; 15 | ~CTextUnits() {}; 16 | 17 | static void SplitLine(const T _src, std::vector& splitedLine, int flag); 18 | static void Split(const T& s, std::vector& v, const T& c, int flag = 0); 19 | static std::vector SplitRegEx(const T s, const T c, int flag = 0); 20 | 21 | private: 22 | 23 | static void GetEolChars(const std::string& _str, std::string& c); 24 | static void GetEolChars(const std::wstring& _str, std::wstring& c); 25 | static void ProcessLine(const T& newline, std::vector& v, int flag); 26 | 27 | }; 28 | 29 | 30 | template class CTextUnits; 31 | template class CTextUnits; 32 | 33 | typedef CTextUnits CTextUnitsA; 34 | typedef CTextUnits CTextUnitsW; 35 | -------------------------------------------------------------------------------- /PckDll/DictHash/DictHash.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // CDictHash.h: used to parse the data in the zup file of Perfect World Company 3 | // Decode zup's base64 dictionary hash table 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2012.4.10 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef _CDICTHASH_H_ 13 | #define _CDICTHASH_H_ 14 | 15 | #define HASH_TABLE_LENGTH 0xffff 16 | #define MAX_PATH_PCK 260 17 | 18 | 19 | typedef struct _ZUP_FILENAME_DICT { 20 | 21 | char base64str[MAX_PATH_PCK]; 22 | char realbase64str[MAX_PATH_PCK]; 23 | char realstr[MAX_PATH_PCK]; 24 | wchar_t wrealstr[MAX_PATH_PCK]; 25 | unsigned int realstrlength; 26 | unsigned int wrealstrlength; 27 | 28 | _ZUP_FILENAME_DICT *next; 29 | }ZUP_FILENAME_DICT, *LPZUP_FILENAME_DICT; 30 | 31 | class CDictHash 32 | { 33 | 34 | public: 35 | CDictHash(); 36 | virtual ~CDictHash(); 37 | 38 | LPZUP_FILENAME_DICT find(const char *keystr); 39 | 40 | LPZUP_FILENAME_DICT add(const char *keystr); 41 | 42 | 43 | protected: 44 | 45 | LPZUP_FILENAME_DICT *lpDictHashTable; 46 | 47 | LPZUP_FILENAME_DICT AllocNode(unsigned int sizeStuct); 48 | void Dealloc(LPZUP_FILENAME_DICT lpDictHash); 49 | 50 | }; 51 | 52 | #endif //_CDICTHASH_H_ -------------------------------------------------------------------------------- /PckDll/MapViewFile/MapViewFileMultiPck.cpp: -------------------------------------------------------------------------------- 1 | #include "MapViewFileMultiPck.h" 2 | 3 | 4 | CMapViewFileMultiPck::CMapViewFileMultiPck() 5 | {} 6 | 7 | CMapViewFileMultiPck::~CMapViewFileMultiPck() 8 | {} 9 | 10 | void CMapViewFileMultiPck::GetPkxPath(LPSTR lpszDest, LPCSTR lpszBaseName, UINT uiNum) 11 | { 12 | if (uiNum == 0) { 13 | sprintf(lpszDest, "%s.pkx", lpszBaseName); 14 | return; 15 | } 16 | 17 | sprintf(lpszDest, "%s.pkx%i", lpszBaseName, uiNum); 18 | } 19 | 20 | void CMapViewFileMultiPck::GetPkxPath(LPWSTR lpszDest, LPCWSTR lpszBaseName, UINT uiNum) 21 | { 22 | if (uiNum == 0) { 23 | swprintf(lpszDest, MAX_PATH, L"%ls.pkx", lpszBaseName); 24 | return; 25 | } 26 | 27 | swprintf(lpszDest, MAX_PATH, L"%ls.pkx%i", lpszBaseName, uiNum); 28 | } 29 | -------------------------------------------------------------------------------- /PckDll/MapViewFile/MapViewFileMultiPck.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MapViewFileMulti.h" 4 | 5 | #ifdef _DEBUG 6 | #define _TEST_MAX_PCK_CELL 0 7 | #else 8 | #define _TEST_MAX_PCK_CELL 0 9 | #endif 10 | 11 | class CMapViewFileMultiPck 12 | { 13 | public: 14 | CMapViewFileMultiPck(); 15 | ~CMapViewFileMultiPck(); 16 | 17 | //BOOL CheckPckPackSize(QWORD qwPckSize); 18 | 19 | protected: 20 | /** 21 | * @brief Returns the basename of the file. (path without file extension) 22 | * 23 | * @param lpszDest Destination buffer 24 | * @param lpszPckPath Path to the file (.pck file) 25 | */ 26 | inline void GetBaseName(LPSTR lpszDest, LPCSTR lpszPckPath) 27 | { 28 | SIZE_T ulLen = strrchr(lpszPckPath, '.') - lpszPckPath; 29 | strncpy(lpszDest, lpszPckPath, ulLen); 30 | lpszDest[ulLen] = '\0'; 31 | } 32 | 33 | inline void GetBaseName(LPWSTR lpszDest, LPCWSTR lpszPckPath) 34 | { 35 | SIZE_T ulLen = wcsrchr(lpszPckPath, L'.') - lpszPckPath; 36 | wcsncpy(lpszDest, lpszPckPath, ulLen); 37 | lpszDest[ulLen] = L'\0'; 38 | } 39 | 40 | /** 41 | * @brief Returns the .pkxN path. 42 | * 43 | * @param lpszDest Destination buffer 44 | * @param lpszBaseName Basename of the (.pck) file 45 | * @param uiNum The .pkx file number 46 | */ 47 | void GetPkxPath(LPSTR lpszDest, LPCSTR lpszBaseName, UINT uiNum); 48 | void GetPkxPath(LPWSTR lpszDest, LPCWSTR lpszBaseName, UINT uiNum); 49 | 50 | protected: 51 | //File size in PCK header structure 52 | UNQWORD m_uqwPckStructSize; 53 | }; 54 | 55 | 56 | class CMapViewFileMultiPckRead : 57 | public CMapViewFileMultiRead, 58 | public CMapViewFileMultiPck 59 | { 60 | public: 61 | CMapViewFileMultiPckRead(); 62 | ~CMapViewFileMultiPckRead(); 63 | 64 | BOOL OpenPck(LPCSTR lpszFilename); 65 | BOOL OpenPck(LPCWSTR lpszFilename); 66 | 67 | BOOL OpenPckAndMappingRead(LPCSTR lpFileName); 68 | BOOL OpenPckAndMappingRead(LPCWSTR lpFileName); 69 | 70 | //LPBYTE OpenMappingAndViewAllRead(LPCSTR lpFileName); 71 | //LPBYTE OpenMappingAndViewAllRead(LPCWSTR lpFileName); 72 | 73 | QWORD GetFileSize(); 74 | 75 | private: 76 | 77 | }; 78 | 79 | class CMapViewFileMultiPckWrite: 80 | public CMapViewFileMultiWrite, 81 | public CMapViewFileMultiPck 82 | { 83 | public: 84 | CMapViewFileMultiPckWrite(QWORD qwMaxPckSize); 85 | ~CMapViewFileMultiPckWrite(); 86 | 87 | BOOL OpenPck(LPCSTR lpszFilename, DWORD dwCreationDisposition, BOOL isNTFSSparseFile = FALSE); 88 | BOOL OpenPck(LPCWSTR lpszFilename, DWORD dwCreationDisposition, BOOL isNTFSSparseFile = FALSE); 89 | 90 | BOOL OpenPckAndMappingWrite(LPCSTR lpFileName, DWORD dwCreationDisposition, QWORD qdwSizeToMap, BOOL isNTFSSparseFile = FALSE); 91 | BOOL OpenPckAndMappingWrite(LPCWSTR lpFileName, DWORD dwCreationDisposition, QWORD qdwSizeToMap, BOOL isNTFSSparseFile = FALSE); 92 | 93 | private: 94 | 95 | QWORD m_Max_PckFile_Size; 96 | QWORD m_Max_PkxFile_Size; 97 | }; 98 | -------------------------------------------------------------------------------- /PckDll/MapViewFile/MapViewFileMultiPckRead.cpp: -------------------------------------------------------------------------------- 1 | #include "MapViewFileMultiPck.h" 2 | 3 | 4 | CMapViewFileMultiPckRead::CMapViewFileMultiPckRead() 5 | {} 6 | 7 | CMapViewFileMultiPckRead::~CMapViewFileMultiPckRead() 8 | {} 9 | 10 | BOOL CMapViewFileMultiPckRead::OpenPck(LPCSTR lpszFilename) 11 | { 12 | BOOL rtn = FALSE; 13 | 14 | // Reads the .pck file 15 | if (AddFile(lpszFilename)) { 16 | UINT uiNum = 0; 17 | CHAR lpszBaseName[MAX_PATH], lpszPkxPath[MAX_PATH]; 18 | 19 | GetBaseName(lpszBaseName, lpszFilename); 20 | 21 | // Then the .pkx files while they exist 22 | while (1) { 23 | GetPkxPath(lpszPkxPath, lpszBaseName, uiNum++); 24 | 25 | if (!AddFile(lpszPkxPath)) { 26 | SetLastError(NOERROR); 27 | break; 28 | } 29 | } 30 | 31 | rtn = TRUE; 32 | } 33 | 34 | m_uqwPckStructSize.qwValue = CMapViewFileMulti::GetFileSize(); 35 | 36 | return rtn; 37 | } 38 | 39 | BOOL CMapViewFileMultiPckRead::OpenPck(LPCWSTR lpszFilename) 40 | { 41 | BOOL rtn = FALSE; 42 | 43 | if (AddFile(lpszFilename)) { 44 | UINT uiNum = 0; 45 | WCHAR lpszBaseName[MAX_PATH], lpszPkxPath[MAX_PATH]; 46 | 47 | GetBaseName(lpszBaseName, lpszFilename); 48 | 49 | while (1) { 50 | GetPkxPath(lpszPkxPath, lpszBaseName, uiNum++); 51 | 52 | if (!AddFile(lpszPkxPath)) { 53 | SetLastError(NOERROR); 54 | break; 55 | } 56 | } 57 | 58 | rtn = TRUE; 59 | } 60 | 61 | m_uqwPckStructSize.qwValue = CMapViewFileMulti::GetFileSize(); 62 | 63 | return rtn; 64 | } 65 | 66 | BOOL CMapViewFileMultiPckRead::OpenPckAndMappingRead(LPCSTR lpFileName) 67 | { 68 | if(!(OpenPck(lpFileName))) 69 | return FALSE; 70 | 71 | if(!(Mapping())) 72 | return FALSE; 73 | 74 | return TRUE; 75 | } 76 | 77 | BOOL CMapViewFileMultiPckRead::OpenPckAndMappingRead(LPCWSTR lpFileName) 78 | { 79 | if(!(OpenPck(lpFileName))) 80 | return FALSE; 81 | 82 | if(!(Mapping())) 83 | return FALSE; 84 | 85 | return TRUE; 86 | } 87 | 88 | #if 0 89 | LPBYTE CMapViewFileMultiPckRead::OpenMappingAndViewAllRead(LPCSTR lpFileName) 90 | { 91 | if(OpenPckAndMappingRead(lpFileName)) 92 | return View(0, 0); 93 | else 94 | return NULL; 95 | } 96 | 97 | LPBYTE CMapViewFileMultiPckRead::OpenMappingAndViewAllRead(LPCWSTR lpFileName) 98 | { 99 | if(OpenPckAndMappingRead(lpFileName)) 100 | return View(0, 0); 101 | else 102 | return NULL; 103 | } 104 | #endif 105 | 106 | QWORD CMapViewFileMultiPckRead::GetFileSize() 107 | { 108 | return m_uqwPckStructSize.qwValue; 109 | } -------------------------------------------------------------------------------- /PckDll/MapViewFile/MapViewFileMultiPckWrite.cpp: -------------------------------------------------------------------------------- 1 | #include "MapViewFileMultiPck.h" 2 | 3 | #define PKX_FILES_LIMIT 5 // The maximum number of pre-created .pkx files 4 | 5 | #if _TEST_MAX_PCK_CELL 6 | CMapViewFileMultiPckWrite::CMapViewFileMultiPckWrite(QWORD qwMaxPckSize): 7 | //alcalm_Max_PckFile_Size(100 * 1024 * 1024) 8 | m_Max_PckFile_Size(100 * 1024 * 1024) 9 | {} 10 | #else 11 | CMapViewFileMultiPckWrite::CMapViewFileMultiPckWrite(QWORD qwMaxPckSize) : 12 | m_Max_PckFile_Size(qwMaxPckSize), 13 | m_Max_PkxFile_Size(0xfffffe00U) 14 | {} 15 | #endif 16 | 17 | 18 | CMapViewFileMultiPckWrite::~CMapViewFileMultiPckWrite() 19 | {} 20 | 21 | 22 | BOOL CMapViewFileMultiPckWrite::OpenPck(LPCSTR lpszFilename, DWORD dwCreationDisposition, BOOL isNTFSSparseFile) 23 | { 24 | BOOL rtn = FALSE; 25 | 26 | // Creates a .pck file first 27 | if (AddFile(lpszFilename, dwCreationDisposition, m_Max_PckFile_Size, isNTFSSparseFile)) { 28 | CHAR lpszBaseName[MAX_PATH], lpszPkxPath[MAX_PATH]; 29 | 30 | GetBaseName(lpszBaseName, lpszFilename); 31 | 32 | // Then creates .pkx files up to the limit 33 | for (UINT i = 0; i < PKX_FILES_LIMIT; ++i) { 34 | GetPkxPath(lpszPkxPath, lpszBaseName, i); 35 | 36 | if (!AddFile(lpszPkxPath, dwCreationDisposition, m_Max_PkxFile_Size, isNTFSSparseFile)) { 37 | goto fin; 38 | } 39 | } 40 | 41 | rtn = TRUE; 42 | } 43 | 44 | fin: 45 | m_uqwPckStructSize.qwValue = CMapViewFileMulti::GetFileSize(); 46 | 47 | return rtn; 48 | } 49 | 50 | //OPEN_ALWAYS, CREATE_ALWAYES, OPEN_EXISTING 51 | BOOL CMapViewFileMultiPckWrite::OpenPck(LPCWSTR lpszFilename, DWORD dwCreationDisposition, BOOL isNTFSSparseFile) 52 | { 53 | BOOL rtn = FALSE; 54 | 55 | if (AddFile(lpszFilename, dwCreationDisposition, m_Max_PckFile_Size, isNTFSSparseFile)) { 56 | WCHAR lpszBaseName[MAX_PATH], lpszPkxPath[MAX_PATH]; 57 | 58 | GetBaseName(lpszBaseName, lpszFilename); 59 | 60 | for (UINT i = 0; i < PKX_FILES_LIMIT; ++i) { 61 | GetPkxPath(lpszPkxPath, lpszBaseName, i); 62 | 63 | if (!AddFile(lpszPkxPath, dwCreationDisposition, m_Max_PkxFile_Size, isNTFSSparseFile)) { 64 | goto fin; 65 | } 66 | } 67 | 68 | rtn = TRUE; 69 | } 70 | 71 | fin: 72 | m_uqwPckStructSize.qwValue = CMapViewFileMulti::GetFileSize(); 73 | 74 | return rtn; 75 | } 76 | 77 | 78 | BOOL CMapViewFileMultiPckWrite::OpenPckAndMappingWrite(LPCSTR lpFileName, DWORD dwCreationDisposition, QWORD qdwSizeToMap, BOOL isNTFSSparseFile) 79 | { 80 | if(!OpenPck(lpFileName, dwCreationDisposition, isNTFSSparseFile)) 81 | return FALSE; 82 | 83 | if(!Mapping(qdwSizeToMap)) 84 | return FALSE; 85 | 86 | return TRUE; 87 | } 88 | 89 | BOOL CMapViewFileMultiPckWrite::OpenPckAndMappingWrite(LPCWSTR lpFileName, DWORD dwCreationDisposition, QWORD qdwSizeToMap, BOOL isNTFSSparseFile) 90 | { 91 | if(!OpenPck(lpFileName, dwCreationDisposition, isNTFSSparseFile)) 92 | return FALSE; 93 | 94 | if(!Mapping(qdwSizeToMap)) 95 | return FALSE; 96 | 97 | return TRUE; 98 | } 99 | -------------------------------------------------------------------------------- /PckDll/MapViewFile/MapViewFileMultiRead.cpp: -------------------------------------------------------------------------------- 1 | #include "MapViewFileMulti.h" 2 | #include "CharsCodeConv.h" 3 | 4 | CMapViewFileMultiRead::CMapViewFileMultiRead() 5 | {} 6 | 7 | CMapViewFileMultiRead::~CMapViewFileMultiRead() 8 | {} 9 | 10 | BOOL CMapViewFileMultiRead::AddFile(CMapViewFileRead *lpRead, LPCWSTR lpszFilename) 11 | { 12 | FILE_CELL cFileCell = {0}; 13 | 14 | wcscpy_s(cFileCell.szFilename, lpszFilename); 15 | cFileCell.lpMapView = lpRead; 16 | cFileCell.qwCellSize = lpRead->GetFileSize(); 17 | cFileCell.qwCellAddressBegin = m_uqwFullSize.qwValue; 18 | cFileCell.qwCellAddressEnd = m_uqwFullSize.qwValue + cFileCell.qwCellSize; 19 | cFileCell.qwMaxCellSize = cFileCell.qwCellSize; 20 | 21 | m_file_cell.push_back(cFileCell); 22 | 23 | m_uqwFullSize.qwValue += cFileCell.qwCellSize; 24 | m_uqwMaxSize.qwValue += cFileCell.qwCellSize; 25 | 26 | return TRUE; 27 | } 28 | 29 | BOOL CMapViewFileMultiRead::AddFile(LPCSTR lpszFilename) 30 | { 31 | CMapViewFileRead *lpRead = new CMapViewFileRead(); 32 | 33 | if(!lpRead->Open(lpszFilename)) { 34 | 35 | delete lpRead; 36 | return FALSE; 37 | } 38 | 39 | CAnsi2Ucs cA2U(CP_ACP); 40 | return AddFile(lpRead, cA2U.GetString(lpszFilename)); 41 | } 42 | 43 | BOOL CMapViewFileMultiRead::AddFile(LPCWSTR lpszFilename) 44 | { 45 | CMapViewFileRead *lpRead = new CMapViewFileRead(); 46 | 47 | if(!lpRead->Open(lpszFilename)) { 48 | 49 | delete lpRead; 50 | return FALSE; 51 | } 52 | return AddFile(lpRead, lpszFilename); 53 | } 54 | 55 | BOOL CMapViewFileMultiRead::Mapping() 56 | { 57 | size_t nCellCount = m_file_cell.size(); 58 | 59 | for(int i = 0;i < nCellCount;i++) { 60 | 61 | CMapViewFileRead *lpRead = (CMapViewFileRead*)m_file_cell[i].lpMapView; 62 | 63 | if(!lpRead->Mapping()) { 64 | return FALSE; 65 | } 66 | } 67 | return TRUE; 68 | } 69 | 70 | LPBYTE CMapViewFileMultiRead::View(QWORD dwAddress, DWORD dwSize) 71 | { 72 | return CMapViewFileMulti::View(dwAddress, dwSize, TRUE); 73 | } -------------------------------------------------------------------------------- /PckDll/MapViewFile/MapViewFileRead.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // MapViewFileRead.cpp: used to map file view (read) 3 | // 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2014.4.24 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #include "MapViewFile.h" 13 | 14 | CMapViewFileRead::CMapViewFileRead() 15 | {} 16 | 17 | CMapViewFileRead::~CMapViewFileRead() 18 | {} 19 | 20 | BOOL CMapViewFileRead::Open(LPCSTR lpszFilename) 21 | { 22 | return CMapViewFile::Open(lpszFilename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS); 23 | } 24 | 25 | BOOL CMapViewFileRead::Open(LPCWSTR lpszFilename) 26 | { 27 | return CMapViewFile::Open(lpszFilename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS); 28 | } 29 | 30 | BOOL CMapViewFileRead::Mapping() 31 | { 32 | if(NULL == (hFileMapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, GenerateMapName()))) { 33 | assert(FALSE); 34 | return FALSE; 35 | } 36 | 37 | return TRUE; 38 | } 39 | 40 | LPBYTE CMapViewFileRead::View(QWORD qdwAddress, DWORD dwSize) 41 | { 42 | return ViewReal(qdwAddress, dwSize, FILE_MAP_READ); 43 | } 44 | 45 | 46 | LPBYTE CMapViewFileRead::ReView(LPVOID lpMapAddressOld, QWORD dwAddress, DWORD dwSize) 47 | { 48 | UnmapView(lpMapAddressOld); 49 | return View(dwAddress, dwSize); 50 | } 51 | 52 | BOOL CMapViewFileRead::OpenMappingRead(LPCSTR lpFileName) 53 | { 54 | if(!(Open(lpFileName))) 55 | return FALSE; 56 | 57 | if(!(Mapping())) 58 | return FALSE; 59 | 60 | return TRUE; 61 | } 62 | 63 | BOOL CMapViewFileRead::OpenMappingRead(LPCWSTR lpFileName) 64 | { 65 | if(!(Open(lpFileName))) 66 | return FALSE; 67 | 68 | if(!(Mapping())) 69 | return FALSE; 70 | 71 | return TRUE; 72 | } 73 | 74 | LPBYTE CMapViewFileRead::OpenMappingViewAllRead(LPCSTR lpFileName) 75 | { 76 | if(OpenMappingRead(lpFileName)) 77 | return View(0, 0); 78 | else 79 | return NULL; 80 | } 81 | 82 | LPBYTE CMapViewFileRead::OpenMappingViewAllRead(LPCWSTR lpFileName) 83 | { 84 | if(OpenMappingRead(lpFileName)) 85 | return View(0, 0); 86 | else 87 | return NULL; 88 | } -------------------------------------------------------------------------------- /PckDll/PckClass/PckAlgorithmId.cpp: -------------------------------------------------------------------------------- 1 | #include "PckAlgorithmId.h" 2 | #include "pck_default_vars.h" 3 | #if PCK_DEBUG_OUTPUT 4 | #include "PckClassLog.h" 5 | #endif 6 | 7 | CPckAlgorithmId::CPckAlgorithmId(unsigned __int32 id, unsigned __int32 CustomPckGuardByte0, unsigned __int32 CustomPckGuardByte1, unsigned __int32 CustomPckMaskDword, unsigned __int32 CustomPckCheckMask) 8 | { 9 | SetAlgorithmId(id, CustomPckGuardByte0, CustomPckGuardByte1, CustomPckMaskDword, CustomPckCheckMask); 10 | } 11 | 12 | 13 | CPckAlgorithmId::~CPckAlgorithmId() 14 | {} 15 | 16 | void CPckAlgorithmId::SetAlgorithmId(unsigned __int32 id, unsigned __int32 CustomPckGuardByte0, unsigned __int32 CustomPckGuardByte1, unsigned __int32 CustomPckMaskDword, unsigned __int32 CustomPckCheckMask) 17 | { 18 | //0 Jade Dynasty, Perfect World 19 | //111 Hot Dance Party 20 | //121 Ether Saga Odyssey 21 | //131 Forsaken World 22 | //161 Saint Seiya, Swordsman Online 23 | 24 | switch (id) 25 | { 26 | case 111: 27 | PckGuardByte0 = 0xAB12908F; 28 | PckGuardByte1 = 0xB3231902; 29 | PckMaskDword = 0x2A63810E; 30 | PckCheckMask = 0x18734563; 31 | break; 32 | 33 | default: 34 | PckGuardByte0 = 0xFDFDFEEE + id * 0x72341F2; 35 | PckGuardByte1 = 0xF00DBEEF + id * 0x1237A73; 36 | //oficial 37 | PckMaskDword = 0xA8937462 + id * 0xAB2321F; //key1 38 | PckCheckMask = 0x59374231 + id * 0x987A223; //key2 39 | break; 40 | } 41 | 42 | if(CustomPckMaskDword != 0) 43 | PckMaskDword = CustomPckMaskDword; 44 | 45 | if(CustomPckCheckMask != 0) 46 | PckCheckMask = CustomPckCheckMask; 47 | 48 | if (CustomPckGuardByte0 != 0) 49 | PckGuardByte0 = CustomPckGuardByte0; 50 | 51 | if (CustomPckGuardByte1 != 0) 52 | PckGuardByte1 = CustomPckGuardByte1; 53 | } -------------------------------------------------------------------------------- /PckDll/PckClass/PckAlgorithmId.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/PckClass/PckAlgorithmId.h -------------------------------------------------------------------------------- /PckDll/PckClass/PckClass.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // PckClass.cpp: used to parse the data in the pck file of Perfect World Company and display it in the List 3 | // Initialization of related classes, etc. 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf. The pck structure refers to Ruoshui's pck structure.txt, and 6 | // Refer to the part of its Yi language code and read the pck file list 7 | // 8 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 9 | // 10 | // 2012.4.10 11 | ////////////////////////////////////////////////////////////////////// 12 | 13 | #include "PckClass.h" 14 | 15 | #pragma warning ( disable : 4996 ) 16 | #pragma warning ( disable : 4146 ) 17 | #pragma warning ( disable : 4267 ) 18 | 19 | CPckClass::CPckClass(LPPCK_RUNTIME_PARAMS inout) 20 | { 21 | m_lpPckParams = inout; 22 | m_zlib.init_compressor(m_lpPckParams->dwCompressLevel); 23 | } 24 | 25 | CPckClass::~CPckClass() 26 | { 27 | Logger.OutputVsIde(__FUNCTION__"\r\n"); 28 | } 29 | 30 | BOOL CPckClass::Init(LPCWSTR szFile) 31 | { 32 | wcscpy_s(m_PckAllInfo.szFilename, szFile); 33 | GetFileTitleW(m_PckAllInfo.szFilename, m_PckAllInfo.szFileTitle, MAX_PATH); 34 | 35 | if(!MountPckFile(m_PckAllInfo.szFilename)) { 36 | 37 | ResetPckInfos(); 38 | 39 | return FALSE; 40 | } else { 41 | 42 | BuildDirTree(); 43 | return (m_PckAllInfo.isPckFileLoaded = TRUE); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClass.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // PckClass.h: used to parse the data in the pck file of Perfect World Company and display it in the List 3 | // head File 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf. The pck structure refers to Ruoshui's pck structure.txt, and 6 | // Refer to the part of its Yi language code and read the pck file list 7 | // 8 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 9 | // 10 | // 2012.4.10 11 | ////////////////////////////////////////////////////////////////////// 12 | 13 | #include 14 | #include "pck_default_vars.h" 15 | 16 | #include "PckClassVersionDetect.h" 17 | #include "PckClassWriteOperator.h" 18 | 19 | #if !defined(_PCKCLASS_H_) 20 | #define _PCKCLASS_H_ 21 | 22 | class CPckClass : 23 | public virtual CPckClassWriteOperator, 24 | public virtual CPckClassVersionDetect 25 | { 26 | //function 27 | public: 28 | CPckClass(LPPCK_RUNTIME_PARAMS inout); 29 | virtual ~CPckClass(); 30 | 31 | virtual BOOL Init(const wchar_t * szFile); 32 | 33 | #pragma region PckClassExtract.cpp 34 | 35 | BOOL ExtractFiles(const PCK_UNIFIED_FILE_ENTRY **lpFileEntryArray, int nEntryCount, const wchar_t *lpszDestDirectory); 36 | BOOL ExtractAllFiles(const wchar_t *lpszDestDirectory); 37 | 38 | private: 39 | //unzip files 40 | BOOL ExtractFiles(const PCKINDEXTABLE **lpIndexToExtract, int nFileCount); 41 | BOOL ExtractFiles(const PCK_PATH_NODE **lpNodeToExtract, int nFileCount); 42 | 43 | public: 44 | //Preview file 45 | virtual BOOL GetSingleFileData(const PCKINDEXTABLE* const lpPckFileIndexTable, char *buffer, size_t sizeOfBuffer = 0); 46 | protected: 47 | virtual BOOL GetSingleFileData(LPVOID lpvoidFileRead, const PCKINDEXTABLE* const lpPckFileIndexTable, char *buffer, size_t sizeOfBuffer = 0); 48 | private: 49 | //PckClassExtract.cpp 50 | BOOL StartExtract(LPPCK_PATH_NODE lpNodeToExtract, LPVOID lpMapAddress); 51 | BOOL DecompressFile(const wchar_t * lpszFilename, const PCKINDEXTABLE* lpPckFileIndexTable, LPVOID lpvoidFileRead); 52 | #pragma endregion 53 | 54 | #pragma region PckClassMount.cpp 55 | protected: 56 | //PckClass.cpp 57 | BOOL MountPckFile(const wchar_t * szFile); 58 | private: 59 | void BuildDirTree(); 60 | #pragma endregion 61 | 62 | 63 | 64 | 65 | }; 66 | 67 | #endif -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassBaseFeatures.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "PckHeader.h" 4 | #include "PckClassLog.h" 5 | 6 | #include "AllocMemPool.h" 7 | #include "PckClassZlib.h" 8 | 9 | #include 10 | 11 | class CPckClassBaseFeatures 12 | { 13 | public: 14 | CPckClassBaseFeatures(); 15 | ~CPckClassBaseFeatures(); 16 | 17 | virtual const LPPCKINDEXTABLE GetPckIndexTable(); 18 | virtual const LPPCK_PATH_NODE GetPckPathNode(); 19 | 20 | //Whether the file has been loaded 21 | BOOL isFileLoaded(); 22 | 23 | //File size 24 | uint64_t GetPckSize(); 25 | 26 | //Get the number of files 27 | uint32_t GetPckFileCount(); 28 | 29 | //Data area size 30 | uint64_t GetPckDataAreaSize(); 31 | 32 | //Data area redundant data size 33 | uint64_t GetPckRedundancyDataSize(); 34 | 35 | protected: 36 | //Reset information 37 | void ResetPckInfos(); 38 | 39 | //Set progress 40 | void SetParams_ProgressInc(); 41 | void SetParams_Progress(DWORD dwUIProgres); 42 | 43 | //Set the maximum value in progress information 44 | void SetParams_ProgressUpper(DWORD dwUIProgressUpper, BOOL bReset = TRUE); 45 | void AddParams_ProgressUpper(DWORD dwUIProgressUpperAdd); 46 | 47 | //multi-threaded process 48 | void SetThreadFlag(BOOL isThreadWorking); 49 | BOOL CheckIfNeedForcedStopWorking(); 50 | void SetErrMsgFlag(int errMsg); 51 | 52 | PCK_ALL_INFOS m_PckAllInfo; 53 | 54 | CAllocMemPool m_NodeMemPool; 55 | 56 | CPckClassZlib m_zlib; 57 | 58 | //runtime variables 59 | LPPCK_RUNTIME_PARAMS m_lpPckParams; 60 | 61 | }; 62 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassCodepage.cpp: -------------------------------------------------------------------------------- 1 | #include "PckClassCodepage.h" 2 | 3 | #pragma region FileNameCodepage 4 | #include "CharsCodeConv.h" 5 | //ansi -> uc cp936 6 | size_t CPckClassCodepage::PckFilenameCode2UCS(const char *_in, wchar_t *_out, size_t _outsize) 7 | { 8 | CAnsi2Ucs cAnsi2Ucs(CP936); 9 | if (NULL != _out) { 10 | cAnsi2Ucs.GetString(_in, _out, _outsize); 11 | return cAnsi2Ucs.GetConvertedStrLen(); 12 | } 13 | else { 14 | return cAnsi2Ucs.GetStrlen(_in); 15 | } 16 | } 17 | //uc -> ansi cp936 18 | size_t CPckClassCodepage::PckFilenameCode2Ansi(const wchar_t *_in, char *_out, size_t _outsize) 19 | { 20 | CUcs2Ansi cUcs2Ansi(CP936); 21 | if (NULL != _out) { 22 | cUcs2Ansi.GetString(_in, _out, _outsize); 23 | return cUcs2Ansi.GetConvertedStrLen(); 24 | } 25 | else { 26 | return cUcs2Ansi.GetStrlen(_in); 27 | } 28 | } 29 | size_t CPckClassCodepage::NativeFilenameCode2UCS(const char *_in, wchar_t *_out, size_t _outsize) 30 | { 31 | CAnsi2Ucs cAnsi2Ucs(CP_ACP); 32 | if (NULL != _out) { 33 | cAnsi2Ucs.GetString(_in, _out, _outsize); 34 | return cAnsi2Ucs.GetConvertedStrLen(); 35 | } 36 | else { 37 | return cAnsi2Ucs.GetStrlen(_in); 38 | } 39 | } 40 | 41 | size_t CPckClassCodepage::NativeFilenameCode2Ansi(const wchar_t *_in, char *_out, size_t _outsize) 42 | { 43 | CUcs2Ansi cUcs2Ansi(CP_ACP); 44 | if (NULL != _out) { 45 | cUcs2Ansi.GetString(_in, _out, _outsize); 46 | return cUcs2Ansi.GetConvertedStrLen(); 47 | } 48 | else { 49 | return cUcs2Ansi.GetStrlen(_in); 50 | } 51 | } 52 | #pragma endregion -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassCodepage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PckClassBaseFeatures.h" 3 | 4 | #define CP936 936 5 | #define PCK_INTERNAL_CODEPAGE CP936 6 | 7 | class CPckClassCodepage 8 | { 9 | private: 10 | CPckClassCodepage(); 11 | ~CPckClassCodepage(); 12 | 13 | public: 14 | //File name transcoding, the return value is the length of the converted string (strlen, wcslen) 15 | //ansi -> uc cp936 16 | static size_t PckFilenameCode2UCS(const char *_in, wchar_t *_out, size_t _outsize); 17 | //uc -> ansi cp936 18 | static size_t PckFilenameCode2Ansi(const wchar_t *_in, char *_out, size_t _outsize); 19 | //ansi -> uc native 20 | static size_t NativeFilenameCode2UCS(const char *_in, wchar_t *_out, size_t _outsize); 21 | //uc -> ansi native 22 | static size_t NativeFilenameCode2Ansi(const wchar_t *_in, char *_out, size_t _outsize); 23 | 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassFileDisk.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef unsigned __int64 QWORD; 4 | #include 5 | #include "PckStructs.h" 6 | #include "PckClassLog.h" 7 | #include "MapViewFileMultiPck.h" 8 | #include "PckClassBaseFeatures.h" 9 | 10 | 11 | class CPckClassFileDisk : 12 | protected virtual CPckClassBaseFeatures 13 | { 14 | public: 15 | CPckClassFileDisk(); 16 | ~CPckClassFileDisk(); 17 | 18 | protected: 19 | BOOL MakeFolderExist(const wchar_t* lpszDirectory); 20 | private: 21 | BOOL MakeFolderExistInternal(const wchar_t* lpszDirectory); 22 | protected: 23 | BOOL EnumAllFilesByPathList(const vector &lpszFilePath, DWORD &_out_FileCount, QWORD &_out_TotalFileSize, vector *lpFileLinkList); 24 | 25 | //Disk space required when rebuilding pck (target file name, size of PCK file to be rebuilt) 26 | QWORD GetPckFilesizeRebuild(const wchar_t * lpszFilename, QWORD qwPckFilesize); 27 | 28 | //The size of the file required when renaming 29 | QWORD GetPckFilesizeRename(const wchar_t * lpszFilename, QWORD qwCurrentPckFilesize); 30 | 31 | //When adding and creating a new file, the size of the pck file written 32 | QWORD GetPckFilesizeByCompressed(const char* lpszFilename, QWORD qwToCompressFilesize, QWORD qwCurrentPckFilesize); 33 | QWORD GetPckFilesizeByCompressed(const wchar_t * lpszFilename, QWORD qwToCompressFilesize, QWORD qwCurrentPckFilesize); 34 | 35 | private: 36 | 37 | //qwCurrentPckFilesize is the size of the existing file, qwToAddSpace is the size that needs to be expanded, and the return value is (qwCurrentPckFilesize + the maximum size that can be expanded) 38 | QWORD GetPckFilesizeByCompressed(QWORD qwDiskFreeSpace, QWORD qwToAddSpace, QWORD qwCurrentPckFilesize); 39 | //Traverse folders 40 | VOID EnumFile(LPWSTR szFilename, BOOL IsPatition, DWORD &dwFileCount, vector *lpFileLinkList, QWORD &qwTotalFileSize, size_t nLen); 41 | 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassHeadTail.cpp: -------------------------------------------------------------------------------- 1 | 2 | //#include 3 | #include "PckClassHeadTail.h" 4 | #include "MapViewFileMultiPck.h" 5 | 6 | CPckClassHeadTail::CPckClassHeadTail() 7 | {} 8 | 9 | CPckClassHeadTail::~CPckClassHeadTail() 10 | { 11 | Logger.OutputVsIde(__FUNCTION__"\r\n"); 12 | } 13 | 14 | 15 | const char * CPckClassHeadTail::GetAdditionalInfo() 16 | { 17 | return m_PckAllInfo.szAdditionalInfo; 18 | } 19 | 20 | BOOL CPckClassHeadTail::SetAdditionalInfo(const char* lpszAdditionalInfo) 21 | { 22 | memcpy(m_PckAllInfo.szAdditionalInfo, lpszAdditionalInfo, PCK_ADDITIONAL_INFO_SIZE); 23 | 24 | if(0 == *m_PckAllInfo.szFilename) 25 | return FALSE; 26 | 27 | CMapViewFileMultiPckWrite cWritefile(m_PckAllInfo.lpSaveAsPckVerFunc->cPckXorKeys.dwMaxSinglePckSize); 28 | 29 | if(NULL == strstr(m_PckAllInfo.szAdditionalInfo, PCK_ADDITIONAL_KEY)) { 30 | strcpy(m_PckAllInfo.szAdditionalInfo, PCK_ADDITIONAL_INFO); 31 | } 32 | 33 | if(!cWritefile.OpenPck(m_PckAllInfo.szFilename, OPEN_EXISTING)) { 34 | Logger_el(UCSTEXT(TEXT_OPENWRITENAME_FAIL), m_PckAllInfo.szFilename); 35 | return FALSE; 36 | } 37 | 38 | cWritefile.SetFilePointer(-((QWORD)(m_PckAllInfo.lpSaveAsPckVerFunc->dwTailSize)), FILE_END); 39 | 40 | if(!cWritefile.Write( 41 | m_PckAllInfo.lpSaveAsPckVerFunc->FillTailData(&m_PckAllInfo), 42 | m_PckAllInfo.lpSaveAsPckVerFunc->dwTailSize)) { 43 | 44 | Logger_el(TEXT_WRITEFILE_FAIL); 45 | return FALSE; 46 | } 47 | 48 | return TRUE; 49 | } 50 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassHeadTail.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PckClassBaseFeatures.h" 3 | #include "PckClassZlib.h" 4 | 5 | class CPckClassHeadTail : 6 | public virtual CPckClassBaseFeatures 7 | { 8 | public: 9 | CPckClassHeadTail(); 10 | ~CPckClassHeadTail(); 11 | 12 | //Set extensions 13 | const char* GetAdditionalInfo(); 14 | BOOL SetAdditionalInfo(const char* lpszAdditionalInfo); 15 | 16 | private: 17 | 18 | }; 19 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassHeadTailWriter.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "PckClassHeadTailWriter.h" 3 | CPckClassHeadTailWriter::CPckClassHeadTailWriter() 4 | {} 5 | 6 | CPckClassHeadTailWriter::~CPckClassHeadTailWriter() 7 | { 8 | Logger.OutputVsIde(__FUNCTION__"\r\n"); 9 | } 10 | 11 | BOOL CPckClassHeadTailWriter::WriteHeadAndTail(CMapViewFileMultiPckWrite *lpWrite, LPPCK_ALL_INFOS lpPckAllInfo, QWORD &dwAddress, BOOL isRenewAddtional) 12 | { 13 | 14 | assert(NULL != dwAddress); 15 | assert(0 != (lpPckAllInfo->dwFileCount + lpPckAllInfo->dwFileCountToAdd)); 16 | 17 | if(isRenewAddtional) 18 | strcpy(lpPckAllInfo->szAdditionalInfo, PCK_ADDITIONAL_INFO); 19 | 20 | //Write pckTail 21 | if (!lpWrite->Write2(dwAddress, m_PckAllInfo.lpSaveAsPckVerFunc->FillTailData(lpPckAllInfo), m_PckAllInfo.lpSaveAsPckVerFunc->dwTailSize)) { 22 | 23 | Logger_el(TEXT_VIEWMAP_FAIL); 24 | return FALSE; 25 | } 26 | 27 | dwAddress += m_PckAllInfo.lpSaveAsPckVerFunc->dwTailSize; 28 | 29 | //Write pckHead 30 | lpPckAllInfo->qwPckSize = dwAddress; 31 | 32 | assert(0 != lpPckAllInfo->qwPckSize); 33 | 34 | if (!lpWrite->Write2(0, m_PckAllInfo.lpSaveAsPckVerFunc->FillHeadData(lpPckAllInfo), m_PckAllInfo.lpSaveAsPckVerFunc->dwHeadSize)) { 35 | Logger_el(TEXT_VIEWMAP_FAIL); 36 | return FALSE; 37 | } 38 | 39 | lpWrite->UnMaping(); 40 | 41 | //Reset the file size here 42 | lpWrite->SetFilePointer(dwAddress, FILE_BEGIN); 43 | lpWrite->SetEndOfFile(); 44 | return TRUE; 45 | 46 | } -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassHeadTailWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PckClassHeadTail.h" 3 | #include "MapViewFileMultiPck.h" 4 | 5 | 6 | class CPckClassHeadTailWriter : 7 | public virtual CPckClassHeadTail 8 | { 9 | public: 10 | CPckClassHeadTailWriter(); 11 | ~CPckClassHeadTailWriter(); 12 | 13 | protected: 14 | 15 | BOOL WriteHeadAndTail(CMapViewFileMultiPckWrite *lpWrite, LPPCK_ALL_INFOS PckAllInfo, QWORD &dwAddress, BOOL isRenewAddtional = TRUE); 16 | 17 | 18 | }; 19 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassIndex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PckClassBaseFeatures.h" 3 | #include "PckClassCodepage.h" 4 | #include "PckClassZlib.h" 5 | #include "MapViewFileMultiPck.h" 6 | 7 | class CPckClassIndex : 8 | public virtual CPckClassBaseFeatures 9 | { 10 | public: 11 | CPckClassIndex(); 12 | ~CPckClassIndex(); 13 | 14 | //Apply for file index memory based on the number of files 15 | LPPCKINDEXTABLE AllocPckIndexTableByFileCount(); 16 | //Convert Ansi characters in lpPckIndexTable->cFileIndex.szFilename to Unicode and write them to lpPckIndexTable->cFileIndex.szwFilename 17 | void GenerateUnicodeStringToIndex(); 18 | // Reading of file header, tail and other structures 19 | BOOL ReadPckFileIndexes(); 20 | 21 | protected: 22 | 23 | void* AllocMemory(size_t sizeStuct); 24 | //Recalculate the number of files during reconstruction and remove invalid and duplicate file names. 25 | DWORD ReCountFiles(); 26 | //Fill the modified index data into the structure by version and compress it 27 | LPPCKINDEXTABLE_COMPRESS FillAndCompressIndexData(LPPCKINDEXTABLE_COMPRESS lpPckIndexTableComped, LPPCKFILEINDEX lpPckFileIndexToCompress); 28 | 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassIndexWriter.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "PckClassIndexWriter.h" 3 | #include "PckIndexCache.h" 4 | 5 | CPckClassIndexWriter::CPckClassIndexWriter() 6 | {} 7 | 8 | CPckClassIndexWriter::~CPckClassIndexWriter() 9 | {} 10 | 11 | //Write all indexes 12 | BOOL CPckClassIndexWriter::WriteAllIndex(CMapViewFileMultiPckWrite *lpWrite, LPPCK_ALL_INFOS lpPckAllInfo, QWORD &dwAddress) 13 | { 14 | CPckMemoryCache cPckCache; 15 | 16 | //The file progress, initialization, and writing index progress are displayed in the window. 17 | DWORD dwValidFileCount = lpPckAllInfo->dwFileCount + lpPckAllInfo->dwFileCountToAdd; 18 | SetParams_ProgressUpper(dwValidFileCount); 19 | 20 | //write original file 21 | LPPCKINDEXTABLE lpPckIndexTableOld = lpPckAllInfo->lpPckIndexTable; 22 | DWORD dwOldPckFileCount = lpPckAllInfo->dwFileCountOld; 23 | DWORD dwFinalFileCount = 0; 24 | 25 | for(DWORD i = 0; i < dwOldPckFileCount; i++) { 26 | 27 | if(!lpPckIndexTableOld->isInvalid) { 28 | PCKINDEXTABLE_COMPRESS pckIndexTableTemp; 29 | 30 | FillAndCompressIndexData(&pckIndexTableTemp, &lpPckIndexTableOld->cFileIndex); 31 | cPckCache.add(pckIndexTableTemp.compressed_index_data, pckIndexTableTemp.dwIndexDataLength + 8); 32 | 33 | ++dwFinalFileCount; 34 | SetParams_ProgressInc(); 35 | } 36 | else { 37 | --dwValidFileCount; 38 | } 39 | lpPckIndexTableOld++; 40 | 41 | } 42 | 43 | SetParams_ProgressUpper(dwValidFileCount, FALSE); 44 | 45 | lpPckAllInfo->dwFileCount = dwFinalFileCount; 46 | 47 | const vector *lpCompedPckIndexTableNew = lpPckAllInfo->lpPckIndexTableToAdd; 48 | 49 | DWORD dwNewPckFileCount = lpPckAllInfo->dwFileCountToAdd; 50 | #if PCK_DEBUG_OUTPUT 51 | DWORD dwVectorSize = 0; 52 | if(NULL != lpCompedPckIndexTableNew) dwVectorSize = lpCompedPckIndexTableNew->size(); 53 | assert(dwNewPckFileCount <= dwVectorSize); 54 | #endif 55 | for(DWORD i = 0; i < dwNewPckFileCount; i++) { 56 | 57 | const PCKINDEXTABLE_COMPRESS *lpPckIndexTablePtr = &(*lpCompedPckIndexTableNew)[i]; 58 | cPckCache.add(lpPckIndexTablePtr->compressed_index_data, lpPckIndexTablePtr->dwIndexDataLength + 8); 59 | 60 | ++dwFinalFileCount; 61 | SetParams_ProgressInc(); 62 | } 63 | 64 | lpPckAllInfo->dwFinalFileCount = dwFinalFileCount; 65 | 66 | lpWrite->Write2(dwAddress, cPckCache.c_buffer(), cPckCache.size()); 67 | dwAddress += cPckCache.size(); 68 | 69 | return TRUE; 70 | } -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassIndexWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PckClassNode.h" 3 | 4 | class CPckClassIndexWriter : 5 | public virtual CPckClassNode 6 | { 7 | public: 8 | CPckClassIndexWriter(); 9 | ~CPckClassIndexWriter(); 10 | 11 | protected: 12 | BOOL WriteAllIndex(CMapViewFileMultiPckWrite *lpWrite, LPPCK_ALL_INFOS lpPckAllInfo, QWORD &dwAddress); 13 | 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassLog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //#include 3 | #include "PckDefines.h" 4 | #if PCK_DEBUG_OUTPUT_FILE 5 | #include 6 | #endif 7 | 8 | //log 9 | #define LOG_BUFFER 8192 10 | 11 | class CPckClassLog 12 | { 13 | private: 14 | CPckClassLog(); 15 | CPckClassLog(const CPckClassLog&) = delete; 16 | ~CPckClassLog(); 17 | 18 | const CPckClassLog& operator=(const CPckClassLog&) = delete; 19 | 20 | public: 21 | 22 | static CPckClassLog& GetInstance() { 23 | static CPckClassLog onlyInstance; 24 | return onlyInstance; 25 | } 26 | //Register LOG display mode 27 | void PckClassLog_func_register(ShowLogW _ShowLogW); 28 | 29 | void e(const char *_text, ...); 30 | void w(const char *_text, ...); 31 | void i(const char *_text, ...); 32 | void d(const char *_text, ...); 33 | void n(const char *_text, ...); 34 | 35 | void e(const wchar_t *_text, ...); 36 | void w(const wchar_t *_text, ...); 37 | void i(const wchar_t *_text, ...); 38 | void d(const wchar_t *_text, ...); 39 | void n(const wchar_t *_text, ...); 40 | 41 | void PrintErrorLog(); 42 | void PrintLog(const char chLevel, const char *_fmt, va_list ap); 43 | void PrintLog(const char chLevel, const wchar_t *_fmt, va_list ap); 44 | 45 | #if PCK_DEBUG_OUTPUT 46 | void OutputVsIde(const char *_text, ...); 47 | #else 48 | void OutputVsIde(...) {}; 49 | #endif 50 | 51 | #if PCK_DEBUG_OUTPUT_FILE 52 | std::mutex m_LockLogFile; 53 | int logOutput(const char *file, const char *format, ...); 54 | #else 55 | void logOutput(...) {} 56 | #endif 57 | 58 | private: 59 | 60 | //Log display mode, displayed to the console by default 61 | static void PrintLogToConsole(const char log_level, const wchar_t *str); 62 | 63 | static ShowLogW ShowLogExtern; 64 | 65 | void ShowLog(const char log_level, const char *str); 66 | void ShowLog(const char log_level, const wchar_t *str); 67 | 68 | //error message 69 | DWORD m_dwLastError = 0; 70 | //Return specific error information 71 | wchar_t *GetErrorMsg(CONST DWORD dwError, wchar_t *szMessage); 72 | 73 | }; 74 | 75 | extern CPckClassLog& Logger; 76 | 77 | #define LoggerExInternal2(msg, file, func, line, ...) Logger.e(##msg " at: "##file ", function: " func ", line: "#line, ##__VA_ARGS__) 78 | #define LoggerExInternal(msg, file, func, line, ...) LoggerExInternal2(msg, file, func, line, ##__VA_ARGS__) 79 | #define Logger_el(msg, ...) LoggerExInternal(msg, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) 80 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassMount.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // PckClassMount.cpp: used to parse the data in the pck file of Perfect World Company and display it in the List 3 | // Initialization of related classes, etc. 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf. The pck structure refers to Ruoshui's pck structure.txt, and 6 | // Refer to the part of its Yi language code and read the pck file list 7 | // 8 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 9 | // 10 | // 2015.5.27 11 | ////////////////////////////////////////////////////////////////////// 12 | #include "PckClass.h" 13 | 14 | BOOL CPckClass::MountPckFile(LPCWSTR szFile) 15 | { 16 | try 17 | { 18 | for(size_t version = 0; version <= GetPckVersionCount(); version++) 19 | { 20 | if(DetectPckVerion(szFile, version)) 21 | { 22 | if(ReadPckFileIndexes()) 23 | { 24 | //Set the entryType of the last Index to PCK_ENTRY_TYPE_TAIL_INDEX 25 | m_PckAllInfo.lpPckIndexTable[m_PckAllInfo.dwFileCount].entryType = PCK_ENTRY_TYPE_TAIL_INDEX; 26 | return TRUE; 27 | } 28 | } 29 | } 30 | return FALSE; 31 | } 32 | catch (MyException e) { 33 | Logger.e(e.what()); 34 | return FALSE; 35 | } 36 | 37 | } 38 | 39 | void CPckClass::BuildDirTree() 40 | { 41 | //Convert all ansi text in the read index to Unicode 42 | GenerateUnicodeStringToIndex(); 43 | //Create a directory tree based on the file names in index 44 | ParseIndexTableToNode(m_PckAllInfo.lpPckIndexTable); 45 | } 46 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassNode.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/PckClass/PckClassNode.cpp -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PckClassIndex.h" 3 | 4 | #define INVALID_NODE ( -1 ) 5 | 6 | class CPckClassNode : 7 | protected virtual CPckClassIndex 8 | { 9 | public: 10 | CPckClassNode(); 11 | ~CPckClassNode(); 12 | 13 | //Perform path analysis on the PckIndex file and put it into Node 14 | void ParseIndexTableToNode(LPPCKINDEXTABLE lpMainIndexTable); 15 | //Find identical nodes 16 | const PCK_PATH_NODE* FindFileNode(const PCK_PATH_NODE* lpBaseNode, wchar_t* lpszFile); 17 | 18 | //Delete a node 19 | virtual VOID DeleteNode(LPPCK_PATH_NODE lpNode); 20 | virtual VOID DeleteNode(LPPCKINDEXTABLE lpIndex); 21 | 22 | protected: 23 | BOOL RenameNodeEnum(LPPCK_PATH_NODE lpNode, size_t lenNodeRes, char* lpszReplaceString, size_t lenrs, size_t lenrp); 24 | BOOL RenameNode(LPPCK_PATH_NODE lpNode, size_t lenNodeRes, char* lpszReplaceString, size_t lenrs, size_t lenrp); 25 | 26 | public: 27 | //Rename a node 28 | virtual BOOL RenameNode(LPPCK_PATH_NODE lpNode, const wchar_t* lpszReplaceString); 29 | virtual BOOL RenameIndex(LPPCK_PATH_NODE lpNode, const wchar_t* lpszReplaceString); 30 | virtual BOOL RenameIndex(LPPCKINDEXTABLE lpIndex, const wchar_t* lpszReplaceString); 31 | 32 | protected: 33 | //Check new file name 34 | //BOOL CheckNewFilename(); 35 | 36 | public: 37 | //Get node path 38 | static BOOL GetCurrentNodeString(wchar_t *szCurrentNodePathString, const PCK_PATH_NODE* lpNode); 39 | protected: 40 | BOOL FindDuplicateNodeFromFileList(const PCK_PATH_NODE* lpNodeToInsertPtr, DWORD &_in_out_FileCount); 41 | 42 | private: 43 | 44 | LPPCK_PATH_NODE m_lpRootNode; //The root node of the PCK file node 45 | 46 | //Perform path analysis on the PckIndex file and put it into Node 47 | BOOL AddFileToNode(LPPCKINDEXTABLE lpPckIndexNode); 48 | 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassRebuildFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "PckClassLog.h" 4 | #include "PckStructs.h" 5 | 6 | class CPckClassRebuildFilter 7 | { 8 | private: 9 | typedef enum { OP_CheckFile = 0, OP_Protect, OP_Delete, OP_Rmdir, OP_Unknown } SCRIPTOP; 10 | 11 | typedef struct _FILEOPS 12 | { 13 | SCRIPTOP op; 14 | wchar_t szFilename[MAX_PATH]; 15 | wchar_t szFilenameBuffer[MAX_PATH]; //Fill in \ or / in the path with 0, and use lpszSepratedPaths to point to the separate path names. 16 | wchar_t* lpszSepratedPaths[MAX_PATH]; 17 | }FILEOP; 18 | 19 | public: 20 | CPckClassRebuildFilter(); 21 | ~CPckClassRebuildFilter(); 22 | 23 | BOOL ApplyScript(const wchar_t * lpszScriptFile, LPPCK_PATH_NODE lpRootNode); 24 | BOOL TestScript(const wchar_t * lpszScriptFile); 25 | 26 | void StripModelTexture(LPPCKINDEXTABLE lpPckIndexHead, DWORD dwFileCount, LPPCK_PATH_NODE lpRootNode, LPCWSTR lpszPckFilename); 27 | 28 | 29 | private: 30 | const wchar_t *szOperators = 31 | L"chkfile;" 32 | "protect;" 33 | "delete;;" 34 | "rmdir;;;"; 35 | 36 | vector m_ScriptLines; 37 | vector m_FirstFileOp; 38 | vector m_EditedNode; 39 | 40 | BOOL OpenScriptFileAndConvBufToUcs2(const wchar_t * lpszScriptFile); 41 | 42 | BOOL ApplyScript2IndexList(LPPCK_PATH_NODE lpRootNode); 43 | void MarkFilterFlagToNode(LPPCK_PATH_NODE lpNode, SCRIPTOP op); 44 | void MarkFilterFlagToFileIndex(LPPCKINDEXTABLE lpPckIndexTable, SCRIPTOP op); 45 | LPPCK_PATH_NODE LocationFileIndex(LPWSTR *lpszPaths, LPPCK_PATH_NODE lpNode); 46 | void SepratePaths(FILEOP * pFileOp); 47 | BOOL ParseOneLine(FILEOP * pFileOp, LPCWSTR lpszLine); 48 | BOOL ParseScript(const wchar_t * lpszScriptFile); 49 | 50 | BOOL Apply(LPPCK_PATH_NODE lpRootNode); 51 | BOOL ModelTextureCheck(LPCWSTR lpszFilename); 52 | void ResetRebuildFilterInIndexList(); 53 | 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassRenamer.cpp: -------------------------------------------------------------------------------- 1 | #include "PckClassWriteOperator.h" 2 | 3 | //Rename file 4 | BOOL CPckClassWriteOperator::RenameFilename() 5 | { 6 | m_zlib.init_compressor(m_lpPckParams->dwCompressLevel); 7 | Logger.i(TEXT_LOG_RENAME); 8 | 9 | //The following is to create a file to save the compressed file 10 | CMapViewFileMultiPckWrite cFileWrite(m_PckAllInfo.lpSaveAsPckVerFunc->cPckXorKeys.dwMaxSinglePckSize); 11 | 12 | if(!cFileWrite.OpenPck(m_PckAllInfo.szFilename, OPEN_EXISTING)) { 13 | 14 | Logger_el(UCSTEXT(TEXT_OPENWRITENAME_FAIL), m_PckAllInfo.szFilename); 15 | assert(FALSE); 16 | return FALSE; 17 | } 18 | 19 | QWORD dwFileSize = GetPckFilesizeRename(m_PckAllInfo.szFilename, cFileWrite.GetFileSize()); 20 | 21 | if(!cFileWrite.Mapping(dwFileSize)) { 22 | 23 | Logger_el(UCSTEXT(TEXT_CREATEMAPNAME_FAIL), m_PckAllInfo.szFilename); 24 | assert(FALSE); 25 | return FALSE; 26 | } 27 | 28 | //Write file index 29 | QWORD dwAddress = m_PckAllInfo.dwAddressOfFileEntry; 30 | 31 | WriteAllIndex(&cFileWrite, &m_PckAllInfo, dwAddress); 32 | 33 | WriteHeadAndTail(&cFileWrite, &m_PckAllInfo, dwAddress, FALSE); 34 | 35 | Logger.i(TEXT_LOG_WORKING_DONE); 36 | 37 | return TRUE; 38 | } -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassVersionDetect.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/PckClass/PckClassVersionDetect.cpp -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassVersionFillDataTemplate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //Data filling and data writing at the beginning and end of the file 4 | template 5 | void* FillHeadData(void* param) 6 | { 7 | LPPCK_ALL_INFOS lpPckAllInfo = (LPPCK_ALL_INFOS)param; 8 | static DWORD headbuf[3]; 9 | T* lpHead = (T*)headbuf; 10 | lpHead->dwHeadCheckHead = lpPckAllInfo->lpSaveAsPckVerFunc->cPckXorKeys.HeadVerifyKey1; 11 | if (lpPckAllInfo->lpSaveAsPckVerFunc->cPckXorKeys.HeadVerifyKey2) { 12 | lpHead->dwHeadCheckTail = lpPckAllInfo->lpSaveAsPckVerFunc->cPckXorKeys.HeadVerifyKey2; 13 | lpHead->dwPckSize = (DWORD)lpPckAllInfo->qwPckSize; 14 | } 15 | else { 16 | lpHead->dwPckSize = lpPckAllInfo->qwPckSize; 17 | } 18 | return headbuf; 19 | } 20 | 21 | template 22 | void* FillTailData(void* param) 23 | { 24 | LPPCK_ALL_INFOS lpPckAllInfo = (LPPCK_ALL_INFOS)param; 25 | static BYTE tailbuf[MAX_TAIL_LENGTH] = { 0 }; 26 | T* lpTail = (T*)tailbuf; 27 | lpTail->dwIndexTableCheckHead = lpPckAllInfo->lpSaveAsPckVerFunc->cPckXorKeys.TailVerifyKey1; 28 | lpTail->dwVersion0 = lpTail->dwVersion = lpPckAllInfo->lpSaveAsPckVerFunc->cPckXorKeys.Version; 29 | lpTail->dwEntryOffset = lpPckAllInfo->dwAddressOfFileEntry ^ lpPckAllInfo->lpSaveAsPckVerFunc->cPckXorKeys.IndexesEntryAddressCryptKey; 30 | //lpTail->dwFlags = 0; 31 | memcpy(lpTail->szAdditionalInfo, lpPckAllInfo->szAdditionalInfo, sizeof(lpTail->szAdditionalInfo)); 32 | lpTail->dwIndexTableCheckTail = lpPckAllInfo->lpSaveAsPckVerFunc->cPckXorKeys.TailVerifyKey2; 33 | lpTail->dwFileCount = lpPckAllInfo->dwFinalFileCount; 34 | return tailbuf; 35 | } 36 | 37 | //Data from param -> lpTail 38 | template 39 | void* FillIndexData(void* lpFileIndexParam, void* lpPckIndexTableClearParam) 40 | { 41 | LPPCKFILEINDEX lpFileIndex = (LPPCKFILEINDEX)lpFileIndexParam; 42 | T* lpPckIndexTableClear = (T*)lpPckIndexTableClearParam; 43 | memcpy(lpPckIndexTableClear->szFilename, lpFileIndex->szFilename, sizeof(lpPckIndexTableClear->szFilename)); 44 | lpPckIndexTableClear->dwUnknown1 = lpPckIndexTableClear->dwUnknown2 = 0; 45 | lpPckIndexTableClear->dwAddressOffset = lpFileIndex->dwAddressOffset; 46 | lpPckIndexTableClear->dwFileCipherTextSize = lpFileIndex->dwFileCipherTextSize; 47 | lpPckIndexTableClear->dwFileClearTextSize = lpFileIndex->dwFileClearTextSize; 48 | return (void*)lpPckIndexTableClear; 49 | } 50 | 51 | //Data from lpIndex -> param 52 | template 53 | BOOL PickIndexData(void* lpFileIndexParam, void* lpPckIndexTableClearParam) 54 | { 55 | LPPCKFILEINDEX lpFileIndex = (LPPCKFILEINDEX)lpFileIndexParam; 56 | T* lpPckIndexTableClear = (T*)lpPckIndexTableClearParam; 57 | lpFileIndex->dwAddressOffset = lpPckIndexTableClear->dwAddressOffset; 58 | lpFileIndex->dwFileCipherTextSize = lpPckIndexTableClear->dwFileCipherTextSize; 59 | lpFileIndex->dwFileClearTextSize = lpPckIndexTableClear->dwFileClearTextSize; 60 | memcpy(lpFileIndex->szFilename, lpPckIndexTableClear->szFilename, sizeof(lpPckIndexTableClear->szFilename)); 61 | return TRUE; 62 | } 63 | 64 | //template 65 | //void* FillIndexData(void *param, LPPCKFILEINDEX_V2020 lpPckIndexTableClear); -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassWriteOperator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PckClassHeadTailWriter.h" 3 | #include "PckClassIndexWriter.h" 4 | #include "PckClassFileDisk.h" 5 | #include "PckThreadRunner.h" 6 | 7 | class CPckClassWriteOperator : 8 | public virtual CPckClassHeadTailWriter, 9 | public virtual CPckClassIndexWriter, 10 | public virtual CPckClassFileDisk 11 | { 12 | public: 13 | CPckClassWriteOperator(); 14 | ~CPckClassWriteOperator(); 15 | 16 | friend class CPckThreadRunner; 17 | 18 | //Rebuild pck file 19 | virtual BOOL RebuildPckFile(const wchar_t * lpszScriptFile, const wchar_t * szRebuildPckFile, BOOL bUseRecompress); 20 | 21 | protected: 22 | BOOL RebuildPckFile(const wchar_t * szRebuildPckFile); 23 | BOOL RecompressPckFile(const wchar_t * szRecompressPckFile, int isStripMode = PCK_STRIP_NONE); 24 | 25 | public: 26 | #pragma region Game streamlined 27 | virtual BOOL StripPck(const wchar_t * lpszStripedPckFile, int flag); 28 | #pragma endregion 29 | 30 | #pragma region PckClassAppendFiles.cpp 31 | public: 32 | //Create and update pck files 33 | virtual BOOL UpdatePckFile(const wchar_t * szPckFile, const vector &lpszFilePath, const PCK_PATH_NODE* lpNodeToInsert); 34 | #pragma endregion 35 | #pragma region PckClassRenamer.cpp 36 | 37 | public: 38 | //Rename file 39 | virtual BOOL RenameFilename(); 40 | 41 | #pragma endregion 42 | 43 | private: 44 | vector m_FilesToBeAdded; 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckClassZlib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define Z_MAX_COMPRESSION 12 3 | #define Z_Default_COMPRESSION 9 4 | 5 | #include 6 | 7 | typedef std::function CompressBoundFunc; 8 | typedef std::function CompressFunc; 9 | 10 | 11 | class CPckClassZlib 12 | { 13 | public: 14 | CPckClassZlib(); 15 | ~CPckClassZlib(); 16 | 17 | private: 18 | 19 | struct COMPRESS_FUNC 20 | { 21 | CompressBoundFunc compressBound; 22 | CompressFunc compress; 23 | //uint32_t(*compressBound)(uint32_t); 24 | //int(*compress)(void *dest, ulong_t *destLen, const void *source, uint32_t sourceLen, int level); 25 | }m_PckCompressFunc; 26 | 27 | int m_compress_level; 28 | 29 | public: 30 | 31 | int init_compressor(int level); 32 | 33 | int check_zlib_header(void *data); 34 | uint32_t compressBound(uint32_t sourceLen); 35 | int compress(void *dest, ulong_t *destLen, const void *source, uint32_t sourceLen); 36 | int decompress(void *dest, ulong_t *destLen, const void *source, uint32_t sourceLen); 37 | int decompress_part(void *dest, ulong_t *destLen, const void *source, uint32_t sourceLen, uint32_t fullDestLen); 38 | 39 | //Get the compressed size of the data. If the source size is less than a certain value, it will not be compressed. 40 | unsigned long GetCompressBoundSizeByFileSize(ulong_t &dwFileClearTextSize, ulong_t &dwFileCipherTextSize, uint32_t dwFileSize); 41 | 42 | private: 43 | 44 | static uint32_t compressBound_zlib(uint32_t sourceLen); 45 | static int compress_zlib(void *dest, ulong_t *destLen, const void *source, uint32_t sourceLen, int level); 46 | static uint32_t compressBound_libdeflate(uint32_t sourceLen); 47 | static int compress_libdeflate(void *dest, ulong_t *destLen, const void *source, uint32_t sourceLen, int level); 48 | 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckHeader.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // PckHeader.h: used to parse the data in the pck file of Perfect World Company and display it in the List 3 | // head File 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf. The pck structure refers to Ruoshui's pck structure.txt, and 6 | // Refer to the part of its Yi language code and read the pck file list 7 | // 8 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 9 | // 10 | // 2012.4.10 11 | ////////////////////////////////////////////////////////////////////// 12 | 13 | #if !defined(_PCKHEADER_H_) 14 | #define _PCKHEADER_H_ 15 | 16 | #ifndef UNICODE 17 | #error("please use Unicode charset") 18 | #endif 19 | 20 | #include "PckStructs.h" 21 | 22 | #endif -------------------------------------------------------------------------------- /PckDll/PckClass/PckIndexCache.cpp: -------------------------------------------------------------------------------- 1 | #include "PckIndexCache.h" 2 | #include "gccException.h" 3 | #include "pck_default_vars.h" 4 | 5 | CPckMemoryCache::CPckMemoryCache() : 6 | usedsize(0), 7 | poolsize(0), 8 | buffer(NULL) 9 | { 10 | } 11 | 12 | CPckMemoryCache::~CPckMemoryCache() 13 | { 14 | if (NULL != buffer) 15 | free(buffer); 16 | } 17 | 18 | BOOL CPckMemoryCache::expand(size_t addsize) 19 | { 20 | size_t newsize = (usedsize + addsize) < (poolsize + _INIT_SIZE_) ? (poolsize + _INIT_SIZE_) : (usedsize + addsize + _INIT_SIZE_); 21 | 22 | char* newbuffer = (char*)realloc(buffer, newsize); 23 | 24 | if (NULL != newbuffer) { 25 | poolsize = newsize; 26 | buffer = newbuffer; 27 | } 28 | else { 29 | 30 | if (NULL != (newbuffer = (char*)malloc(newsize))) { 31 | 32 | memcpy(newbuffer, buffer, poolsize); 33 | free(buffer); 34 | poolsize = newsize; 35 | buffer = newbuffer; 36 | } 37 | else { 38 | throw std::bad_alloc(); 39 | } 40 | } 41 | return TRUE; 42 | } 43 | 44 | BOOL CPckMemoryCache::add(const void* buf, size_t size) 45 | { 46 | if (0 != size) { 47 | 48 | if (poolsize < (usedsize + size)) { 49 | expand(size); 50 | } 51 | memcpy(buffer + usedsize, buf, size); 52 | usedsize += size; 53 | } 54 | 55 | return TRUE; 56 | } 57 | 58 | size_t CPckMemoryCache::size() 59 | { 60 | return usedsize; 61 | } 62 | 63 | const void* CPckMemoryCache::c_buffer() 64 | { 65 | return buffer; 66 | } -------------------------------------------------------------------------------- /PckDll/PckClass/PckIndexCache.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "pck_default_vars.h" 3 | 4 | #define _INIT_SIZE_ (10 * 1024 * 1024) 5 | 6 | class CPckMemoryCache 7 | { 8 | public: 9 | CPckMemoryCache(); 10 | ~CPckMemoryCache(); 11 | 12 | BOOL add(const void* buf, size_t size); 13 | size_t size(); 14 | const void* c_buffer(); 15 | 16 | private: 17 | 18 | char *buffer; 19 | size_t usedsize, poolsize; 20 | 21 | BOOL expand(size_t addsize); 22 | 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckModelStrip.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/PckClass/PckModelStrip.cpp -------------------------------------------------------------------------------- /PckDll/PckClass/PckModelStrip.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _STRIP_ECM_ 0 4 | 5 | #include 6 | #include "PckStructs.h" 7 | #include "PckModelStripDefines.h" 8 | 9 | class CPckModelStrip 10 | { 11 | public: 12 | CPckModelStrip(); 13 | ~CPckModelStrip(); 14 | 15 | BOOL StripContent(BYTE* buffer, LPPCKFILEINDEX lpFileIndex, int flag); 16 | 17 | private: 18 | 19 | int GetFileTypeByName(const wchar_t* lpszFilename); 20 | BOOL StripAtt(BYTE* buffer, LPPCKFILEINDEX lpFileIndex); 21 | BOOL StripGfx(BYTE* buffer, LPPCKFILEINDEX lpFileIndex); 22 | #if _STRIP_ECM_ 23 | BOOL StripEcm(BYTE* buffer, LPPCKFILEINDEX lpFileIndex); 24 | #endif 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /PckDll/PckClass/PckModelStripDefines.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/PckClass/PckModelStripDefines.h -------------------------------------------------------------------------------- /PckDll/PckClass/PckThreadRunnerMemory.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/PckClass/PckThreadRunnerMemory.cpp -------------------------------------------------------------------------------- /PckDll/PckControlCenter/PckControlCenter.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // PckControlCenter.cpp: used to parse the data in the pck file of Perfect World Company and display it in the List 3 | // Header file, data interaction between interface and PCK class, control center 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf. The pck structure refers to Ruoshui's pck structure.txt, and 6 | // Refer to the part of its Yi language code and read the pck file list 7 | // 8 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 9 | // 10 | // 2012.10.10 11 | ////////////////////////////////////////////////////////////////////// 12 | 13 | #include "PckControlCenter.h" 14 | #include "PckClass.h" 15 | #include "PckClassLog.h" 16 | #include 17 | 18 | //const DWORD CPckControlCenter::m_dwNumberOfProcessors = thread::hardware_concurrency(); 19 | 20 | CPckControlCenter::CPckControlCenter(): 21 | m_lpClassPck(NULL), 22 | m_lpPckRootNode(NULL), 23 | m_emunFileFormat(FMTPCK_UNKNOWN), 24 | cParams({ 0 }) 25 | { 26 | init(); 27 | New(); 28 | } 29 | 30 | CPckControlCenter::~CPckControlCenter() 31 | { 32 | regMsgFeedback(NULL, DefaultFeedbackCallback); 33 | Close(); 34 | uninit(); 35 | Logger.OutputVsIde(__FUNCTION__"\r\n"); 36 | } 37 | 38 | void CPckControlCenter::init() 39 | { 40 | cParams.lpPckControlCenter = this; 41 | //cParams.code_page = 936; 42 | cParams.dwCompressLevel = getDefaultCompressLevel(); 43 | cParams.dwMTThread = thread::hardware_concurrency(); 44 | cParams.dwMTMaxMemory = getMaxMemoryAllowed(); 45 | } 46 | 47 | void CPckControlCenter::uninit() 48 | { 49 | lpszFilePathToAdd.clear(); 50 | } 51 | 52 | void CPckControlCenter::Reset(uint32_t dwUIProgressUpper) 53 | { 54 | memset(&cParams.cVarParams, 0, sizeof(PCK_VARIETY_PARAMS)); 55 | cParams.cVarParams.dwUIProgressUpper = dwUIProgressUpper; 56 | } 57 | -------------------------------------------------------------------------------- /PckDll/PckControlCenter/PckControlCenter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/PckControlCenter/PckControlCenter.h -------------------------------------------------------------------------------- /PckDll/PckControlCenter/PckControlCenterOperation.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/PckControlCenter/PckControlCenterOperation.cpp -------------------------------------------------------------------------------- /PckDll/WinPCK_dll.common.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | 8 | $(TargetPath) 9 | 10 | $(ProjectDir) 11 | 12 | true 13 | 14 | 15 | true 16 | true 17 | 18 | true 19 | true 20 | true 21 | 22 | -------------------------------------------------------------------------------- /PckDll/ZupClass/ZupClass.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // ZupClass.h: used to parse the data in the zup file of Perfect World Company and display it in the List 3 | // head File 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2012.5.23 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #include "PckClass.h" 13 | #include "ZupHeader.h" 14 | #include "DictHash.h" 15 | #include "PckClassLog.h" 16 | 17 | #if !defined(_ZUPCLASS_H_) 18 | #define _ZUPCLASS_H_ 19 | 20 | class CZupClass : public CPckClass 21 | { 22 | public: 23 | 24 | //CZupClass(); 25 | CZupClass(LPPCK_RUNTIME_PARAMS inout); 26 | virtual ~CZupClass(); 27 | 28 | BOOL Init(LPCWSTR szFile) override; 29 | 30 | const LPPCKINDEXTABLE GetPckIndexTable() override; 31 | 32 | //Rebuild pck file 33 | virtual BOOL RebuildPckFile(LPCWSTR lpszScriptFile, LPCWSTR szRebuildPckFile, BOOL bUseRecompress) override { Logger.e(TEXT_NOTSUPPORT);return FALSE; } 34 | virtual BOOL StripPck(LPCWSTR lpszStripedPckFile, int flag) override { Logger.e(TEXT_NOTSUPPORT); return FALSE; } 35 | 36 | //Create and update pck files 37 | virtual BOOL UpdatePckFile(LPCWSTR szPckFile, const vector &lpszFilePath, const PCK_PATH_NODE* lpNodeToInsert) override { Logger.e(TEXT_NOTSUPPORT);return FALSE; } 38 | 39 | //Rename file 40 | virtual BOOL RenameFilename() override { Logger.e(TEXT_NOTSUPPORT);return FALSE; } 41 | 42 | //Delete a node 43 | virtual void DeleteNode(LPPCK_PATH_NODE lpNode) override { Logger.e(TEXT_NOTSUPPORT);} 44 | virtual void DeleteNode(LPPCKINDEXTABLE lpIndex) override { Logger.e(TEXT_NOTSUPPORT); } 45 | 46 | //Rename a node 47 | virtual BOOL RenameNode(LPPCK_PATH_NODE lpNode, const wchar_t* lpszReplaceString) override { Logger.e(TEXT_NOTSUPPORT); return FALSE; } 48 | virtual BOOL RenameIndex(LPPCK_PATH_NODE lpNode, const wchar_t* lpszReplaceString) override { Logger.e(TEXT_NOTSUPPORT); return FALSE; } 49 | virtual BOOL RenameIndex(LPPCKINDEXTABLE lpIndex, const wchar_t* lpszReplaceString) override { Logger.e(TEXT_NOTSUPPORT); return FALSE; } 50 | 51 | //Preview file 52 | virtual BOOL GetSingleFileData(const PCKINDEXTABLE* const lpZupFileIndexTable, char *buffer, size_t sizeOfBuffer = 0) override; 53 | protected: 54 | virtual BOOL GetSingleFileData(LPVOID lpvoidFileRead, const PCKINDEXTABLE* const lpPckFileIndexTable, char *buffer, size_t sizeOfBuffer = 0) override; 55 | 56 | private: 57 | 58 | LPPCKINDEXTABLE m_lpZupIndexTable; 59 | CDictHash *m_lpDictHash; 60 | 61 | private: 62 | 63 | void BuildDirTree(); 64 | BOOL BuildZupBaseDict(); 65 | void DecodeFilename(char *_dst, wchar_t *_wdst, char *_src); 66 | 67 | _inline void DecodeDict(LPZUP_FILENAME_DICT lpZupDict); 68 | //void AddDict(char *&lpszStringToAdd); 69 | void AddDict(std::string& base_file); 70 | 71 | const PCKINDEXTABLE* GetBaseFileIndex(const PCKINDEXTABLE* lpIndex, const PCKINDEXTABLE* lpZeroBaseIndex); 72 | 73 | }; 74 | 75 | #endif -------------------------------------------------------------------------------- /PckDll/ZupClass/ZupHeader.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // ZupHeader.h: used to parse the data in the zup file of Perfect World Company and display it in the List 3 | // head File 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2012.5.23 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #if !defined(_ZUPHEADER_H_) 13 | #define _ZUPHEADER_H_ 14 | 15 | //#define TEXT_SORRY "sorry" 16 | #define TEXT_NOTSUPPORT "This feature is not supported at the moment" 17 | 18 | typedef struct _ZUP_INC { 19 | uint16_t wID; 20 | char szMD5[34]; 21 | uint8_t abMD5[16]; 22 | 23 | _ZUP_INC *next; 24 | }ZUPINC, *LPZUPINC; 25 | 26 | typedef struct _ZUP_INC_LIST { 27 | 28 | uint16_t wID; 29 | uint16_t wMinVersion; 30 | uint16_t wTargetVersion; 31 | uint32_t dwTotalSize; 32 | char szSingature[192]; 33 | uint8_t abSingature[128]; 34 | LPZUPINC lpZupIncFileList; 35 | 36 | _ZUP_INC_LIST *next; 37 | 38 | }ZUPINCLIST, *LPZUPINCLIST; 39 | 40 | 41 | 42 | #endif -------------------------------------------------------------------------------- /PckDll/icons/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/icons/Thumbs.db -------------------------------------------------------------------------------- /PckDll/icons/chinaz1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/icons/chinaz1.png -------------------------------------------------------------------------------- /PckDll/icons/chinaz1x.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/icons/chinaz1x.ico -------------------------------------------------------------------------------- /PckDll/icons/filefind.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/icons/filefind.ico -------------------------------------------------------------------------------- /PckDll/icons/logerror.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/icons/logerror.png -------------------------------------------------------------------------------- /PckDll/icons/loginfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/icons/loginfo.png -------------------------------------------------------------------------------- /PckDll/icons/logwarning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/icons/logwarning.png -------------------------------------------------------------------------------- /PckDll/include/compiler.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMPILER_H_ 2 | #define _COMPILER_H_ 3 | 4 | #ifdef __GNUC__ 5 | # include "compiler_gcc.h" 6 | #elif defined(_MSC_VER) 7 | # include "compiler_msc.h" 8 | #else 9 | # pragma message("Unrecognized compiler. Please add a header file for your compiler. Compilation will proceed, but performance may suffer!") 10 | #endif 11 | 12 | #include /* size_t */ 13 | 14 | #ifndef __bool_true_false_are_defined 15 | # include /* bool */ 16 | #endif 17 | 18 | /* Fixed-width integer types */ 19 | #ifndef PRIu32 20 | # include 21 | #endif 22 | 23 | //#include 24 | #include 25 | 26 | #ifdef _WIN32 27 | #include 28 | #define PATH_SEPERATOR "\\" 29 | #define MAX_PATH_LEN MAX_PATH 30 | #else 31 | //#include 32 | #define PATH_SEPERATOR "/" 33 | #define MAX_PATH_LEN PATH_MAX 34 | #endif 35 | 36 | 37 | //typedef unsigned __int64 QWORD, *LPQWORD; 38 | typedef unsigned long ulong_t; 39 | typedef int BOOL; 40 | //typedef unsigned char BYTE; 41 | //typedef unsigned short WORD; 42 | 43 | typedef const wchar_t * LPCWSTR; 44 | typedef wchar_t * LPWSTR; 45 | typedef const char * LPCSTR; 46 | typedef char * LPSTR; 47 | 48 | #ifndef TRUE 49 | #define TRUE 1 50 | #define FALSE 0 51 | #endif 52 | 53 | 54 | #if defined(_MSC_VER) 55 | #pragma warning(disable:4996) 56 | #pragma warning ( disable : 4005 ) 57 | #pragma warning ( disable : 4995 ) 58 | 59 | #else 60 | 61 | #define strcmpi strcasecmp 62 | #define stricmp strcasecmp 63 | #define strcpy_s strcpy 64 | #define strcat_s strcat 65 | //#if 0 66 | //#define sprintf_s(x,args...) snprintf((x), sizeof((x)),##args) 67 | //extern "C" char * strlwr(char *s); 68 | //#endif 69 | #endif 70 | 71 | 72 | #endif //_COMPILER_H_ -------------------------------------------------------------------------------- /PckDll/include/compiler_msc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * compiler_msc.h - definitions for the Microsoft C Compiler 3 | */ 4 | 5 | #define LIBEXPORT __declspec(dllexport) 6 | 7 | /* 8 | * Old versions (e.g. VS2010) of MSC don't have the C99 header stdbool.h. 9 | * Beware: the below replacement isn't fully standard, since normally any value 10 | * != 0 should be implicitly cast to a bool with value 1... but that doesn't 11 | * happen if bool is really just an 'int'. 12 | */ 13 | //typedef int bool; 14 | //#define true 1 15 | //#define false 0 16 | //#define __bool_true_false_are_defined 1 17 | 18 | /* Define ssize_t */ 19 | #ifdef _WIN64 20 | typedef long long ssize_t; 21 | #else 22 | typedef int ssize_t; 23 | #endif 24 | 25 | /* 26 | * Old versions (e.g. VS2010) of MSC have stdint.h but not the C99 header 27 | * inttypes.h. Work around this by defining the PRI* macros ourselves. 28 | */ 29 | //#include 30 | #include 31 | 32 | //add by stsm 33 | //#include "msvc_conf.h" 34 | //#include "fix_clang_emmintrin.h" 35 | 36 | #define PRIu8 "hhu" 37 | #define PRIu16 "hu" 38 | #define PRIu32 "u" 39 | #define PRIu64 "llu" 40 | #define PRIi8 "hhi" 41 | #define PRIi16 "hi" 42 | #define PRIi32 "i" 43 | #define PRIi64 "lli" 44 | #define PRIx8 "hhx" 45 | #define PRIx16 "hx" 46 | #define PRIx32 "x" 47 | #define PRIx64 "llx" 48 | 49 | /* Assume a little endian architecture with fast unaligned access */ 50 | #define CPU_IS_LITTLE_ENDIAN() 1 51 | #define UNALIGNED_ACCESS_IS_FAST 1 52 | 53 | /* __restrict has nonstandard behavior; don't use it */ 54 | #define restrict 55 | 56 | /* ... but we can use __inline and __forceinline */ 57 | #define inline __inline 58 | #define forceinline __forceinline 59 | 60 | /* Byte swap functions */ 61 | #define bswap16 _byteswap_ushort 62 | #define bswap32 _byteswap_ulong 63 | #define bswap64 _byteswap_uint64 64 | -------------------------------------------------------------------------------- /PckDll/include/gccException.h: -------------------------------------------------------------------------------- 1 | #ifndef _GCC_EXCEPTION_H 2 | #define _GCC_EXCEPTION_H 3 | 4 | using namespace std; 5 | 6 | #if defined(_MSC_VER) 7 | #include 8 | #define MyException exception 9 | 10 | #else 11 | #include 12 | 13 | class MyException 14 | { 15 | public: 16 | MyException(string data) { buf = data; }; 17 | ~MyException() /*noexcept*/ {}; 18 | virtual char const* what() const { return buf.c_str(); }; 19 | private: 20 | std::string buf; 21 | }; 22 | #endif 23 | 24 | #define __ExceptionWithLine(msg, file, func, line) MyException(##msg " at: "##file ", function: " func ", line: "#line) 25 | #define _ExceptionWithLine(msg, file, func, line) __ExceptionWithLine(msg, file, func, line) 26 | #define MyExceptionEx(msg) _ExceptionWithLine(msg, __FILE__, __FUNCTION__, __LINE__) 27 | 28 | #endif //_GCC_EXCEPTION_H 29 | -------------------------------------------------------------------------------- /PckDll/include/msvc_conf.h: -------------------------------------------------------------------------------- 1 | #include 2 | #define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 3 | #define __SSE2__ 1 4 | #define _aligned_attribute 5 | 6 | //#define COMPILER_SUPPORTS_AVX_TARGET 1 7 | //#define COMPILER_SUPPORTS_AVX2_TARGET 1 8 | //#define COMPILER_SUPPORTS_TARGET_INTRINSICS 1 9 | 10 | 11 | -------------------------------------------------------------------------------- /PckDll/include/pck_default_vars.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "gccException.h" 6 | 7 | typedef unsigned long ulong_t; 8 | typedef int BOOL; 9 | typedef unsigned char BYTE; 10 | 11 | typedef const wchar_t * LPCWSTR; 12 | typedef wchar_t * LPWSTR; 13 | typedef const char * LPCSTR; 14 | typedef char * LPSTR; 15 | 16 | /* Define ssize_t */ 17 | #ifdef _WIN64 18 | typedef long long ssize_t; 19 | #else 20 | typedef int ssize_t; 21 | #endif 22 | 23 | #ifndef TRUE 24 | #define TRUE 1 25 | #define FALSE 0 26 | #endif 27 | 28 | 29 | //Version Information 30 | #define WINPCK_VERSION_NUMBER 1,33,1,0 31 | #define WINPCK_VERSION "1.33.1.0" 32 | 33 | //Scheduling output 34 | #ifdef _DEBUG 35 | #define PCK_DEBUG_OUTPUT 0 36 | #define PCK_DEBUG_OUTPUT_FILE 0 37 | #else 38 | #define PCK_DEBUG_OUTPUT 0 39 | #define PCK_DEBUG_OUTPUT_FILE 0 40 | #endif 41 | 42 | #define PCK_V2031_ENABLE 0 43 | 44 | //Open, close, restore and other event registration 45 | #define PCK_FILE_OPEN_SUCESS 1 46 | #define PCK_FILE_CLOSE 2 47 | 48 | 49 | #define MAX_PATH 260 50 | 51 | //zlib 52 | #define Z_OK 0 53 | 54 | //params 55 | #define MT_MAX_MEMORY 0x80000000 //2048MB 56 | //#define MT_MAX_MEMORY 0x100000000 57 | #define MAX_COMPRESS_LEVEL 12 58 | #define Z_DEFAULT_COMPRESS_LEVEL 9 59 | 60 | #define PCK_OK 0 /* Successful result */ 61 | /* beginning-of-error-codes */ 62 | #define PCK_MSG_USERCANCELED 1 /* User cancels */ 63 | #define PCK_ERROR 2 /* Generic error */ 64 | #define PCK_ERR_DISKFULL 3 /* Disk is full */ //Insufficient disk space, requested space: %d, remaining space: %d 65 | #define PCK_ERR_VIEWMAP_FAIL 4 /* Mapping failed */ 66 | #define PCK_ERR_VIEW 5 /* View failed */ 67 | #define PCK_ERR_OPENMAPVIEWR 6 /* OpenMappingViewAllRead failed */ 68 | #define PCK_ERR_MALLOC 7 /* Memory request failed */ 69 | 70 | /* end-of-error-codes */ 71 | 72 | //The length of the string used when converting numbers to characters 73 | #define CHAR_NUM_LEN 12 74 | 75 | #define MAX_INDEXTABLE_CLEARTEXT_LENGTH 0x120 76 | #define MAX_TAIL_LENGTH 300 77 | 78 | #define PCK_BEGINCOMPRESS_SIZE 20 79 | #define MAX_PATH_PCK_256 256 80 | #define MAX_PATH_PCK_260 260 81 | #define PCK_ADDITIONAL_INFO_SIZE 252 82 | #define PCK_DATA_START_AT 12 83 | 84 | #define PCK_ENTRY_TYPE_INDEX 1 85 | #define PCK_ENTRY_TYPE_NODE 2 86 | #define PCK_ENTRY_TYPE_FOLDER 4 87 | #define PCK_ENTRY_TYPE_DOTDOT 8 88 | #define PCK_ENTRY_TYPE_ROOT 16 89 | #define PCK_ENTRY_TYPE_TAIL_INDEX 0x80000000 90 | //#define PCK_ENTRY_TYPE_TAIL_INDEX 0x100000000 91 | 92 | #define PCK_ADDITIONAL_KEY "Angelica File Package" 93 | #define PCK_ADDITIONAL_INFO PCK_ADDITIONAL_KEY", Perfect World Co. Ltd. 2002~2008. All Rights Reserved.\r\nCreated by WinPCK v" WINPCK_VERSION 94 | -------------------------------------------------------------------------------- /PckDll/include/pck_dependencies.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "pck_default_vars.h" 4 | #include "PckModelStripDefines.h" 5 | 6 | //callback function to display list 7 | typedef void(*SHOW_LIST_CALLBACK)(void*, int32_t, const wchar_t *, int32_t, uint64_t, uint64_t, void*); 8 | typedef int32_t(*FeedbackCallback)(void* pTag, int32_t eventId, size_t wParam, ssize_t lParam); 9 | 10 | //Log echo callback function 11 | typedef void(*ShowLogA)(const char log_level, const char *str); 12 | typedef void(*ShowLogW)(const char log_level, const wchar_t *str); 13 | 14 | typedef struct _PCK_UNIFIED_FILEENTRY { 15 | int32_t entryType; 16 | wchar_t szName[MAX_PATH_PCK_260]; 17 | }PCK_UNIFIED_FILE_ENTRY, *LPPCK_UNIFIED_FILE_ENTRY; 18 | 19 | typedef PCK_UNIFIED_FILE_ENTRY* LPENTRY; 20 | typedef const PCK_UNIFIED_FILE_ENTRY* LPCENTRY; 21 | -------------------------------------------------------------------------------- /PckDll/pckdll.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/PckDll/pckdll.rc -------------------------------------------------------------------------------- /PckDll/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by pckdll.rc 4 | 5 | // The next set of default values for the new object 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WinPCK 2 | Perfect World Company game pck file compressed package viewer 3 | 4 | Currently supported game versions are: Zhu Xian, Perfect World, Saint Seiya, Swordsman, Gods and Demons, Hot Dance Party, Pocket Westward Journey 5 | 6 | ChangeLog WinPCK v1.33.1.0: 7 | 8 | - Improved support for .pkx files 9 | - Fixed package creation bug 10 | 11 | ChangeLog WinPCK v1.33.0.3: 12 | 13 | - Reading of .cup files, WinPCK will decode the cup. 14 | - Installation in the Windows registry with .cup 15 | - Reading of .pck files with .pkx larger than 2GB 16 | - Reading of .pck files with .pkx1 17 | - English translation 18 | - Updated to C++20 19 | - Updated for Visual Studio 2022 20 | -------------------------------------------------------------------------------- /Release/pckdll_x64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/Release/pckdll_x64.lib -------------------------------------------------------------------------------- /WinPCK/ShowLogOnDlgListView.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // ShowLogOnDlgListView.cpp: Display the log in the listView 3 | // 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2018.6.4 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #include 13 | #include "ShowLogOnDlgListView.h" 14 | #include "resource.h" 15 | #include 16 | #include 17 | 18 | CLogUnits LogUnits; 19 | 20 | void PreInsertLogToList(const char ch, const wchar_t *str) 21 | { 22 | LogUnits.InsertLog(ch, str); 23 | } 24 | 25 | 26 | CLogUnits::CLogUnits() 27 | { 28 | } 29 | 30 | CLogUnits::~CLogUnits() 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /WinPCK/ShowLogOnDlgListView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | using namespace std; 5 | 6 | typedef std::function InsertLogFunc; 7 | typedef std::function SetStatusBarInfoFunc; 8 | 9 | class CLogUnits 10 | { 11 | public: 12 | CLogUnits(); 13 | ~CLogUnits(); 14 | 15 | void setInsertLogFunc(InsertLogFunc func) { 16 | m_InsertLog = func; 17 | } 18 | 19 | void setSetStatusBarInfoFunc(SetStatusBarInfoFunc func) { 20 | 21 | m_SetStatusBarInfo = func; 22 | } 23 | 24 | void InsertLog(const char ch, const wchar_t* str) { 25 | try { 26 | m_InsertLog(ch, str); 27 | } 28 | catch (std::bad_function_call ex) { 29 | ; 30 | } 31 | } 32 | 33 | void SetStatusBarInfo(const wchar_t* str) { 34 | try { 35 | m_SetStatusBarInfo(str); 36 | } 37 | catch(std::bad_function_call ex) { 38 | ; 39 | } 40 | } 41 | 42 | private: 43 | 44 | InsertLogFunc m_InsertLog = nullptr; 45 | SetStatusBarInfoFunc m_SetStatusBarInfo = nullptr; 46 | 47 | }; 48 | 49 | extern CLogUnits LogUnits; 50 | void PreInsertLogToList(const char, const wchar_t *); 51 | 52 | //log 53 | #define LOG_IMAGE_NOTICE 0 54 | #define LOG_IMAGE_INFO 1 55 | #define LOG_IMAGE_WARNING 2 56 | #define LOG_IMAGE_ERROR 3 57 | #define LOG_IMAGE_DEBUG 4 58 | #define LOG_IMAGE_EMPTY 5 59 | #define LOG_IMAGE_COUNT 6 60 | 61 | -------------------------------------------------------------------------------- /WinPCK/WinPCK_2022.common.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | 8 | $(TargetPath) 9 | 10 | $(ProjectDir) 11 | 12 | true 13 | 14 | 15 | true 16 | true 17 | 18 | true 19 | true 20 | true 21 | 22 | -------------------------------------------------------------------------------- /WinPCK/X86-64.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | WinPCK archiver 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | true 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /WinPCK/decode_dds/BlendPicture.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/decode_dds/BlendPicture.cpp -------------------------------------------------------------------------------- /WinPCK/decode_dds/DDSTextureLoader.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: DDSTextureLoader.h 3 | // 4 | // Functions for loading a DDS texture without using D3DX 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //-------------------------------------------------------------------------------------- 8 | 9 | #include "DDS.h" 10 | 11 | D3DFORMAT GetD3D9Format( const DDS_PIXELFORMAT& ddpf ); 12 | UINT BitsPerPixel( D3DFORMAT fmt ); 13 | -------------------------------------------------------------------------------- /WinPCK/decode_dds/DdsTgaDecoder.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/decode_dds/DdsTgaDecoder.cpp -------------------------------------------------------------------------------- /WinPCK/decode_dds/DdsTgaDecoder.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/decode_dds/DdsTgaDecoder.h -------------------------------------------------------------------------------- /WinPCK/decode_dds/DdsTgaDecoderBuildDIB.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/decode_dds/DdsTgaDecoderBuildDIB.cpp -------------------------------------------------------------------------------- /WinPCK/decode_dds/DdsTgaDecoderDefine.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/decode_dds/DdsTgaDecoderDefine.h -------------------------------------------------------------------------------- /WinPCK/decode_dds/DrawPicture.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // DrawPicture.cpp: display dds, tga images 3 | // Decode dds, tga and display 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2018.5.29 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #include 13 | #include 14 | #include "ShowPicture.h" 15 | #include "DdsTgaDecoder.h" 16 | 17 | 18 | BOOL CShowPicture::BuildImage() 19 | { 20 | //Read dds header 21 | CDdsTgaDecoder cDdsTgaDecoder; 22 | switch(m_picFormat) { 23 | case FMT_DDS: 24 | 25 | if(!cDdsTgaDecoder.DecodeDDS(m_resBufferInClass, m_bufsize, m_DecodedDIBData, m_picWidth, m_picHeight, m_szPictureFormat)) { 26 | MessageBoxA(NULL, TEXT_SHOWPIC_ERROR, NULL, MB_OK | MB_ICONERROR); 27 | assert(FALSE); 28 | return FALSE; 29 | } 30 | { 31 | free(m_resBufferInClass); 32 | m_resBufferInClass = NULL; 33 | m_lpmyImage = new Bitmap(m_picWidth, m_picHeight, cDdsTgaDecoder.GetStride(), cDdsTgaDecoder.GetPixelFormat(), m_DecodedDIBData); 34 | } 35 | break; 36 | 37 | case FMT_TGA: 38 | 39 | if(!cDdsTgaDecoder.DecodeTGA(m_resBufferInClass, m_bufsize, m_DecodedDIBData, m_picWidth, m_picHeight, m_szPictureFormat)) { 40 | MessageBoxA(NULL, TEXT_SHOWPIC_ERROR, NULL, MB_OK | MB_ICONERROR); 41 | assert(FALSE); 42 | return FALSE; 43 | } 44 | 45 | free(m_resBufferInClass); 46 | m_resBufferInClass = NULL; 47 | 48 | m_lpmyImage = new Bitmap(m_picWidth, m_picHeight, cDdsTgaDecoder.GetStride(), cDdsTgaDecoder.GetPixelFormat(), m_DecodedDIBData); 49 | break; 50 | 51 | case FMT_RAW: //bmp,jpg,png.. 52 | 53 | CreateStreamOnHGlobal(m_hGlobal, FALSE, &m_stream); 54 | if(!m_stream) { 55 | MessageBoxA(NULL, TEXT_SHOWPIC_ERROR, NULL, MB_OK | MB_ICONERROR); 56 | assert(FALSE); 57 | return FALSE; 58 | } 59 | 60 | //show picture 61 | m_lpmyImage = new Image(m_stream); 62 | 63 | //Look at the picture size and display window size 64 | m_picWidth = m_lpmyImage->GetWidth(); 65 | m_picHeight = m_lpmyImage->GetHeight(); 66 | 67 | break; 68 | 69 | default: 70 | 71 | MessageBoxA(NULL, TEXT_NOT_DEFINE, NULL, MB_OK | MB_ICONERROR); 72 | return FALSE; 73 | break; 74 | } 75 | 76 | return TRUE; 77 | } 78 | 79 | BOOL CShowPicture::DrawPictureOnDC() 80 | { 81 | DrawBlockOnDlg(); 82 | 83 | m_lpoGraph = new Graphics(m_MemDC); 84 | 85 | m_lpoGraph->DrawImage(m_lpmyImage, 0, 0, m_picWidth, m_picHeight); 86 | 87 | if(NULL != m_lpoGraph) 88 | delete m_lpoGraph; 89 | m_lpoGraph = NULL; 90 | 91 | //The following in the source code is executed when FMT_RAW == iFormat 92 | if (FMT_RAW == m_picFormat) { 93 | 94 | //m_lpmyImage cannot be released now, it will be used when saving as png 95 | if(NULL != m_lpmyImage) 96 | delete m_lpmyImage; 97 | m_lpmyImage = NULL; 98 | 99 | if (NULL != m_stream) 100 | m_stream->Release(); 101 | m_stream = NULL; 102 | 103 | if (NULL != m_hGlobal) 104 | GlobalFree(m_hGlobal); 105 | m_hGlobal = NULL; 106 | } 107 | 108 | return TRUE; 109 | } -------------------------------------------------------------------------------- /WinPCK/decode_dds/SavePicture.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // SavePicture.cpp: Construct DIB data 3 | // Save the decoded dds and tga data as files 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2018.5.29 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #include 13 | #include "ShowPicture.h" 14 | 15 | int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) 16 | { 17 | UINT num = 0; 18 | UINT size = 0; 19 | 20 | ImageCodecInfo* pImageCodecInfo = NULL; 21 | 22 | GetImageEncodersSize(&num, &size); 23 | if(size == 0) { 24 | return -1; 25 | } 26 | pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); 27 | if(pImageCodecInfo == NULL) { 28 | return -1; 29 | } 30 | 31 | GetImageEncoders(num, size, pImageCodecInfo); 32 | 33 | for(UINT j = 0; j < num; ++j) { 34 | if(wcscmp(pImageCodecInfo[j].MimeType, format) == 0) { 35 | *pClsid = pImageCodecInfo[j].Clsid; 36 | free(pImageCodecInfo); 37 | return j; 38 | } 39 | } 40 | 41 | free(pImageCodecInfo); 42 | return -1; 43 | } 44 | 45 | BOOL CShowPicture::Save(const WCHAR *lpszFilename) 46 | { 47 | CLSID pngClsid; 48 | GetEncoderClsid(L"image/png", &pngClsid); 49 | m_lpmyImage->Save(lpszFilename, &pngClsid, NULL); 50 | return TRUE; 51 | } -------------------------------------------------------------------------------- /WinPCK/decode_dds/ShowPicture.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/decode_dds/ShowPicture.h -------------------------------------------------------------------------------- /WinPCK/decode_dds/ShowPictureWithZoom.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/decode_dds/ShowPictureWithZoom.h -------------------------------------------------------------------------------- /WinPCK/globals.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // globals.h: WinPCK global header file 3 | // Global header file of interface class 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2012.4.10 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #ifndef _GLOBALS_H_ 13 | #define _GLOBALS_H_ 14 | 15 | #include 16 | #include 17 | #include 18 | using namespace std; 19 | 20 | #ifndef UNICODE 21 | #error("please use Unicode charset") 22 | #endif 23 | 24 | //****** some defines ******* 25 | #define _USE_CUSTOMDRAW_ 26 | 27 | #define THIS_NAME "WinPCK " 28 | #define THIS_DESC L"Perfect World series game PCK file package comprehensive viewer" 29 | #define THIS_AUTHOR L"Programming: stsm/liqf/Li Qiufeng\r\n" \ 30 | "E-Mail: stsm85@126.com " 31 | #define THIS_UESDLIB L"This software is open source \n\n" \ 32 | "Updated by Haly \n\n" \ 33 | "updated source code address : https://github.com/halysondev/WinPCK\r\n\r\n" \ 34 | "stsm source code address\r\nhttps://github.com/stsm85\r\n\r\n" \ 35 | "Use open source libraries\r\n" \ 36 | "VC LTL(Copyright (C) Chuyu-Team)\r\n" \ 37 | "libdeflate(Copyright (C) 2016 Eric Biggers)\r\n" \ 38 | "zlib(Copyright (C) 1995-2011 Mark Adler)\r\n" \ 39 | "tlib(Copyright (C) 1996-2010 H.Shirouzu) " \ 40 | 41 | 42 | #ifdef _WIN64 43 | #define THIS_MAIN_CAPTION THIS_NAME \ 44 | "64bit v" \ 45 | WINPCK_VERSION 46 | #else 47 | #define THIS_MAIN_CAPTION THIS_NAME \ 48 | "v"WINPCK_VERSION 49 | #endif 50 | 51 | 52 | //#define SHELL_LISTVIEW_PARENT_CLASS TEXT("SHELLDLL_DefView") 53 | #define SHELL_LISTVIEW_ROOT_CLASS1 TEXT("ExploreWClass") 54 | #define SHELL_LISTVIEW_ROOT_CLASS2 TEXT("CabinetWClass") 55 | //#define SHELL_EXENAME TEXT("\\explorer.exe") 56 | 57 | #define TEXT_INVALID_PATHCHAR "\\/:*?\"<>|" 58 | 59 | #define TEXT_FILE_FILTER TEXT( "PCK compressed file(*.pck;*.zup;*.cup)\0*.pck;*.zup;*.cup\0") \ 60 | TEXT( "All files\0*.*\0\0") 61 | 62 | #define IMGLIST_FOLDER 0 63 | #define IMGLIST_FILE 1 64 | 65 | #define WM_TIMER_PROGRESS_100 (WM_USER + 1) 66 | 67 | #define TIMER_PROGRESS 100 68 | 69 | #ifndef SE_CREATE_SYMBOLIC_LINK_NAME 70 | #define SE_CREATE_SYMBOLIC_LINK_NAME TEXT("SeCreateSymbolicLinkPrivilege") 71 | #endif 72 | 73 | #endif -------------------------------------------------------------------------------- /WinPCK/guirelated.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/guirelated.cpp -------------------------------------------------------------------------------- /WinPCK/icons/DROP.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/DROP.cur -------------------------------------------------------------------------------- /WinPCK/icons/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/Thumbs.db -------------------------------------------------------------------------------- /WinPCK/icons/chinaz1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/chinaz1.ico -------------------------------------------------------------------------------- /WinPCK/icons/chinaz1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/chinaz1.png -------------------------------------------------------------------------------- /WinPCK/icons/chinaz1x.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/chinaz1x.ico -------------------------------------------------------------------------------- /WinPCK/icons/dir.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/dir.ico -------------------------------------------------------------------------------- /WinPCK/icons/edit.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/edit.ico -------------------------------------------------------------------------------- /WinPCK/icons/edit_add.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/edit_add.ico -------------------------------------------------------------------------------- /WinPCK/icons/exit.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/exit.ico -------------------------------------------------------------------------------- /WinPCK/icons/file.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/file.ico -------------------------------------------------------------------------------- /WinPCK/icons/fileclose.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/fileclose.ico -------------------------------------------------------------------------------- /WinPCK/icons/filenew.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/filenew.ico -------------------------------------------------------------------------------- /WinPCK/icons/fileopen.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/fileopen.ico -------------------------------------------------------------------------------- /WinPCK/icons/filesave.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/filesave.ico -------------------------------------------------------------------------------- /WinPCK/icons/info.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/info.ico -------------------------------------------------------------------------------- /WinPCK/icons/lin_agt_wrench.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/lin_agt_wrench.ico -------------------------------------------------------------------------------- /WinPCK/icons/logdebug.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/logdebug.ico -------------------------------------------------------------------------------- /WinPCK/icons/logerror.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/logerror.ico -------------------------------------------------------------------------------- /WinPCK/icons/logerror.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/logerror.png -------------------------------------------------------------------------------- /WinPCK/icons/loginfo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/loginfo.ico -------------------------------------------------------------------------------- /WinPCK/icons/loginfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/loginfo.png -------------------------------------------------------------------------------- /WinPCK/icons/logwarning.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/logwarning.ico -------------------------------------------------------------------------------- /WinPCK/icons/logwarning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/logwarning.png -------------------------------------------------------------------------------- /WinPCK/icons/rebuild.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/rebuild.ico -------------------------------------------------------------------------------- /WinPCK/icons/save_all.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/save_all.ico -------------------------------------------------------------------------------- /WinPCK/icons/search.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/search.ico -------------------------------------------------------------------------------- /WinPCK/icons/stop.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/icons/stop.ico -------------------------------------------------------------------------------- /WinPCK/listViewFunc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/listViewFunc.cpp -------------------------------------------------------------------------------- /WinPCK/mainControlStatus.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // mainControlStatus.cpp: WinPCK interface thread part 3 | // Interface control function 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2019.9.10 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #include "tlib.h" 13 | #include "resource.h" 14 | //#include "globals.h" 15 | #include "winmain.h" 16 | 17 | 18 | void TInstDlg::SetStatusBarText(int iPart, LPCSTR lpszText) 19 | { 20 | SendDlgItemMessageA(IDC_STATUS, SB_SETTEXTA, iPart, (LPARAM)lpszText); 21 | SendDlgItemMessageA(IDC_STATUS, SB_SETTIPTEXTA, iPart, (LPARAM)lpszText); 22 | } 23 | 24 | void TInstDlg::SetStatusBarText(int iPart, LPCWSTR lpszText) 25 | { 26 | SendDlgItemMessageW(IDC_STATUS, SB_SETTEXTW, iPart, (LPARAM)lpszText); 27 | SendDlgItemMessageW(IDC_STATUS, SB_SETTIPTEXTW, iPart, (LPARAM)lpszText); 28 | } 29 | 30 | void TInstDlg::SetStatusBarTitle(LPCWSTR lpszText) 31 | { 32 | SetStatusBarText(0, lpszText); 33 | } 34 | 35 | void TInstDlg::SetStatusBarFileSize(uint64_t size) 36 | { 37 | wchar_t szString[64]; 38 | swprintf_s(szString, 64, GetLoadStrW(IDS_STRING_OPENFILESIZE), size); 39 | SetStatusBarText(1, szString); 40 | } 41 | 42 | void TInstDlg::SetStatusBarFileCount(uint32_t size) 43 | { 44 | wchar_t szString[64]; 45 | swprintf_s(szString, 64, GetLoadStrW(IDS_STRING_OPENFILECOUNT), size); 46 | SetStatusBarText(2, szString); 47 | } 48 | 49 | void TInstDlg::ClearStatusBarProgress() 50 | { 51 | SetStatusBarText(3, ""); 52 | } 53 | 54 | void TInstDlg::SetStatusBarProgress(LPCWSTR lpszText) 55 | { 56 | SetStatusBarText(3, lpszText); 57 | } 58 | 59 | void TInstDlg::SetStatusBarInfo(LPCWSTR lpszText) 60 | { 61 | SetStatusBarText(4, lpszText); 62 | } -------------------------------------------------------------------------------- /WinPCK/miscdlg.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MISCDLG_H_ 3 | #define _MISCDLG_H_ 4 | 5 | #include "tlib.h" 6 | #include "resource.h" 7 | #include 8 | #include 9 | #include "pck_handle.h" 10 | 11 | class TInfoDlg : public TDlg 12 | { 13 | public: 14 | TInfoDlg(TWin *_win) : TDlg(IDD_DIALOG_INFO, _win) {} 15 | virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl); 16 | virtual BOOL EvCreate(LPARAM lParam); 17 | }; 18 | 19 | class TSearchDlg : public TDlg 20 | { 21 | protected: 22 | wchar_t *dirBuf; 23 | 24 | public: 25 | TSearchDlg(wchar_t *_dirBuf, TWin *_win) : TDlg(IDD_DIALOG_SEARCH, _win) { dirBuf = _dirBuf; } 26 | virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl); 27 | virtual BOOL EvCreate(LPARAM lParam); 28 | }; 29 | 30 | class TCompressOptDlg : public TDlg 31 | { 32 | public: 33 | TCompressOptDlg(TWin *_win) : TDlg(IDD_DIALOG_COMPRESS, _win) { } 34 | 35 | virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl); 36 | virtual BOOL EvCreate(LPARAM lParam); 37 | virtual BOOL EventScroll(UINT uMsg, int nCode, int nPos, HWND scrollBar); 38 | }; 39 | 40 | class TAttrDlg : public TDlg 41 | { 42 | protected: 43 | const PCK_UNIFIED_FILE_ENTRY* lpPckInfo; 44 | 45 | wchar_t *lpszPath; 46 | 47 | public: 48 | TAttrDlg(const PCK_UNIFIED_FILE_ENTRY *_lpPckInfo, wchar_t *_lpszPath, TWin *_win); 49 | //~TAttrDlg(); 50 | 51 | virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl); 52 | virtual BOOL EvCreate(LPARAM lParam); 53 | }; 54 | 55 | 56 | class TRebuildOptDlg : public TDlg 57 | { 58 | private: 59 | 60 | TCHAR szScriptFile[MAX_PATH]; 61 | BOOL *lpNeedRecompress; 62 | TCHAR* lpszScriptFile; 63 | public: 64 | TRebuildOptDlg(TCHAR* _lpszScriptFile, BOOL *_lpNeedRecompress, TWin *_win) : 65 | TDlg(IDD_DIALOG_REBUILD_OPT, _win), 66 | lpNeedRecompress(_lpNeedRecompress), 67 | isScriptParseSuccess(FALSE), 68 | lpszScriptFile(_lpszScriptFile) 69 | { 70 | *szScriptFile = 0; 71 | } 72 | 73 | 74 | virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl); 75 | virtual BOOL EvCreate(LPARAM lParam); 76 | virtual BOOL EventScroll(UINT uMsg, int nCode, int nPos, HWND scrollBar); 77 | virtual BOOL EvDropFiles(HDROP hDrop); 78 | 79 | private: 80 | 81 | void OnOK(); 82 | BOOL OnOpenClick(); 83 | BOOL isScriptParseSuccess; 84 | BOOL ParseScript(); 85 | }; 86 | 87 | 88 | class TStripDlg : public TDlg 89 | { 90 | private: 91 | 92 | int *pStripFlag; 93 | 94 | public: 95 | TStripDlg(int *_pStripFlag, TWin *_win) : 96 | TDlg(IDD_DIALOG_STRIP, _win), 97 | pStripFlag(_pStripFlag) 98 | {} 99 | 100 | virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl); 101 | virtual BOOL EvCreate(LPARAM lParam); 102 | 103 | private: 104 | void OnOK(); 105 | }; 106 | #endif 107 | -------------------------------------------------------------------------------- /WinPCK/tCompressOptDlg.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // tCompressOptDlg.cpp: WinPCK interface thread part 3 | // Dialog code 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2017.12.26 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #include "globals.h" 13 | #include "miscdlg.h" 14 | #include "pck_handle.h" 15 | 16 | /* 17 | Compression options 18 | */ 19 | BOOL TCompressOptDlg::EvCreate(LPARAM lParam) 20 | { 21 | char szStr[8]; 22 | 23 | SendDlgItemMessage(IDC_EDIT_MEM, EM_LIMITTEXT, 4, 0); 24 | 25 | SendDlgItemMessage(IDC_SLIDER_LEVEL, TBM_SETRANGE, FALSE, MAKELONG(1, pck_getMaxCompressLevel())); 26 | SendDlgItemMessage(IDC_SLIDER_THREAD, TBM_SETRANGE, FALSE, MAKELONG(1, pck_getMaxThreadUpperLimit())); 27 | SendDlgItemMessage(IDC_SLIDER_LEVEL, TBM_SETPOS, TRUE, (LPARAM)pck_getCompressLevel()); 28 | SendDlgItemMessage(IDC_SLIDER_THREAD, TBM_SETPOS, TRUE, (LPARAM)pck_getMaxThread()); 29 | 30 | SendDlgItemMessageA(IDC_CBO_CODEPAGE, CB_ADDSTRING, 0, (LPARAM)"CP936"); 31 | SendDlgItemMessageA(IDC_CBO_CODEPAGE, CB_SETCURSEL, 0, 0); 32 | 33 | SetDlgItemTextA(IDC_STATIC_LEVEL, ultoa(pck_getCompressLevel(), szStr, 10)); 34 | SetDlgItemTextA(IDC_STATIC_THREAD, ultoa(pck_getMaxThread(), szStr, 10)); 35 | SetDlgItemTextA(IDC_EDIT_MEM, ultoa((pck_getMTMaxMemory()) >> 20, szStr, 10)); 36 | 37 | return TRUE; 38 | } 39 | 40 | BOOL TCompressOptDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl) 41 | { 42 | char szStr[8]; 43 | 44 | switch(wID) { 45 | case IDOK: 46 | { 47 | DWORD dwCompressLevel = pck_getCompressLevel(); 48 | pck_setCompressLevel(SendDlgItemMessage(IDC_SLIDER_LEVEL, TBM_GETPOS, 0, 0)); 49 | 50 | pck_setMaxThread(SendDlgItemMessage(IDC_SLIDER_THREAD, TBM_GETPOS, 0, 0)); 51 | 52 | GetDlgItemTextA(IDC_EDIT_MEM, szStr, 8); 53 | pck_setMTMaxMemory((atoi(szStr) << 20)); 54 | 55 | EndDialog(wID); 56 | return TRUE; 57 | } 58 | case IDCANCEL: 59 | EndDialog(wID); 60 | return TRUE; 61 | } 62 | return FALSE; 63 | } 64 | 65 | BOOL TCompressOptDlg::EventScroll(UINT uMsg, int nCode, int nPos, HWND scrollBar) 66 | { 67 | int iPos; 68 | char szStr[4]; 69 | 70 | switch(nCode) { 71 | case TB_THUMBTRACK: 72 | case TB_PAGEDOWN: 73 | case TB_PAGEUP: 74 | 75 | iPos = ::SendMessage(scrollBar, TBM_GETPOS, 0, 0); 76 | 77 | if(scrollBar == GetDlgItem(IDC_SLIDER_LEVEL)) { 78 | SetDlgItemTextA(IDC_STATIC_LEVEL, ultoa(iPos, szStr, 10)); 79 | break; 80 | } 81 | if(scrollBar == GetDlgItem(IDC_SLIDER_THREAD)) { 82 | SetDlgItemTextA(IDC_STATIC_THREAD, ultoa(iPos, szStr, 10)); 83 | break; 84 | } 85 | 86 | break; 87 | } 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /WinPCK/tInfoDlg.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // tInfoDlg.cpp: WinPCK interface thread part 3 | // Dialog code 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is expected to be open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2017.12.26 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #include "globals.h" 13 | #include "miscdlg.h" 14 | #include "PckHeader.h" 15 | 16 | /* 17 | Additional information dialog 18 | */ 19 | BOOL TInfoDlg::EvCreate(LPARAM lParam) 20 | { 21 | SendDlgItemMessage(IDC_EDIT_INFO, EM_LIMITTEXT, pck_GetAdditionalInfoMaxSize() - 1, 0); 22 | SetDlgItemTextA(IDC_EDIT_INFO, pck_GetAdditionalInfo()); 23 | return TRUE; 24 | } 25 | 26 | BOOL TInfoDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl) 27 | { 28 | char *szAdditionalInfo; 29 | switch(wID) { 30 | case IDOK: 31 | szAdditionalInfo = new char[pck_GetAdditionalInfoMaxSize()]; 32 | memset(szAdditionalInfo, 0, pck_GetAdditionalInfoMaxSize()); 33 | GetDlgItemTextA(IDC_EDIT_INFO, szAdditionalInfo, pck_GetAdditionalInfoMaxSize()); 34 | 35 | //Returning 1 means the operation is successful, success=WINPCK_OK 36 | pck_SetAdditionalInfo(szAdditionalInfo); 37 | EndDialog(wID); 38 | return TRUE; 39 | 40 | case IDCANCEL: 41 | EndDialog(wID); 42 | return TRUE; 43 | } 44 | return FALSE; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /WinPCK/tLogDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/tLogDlg.cpp -------------------------------------------------------------------------------- /WinPCK/tLogDlg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "tlib.h" 4 | #include "resource.h" 5 | 6 | class TLogDlg : public TDlg 7 | { 8 | private: 9 | 10 | HWND hWndList; 11 | wchar_t szExePath[MAX_PATH]; 12 | 13 | int m_LogListCount = 0; 14 | 15 | wchar_t* pszLogFileName(); 16 | wchar_t* pszTargetListLog(int iItem); 17 | 18 | int m_iCurrentHotItem; 19 | const char m_szLogPrefix[6] = { 'N', 'I', 'W', 'E', 'D', ' ' }; 20 | 21 | int log_level_char_to_int(const char level); 22 | void _InsertLogIntoList(const char, const wchar_t *); 23 | 24 | public: 25 | TLogDlg(TWin *_win) : TDlg(IDD_DIALOG_LOG, _win) { } 26 | 27 | virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl); 28 | virtual BOOL EvCreate(LPARAM lParam); 29 | virtual BOOL EvSize(UINT fwSizeType, WORD nWidth, WORD nHeight); 30 | virtual BOOL EvClose(); 31 | virtual BOOL EvNotify(UINT ctlID, NMHDR *pNmHdr); 32 | 33 | void InsertLogToList(const char, const wchar_t *); 34 | }; 35 | -------------------------------------------------------------------------------- /WinPCK/tPreviewDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/tPreviewDlg.cpp -------------------------------------------------------------------------------- /WinPCK/tPreviewDlg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tlib.h" 3 | #include "resource.h" 4 | #include "ShowPictureWithZoom.h" 5 | #include "pck_handle.h" 6 | 7 | class CPriviewInDlg 8 | { 9 | public: 10 | CPriviewInDlg(); 11 | ~CPriviewInDlg(); 12 | 13 | BOOL Show(const PCK_UNIFIED_FILE_ENTRY* const lpPckFileIndexToShow, TWin *_win); 14 | 15 | protected: 16 | 17 | //dialog box to be displayed 18 | TDlg * dlg; 19 | 20 | void * m_buffer; 21 | DWORD m_buffersize; 22 | 23 | PICFORMAT GetPicFormatFromFilename(LPCWSTR lpszFilename); 24 | BOOL AllocBuffer(PICFORMAT fmt, DWORD dwSize); 25 | }; 26 | 27 | 28 | #pragma region TViewDlg 29 | 30 | #define VIEW_TEXT_MAX_BUFFER (16*1024*1024) //16MB 31 | #define VIEW_RAW_MAX_BUFFER (16*1024*1024) //16MB 32 | 33 | class TViewDlg : public TDlg 34 | { 35 | protected: 36 | LPBYTE *buf; 37 | const char *lpszTextShow; 38 | 39 | DWORD dwSize; 40 | const wchar_t *lpszFile; 41 | 42 | int textType; 43 | 44 | void ShowRaw(LPBYTE lpbuf, size_t rawlength); 45 | 46 | public: 47 | TViewDlg(LPBYTE *_buf, DWORD _dwSize, const wchar_t *_lpszFile, TWin *_win); 48 | ~TViewDlg(); 49 | 50 | virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl); 51 | virtual BOOL EvCreate(LPARAM lParam); 52 | }; 53 | #pragma endregion 54 | 55 | #pragma region TPicDlg 56 | 57 | //#define DBG_DISABLE_ALPHA 58 | 59 | class TPicDlg : public TDlg 60 | { 61 | protected: 62 | 63 | //window title 64 | wchar_t m_szTitle[MAX_PATH]; 65 | 66 | //Image data and size to be displayed 67 | LPBYTE *buf; 68 | UINT32 dwSize; 69 | 70 | //file name 71 | const wchar_t *lpszFile; 72 | 73 | //Format 74 | PICFORMAT iFormat; 75 | 76 | //Record the current mouse position 77 | POINT pointMouse; 78 | BOOL isMouseDown; 79 | 80 | CShowPictureWithZoom *lpShowPicture; 81 | 82 | BOOL SaveFile(); 83 | 84 | void InitFixedShowPositionAndShowWindow(); 85 | 86 | void FreshWindowTitle(); 87 | 88 | 89 | public: 90 | TPicDlg(LPBYTE *_buf, UINT32 _dwSize, PICFORMAT _iFormat, const wchar_t *_lpszFile, TWin *_win); 91 | ~TPicDlg(); 92 | 93 | virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl); 94 | virtual BOOL EvCreate(LPARAM lParam); 95 | //virtual BOOL EvDrawItem(UINT ctlID, DRAWITEMSTRUCT *lpDis); 96 | virtual BOOL EvSize(UINT fwSizeType, WORD nWidth, WORD nHeight); 97 | //virtual BOOL EventScroll(UINT uMsg, int nCode, int nPos, HWND scrollBar); 98 | virtual BOOL EvMouseMove(UINT fwKeys, POINTS pos); 99 | virtual BOOL EvMouseWheel(UINT nFlags, short zDelta, POINTS pos); 100 | virtual BOOL EventButton(UINT uMsg, int nHitTest, POINTS pos); 101 | //virtual BOOL EvTimer(WPARAM timerID, TIMERPROC proc); 102 | //virtual BOOL EventCtlColor(UINT uMsg, HDC hDcCtl, HWND hWndCtl, HBRUSH *result); 103 | 104 | virtual BOOL EvPaint(void); 105 | //virtual BOOL EvClose(); 106 | 107 | }; 108 | #pragma endregion -------------------------------------------------------------------------------- /WinPCK/tSearchDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/tSearchDlg.cpp -------------------------------------------------------------------------------- /WinPCK/tStripDlg.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // tStripDlg.cpp: WinPCK interface thread part 3 | // Dialog code 4 | // 5 | // This program is written by Li Qiufeng/stsm/liqf 6 | // 7 | // This code is open source. Please retain the original author information for any modified release based on this code. 8 | // 9 | // 2018.12.29 10 | ////////////////////////////////////////////////////////////////////// 11 | 12 | #include "miscdlg.h" 13 | #include "PckModelStripDefines.h" 14 | 15 | BOOL TStripDlg::EvCreate(LPARAM lParam) 16 | { 17 | Show(); 18 | return FALSE; 19 | } 20 | 21 | BOOL TStripDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl) 22 | { 23 | switch (wID) { 24 | case IDOK: 25 | OnOK(); 26 | case IDCANCEL: 27 | EndDialog(wID); 28 | return TRUE; 29 | } 30 | return FALSE; 31 | } 32 | 33 | void TStripDlg::OnOK() 34 | { 35 | int flag = PCK_STRIP_NONE; 36 | 37 | flag |= (BST_CHECKED == IsDlgButtonChecked(IDC_CHECK_DDS) ? PCK_STRIP_DDS : PCK_STRIP_NONE); 38 | flag |= (BST_CHECKED == IsDlgButtonChecked(IDC_CHECK_ATT) ? PCK_STRIP_ATT : PCK_STRIP_NONE); 39 | flag |= (BST_CHECKED == IsDlgButtonChecked(IDC_CHECK_GFX) ? PCK_STRIP_GFX : PCK_STRIP_NONE); 40 | flag |= (BST_CHECKED == IsDlgButtonChecked(IDC_CHECK_ECM) ? PCK_STRIP_ECM : PCK_STRIP_NONE); 41 | 42 | *pStripFlag = flag; 43 | } -------------------------------------------------------------------------------- /WinPCK/tViewDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/WinPCK/tViewDlg.cpp -------------------------------------------------------------------------------- /base64/base64.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "base64.h" 3 | #include 4 | 5 | BEXTERN uint32_t BEXPORT decodeBound(const char* pdata,const uint32_t data_size) 6 | { 7 | const char* input = pdata; 8 | uint32_t size; 9 | uint32_t dstsize; 10 | 11 | if(0 == data_size){ 12 | size = strlen(input); 13 | }else if(0 == (data_size & 0x3)){ 14 | size = data_size; 15 | }else{ 16 | return 0; 17 | } 18 | 19 | input += size; 20 | input -= 2; 21 | 22 | dstsize = (size >>2) * 3; 23 | 24 | if('=' == *input++) 25 | dstsize -= 2; 26 | else if('=' == *input) 27 | dstsize -= 1; 28 | 29 | return dstsize; 30 | } 31 | 32 | BEXTERN uint32_t BEXPORT encodeBound(const uint32_t data_size) 33 | { 34 | 35 | if(0 == data_size) 36 | return 0; 37 | 38 | return (((data_size + 2) / 3)<<2) + 1; 39 | 40 | } 41 | 42 | // 43 | //#ifdef _WINDLL 44 | // 45 | // #include 46 | // 47 | // #ifdef _MANAGED 48 | // #pragma managed(push, off) 49 | // #endif 50 | // 51 | // BOOL APIENTRY DllMain( HMODULE hModule, 52 | // DWORD ul_reason_for_call, 53 | // LPVOID lpReserved 54 | // ) 55 | // { 56 | // switch (ul_reason_for_call) 57 | // { 58 | // case DLL_PROCESS_ATTACH: 59 | // case DLL_THREAD_ATTACH: 60 | // case DLL_THREAD_DETACH: 61 | // case DLL_PROCESS_DETACH: 62 | // break; 63 | // } 64 | // return TRUE; 65 | // } 66 | // 67 | // #ifdef _MANAGED 68 | // #pragma managed(pop) 69 | // #endif 70 | // 71 | //#endif //_WINDLL 72 | // -------------------------------------------------------------------------------- /base64/base64.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _BASE64_H_ 3 | #define _BASE64_H_ 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | //#define BASE64_DLLEXP 11 | //#define BASE64_DLLIMP 12 | #define BASE64_STATIC 13 | 14 | #ifdef BASE64_DLLEXP 15 | # define BEXTERN extern __declspec(dllexport) 16 | # define BEXPORTVA __cdecl 17 | # define BEXPORT __stdcall 18 | #elif defined BASE64_STATIC 19 | # define BEXTERN 20 | # define BEXPORTVA __cdecl 21 | # define BEXPORT __stdcall 22 | #else 23 | # define BEXTERN extern __declspec(dllimport) 24 | # define BEXPORTVA __cdecl 25 | # define BEXPORT __stdcall 26 | #endif 27 | 28 | #define BASE64_ZUP 0 29 | 30 | BEXTERN uint32_t BEXPORT decodeBound(const char* pdata,const uint32_t data_size); 31 | BEXTERN uint32_t BEXPORT encodeBound(const uint32_t data_size); 32 | 33 | BEXTERN void BEXPORT base64_encode(const void* pdata,const uint32_t data_size,void* out_pcode); 34 | BEXTERN void BEXPORT base64_decode(const void* pdata,const uint32_t data_size,void* out_pcode); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif //_BASE64_H_ -------------------------------------------------------------------------------- /base64/base64_2022.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 6 | h;hpp;hxx;hm;inl;inc;xsd 7 | 8 | 9 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 10 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 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 23 | 24 | 25 | 26 | 27 | Source 28 | 29 | 30 | Source 31 | 32 | 33 | Source 34 | 35 | 36 | -------------------------------------------------------------------------------- /base64/base64_decoder.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "base64.h" 3 | 4 | #if BASE64_ZUP 5 | const uint32_t BASE64_DECODE[] = { 6 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0 7 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //1 8 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 63, 0, 0, //2 9 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, //3 10 | 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, //4 11 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, //5 12 | 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, //6 13 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0}; //7 14 | 15 | #else 16 | 17 | const uint32_t BASE64_DECODE[] = { 18 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0 19 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //1 20 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, //2 21 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, //3 22 | 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, //4 23 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, //5 24 | 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, //6 25 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0}; //7 26 | 27 | #endif 28 | 29 | 30 | //Encoding function (original data address, original data byte size, encoding output address), using char as the type 31 | BEXTERN void BEXPORT base64_decode(const void* pdata, const uint32_t data_size, void* out_pcode) 32 | { 33 | const uint8_t* input = (const uint8_t*)pdata; 34 | const uint8_t* input_end = &input[data_size] - 4; 35 | uint8_t* output = (uint8_t*)out_pcode; 36 | 37 | for (; input < input_end; input += 4, output += 3) 38 | { 39 | uint32_t decode0 = BASE64_DECODE[input[0]]; 40 | uint32_t decode1 = BASE64_DECODE[input[1]]; 41 | uint32_t decode2 = BASE64_DECODE[input[2]]; 42 | uint32_t decode3 = BASE64_DECODE[input[3]]; 43 | 44 | output[0] = decode0 << 2 | decode1 >> 4; 45 | output[1] = decode1 << 4 | decode2 >> 2; 46 | output[2] = decode2 << 6 | decode3; 47 | } 48 | 49 | 50 | uint32_t decode0 = BASE64_DECODE[input[0]]; 51 | uint32_t decode1 = BASE64_DECODE[input[1]]; 52 | 53 | output[0] = decode0 << 2 | decode1 >> 4; 54 | 55 | if (input[2] == '=') { 56 | 57 | output[1] = decode1 << 4; 58 | output[2] = 0; 59 | } 60 | else if (input[3] == '=') { 61 | uint32_t decode2 = BASE64_DECODE[input[2]]; 62 | 63 | output[1] = decode1 << 4 | decode2 >> 2; 64 | output[2] = decode2 << 6; 65 | output[3] = 0; 66 | } 67 | else { 68 | uint32_t decode2 = BASE64_DECODE[input[2]]; 69 | uint32_t decode3 = BASE64_DECODE[input[3]]; 70 | 71 | output[1] = decode1 << 4 | decode2 >> 2; 72 | output[2] = decode2 << 6 | decode3; 73 | output[3] = 0; 74 | } 75 | 76 | } 77 | 78 | -------------------------------------------------------------------------------- /base64/base64_encoder.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "base64.h" 3 | 4 | const unsigned char BASE64_PADDING='='; //When the input data is less than a multiple of 3, the '=' sign is filled after the output character. 5 | #if BASE64_ZUP 6 | const unsigned char BASE64_CODE[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-"; 7 | #else 8 | const unsigned char BASE64_CODE[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 9 | #endif 10 | 11 | //Encoding function (original data address, original data byte size, encoding output address) 12 | BEXTERN void BEXPORT base64_encode01(const void* pdata, const uint32_t data_size, void* out_pcode) 13 | { 14 | const uint8_t* input = (const uint8_t*)pdata; 15 | const uint8_t* input_end = &input[data_size]; 16 | uint8_t* output = (uint8_t*)out_pcode; 17 | 18 | for (; input + 2 < input_end; input += 3, output += 4) 19 | { 20 | output[0] = BASE64_CODE[input[0] >> 2]; 21 | output[1] = BASE64_CODE[((input[0] << 4) | (input[1] >> 4)) & 0x3F]; 22 | output[2] = BASE64_CODE[((input[1] << 2) | (input[2] >> 6)) & 0x3F]; 23 | output[3] = BASE64_CODE[input[2] & 0x3F]; 24 | } 25 | 26 | uint32_t bord_width = input_end - input; 27 | if (bord_width == 1) 28 | { 29 | output[0] = BASE64_CODE[input[0] >> 2]; 30 | output[1] = BASE64_CODE[(input[0] << 4) & 0x3F]; 31 | output[2] = BASE64_PADDING; 32 | output[3] = BASE64_PADDING; 33 | } 34 | else if (bord_width == 2) 35 | { 36 | output[0] = BASE64_CODE[input[0] >> 2]; 37 | output[1] = BASE64_CODE[((input[0] << 4) | (input[1] >> 4)) & 0x3F]; 38 | output[2] = BASE64_CODE[(input[1] << 2) & 0x3F]; 39 | output[3] = BASE64_PADDING; 40 | } 41 | output[4] = 0; 42 | } 43 | -------------------------------------------------------------------------------- /dlltester/dlltester.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/dlltester/dlltester.cpp -------------------------------------------------------------------------------- /dlltester/dlltester.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 6 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 7 | 8 | 9 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 10 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 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 | Header 20 | 21 | 22 | Header 23 | 24 | 25 | 26 | 27 | Source 28 | 29 | 30 | Source 31 | 32 | 33 | -------------------------------------------------------------------------------- /dlltester/pch.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/dlltester/pch.cpp -------------------------------------------------------------------------------- /dlltester/pch.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/dlltester/pch.h -------------------------------------------------------------------------------- /libdeflate/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.dll 3 | *.exe 4 | *.exp 5 | *.lib 6 | *.o 7 | *.obj 8 | *.so 9 | *.so.* 10 | /.lib-cflags 11 | /.prog-cflags 12 | /programs/config.h 13 | /benchmark 14 | /checksum 15 | /gzip 16 | /gunzip 17 | /run_tests.log 18 | /test_* 19 | tags 20 | cscope* 21 | -------------------------------------------------------------------------------- /libdeflate/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2016 Eric Biggers 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation files 5 | (the "Software"), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, 7 | publish, distribute, sublicense, and/or sell copies of the Software, 8 | and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 18 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /libdeflate/Makefile.msc: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the Microsoft toolchain 3 | # 4 | # Usage: 5 | # nmake /f Makefile.msc 6 | # 7 | 8 | .SUFFIXES: .c .obj .dllobj 9 | 10 | CC = cl 11 | LD = link 12 | AR = lib 13 | CFLAGS = /MD /O2 -I. -Icommon 14 | LDFLAGS = 15 | 16 | STATIC_LIB = libdeflatestatic.lib 17 | SHARED_LIB = libdeflate.dll 18 | IMPORT_LIB = libdeflate.lib 19 | 20 | STATIC_LIB_OBJ = \ 21 | lib/aligned_malloc.obj \ 22 | lib/adler32.obj \ 23 | lib/crc32.obj \ 24 | lib/deflate_compress.obj \ 25 | lib/deflate_decompress.obj \ 26 | lib/gzip_compress.obj \ 27 | lib/gzip_decompress.obj \ 28 | lib/x86/cpu_features.obj \ 29 | lib/zlib_compress.obj \ 30 | lib/zlib_decompress.obj 31 | 32 | SHARED_LIB_OBJ = $(STATIC_LIB_OBJ:.obj=.dllobj) 33 | 34 | PROG_COMMON_OBJ = programs/prog_util.obj \ 35 | programs/tgetopt.obj \ 36 | $(STATIC_LIB) 37 | 38 | PROG_CFLAGS = $(CFLAGS) -Iprograms 39 | 40 | all: $(STATIC_LIB) $(SHARED_LIB) $(IMPORT_LIB) gzip.exe gunzip.exe 41 | 42 | .c.obj: 43 | $(CC) -c /Fo$@ $(CFLAGS) $** 44 | 45 | .c.dllobj: 46 | $(CC) -c /Fo$@ $(CFLAGS) /DLIBDEFLATE_DLL $** 47 | 48 | $(STATIC_LIB): $(STATIC_LIB_OBJ) 49 | $(AR) $(ARFLAGS) -out:$@ $(STATIC_LIB_OBJ) 50 | 51 | $(SHARED_LIB): $(SHARED_LIB_OBJ) 52 | $(LD) $(LDFLAGS) -out:$@ -dll -implib:$(IMPORT_LIB) $(SHARED_LIB_OBJ) 53 | 54 | $(IMPORT_LIB): $(SHARED_LIB) 55 | 56 | gzip.exe:programs/gzip.obj $(PROG_COMMON_OBJ) 57 | $(LD) $(LDFLAGS) -out:$@ $** 58 | 59 | gunzip.exe:gzip.exe 60 | copy $** $@ 61 | 62 | clean: 63 | -del *.dll *.exe *.exp libdeflate.lib libdeflatestatic.lib gzip.lib \ 64 | lib\*.obj lib\*\*.obj lib\*.dllobj lib\*\*.dllobj \ 65 | programs\*.obj 2>nul 66 | -------------------------------------------------------------------------------- /libdeflate/common/compiler_msc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * compiler_msc.h - definitions for the Microsoft C Compiler 3 | */ 4 | 5 | #define LIBEXPORT __declspec(dllexport) 6 | 7 | /* 8 | * Old versions (e.g. VS2010) of MSC don't have the C99 header stdbool.h. 9 | * Beware: the below replacement isn't fully standard, since normally any value 10 | * != 0 should be implicitly cast to a bool with value 1... but that doesn't 11 | * happen if bool is really just an 'int'. 12 | */ 13 | typedef int bool; 14 | #define true 1 15 | #define false 0 16 | #define __bool_true_false_are_defined 1 17 | 18 | /* Define ssize_t */ 19 | #ifdef _WIN64 20 | typedef long long ssize_t; 21 | #else 22 | typedef int ssize_t; 23 | #endif 24 | 25 | /* 26 | * Old versions (e.g. VS2010) of MSC have stdint.h but not the C99 header 27 | * inttypes.h. Work around this by defining the PRI* macros ourselves. 28 | */ 29 | #include 30 | 31 | //add by stsm 32 | #include "msvc_conf.h" 33 | //#include "fix_clang_emmintrin.h" 34 | 35 | #define PRIu8 "hhu" 36 | #define PRIu16 "hu" 37 | #define PRIu32 "u" 38 | #define PRIu64 "llu" 39 | #define PRIi8 "hhi" 40 | #define PRIi16 "hi" 41 | #define PRIi32 "i" 42 | #define PRIi64 "lli" 43 | #define PRIx8 "hhx" 44 | #define PRIx16 "hx" 45 | #define PRIx32 "x" 46 | #define PRIx64 "llx" 47 | 48 | /* Assume a little endian architecture with fast unaligned access */ 49 | #define CPU_IS_LITTLE_ENDIAN() 1 50 | #define UNALIGNED_ACCESS_IS_FAST 1 51 | 52 | /* __restrict has nonstandard behavior; don't use it */ 53 | #define restrict 54 | 55 | /* ... but we can use __inline and __forceinline */ 56 | #define inline __inline 57 | #define forceinline __forceinline 58 | 59 | /* Byte swap functions */ 60 | #include 61 | #define bswap16 _byteswap_ushort 62 | #define bswap32 _byteswap_ulong 63 | #define bswap64 _byteswap_uint64 64 | 65 | /* Bit scan functions (32-bit) */ 66 | 67 | static forceinline unsigned 68 | bsr32(uint32_t n) 69 | { 70 | _BitScanReverse(&n, n); 71 | return n; 72 | } 73 | #define bsr32 bsr32 74 | 75 | static forceinline unsigned 76 | bsf32(uint32_t n) 77 | { 78 | _BitScanForward(&n, n); 79 | return n; 80 | } 81 | #define bsf32 bsf32 82 | 83 | #ifdef _M_X64 /* Bit scan functions (64-bit) */ 84 | 85 | static forceinline unsigned 86 | bsr64(uint64_t n) 87 | { 88 | _BitScanReverse64(&n, n); 89 | return n; 90 | } 91 | #define bsr64 bsr64 92 | 93 | static forceinline unsigned 94 | bsf64(uint64_t n) 95 | { 96 | _BitScanForward64(&n, n); 97 | return n; 98 | } 99 | #define bsf64 bsf64 100 | 101 | #endif /* _M_X64 */ 102 | -------------------------------------------------------------------------------- /libdeflate/common/msvc_conf.h: -------------------------------------------------------------------------------- 1 | #include 2 | #define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 3 | #define __SSE2__ 1 4 | 5 | #ifdef _M_IX86 6 | #define __i386__ 7 | #elif defined _M_X64 8 | #define __x86_64__ 9 | #endif 10 | 11 | //#define COMPILER_SUPPORTS_AVX_TARGET 1 12 | //#define COMPILER_SUPPORTS_AVX2_TARGET 1 13 | //#define COMPILER_SUPPORTS_TARGET_INTRINSICS 1 14 | -------------------------------------------------------------------------------- /libdeflate/lib/aligned_malloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * aligned_malloc.c - aligned memory allocation 3 | * 4 | * Originally public domain; changes after 2016-09-07 are copyrighted. 5 | * 6 | * Copyright 2016 Eric Biggers 7 | * 8 | * Permission is hereby granted, free of charge, to any person 9 | * obtaining a copy of this software and associated documentation 10 | * files (the "Software"), to deal in the Software without 11 | * restriction, including without limitation the rights to use, 12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the 14 | * Software is furnished to do so, subject to the following 15 | * conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | /* 31 | * This file provides portable aligned memory allocation functions that only 32 | * use malloc() and free(). This avoids portability problems with 33 | * posix_memalign(), aligned_alloc(), etc. 34 | */ 35 | 36 | #include 37 | 38 | #include "aligned_malloc.h" 39 | 40 | void * 41 | aligned_malloc(size_t alignment, size_t size) 42 | { 43 | #if defined(_MSC_VER) || defined(__ICC) 44 | return _aligned_malloc(size, alignment); 45 | #else 46 | void *ptr = malloc(sizeof(void *) + alignment - 1 + size); 47 | if (ptr) { 48 | void *orig_ptr = ptr; 49 | ptr = (void *)ALIGN((uintptr_t)ptr + sizeof(void *), alignment); 50 | ((void **)ptr)[-1] = orig_ptr; 51 | } 52 | return ptr; 53 | #endif 54 | } 55 | 56 | void 57 | aligned_free(void *ptr) 58 | { 59 | if (ptr) 60 | #if defined(_MSC_VER) || defined(__ICC) 61 | _aligned_free(ptr); 62 | #else 63 | free(((void **)ptr)[-1]); 64 | #endif 65 | } 66 | -------------------------------------------------------------------------------- /libdeflate/lib/aligned_malloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * aligned_malloc.c - aligned memory allocation 3 | */ 4 | 5 | #ifndef LIB_ALIGNED_MALLOC_H 6 | #define LIB_ALIGNED_MALLOC_H 7 | 8 | #include "lib_common.h" 9 | 10 | extern void *aligned_malloc(size_t alignment, size_t size); 11 | extern void aligned_free(void *ptr); 12 | 13 | #endif /* LIB_ALIGNED_MALLOC_H */ 14 | -------------------------------------------------------------------------------- /libdeflate/lib/arm/cpu_features.h: -------------------------------------------------------------------------------- 1 | /* 2 | * arm/cpu_features.h - feature detection for ARM processors 3 | */ 4 | 5 | #ifndef LIB_ARM_CPU_FEATURES_H 6 | #define LIB_ARM_CPU_FEATURES_H 7 | 8 | #include "../lib_common.h" 9 | 10 | #if (defined(__arm__) || defined(__aarch64__)) && \ 11 | defined(__linux__) && COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 12 | # define ARM_CPU_FEATURES_ENABLED 1 13 | #else 14 | # define ARM_CPU_FEATURES_ENABLED 0 15 | #endif 16 | 17 | #if ARM_CPU_FEATURES_ENABLED 18 | 19 | #define ARM_CPU_FEATURE_NEON 0x00000001 20 | #define ARM_CPU_FEATURE_PMULL 0x00000002 21 | 22 | #define ARM_CPU_FEATURES_KNOWN 0x80000000 23 | 24 | extern volatile u32 _cpu_features; 25 | 26 | extern void setup_cpu_features(void); 27 | 28 | static inline u32 get_cpu_features(void) 29 | { 30 | if (_cpu_features == 0) 31 | setup_cpu_features(); 32 | return _cpu_features; 33 | } 34 | 35 | #endif /* ARM_CPU_FEATURES_ENABLED */ 36 | 37 | #endif /* LIB_ARM_CPU_FEATURES_H */ 38 | -------------------------------------------------------------------------------- /libdeflate/lib/arm/matchfinder_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * arm/matchfinder_impl.h - ARM implementations of matchfinder functions 3 | * 4 | * Copyright 2016 Eric Biggers 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following 13 | * conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | * OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #ifdef __ARM_NEON 29 | # if MATCHFINDER_ALIGNMENT < 16 30 | # undef MATCHFINDER_ALIGNMENT 31 | # define MATCHFINDER_ALIGNMENT 16 32 | # endif 33 | # include 34 | static forceinline bool 35 | matchfinder_init_neon(mf_pos_t *data, size_t size) 36 | { 37 | int16x8_t v, *p; 38 | size_t n; 39 | 40 | if (size % (sizeof(int16x8_t) * 4) != 0) 41 | return false; 42 | 43 | STATIC_ASSERT(sizeof(mf_pos_t) == 2); 44 | v = (int16x8_t) { 45 | MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, 46 | MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, 47 | MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, 48 | }; 49 | p = (int16x8_t *)data; 50 | n = size / (sizeof(int16x8_t) * 4); 51 | do { 52 | p[0] = v; 53 | p[1] = v; 54 | p[2] = v; 55 | p[3] = v; 56 | p += 4; 57 | } while (--n); 58 | return true; 59 | } 60 | #undef arch_matchfinder_init 61 | #define arch_matchfinder_init matchfinder_init_neon 62 | 63 | static forceinline bool 64 | matchfinder_rebase_neon(mf_pos_t *data, size_t size) 65 | { 66 | int16x8_t v, *p; 67 | size_t n; 68 | 69 | if (size % (sizeof(int16x8_t) * 4) != 0) 70 | return false; 71 | 72 | STATIC_ASSERT(sizeof(mf_pos_t) == 2); 73 | v = (int16x8_t) { 74 | (u16)-MATCHFINDER_WINDOW_SIZE, (u16)-MATCHFINDER_WINDOW_SIZE, 75 | (u16)-MATCHFINDER_WINDOW_SIZE, (u16)-MATCHFINDER_WINDOW_SIZE, 76 | (u16)-MATCHFINDER_WINDOW_SIZE, (u16)-MATCHFINDER_WINDOW_SIZE, 77 | (u16)-MATCHFINDER_WINDOW_SIZE, (u16)-MATCHFINDER_WINDOW_SIZE, 78 | }; 79 | p = (int16x8_t *)data; 80 | n = size / (sizeof(int16x8_t) * 4); 81 | do { 82 | p[0] = vqaddq_s16(p[0], v); 83 | p[1] = vqaddq_s16(p[1], v); 84 | p[2] = vqaddq_s16(p[2], v); 85 | p[3] = vqaddq_s16(p[3], v); 86 | p += 4; 87 | } while (--n); 88 | return true; 89 | } 90 | #undef arch_matchfinder_rebase 91 | #define arch_matchfinder_rebase matchfinder_rebase_neon 92 | 93 | #endif /* __ARM_NEON */ 94 | -------------------------------------------------------------------------------- /libdeflate/lib/crc32_vec_template.h: -------------------------------------------------------------------------------- 1 | /* 2 | * crc32_vec_template.h - template for vectorized CRC-32 implementations 3 | * 4 | * Copyright 2016 Eric Biggers 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following 13 | * conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | * OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #define CRC32_SLICE1 1 29 | static u32 crc32_slice1(u32, const u8 *, size_t); 30 | 31 | /* 32 | * Template for vectorized CRC-32 implementations. 33 | * 34 | * Note: on unaligned ends of the buffer, we fall back to crc32_slice1() instead 35 | * of crc32_slice8() because only a few bytes need to be processed, so a smaller 36 | * table is preferable. 37 | */ 38 | static u32 ATTRIBUTES 39 | FUNCNAME(u32 remainder, const u8 *p, size_t size) 40 | { 41 | if ((uintptr_t)p % IMPL_ALIGNMENT) { 42 | size_t n = MIN(size, -(uintptr_t)p % IMPL_ALIGNMENT); 43 | 44 | remainder = crc32_slice1(remainder, p, n); 45 | p += n; 46 | size -= n; 47 | } 48 | if (size >= IMPL_SEGMENT_SIZE) { 49 | remainder = FUNCNAME_ALIGNED(remainder, (const void *)p, 50 | size / IMPL_SEGMENT_SIZE); 51 | p += size - (size % IMPL_SEGMENT_SIZE); 52 | size %= IMPL_SEGMENT_SIZE; 53 | } 54 | return crc32_slice1(remainder, p, size); 55 | } 56 | 57 | #undef FUNCNAME 58 | #undef FUNCNAME_ALIGNED 59 | #undef ATTRIBUTES 60 | #undef IMPL_ALIGNMENT 61 | #undef IMPL_SEGMENT_SIZE 62 | -------------------------------------------------------------------------------- /libdeflate/lib/deflate_compress.h: -------------------------------------------------------------------------------- 1 | #ifndef LIB_DEFLATE_COMPRESS_H 2 | #define LIB_DEFLATE_COMPRESS_H 3 | 4 | #include "lib_common.h" 5 | 6 | /* DEFLATE compression is private to deflate_compress.c, but we do need to be 7 | * able to query the compression level for zlib and gzip header generation. */ 8 | 9 | struct libdeflate_compressor; 10 | 11 | extern unsigned int 12 | deflate_get_compression_level(struct libdeflate_compressor *c); 13 | 14 | #endif /* LIB_DEFLATE_COMPRESS_H */ 15 | -------------------------------------------------------------------------------- /libdeflate/lib/deflate_constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * deflate_constants.h - constants for the DEFLATE compression format 3 | */ 4 | 5 | #ifndef LIB_DEFLATE_CONSTANTS_H 6 | #define LIB_DEFLATE_CONSTANTS_H 7 | 8 | /* Valid block types */ 9 | #define DEFLATE_BLOCKTYPE_UNCOMPRESSED 0 10 | #define DEFLATE_BLOCKTYPE_STATIC_HUFFMAN 1 11 | #define DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN 2 12 | 13 | /* Minimum and maximum supported match lengths (in bytes) */ 14 | #define DEFLATE_MIN_MATCH_LEN 3 15 | #define DEFLATE_MAX_MATCH_LEN 258 16 | 17 | /* Minimum and maximum supported match offsets (in bytes) */ 18 | #define DEFLATE_MIN_MATCH_OFFSET 1 19 | #define DEFLATE_MAX_MATCH_OFFSET 32768 20 | 21 | #define DEFLATE_MAX_WINDOW_SIZE 32768 22 | 23 | /* Number of symbols in each Huffman code. Note: for the literal/length 24 | * and offset codes, these are actually the maximum values; a given block 25 | * might use fewer symbols. */ 26 | #define DEFLATE_NUM_PRECODE_SYMS 19 27 | #define DEFLATE_NUM_LITLEN_SYMS 288 28 | #define DEFLATE_NUM_OFFSET_SYMS 32 29 | 30 | /* The maximum number of symbols across all codes */ 31 | #define DEFLATE_MAX_NUM_SYMS 288 32 | 33 | /* Division of symbols in the literal/length code */ 34 | #define DEFLATE_NUM_LITERALS 256 35 | #define DEFLATE_END_OF_BLOCK 256 36 | #define DEFLATE_NUM_LEN_SYMS 31 37 | 38 | /* Maximum codeword length, in bits, within each Huffman code */ 39 | #define DEFLATE_MAX_PRE_CODEWORD_LEN 7 40 | #define DEFLATE_MAX_LITLEN_CODEWORD_LEN 15 41 | #define DEFLATE_MAX_OFFSET_CODEWORD_LEN 15 42 | 43 | /* The maximum codeword length across all codes */ 44 | #define DEFLATE_MAX_CODEWORD_LEN 15 45 | 46 | /* Maximum possible overrun when decoding codeword lengths */ 47 | #define DEFLATE_MAX_LENS_OVERRUN 137 48 | 49 | /* 50 | * Maximum number of extra bits that may be required to represent a match 51 | * length or offset. 52 | * 53 | * TODO: are we going to have full DEFLATE64 support? If so, up to 16 54 | * length bits must be supported. 55 | */ 56 | #define DEFLATE_MAX_EXTRA_LENGTH_BITS 5 57 | #define DEFLATE_MAX_EXTRA_OFFSET_BITS 14 58 | 59 | /* The maximum number of bits in which a match can be represented. This 60 | * is the absolute worst case, which assumes the longest possible Huffman 61 | * codewords and the maximum numbers of extra bits. */ 62 | #define DEFLATE_MAX_MATCH_BITS \ 63 | (DEFLATE_MAX_LITLEN_CODEWORD_LEN + DEFLATE_MAX_EXTRA_LENGTH_BITS + \ 64 | DEFLATE_MAX_OFFSET_CODEWORD_LEN + DEFLATE_MAX_EXTRA_OFFSET_BITS) 65 | 66 | #endif /* LIB_DEFLATE_CONSTANTS_H */ 67 | -------------------------------------------------------------------------------- /libdeflate/lib/gzip_compress.c: -------------------------------------------------------------------------------- 1 | /* 2 | * gzip_compress.c - compress with a gzip wrapper 3 | * 4 | * Originally public domain; changes after 2016-09-07 are copyrighted. 5 | * 6 | * Copyright 2016 Eric Biggers 7 | * 8 | * Permission is hereby granted, free of charge, to any person 9 | * obtaining a copy of this software and associated documentation 10 | * files (the "Software"), to deal in the Software without 11 | * restriction, including without limitation the rights to use, 12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the 14 | * Software is furnished to do so, subject to the following 15 | * conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #include "deflate_compress.h" 31 | #include "gzip_constants.h" 32 | #include "unaligned.h" 33 | 34 | #include "libdeflate.h" 35 | 36 | LIBDEFLATEAPI size_t 37 | libdeflate_gzip_compress(struct libdeflate_compressor *c, 38 | const void *in, size_t in_size, 39 | void *out, size_t out_nbytes_avail) 40 | { 41 | u8 *out_next = out; 42 | unsigned compression_level; 43 | u8 xfl; 44 | size_t deflate_size; 45 | 46 | if (out_nbytes_avail <= GZIP_MIN_OVERHEAD) 47 | return 0; 48 | 49 | /* ID1 */ 50 | *out_next++ = GZIP_ID1; 51 | /* ID2 */ 52 | *out_next++ = GZIP_ID2; 53 | /* CM */ 54 | *out_next++ = GZIP_CM_DEFLATE; 55 | /* FLG */ 56 | *out_next++ = 0; 57 | /* MTIME */ 58 | put_unaligned_le32(GZIP_MTIME_UNAVAILABLE, out_next); 59 | out_next += 4; 60 | /* XFL */ 61 | xfl = 0; 62 | compression_level = deflate_get_compression_level(c); 63 | if (compression_level < 2) 64 | xfl |= GZIP_XFL_FASTEST_COMRESSION; 65 | else if (compression_level >= 8) 66 | xfl |= GZIP_XFL_SLOWEST_COMRESSION; 67 | *out_next++ = xfl; 68 | /* OS */ 69 | *out_next++ = GZIP_OS_UNKNOWN; /* OS */ 70 | 71 | /* Compressed data */ 72 | deflate_size = libdeflate_deflate_compress(c, in, in_size, out_next, 73 | out_nbytes_avail - GZIP_MIN_OVERHEAD); 74 | if (deflate_size == 0) 75 | return 0; 76 | out_next += deflate_size; 77 | 78 | /* CRC32 */ 79 | put_unaligned_le32(libdeflate_crc32(0, in, in_size), out_next); 80 | out_next += 4; 81 | 82 | /* ISIZE */ 83 | put_unaligned_le32((u32)in_size, out_next); 84 | out_next += 4; 85 | 86 | return out_next - (u8 *)out; 87 | } 88 | 89 | LIBDEFLATEAPI size_t 90 | libdeflate_gzip_compress_bound(struct libdeflate_compressor *c, 91 | size_t in_nbytes) 92 | { 93 | return GZIP_MIN_OVERHEAD + 94 | libdeflate_deflate_compress_bound(c, in_nbytes); 95 | } 96 | -------------------------------------------------------------------------------- /libdeflate/lib/gzip_constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gzip_constants.h - constants for the gzip wrapper format 3 | */ 4 | 5 | #ifndef LIB_GZIP_CONSTANTS_H 6 | #define LIB_GZIP_CONSTANTS_H 7 | 8 | #define GZIP_MIN_HEADER_SIZE 10 9 | #define GZIP_FOOTER_SIZE 8 10 | #define GZIP_MIN_OVERHEAD (GZIP_MIN_HEADER_SIZE + GZIP_FOOTER_SIZE) 11 | 12 | #define GZIP_ID1 0x1F 13 | #define GZIP_ID2 0x8B 14 | 15 | #define GZIP_CM_DEFLATE 8 16 | 17 | #define GZIP_FTEXT 0x01 18 | #define GZIP_FHCRC 0x02 19 | #define GZIP_FEXTRA 0x04 20 | #define GZIP_FNAME 0x08 21 | #define GZIP_FCOMMENT 0x10 22 | #define GZIP_FRESERVED 0xE0 23 | 24 | #define GZIP_MTIME_UNAVAILABLE 0 25 | 26 | #define GZIP_XFL_SLOWEST_COMRESSION 0x02 27 | #define GZIP_XFL_FASTEST_COMRESSION 0x04 28 | 29 | #define GZIP_OS_FAT 0 30 | #define GZIP_OS_AMIGA 1 31 | #define GZIP_OS_VMS 2 32 | #define GZIP_OS_UNIX 3 33 | #define GZIP_OS_VM_CMS 4 34 | #define GZIP_OS_ATARI_TOS 5 35 | #define GZIP_OS_HPFS 6 36 | #define GZIP_OS_MACINTOSH 7 37 | #define GZIP_OS_Z_SYSTEM 8 38 | #define GZIP_OS_CP_M 9 39 | #define GZIP_OS_TOPS_20 10 40 | #define GZIP_OS_NTFS 11 41 | #define GZIP_OS_QDOS 12 42 | #define GZIP_OS_RISCOS 13 43 | #define GZIP_OS_UNKNOWN 255 44 | 45 | #endif /* LIB_GZIP_CONSTANTS_H */ 46 | -------------------------------------------------------------------------------- /libdeflate/lib/lib_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lib_common.h - internal header included by all library code 3 | */ 4 | 5 | #ifndef LIB_LIB_COMMON_H 6 | #define LIB_LIB_COMMON_H 7 | 8 | #ifdef LIBDEFLATE_H 9 | # error "lib_common.h must always be included before libdeflate.h" 10 | /* because BUILDING_LIBDEFLATE must be set first */ 11 | #endif 12 | 13 | #define BUILDING_LIBDEFLATE 14 | 15 | #include "common_defs.h" 16 | 17 | /* 18 | * Prefix with "_libdeflate_" all global symbols which are not part of the API. 19 | * This avoids exposing overly generic names when libdeflate is built as a 20 | * static library. 21 | * 22 | * Note that the chosen prefix is not really important and can be changed 23 | * without breaking library users. It was just chosen so that the resulting 24 | * symbol names are unlikely to conflict with those from any other software. 25 | * Also note that this fixup has no useful effect when libdeflate is built as a 26 | * shared library, since these symbols are not exported. 27 | */ 28 | #define SYM_FIXUP(sym) _libdeflate_##sym 29 | #define aligned_malloc SYM_FIXUP(aligned_malloc) 30 | #define aligned_free SYM_FIXUP(aligned_free) 31 | #define deflate_get_compression_level SYM_FIXUP(deflate_get_compression_level) 32 | #define _cpu_features SYM_FIXUP(_cpu_features) 33 | #define setup_cpu_features SYM_FIXUP(setup_cpu_features) 34 | 35 | #endif /* LIB_LIB_COMMON_H */ 36 | -------------------------------------------------------------------------------- /libdeflate/lib/x86/adler32_impl_msvc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/libdeflate/lib/x86/adler32_impl_msvc.h -------------------------------------------------------------------------------- /libdeflate/lib/x86/cpu_features.h: -------------------------------------------------------------------------------- 1 | /* 2 | * x86/cpu_features.h - feature detection for x86 processors 3 | */ 4 | 5 | #ifndef LIB_X86_CPU_FEATURES_H 6 | #define LIB_X86_CPU_FEATURES_H 7 | 8 | #include "../lib_common.h" 9 | 10 | #if (defined(__i386__) || defined(__x86_64__)) && \ 11 | COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 12 | # define X86_CPU_FEATURES_ENABLED 1 13 | #else 14 | # define X86_CPU_FEATURES_ENABLED 0 15 | #endif 16 | 17 | //#ifdef __GNUC__ 18 | // #if (defined(__i386__) || defined(__x86_64__)) && \ 19 | // COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 20 | // # define X86_CPU_FEATURES_ENABLED 1 21 | // #else 22 | // # define X86_CPU_FEATURES_ENABLED 0 23 | // #endif 24 | //#elif defined(_MSC_VER) 25 | // 26 | // #if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 27 | // # define X86_CPU_FEATURES_ENABLED 1 28 | // #else 29 | // # define X86_CPU_FEATURES_ENABLED 0 30 | // #endif 31 | //#endif 32 | 33 | #if X86_CPU_FEATURES_ENABLED 34 | 35 | #define X86_CPU_FEATURE_SSE2 0x00000001 36 | #define X86_CPU_FEATURE_PCLMULQDQ 0x00000002 37 | #define X86_CPU_FEATURE_AVX 0x00000004 38 | #define X86_CPU_FEATURE_AVX2 0x00000008 39 | #define X86_CPU_FEATURE_BMI2 0x00000010 40 | #define X86_CPU_FEATURE_AVX512BW 0x00000020 41 | 42 | #define X86_CPU_FEATURES_KNOWN 0x80000000 43 | 44 | extern volatile u32 _cpu_features; 45 | 46 | extern void setup_cpu_features(void); 47 | 48 | static inline u32 get_cpu_features(void) 49 | { 50 | if (_cpu_features == 0) 51 | setup_cpu_features(); 52 | return _cpu_features; 53 | } 54 | 55 | #endif /* X86_CPU_FEATURES_ENABLED */ 56 | 57 | #endif /* LIB_X86_CPU_FEATURES_H */ 58 | -------------------------------------------------------------------------------- /libdeflate/lib/x86/decompress_impl.h: -------------------------------------------------------------------------------- 1 | #include "cpu_features.h" 2 | 3 | /* Include the BMI2-optimized version? */ 4 | #undef DISPATCH_BMI2 5 | #if !defined(__BMI2__) && X86_CPU_FEATURES_ENABLED && \ 6 | COMPILER_SUPPORTS_BMI2_TARGET 7 | # define FUNCNAME deflate_decompress_bmi2 8 | # define ATTRIBUTES __attribute__((target("bmi2"))) 9 | # define DISPATCH 1 10 | # define DISPATCH_BMI2 1 11 | # include "../decompress_template.h" 12 | #endif 13 | 14 | #ifdef DISPATCH 15 | static inline decompress_func_t 16 | arch_select_decompress_func(void) 17 | { 18 | u32 features = get_cpu_features(); 19 | 20 | #ifdef DISPATCH_BMI2 21 | if (features & X86_CPU_FEATURE_BMI2) 22 | return deflate_decompress_bmi2; 23 | #endif 24 | return NULL; 25 | } 26 | #endif /* DISPATCH */ 27 | -------------------------------------------------------------------------------- /libdeflate/lib/zlib_compress.c: -------------------------------------------------------------------------------- 1 | /* 2 | * zlib_compress.c - compress with a zlib wrapper 3 | * 4 | * Originally public domain; changes after 2016-09-07 are copyrighted. 5 | * 6 | * Copyright 2016 Eric Biggers 7 | * 8 | * Permission is hereby granted, free of charge, to any person 9 | * obtaining a copy of this software and associated documentation 10 | * files (the "Software"), to deal in the Software without 11 | * restriction, including without limitation the rights to use, 12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the 14 | * Software is furnished to do so, subject to the following 15 | * conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #include "deflate_compress.h" 31 | #include "unaligned.h" 32 | #include "zlib_constants.h" 33 | 34 | #include "libdeflate.h" 35 | 36 | LIBDEFLATEAPI size_t 37 | libdeflate_zlib_compress(struct libdeflate_compressor *c, 38 | const void *in, size_t in_size, 39 | void *out, size_t out_nbytes_avail) 40 | { 41 | u8 *out_next = out; 42 | u16 hdr; 43 | unsigned compression_level; 44 | unsigned level_hint; 45 | size_t deflate_size; 46 | 47 | if (out_nbytes_avail <= ZLIB_MIN_OVERHEAD) 48 | return 0; 49 | 50 | /* 2 byte header: CMF and FLG */ 51 | hdr = (ZLIB_CM_DEFLATE << 8) | (ZLIB_CINFO_32K_WINDOW << 12); 52 | compression_level = deflate_get_compression_level(c); 53 | if (compression_level < 2) 54 | level_hint = ZLIB_FASTEST_COMPRESSION; 55 | else if (compression_level < 6) 56 | level_hint = ZLIB_FAST_COMPRESSION; 57 | else if (compression_level < 8) 58 | level_hint = ZLIB_DEFAULT_COMPRESSION; 59 | else 60 | level_hint = ZLIB_SLOWEST_COMPRESSION; 61 | hdr |= level_hint << 6; 62 | hdr |= 31 - (hdr % 31); 63 | 64 | put_unaligned_be16(hdr, out_next); 65 | out_next += 2; 66 | 67 | /* Compressed data */ 68 | deflate_size = libdeflate_deflate_compress(c, in, in_size, out_next, 69 | out_nbytes_avail - ZLIB_MIN_OVERHEAD); 70 | if (deflate_size == 0) 71 | return 0; 72 | out_next += deflate_size; 73 | 74 | /* ADLER32 */ 75 | put_unaligned_be32(libdeflate_adler32(1, in, in_size), out_next); 76 | out_next += 4; 77 | 78 | return out_next - (u8 *)out; 79 | } 80 | 81 | LIBDEFLATEAPI size_t 82 | libdeflate_zlib_compress_bound(struct libdeflate_compressor *c, 83 | size_t in_nbytes) 84 | { 85 | return ZLIB_MIN_OVERHEAD + 86 | libdeflate_deflate_compress_bound(c, in_nbytes); 87 | } 88 | -------------------------------------------------------------------------------- /libdeflate/lib/zlib_constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * zlib_constants.h - constants for the zlib wrapper format 3 | */ 4 | 5 | #ifndef LIB_ZLIB_CONSTANTS_H 6 | #define LIB_ZLIB_CONSTANTS_H 7 | 8 | #define ZLIB_MIN_HEADER_SIZE 2 9 | #define ZLIB_FOOTER_SIZE 4 10 | #define ZLIB_MIN_OVERHEAD (ZLIB_MIN_HEADER_SIZE + ZLIB_FOOTER_SIZE) 11 | 12 | #define ZLIB_CM_DEFLATE 8 13 | 14 | #define ZLIB_CINFO_32K_WINDOW 7 15 | 16 | #define ZLIB_FASTEST_COMPRESSION 0 17 | #define ZLIB_FAST_COMPRESSION 1 18 | #define ZLIB_DEFAULT_COMPRESSION 2 19 | #define ZLIB_SLOWEST_COMPRESSION 3 20 | 21 | #endif /* LIB_ZLIB_CONSTANTS_H */ 22 | -------------------------------------------------------------------------------- /libdeflate/lib/zlib_decompress.c: -------------------------------------------------------------------------------- 1 | /* 2 | * zlib_decompress.c - decompress with a zlib wrapper 3 | * 4 | * Originally public domain; changes after 2016-09-07 are copyrighted. 5 | * 6 | * Copyright 2016 Eric Biggers 7 | * 8 | * Permission is hereby granted, free of charge, to any person 9 | * obtaining a copy of this software and associated documentation 10 | * files (the "Software"), to deal in the Software without 11 | * restriction, including without limitation the rights to use, 12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the 14 | * Software is furnished to do so, subject to the following 15 | * conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #include "unaligned.h" 31 | #include "zlib_constants.h" 32 | 33 | #include "libdeflate.h" 34 | 35 | LIBDEFLATEAPI enum libdeflate_result 36 | libdeflate_zlib_decompress(struct libdeflate_decompressor *d, 37 | const void *in, size_t in_nbytes, 38 | void *out, size_t out_nbytes_avail, 39 | size_t *actual_out_nbytes_ret) 40 | { 41 | const u8 *in_next = in; 42 | const u8 * const in_end = in_next + in_nbytes; 43 | u16 hdr; 44 | size_t actual_out_nbytes; 45 | enum libdeflate_result result; 46 | 47 | if (in_nbytes < ZLIB_MIN_OVERHEAD) 48 | return LIBDEFLATE_BAD_DATA; 49 | 50 | /* 2 byte header: CMF and FLG */ 51 | hdr = get_unaligned_be16(in_next); 52 | in_next += 2; 53 | 54 | /* FCHECK */ 55 | if ((hdr % 31) != 0) 56 | return LIBDEFLATE_BAD_DATA; 57 | 58 | /* CM */ 59 | if (((hdr >> 8) & 0xF) != ZLIB_CM_DEFLATE) 60 | return LIBDEFLATE_BAD_DATA; 61 | 62 | /* CINFO */ 63 | if ((hdr >> 12) > ZLIB_CINFO_32K_WINDOW) 64 | return LIBDEFLATE_BAD_DATA; 65 | 66 | /* FDICT */ 67 | if ((hdr >> 5) & 1) 68 | return LIBDEFLATE_BAD_DATA; 69 | 70 | /* Compressed data */ 71 | result = libdeflate_deflate_decompress(d, in_next, 72 | in_end - ZLIB_FOOTER_SIZE - in_next, 73 | out, out_nbytes_avail, 74 | actual_out_nbytes_ret); 75 | if (result != LIBDEFLATE_SUCCESS) 76 | return result; 77 | 78 | if (actual_out_nbytes_ret) 79 | actual_out_nbytes = *actual_out_nbytes_ret; 80 | else 81 | actual_out_nbytes = out_nbytes_avail; 82 | 83 | in_next = in_end - ZLIB_FOOTER_SIZE; 84 | 85 | /* ADLER32 */ 86 | if (libdeflate_adler32(1, out, actual_out_nbytes) != 87 | get_unaligned_be32(in_next)) 88 | return LIBDEFLATE_BAD_DATA; 89 | 90 | return LIBDEFLATE_SUCCESS; 91 | } 92 | -------------------------------------------------------------------------------- /libdeflate/libdeflate_2022.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.757 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdeflate", "libdeflate_2022.vcxproj", "{2A3F22C4-D534-497B-82FC-F92A634FB20F}" 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 | {2A3F22C4-D534-497B-82FC-F92A634FB20F}.Debug|x64.ActiveCfg = Debug|x64 17 | {2A3F22C4-D534-497B-82FC-F92A634FB20F}.Debug|x64.Build.0 = Debug|x64 18 | {2A3F22C4-D534-497B-82FC-F92A634FB20F}.Debug|x86.ActiveCfg = Debug|Win32 19 | {2A3F22C4-D534-497B-82FC-F92A634FB20F}.Debug|x86.Build.0 = Debug|Win32 20 | {2A3F22C4-D534-497B-82FC-F92A634FB20F}.Release|x64.ActiveCfg = Release|x64 21 | {2A3F22C4-D534-497B-82FC-F92A634FB20F}.Release|x64.Build.0 = Release|x64 22 | {2A3F22C4-D534-497B-82FC-F92A634FB20F}.Release|x86.ActiveCfg = Release|Win32 23 | {2A3F22C4-D534-497B-82FC-F92A634FB20F}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {E8D67C60-5110-4391-B1C6-6E508D3DB8F1} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /libdeflate/programs/detect.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$CC" ]; then 4 | CC=cc 5 | fi 6 | 7 | echo "/* THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT. */" 8 | echo "#ifndef CONFIG_H" 9 | echo "#define CONFIG_H" 10 | 11 | tmpfile="$(mktemp -t libdeflate_config.XXXXXXXX)" 12 | trap "rm -f \"$tmpfile\"" EXIT 13 | 14 | program_compiles() { 15 | echo "$1" > "$tmpfile" 16 | $CC $CFLAGS -x c "$tmpfile" -o /dev/null > /dev/null 2>&1 17 | } 18 | 19 | check_function() { 20 | funcname="$1" 21 | macro="HAVE_$(echo $funcname | tr a-z A-Z)" 22 | echo 23 | echo "/* Is the $funcname() function available? */" 24 | if program_compiles "int main() { $funcname(); }"; then 25 | echo "#define $macro 1" 26 | else 27 | echo "/* $macro is not set */" 28 | fi 29 | } 30 | 31 | have_stat_field() { 32 | program_compiles "#include 33 | #include 34 | int main() { struct stat st; st.$1; }" 35 | } 36 | 37 | check_stat_nanosecond_precision() { 38 | echo 39 | echo "/* Does stat() provide nanosecond-precision timestamps? */" 40 | if have_stat_field st_atim; then 41 | echo "#define HAVE_STAT_NANOSECOND_PRECISION 1" 42 | elif have_stat_field st_atimespec; then 43 | # Nonstandard field names used by OS X and older BSDs 44 | echo "#define HAVE_STAT_NANOSECOND_PRECISION 1" 45 | echo "#define st_atim st_atimespec" 46 | echo "#define st_mtim st_mtimespec" 47 | echo "#define st_ctim st_ctimespec" 48 | else 49 | echo "/* HAVE_STAT_NANOSECOND_PRECISION is not set */" 50 | fi 51 | } 52 | 53 | check_function clock_gettime 54 | check_function futimens 55 | check_function futimes 56 | check_function posix_fadvise 57 | check_function posix_madvise 58 | 59 | check_stat_nanosecond_precision 60 | 61 | echo 62 | echo "#endif /* CONFIG_H */" 63 | -------------------------------------------------------------------------------- /libdeflate/programs/test_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * test_util.h - utility functions for test programs 3 | * 4 | * Copyright 2016 Eric Biggers 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following 13 | * conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | * OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #ifndef PROGRAMS_TEST_UTIL_H 29 | #define PROGRAMS_TEST_UTIL_H 30 | 31 | #include "prog_util.h" 32 | 33 | #include /* for comparison purposes */ 34 | 35 | #ifdef __GNUC__ 36 | # define _noreturn __attribute__((noreturn)) 37 | #else 38 | # define _noreturn 39 | #endif 40 | 41 | extern void _noreturn 42 | assertion_failed(const char *expr, const char *file, int line); 43 | 44 | #define ASSERT(expr) { if (unlikely(!(expr))) \ 45 | assertion_failed(#expr, __FILE__, __LINE__); } 46 | 47 | extern int alloc_guarded_buffer(size_t size, u8 **start_ret, u8 **end_ret); 48 | extern void free_guarded_buffer(u8 *start, u8 *end); 49 | 50 | extern u64 timer_ticks(void); 51 | extern u64 timer_ticks_to_ms(u64 ticks); 52 | extern u64 timer_MB_per_s(u64 bytes, u64 ticks); 53 | extern u64 timer_KB_per_s(u64 bytes, u64 ticks); 54 | 55 | struct output_bitstream { 56 | machine_word_t bitbuf; 57 | int bitcount; 58 | u8 *next; 59 | u8 *end; 60 | }; 61 | 62 | extern bool put_bits(struct output_bitstream *os, machine_word_t bits, 63 | int num_bits); 64 | extern bool flush_bits(struct output_bitstream *os); 65 | 66 | #endif /* PROGRAMS_TEST_UTIL_H */ 67 | -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/Makefile: -------------------------------------------------------------------------------- 1 | SRC := $(wildcard */*.c) 2 | EXE := $(SRC:.c=) 3 | 4 | CFLAGS := -O2 -s 5 | LDLIBS := -ldeflate 6 | LDFLAGS := -L../.. 7 | CPPFLAGS := -I../.. 8 | 9 | all:$(EXE) 10 | 11 | clean: 12 | rm -f $(EXE) 13 | -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/deflate_compress/fuzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char **argv) 9 | { 10 | struct libdeflate_decompressor *d; 11 | struct libdeflate_compressor *c; 12 | int ret; 13 | int fd = open(argv[1], O_RDONLY); 14 | struct stat stbuf; 15 | assert(fd >= 0); 16 | ret = fstat(fd, &stbuf); 17 | assert(!ret); 18 | 19 | char in[stbuf.st_size]; 20 | ret = read(fd, in, sizeof in); 21 | assert(ret == sizeof in); 22 | 23 | c = libdeflate_alloc_compressor(6); 24 | d = libdeflate_alloc_decompressor(); 25 | 26 | char out[sizeof(in)]; 27 | char checkarray[sizeof(in)]; 28 | 29 | size_t csize = libdeflate_deflate_compress(c, in,sizeof in, out, sizeof out); 30 | if (csize) { 31 | enum libdeflate_result res; 32 | res = libdeflate_deflate_decompress(d, out, csize, checkarray, sizeof in, NULL); 33 | assert(!res); 34 | assert(!memcmp(in, checkarray, sizeof in)); 35 | } 36 | 37 | libdeflate_free_compressor(c); 38 | libdeflate_free_decompressor(d); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/deflate_compress/inputs/0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/libdeflate/tools/afl-fuzz/deflate_compress/inputs/0 -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/deflate_decompress/fuzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char **argv) 8 | { 9 | struct libdeflate_decompressor *d; 10 | int ret; 11 | int fd = open(argv[1], O_RDONLY); 12 | struct stat stbuf; 13 | assert(fd >= 0); 14 | ret = fstat(fd, &stbuf); 15 | assert(!ret); 16 | 17 | char in[stbuf.st_size]; 18 | ret = read(fd, in, sizeof in); 19 | assert(ret == sizeof in); 20 | 21 | char out[sizeof(in) * 3]; 22 | 23 | d = libdeflate_alloc_decompressor(); 24 | 25 | libdeflate_deflate_decompress(d, in, sizeof in, out, sizeof out, NULL); 26 | libdeflate_free_decompressor(d); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/deflate_decompress/inputs/0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/libdeflate/tools/afl-fuzz/deflate_decompress/inputs/0 -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/gzip_decompress/fuzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char **argv) 8 | { 9 | struct libdeflate_decompressor *d; 10 | int ret; 11 | int fd = open(argv[1], O_RDONLY); 12 | struct stat stbuf; 13 | assert(fd >= 0); 14 | ret = fstat(fd, &stbuf); 15 | assert(!ret); 16 | 17 | char in[stbuf.st_size]; 18 | ret = read(fd, in, sizeof in); 19 | assert(ret == sizeof in); 20 | 21 | char out[sizeof(in) * 3]; 22 | 23 | d = libdeflate_alloc_decompressor(); 24 | 25 | libdeflate_gzip_decompress(d, in, sizeof in, out, sizeof out, NULL); 26 | libdeflate_free_decompressor(d); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/gzip_decompress/inputs/0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/libdeflate/tools/afl-fuzz/gzip_decompress/inputs/0 -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/prepare_for_fuzz.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | make -C ../../ clean 6 | make clean 7 | AFL_HARDEN=1 make CC=afl-gcc -C ../../ 8 | AFL_HARDEN=1 make CC=afl-gcc 9 | 10 | for dir in $(find . -mindepth 1 -maxdepth 1 -type d); do 11 | rm -rf /tmp/$dir 12 | cp -va $dir /tmp/$dir 13 | mkdir -p /tmp/$dir/outputs 14 | done 15 | -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/zlib_decompress/fuzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char **argv) 8 | { 9 | struct libdeflate_decompressor *d; 10 | int ret; 11 | int fd = open(argv[1], O_RDONLY); 12 | struct stat stbuf; 13 | assert(fd >= 0); 14 | ret = fstat(fd, &stbuf); 15 | assert(!ret); 16 | 17 | char in[stbuf.st_size]; 18 | ret = read(fd, in, sizeof in); 19 | assert(ret == sizeof in); 20 | 21 | char out[sizeof(in) * 3]; 22 | 23 | d = libdeflate_alloc_decompressor(); 24 | 25 | libdeflate_zlib_decompress(d, in, sizeof in, out, sizeof out, NULL); 26 | libdeflate_free_decompressor(d); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /libdeflate/tools/afl-fuzz/zlib_decompress/inputs/0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/libdeflate/tools/afl-fuzz/zlib_decompress/inputs/0 -------------------------------------------------------------------------------- /libdeflate/tools/android_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eu 4 | 5 | ARCH="arm32" 6 | COMPILER="gcc" 7 | NDKDIR="/opt/android-ndk" 8 | ENABLE_NEON=false 9 | ENABLE_CRYPTO=false 10 | 11 | usage() { 12 | cat << EOF 13 | Usage: $0 [OPTION]... -- [BENCHMARK_PROGRAM_ARG]... 14 | Build the libdeflate test programs for Android 15 | 16 | --arch=ARCH Architecture: arm32|arm64 (default: $ARCH) 17 | --compiler=COMPILER Compiler: gcc|clang (default: $COMPILER) 18 | --ndkdir=NDKDIR Android NDK directory (default: $NDKDIR) 19 | --enable-neon Enable NEON instructions 20 | --enable-crypto Enable crypto extensions (implies NEON too) 21 | EOF 22 | } 23 | 24 | if ! options=$(getopt -o '' \ 25 | -l 'arch:,compiler:,ndkdir:,enable-neon,enable-crypto,help' -- "$@"); then 26 | usage 27 | exit 1 28 | fi 29 | 30 | eval set -- "$options" 31 | 32 | while [ $# -gt 0 ]; do 33 | case "$1" in 34 | --arch) 35 | ARCH="$2" 36 | shift 37 | ;; 38 | --compiler) 39 | COMPILER="$2" 40 | shift 41 | ;; 42 | --ndkdir) 43 | NDKDIR="$2" 44 | shift 45 | ;; 46 | --enable-neon) 47 | ENABLE_NEON=true 48 | ;; 49 | --enable-crypto) 50 | ENABLE_CRYPTO=true 51 | ;; 52 | --help) 53 | usage 54 | exit 0 55 | ;; 56 | --) 57 | shift 58 | break 59 | ;; 60 | *) 61 | echo 1>&2 "Unknown option \"$1\"" 62 | usage 63 | exit 1 64 | esac 65 | shift 66 | done 67 | 68 | CFLAGS="-fPIC" 69 | 70 | case "$ARCH" in 71 | arm|arm32|aarch32) 72 | GCC_TOOLCHAIN="arm-linux-androideabi-4.9" 73 | CLANG_TARGET="armv7-none-linux-androideabi" 74 | if $ENABLE_CRYPTO; then 75 | CFLAGS+=" -march=armv7-a -mfloat-abi=softfp -mfpu=crypto-neon-fp-armv8" 76 | elif $ENABLE_NEON; then 77 | CFLAGS+=" -march=armv7-a -mfloat-abi=softfp -mfpu=neon" 78 | else 79 | CFLAGS+=" -march=armv6" 80 | fi 81 | CFLAGS+=" --sysroot=\"$NDKDIR/platforms/android-12/arch-arm\"" 82 | ;; 83 | arm64|aarch64) 84 | GCC_TOOLCHAIN="aarch64-linux-android-4.9" 85 | CLANG_TARGET="aarch64-none-linux-android" 86 | if $ENABLE_CRYPTO; then 87 | CFLAGS+=" -march=armv8-a+crypto" 88 | else 89 | CFLAGS+=" -march=armv8-a" 90 | fi 91 | CFLAGS+=" --sysroot=\"$NDKDIR/platforms/android-21/arch-arm64\"" 92 | ;; 93 | *) 94 | echo 1>&2 "Unknown architecture: \"$ARCH\"" 95 | usage 96 | exit 1 97 | esac 98 | 99 | case "$COMPILER" in 100 | gcc) 101 | CC="\"$NDKDIR/toolchains/$GCC_TOOLCHAIN/prebuilt/linux-x86_64/bin/${GCC_TOOLCHAIN%-*}-gcc\"" 102 | ;; 103 | clang) 104 | CC="\"$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin/clang\"" 105 | CFLAGS+=" -target \"$CLANG_TARGET\"" 106 | CFLAGS+=" -gcc-toolchain \"$NDKDIR/toolchains/$GCC_TOOLCHAIN/prebuilt/linux-x86_64\"" 107 | ;; 108 | *) 109 | echo 1>&2 "Unknown compiler: \"$COMPILER\"" 110 | usage 111 | exit 1 112 | esac 113 | 114 | make -j$(grep -c processor /proc/cpuinfo) test_programs \ 115 | CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="-pie" 116 | -------------------------------------------------------------------------------- /libdeflate/tools/exec_tests.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Helper script used by run_tests.sh, not intended to be run directly 3 | # 4 | 5 | set -eu 6 | 7 | run_cmd() { 8 | echo "$WRAPPER $@" 9 | $WRAPPER "$@" > /dev/null 10 | } 11 | 12 | for prog in ./test_*; do 13 | run_cmd $prog 14 | done 15 | 16 | for format in '' '-g' '-z'; do 17 | for ref_impl in '' '-Y' '-Z'; do 18 | run_cmd ./benchmark $format $ref_impl $SMOKEDATA 19 | done 20 | done 21 | for level in 1 3 7 9; do 22 | for ref_impl in '' '-Y'; do 23 | run_cmd ./benchmark -$level $ref_impl $SMOKEDATA 24 | done 25 | done 26 | for level in 1 3 7 9 12; do 27 | for ref_impl in '' '-Z'; do 28 | run_cmd ./benchmark -$level $ref_impl $SMOKEDATA 29 | done 30 | done 31 | 32 | echo "exec_tests finished successfully" # Needed for 'adb shell' 33 | -------------------------------------------------------------------------------- /libdeflate/tools/make-windows-releases: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eu 4 | 5 | for arch in 'i686' 'x86_64'; do 6 | make clean 7 | make -j CC=${arch}-w64-mingw32-gcc CFLAGS="-Werror" all \ 8 | benchmark.exe checksum.exe 9 | dir=libdeflate-$(git describe --tags | tr -d v)-windows-${arch}-bin 10 | rm -rf $dir ${dir}.zip 11 | mkdir $dir 12 | cp libdeflate.dll libdeflate.lib libdeflatestatic.lib \ 13 | libdeflate.h *.exe $dir 14 | ${arch}-w64-mingw32-strip ${dir}/libdeflate.dll ${dir}/*.exe 15 | for file in COPYING NEWS; do 16 | sed < $file > ${dir}/${file}.txt -e 's/$/\r/g' 17 | done 18 | for file in README.md; do 19 | sed < $file > ${dir}/${file} -e 's/$/\r/g' 20 | done 21 | (cd ${dir} && zip -r ../${dir}.zip .) 22 | done 23 | -------------------------------------------------------------------------------- /libdeflate/tools/mips_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eu 4 | 5 | TOOLCHAIN_DIR=$HOME/src/ddwrt-toolchains/toolchain-mips_34kc_gcc-5.1.0_musl-1.1.9 6 | 7 | make -j$(grep -c processor /proc/cpuinfo) all test_programs \ 8 | CC="$TOOLCHAIN_DIR/bin/mips-openwrt-linux-musl-gcc" \ 9 | CFLAGS="-DNEED_PRINTF -Werror" 10 | -------------------------------------------------------------------------------- /libdeflate/tools/msc_test.bat: -------------------------------------------------------------------------------- 1 | nmake /f Makefile.msc clean 2 | nmake /f Makefile.msc 3 | copy /y *.exe j:\exe\ 4 | -------------------------------------------------------------------------------- /libdeflate/tools/pgo_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Try gcc profile-guided optimizations 4 | 5 | set -eu 6 | 7 | MAKE="make -j$(grep -c processor /proc/cpuinfo)" 8 | DATAFILE="$HOME/data/silesia" 9 | 10 | $MAKE benchmark > /dev/null 11 | echo "=====================" 12 | echo "Original performance:" 13 | echo "---------------------" 14 | ./benchmark "$@" "$DATAFILE" 15 | 16 | $MAKE CFLAGS=-fprofile-generate LDFLAGS=-fprofile-generate benchmark > /dev/null 17 | ./benchmark "$@" "$DATAFILE" > /dev/null 18 | $MAKE CFLAGS=-fprofile-use benchmark > /dev/null 19 | rm -f {lib,programs}/*.gcda 20 | echo "==========================" 21 | echo "PGO-optimized performance:" 22 | echo "--------------------------" 23 | ./benchmark "$@" "$DATAFILE" 24 | -------------------------------------------------------------------------------- /libdeflate/tools/produce_gzip_benchmark_table.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | do_benchmark() { 6 | usize=$(stat -c %s "$file") 7 | "$HOME/proj/libdeflate/benchmark" -g -s $usize "$@" "$file" \ 8 | | grep Compressed | cut -f 4 -d ' ' 9 | } 10 | 11 | echo "File | zlib -6 | zlib -9 | libdeflate -6 | libdeflate -9 | libdeflate -12" 12 | echo "-----|---------|---------|---------------|---------------|---------------" 13 | 14 | for file in "$@"; do 15 | echo -n "$(basename "$file")" 16 | results=() 17 | results+=($(do_benchmark -Y -6)) 18 | results+=($(do_benchmark -Y -9)) 19 | results+=($(do_benchmark -6)) 20 | results+=($(do_benchmark -9)) 21 | results+=($(do_benchmark -12)) 22 | best=2000000000 23 | for result in "${results[@]}"; do 24 | if (( result < best)); then 25 | best=$result 26 | fi 27 | done 28 | for result in "${results[@]}"; do 29 | if (( result == best )); then 30 | em="**" 31 | else 32 | em="" 33 | fi 34 | echo -n " | ${em}${result}${em}" 35 | done 36 | echo 37 | done 38 | -------------------------------------------------------------------------------- /libdeflate/tools/windows_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eu 4 | 5 | make -j CC=i686-w64-mingw32-gcc all test_programs 6 | cp -vf *.exe /j/exe/ 7 | make -j CC=x86_64-w64-mingw32-gcc all test_programs 8 | cp -vf *.exe /j/exe64/ 9 | 10 | sudo $HOME/bin/sudo/restart-smbd 11 | -------------------------------------------------------------------------------- /tlib/tDebug.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEBUG 2 | #define Debug 3 | #define DebugA 4 | #define DebugW 5 | #define DebugU8 6 | #endif 7 | -------------------------------------------------------------------------------- /tlib/tapi32ex.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/tlib/tapi32ex.cpp -------------------------------------------------------------------------------- /tlib/tapi32u8.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/tlib/tapi32u8.cpp -------------------------------------------------------------------------------- /tlib/tapi32u8.h: -------------------------------------------------------------------------------- 1 | /* @(#)Copyright (C) 1996-2010 H.Shirouzu tapi32u8.h Ver0.99 */ 2 | /* ======================================================================== 3 | Project Name : Win32 Lightweight Class Library Test 4 | Module Name : Main Header 5 | Create : 2005-04-10(Sun) 6 | Update : 2010-05-09(Sun) 7 | Copyright : H.Shirouzu 8 | Reference : 9 | ======================================================================== */ 10 | 11 | #ifndef TAPI32U8_H 12 | #define TAPI32U8_H 13 | 14 | #ifdef _USE_T_U8FUNC_ 15 | 16 | // UTF8 string class 17 | enum StrMode { BY_UTF8, BY_MBCS }; 18 | 19 | inline int WtoU8(const WCHAR *src, char *dst, int bufsize, int max_len=-1) { 20 | return ::WideCharToMultiByte(CP_UTF8, 0, src, max_len, dst, bufsize, 0, 0); 21 | } 22 | inline int U8toW(const char *src, WCHAR *dst, int bufsize, int max_len=-1) { 23 | return ::MultiByteToWideChar(CP_UTF8, 0, src, max_len, dst, bufsize); 24 | } 25 | inline int WtoS(LPCWSTR src, char *dst, int bufsize, StrMode mode, int max_len=-1) { 26 | return (mode == BY_UTF8) ? WtoU8(src, dst, bufsize, max_len) 27 | : WtoA(src, dst, bufsize, max_len); 28 | } 29 | 30 | WCHAR *U8toW(const char *src, BOOL noStatic=FALSE); 31 | char *WtoU8(const WCHAR *src, BOOL noStatic=FALSE); 32 | char *WtoA(const WCHAR *src, BOOL noStatic=FALSE); 33 | char *AtoU8(const char *src, BOOL noStatic=FALSE); 34 | char *U8toA(const char *src, BOOL noStatic=FALSE); 35 | 36 | // Win32(W) API UTF8 wrapper 37 | BOOL GetMenuStringU8(HMENU hMenu, UINT uItem, char *buf, int bufsize, UINT flags); 38 | DWORD GetModuleFileNameU8(HMODULE hModule, char *buf, DWORD bufsize); 39 | UINT GetDriveTypeU8(const char *path); 40 | 41 | class U8str { 42 | char *s; 43 | public: 44 | U8str(const WCHAR *_s=NULL) { s = _s ? WtoU8(_s, TRUE) : NULL; } 45 | U8str(const char *_s, StrMode mode=BY_UTF8) { 46 | s = _s ? mode == BY_UTF8 ? strdupNew(s) : AtoU8(_s, TRUE) : NULL; 47 | } 48 | U8str(int len) { if (len) { s = new char [len]; *s = 0; } else { s = NULL; } } 49 | ~U8str() { delete [] s; } 50 | operator const char *() { return s; } 51 | char *Buf() { return s; } 52 | }; 53 | 54 | class Wstr { 55 | WCHAR *s; 56 | public: 57 | Wstr(const char *_s, StrMode mode=BY_UTF8) { 58 | s = _s ? mode == BY_UTF8 ? U8toW(_s, TRUE) : AtoW(_s, TRUE) : NULL; 59 | } 60 | Wstr(int len) { if (len) { s = new WCHAR [len]; *s = 0; } else { s = NULL; } } 61 | ~Wstr() { delete [] s; } 62 | operator const WCHAR *() { return s; } 63 | operator const void *() { return s; } // for V() 64 | WCHAR *Buf() { return s; } 65 | }; 66 | 67 | class MBCSstr { 68 | char *s; 69 | public: 70 | MBCSstr(const WCHAR *_s=NULL) { s = _s ? WtoA(_s, TRUE) : NULL; } 71 | MBCSstr(const char *_s, StrMode mode=BY_UTF8) { 72 | s = _s ? mode == BY_UTF8 ? U8toA(_s, TRUE) : strdupNew(s) : NULL; 73 | } 74 | MBCSstr(int len) { if (len) { s = new char [len]; *s = 0; } else { s = NULL; } } 75 | ~MBCSstr() { delete [] s; } 76 | operator const char *() { return s; } 77 | char *Buf() { return s; } 78 | }; 79 | 80 | BOOL IsUTF8(const char *s); 81 | 82 | #endif 83 | #endif 84 | -------------------------------------------------------------------------------- /tlib/tconf.h: -------------------------------------------------------------------------------- 1 | #ifndef TCONF_H 2 | #define TCONF_H 3 | 4 | //#define _USE_T_CHARCONV_ 5 | //#define _USE_T_REG_ 6 | //#define _USE_T_INI_ 7 | //#define _USE_T_LIST_ 8 | //#define _USE_T_U8FUNC_ 9 | //#define _USE_T_CRYPT_ 10 | 11 | #endif -------------------------------------------------------------------------------- /tlib/tlist.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* ======================================================================== 3 | Project Name : Win32 Lightweight Class Library Test 4 | Module Name : List Class 5 | Create : 1996-06-01(Sat) 6 | Update : 2009-03-09(Mon) 7 | Copyright : H.Shirouzu 8 | Reference : 9 | ======================================================================== */ 10 | 11 | #include "tlib.h" 12 | #ifdef _USE_T_LIST_ 13 | static char *tlist_id = 14 | "@(#)Copyright (C) 1996-2009 H.Shirouzu tlist.cpp Ver0.97"; 15 | 16 | #include "tlist.h" 17 | /* 18 | TList class 19 | */ 20 | 21 | TList::TList(void) 22 | { 23 | Init(); 24 | } 25 | 26 | void TList::Init(void) 27 | { 28 | top.prior = top.next = ⊤ 29 | } 30 | 31 | void TList::AddObj(TListObj * obj) 32 | { 33 | obj->prior = top.prior; 34 | obj->next = ⊤ 35 | top.prior->next = obj; 36 | top.prior = obj; 37 | } 38 | 39 | void TList::DelObj(TListObj * obj) 40 | { 41 | // if (!obj->next || !obj->prior || obj->next != &top && obj->prior != &top) { 42 | // Debug("DelObj(%p) (%p/%p)\n", obj, obj->next, obj->prior); 43 | // } 44 | if (obj->next) { 45 | obj->next->prior = obj->prior; 46 | } 47 | if (obj->prior) { 48 | obj->prior->next = obj->next; 49 | } 50 | obj->next = obj->prior = NULL; 51 | } 52 | 53 | TListObj* TList::TopObj(void) 54 | { 55 | // if (top.next != &top && top.next->next != &top && top.next->prior != &top) { 56 | // Debug("TopObj(%p) \n", top.next); 57 | // } 58 | return top.next == &top ? NULL : top.next; 59 | } 60 | 61 | TListObj* TList::NextObj(TListObj *obj) 62 | { 63 | return obj->next == &top ? NULL : obj->next; 64 | } 65 | 66 | void TList::MoveList(TList *from_list) 67 | { 68 | if (from_list->top.next != &from_list->top) { // from_list is not empty 69 | if (top.next == &top) { // empty 70 | top = from_list->top; 71 | top.next->prior = top.prior->next = ⊤ 72 | } 73 | else { 74 | top.prior->next = from_list->top.next; 75 | from_list->top.next->prior = top.prior; 76 | from_list->top.prior->next = ⊤ 77 | top.prior = from_list->top.prior; 78 | } 79 | from_list->Init(); 80 | } 81 | } 82 | 83 | /* 84 | TRecycleList class 85 | */ 86 | TRecycleList::TRecycleList(int init_cnt, int size) 87 | { 88 | data = new char [init_cnt * size]; 89 | memset(data, 0, init_cnt * size); 90 | 91 | for (int cnt=0; cnt < init_cnt; cnt++) { 92 | TListObj *obj = (TListObj *)(data + cnt * size); 93 | list[FREE_LIST].AddObj(obj); 94 | } 95 | } 96 | 97 | TRecycleList::~TRecycleList() 98 | { 99 | delete [] data; 100 | } 101 | 102 | TListObj *TRecycleList::GetObj(int list_type) 103 | { 104 | TListObj *obj = list[list_type].TopObj(); 105 | 106 | if (obj) 107 | list[list_type].DelObj(obj); 108 | 109 | return obj; 110 | } 111 | 112 | void TRecycleList::PutObj(int list_type, TListObj *obj) 113 | { 114 | list[list_type].AddObj(obj); 115 | } 116 | 117 | #endif -------------------------------------------------------------------------------- /tlib/tlist.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TLIST_H 3 | #define TLIST_H 4 | 5 | #ifdef _USE_T_INI_ 6 | #ifndef _USE_T_LIST_ 7 | #define _USE_T_LIST_ 8 | #endif 9 | #endif 10 | 11 | #ifdef _USE_T_LIST_ 12 | 13 | struct TListObj { 14 | TListObj *prior, *next; 15 | }; 16 | 17 | class TList { 18 | protected: 19 | TListObj top; 20 | 21 | public: 22 | TList(void); 23 | void Init(void); 24 | void AddObj(TListObj *obj); 25 | void DelObj(TListObj *obj); 26 | TListObj *TopObj(void); 27 | TListObj *NextObj(TListObj *obj); 28 | BOOL IsEmpty() { return top.next == ⊤ } 29 | void MoveList(TList *from_list); 30 | }; 31 | 32 | #define FREE_LIST 0 33 | #define USED_LIST 1 34 | #define RLIST_MAX 2 35 | class TRecycleList { 36 | protected: 37 | char *data; 38 | TList list[RLIST_MAX]; 39 | 40 | public: 41 | TRecycleList(int init_cnt, int size); 42 | ~TRecycleList(); 43 | TListObj *GetObj(int list_type); 44 | void PutObj(int list_type, TListObj *obj); 45 | }; 46 | 47 | #endif 48 | #endif -------------------------------------------------------------------------------- /tlib/tmisc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/tlib/tmisc.cpp -------------------------------------------------------------------------------- /tlib/tregist.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/tlib/tregist.cpp -------------------------------------------------------------------------------- /tlib/tregist.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TREGISTRY_H 3 | #define TREGISTRY_H 4 | 5 | #define MAX_KEYARRAY 30 6 | 7 | #ifdef _USE_T_REG_ 8 | 9 | class TRegistry { 10 | protected: 11 | HKEY topKey; 12 | int openCnt; 13 | //StrMode strMode; 14 | HKEY hKey[MAX_KEYARRAY]; 15 | 16 | public: 17 | TRegistry(LPCTSTR company, LPTSTR appName=NULL/*, StrMode mode=BY_UTF8*/); 18 | TRegistry(HKEY top_key/*, StrMode mode=BY_UTF8*/); 19 | ~TRegistry(); 20 | 21 | void ChangeTopKey(HKEY topKey); 22 | 23 | BOOL ChangeApp(LPCTSTR company, LPTSTR appName=NULL); 24 | 25 | BOOL OpenKey(LPCTSTR subKey, BOOL createFlg=FALSE); 26 | 27 | BOOL CreateKey(LPCTSTR subKey) { return OpenKey(subKey, TRUE); } 28 | 29 | BOOL CloseKey(void); 30 | 31 | BOOL GetInt(LPCTSTR key, int *val); 32 | 33 | BOOL SetInt(LPCTSTR key, int val); 34 | 35 | BOOL GetLong(LPCTSTR key, long *val); 36 | 37 | BOOL SetLong(LPCTSTR key, long val); 38 | 39 | BOOL GetStr(LPCTSTR key, LPTSTR str, int size_byte); 40 | 41 | BOOL SetStr(LPCTSTR key, LPCTSTR str); 42 | 43 | BOOL GetByte(LPCTSTR key, BYTE *data, int *size); 44 | 45 | BOOL SetByte(LPCTSTR key, const BYTE *data, int size); 46 | 47 | BOOL DeleteKey(LPCTSTR str); 48 | 49 | BOOL DeleteValue(LPCTSTR str); 50 | 51 | BOOL EnumKey(DWORD cnt, LPTSTR buf, int size); 52 | 53 | BOOL EnumValue(DWORD cnt, LPTSTR buf, int size, DWORD *type=NULL); 54 | 55 | BOOL DeleteChildTree(LPCTSTR subkey=NULL); 56 | 57 | }; 58 | 59 | #endif 60 | 61 | #endif -------------------------------------------------------------------------------- /tlib/twin.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/tlib/twin.cpp -------------------------------------------------------------------------------- /zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (z_const Bytef *)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 79 | (sourceLen >> 25) + 13; 80 | } 81 | -------------------------------------------------------------------------------- /zlib/contrib/README.contrib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halysondev/WinPCK/e61bc2bb8401ac3cb44aaec746c8daa45a6b3d15/zlib/contrib/README.contrib -------------------------------------------------------------------------------- /zlib/contrib/asm686/README.686: -------------------------------------------------------------------------------- 1 | This is a patched version of zlib, modified to use 2 | Pentium-Pro-optimized assembly code in the deflation algorithm. The 3 | files changed/added by this patch are: 4 | 5 | README.686 6 | match.S 7 | 8 | The speedup that this patch provides varies, depending on whether the 9 | compiler used to build the original version of zlib falls afoul of the 10 | PPro's speed traps. My own tests show a speedup of around 10-20% at 11 | the default compression level, and 20-30% using -9, against a version 12 | compiled using gcc 2.7.2.3. Your mileage may vary. 13 | 14 | Note that this code has been tailored for the PPro/PII in particular, 15 | and will not perform particuarly well on a Pentium. 16 | 17 | If you are using an assembler other than GNU as, you will have to 18 | translate match.S to use your assembler's syntax. (Have fun.) 19 | 20 | Brian Raiter 21 | breadbox@muppetlabs.com 22 | April, 1998 23 | 24 | 25 | Added for zlib 1.1.3: 26 | 27 | The patches come from 28 | http://www.muppetlabs.com/~breadbox/software/assembly.html 29 | 30 | To compile zlib with this asm file, copy match.S to the zlib directory 31 | then do: 32 | 33 | CFLAGS="-O3 -DASMV" ./configure 34 | make OBJA=match.o 35 | 36 | 37 | Update: 38 | 39 | I've been ignoring these assembly routines for years, believing that 40 | gcc's generated code had caught up with it sometime around gcc 2.95 41 | and the major rearchitecting of the Pentium 4. However, I recently 42 | learned that, despite what I believed, this code still has some life 43 | in it. On the Pentium 4 and AMD64 chips, it continues to run about 8% 44 | faster than the code produced by gcc 4.1. 45 | 46 | In acknowledgement of its continuing usefulness, I've altered the 47 | license to match that of the rest of zlib. Share and Enjoy! 48 | 49 | Brian Raiter 50 | breadbox@muppetlabs.com 51 | April, 2007 52 | -------------------------------------------------------------------------------- /zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribtution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 | The initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work)); 63 | -------------------------------------------------------------------------------- /zlib/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | 20 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 21 | enough memory, Z_BUF_ERROR if there was not enough room in the output 22 | buffer, or Z_DATA_ERROR if the input data was corrupted. 23 | */ 24 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 25 | Bytef *dest; 26 | uLongf *destLen; 27 | const Bytef *source; 28 | uLong sourceLen; 29 | { 30 | z_stream stream; 31 | int err; 32 | 33 | stream.next_in = (z_const Bytef *)source; 34 | stream.avail_in = (uInt)sourceLen; 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | 45 | err = inflateInit(&stream); 46 | if (err != Z_OK) return err; 47 | 48 | err = inflate(&stream, Z_FINISH); 49 | if (err != Z_STREAM_END) { 50 | inflateEnd(&stream); 51 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 52 | return Z_DATA_ERROR; 53 | return err; 54 | } 55 | *destLen = stream.total_out; 56 | 57 | err = inflateEnd(&stream); 58 | return err; 59 | } 60 | --------------------------------------------------------------------------------