├── .gitignore ├── 1.xlog ├── 1_.log ├── LICENSE ├── README.md ├── XlogDecode.sln ├── XlogDecode.suo └── XlogDecode ├── BytesUtils.h ├── CFileScan.cpp ├── CFileScan.h ├── FileEx.cpp ├── FileEx.h ├── ReadMe.txt ├── XlogDecode.aps ├── XlogDecode.cpp ├── XlogDecode.h ├── XlogDecode.rc ├── XlogDecode.vcproj ├── XlogDecode.vcproj.TTY-20161208PTY.Administrator.user ├── XlogDecode.vcproj.XXY-20161208PTW.Administrator.user ├── XlogDecodeDlg.cpp ├── XlogDecodeDlg.h ├── XlogDef.h ├── XlogFileScan.cpp ├── XlogFileScan.h ├── def.h ├── misc.cpp ├── misc.h ├── res ├── XlogDecode.ico ├── XlogDecode.rc2 └── XlogDecode2.ico ├── resource.h ├── stdafx.cpp ├── stdafx.h ├── targetver.h └── zlib ├── adler32.c ├── compress.c ├── crc32.c ├── crc32.h ├── deflate.c ├── deflate.h ├── gzclose.c ├── gzguts.h ├── gzlib.c ├── gzread.c ├── gzwrite.c ├── 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 ├── zutil.c └── zutil.h /.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 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /1.xlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/1.xlog -------------------------------------------------------------------------------- /1_.log: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^Mar 13 2018^^^11:52:29^^^^^^^^^^[14735,14735][2018-03-13 +0800 17:12:23] 2 | del time out files time: 2 3 | get mmap time: 0 4 | MARS_URL: 5 | MARS_PATH: 6 | MARS_REVISION: 7 | MARS_BUILD_TIME: 2018-03-13 11:50:31 8 | MARS_BUILD_JOB: mars_xlog_sdk/mars_libs 9 | log appender mode:0, use mmap:1 10 | [D][2018-03-13 +8.0 17:12:23.203][14735, 1*][dream][, , 0][========test中国家医药管理局 今天发布重要消息:!@#%^& 11 | [D][2018-03-13 +8.0 17:12:23.205][14735, 1*][dream][, , 0][_20180313_171223 12 | [D][2018-03-13 +8.0 17:12:23.206][14735, 1*][dream][, , 0][locker version:aa 00 03 00 d1 00 d1 55 13 | [D][2018-03-13 +8.0 17:12:23.206][14735, 1*][dream][, , 0][locker unlock:aa 00 03 00 d2 00 d2 55 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 staneychan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XlogDecode 2 | Source code of win32 tool which is used to decode the xlog written by tencent. 3 | 4 | Project was compiled on visual studio 2008 on windows 7 64. 5 | 6 | Anyone who wants to compiled on vs2015(or vs2017) just need to copy the source to your new project 7 | 8 | and set *.c files in zlib to not using pre-compile header. 9 | 10 | remember to add all files to your project, enjoy it :) 11 | 12 | contact:124928918@qq.com 13 | 14 | 中文: 15 | 16 | win32下解码xlog的工具。 17 | 18 | xlog为腾讯开源mars工程里的log模块,对保存的xlog文件进行了压缩和加密,并且目前只提供了python工具用于解密xlog文件。 19 | 20 | 当需要在任意PC电脑查看加密的LOG内容时,需要安装python才能进行解密,极其不方便。 21 | 22 | 因此编写了上述工具,可直接拖放xlog文件点击解密即可在.xlog文件路径下生成.log的同名解密文件。 23 | 24 | 源码说明: 25 | 26 | zlib移植自mars, 编译工程需要将zlib下的.C文件选择not using pre-compile header。其他代码自己编写。 27 | 28 | 联系方式:124928918@qq.com 29 | -------------------------------------------------------------------------------- /XlogDecode.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XlogDecode", "XlogDecode\XlogDecode.vcproj", "{3A3FBDFF-DDA3-4075-9307-D2CB8F5BD748}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {3A3FBDFF-DDA3-4075-9307-D2CB8F5BD748}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {3A3FBDFF-DDA3-4075-9307-D2CB8F5BD748}.Debug|Win32.Build.0 = Debug|Win32 14 | {3A3FBDFF-DDA3-4075-9307-D2CB8F5BD748}.Release|Win32.ActiveCfg = Release|Win32 15 | {3A3FBDFF-DDA3-4075-9307-D2CB8F5BD748}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /XlogDecode.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode.suo -------------------------------------------------------------------------------- /XlogDecode/BytesUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | CString dump(byte *buf, int len){ 4 | TCHAR hex[8]; 5 | CString out = L""; 6 | for(int ii=0;ii>>>>>>>>file does not exist"); 23 | return FALSE; 24 | } 25 | m_lFileLength = _GetLength(); 26 | 27 | return TRUE; 28 | } 29 | 30 | BOOL CFileEx::Open(LPCSTR pszPathName, CHAR *pszOpenFlags) 31 | { 32 | m_pFileStream = fopen(pszPathName, pszOpenFlags); 33 | if(NULL == m_pFileStream){ 34 | // wprintf(L">>>>>>>>>file does not exist"); 35 | return FALSE; 36 | } 37 | m_lFileLength = _GetLength(); 38 | 39 | return TRUE; 40 | } 41 | 42 | 43 | BOOL CFileEx::Close() 44 | { 45 | if(m_pFileStream){ 46 | //0 indicate okay, nonzero indicate failure 47 | if(0 == fclose(m_pFileStream)){ 48 | m_lFileLength = 0; 49 | m_pFileStream = NULL; 50 | return TRUE; 51 | } 52 | } 53 | return FALSE; 54 | } 55 | 56 | LONG CFileEx::_GetLength() 57 | { 58 | LONG lCurPos = 0, lFileLength = 0; 59 | 60 | //Save current pos 61 | lCurPos = ftell(m_pFileStream); 62 | //Calculate file size 63 | fseek(m_pFileStream, 0L, SEEK_END); 64 | lFileLength = ftell(m_pFileStream); 65 | //Restore to original pos 66 | fseek(m_pFileStream, lCurPos, SEEK_SET); 67 | 68 | return lFileLength; 69 | } 70 | 71 | LONG CFileEx::Length()//public function 72 | { 73 | return m_lFileLength; 74 | } 75 | 76 | UINT CFileEx::Read(void* buffer, UINT size) 77 | { 78 | UINT nRead = 0; 79 | 80 | if(m_pFileStream){ 81 | LONG lCurPos = ftell(m_pFileStream); 82 | if(fread(buffer, size, 1, m_pFileStream)){ 83 | nRead = size; 84 | } 85 | else{ 86 | LONG lFileEnd = ftell(m_pFileStream); 87 | nRead = lFileEnd - lCurPos; 88 | } 89 | } 90 | 91 | return nRead; 92 | } 93 | 94 | BOOL CFileEx::Write(void* buffer, UINT size) 95 | { 96 | if(m_pFileStream){ 97 | size_t count = fwrite(buffer, size, 1, m_pFileStream); 98 | if(count) 99 | return 1; 100 | } 101 | return 0; 102 | } 103 | 104 | void CFileEx::SeekToEnd() 105 | { 106 | if(m_pFileStream){ 107 | fseek(m_pFileStream, 0, SEEK_END); 108 | } 109 | } 110 | 111 | void CFileEx::SeekToBegin() 112 | { 113 | if(m_pFileStream){ 114 | fseek(m_pFileStream, 0, SEEK_SET); 115 | } 116 | } 117 | 118 | int CFileEx::Seek(LONG lOff, int nFrom) 119 | { 120 | if(m_pFileStream){ 121 | return fseek(m_pFileStream, lOff, nFrom); 122 | } 123 | return -1; 124 | } 125 | 126 | void CFileEx::SeekOffset(LONG lOffset) 127 | { 128 | if(m_pFileStream){ 129 | fseek(m_pFileStream, lOffset, SEEK_CUR); 130 | } 131 | } -------------------------------------------------------------------------------- /XlogDecode/FileEx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/FileEx.h -------------------------------------------------------------------------------- /XlogDecode/ReadMe.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/ReadMe.txt -------------------------------------------------------------------------------- /XlogDecode/XlogDecode.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/XlogDecode.aps -------------------------------------------------------------------------------- /XlogDecode/XlogDecode.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/XlogDecode.cpp -------------------------------------------------------------------------------- /XlogDecode/XlogDecode.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/XlogDecode.h -------------------------------------------------------------------------------- /XlogDecode/XlogDecode.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/XlogDecode.rc -------------------------------------------------------------------------------- /XlogDecode/XlogDecode.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/XlogDecode.vcproj -------------------------------------------------------------------------------- /XlogDecode/XlogDecode.vcproj.TTY-20161208PTY.Administrator.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /XlogDecode/XlogDecode.vcproj.XXY-20161208PTW.Administrator.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /XlogDecode/XlogDecodeDlg.cpp: -------------------------------------------------------------------------------- 1 | 2 | // XlogDecodeDlg.cpp : 实现文件 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "XlogDecode.h" 7 | #include "XlogDecodeDlg.h" 8 | 9 | #include "BytesUtils.h" 10 | #include "xlogdef.h" 11 | #ifdef _DEBUG 12 | #define new DEBUG_NEW 13 | #endif 14 | 15 | 16 | // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 17 | 18 | class CAboutDlg : public CDialog 19 | { 20 | public: 21 | CAboutDlg(); 22 | 23 | // 对话框数据 24 | enum { IDD = IDD_ABOUTBOX }; 25 | 26 | protected: 27 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 28 | 29 | // 实现 30 | protected: 31 | DECLARE_MESSAGE_MAP() 32 | }; 33 | 34 | CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 35 | { 36 | } 37 | 38 | void CAboutDlg::DoDataExchange(CDataExchange* pDX) 39 | { 40 | CDialog::DoDataExchange(pDX); 41 | } 42 | 43 | BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 44 | END_MESSAGE_MAP() 45 | 46 | 47 | // CXlogDecodeDlg 对话框 48 | 49 | 50 | 51 | 52 | CXlogDecodeDlg::CXlogDecodeDlg(CWnd* pParent /*=NULL*/) 53 | : CDialog(CXlogDecodeDlg::IDD, pParent) 54 | { 55 | m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 56 | } 57 | 58 | void CXlogDecodeDlg::DoDataExchange(CDataExchange* pDX) 59 | { 60 | CDialog::DoDataExchange(pDX); 61 | DDX_Control(pDX, IDC_CHECK_RECURSE, m_chk_recurse); 62 | DDX_Control(pDX, IDC_CHECK_SKIP_ERROR_BLOCK, m_chk_skip_error_block); 63 | } 64 | 65 | BEGIN_MESSAGE_MAP(CXlogDecodeDlg, CDialog) 66 | ON_WM_SYSCOMMAND() 67 | ON_WM_PAINT() 68 | ON_WM_QUERYDRAGICON() 69 | //}}AFX_MSG_MAP 70 | ON_BN_CLICKED(IDC_BTN_DECODE, &CXlogDecodeDlg::OnBnClickedBtnDecode) 71 | ON_WM_DROPFILES() 72 | END_MESSAGE_MAP() 73 | 74 | 75 | // CXlogDecodeDlg 消息处理程序 76 | 77 | BOOL CXlogDecodeDlg::OnInitDialog() 78 | { 79 | CDialog::OnInitDialog(); 80 | 81 | // 将“关于...”菜单项添加到系统菜单中。 82 | 83 | // IDM_ABOUTBOX 必须在系统命令范围内。 84 | ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 85 | ASSERT(IDM_ABOUTBOX < 0xF000); 86 | 87 | CMenu* pSysMenu = GetSystemMenu(FALSE); 88 | if (pSysMenu != NULL) 89 | { 90 | BOOL bNameValid; 91 | CString strAboutMenu; 92 | bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); 93 | ASSERT(bNameValid); 94 | if (!strAboutMenu.IsEmpty()) 95 | { 96 | pSysMenu->AppendMenu(MF_SEPARATOR); 97 | pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 98 | } 99 | } 100 | 101 | // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 102 | // 执行此操作 103 | SetIcon(m_hIcon, TRUE); // 设置大图标 104 | SetIcon(m_hIcon, FALSE); // 设置小图标 105 | m_chk_skip_error_block.SetCheck(TRUE); 106 | 107 | // TODO: 在此添加额外的初始化代码 108 | 109 | //Xlog参考:http://blog.csdn.net/linuxfu/article/details/61915473 110 | //zlib参考:http://zlib.net/zlib_how.html 111 | 112 | 113 | return TRUE; // 除非将焦点设置到控件,否则返回 TRUE 114 | } 115 | 116 | void CXlogDecodeDlg::OnSysCommand(UINT nID, LPARAM lParam) 117 | { 118 | if ((nID & 0xFFF0) == IDM_ABOUTBOX) 119 | { 120 | CAboutDlg dlgAbout; 121 | dlgAbout.DoModal(); 122 | } 123 | else 124 | { 125 | CDialog::OnSysCommand(nID, lParam); 126 | } 127 | } 128 | 129 | // 如果向对话框添加最小化按钮,则需要下面的代码 130 | // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, 131 | // 这将由框架自动完成。 132 | 133 | void CXlogDecodeDlg::OnPaint() 134 | { 135 | if (IsIconic()) 136 | { 137 | CPaintDC dc(this); // 用于绘制的设备上下文 138 | 139 | SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); 140 | 141 | // 使图标在工作区矩形中居中 142 | int cxIcon = GetSystemMetrics(SM_CXICON); 143 | int cyIcon = GetSystemMetrics(SM_CYICON); 144 | CRect rect; 145 | GetClientRect(&rect); 146 | int x = (rect.Width() - cxIcon + 1) / 2; 147 | int y = (rect.Height() - cyIcon + 1) / 2; 148 | 149 | // 绘制图标 150 | dc.DrawIcon(x, y, m_hIcon); 151 | } 152 | else 153 | { 154 | CDialog::OnPaint(); 155 | } 156 | } 157 | 158 | //当用户拖动最小化窗口时系统调用此函数取得光标 159 | //显示。 160 | HCURSOR CXlogDecodeDlg::OnQueryDragIcon() 161 | { 162 | return static_cast(m_hIcon); 163 | } 164 | 165 | //////////////////////////////////////////////////////////////////////////////// 166 | //////////////////////////////////////////////////////////////////////////////// 167 | 168 | 169 | void CXlogDecodeDlg::OnDropFiles(HDROP hDropInfo) 170 | { 171 | //清空所有 172 | m_listFile.RemoveAll(); 173 | 174 | int DropCount = DragQueryFile(hDropInfo,-1,NULL,0);//取得被拖动文件的数目 175 | for(int i=0;i< DropCount;i++) 176 | { 177 | WCHAR wcStr[MAX_PATH]; 178 | DragQueryFile(hDropInfo,i,wcStr,MAX_PATH);//获得拖曳的第i个文件的文件名 179 | m_listFile.Add(wcStr); 180 | OutputDebugString(wcStr); 181 | } 182 | DragFinish(hDropInfo); //拖放结束后,释放内存 183 | 184 | SetDlgItemText(IDC_EDIT_PATH, m_listFile.GetAt(0)); 185 | 186 | CDialog::OnDropFiles(hDropInfo); 187 | } 188 | 189 | 190 | int CXlogDecodeDlg::decode(){ 191 | CFileEx file; 192 | file.Open(L"F:\\project_ms\\XlogDecode\\1.xlog", L"rb"); 193 | TRACE1("GET file len:%d\r\n", file.Length()); 194 | byte *header = new byte[GetHeaderLen()]; 195 | file.Read(header, GetHeaderLen()); 196 | CString szHead = dump(header, GetHeaderLen()); 197 | OutputDebugString(szHead + L"\r\n"); 198 | xlogHead sHead; 199 | memcpy(&sHead , header, sizeof(xlogHead)); 200 | TRACE("DEBUG_GET BODY length:%d start=>%d:%d\r\n", sHead.length, sHead.beginHour, sHead.endHour); 201 | 202 | //body 203 | byte *out = new byte[sHead.length]; 204 | file.Read(out, sHead.length); 205 | //TRACE("last :%x %x\r\n", out[sHead.length-2],out[sHead.length-1]); 206 | 207 | CFileEx writer; 208 | if(writer.Open(L"F:\\project_ms\\XlogDecode\\_1.log", L"wb")){ 209 | inflateToFile(out, sHead.length, writer); 210 | writer.Close(); 211 | } 212 | 213 | 214 | #if 0 215 | byte decodeBuf[128]; 216 | DWORD bytesDecoded; 217 | DWORD testlen = 100; 218 | byte *testDest = new byte[testlen]; 219 | memset(testDest,0,100); 220 | byte *testSrc = new byte[20]; 221 | memcpy(testSrc, "123abc", 6); 222 | compress(testDest, &testlen, testSrc, 6); 223 | 224 | if(Z_OK == uncompress(decodeBuf, &bytesDecoded, testDest, 100)){ 225 | decodeBuf[bytesDecoded] = 0; 226 | } 227 | #endif 228 | 229 | delete []header; 230 | 231 | return 1; 232 | } 233 | 234 | int skipToNextBlock(CFileEx &reader, xlogHead &sHead){ 235 | int skipCount = 0; 236 | byte endFlag,startFlag; 237 | byte *header = new byte[GetHeaderLen()]; 238 | UINT readCount = 0; 239 | do{ 240 | readCount = reader.Read(&endFlag, 1); 241 | skipCount++; 242 | if(endFlag == 0x00){ 243 | reader.Read(&startFlag, 1); 244 | skipCount++; 245 | if(startFlag == 0x09){//kMagicAsyncNoCryptStart 246 | reader.SeekOffset(-1); 247 | reader.Read(header, GetHeaderLen()); 248 | memcpy(&sHead , header, sizeof(xlogHead)); 249 | } 250 | } 251 | }while(sHead.length > 65535 && readCount > 0); 252 | delete header; 253 | return skipCount; 254 | } 255 | 256 | void CXlogDecodeDlg::decodeFile(CString srcFilePath, CString savePath){ 257 | CFileEx writer; 258 | CFileEx reader; 259 | if(!reader.Open(srcFilePath, L"rb")){ 260 | TRACE("@@@@@@@FILE not exist!!!\r\n"); 261 | ASSERT(0); 262 | return; 263 | } 264 | if(!writer.Open(savePath, L"wb+")){ 265 | TRACE("@@@@@@@create FILE ERROR!!!\r\n"); 266 | ASSERT(0); 267 | return; 268 | } 269 | UINT fileLength = reader.Length(); 270 | TRACE1("GET file len:%d\r\n", fileLength); 271 | byte *header = new byte[GetHeaderLen()]; 272 | UINT readPos = 0; 273 | while(readPos < fileLength){ 274 | //header 275 | reader.Read(header, GetHeaderLen()); 276 | readPos += GetHeaderLen(); 277 | //打印header 278 | // CString szHead = dump(header, GetHeaderLen()); 279 | // OutputDebugString(szHead + L"\r\n"); 280 | 281 | xlogHead sHead; 282 | memcpy(&sHead , header, sizeof(xlogHead)); 283 | TRACE("GET BODY start FLAG:%02x ->seq:%d\r\n", sHead.start, sHead.seq); 284 | 285 | TRACE("GET BODY length:%d start=>%d:%d\r\n", sHead.length, sHead.beginHour, sHead.endHour); 286 | 287 | if(m_bSkipErrorBlock && sHead.length > 65535){ 288 | readPos += skipToNextBlock(reader, sHead); 289 | } 290 | if(sHead.length == 0 || sHead.length > 65535){ 291 | continue; 292 | } 293 | //body 294 | byte *body = new byte[sHead.length]; 295 | reader.Read(body, sHead.length); 296 | //TRACE("last :%x %x\r\n", out[sHead.length-2],out[sHead.length-1]); 297 | 298 | //write to file 299 | inflateToFile(body, sHead.length, writer); 300 | 301 | //END tag 302 | reader.Read(body, 1); 303 | 304 | readPos += sHead.length + 1; 305 | delete []body; 306 | } 307 | writer.Close(); 308 | delete []header; 309 | } 310 | 311 | int CXlogDecodeDlg::inflateToFile(byte *_inBlock, DWORD _inSize, CFileEx &_writer){ 312 | 313 | #define CHUNK 1024 314 | int ret; 315 | unsigned int have; 316 | z_stream strm; 317 | // unsigned char in[CHUNK]; 318 | unsigned char out[CHUNK]; 319 | 320 | 321 | /* allocate inflate state */ 322 | strm.zalloc = Z_NULL; 323 | strm.zfree = Z_NULL; 324 | strm.opaque = Z_NULL; 325 | strm.avail_in = 0; 326 | strm.next_in = Z_NULL; 327 | ret = inflateInit2(&strm,-MAX_WBITS); 328 | if (ret != Z_OK) 329 | return ret; 330 | 331 | /* decompress until deflate stream ends or end of file */ 332 | strm.avail_in = _inSize;//fread(in, 1, CHUNK, source); 333 | strm.next_in = _inBlock; 334 | /* run inflate() on input until output buffer not full */ 335 | do { 336 | strm.avail_out = CHUNK; 337 | strm.next_out = out; 338 | ret = inflate(&strm, Z_NO_FLUSH); 339 | ASSERT(ret != Z_STREAM_ERROR); /* state not clobbered */ 340 | switch (ret) { 341 | case Z_NEED_DICT: 342 | ret = Z_DATA_ERROR; /* and fall through */ 343 | case Z_DATA_ERROR: 344 | case Z_MEM_ERROR: 345 | (void)inflateEnd(&strm); 346 | return ret; 347 | } 348 | have = CHUNK - strm.avail_out; 349 | if(!_writer.Write(out, have)){ 350 | (void)inflateEnd(&strm); 351 | return Z_ERRNO; 352 | } 353 | } while (strm.avail_out == 0); 354 | 355 | 356 | 357 | /* clean up and return */ 358 | (void)inflateEnd(&strm); 359 | return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; 360 | } 361 | 362 | 363 | 364 | #if 0 365 | int unzip(unsigned char * pDest, unsigned long * ulDestLen, unsigned char * pSource, int iSourceLen) 366 | { 367 | int ret = 0; 368 | unsigned int uiUncompressedBytes = 0; // Number of uncompressed bytes returned from inflate() function 369 | unsigned char * pPositionDestBuffer = pDest; // Current position in dest buffer 370 | unsigned char * pLastSource = &pSource[iSourceLen]; // Last position in source buffer 371 | z_stream strm; 372 | 373 | // Skip over local file header 374 | SLocalFileHeader * header = (SLocalFileHeader *) pSource; 375 | pSource += sizeof(SLocalFileHeader) + header->sFileNameLen + header->sExtraFieldLen; 376 | 377 | 378 | // We should now be at the beginning of the stream data 379 | /* allocate inflate state */ 380 | strm.zalloc = Z_NULL; 381 | strm.zfree = Z_NULL; 382 | strm.opaque = Z_NULL; 383 | strm.avail_in = 0; 384 | strm.next_in = Z_NULL; 385 | ret = inflateInit2(&strm, -MAX_WBITS); 386 | if (ret != Z_OK) 387 | { 388 | return -1; 389 | } 390 | 391 | // Uncompress the data 392 | strm.avail_in = header->iCompressedSize; //iSourceLen; 393 | strm.next_in = pSource; 394 | 395 | do { 396 | strm.avail_out = *ulDestLen; 397 | strm.next_out = pPositionDestBuffer; 398 | ret = inflate(&strm, Z_NO_FLUSH); 399 | assert(ret != Z_STREAM_ERROR); /* state not clobbered */ 400 | 401 | switch (ret) { 402 | case Z_NEED_DICT: 403 | ret = Z_DATA_ERROR; /* and fall through */ 404 | case Z_DATA_ERROR: 405 | case Z_MEM_ERROR: 406 | (void)inflateEnd(&strm); 407 | return -2; 408 | } 409 | uiUncompressedBytes = *ulDestLen - strm.avail_out; 410 | *ulDestLen -= uiUncompressedBytes; // ulDestSize holds number of free/empty bytes in buffer 411 | pPositionDestBuffer += uiUncompressedBytes; 412 | } while (strm.avail_out == 0); 413 | 414 | // Close the decompression stream 415 | inflateEnd(&strm); 416 | ASSERT(ret == Z_STREAM_END); 417 | 418 | return 0; 419 | } 420 | #endif 421 | void CXlogDecodeDlg::OnBnClickedBtnDecode() 422 | { 423 | m_bSkipErrorBlock = m_chk_skip_error_block.GetCheck(); 424 | // decode(); 425 | 426 | XlogFileScan scaner; 427 | for(int xx = 0;xx < m_listFile.GetCount();xx++){ 428 | int count = scaner.scan(m_listFile.GetAt(xx), m_chk_recurse.GetCheck()); 429 | if(count > 0){ 430 | CStringArray &outXlogs = scaner.getList(); 431 | TRACE("=======GET file: %d\r\n", outXlogs.GetCount()); 432 | for(int jj = 0;jj < outXlogs.GetCount();jj++){ 433 | OutputDebugString(outXlogs.GetAt(jj)+L"\r\nnew FILE:"); 434 | CString newFile; 435 | XlogFileScan::genDecodeFileName(outXlogs.GetAt(jj), newFile); 436 | OutputDebugString(newFile+L"\r\n"); 437 | decodeFile(outXlogs.GetAt(jj), newFile); 438 | } 439 | } 440 | } 441 | MessageBox(L"完成"); 442 | } 443 | 444 | -------------------------------------------------------------------------------- /XlogDecode/XlogDecodeDlg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/XlogDecodeDlg.h -------------------------------------------------------------------------------- /XlogDecode/XlogDef.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #pragma pack (push,1) 5 | typedef struct _xlogHead{ 6 | byte start; 7 | UINT16 seq; 8 | byte beginHour; 9 | byte endHour; 10 | UINT32 length; 11 | byte crypt[64]; 12 | 13 | }xlogHead; 14 | #pragma pack(pop) 15 | 16 | 17 | uint32_t GetHeaderLen() { 18 | return sizeof(char) * 3 + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(char) * 64; 19 | } 20 | 21 | uint32_t GetTailerLen() { 22 | return sizeof(kMagicEnd); 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /XlogDecode/XlogFileScan.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/XlogFileScan.cpp -------------------------------------------------------------------------------- /XlogDecode/XlogFileScan.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cfilescan.h" 3 | 4 | 5 | class XlogFileScan : public CFileScan{ 6 | private: 7 | BOOL isXlogFile(CString pathname); 8 | BOOL isDirectory(LPCWSTR pathname); 9 | protected: 10 | virtual void onFile(LPCWSTR dir, LPCWSTR fileName); 11 | virtual void onDirectory(LPCWSTR dir, LPCWSTR dirName); 12 | 13 | CStringArray m_fileXlogs; 14 | CString m_scanPath; 15 | public: 16 | XlogFileScan(LPCWSTR path = NULL); 17 | ~XlogFileScan(); 18 | 19 | int scan(CString path, BOOL recurseSubDir); 20 | CStringArray & getList(){return m_fileXlogs;} 21 | 22 | static BOOL genDecodeFileName(const CString &in, CString &out); 23 | 24 | }; -------------------------------------------------------------------------------- /XlogDecode/def.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef UINT32 uint32_t; 4 | typedef UINT16 uint16_t; 5 | #ifndef byte 6 | typedef unsigned char byte; 7 | #endif 8 | 9 | static const char kMagicSyncStart = '\x06'; 10 | static const char kMagicSyncNoCryptStart ='\x08'; 11 | static const char kMagicAsyncStart ='\x07'; 12 | static const char kMagicAsyncNoCryptStart ='\x09'; 13 | 14 | static const char kMagicEnd = '\0'; -------------------------------------------------------------------------------- /XlogDecode/misc.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "misc.h" 3 | 4 | int GetAppPath(TCHAR *outPath, UINT nLenth)//with \ at the end of the path 5 | { 6 | if(!outPath || !nLenth){ 7 | return 0; 8 | } 9 | if( 0 == GetModuleFileName(NULL , outPath , nLenth) ){ 10 | return 0; 11 | } 12 | int nLen = 0; 13 | for(nLen = (int)wcslen(outPath) - 1 ; nLen >= 0 ;nLen-- ){ 14 | if(outPath[nLen] == '\\'){ 15 | nLen++;//include "\" here 16 | outPath[nLen] = '\0'; 17 | break; 18 | } 19 | } 20 | return nLen; 21 | } 22 | 23 | 24 | /************************************************ 25 | CharToUnicode 26 | -pszOutBuffer : output buffer 27 | +nOutBufferSize : length of the buffer in TCHAR 28 | +pszInBuffer : input buffer(currently point to the UTF-8 bytes) 29 | +uCodePage : MultiByteToWideChar refer to this codepage 30 | @return : bytes converted,not character 31 | ************************************************/ 32 | int CharToUnicode(TCHAR *pszOutBuffer, int nOutBufferSize, const char *pszInBuffer , UINT uCodePage) 33 | { 34 | // CODE_PAGE_CHS 936 35 | // CODE_PAGE_CHT 950 36 | int nLen = MultiByteToWideChar(uCodePage, 0, pszInBuffer, -1, NULL, 0); 37 | if(nOutBufferSize < nLen)return 0; 38 | 39 | return MultiByteToWideChar(uCodePage, 0, pszInBuffer, -1, pszOutBuffer, nLen);; 40 | } 41 | 42 | int UnicodeToChar(const TCHAR *pszInBuffer, char *outBuffer, int nOutBufferSize, UINT uCodePage)//CP_ACP 43 | { 44 | int nLen = WideCharToMultiByte(uCodePage, 0, pszInBuffer, -1, NULL, 0, NULL, NULL); 45 | if(nOutBufferSize < nLen)return 0; 46 | 47 | return WideCharToMultiByte (uCodePage, 0,pszInBuffer, -1,outBuffer , nLen, NULL,NULL);; 48 | } 49 | 50 | double sum(char *num0, char *num1) 51 | { 52 | double val = 0.0; 53 | if(num0 ==NULL || num1 == NULL)return val; 54 | 55 | val = atof(num0) + atof(num1); 56 | 57 | return val; 58 | } 59 | 60 | BOOL isDirectory(LPCWSTR pathname){ 61 | DWORD flag = ::GetFileAttributes(pathname); 62 | return (0xffffffff != flag && FILE_ATTRIBUTE_DIRECTORY == flag); 63 | } -------------------------------------------------------------------------------- /XlogDecode/misc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * GetAppPath: get current application path 5 | * with \ at the end of the path 6 | * outPath: The path will be filled if exist 7 | * nLenth:indicate the outPath length 8 | */ 9 | int GetAppPath(TCHAR *outPath, UINT nLenth); 10 | 11 | /************************************************ 12 | CharToUnicode 13 | -pszOutBuffer : output buffer 14 | +nOutBufferSize : length of the buffer in TCHAR 15 | +pszInBuffer : input buffer(currently point to the UTF-8 bytes) 16 | +uCodePage : MultiByteToWideChar refer to this codepage 17 | @return : bytes converted,not character 18 | ************************************************/ 19 | int CharToUnicode(TCHAR *pszOutBuffer, 20 | int nOutBufferSize, 21 | const char *pszInBuffer , 22 | UINT uCodePage); 23 | 24 | int UnicodeToChar(const TCHAR *pszInBuffer, 25 | char *outBuffer, 26 | int nOutBufferSize, 27 | UINT uCodePage);//CP_ACP 28 | 29 | double sum(char *num0, char *num1); 30 | 31 | #define IS_EMPTY_STR(x) ((x == NULL?)TRUE:(strcmp(x, "") == 0)) 32 | #define NOT_EMPTY_STR(x) (!IS_EMPTY_STR(x)) 33 | 34 | BOOL isDirectory(LPCWSTR pathname); -------------------------------------------------------------------------------- /XlogDecode/res/XlogDecode.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/res/XlogDecode.ico -------------------------------------------------------------------------------- /XlogDecode/res/XlogDecode.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/res/XlogDecode.rc2 -------------------------------------------------------------------------------- /XlogDecode/res/XlogDecode2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/res/XlogDecode2.ico -------------------------------------------------------------------------------- /XlogDecode/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by XlogDecode.rc 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_XLOGDECODE_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BTN_DECODE 1000 11 | #define IDC_CHECK_RECURSE 1001 12 | #define IDC_EDIT_PATH 1002 13 | #define IDC_CHECK_RECURSE2 1003 14 | #define IDC_CHECK_SKIP_ERROR_BLOCK 1003 15 | 16 | // Next default values for new objects 17 | // 18 | #ifdef APSTUDIO_INVOKED 19 | #ifndef APSTUDIO_READONLY_SYMBOLS 20 | #define _APS_NEXT_RESOURCE_VALUE 129 21 | #define _APS_NEXT_COMMAND_VALUE 32771 22 | #define _APS_NEXT_CONTROL_VALUE 1003 23 | #define _APS_NEXT_SYMED_VALUE 101 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /XlogDecode/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/stdafx.cpp -------------------------------------------------------------------------------- /XlogDecode/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/stdafx.h -------------------------------------------------------------------------------- /XlogDecode/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/staneychan/XlogDecode/8e75b622e75763ab2107547d101a692182ca96eb/XlogDecode/targetver.h -------------------------------------------------------------------------------- /XlogDecode/zlib/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2011 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | 10 | #define local static 11 | 12 | local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); 13 | 14 | #define BASE 65521 /* largest prime smaller than 65536 */ 15 | #define NMAX 5552 16 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 17 | 18 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 19 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 20 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 21 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 22 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 23 | 24 | /* use NO_DIVIDE if your processor does not do division in hardware -- 25 | try it both ways to see which is faster */ 26 | #ifdef NO_DIVIDE 27 | /* note that this assumes BASE is 65521, where 65536 % 65521 == 15 28 | (thank you to John Reiser for pointing this out) */ 29 | # define CHOP(a) \ 30 | do { \ 31 | unsigned long tmp = a >> 16; \ 32 | a &= 0xffffUL; \ 33 | a += (tmp << 4) - tmp; \ 34 | } while (0) 35 | # define MOD28(a) \ 36 | do { \ 37 | CHOP(a); \ 38 | if (a >= BASE) a -= BASE; \ 39 | } while (0) 40 | # define MOD(a) \ 41 | do { \ 42 | CHOP(a); \ 43 | MOD28(a); \ 44 | } while (0) 45 | # define MOD63(a) \ 46 | do { /* this assumes a is not negative */ \ 47 | z_off64_t tmp = a >> 32; \ 48 | a &= 0xffffffffL; \ 49 | a += (tmp << 8) - (tmp << 5) + tmp; \ 50 | tmp = a >> 16; \ 51 | a &= 0xffffL; \ 52 | a += (tmp << 4) - tmp; \ 53 | tmp = a >> 16; \ 54 | a &= 0xffffL; \ 55 | a += (tmp << 4) - tmp; \ 56 | if (a >= BASE) a -= BASE; \ 57 | } while (0) 58 | #else 59 | # define MOD(a) a %= BASE 60 | # define MOD28(a) a %= BASE 61 | # define MOD63(a) a %= BASE 62 | #endif 63 | 64 | /* ========================================================================= */ 65 | uLong ZEXPORT adler32(adler, buf, len) 66 | uLong adler; 67 | const Bytef *buf; 68 | uInt len; 69 | { 70 | unsigned long sum2; 71 | unsigned n; 72 | 73 | /* split Adler-32 into component sums */ 74 | sum2 = (adler >> 16) & 0xffff; 75 | adler &= 0xffff; 76 | 77 | /* in case user likes doing a byte at a time, keep it fast */ 78 | if (len == 1) { 79 | adler += buf[0]; 80 | if (adler >= BASE) 81 | adler -= BASE; 82 | sum2 += adler; 83 | if (sum2 >= BASE) 84 | sum2 -= BASE; 85 | return adler | (sum2 << 16); 86 | } 87 | 88 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 89 | if (buf == Z_NULL) 90 | return 1L; 91 | 92 | /* in case short lengths are provided, keep it somewhat fast */ 93 | if (len < 16) { 94 | while (len--) { 95 | adler += *buf++; 96 | sum2 += adler; 97 | } 98 | if (adler >= BASE) 99 | adler -= BASE; 100 | MOD28(sum2); /* only added so many BASE's */ 101 | return adler | (sum2 << 16); 102 | } 103 | 104 | /* do length NMAX blocks -- requires just one modulo operation */ 105 | while (len >= NMAX) { 106 | len -= NMAX; 107 | n = NMAX / 16; /* NMAX is divisible by 16 */ 108 | do { 109 | DO16(buf); /* 16 sums unrolled */ 110 | buf += 16; 111 | } while (--n); 112 | MOD(adler); 113 | MOD(sum2); 114 | } 115 | 116 | /* do remaining bytes (less than NMAX, still just one modulo) */ 117 | if (len) { /* avoid modulos if none remaining */ 118 | while (len >= 16) { 119 | len -= 16; 120 | DO16(buf); 121 | buf += 16; 122 | } 123 | while (len--) { 124 | adler += *buf++; 125 | sum2 += adler; 126 | } 127 | MOD(adler); 128 | MOD(sum2); 129 | } 130 | 131 | /* return recombined sums */ 132 | return adler | (sum2 << 16); 133 | } 134 | 135 | /* ========================================================================= */ 136 | local uLong adler32_combine_(adler1, adler2, len2) 137 | uLong adler1; 138 | uLong adler2; 139 | z_off64_t len2; 140 | { 141 | unsigned long sum1; 142 | unsigned long sum2; 143 | unsigned rem; 144 | 145 | /* for negative len, return invalid adler32 as a clue for debugging */ 146 | if (len2 < 0) 147 | return 0xffffffffUL; 148 | 149 | /* the derivation of this formula is left as an exercise for the reader */ 150 | MOD63(len2); /* assumes len2 >= 0 */ 151 | rem = (unsigned)len2; 152 | sum1 = adler1 & 0xffff; 153 | sum2 = rem * sum1; 154 | MOD(sum2); 155 | sum1 += (adler2 & 0xffff) + BASE - 1; 156 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 157 | if (sum1 >= BASE) sum1 -= BASE; 158 | if (sum1 >= BASE) sum1 -= BASE; 159 | if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); 160 | if (sum2 >= BASE) sum2 -= BASE; 161 | return sum1 | (sum2 << 16); 162 | } 163 | 164 | /* ========================================================================= */ 165 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 166 | uLong adler1; 167 | uLong adler2; 168 | z_off_t len2; 169 | { 170 | return adler32_combine_(adler1, adler2, len2); 171 | } 172 | 173 | uLong ZEXPORT adler32_combine64(adler1, adler2, len2) 174 | uLong adler1; 175 | uLong adler2; 176 | z_off64_t len2; 177 | { 178 | return adler32_combine_(adler1, adler2, len2); 179 | } 180 | -------------------------------------------------------------------------------- /XlogDecode/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 = (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 | -------------------------------------------------------------------------------- /XlogDecode/zlib/crc32.c: -------------------------------------------------------------------------------- 1 | /* crc32.c -- compute the CRC-32 of a data stream 2 | * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | * 5 | * Thanks to Rodney Brown for his contribution of faster 6 | * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing 7 | * tables for updating the shift register in one step with three exclusive-ors 8 | * instead of four steps with four exclusive-ors. This results in about a 9 | * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. 10 | */ 11 | 12 | /* @(#) $Id$ */ 13 | 14 | /* 15 | Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore 16 | protection on the static variables used to control the first-use generation 17 | of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should 18 | first call get_crc_table() to initialize the tables before allowing more than 19 | one thread to use crc32(). 20 | 21 | DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. 22 | */ 23 | 24 | #ifdef MAKECRCH 25 | # include 26 | # ifndef DYNAMIC_CRC_TABLE 27 | # define DYNAMIC_CRC_TABLE 28 | # endif /* !DYNAMIC_CRC_TABLE */ 29 | #endif /* MAKECRCH */ 30 | 31 | #include "zutil.h" /* for STDC and FAR definitions */ 32 | 33 | #define local static 34 | 35 | /* Definitions for doing the crc four data bytes at a time. */ 36 | #if !defined(NOBYFOUR) && defined(Z_U4) 37 | # define BYFOUR 38 | #endif 39 | #ifdef BYFOUR 40 | local unsigned long crc32_little OF((unsigned long, 41 | const unsigned char FAR *, unsigned)); 42 | local unsigned long crc32_big OF((unsigned long, 43 | const unsigned char FAR *, unsigned)); 44 | # define TBLS 8 45 | #else 46 | # define TBLS 1 47 | #endif /* BYFOUR */ 48 | 49 | /* Local functions for crc concatenation */ 50 | local unsigned long gf2_matrix_times OF((unsigned long *mat, 51 | unsigned long vec)); 52 | local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); 53 | local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); 54 | 55 | 56 | #ifdef DYNAMIC_CRC_TABLE 57 | 58 | local volatile int crc_table_empty = 1; 59 | local z_crc_t FAR crc_table[TBLS][256]; 60 | local void make_crc_table OF((void)); 61 | #ifdef MAKECRCH 62 | local void write_table OF((FILE *, const z_crc_t FAR *)); 63 | #endif /* MAKECRCH */ 64 | /* 65 | Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: 66 | x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. 67 | 68 | Polynomials over GF(2) are represented in binary, one bit per coefficient, 69 | with the lowest powers in the most significant bit. Then adding polynomials 70 | is just exclusive-or, and multiplying a polynomial by x is a right shift by 71 | one. If we call the above polynomial p, and represent a byte as the 72 | polynomial q, also with the lowest power in the most significant bit (so the 73 | byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, 74 | where a mod b means the remainder after dividing a by b. 75 | 76 | This calculation is done using the shift-register method of multiplying and 77 | taking the remainder. The register is initialized to zero, and for each 78 | incoming bit, x^32 is added mod p to the register if the bit is a one (where 79 | x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by 80 | x (which is shifting right by one and adding x^32 mod p if the bit shifted 81 | out is a one). We start with the highest power (least significant bit) of 82 | q and repeat for all eight bits of q. 83 | 84 | The first table is simply the CRC of all possible eight bit values. This is 85 | all the information needed to generate CRCs on data a byte at a time for all 86 | combinations of CRC register values and incoming bytes. The remaining tables 87 | allow for word-at-a-time CRC calculation for both big-endian and little- 88 | endian machines, where a word is four bytes. 89 | */ 90 | local void make_crc_table() 91 | { 92 | z_crc_t c; 93 | int n, k; 94 | z_crc_t poly; /* polynomial exclusive-or pattern */ 95 | /* terms of polynomial defining this crc (except x^32): */ 96 | static volatile int first = 1; /* flag to limit concurrent making */ 97 | static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 98 | 99 | /* See if another task is already doing this (not thread-safe, but better 100 | than nothing -- significantly reduces duration of vulnerability in 101 | case the advice about DYNAMIC_CRC_TABLE is ignored) */ 102 | if (first) { 103 | first = 0; 104 | 105 | /* make exclusive-or pattern from polynomial (0xedb88320UL) */ 106 | poly = 0; 107 | for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) 108 | poly |= (z_crc_t)1 << (31 - p[n]); 109 | 110 | /* generate a crc for every 8-bit value */ 111 | for (n = 0; n < 256; n++) { 112 | c = (z_crc_t)n; 113 | for (k = 0; k < 8; k++) 114 | c = c & 1 ? poly ^ (c >> 1) : c >> 1; 115 | crc_table[0][n] = c; 116 | } 117 | 118 | #ifdef BYFOUR 119 | /* generate crc for each value followed by one, two, and three zeros, 120 | and then the byte reversal of those as well as the first table */ 121 | for (n = 0; n < 256; n++) { 122 | c = crc_table[0][n]; 123 | crc_table[4][n] = ZSWAP32(c); 124 | for (k = 1; k < 4; k++) { 125 | c = crc_table[0][c & 0xff] ^ (c >> 8); 126 | crc_table[k][n] = c; 127 | crc_table[k + 4][n] = ZSWAP32(c); 128 | } 129 | } 130 | #endif /* BYFOUR */ 131 | 132 | crc_table_empty = 0; 133 | } 134 | else { /* not first */ 135 | /* wait for the other guy to finish (not efficient, but rare) */ 136 | while (crc_table_empty) 137 | ; 138 | } 139 | 140 | #ifdef MAKECRCH 141 | /* write out CRC tables to crc32.h */ 142 | { 143 | FILE *out; 144 | 145 | out = fopen("crc32.h", "w"); 146 | if (out == NULL) return; 147 | fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); 148 | fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); 149 | fprintf(out, "local const z_crc_t FAR "); 150 | fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); 151 | write_table(out, crc_table[0]); 152 | # ifdef BYFOUR 153 | fprintf(out, "#ifdef BYFOUR\n"); 154 | for (k = 1; k < 8; k++) { 155 | fprintf(out, " },\n {\n"); 156 | write_table(out, crc_table[k]); 157 | } 158 | fprintf(out, "#endif\n"); 159 | # endif /* BYFOUR */ 160 | fprintf(out, " }\n};\n"); 161 | fclose(out); 162 | } 163 | #endif /* MAKECRCH */ 164 | } 165 | 166 | #ifdef MAKECRCH 167 | local void write_table(out, table) 168 | FILE *out; 169 | const z_crc_t FAR *table; 170 | { 171 | int n; 172 | 173 | for (n = 0; n < 256; n++) 174 | fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", 175 | (unsigned long)(table[n]), 176 | n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); 177 | } 178 | #endif /* MAKECRCH */ 179 | 180 | #else /* !DYNAMIC_CRC_TABLE */ 181 | /* ======================================================================== 182 | * Tables of CRC-32s of all single-byte values, made by make_crc_table(). 183 | */ 184 | #include "crc32.h" 185 | #endif /* DYNAMIC_CRC_TABLE */ 186 | 187 | /* ========================================================================= 188 | * This function can be used by asm versions of crc32() 189 | */ 190 | const z_crc_t FAR * ZEXPORT get_crc_table() 191 | { 192 | #ifdef DYNAMIC_CRC_TABLE 193 | if (crc_table_empty) 194 | make_crc_table(); 195 | #endif /* DYNAMIC_CRC_TABLE */ 196 | return (const z_crc_t FAR *)crc_table; 197 | } 198 | 199 | /* ========================================================================= */ 200 | #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) 201 | #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 202 | 203 | /* ========================================================================= */ 204 | unsigned long ZEXPORT crc32(crc, buf, len) 205 | unsigned long crc; 206 | const unsigned char FAR *buf; 207 | uInt len; 208 | { 209 | if (buf == Z_NULL) return 0UL; 210 | 211 | #ifdef DYNAMIC_CRC_TABLE 212 | if (crc_table_empty) 213 | make_crc_table(); 214 | #endif /* DYNAMIC_CRC_TABLE */ 215 | 216 | #ifdef BYFOUR 217 | if (sizeof(void *) == sizeof(ptrdiff_t)) { 218 | z_crc_t endian; 219 | 220 | endian = 1; 221 | if (*((unsigned char *)(&endian))) 222 | return crc32_little(crc, buf, len); 223 | else 224 | return crc32_big(crc, buf, len); 225 | } 226 | #endif /* BYFOUR */ 227 | crc = crc ^ 0xffffffffUL; 228 | while (len >= 8) { 229 | DO8; 230 | len -= 8; 231 | } 232 | if (len) do { 233 | DO1; 234 | } while (--len); 235 | return crc ^ 0xffffffffUL; 236 | } 237 | 238 | #ifdef BYFOUR 239 | 240 | /* ========================================================================= */ 241 | #define DOLIT4 c ^= *buf4++; \ 242 | c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ 243 | crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] 244 | #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 245 | 246 | /* ========================================================================= */ 247 | local unsigned long crc32_little(crc, buf, len) 248 | unsigned long crc; 249 | const unsigned char FAR *buf; 250 | unsigned len; 251 | { 252 | register z_crc_t c; 253 | register const z_crc_t FAR *buf4; 254 | 255 | c = (z_crc_t)crc; 256 | c = ~c; 257 | while (len && ((ptrdiff_t)buf & 3)) { 258 | c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 259 | len--; 260 | } 261 | 262 | buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 263 | while (len >= 32) { 264 | DOLIT32; 265 | len -= 32; 266 | } 267 | while (len >= 4) { 268 | DOLIT4; 269 | len -= 4; 270 | } 271 | buf = (const unsigned char FAR *)buf4; 272 | 273 | if (len) do { 274 | c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 275 | } while (--len); 276 | c = ~c; 277 | return (unsigned long)c; 278 | } 279 | 280 | /* ========================================================================= */ 281 | #define DOBIG4 c ^= *++buf4; \ 282 | c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ 283 | crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] 284 | #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 285 | 286 | /* ========================================================================= */ 287 | local unsigned long crc32_big(crc, buf, len) 288 | unsigned long crc; 289 | const unsigned char FAR *buf; 290 | unsigned len; 291 | { 292 | register z_crc_t c; 293 | register const z_crc_t FAR *buf4; 294 | 295 | c = ZSWAP32((z_crc_t)crc); 296 | c = ~c; 297 | while (len && ((ptrdiff_t)buf & 3)) { 298 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 299 | len--; 300 | } 301 | 302 | buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 303 | buf4--; 304 | while (len >= 32) { 305 | DOBIG32; 306 | len -= 32; 307 | } 308 | while (len >= 4) { 309 | DOBIG4; 310 | len -= 4; 311 | } 312 | buf4++; 313 | buf = (const unsigned char FAR *)buf4; 314 | 315 | if (len) do { 316 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 317 | } while (--len); 318 | c = ~c; 319 | return (unsigned long)(ZSWAP32(c)); 320 | } 321 | 322 | #endif /* BYFOUR */ 323 | 324 | #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ 325 | 326 | /* ========================================================================= */ 327 | local unsigned long gf2_matrix_times(mat, vec) 328 | unsigned long *mat; 329 | unsigned long vec; 330 | { 331 | unsigned long sum; 332 | 333 | sum = 0; 334 | while (vec) { 335 | if (vec & 1) 336 | sum ^= *mat; 337 | vec >>= 1; 338 | mat++; 339 | } 340 | return sum; 341 | } 342 | 343 | /* ========================================================================= */ 344 | local void gf2_matrix_square(square, mat) 345 | unsigned long *square; 346 | unsigned long *mat; 347 | { 348 | int n; 349 | 350 | for (n = 0; n < GF2_DIM; n++) 351 | square[n] = gf2_matrix_times(mat, mat[n]); 352 | } 353 | 354 | /* ========================================================================= */ 355 | local uLong crc32_combine_(crc1, crc2, len2) 356 | uLong crc1; 357 | uLong crc2; 358 | z_off64_t len2; 359 | { 360 | int n; 361 | unsigned long row; 362 | unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ 363 | unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ 364 | 365 | /* degenerate case (also disallow negative lengths) */ 366 | if (len2 <= 0) 367 | return crc1; 368 | 369 | /* put operator for one zero bit in odd */ 370 | odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ 371 | row = 1; 372 | for (n = 1; n < GF2_DIM; n++) { 373 | odd[n] = row; 374 | row <<= 1; 375 | } 376 | 377 | /* put operator for two zero bits in even */ 378 | gf2_matrix_square(even, odd); 379 | 380 | /* put operator for four zero bits in odd */ 381 | gf2_matrix_square(odd, even); 382 | 383 | /* apply len2 zeros to crc1 (first square will put the operator for one 384 | zero byte, eight zero bits, in even) */ 385 | do { 386 | /* apply zeros operator for this bit of len2 */ 387 | gf2_matrix_square(even, odd); 388 | if (len2 & 1) 389 | crc1 = gf2_matrix_times(even, crc1); 390 | len2 >>= 1; 391 | 392 | /* if no more bits set, then done */ 393 | if (len2 == 0) 394 | break; 395 | 396 | /* another iteration of the loop with odd and even swapped */ 397 | gf2_matrix_square(odd, even); 398 | if (len2 & 1) 399 | crc1 = gf2_matrix_times(odd, crc1); 400 | len2 >>= 1; 401 | 402 | /* if no more bits set, then done */ 403 | } while (len2 != 0); 404 | 405 | /* return combined crc */ 406 | crc1 ^= crc2; 407 | return crc1; 408 | } 409 | 410 | /* ========================================================================= */ 411 | uLong ZEXPORT crc32_combine(crc1, crc2, len2) 412 | uLong crc1; 413 | uLong crc2; 414 | z_off_t len2; 415 | { 416 | return crc32_combine_(crc1, crc2, len2); 417 | } 418 | 419 | uLong ZEXPORT crc32_combine64(crc1, crc2, len2) 420 | uLong crc1; 421 | uLong crc2; 422 | z_off64_t len2; 423 | { 424 | return crc32_combine_(crc1, crc2, len2); 425 | } 426 | -------------------------------------------------------------------------------- /XlogDecode/zlib/deflate.h: -------------------------------------------------------------------------------- 1 | /* deflate.h -- internal compression state 2 | * Copyright (C) 1995-2012 Jean-loup Gailly 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 | /* @(#) $Id$ */ 12 | 13 | #ifndef DEFLATE_H 14 | #define DEFLATE_H 15 | 16 | #include "zutil.h" 17 | 18 | /* define NO_GZIP when compiling if you want to disable gzip header and 19 | trailer creation by deflate(). NO_GZIP would be used to avoid linking in 20 | the crc code when it is not needed. For shared libraries, gzip encoding 21 | should be left enabled. */ 22 | #ifndef NO_GZIP 23 | # define GZIP 24 | #endif 25 | 26 | /* =========================================================================== 27 | * Internal compression state. 28 | */ 29 | 30 | #define LENGTH_CODES 29 31 | /* number of length codes, not counting the special END_BLOCK code */ 32 | 33 | #define LITERALS 256 34 | /* number of literal bytes 0..255 */ 35 | 36 | #define L_CODES (LITERALS+1+LENGTH_CODES) 37 | /* number of Literal or Length codes, including the END_BLOCK code */ 38 | 39 | #define D_CODES 30 40 | /* number of distance codes */ 41 | 42 | #define BL_CODES 19 43 | /* number of codes used to transfer the bit lengths */ 44 | 45 | #define HEAP_SIZE (2*L_CODES+1) 46 | /* maximum heap size */ 47 | 48 | #define MAX_BITS 15 49 | /* All codes must not exceed MAX_BITS bits */ 50 | 51 | #define Buf_size 16 52 | /* size of bit buffer in bi_buf */ 53 | 54 | #define INIT_STATE 42 55 | #define EXTRA_STATE 69 56 | #define NAME_STATE 73 57 | #define COMMENT_STATE 91 58 | #define HCRC_STATE 103 59 | #define BUSY_STATE 113 60 | #define FINISH_STATE 666 61 | /* Stream status */ 62 | 63 | 64 | /* Data structure describing a single value and its code string. */ 65 | typedef struct ct_data_s { 66 | union { 67 | ush freq; /* frequency count */ 68 | ush code; /* bit string */ 69 | } fc; 70 | union { 71 | ush dad; /* father node in Huffman tree */ 72 | ush len; /* length of bit string */ 73 | } dl; 74 | } FAR ct_data; 75 | 76 | #define Freq fc.freq 77 | #define Code fc.code 78 | #define Dad dl.dad 79 | #define Len dl.len 80 | 81 | typedef struct static_tree_desc_s static_tree_desc; 82 | 83 | typedef struct tree_desc_s { 84 | ct_data *dyn_tree; /* the dynamic tree */ 85 | int max_code; /* largest code with non zero frequency */ 86 | static_tree_desc *stat_desc; /* the corresponding static tree */ 87 | } FAR tree_desc; 88 | 89 | typedef ush Pos; 90 | typedef Pos FAR Posf; 91 | typedef unsigned IPos; 92 | 93 | /* A Pos is an index in the character window. We use short instead of int to 94 | * save space in the various tables. IPos is used only for parameter passing. 95 | */ 96 | 97 | typedef struct internal_state { 98 | z_streamp strm; /* pointer back to this zlib stream */ 99 | int status; /* as the name implies */ 100 | Bytef *pending_buf; /* output still pending */ 101 | ulg pending_buf_size; /* size of pending_buf */ 102 | Bytef *pending_out; /* next pending byte to output to the stream */ 103 | uInt pending; /* nb of bytes in the pending buffer */ 104 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 105 | gz_headerp gzhead; /* gzip header information to write */ 106 | uInt gzindex; /* where in extra, name, or comment */ 107 | Byte method; /* STORED (for zip only) or DEFLATED */ 108 | int last_flush; /* value of flush param for previous deflate call */ 109 | 110 | /* used by deflate.c: */ 111 | 112 | uInt w_size; /* LZ77 window size (32K by default) */ 113 | uInt w_bits; /* log2(w_size) (8..16) */ 114 | uInt w_mask; /* w_size - 1 */ 115 | 116 | Bytef *window; 117 | /* Sliding window. Input bytes are read into the second half of the window, 118 | * and move to the first half later to keep a dictionary of at least wSize 119 | * bytes. With this organization, matches are limited to a distance of 120 | * wSize-MAX_MATCH bytes, but this ensures that IO is always 121 | * performed with a length multiple of the block size. Also, it limits 122 | * the window size to 64K, which is quite useful on MSDOS. 123 | * To do: use the user input buffer as sliding window. 124 | */ 125 | 126 | ulg window_size; 127 | /* Actual size of window: 2*wSize, except when the user input buffer 128 | * is directly used as sliding window. 129 | */ 130 | 131 | Posf *prev; 132 | /* Link to older string with same hash index. To limit the size of this 133 | * array to 64K, this link is maintained only for the last 32K strings. 134 | * An index in this array is thus a window index modulo 32K. 135 | */ 136 | 137 | Posf *head; /* Heads of the hash chains or NIL. */ 138 | 139 | uInt ins_h; /* hash index of string to be inserted */ 140 | uInt hash_size; /* number of elements in hash table */ 141 | uInt hash_bits; /* log2(hash_size) */ 142 | uInt hash_mask; /* hash_size-1 */ 143 | 144 | uInt hash_shift; 145 | /* Number of bits by which ins_h must be shifted at each input 146 | * step. It must be such that after MIN_MATCH steps, the oldest 147 | * byte no longer takes part in the hash key, that is: 148 | * hash_shift * MIN_MATCH >= hash_bits 149 | */ 150 | 151 | long block_start; 152 | /* Window position at the beginning of the current output block. Gets 153 | * negative when the window is moved backwards. 154 | */ 155 | 156 | uInt match_length; /* length of best match */ 157 | IPos prev_match; /* previous match */ 158 | int match_available; /* set if previous match exists */ 159 | uInt strstart; /* start of string to insert */ 160 | uInt match_start; /* start of matching string */ 161 | uInt lookahead; /* number of valid bytes ahead in window */ 162 | 163 | uInt prev_length; 164 | /* Length of the best match at previous step. Matches not greater than this 165 | * are discarded. This is used in the lazy match evaluation. 166 | */ 167 | 168 | uInt max_chain_length; 169 | /* To speed up deflation, hash chains are never searched beyond this 170 | * length. A higher limit improves compression ratio but degrades the 171 | * speed. 172 | */ 173 | 174 | uInt max_lazy_match; 175 | /* Attempt to find a better match only when the current match is strictly 176 | * smaller than this value. This mechanism is used only for compression 177 | * levels >= 4. 178 | */ 179 | # define max_insert_length max_lazy_match 180 | /* Insert new strings in the hash table only if the match length is not 181 | * greater than this length. This saves time but degrades compression. 182 | * max_insert_length is used only for compression levels <= 3. 183 | */ 184 | 185 | int level; /* compression level (1..9) */ 186 | int strategy; /* favor or force Huffman coding*/ 187 | 188 | uInt good_match; 189 | /* Use a faster search when the previous match is longer than this */ 190 | 191 | int nice_match; /* Stop searching when current match exceeds this */ 192 | 193 | /* used by trees.c: */ 194 | /* Didn't use ct_data typedef below to suppress compiler warning */ 195 | struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ 196 | struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ 197 | struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ 198 | 199 | struct tree_desc_s l_desc; /* desc. for literal tree */ 200 | struct tree_desc_s d_desc; /* desc. for distance tree */ 201 | struct tree_desc_s bl_desc; /* desc. for bit length tree */ 202 | 203 | ush bl_count[MAX_BITS+1]; 204 | /* number of codes at each bit length for an optimal tree */ 205 | 206 | int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ 207 | int heap_len; /* number of elements in the heap */ 208 | int heap_max; /* element of largest frequency */ 209 | /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. 210 | * The same heap array is used to build all trees. 211 | */ 212 | 213 | uch depth[2*L_CODES+1]; 214 | /* Depth of each subtree used as tie breaker for trees of equal frequency 215 | */ 216 | 217 | uchf *l_buf; /* buffer for literals or lengths */ 218 | 219 | uInt lit_bufsize; 220 | /* Size of match buffer for literals/lengths. There are 4 reasons for 221 | * limiting lit_bufsize to 64K: 222 | * - frequencies can be kept in 16 bit counters 223 | * - if compression is not successful for the first block, all input 224 | * data is still in the window so we can still emit a stored block even 225 | * when input comes from standard input. (This can also be done for 226 | * all blocks if lit_bufsize is not greater than 32K.) 227 | * - if compression is not successful for a file smaller than 64K, we can 228 | * even emit a stored file instead of a stored block (saving 5 bytes). 229 | * This is applicable only for zip (not gzip or zlib). 230 | * - creating new Huffman trees less frequently may not provide fast 231 | * adaptation to changes in the input data statistics. (Take for 232 | * example a binary file with poorly compressible code followed by 233 | * a highly compressible string table.) Smaller buffer sizes give 234 | * fast adaptation but have of course the overhead of transmitting 235 | * trees more frequently. 236 | * - I can't count above 4 237 | */ 238 | 239 | uInt last_lit; /* running index in l_buf */ 240 | 241 | ushf *d_buf; 242 | /* Buffer for distances. To simplify the code, d_buf and l_buf have 243 | * the same number of elements. To use different lengths, an extra flag 244 | * array would be necessary. 245 | */ 246 | 247 | ulg opt_len; /* bit length of current block with optimal trees */ 248 | ulg static_len; /* bit length of current block with static trees */ 249 | uInt matches; /* number of string matches in current block */ 250 | uInt insert; /* bytes at end of window left to insert */ 251 | 252 | #ifdef DEBUG 253 | ulg compressed_len; /* total bit length of compressed file mod 2^32 */ 254 | ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ 255 | #endif 256 | 257 | ush bi_buf; 258 | /* Output buffer. bits are inserted starting at the bottom (least 259 | * significant bits). 260 | */ 261 | int bi_valid; 262 | /* Number of valid bits in bi_buf. All bits above the last valid bit 263 | * are always zero. 264 | */ 265 | 266 | ulg high_water; 267 | /* High water mark offset in window for initialized bytes -- bytes above 268 | * this are set to zero in order to avoid memory check warnings when 269 | * longest match routines access bytes past the input. This is then 270 | * updated to the new high water mark. 271 | */ 272 | 273 | } FAR deflate_state; 274 | 275 | /* Output a byte on the stream. 276 | * IN assertion: there is enough room in pending_buf. 277 | */ 278 | #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} 279 | 280 | 281 | #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) 282 | /* Minimum amount of lookahead, except at the end of the input file. 283 | * See deflate.c for comments about the MIN_MATCH+1. 284 | */ 285 | 286 | #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) 287 | /* In order to simplify the code, particularly on 16 bit machines, match 288 | * distances are limited to MAX_DIST instead of WSIZE. 289 | */ 290 | 291 | #define WIN_INIT MAX_MATCH 292 | /* Number of bytes after end of data in window to initialize in order to avoid 293 | memory checker errors from longest match routines */ 294 | 295 | /* in trees.c */ 296 | void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); 297 | int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); 298 | void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, 299 | ulg stored_len, int last)); 300 | void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); 301 | void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); 302 | void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, 303 | ulg stored_len, int last)); 304 | 305 | #define d_code(dist) \ 306 | ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) 307 | /* Mapping from a distance to a distance code. dist is the distance - 1 and 308 | * must not have side effects. _dist_code[256] and _dist_code[257] are never 309 | * used. 310 | */ 311 | 312 | #ifndef DEBUG 313 | /* Inline versions of _tr_tally for speed: */ 314 | 315 | #if defined(GEN_TREES_H) || !defined(STDC) 316 | extern uch ZLIB_INTERNAL _length_code[]; 317 | extern uch ZLIB_INTERNAL _dist_code[]; 318 | #else 319 | extern const uch ZLIB_INTERNAL _length_code[]; 320 | extern const uch ZLIB_INTERNAL _dist_code[]; 321 | #endif 322 | 323 | # define _tr_tally_lit(s, c, flush) \ 324 | { uch cc = (c); \ 325 | s->d_buf[s->last_lit] = 0; \ 326 | s->l_buf[s->last_lit++] = cc; \ 327 | s->dyn_ltree[cc].Freq++; \ 328 | flush = (s->last_lit == s->lit_bufsize-1); \ 329 | } 330 | # define _tr_tally_dist(s, distance, length, flush) \ 331 | { uch len = (length); \ 332 | ush dist = (distance); \ 333 | s->d_buf[s->last_lit] = dist; \ 334 | s->l_buf[s->last_lit++] = len; \ 335 | dist--; \ 336 | s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ 337 | s->dyn_dtree[d_code(dist)].Freq++; \ 338 | flush = (s->last_lit == s->lit_bufsize-1); \ 339 | } 340 | #else 341 | # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) 342 | # define _tr_tally_dist(s, distance, length, flush) \ 343 | flush = _tr_tally(s, distance, length) 344 | #endif 345 | 346 | #endif /* DEFLATE_H */ 347 | -------------------------------------------------------------------------------- /XlogDecode/zlib/gzclose.c: -------------------------------------------------------------------------------- 1 | /* gzclose.c -- zlib gzclose() function 2 | * Copyright (C) 2004, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | 8 | /* gzclose() is in a separate file so that it is linked in only if it is used. 9 | That way the other gzclose functions can be used instead to avoid linking in 10 | unneeded compression or decompression routines. */ 11 | int ZEXPORT gzclose(file) 12 | gzFile file; 13 | { 14 | #ifndef NO_GZCOMPRESS 15 | gz_statep state; 16 | 17 | if (file == NULL) 18 | return Z_STREAM_ERROR; 19 | state = (gz_statep)file; 20 | 21 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); 22 | #else 23 | return gzclose_r(file); 24 | #endif 25 | } 26 | -------------------------------------------------------------------------------- /XlogDecode/zlib/gzguts.h: -------------------------------------------------------------------------------- 1 | /* gzguts.h -- zlib internal header definitions for gz* operations 2 | * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #ifdef _LARGEFILE64_SOURCE 7 | # ifndef _LARGEFILE_SOURCE 8 | # define _LARGEFILE_SOURCE 1 9 | # endif 10 | # ifdef _FILE_OFFSET_BITS 11 | # undef _FILE_OFFSET_BITS 12 | # endif 13 | #endif 14 | 15 | #ifdef HAVE_HIDDEN 16 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 17 | #else 18 | # define ZLIB_INTERNAL 19 | #endif 20 | 21 | #include 22 | #include "zlib.h" 23 | #ifdef STDC 24 | # include 25 | # include 26 | # include 27 | #endif 28 | //#include 29 | 30 | #ifdef _WIN32 31 | # include 32 | #endif 33 | 34 | #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) 35 | # include 36 | #endif 37 | 38 | #ifdef NO_DEFLATE /* for compatibility with old definition */ 39 | # define NO_GZCOMPRESS 40 | #endif 41 | 42 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 43 | # ifndef HAVE_VSNPRINTF 44 | # define HAVE_VSNPRINTF 45 | # endif 46 | #endif 47 | 48 | #if defined(__CYGWIN__) 49 | # ifndef HAVE_VSNPRINTF 50 | # define HAVE_VSNPRINTF 51 | # endif 52 | #endif 53 | 54 | #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) 55 | # ifndef HAVE_VSNPRINTF 56 | # define HAVE_VSNPRINTF 57 | # endif 58 | #endif 59 | 60 | #ifndef HAVE_VSNPRINTF 61 | # ifdef MSDOS 62 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 63 | but for now we just assume it doesn't. */ 64 | # define NO_vsnprintf 65 | # endif 66 | # ifdef __TURBOC__ 67 | # define NO_vsnprintf 68 | # endif 69 | # ifdef WIN32 70 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 71 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 72 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) 73 | # define vsnprintf _vsnprintf 74 | # endif 75 | # endif 76 | # endif 77 | # ifdef __SASC 78 | # define NO_vsnprintf 79 | # endif 80 | # ifdef VMS 81 | # define NO_vsnprintf 82 | # endif 83 | # ifdef __OS400__ 84 | # define NO_vsnprintf 85 | # endif 86 | # ifdef __MVS__ 87 | # define NO_vsnprintf 88 | # endif 89 | #endif 90 | 91 | #ifndef local 92 | # define local static 93 | #endif 94 | /* compile with -Dlocal if your debugger can't find static symbols */ 95 | 96 | /* gz* functions always use library allocation functions */ 97 | #ifndef STDC 98 | extern voidp malloc OF((uInt size)); 99 | extern void free OF((voidpf ptr)); 100 | #endif 101 | 102 | /* get errno and strerror definition */ 103 | #if defined UNDER_CE 104 | # include 105 | # define zstrerror() gz_strwinerror((DWORD)GetLastError()) 106 | #else 107 | # ifndef NO_STRERROR 108 | # include 109 | # define zstrerror() strerror(errno) 110 | # else 111 | # define zstrerror() "stdio error (consult errno)" 112 | # endif 113 | #endif 114 | 115 | /* provide prototypes for these when building zlib without LFS */ 116 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 117 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 118 | ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 119 | ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 120 | ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 121 | #endif 122 | 123 | /* default memLevel */ 124 | #if MAX_MEM_LEVEL >= 8 125 | # define DEF_MEM_LEVEL 8 126 | #else 127 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 128 | #endif 129 | 130 | /* default i/o buffer size -- double this for output when reading */ 131 | #define GZBUFSIZE 8192 132 | 133 | /* gzip modes, also provide a little integrity check on the passed structure */ 134 | #define GZ_NONE 0 135 | #define GZ_READ 7247 136 | #define GZ_WRITE 31153 137 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ 138 | 139 | /* values for gz_state how */ 140 | #define LOOK 0 /* look for a gzip header */ 141 | #define COPY 1 /* copy input directly */ 142 | #define GZIP 2 /* decompress a gzip stream */ 143 | 144 | /* internal gzip file state data structure */ 145 | typedef struct { 146 | /* exposed contents for gzgetc() macro */ 147 | struct gzFile_s x; /* "x" for exposed */ 148 | /* x.have: number of bytes available at x.next */ 149 | /* x.next: next output data to deliver or write */ 150 | /* x.pos: current position in uncompressed data */ 151 | /* used for both reading and writing */ 152 | int mode; /* see gzip modes above */ 153 | int fd; /* file descriptor */ 154 | char *path; /* path or fd for error messages */ 155 | unsigned size; /* buffer size, zero if not allocated yet */ 156 | unsigned want; /* requested buffer size, default is GZBUFSIZE */ 157 | unsigned char *in; /* input buffer */ 158 | unsigned char *out; /* output buffer (double-sized when reading) */ 159 | int direct; /* 0 if processing gzip, 1 if transparent */ 160 | /* just for reading */ 161 | int how; /* 0: get header, 1: copy, 2: decompress */ 162 | z_off64_t start; /* where the gzip data started, for rewinding */ 163 | int eof; /* true if end of input file reached */ 164 | int past; /* true if read requested past end */ 165 | /* just for writing */ 166 | int level; /* compression level */ 167 | int strategy; /* compression strategy */ 168 | /* seek request */ 169 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ 170 | int seek; /* true if seek request pending */ 171 | /* error information */ 172 | int err; /* error code */ 173 | char *msg; /* error message */ 174 | /* zlib inflate or deflate stream */ 175 | z_stream strm; /* stream structure in-place (not a pointer) */ 176 | } gz_state; 177 | typedef gz_state FAR *gz_statep; 178 | 179 | /* shared functions */ 180 | void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); 181 | #if defined UNDER_CE 182 | char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); 183 | #endif 184 | 185 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t 186 | value -- needed when comparing unsigned to z_off64_t, which is signed 187 | (possible z_off64_t types off_t, off64_t, and long are all signed) */ 188 | #ifdef INT_MAX 189 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) 190 | #else 191 | unsigned ZLIB_INTERNAL gz_intmax OF((void)); 192 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) 193 | #endif 194 | -------------------------------------------------------------------------------- /XlogDecode/zlib/gzlib.c: -------------------------------------------------------------------------------- 1 | /* gzlib.c -- zlib functions common to reading and writing gzip files 2 | * Copyright (C) 2004, 2010, 2011, 2012 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | #include 8 | 9 | #ifdef _WIN32 10 | #define open _open 11 | #endif 12 | 13 | #if defined(_WIN32) && !defined(__BORLANDC__) 14 | # define LSEEK _lseeki64 15 | #else 16 | #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 17 | # define LSEEK lseek64 18 | #else 19 | # define LSEEK lseek 20 | #endif 21 | #endif 22 | 23 | /* Local functions */ 24 | local void gz_reset OF((gz_statep)); 25 | local gzFile gz_open OF((const void *, int, const char *)); 26 | 27 | #if defined UNDER_CE 28 | 29 | /* Map the Windows error number in ERROR to a locale-dependent error message 30 | string and return a pointer to it. Typically, the values for ERROR come 31 | from GetLastError. 32 | 33 | The string pointed to shall not be modified by the application, but may be 34 | overwritten by a subsequent call to gz_strwinerror 35 | 36 | The gz_strwinerror function does not change the current setting of 37 | GetLastError. */ 38 | char ZLIB_INTERNAL *gz_strwinerror (error) 39 | DWORD error; 40 | { 41 | static char buf[1024]; 42 | 43 | wchar_t *msgbuf; 44 | DWORD lasterr = GetLastError(); 45 | DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM 46 | | FORMAT_MESSAGE_ALLOCATE_BUFFER, 47 | NULL, 48 | error, 49 | 0, /* Default language */ 50 | (LPVOID)&msgbuf, 51 | 0, 52 | NULL); 53 | if (chars != 0) { 54 | /* If there is an \r\n appended, zap it. */ 55 | if (chars >= 2 56 | && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { 57 | chars -= 2; 58 | msgbuf[chars] = 0; 59 | } 60 | 61 | if (chars > sizeof (buf) - 1) { 62 | chars = sizeof (buf) - 1; 63 | msgbuf[chars] = 0; 64 | } 65 | 66 | wcstombs(buf, msgbuf, chars + 1); 67 | LocalFree(msgbuf); 68 | } 69 | else { 70 | sprintf(buf, "unknown win32 error (%ld)", error); 71 | } 72 | 73 | SetLastError(lasterr); 74 | return buf; 75 | } 76 | 77 | #endif /* UNDER_CE */ 78 | 79 | /* Reset gzip file state */ 80 | local void gz_reset(state) 81 | gz_statep state; 82 | { 83 | state->x.have = 0; /* no output data available */ 84 | if (state->mode == GZ_READ) { /* for reading ... */ 85 | state->eof = 0; /* not at end of file */ 86 | state->past = 0; /* have not read past end yet */ 87 | state->how = LOOK; /* look for gzip header */ 88 | } 89 | state->seek = 0; /* no seek request pending */ 90 | gz_error(state, Z_OK, NULL); /* clear error */ 91 | state->x.pos = 0; /* no uncompressed data yet */ 92 | state->strm.avail_in = 0; /* no input data yet */ 93 | } 94 | 95 | /* Open a gzip file either by name or file descriptor. */ 96 | local gzFile gz_open(path, fd, mode) 97 | const void *path; 98 | int fd; 99 | const char *mode; 100 | { 101 | gz_statep state; 102 | size_t len; 103 | int oflag; 104 | #ifdef O_CLOEXEC 105 | int cloexec = 0; 106 | #endif 107 | #ifdef O_EXCL 108 | int exclusive = 0; 109 | #endif 110 | 111 | /* check input */ 112 | if (path == NULL) 113 | return NULL; 114 | 115 | /* allocate gzFile structure to return */ 116 | state = malloc(sizeof(gz_state)); 117 | if (state == NULL) 118 | return NULL; 119 | state->size = 0; /* no buffers allocated yet */ 120 | state->want = GZBUFSIZE; /* requested buffer size */ 121 | state->msg = NULL; /* no error message yet */ 122 | 123 | /* interpret mode */ 124 | state->mode = GZ_NONE; 125 | state->level = Z_DEFAULT_COMPRESSION; 126 | state->strategy = Z_DEFAULT_STRATEGY; 127 | state->direct = 0; 128 | while (*mode) { 129 | if (*mode >= '0' && *mode <= '9') 130 | state->level = *mode - '0'; 131 | else 132 | switch (*mode) { 133 | case 'r': 134 | state->mode = GZ_READ; 135 | break; 136 | #ifndef NO_GZCOMPRESS 137 | case 'w': 138 | state->mode = GZ_WRITE; 139 | break; 140 | case 'a': 141 | state->mode = GZ_APPEND; 142 | break; 143 | #endif 144 | case '+': /* can't read and write at the same time */ 145 | free(state); 146 | return NULL; 147 | case 'b': /* ignore -- will request binary anyway */ 148 | break; 149 | #ifdef O_CLOEXEC 150 | case 'e': 151 | cloexec = 1; 152 | break; 153 | #endif 154 | #ifdef O_EXCL 155 | case 'x': 156 | exclusive = 1; 157 | break; 158 | #endif 159 | case 'f': 160 | state->strategy = Z_FILTERED; 161 | break; 162 | case 'h': 163 | state->strategy = Z_HUFFMAN_ONLY; 164 | break; 165 | case 'R': 166 | state->strategy = Z_RLE; 167 | break; 168 | case 'F': 169 | state->strategy = Z_FIXED; 170 | case 'T': 171 | state->direct = 1; 172 | default: /* could consider as an error, but just ignore */ 173 | ; 174 | } 175 | mode++; 176 | } 177 | 178 | /* must provide an "r", "w", or "a" */ 179 | if (state->mode == GZ_NONE) { 180 | free(state); 181 | return NULL; 182 | } 183 | 184 | /* can't force transparent read */ 185 | if (state->mode == GZ_READ) { 186 | if (state->direct) { 187 | free(state); 188 | return NULL; 189 | } 190 | state->direct = 1; /* for empty file */ 191 | } 192 | 193 | /* save the path name for error messages */ 194 | #ifdef _WIN32 195 | if (fd == -2) { 196 | len = wcstombs(NULL, path, 0); 197 | if (len == (size_t)-1) 198 | len = 0; 199 | } 200 | else 201 | #endif 202 | len = strlen(path); 203 | state->path = malloc(len + 1); 204 | if (state->path == NULL) { 205 | free(state); 206 | return NULL; 207 | } 208 | #ifdef _WIN32 209 | if (fd == -2) 210 | if (len) 211 | wcstombs(state->path, path, len + 1); 212 | else 213 | *(state->path) = 0; 214 | else 215 | #endif 216 | strcpy(state->path, path); 217 | 218 | /* compute the flags for open() */ 219 | oflag = 220 | #ifdef O_LARGEFILE 221 | O_LARGEFILE | 222 | #endif 223 | #ifdef O_BINARY 224 | O_BINARY | 225 | #endif 226 | #ifdef O_CLOEXEC 227 | (cloexec ? O_CLOEXEC : 0) | 228 | #endif 229 | (state->mode == GZ_READ ? 230 | O_RDONLY : 231 | (O_WRONLY | O_CREAT | 232 | #ifdef O_EXCL 233 | (exclusive ? O_EXCL : 0) | 234 | #endif 235 | (state->mode == GZ_WRITE ? 236 | O_TRUNC : 237 | O_APPEND))); 238 | 239 | /* open the file with the appropriate flags (or just use fd) */ 240 | state->fd = fd > -1 ? fd : ( 241 | #ifdef _WIN32 242 | fd == -2 ? _wopen(path, oflag, 0666) : 243 | #endif 244 | open(path, oflag, 0666)); 245 | if (state->fd == -1) { 246 | free(state->path); 247 | free(state); 248 | return NULL; 249 | } 250 | if (state->mode == GZ_APPEND) 251 | state->mode = GZ_WRITE; /* simplify later checks */ 252 | 253 | /* save the current position for rewinding (only if reading) */ 254 | if (state->mode == GZ_READ) { 255 | state->start = LSEEK(state->fd, 0, SEEK_CUR); 256 | if (state->start == -1) state->start = 0; 257 | } 258 | 259 | /* initialize stream */ 260 | gz_reset(state); 261 | 262 | /* return stream */ 263 | return (gzFile)state; 264 | } 265 | 266 | /* -- see zlib.h -- */ 267 | gzFile ZEXPORT gzopen(path, mode) 268 | const char *path; 269 | const char *mode; 270 | { 271 | return gz_open(path, -1, mode); 272 | } 273 | 274 | /* -- see zlib.h -- */ 275 | gzFile ZEXPORT gzopen64(path, mode) 276 | const char *path; 277 | const char *mode; 278 | { 279 | return gz_open(path, -1, mode); 280 | } 281 | 282 | /* -- see zlib.h -- */ 283 | gzFile ZEXPORT gzdopen(fd, mode) 284 | int fd; 285 | const char *mode; 286 | { 287 | char *path; /* identifier for error messages */ 288 | gzFile gz; 289 | 290 | if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL) 291 | return NULL; 292 | sprintf(path, "", fd); /* for debugging */ 293 | gz = gz_open(path, fd, mode); 294 | free(path); 295 | return gz; 296 | } 297 | 298 | /* -- see zlib.h -- */ 299 | #ifdef _WIN32 300 | gzFile ZEXPORT gzopen_w(path, mode) 301 | const wchar_t *path; 302 | const char *mode; 303 | { 304 | return gz_open(path, -2, mode); 305 | } 306 | #endif 307 | 308 | /* -- see zlib.h -- */ 309 | int ZEXPORT gzbuffer(file, size) 310 | gzFile file; 311 | unsigned size; 312 | { 313 | gz_statep state; 314 | 315 | /* get internal structure and check integrity */ 316 | if (file == NULL) 317 | return -1; 318 | state = (gz_statep)file; 319 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) 320 | return -1; 321 | 322 | /* make sure we haven't already allocated memory */ 323 | if (state->size != 0) 324 | return -1; 325 | 326 | /* check and set requested size */ 327 | if (size < 2) 328 | size = 2; /* need two bytes to check magic header */ 329 | state->want = size; 330 | return 0; 331 | } 332 | 333 | /* -- see zlib.h -- */ 334 | int ZEXPORT gzrewind(file) 335 | gzFile file; 336 | { 337 | gz_statep state; 338 | 339 | /* get internal structure */ 340 | if (file == NULL) 341 | return -1; 342 | state = (gz_statep)file; 343 | 344 | /* check that we're reading and that there's no error */ 345 | if (state->mode != GZ_READ || 346 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) 347 | return -1; 348 | 349 | /* back up and start over */ 350 | if (LSEEK(state->fd, state->start, SEEK_SET) == -1) 351 | return -1; 352 | gz_reset(state); 353 | return 0; 354 | } 355 | 356 | /* -- see zlib.h -- */ 357 | z_off64_t ZEXPORT gzseek64(file, offset, whence) 358 | gzFile file; 359 | z_off64_t offset; 360 | int whence; 361 | { 362 | unsigned n; 363 | z_off64_t ret; 364 | gz_statep state; 365 | 366 | /* get internal structure and check integrity */ 367 | if (file == NULL) 368 | return -1; 369 | state = (gz_statep)file; 370 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) 371 | return -1; 372 | 373 | /* check that there's no error */ 374 | if (state->err != Z_OK && state->err != Z_BUF_ERROR) 375 | return -1; 376 | 377 | /* can only seek from start or relative to current position */ 378 | if (whence != SEEK_SET && whence != SEEK_CUR) 379 | return -1; 380 | 381 | /* normalize offset to a SEEK_CUR specification */ 382 | if (whence == SEEK_SET) 383 | offset -= state->x.pos; 384 | else if (state->seek) 385 | offset += state->skip; 386 | state->seek = 0; 387 | 388 | /* if within raw area while reading, just go there */ 389 | if (state->mode == GZ_READ && state->how == COPY && 390 | state->x.pos + offset >= 0) { 391 | ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR); 392 | if (ret == -1) 393 | return -1; 394 | state->x.have = 0; 395 | state->eof = 0; 396 | state->past = 0; 397 | state->seek = 0; 398 | gz_error(state, Z_OK, NULL); 399 | state->strm.avail_in = 0; 400 | state->x.pos += offset; 401 | return state->x.pos; 402 | } 403 | 404 | /* calculate skip amount, rewinding if needed for back seek when reading */ 405 | if (offset < 0) { 406 | if (state->mode != GZ_READ) /* writing -- can't go backwards */ 407 | return -1; 408 | offset += state->x.pos; 409 | if (offset < 0) /* before start of file! */ 410 | return -1; 411 | if (gzrewind(file) == -1) /* rewind, then skip to offset */ 412 | return -1; 413 | } 414 | 415 | /* if reading, skip what's in output buffer (one less gzgetc() check) */ 416 | if (state->mode == GZ_READ) { 417 | n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ? 418 | (unsigned)offset : state->x.have; 419 | state->x.have -= n; 420 | state->x.next += n; 421 | state->x.pos += n; 422 | offset -= n; 423 | } 424 | 425 | /* request skip (if not zero) */ 426 | if (offset) { 427 | state->seek = 1; 428 | state->skip = offset; 429 | } 430 | return state->x.pos + offset; 431 | } 432 | 433 | /* -- see zlib.h -- */ 434 | z_off_t ZEXPORT gzseek(file, offset, whence) 435 | gzFile file; 436 | z_off_t offset; 437 | int whence; 438 | { 439 | z_off64_t ret; 440 | 441 | ret = gzseek64(file, (z_off64_t)offset, whence); 442 | return ret == (z_off_t)ret ? (z_off_t)ret : -1; 443 | } 444 | 445 | /* -- see zlib.h -- */ 446 | z_off64_t ZEXPORT gztell64(file) 447 | gzFile file; 448 | { 449 | gz_statep state; 450 | 451 | /* get internal structure and check integrity */ 452 | if (file == NULL) 453 | return -1; 454 | state = (gz_statep)file; 455 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) 456 | return -1; 457 | 458 | /* return position */ 459 | return state->x.pos + (state->seek ? state->skip : 0); 460 | } 461 | 462 | /* -- see zlib.h -- */ 463 | z_off_t ZEXPORT gztell(file) 464 | gzFile file; 465 | { 466 | z_off64_t ret; 467 | 468 | ret = gztell64(file); 469 | return ret == (z_off_t)ret ? (z_off_t)ret : -1; 470 | } 471 | 472 | /* -- see zlib.h -- */ 473 | z_off64_t ZEXPORT gzoffset64(file) 474 | gzFile file; 475 | { 476 | z_off64_t offset; 477 | gz_statep state; 478 | 479 | /* get internal structure and check integrity */ 480 | if (file == NULL) 481 | return -1; 482 | state = (gz_statep)file; 483 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) 484 | return -1; 485 | 486 | /* compute and return effective offset in file */ 487 | offset = LSEEK(state->fd, 0, SEEK_CUR); 488 | if (offset == -1) 489 | return -1; 490 | if (state->mode == GZ_READ) /* reading */ 491 | offset -= state->strm.avail_in; /* don't count buffered input */ 492 | return offset; 493 | } 494 | 495 | /* -- see zlib.h -- */ 496 | z_off_t ZEXPORT gzoffset(file) 497 | gzFile file; 498 | { 499 | z_off64_t ret; 500 | 501 | ret = gzoffset64(file); 502 | return ret == (z_off_t)ret ? (z_off_t)ret : -1; 503 | } 504 | 505 | /* -- see zlib.h -- */ 506 | int ZEXPORT gzeof(file) 507 | gzFile file; 508 | { 509 | gz_statep state; 510 | 511 | /* get internal structure and check integrity */ 512 | if (file == NULL) 513 | return 0; 514 | state = (gz_statep)file; 515 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) 516 | return 0; 517 | 518 | /* return end-of-file state */ 519 | return state->mode == GZ_READ ? state->past : 0; 520 | } 521 | 522 | /* -- see zlib.h -- */ 523 | const char * ZEXPORT gzerror(file, errnum) 524 | gzFile file; 525 | int *errnum; 526 | { 527 | gz_statep state; 528 | 529 | /* get internal structure and check integrity */ 530 | if (file == NULL) 531 | return NULL; 532 | state = (gz_statep)file; 533 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) 534 | return NULL; 535 | 536 | /* return error information */ 537 | if (errnum != NULL) 538 | *errnum = state->err; 539 | return state->msg == NULL ? "" : state->msg; 540 | } 541 | 542 | /* -- see zlib.h -- */ 543 | void ZEXPORT gzclearerr(file) 544 | gzFile file; 545 | { 546 | gz_statep state; 547 | 548 | /* get internal structure and check integrity */ 549 | if (file == NULL) 550 | return; 551 | state = (gz_statep)file; 552 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) 553 | return; 554 | 555 | /* clear error and end-of-file */ 556 | if (state->mode == GZ_READ) { 557 | state->eof = 0; 558 | state->past = 0; 559 | } 560 | gz_error(state, Z_OK, NULL); 561 | } 562 | 563 | /* Create an error message in allocated memory and set state->err and 564 | state->msg accordingly. Free any previous error message already there. Do 565 | not try to free or allocate space if the error is Z_MEM_ERROR (out of 566 | memory). Simply save the error message as a static string. If there is an 567 | allocation failure constructing the error message, then convert the error to 568 | out of memory. */ 569 | void ZLIB_INTERNAL gz_error(state, err, msg) 570 | gz_statep state; 571 | int err; 572 | const char *msg; 573 | { 574 | /* free previously allocated message and clear */ 575 | if (state->msg != NULL) { 576 | if (state->err != Z_MEM_ERROR) 577 | free(state->msg); 578 | state->msg = NULL; 579 | } 580 | 581 | /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */ 582 | if (err != Z_OK && err != Z_BUF_ERROR) 583 | state->x.have = 0; 584 | 585 | /* set error code, and if no message, then done */ 586 | state->err = err; 587 | if (msg == NULL) 588 | return; 589 | 590 | /* for an out of memory error, save as static string */ 591 | if (err == Z_MEM_ERROR) { 592 | state->msg = (char *)msg; 593 | return; 594 | } 595 | 596 | /* construct error message with path */ 597 | if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { 598 | state->err = Z_MEM_ERROR; 599 | state->msg = (char *)"out of memory"; 600 | return; 601 | } 602 | strcpy(state->msg, state->path); 603 | strcat(state->msg, ": "); 604 | strcat(state->msg, msg); 605 | return; 606 | } 607 | 608 | #ifndef INT_MAX 609 | /* portably return maximum value for an int (when limits.h presumed not 610 | available) -- we need to do this to cover cases where 2's complement not 611 | used, since C standard permits 1's complement and sign-bit representations, 612 | otherwise we could just use ((unsigned)-1) >> 1 */ 613 | unsigned ZLIB_INTERNAL gz_intmax() 614 | { 615 | unsigned p, q; 616 | 617 | p = 1; 618 | do { 619 | q = p; 620 | p <<= 1; 621 | p++; 622 | } while (p > q); 623 | return q >> 1; 624 | } 625 | #endif 626 | -------------------------------------------------------------------------------- /XlogDecode/zlib/gzread.c: -------------------------------------------------------------------------------- 1 | /* gzread.c -- zlib functions for reading gzip files 2 | * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | 8 | #ifdef _WIN32 9 | #define read _read 10 | #define close _close 11 | #endif 12 | 13 | /* Local functions */ 14 | local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); 15 | local int gz_avail OF((gz_statep)); 16 | local int gz_look OF((gz_statep)); 17 | local int gz_decomp OF((gz_statep)); 18 | local int gz_fetch OF((gz_statep)); 19 | local int gz_skip OF((gz_statep, z_off64_t)); 20 | 21 | /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from 22 | state->fd, and update state->eof, state->err, and state->msg as appropriate. 23 | This function needs to loop on read(), since read() is not guaranteed to 24 | read the number of bytes requested, depending on the type of descriptor. */ 25 | local int gz_load(state, buf, len, have) 26 | gz_statep state; 27 | unsigned char *buf; 28 | unsigned len; 29 | unsigned *have; 30 | { 31 | int ret; 32 | 33 | *have = 0; 34 | do { 35 | ret = read(state->fd, buf + *have, len - *have); 36 | if (ret <= 0) 37 | break; 38 | *have += ret; 39 | } while (*have < len); 40 | if (ret < 0) { 41 | gz_error(state, Z_ERRNO, zstrerror()); 42 | return -1; 43 | } 44 | if (ret == 0) 45 | state->eof = 1; 46 | return 0; 47 | } 48 | 49 | /* Load up input buffer and set eof flag if last data loaded -- return -1 on 50 | error, 0 otherwise. Note that the eof flag is set when the end of the input 51 | file is reached, even though there may be unused data in the buffer. Once 52 | that data has been used, no more attempts will be made to read the file. 53 | If strm->avail_in != 0, then the current data is moved to the beginning of 54 | the input buffer, and then the remainder of the buffer is loaded with the 55 | available data from the input file. */ 56 | local int gz_avail(state) 57 | gz_statep state; 58 | { 59 | unsigned got; 60 | z_streamp strm = &(state->strm); 61 | 62 | if (state->err != Z_OK && state->err != Z_BUF_ERROR) 63 | return -1; 64 | if (state->eof == 0) { 65 | if (strm->avail_in) { /* copy what's there to the start */ 66 | unsigned char *p = state->in, *q = strm->next_in; 67 | unsigned n = strm->avail_in; 68 | do { 69 | *p++ = *q++; 70 | } while (--n); 71 | } 72 | if (gz_load(state, state->in + strm->avail_in, 73 | state->size - strm->avail_in, &got) == -1) 74 | return -1; 75 | strm->avail_in += got; 76 | strm->next_in = state->in; 77 | } 78 | return 0; 79 | } 80 | 81 | /* Look for gzip header, set up for inflate or copy. state->x.have must be 0. 82 | If this is the first time in, allocate required memory. state->how will be 83 | left unchanged if there is no more input data available, will be set to COPY 84 | if there is no gzip header and direct copying will be performed, or it will 85 | be set to GZIP for decompression. If direct copying, then leftover input 86 | data from the input buffer will be copied to the output buffer. In that 87 | case, all further file reads will be directly to either the output buffer or 88 | a user buffer. If decompressing, the inflate state will be initialized. 89 | gz_look() will return 0 on success or -1 on failure. */ 90 | local int gz_look(state) 91 | gz_statep state; 92 | { 93 | z_streamp strm = &(state->strm); 94 | 95 | /* allocate read buffers and inflate memory */ 96 | if (state->size == 0) { 97 | /* allocate buffers */ 98 | state->in = malloc(state->want); 99 | state->out = malloc(state->want << 1); 100 | if (state->in == NULL || state->out == NULL) { 101 | if (state->out != NULL) 102 | free(state->out); 103 | if (state->in != NULL) 104 | free(state->in); 105 | gz_error(state, Z_MEM_ERROR, "out of memory"); 106 | return -1; 107 | } 108 | state->size = state->want; 109 | 110 | /* allocate inflate memory */ 111 | state->strm.zalloc = Z_NULL; 112 | state->strm.zfree = Z_NULL; 113 | state->strm.opaque = Z_NULL; 114 | state->strm.avail_in = 0; 115 | state->strm.next_in = Z_NULL; 116 | if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */ 117 | free(state->out); 118 | free(state->in); 119 | state->size = 0; 120 | gz_error(state, Z_MEM_ERROR, "out of memory"); 121 | return -1; 122 | } 123 | } 124 | 125 | /* get at least the magic bytes in the input buffer */ 126 | if (strm->avail_in < 2) { 127 | if (gz_avail(state) == -1) 128 | return -1; 129 | if (strm->avail_in == 0) 130 | return 0; 131 | } 132 | 133 | /* look for gzip magic bytes -- if there, do gzip decoding (note: there is 134 | a logical dilemma here when considering the case of a partially written 135 | gzip file, to wit, if a single 31 byte is written, then we cannot tell 136 | whether this is a single-byte file, or just a partially written gzip 137 | file -- for here we assume that if a gzip file is being written, then 138 | the header will be written in a single operation, so that reading a 139 | single byte is sufficient indication that it is not a gzip file) */ 140 | if (strm->avail_in > 1 && 141 | strm->next_in[0] == 31 && strm->next_in[1] == 139) { 142 | inflateReset(strm); 143 | state->how = GZIP; 144 | state->direct = 0; 145 | return 0; 146 | } 147 | 148 | /* no gzip header -- if we were decoding gzip before, then this is trailing 149 | garbage. Ignore the trailing garbage and finish. */ 150 | if (state->direct == 0) { 151 | strm->avail_in = 0; 152 | state->eof = 1; 153 | state->x.have = 0; 154 | return 0; 155 | } 156 | 157 | /* doing raw i/o, copy any leftover input to output -- this assumes that 158 | the output buffer is larger than the input buffer, which also assures 159 | space for gzungetc() */ 160 | state->x.next = state->out; 161 | if (strm->avail_in) { 162 | memcpy(state->x.next, strm->next_in, strm->avail_in); 163 | state->x.have = strm->avail_in; 164 | strm->avail_in = 0; 165 | } 166 | state->how = COPY; 167 | state->direct = 1; 168 | return 0; 169 | } 170 | 171 | /* Decompress from input to the provided next_out and avail_out in the state. 172 | On return, state->x.have and state->x.next point to the just decompressed 173 | data. If the gzip stream completes, state->how is reset to LOOK to look for 174 | the next gzip stream or raw data, once state->x.have is depleted. Returns 0 175 | on success, -1 on failure. */ 176 | local int gz_decomp(state) 177 | gz_statep state; 178 | { 179 | int ret = Z_OK; 180 | unsigned had; 181 | z_streamp strm = &(state->strm); 182 | 183 | /* fill output buffer up to end of deflate stream */ 184 | had = strm->avail_out; 185 | do { 186 | /* get more input for inflate() */ 187 | if (strm->avail_in == 0 && gz_avail(state) == -1) 188 | return -1; 189 | if (strm->avail_in == 0) { 190 | gz_error(state, Z_BUF_ERROR, "unexpected end of file"); 191 | break; 192 | } 193 | 194 | /* decompress and handle errors */ 195 | ret = inflate(strm, Z_NO_FLUSH); 196 | if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { 197 | gz_error(state, Z_STREAM_ERROR, 198 | "internal error: inflate stream corrupt"); 199 | return -1; 200 | } 201 | if (ret == Z_MEM_ERROR) { 202 | gz_error(state, Z_MEM_ERROR, "out of memory"); 203 | return -1; 204 | } 205 | if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ 206 | gz_error(state, Z_DATA_ERROR, 207 | strm->msg == NULL ? "compressed data error" : strm->msg); 208 | return -1; 209 | } 210 | } while (strm->avail_out && ret != Z_STREAM_END); 211 | 212 | /* update available output */ 213 | state->x.have = had - strm->avail_out; 214 | state->x.next = strm->next_out - state->x.have; 215 | 216 | /* if the gzip stream completed successfully, look for another */ 217 | if (ret == Z_STREAM_END) 218 | state->how = LOOK; 219 | 220 | /* good decompression */ 221 | return 0; 222 | } 223 | 224 | /* Fetch data and put it in the output buffer. Assumes state->x.have is 0. 225 | Data is either copied from the input file or decompressed from the input 226 | file depending on state->how. If state->how is LOOK, then a gzip header is 227 | looked for to determine whether to copy or decompress. Returns -1 on error, 228 | otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the 229 | end of the input file has been reached and all data has been processed. */ 230 | local int gz_fetch(state) 231 | gz_statep state; 232 | { 233 | z_streamp strm = &(state->strm); 234 | 235 | do { 236 | switch(state->how) { 237 | case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */ 238 | if (gz_look(state) == -1) 239 | return -1; 240 | if (state->how == LOOK) 241 | return 0; 242 | break; 243 | case COPY: /* -> COPY */ 244 | if (gz_load(state, state->out, state->size << 1, &(state->x.have)) 245 | == -1) 246 | return -1; 247 | state->x.next = state->out; 248 | return 0; 249 | case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */ 250 | strm->avail_out = state->size << 1; 251 | strm->next_out = state->out; 252 | if (gz_decomp(state) == -1) 253 | return -1; 254 | } 255 | } while (state->x.have == 0 && (!state->eof || strm->avail_in)); 256 | return 0; 257 | } 258 | 259 | /* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ 260 | local int gz_skip(state, len) 261 | gz_statep state; 262 | z_off64_t len; 263 | { 264 | unsigned n; 265 | 266 | /* skip over len bytes or reach end-of-file, whichever comes first */ 267 | while (len) 268 | /* skip over whatever is in output buffer */ 269 | if (state->x.have) { 270 | n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ? 271 | (unsigned)len : state->x.have; 272 | state->x.have -= n; 273 | state->x.next += n; 274 | state->x.pos += n; 275 | len -= n; 276 | } 277 | 278 | /* output buffer empty -- return if we're at the end of the input */ 279 | else if (state->eof && state->strm.avail_in == 0) 280 | break; 281 | 282 | /* need more data to skip -- load up output buffer */ 283 | else { 284 | /* get more output, looking for header if required */ 285 | if (gz_fetch(state) == -1) 286 | return -1; 287 | } 288 | return 0; 289 | } 290 | 291 | /* -- see zlib.h -- */ 292 | int ZEXPORT gzread(file, buf, len) 293 | gzFile file; 294 | voidp buf; 295 | unsigned len; 296 | { 297 | unsigned got, n; 298 | gz_statep state; 299 | z_streamp strm; 300 | 301 | /* get internal structure */ 302 | if (file == NULL) 303 | return -1; 304 | state = (gz_statep)file; 305 | strm = &(state->strm); 306 | 307 | /* check that we're reading and that there's no (serious) error */ 308 | if (state->mode != GZ_READ || 309 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) 310 | return -1; 311 | 312 | /* since an int is returned, make sure len fits in one, otherwise return 313 | with an error (this avoids the flaw in the interface) */ 314 | if ((int)len < 0) { 315 | gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); 316 | return -1; 317 | } 318 | 319 | /* if len is zero, avoid unnecessary operations */ 320 | if (len == 0) 321 | return 0; 322 | 323 | /* process a skip request */ 324 | if (state->seek) { 325 | state->seek = 0; 326 | if (gz_skip(state, state->skip) == -1) 327 | return -1; 328 | } 329 | 330 | /* get len bytes to buf, or less than len if at the end */ 331 | got = 0; 332 | do { 333 | /* first just try copying data from the output buffer */ 334 | if (state->x.have) { 335 | n = state->x.have > len ? len : state->x.have; 336 | memcpy(buf, state->x.next, n); 337 | state->x.next += n; 338 | state->x.have -= n; 339 | } 340 | 341 | /* output buffer empty -- return if we're at the end of the input */ 342 | else if (state->eof && strm->avail_in == 0) { 343 | state->past = 1; /* tried to read past end */ 344 | break; 345 | } 346 | 347 | /* need output data -- for small len or new stream load up our output 348 | buffer */ 349 | else if (state->how == LOOK || len < (state->size << 1)) { 350 | /* get more output, looking for header if required */ 351 | if (gz_fetch(state) == -1) 352 | return -1; 353 | continue; /* no progress yet -- go back to copy above */ 354 | /* the copy above assures that we will leave with space in the 355 | output buffer, allowing at least one gzungetc() to succeed */ 356 | } 357 | 358 | /* large len -- read directly into user buffer */ 359 | else if (state->how == COPY) { /* read directly */ 360 | if (gz_load(state, buf, len, &n) == -1) 361 | return -1; 362 | } 363 | 364 | /* large len -- decompress directly into user buffer */ 365 | else { /* state->how == GZIP */ 366 | strm->avail_out = len; 367 | strm->next_out = buf; 368 | if (gz_decomp(state) == -1) 369 | return -1; 370 | n = state->x.have; 371 | state->x.have = 0; 372 | } 373 | 374 | /* update progress */ 375 | len -= n; 376 | buf = (char *)buf + n; 377 | got += n; 378 | state->x.pos += n; 379 | } while (len); 380 | 381 | /* return number of bytes read into user buffer (will fit in int) */ 382 | return (int)got; 383 | } 384 | 385 | /* -- see zlib.h -- */ 386 | #undef gzgetc 387 | int ZEXPORT gzgetc(file) 388 | gzFile file; 389 | { 390 | int ret; 391 | unsigned char buf[1]; 392 | gz_statep state; 393 | 394 | /* get internal structure */ 395 | if (file == NULL) 396 | return -1; 397 | state = (gz_statep)file; 398 | 399 | /* check that we're reading and that there's no (serious) error */ 400 | if (state->mode != GZ_READ || 401 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) 402 | return -1; 403 | 404 | /* try output buffer (no need to check for skip request) */ 405 | if (state->x.have) { 406 | state->x.have--; 407 | state->x.pos++; 408 | return *(state->x.next)++; 409 | } 410 | 411 | /* nothing there -- try gzread() */ 412 | ret = gzread(file, buf, 1); 413 | return ret < 1 ? -1 : buf[0]; 414 | } 415 | 416 | int ZEXPORT gzgetc_(file) 417 | gzFile file; 418 | { 419 | return gzgetc(file); 420 | } 421 | 422 | /* -- see zlib.h -- */ 423 | int ZEXPORT gzungetc(c, file) 424 | int c; 425 | gzFile file; 426 | { 427 | gz_statep state; 428 | 429 | /* get internal structure */ 430 | if (file == NULL) 431 | return -1; 432 | state = (gz_statep)file; 433 | 434 | /* check that we're reading and that there's no (serious) error */ 435 | if (state->mode != GZ_READ || 436 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) 437 | return -1; 438 | 439 | /* process a skip request */ 440 | if (state->seek) { 441 | state->seek = 0; 442 | if (gz_skip(state, state->skip) == -1) 443 | return -1; 444 | } 445 | 446 | /* can't push EOF */ 447 | if (c < 0) 448 | return -1; 449 | 450 | /* if output buffer empty, put byte at end (allows more pushing) */ 451 | if (state->x.have == 0) { 452 | state->x.have = 1; 453 | state->x.next = state->out + (state->size << 1) - 1; 454 | state->x.next[0] = c; 455 | state->x.pos--; 456 | state->past = 0; 457 | return c; 458 | } 459 | 460 | /* if no room, give up (must have already done a gzungetc()) */ 461 | if (state->x.have == (state->size << 1)) { 462 | gz_error(state, Z_DATA_ERROR, "out of room to push characters"); 463 | return -1; 464 | } 465 | 466 | /* slide output data if needed and insert byte before existing data */ 467 | if (state->x.next == state->out) { 468 | unsigned char *src = state->out + state->x.have; 469 | unsigned char *dest = state->out + (state->size << 1); 470 | while (src > state->out) 471 | *--dest = *--src; 472 | state->x.next = dest; 473 | } 474 | state->x.have++; 475 | state->x.next--; 476 | state->x.next[0] = c; 477 | state->x.pos--; 478 | state->past = 0; 479 | return c; 480 | } 481 | 482 | /* -- see zlib.h -- */ 483 | char * ZEXPORT gzgets(file, buf, len) 484 | gzFile file; 485 | char *buf; 486 | int len; 487 | { 488 | unsigned left, n; 489 | char *str; 490 | unsigned char *eol; 491 | gz_statep state; 492 | 493 | /* check parameters and get internal structure */ 494 | if (file == NULL || buf == NULL || len < 1) 495 | return NULL; 496 | state = (gz_statep)file; 497 | 498 | /* check that we're reading and that there's no (serious) error */ 499 | if (state->mode != GZ_READ || 500 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) 501 | return NULL; 502 | 503 | /* process a skip request */ 504 | if (state->seek) { 505 | state->seek = 0; 506 | if (gz_skip(state, state->skip) == -1) 507 | return NULL; 508 | } 509 | 510 | /* copy output bytes up to new line or len - 1, whichever comes first -- 511 | append a terminating zero to the string (we don't check for a zero in 512 | the contents, let the user worry about that) */ 513 | str = buf; 514 | left = (unsigned)len - 1; 515 | if (left) do { 516 | /* assure that something is in the output buffer */ 517 | if (state->x.have == 0 && gz_fetch(state) == -1) 518 | return NULL; /* error */ 519 | if (state->x.have == 0) { /* end of file */ 520 | state->past = 1; /* read past end */ 521 | break; /* return what we have */ 522 | } 523 | 524 | /* look for end-of-line in current output buffer */ 525 | n = state->x.have > left ? left : state->x.have; 526 | eol = memchr(state->x.next, '\n', n); 527 | if (eol != NULL) 528 | n = (unsigned)(eol - state->x.next) + 1; 529 | 530 | /* copy through end-of-line, or remainder if not found */ 531 | memcpy(buf, state->x.next, n); 532 | state->x.have -= n; 533 | state->x.next += n; 534 | state->x.pos += n; 535 | left -= n; 536 | buf += n; 537 | } while (left && eol == NULL); 538 | 539 | /* return terminated string, or if nothing, end of file */ 540 | if (buf == str) 541 | return NULL; 542 | buf[0] = 0; 543 | return str; 544 | } 545 | 546 | /* -- see zlib.h -- */ 547 | int ZEXPORT gzdirect(file) 548 | gzFile file; 549 | { 550 | gz_statep state; 551 | 552 | /* get internal structure */ 553 | if (file == NULL) 554 | return 0; 555 | state = (gz_statep)file; 556 | 557 | /* if the state is not known, but we can find out, then do so (this is 558 | mainly for right after a gzopen() or gzdopen()) */ 559 | if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) 560 | (void)gz_look(state); 561 | 562 | /* return 1 if transparent, 0 if processing a gzip stream */ 563 | return state->direct; 564 | } 565 | 566 | /* -- see zlib.h -- */ 567 | int ZEXPORT gzclose_r(file) 568 | gzFile file; 569 | { 570 | int ret, err; 571 | gz_statep state; 572 | 573 | /* get internal structure */ 574 | if (file == NULL) 575 | return Z_STREAM_ERROR; 576 | state = (gz_statep)file; 577 | 578 | /* check that we're reading */ 579 | if (state->mode != GZ_READ) 580 | return Z_STREAM_ERROR; 581 | 582 | /* free memory and close file */ 583 | if (state->size) { 584 | inflateEnd(&(state->strm)); 585 | free(state->out); 586 | free(state->in); 587 | } 588 | err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK; 589 | gz_error(state, Z_OK, NULL); 590 | free(state->path); 591 | ret = close(state->fd); 592 | free(state); 593 | return ret ? Z_ERRNO : err; 594 | } 595 | -------------------------------------------------------------------------------- /XlogDecode/zlib/gzwrite.c: -------------------------------------------------------------------------------- 1 | /* gzwrite.c -- zlib functions for writing gzip files 2 | * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | #ifdef _WIN32 8 | #define read _read 9 | #define close _close 10 | #define write _write 11 | #endif 12 | 13 | /* Local functions */ 14 | local int gz_init OF((gz_statep)); 15 | local int gz_comp OF((gz_statep, int)); 16 | local int gz_zero OF((gz_statep, z_off64_t)); 17 | 18 | /* Initialize state for writing a gzip file. Mark initialization by setting 19 | state->size to non-zero. Return -1 on failure or 0 on success. */ 20 | local int gz_init(state) 21 | gz_statep state; 22 | { 23 | int ret; 24 | z_streamp strm = &(state->strm); 25 | 26 | /* allocate input buffer */ 27 | state->in = malloc(state->want); 28 | if (state->in == NULL) { 29 | gz_error(state, Z_MEM_ERROR, "out of memory"); 30 | return -1; 31 | } 32 | 33 | /* only need output buffer and deflate state if compressing */ 34 | if (!state->direct) { 35 | /* allocate output buffer */ 36 | state->out = malloc(state->want); 37 | if (state->out == NULL) { 38 | free(state->in); 39 | gz_error(state, Z_MEM_ERROR, "out of memory"); 40 | return -1; 41 | } 42 | 43 | /* allocate deflate memory, set up for gzip compression */ 44 | strm->zalloc = Z_NULL; 45 | strm->zfree = Z_NULL; 46 | strm->opaque = Z_NULL; 47 | ret = deflateInit2(strm, state->level, Z_DEFLATED, 48 | MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy); 49 | if (ret != Z_OK) { 50 | free(state->out); 51 | free(state->in); 52 | gz_error(state, Z_MEM_ERROR, "out of memory"); 53 | return -1; 54 | } 55 | } 56 | 57 | /* mark state as initialized */ 58 | state->size = state->want; 59 | 60 | /* initialize write buffer if compressing */ 61 | if (!state->direct) { 62 | strm->avail_out = state->size; 63 | strm->next_out = state->out; 64 | state->x.next = strm->next_out; 65 | } 66 | return 0; 67 | } 68 | 69 | /* Compress whatever is at avail_in and next_in and write to the output file. 70 | Return -1 if there is an error writing to the output file, otherwise 0. 71 | flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, 72 | then the deflate() state is reset to start a new gzip stream. If gz->direct 73 | is true, then simply write to the output file without compressing, and 74 | ignore flush. */ 75 | local int gz_comp(state, flush) 76 | gz_statep state; 77 | int flush; 78 | { 79 | int ret, got; 80 | unsigned have; 81 | z_streamp strm = &(state->strm); 82 | 83 | /* allocate memory if this is the first time through */ 84 | if (state->size == 0 && gz_init(state) == -1) 85 | return -1; 86 | 87 | /* write directly if requested */ 88 | if (state->direct) { 89 | got = write(state->fd, strm->next_in, strm->avail_in); 90 | if (got < 0 || (unsigned)got != strm->avail_in) { 91 | gz_error(state, Z_ERRNO, zstrerror()); 92 | return -1; 93 | } 94 | strm->avail_in = 0; 95 | return 0; 96 | } 97 | 98 | /* run deflate() on provided input until it produces no more output */ 99 | ret = Z_OK; 100 | do { 101 | /* write out current buffer contents if full, or if flushing, but if 102 | doing Z_FINISH then don't write until we get to Z_STREAM_END */ 103 | if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && 104 | (flush != Z_FINISH || ret == Z_STREAM_END))) { 105 | have = (unsigned)(strm->next_out - state->x.next); 106 | if (have && ((got = write(state->fd, state->x.next, have)) < 0 || 107 | (unsigned)got != have)) { 108 | gz_error(state, Z_ERRNO, zstrerror()); 109 | return -1; 110 | } 111 | if (strm->avail_out == 0) { 112 | strm->avail_out = state->size; 113 | strm->next_out = state->out; 114 | } 115 | state->x.next = strm->next_out; 116 | } 117 | 118 | /* compress */ 119 | have = strm->avail_out; 120 | ret = deflate(strm, flush); 121 | if (ret == Z_STREAM_ERROR) { 122 | gz_error(state, Z_STREAM_ERROR, 123 | "internal error: deflate stream corrupt"); 124 | return -1; 125 | } 126 | have -= strm->avail_out; 127 | } while (have); 128 | 129 | /* if that completed a deflate stream, allow another to start */ 130 | if (flush == Z_FINISH) 131 | deflateReset(strm); 132 | 133 | /* all done, no errors */ 134 | return 0; 135 | } 136 | 137 | /* Compress len zeros to output. Return -1 on error, 0 on success. */ 138 | local int gz_zero(state, len) 139 | gz_statep state; 140 | z_off64_t len; 141 | { 142 | int first; 143 | unsigned n; 144 | z_streamp strm = &(state->strm); 145 | 146 | /* consume whatever's left in the input buffer */ 147 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) 148 | return -1; 149 | 150 | /* compress len zeros (len guaranteed > 0) */ 151 | first = 1; 152 | while (len) { 153 | n = GT_OFF(state->size) || (z_off64_t)state->size > len ? 154 | (unsigned)len : state->size; 155 | if (first) { 156 | memset(state->in, 0, n); 157 | first = 0; 158 | } 159 | strm->avail_in = n; 160 | strm->next_in = state->in; 161 | state->x.pos += n; 162 | if (gz_comp(state, Z_NO_FLUSH) == -1) 163 | return -1; 164 | len -= n; 165 | } 166 | return 0; 167 | } 168 | 169 | /* -- see zlib.h -- */ 170 | int ZEXPORT gzwrite(file, buf, len) 171 | gzFile file; 172 | voidpc buf; 173 | unsigned len; 174 | { 175 | unsigned put = len; 176 | unsigned n; 177 | gz_statep state; 178 | z_streamp strm; 179 | 180 | /* get internal structure */ 181 | if (file == NULL) 182 | return 0; 183 | state = (gz_statep)file; 184 | strm = &(state->strm); 185 | 186 | /* check that we're writing and that there's no error */ 187 | if (state->mode != GZ_WRITE || state->err != Z_OK) 188 | return 0; 189 | 190 | /* since an int is returned, make sure len fits in one, otherwise return 191 | with an error (this avoids the flaw in the interface) */ 192 | if ((int)len < 0) { 193 | gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); 194 | return 0; 195 | } 196 | 197 | /* if len is zero, avoid unnecessary operations */ 198 | if (len == 0) 199 | return 0; 200 | 201 | /* allocate memory if this is the first time through */ 202 | if (state->size == 0 && gz_init(state) == -1) 203 | return 0; 204 | 205 | /* check for seek request */ 206 | if (state->seek) { 207 | state->seek = 0; 208 | if (gz_zero(state, state->skip) == -1) 209 | return 0; 210 | } 211 | 212 | /* for small len, copy to input buffer, otherwise compress directly */ 213 | if (len < state->size) { 214 | /* copy to input buffer, compress when full */ 215 | do { 216 | if (strm->avail_in == 0) 217 | strm->next_in = state->in; 218 | n = state->size - strm->avail_in; 219 | if (n > len) 220 | n = len; 221 | memcpy(strm->next_in + strm->avail_in, buf, n); 222 | strm->avail_in += n; 223 | state->x.pos += n; 224 | buf = (char *)buf + n; 225 | len -= n; 226 | if (len && gz_comp(state, Z_NO_FLUSH) == -1) 227 | return 0; 228 | } while (len); 229 | } 230 | else { 231 | /* consume whatever's left in the input buffer */ 232 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) 233 | return 0; 234 | 235 | /* directly compress user buffer to file */ 236 | strm->avail_in = len; 237 | strm->next_in = (voidp)buf; 238 | state->x.pos += len; 239 | if (gz_comp(state, Z_NO_FLUSH) == -1) 240 | return 0; 241 | } 242 | 243 | /* input was all buffered or compressed (put will fit in int) */ 244 | return (int)put; 245 | } 246 | 247 | /* -- see zlib.h -- */ 248 | int ZEXPORT gzputc(file, c) 249 | gzFile file; 250 | int c; 251 | { 252 | unsigned char buf[1]; 253 | gz_statep state; 254 | z_streamp strm; 255 | 256 | /* get internal structure */ 257 | if (file == NULL) 258 | return -1; 259 | state = (gz_statep)file; 260 | strm = &(state->strm); 261 | 262 | /* check that we're writing and that there's no error */ 263 | if (state->mode != GZ_WRITE || state->err != Z_OK) 264 | return -1; 265 | 266 | /* check for seek request */ 267 | if (state->seek) { 268 | state->seek = 0; 269 | if (gz_zero(state, state->skip) == -1) 270 | return -1; 271 | } 272 | 273 | /* try writing to input buffer for speed (state->size == 0 if buffer not 274 | initialized) */ 275 | if (strm->avail_in < state->size) { 276 | if (strm->avail_in == 0) 277 | strm->next_in = state->in; 278 | strm->next_in[strm->avail_in++] = c; 279 | state->x.pos++; 280 | return c & 0xff; 281 | } 282 | 283 | /* no room in buffer or not initialized, use gz_write() */ 284 | buf[0] = c; 285 | if (gzwrite(file, buf, 1) != 1) 286 | return -1; 287 | return c & 0xff; 288 | } 289 | 290 | /* -- see zlib.h -- */ 291 | int ZEXPORT gzputs(file, str) 292 | gzFile file; 293 | const char *str; 294 | { 295 | int ret; 296 | unsigned len; 297 | 298 | /* write string */ 299 | len = (unsigned)strlen(str); 300 | ret = gzwrite(file, str, len); 301 | return ret == 0 && len != 0 ? -1 : ret; 302 | } 303 | 304 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) 305 | #include 306 | 307 | /* -- see zlib.h -- */ 308 | int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) 309 | { 310 | int size, len; 311 | gz_statep state; 312 | z_streamp strm; 313 | va_list va; 314 | 315 | /* get internal structure */ 316 | if (file == NULL) 317 | return -1; 318 | state = (gz_statep)file; 319 | strm = &(state->strm); 320 | 321 | /* check that we're writing and that there's no error */ 322 | if (state->mode != GZ_WRITE || state->err != Z_OK) 323 | return 0; 324 | 325 | /* make sure we have some buffer space */ 326 | if (state->size == 0 && gz_init(state) == -1) 327 | return 0; 328 | 329 | /* check for seek request */ 330 | if (state->seek) { 331 | state->seek = 0; 332 | if (gz_zero(state, state->skip) == -1) 333 | return 0; 334 | } 335 | 336 | /* consume whatever's left in the input buffer */ 337 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) 338 | return 0; 339 | 340 | /* do the printf() into the input buffer, put length in len */ 341 | size = (int)(state->size); 342 | state->in[size - 1] = 0; 343 | va_start(va, format); 344 | #ifdef NO_vsnprintf 345 | # ifdef HAS_vsprintf_void 346 | (void)vsprintf((char *)(state->in), format, va); 347 | va_end(va); 348 | for (len = 0; len < size; len++) 349 | if (state->in[len] == 0) break; 350 | # else 351 | len = vsprintf((char *)(state->in), format, va); 352 | va_end(va); 353 | # endif 354 | #else 355 | # ifdef HAS_vsnprintf_void 356 | (void)vsnprintf((char *)(state->in), size, format, va); 357 | va_end(va); 358 | len = strlen((char *)(state->in)); 359 | # else 360 | len = vsnprintf((char *)(state->in), size, format, va); 361 | va_end(va); 362 | # endif 363 | #endif 364 | 365 | /* check that printf() results fit in buffer */ 366 | if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) 367 | return 0; 368 | 369 | /* update buffer and position, defer compression until needed */ 370 | strm->avail_in = (unsigned)len; 371 | strm->next_in = state->in; 372 | state->x.pos += len; 373 | return len; 374 | } 375 | 376 | #else /* !STDC && !Z_HAVE_STDARG_H */ 377 | 378 | /* -- see zlib.h -- */ 379 | int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 380 | a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) 381 | gzFile file; 382 | const char *format; 383 | int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 384 | a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; 385 | { 386 | int size, len; 387 | gz_statep state; 388 | z_streamp strm; 389 | 390 | /* get internal structure */ 391 | if (file == NULL) 392 | return -1; 393 | state = (gz_statep)file; 394 | strm = &(state->strm); 395 | 396 | /* check that can really pass pointer in ints */ 397 | if (sizeof(int) != sizeof(void *)) 398 | return 0; 399 | 400 | /* check that we're writing and that there's no error */ 401 | if (state->mode != GZ_WRITE || state->err != Z_OK) 402 | return 0; 403 | 404 | /* make sure we have some buffer space */ 405 | if (state->size == 0 && gz_init(state) == -1) 406 | return 0; 407 | 408 | /* check for seek request */ 409 | if (state->seek) { 410 | state->seek = 0; 411 | if (gz_zero(state, state->skip) == -1) 412 | return 0; 413 | } 414 | 415 | /* consume whatever's left in the input buffer */ 416 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) 417 | return 0; 418 | 419 | /* do the printf() into the input buffer, put length in len */ 420 | size = (int)(state->size); 421 | state->in[size - 1] = 0; 422 | #ifdef NO_snprintf 423 | # ifdef HAS_sprintf_void 424 | sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, 425 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 426 | for (len = 0; len < size; len++) 427 | if (state->in[len] == 0) break; 428 | # else 429 | len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, 430 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 431 | # endif 432 | #else 433 | # ifdef HAS_snprintf_void 434 | snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8, 435 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 436 | len = strlen((char *)(state->in)); 437 | # else 438 | len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, 439 | a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, 440 | a19, a20); 441 | # endif 442 | #endif 443 | 444 | /* check that printf() results fit in buffer */ 445 | if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) 446 | return 0; 447 | 448 | /* update buffer and position, defer compression until needed */ 449 | strm->avail_in = (unsigned)len; 450 | strm->next_in = state->in; 451 | state->x.pos += len; 452 | return len; 453 | } 454 | 455 | #endif 456 | 457 | /* -- see zlib.h -- */ 458 | int ZEXPORT gzflush(file, flush) 459 | gzFile file; 460 | int flush; 461 | { 462 | gz_statep state; 463 | 464 | /* get internal structure */ 465 | if (file == NULL) 466 | return -1; 467 | state = (gz_statep)file; 468 | 469 | /* check that we're writing and that there's no error */ 470 | if (state->mode != GZ_WRITE || state->err != Z_OK) 471 | return Z_STREAM_ERROR; 472 | 473 | /* check flush parameter */ 474 | if (flush < 0 || flush > Z_FINISH) 475 | return Z_STREAM_ERROR; 476 | 477 | /* check for seek request */ 478 | if (state->seek) { 479 | state->seek = 0; 480 | if (gz_zero(state, state->skip) == -1) 481 | return -1; 482 | } 483 | 484 | /* compress remaining data with requested flush */ 485 | gz_comp(state, flush); 486 | return state->err; 487 | } 488 | 489 | /* -- see zlib.h -- */ 490 | int ZEXPORT gzsetparams(file, level, strategy) 491 | gzFile file; 492 | int level; 493 | int strategy; 494 | { 495 | gz_statep state; 496 | z_streamp strm; 497 | 498 | /* get internal structure */ 499 | if (file == NULL) 500 | return Z_STREAM_ERROR; 501 | state = (gz_statep)file; 502 | strm = &(state->strm); 503 | 504 | /* check that we're writing and that there's no error */ 505 | if (state->mode != GZ_WRITE || state->err != Z_OK) 506 | return Z_STREAM_ERROR; 507 | 508 | /* if no change is requested, then do nothing */ 509 | if (level == state->level && strategy == state->strategy) 510 | return Z_OK; 511 | 512 | /* check for seek request */ 513 | if (state->seek) { 514 | state->seek = 0; 515 | if (gz_zero(state, state->skip) == -1) 516 | return -1; 517 | } 518 | 519 | /* change compression parameters for subsequent input */ 520 | if (state->size) { 521 | /* flush previous input with previous parameters before changing */ 522 | if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) 523 | return state->err; 524 | deflateParams(strm, level, strategy); 525 | } 526 | state->level = level; 527 | state->strategy = strategy; 528 | return Z_OK; 529 | } 530 | 531 | /* -- see zlib.h -- */ 532 | int ZEXPORT gzclose_w(file) 533 | gzFile file; 534 | { 535 | int ret = Z_OK; 536 | gz_statep state; 537 | 538 | /* get internal structure */ 539 | if (file == NULL) 540 | return Z_STREAM_ERROR; 541 | state = (gz_statep)file; 542 | 543 | /* check that we're writing */ 544 | if (state->mode != GZ_WRITE) 545 | return Z_STREAM_ERROR; 546 | 547 | /* check for seek request */ 548 | if (state->seek) { 549 | state->seek = 0; 550 | if (gz_zero(state, state->skip) == -1) 551 | ret = state->err; 552 | } 553 | 554 | /* flush, free memory, and close file */ 555 | if (state->size) { 556 | if (gz_comp(state, Z_FINISH) == -1) 557 | ret = state->err; 558 | if (!state->direct) { 559 | (void)deflateEnd(&(state->strm)); 560 | free(state->out); 561 | } 562 | free(state->in); 563 | } 564 | gz_error(state, Z_OK, NULL); 565 | free(state->path); 566 | if (close(state->fd) == -1) 567 | ret = Z_ERRNO; 568 | free(state); 569 | return ret; 570 | } 571 | -------------------------------------------------------------------------------- /XlogDecode/zlib/inffast.c: -------------------------------------------------------------------------------- 1 | /* inffast.c -- fast decoding 2 | * Copyright (C) 1995-2008, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "zutil.h" 7 | #include "inftrees.h" 8 | #include "inflate.h" 9 | #include "inffast.h" 10 | 11 | #ifndef ASMINF 12 | 13 | /* Allow machine dependent optimization for post-increment or pre-increment. 14 | Based on testing to date, 15 | Pre-increment preferred for: 16 | - PowerPC G3 (Adler) 17 | - MIPS R5000 (Randers-Pehrson) 18 | Post-increment preferred for: 19 | - none 20 | No measurable difference: 21 | - Pentium III (Anderson) 22 | - M68060 (Nikl) 23 | */ 24 | #ifdef POSTINC 25 | # define OFF 0 26 | # define PUP(a) *(a)++ 27 | #else 28 | # define OFF 1 29 | # define PUP(a) *++(a) 30 | #endif 31 | 32 | /* 33 | Decode literal, length, and distance codes and write out the resulting 34 | literal and match bytes until either not enough input or output is 35 | available, an end-of-block is encountered, or a data error is encountered. 36 | When large enough input and output buffers are supplied to inflate(), for 37 | example, a 16K input buffer and a 64K output buffer, more than 95% of the 38 | inflate execution time is spent in this routine. 39 | 40 | Entry assumptions: 41 | 42 | state->mode == LEN 43 | strm->avail_in >= 6 44 | strm->avail_out >= 258 45 | start >= strm->avail_out 46 | state->bits < 8 47 | 48 | On return, state->mode is one of: 49 | 50 | LEN -- ran out of enough output space or enough available input 51 | TYPE -- reached end of block code, inflate() to interpret next block 52 | BAD -- error in block data 53 | 54 | Notes: 55 | 56 | - The maximum input bits used by a length/distance pair is 15 bits for the 57 | length code, 5 bits for the length extra, 15 bits for the distance code, 58 | and 13 bits for the distance extra. This totals 48 bits, or six bytes. 59 | Therefore if strm->avail_in >= 6, then there is enough input to avoid 60 | checking for available input while decoding. 61 | 62 | - The maximum bytes that a single length/distance pair can output is 258 63 | bytes, which is the maximum length that can be coded. inflate_fast() 64 | requires strm->avail_out >= 258 for each loop to avoid checking for 65 | output space. 66 | */ 67 | void ZLIB_INTERNAL inflate_fast(strm, start) 68 | z_streamp strm; 69 | unsigned start; /* inflate()'s starting value for strm->avail_out */ 70 | { 71 | struct inflate_state FAR *state; 72 | unsigned char FAR *in; /* local strm->next_in */ 73 | unsigned char FAR *last; /* while in < last, enough input available */ 74 | unsigned char FAR *out; /* local strm->next_out */ 75 | unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ 76 | unsigned char FAR *end; /* while out < end, enough space available */ 77 | #ifdef INFLATE_STRICT 78 | unsigned dmax; /* maximum distance from zlib header */ 79 | #endif 80 | unsigned wsize; /* window size or zero if not using window */ 81 | unsigned whave; /* valid bytes in the window */ 82 | unsigned wnext; /* window write index */ 83 | unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ 84 | unsigned long hold; /* local strm->hold */ 85 | unsigned bits; /* local strm->bits */ 86 | code const FAR *lcode; /* local strm->lencode */ 87 | code const FAR *dcode; /* local strm->distcode */ 88 | unsigned lmask; /* mask for first level of length codes */ 89 | unsigned dmask; /* mask for first level of distance codes */ 90 | code here; /* retrieved table entry */ 91 | unsigned op; /* code bits, operation, extra bits, or */ 92 | /* window position, window bytes to copy */ 93 | unsigned len; /* match length, unused bytes */ 94 | unsigned dist; /* match distance */ 95 | unsigned char FAR *from; /* where to copy match from */ 96 | 97 | /* copy state to local variables */ 98 | state = (struct inflate_state FAR *)strm->state; 99 | in = strm->next_in - OFF; 100 | last = in + (strm->avail_in - 5); 101 | out = strm->next_out - OFF; 102 | beg = out - (start - strm->avail_out); 103 | end = out + (strm->avail_out - 257); 104 | #ifdef INFLATE_STRICT 105 | dmax = state->dmax; 106 | #endif 107 | wsize = state->wsize; 108 | whave = state->whave; 109 | wnext = state->wnext; 110 | window = state->window; 111 | hold = state->hold; 112 | bits = state->bits; 113 | lcode = state->lencode; 114 | dcode = state->distcode; 115 | lmask = (1U << state->lenbits) - 1; 116 | dmask = (1U << state->distbits) - 1; 117 | 118 | /* decode literals and length/distances until end-of-block or not enough 119 | input data or output space */ 120 | do { 121 | if (bits < 15) { 122 | hold += (unsigned long)(PUP(in)) << bits; 123 | bits += 8; 124 | hold += (unsigned long)(PUP(in)) << bits; 125 | bits += 8; 126 | } 127 | here = lcode[hold & lmask]; 128 | dolen: 129 | op = (unsigned)(here.bits); 130 | hold >>= op; 131 | bits -= op; 132 | op = (unsigned)(here.op); 133 | if (op == 0) { /* literal */ 134 | Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 135 | "inflate: literal '%c'\n" : 136 | "inflate: literal 0x%02x\n", here.val)); 137 | PUP(out) = (unsigned char)(here.val); 138 | } 139 | else if (op & 16) { /* length base */ 140 | len = (unsigned)(here.val); 141 | op &= 15; /* number of extra bits */ 142 | if (op) { 143 | if (bits < op) { 144 | hold += (unsigned long)(PUP(in)) << bits; 145 | bits += 8; 146 | } 147 | len += (unsigned)hold & ((1U << op) - 1); 148 | hold >>= op; 149 | bits -= op; 150 | } 151 | Tracevv((stderr, "inflate: length %u\n", len)); 152 | if (bits < 15) { 153 | hold += (unsigned long)(PUP(in)) << bits; 154 | bits += 8; 155 | hold += (unsigned long)(PUP(in)) << bits; 156 | bits += 8; 157 | } 158 | here = dcode[hold & dmask]; 159 | dodist: 160 | op = (unsigned)(here.bits); 161 | hold >>= op; 162 | bits -= op; 163 | op = (unsigned)(here.op); 164 | if (op & 16) { /* distance base */ 165 | dist = (unsigned)(here.val); 166 | op &= 15; /* number of extra bits */ 167 | if (bits < op) { 168 | hold += (unsigned long)(PUP(in)) << bits; 169 | bits += 8; 170 | if (bits < op) { 171 | hold += (unsigned long)(PUP(in)) << bits; 172 | bits += 8; 173 | } 174 | } 175 | dist += (unsigned)hold & ((1U << op) - 1); 176 | #ifdef INFLATE_STRICT 177 | if (dist > dmax) { 178 | strm->msg = (char *)"invalid distance too far back"; 179 | state->mode = BAD; 180 | break; 181 | } 182 | #endif 183 | hold >>= op; 184 | bits -= op; 185 | Tracevv((stderr, "inflate: distance %u\n", dist)); 186 | op = (unsigned)(out - beg); /* max distance in output */ 187 | if (dist > op) { /* see if copy from window */ 188 | op = dist - op; /* distance back in window */ 189 | if (op > whave) { 190 | if (state->sane) { 191 | strm->msg = 192 | (char *)"invalid distance too far back"; 193 | state->mode = BAD; 194 | break; 195 | } 196 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 197 | if (len <= op - whave) { 198 | do { 199 | PUP(out) = 0; 200 | } while (--len); 201 | continue; 202 | } 203 | len -= op - whave; 204 | do { 205 | PUP(out) = 0; 206 | } while (--op > whave); 207 | if (op == 0) { 208 | from = out - dist; 209 | do { 210 | PUP(out) = PUP(from); 211 | } while (--len); 212 | continue; 213 | } 214 | #endif 215 | } 216 | from = window - OFF; 217 | if (wnext == 0) { /* very common case */ 218 | from += wsize - op; 219 | if (op < len) { /* some from window */ 220 | len -= op; 221 | do { 222 | PUP(out) = PUP(from); 223 | } while (--op); 224 | from = out - dist; /* rest from output */ 225 | } 226 | } 227 | else if (wnext < op) { /* wrap around window */ 228 | from += wsize + wnext - op; 229 | op -= wnext; 230 | if (op < len) { /* some from end of window */ 231 | len -= op; 232 | do { 233 | PUP(out) = PUP(from); 234 | } while (--op); 235 | from = window - OFF; 236 | if (wnext < len) { /* some from start of window */ 237 | op = wnext; 238 | len -= op; 239 | do { 240 | PUP(out) = PUP(from); 241 | } while (--op); 242 | from = out - dist; /* rest from output */ 243 | } 244 | } 245 | } 246 | else { /* contiguous in window */ 247 | from += wnext - op; 248 | if (op < len) { /* some from window */ 249 | len -= op; 250 | do { 251 | PUP(out) = PUP(from); 252 | } while (--op); 253 | from = out - dist; /* rest from output */ 254 | } 255 | } 256 | while (len > 2) { 257 | PUP(out) = PUP(from); 258 | PUP(out) = PUP(from); 259 | PUP(out) = PUP(from); 260 | len -= 3; 261 | } 262 | if (len) { 263 | PUP(out) = PUP(from); 264 | if (len > 1) 265 | PUP(out) = PUP(from); 266 | } 267 | } 268 | else { 269 | from = out - dist; /* copy direct from output */ 270 | do { /* minimum length is three */ 271 | PUP(out) = PUP(from); 272 | PUP(out) = PUP(from); 273 | PUP(out) = PUP(from); 274 | len -= 3; 275 | } while (len > 2); 276 | if (len) { 277 | PUP(out) = PUP(from); 278 | if (len > 1) 279 | PUP(out) = PUP(from); 280 | } 281 | } 282 | } 283 | else if ((op & 64) == 0) { /* 2nd level distance code */ 284 | here = dcode[here.val + (hold & ((1U << op) - 1))]; 285 | goto dodist; 286 | } 287 | else { 288 | strm->msg = (char *)"invalid distance code"; 289 | state->mode = BAD; 290 | break; 291 | } 292 | } 293 | else if ((op & 64) == 0) { /* 2nd level length code */ 294 | here = lcode[here.val + (hold & ((1U << op) - 1))]; 295 | goto dolen; 296 | } 297 | else if (op & 32) { /* end-of-block */ 298 | Tracevv((stderr, "inflate: end of block\n")); 299 | state->mode = TYPE; 300 | break; 301 | } 302 | else { 303 | strm->msg = (char *)"invalid literal/length code"; 304 | state->mode = BAD; 305 | break; 306 | } 307 | } while (in < last && out < end); 308 | 309 | /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ 310 | len = bits >> 3; 311 | in -= len; 312 | bits -= len << 3; 313 | hold &= (1U << bits) - 1; 314 | 315 | /* update state and return */ 316 | strm->next_in = in + OFF; 317 | strm->next_out = out + OFF; 318 | strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); 319 | strm->avail_out = (unsigned)(out < end ? 320 | 257 + (end - out) : 257 - (out - end)); 321 | state->hold = hold; 322 | state->bits = bits; 323 | return; 324 | } 325 | 326 | /* 327 | inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): 328 | - Using bit fields for code structure 329 | - Different op definition to avoid & for extra bits (do & for table bits) 330 | - Three separate decoding do-loops for direct, window, and wnext == 0 331 | - Special case for distance > 1 copies to do overlapped load and store copy 332 | - Explicit branch predictions (based on measured branch probabilities) 333 | - Deferring match copy and interspersed it with decoding subsequent codes 334 | - Swapping literal/length else 335 | - Swapping window/direct else 336 | - Larger unrolled copy loops (three is about right) 337 | - Moving len -= 3 statement into middle of loop 338 | */ 339 | 340 | #endif /* !ASMINF */ 341 | -------------------------------------------------------------------------------- /XlogDecode/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 | -------------------------------------------------------------------------------- /XlogDecode/zlib/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. 6 | It is part of the implementation of this library and is 7 | subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /XlogDecode/zlib/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2009 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 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY_, /* i/o: same as COPY below, but only first time in */ 36 | COPY, /* i/o: waiting for input or output to copy stored block */ 37 | TABLE, /* i: waiting for dynamic block table lengths */ 38 | LENLENS, /* i: waiting for code length code lengths */ 39 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 40 | LEN_, /* i: same as LEN below, but only first time in */ 41 | LEN, /* i: waiting for length/lit/eob code */ 42 | LENEXT, /* i: waiting for length extra bits */ 43 | DIST, /* i: waiting for distance code */ 44 | DISTEXT, /* i: waiting for distance extra bits */ 45 | MATCH, /* o: waiting for output space to copy string */ 46 | LIT, /* o: waiting for output space to write literal */ 47 | CHECK, /* i: waiting for 32-bit check value */ 48 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 49 | DONE, /* finished check, done -- remain here until reset */ 50 | BAD, /* got a data error -- remain here until reset */ 51 | MEM, /* got an inflate() memory error -- remain here until reset */ 52 | SYNC /* looking for synchronization bytes to restart inflate() */ 53 | } inflate_mode; 54 | 55 | /* 56 | State transitions between above modes - 57 | 58 | (most modes can go to BAD or MEM on error -- not shown for clarity) 59 | 60 | Process header: 61 | HEAD -> (gzip) or (zlib) or (raw) 62 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> 63 | HCRC -> TYPE 64 | (zlib) -> DICTID or TYPE 65 | DICTID -> DICT -> TYPE 66 | (raw) -> TYPEDO 67 | Read deflate blocks: 68 | TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK 69 | STORED -> COPY_ -> COPY -> TYPE 70 | TABLE -> LENLENS -> CODELENS -> LEN_ 71 | LEN_ -> LEN 72 | Read deflate codes in fixed or dynamic block: 73 | LEN -> LENEXT or LIT or TYPE 74 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 75 | LIT -> LEN 76 | Process trailer: 77 | CHECK -> LENGTH -> DONE 78 | */ 79 | 80 | /* state maintained between inflate() calls. Approximately 10K bytes. */ 81 | struct inflate_state { 82 | inflate_mode mode; /* current inflate mode */ 83 | int last; /* true if processing last block */ 84 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 85 | int havedict; /* true if dictionary provided */ 86 | int flags; /* gzip header method and flags (0 if zlib) */ 87 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 88 | unsigned long check; /* protected copy of check value */ 89 | unsigned long total; /* protected copy of output count */ 90 | gz_headerp head; /* where to save gzip header information */ 91 | /* sliding window */ 92 | unsigned wbits; /* log base 2 of requested window size */ 93 | unsigned wsize; /* window size or zero if not using window */ 94 | unsigned whave; /* valid bytes in the window */ 95 | unsigned wnext; /* window write index */ 96 | unsigned char FAR *window; /* allocated sliding window, if needed */ 97 | /* bit accumulator */ 98 | unsigned long hold; /* input bit accumulator */ 99 | unsigned bits; /* number of bits in "in" */ 100 | /* for string and stored block copying */ 101 | unsigned length; /* literal or length of data to copy */ 102 | unsigned offset; /* distance back to copy string from */ 103 | /* for table and code decoding */ 104 | unsigned extra; /* extra bits needed */ 105 | /* fixed and dynamic code tables */ 106 | code const FAR *lencode; /* starting table for length/literal codes */ 107 | code const FAR *distcode; /* starting table for distance codes */ 108 | unsigned lenbits; /* index bits for lencode */ 109 | unsigned distbits; /* index bits for distcode */ 110 | /* dynamic table building */ 111 | unsigned ncode; /* number of code length code lengths */ 112 | unsigned nlen; /* number of length code lengths */ 113 | unsigned ndist; /* number of distance code lengths */ 114 | unsigned have; /* number of code lengths in lens[] */ 115 | code FAR *next; /* next available space in codes[] */ 116 | unsigned short lens[320]; /* temporary storage for code lengths */ 117 | unsigned short work[288]; /* work area for code table building */ 118 | code codes[ENOUGH]; /* space for code tables */ 119 | int sane; /* if false, allow invalid distance too far */ 120 | int back; /* bits back of last unprocessed length/lit */ 121 | unsigned was; /* initial length of match */ 122 | }; 123 | -------------------------------------------------------------------------------- /XlogDecode/zlib/inftrees.c: -------------------------------------------------------------------------------- 1 | /* inftrees.c -- generate Huffman trees for efficient decoding 2 | * Copyright (C) 1995-2012 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "zutil.h" 7 | #include "inftrees.h" 8 | 9 | #define MAXBITS 15 10 | 11 | const char inflate_copyright[] = 12 | " inflate 1.2.7 Copyright 1995-2012 Mark Adler "; 13 | /* 14 | If you use the zlib library in a product, an acknowledgment is welcome 15 | in the documentation of your product. If for some reason you cannot 16 | include such an acknowledgment, I would appreciate that you keep this 17 | copyright string in the executable of your product. 18 | */ 19 | 20 | /* 21 | Build a set of tables to decode the provided canonical Huffman code. 22 | The code lengths are lens[0..codes-1]. The result starts at *table, 23 | whose indices are 0..2^bits-1. work is a writable array of at least 24 | lens shorts, which is used as a work area. type is the type of code 25 | to be generated, CODES, LENS, or DISTS. On return, zero is success, 26 | -1 is an invalid code, and +1 means that ENOUGH isn't enough. table 27 | on return points to the next available entry's address. bits is the 28 | requested root table index bits, and on return it is the actual root 29 | table index bits. It will differ if the request is greater than the 30 | longest code or if it is less than the shortest code. 31 | */ 32 | int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) 33 | codetype type; 34 | unsigned short FAR *lens; 35 | unsigned codes; 36 | code FAR * FAR *table; 37 | unsigned FAR *bits; 38 | unsigned short FAR *work; 39 | { 40 | unsigned len; /* a code's length in bits */ 41 | unsigned sym; /* index of code symbols */ 42 | unsigned min, max; /* minimum and maximum code lengths */ 43 | unsigned root; /* number of index bits for root table */ 44 | unsigned curr; /* number of index bits for current table */ 45 | unsigned drop; /* code bits to drop for sub-table */ 46 | int left; /* number of prefix codes available */ 47 | unsigned used; /* code entries in table used */ 48 | unsigned huff; /* Huffman code */ 49 | unsigned incr; /* for incrementing code, index */ 50 | unsigned fill; /* index for replicating entries */ 51 | unsigned low; /* low bits for current root entry */ 52 | unsigned mask; /* mask for low root bits */ 53 | code here; /* table entry for duplication */ 54 | code FAR *next; /* next available space in table */ 55 | const unsigned short FAR *base; /* base value table to use */ 56 | const unsigned short FAR *extra; /* extra bits table to use */ 57 | int end; /* use base and extra for symbol > end */ 58 | unsigned short count[MAXBITS+1]; /* number of codes of each length */ 59 | unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ 60 | static const unsigned short lbase[31] = { /* Length codes 257..285 base */ 61 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 62 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 63 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 64 | 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 65 | 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68}; 66 | static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 67 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 68 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 69 | 8193, 12289, 16385, 24577, 0, 0}; 70 | static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ 71 | 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 72 | 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 73 | 28, 28, 29, 29, 64, 64}; 74 | 75 | /* 76 | Process a set of code lengths to create a canonical Huffman code. The 77 | code lengths are lens[0..codes-1]. Each length corresponds to the 78 | symbols 0..codes-1. The Huffman code is generated by first sorting the 79 | symbols by length from short to long, and retaining the symbol order 80 | for codes with equal lengths. Then the code starts with all zero bits 81 | for the first code of the shortest length, and the codes are integer 82 | increments for the same length, and zeros are appended as the length 83 | increases. For the deflate format, these bits are stored backwards 84 | from their more natural integer increment ordering, and so when the 85 | decoding tables are built in the large loop below, the integer codes 86 | are incremented backwards. 87 | 88 | This routine assumes, but does not check, that all of the entries in 89 | lens[] are in the range 0..MAXBITS. The caller must assure this. 90 | 1..MAXBITS is interpreted as that code length. zero means that that 91 | symbol does not occur in this code. 92 | 93 | The codes are sorted by computing a count of codes for each length, 94 | creating from that a table of starting indices for each length in the 95 | sorted table, and then entering the symbols in order in the sorted 96 | table. The sorted table is work[], with that space being provided by 97 | the caller. 98 | 99 | The length counts are used for other purposes as well, i.e. finding 100 | the minimum and maximum length codes, determining if there are any 101 | codes at all, checking for a valid set of lengths, and looking ahead 102 | at length counts to determine sub-table sizes when building the 103 | decoding tables. 104 | */ 105 | 106 | /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ 107 | for (len = 0; len <= MAXBITS; len++) 108 | count[len] = 0; 109 | for (sym = 0; sym < codes; sym++) 110 | count[lens[sym]]++; 111 | 112 | /* bound code lengths, force root to be within code lengths */ 113 | root = *bits; 114 | for (max = MAXBITS; max >= 1; max--) 115 | if (count[max] != 0) break; 116 | if (root > max) root = max; 117 | if (max == 0) { /* no symbols to code at all */ 118 | here.op = (unsigned char)64; /* invalid code marker */ 119 | here.bits = (unsigned char)1; 120 | here.val = (unsigned short)0; 121 | *(*table)++ = here; /* make a table to force an error */ 122 | *(*table)++ = here; 123 | *bits = 1; 124 | return 0; /* no symbols, but wait for decoding to report error */ 125 | } 126 | for (min = 1; min < max; min++) 127 | if (count[min] != 0) break; 128 | if (root < min) root = min; 129 | 130 | /* check for an over-subscribed or incomplete set of lengths */ 131 | left = 1; 132 | for (len = 1; len <= MAXBITS; len++) { 133 | left <<= 1; 134 | left -= count[len]; 135 | if (left < 0) return -1; /* over-subscribed */ 136 | } 137 | if (left > 0 && (type == CODES || max != 1)) 138 | return -1; /* incomplete set */ 139 | 140 | /* generate offsets into symbol table for each length for sorting */ 141 | offs[1] = 0; 142 | for (len = 1; len < MAXBITS; len++) 143 | offs[len + 1] = offs[len] + count[len]; 144 | 145 | /* sort symbols by length, by symbol order within each length */ 146 | for (sym = 0; sym < codes; sym++) 147 | if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; 148 | 149 | /* 150 | Create and fill in decoding tables. In this loop, the table being 151 | filled is at next and has curr index bits. The code being used is huff 152 | with length len. That code is converted to an index by dropping drop 153 | bits off of the bottom. For codes where len is less than drop + curr, 154 | those top drop + curr - len bits are incremented through all values to 155 | fill the table with replicated entries. 156 | 157 | root is the number of index bits for the root table. When len exceeds 158 | root, sub-tables are created pointed to by the root entry with an index 159 | of the low root bits of huff. This is saved in low to check for when a 160 | new sub-table should be started. drop is zero when the root table is 161 | being filled, and drop is root when sub-tables are being filled. 162 | 163 | When a new sub-table is needed, it is necessary to look ahead in the 164 | code lengths to determine what size sub-table is needed. The length 165 | counts are used for this, and so count[] is decremented as codes are 166 | entered in the tables. 167 | 168 | used keeps track of how many table entries have been allocated from the 169 | provided *table space. It is checked for LENS and DIST tables against 170 | the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in 171 | the initial root table size constants. See the comments in inftrees.h 172 | for more information. 173 | 174 | sym increments through all symbols, and the loop terminates when 175 | all codes of length max, i.e. all codes, have been processed. This 176 | routine permits incomplete codes, so another loop after this one fills 177 | in the rest of the decoding tables with invalid code markers. 178 | */ 179 | 180 | /* set up for code type */ 181 | switch (type) { 182 | case CODES: 183 | base = extra = work; /* dummy value--not used */ 184 | end = 19; 185 | break; 186 | case LENS: 187 | base = lbase; 188 | base -= 257; 189 | extra = lext; 190 | extra -= 257; 191 | end = 256; 192 | break; 193 | default: /* DISTS */ 194 | base = dbase; 195 | extra = dext; 196 | end = -1; 197 | } 198 | 199 | /* initialize state for loop */ 200 | huff = 0; /* starting code */ 201 | sym = 0; /* starting code symbol */ 202 | len = min; /* starting code length */ 203 | next = *table; /* current table to fill in */ 204 | curr = root; /* current table index bits */ 205 | drop = 0; /* current bits to drop from code for index */ 206 | low = (unsigned)(-1); /* trigger new sub-table when len > root */ 207 | used = 1U << root; /* use root table entries */ 208 | mask = used - 1; /* mask for comparing low */ 209 | 210 | /* check available table space */ 211 | if ((type == LENS && used >= ENOUGH_LENS) || 212 | (type == DISTS && used >= ENOUGH_DISTS)) 213 | return 1; 214 | 215 | /* process all codes and make table entries */ 216 | for (;;) { 217 | /* create table entry */ 218 | here.bits = (unsigned char)(len - drop); 219 | if ((int)(work[sym]) < end) { 220 | here.op = (unsigned char)0; 221 | here.val = work[sym]; 222 | } 223 | else if ((int)(work[sym]) > end) { 224 | here.op = (unsigned char)(extra[work[sym]]); 225 | here.val = base[work[sym]]; 226 | } 227 | else { 228 | here.op = (unsigned char)(32 + 64); /* end of block */ 229 | here.val = 0; 230 | } 231 | 232 | /* replicate for those indices with low len bits equal to huff */ 233 | incr = 1U << (len - drop); 234 | fill = 1U << curr; 235 | min = fill; /* save offset to next table */ 236 | do { 237 | fill -= incr; 238 | next[(huff >> drop) + fill] = here; 239 | } while (fill != 0); 240 | 241 | /* backwards increment the len-bit code huff */ 242 | incr = 1U << (len - 1); 243 | while (huff & incr) 244 | incr >>= 1; 245 | if (incr != 0) { 246 | huff &= incr - 1; 247 | huff += incr; 248 | } 249 | else 250 | huff = 0; 251 | 252 | /* go to next symbol, update count, len */ 253 | sym++; 254 | if (--(count[len]) == 0) { 255 | if (len == max) break; 256 | len = lens[work[sym]]; 257 | } 258 | 259 | /* create new sub-table if needed */ 260 | if (len > root && (huff & mask) != low) { 261 | /* if first time, transition to sub-tables */ 262 | if (drop == 0) 263 | drop = root; 264 | 265 | /* increment past last table */ 266 | next += min; /* here min is 1 << curr */ 267 | 268 | /* determine length of next table */ 269 | curr = len - drop; 270 | left = (int)(1 << curr); 271 | while (curr + drop < max) { 272 | left -= count[curr + drop]; 273 | if (left <= 0) break; 274 | curr++; 275 | left <<= 1; 276 | } 277 | 278 | /* check for enough space */ 279 | used += 1U << curr; 280 | if ((type == LENS && used >= ENOUGH_LENS) || 281 | (type == DISTS && used >= ENOUGH_DISTS)) 282 | return 1; 283 | 284 | /* point entry in root table to sub-table */ 285 | low = huff & mask; 286 | (*table)[low].op = (unsigned char)curr; 287 | (*table)[low].bits = (unsigned char)root; 288 | (*table)[low].val = (unsigned short)(next - *table); 289 | } 290 | } 291 | 292 | /* fill in remaining table entry if code is incomplete (guaranteed to have 293 | at most one remaining entry, since if the code is incomplete, the 294 | maximum code length that was allowed to get this far is one bit) */ 295 | if (huff != 0) { 296 | here.op = (unsigned char)64; /* invalid code marker */ 297 | here.bits = (unsigned char)(len - drop); 298 | here.val = (unsigned short)0; 299 | next[huff] = here; 300 | } 301 | 302 | /* set return parameters */ 303 | *table += used; 304 | *bits = root; 305 | return 0; 306 | } 307 | -------------------------------------------------------------------------------- /XlogDecode/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 | -------------------------------------------------------------------------------- /XlogDecode/zlib/trees.h: -------------------------------------------------------------------------------- 1 | /* header created automatically with -DGEN_TREES_H */ 2 | 3 | local const ct_data static_ltree[L_CODES+2] = { 4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 | }; 63 | 64 | local const ct_data static_dtree[D_CODES] = { 65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 | }; 72 | 73 | const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { 74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 | }; 101 | 102 | const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 | }; 117 | 118 | local const int base_length[LENGTH_CODES] = { 119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 | 64, 80, 96, 112, 128, 160, 192, 224, 0 121 | }; 122 | 123 | local const int base_dist[D_CODES] = { 124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /XlogDecode/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 = (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 | -------------------------------------------------------------------------------- /XlogDecode/zlib/zconf.h: -------------------------------------------------------------------------------- 1 | /* zconf.h -- configuration of the zlib compression library 2 | * Copyright (C) 1995-2012 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #ifndef ZCONF_H 9 | #define ZCONF_H 10 | 11 | /* 12 | * If you *really* need a unique prefix for all types and library functions, 13 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 14 | * Even better than compiling with -DZ_PREFIX would be to use configure to set 15 | * this permanently in zconf.h using "./configure --zprefix". 16 | */ 17 | #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ 18 | # define Z_PREFIX_SET 19 | 20 | /* all linked symbols */ 21 | # define _dist_code z__dist_code 22 | # define _length_code z__length_code 23 | # define _tr_align z__tr_align 24 | # define _tr_flush_block z__tr_flush_block 25 | # define _tr_init z__tr_init 26 | # define _tr_stored_block z__tr_stored_block 27 | # define _tr_tally z__tr_tally 28 | # define adler32 z_adler32 29 | # define adler32_combine z_adler32_combine 30 | # define adler32_combine64 z_adler32_combine64 31 | # ifndef Z_SOLO 32 | # define compress z_compress 33 | # define compress2 z_compress2 34 | # define compressBound z_compressBound 35 | # endif 36 | # define crc32 z_crc32 37 | # define crc32_combine z_crc32_combine 38 | # define crc32_combine64 z_crc32_combine64 39 | # define deflate z_deflate 40 | # define deflateBound z_deflateBound 41 | # define deflateCopy z_deflateCopy 42 | # define deflateEnd z_deflateEnd 43 | # define deflateInit2_ z_deflateInit2_ 44 | # define deflateInit_ z_deflateInit_ 45 | # define deflateParams z_deflateParams 46 | # define deflatePending z_deflatePending 47 | # define deflatePrime z_deflatePrime 48 | # define deflateReset z_deflateReset 49 | # define deflateResetKeep z_deflateResetKeep 50 | # define deflateSetDictionary z_deflateSetDictionary 51 | # define deflateSetHeader z_deflateSetHeader 52 | # define deflateTune z_deflateTune 53 | # define deflate_copyright z_deflate_copyright 54 | # define get_crc_table z_get_crc_table 55 | # ifndef Z_SOLO 56 | # define gz_error z_gz_error 57 | # define gz_intmax z_gz_intmax 58 | # define gz_strwinerror z_gz_strwinerror 59 | # define gzbuffer z_gzbuffer 60 | # define gzclearerr z_gzclearerr 61 | # define gzclose z_gzclose 62 | # define gzclose_r z_gzclose_r 63 | # define gzclose_w z_gzclose_w 64 | # define gzdirect z_gzdirect 65 | # define gzdopen z_gzdopen 66 | # define gzeof z_gzeof 67 | # define gzerror z_gzerror 68 | # define gzflush z_gzflush 69 | # define gzgetc z_gzgetc 70 | # define gzgetc_ z_gzgetc_ 71 | # define gzgets z_gzgets 72 | # define gzoffset z_gzoffset 73 | # define gzoffset64 z_gzoffset64 74 | # define gzopen z_gzopen 75 | # define gzopen64 z_gzopen64 76 | # ifdef _WIN32 77 | # define gzopen_w z_gzopen_w 78 | # endif 79 | # define gzprintf z_gzprintf 80 | # define gzputc z_gzputc 81 | # define gzputs z_gzputs 82 | # define gzread z_gzread 83 | # define gzrewind z_gzrewind 84 | # define gzseek z_gzseek 85 | # define gzseek64 z_gzseek64 86 | # define gzsetparams z_gzsetparams 87 | # define gztell z_gztell 88 | # define gztell64 z_gztell64 89 | # define gzungetc z_gzungetc 90 | # define gzwrite z_gzwrite 91 | # endif 92 | # define inflate z_inflate 93 | # define inflateBack z_inflateBack 94 | # define inflateBackEnd z_inflateBackEnd 95 | # define inflateBackInit_ z_inflateBackInit_ 96 | # define inflateCopy z_inflateCopy 97 | # define inflateEnd z_inflateEnd 98 | # define inflateGetHeader z_inflateGetHeader 99 | # define inflateInit2_ z_inflateInit2_ 100 | # define inflateInit_ z_inflateInit_ 101 | # define inflateMark z_inflateMark 102 | # define inflatePrime z_inflatePrime 103 | # define inflateReset z_inflateReset 104 | # define inflateReset2 z_inflateReset2 105 | # define inflateSetDictionary z_inflateSetDictionary 106 | # define inflateSync z_inflateSync 107 | # define inflateSyncPoint z_inflateSyncPoint 108 | # define inflateUndermine z_inflateUndermine 109 | # define inflateResetKeep z_inflateResetKeep 110 | # define inflate_copyright z_inflate_copyright 111 | # define inflate_fast z_inflate_fast 112 | # define inflate_table z_inflate_table 113 | # ifndef Z_SOLO 114 | # define uncompress z_uncompress 115 | # endif 116 | # define zError z_zError 117 | # ifndef Z_SOLO 118 | # define zcalloc z_zcalloc 119 | # define zcfree z_zcfree 120 | # endif 121 | # define zlibCompileFlags z_zlibCompileFlags 122 | # define zlibVersion z_zlibVersion 123 | 124 | /* all zlib typedefs in zlib.h and zconf.h */ 125 | # define Byte z_Byte 126 | # define Bytef z_Bytef 127 | # define alloc_func z_alloc_func 128 | # define charf z_charf 129 | # define free_func z_free_func 130 | # ifndef Z_SOLO 131 | # define gzFile z_gzFile 132 | # endif 133 | # define gz_header z_gz_header 134 | # define gz_headerp z_gz_headerp 135 | # define in_func z_in_func 136 | # define intf z_intf 137 | # define out_func z_out_func 138 | # define uInt z_uInt 139 | # define uIntf z_uIntf 140 | # define uLong z_uLong 141 | # define uLongf z_uLongf 142 | # define voidp z_voidp 143 | # define voidpc z_voidpc 144 | # define voidpf z_voidpf 145 | 146 | /* all zlib structs in zlib.h and zconf.h */ 147 | # define gz_header_s z_gz_header_s 148 | # define internal_state z_internal_state 149 | 150 | #endif 151 | 152 | #if defined(__MSDOS__) && !defined(MSDOS) 153 | # define MSDOS 154 | #endif 155 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 156 | # define OS2 157 | #endif 158 | #if defined(_WINDOWS) && !defined(WINDOWS) 159 | # define WINDOWS 160 | #endif 161 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 162 | # ifndef WIN32 163 | # define WIN32 164 | # endif 165 | #endif 166 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 167 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 168 | # ifndef SYS16BIT 169 | # define SYS16BIT 170 | # endif 171 | # endif 172 | #endif 173 | 174 | /* 175 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 176 | * than 64k bytes at a time (needed on systems with 16-bit int). 177 | */ 178 | #ifdef SYS16BIT 179 | # define MAXSEG_64K 180 | #endif 181 | #ifdef MSDOS 182 | # define UNALIGNED_OK 183 | #endif 184 | 185 | #ifdef __STDC_VERSION__ 186 | # ifndef STDC 187 | # define STDC 188 | # endif 189 | # if __STDC_VERSION__ >= 199901L 190 | # ifndef STDC99 191 | # define STDC99 192 | # endif 193 | # endif 194 | #endif 195 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 196 | # define STDC 197 | #endif 198 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 199 | # define STDC 200 | #endif 201 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 202 | # define STDC 203 | #endif 204 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 205 | # define STDC 206 | #endif 207 | 208 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 209 | # define STDC 210 | #endif 211 | 212 | #ifndef STDC 213 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 214 | # define const /* note: need a more gentle solution here */ 215 | # endif 216 | #endif 217 | 218 | #if defined(ZLIB_CONST) && !defined(z_const) 219 | # define z_const const 220 | #else 221 | # define z_const 222 | #endif 223 | 224 | /* Some Mac compilers merge all .h files incorrectly: */ 225 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 226 | # define NO_DUMMY_DECL 227 | #endif 228 | 229 | /* Maximum value for memLevel in deflateInit2 */ 230 | #ifndef MAX_MEM_LEVEL 231 | # ifdef MAXSEG_64K 232 | # define MAX_MEM_LEVEL 8 233 | # else 234 | # define MAX_MEM_LEVEL 9 235 | # endif 236 | #endif 237 | 238 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. 239 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 240 | * created by gzip. (Files created by minigzip can still be extracted by 241 | * gzip.) 242 | */ 243 | #ifndef MAX_WBITS 244 | # define MAX_WBITS 15 /* 32K LZ77 window */ 245 | #endif 246 | 247 | /* The memory requirements for deflate are (in bytes): 248 | (1 << (windowBits+2)) + (1 << (memLevel+9)) 249 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 250 | plus a few kilobytes for small objects. For example, if you want to reduce 251 | the default memory requirements from 256K to 128K, compile with 252 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 253 | Of course this will generally degrade compression (there's no free lunch). 254 | 255 | The memory requirements for inflate are (in bytes) 1 << windowBits 256 | that is, 32K for windowBits=15 (default value) plus a few kilobytes 257 | for small objects. 258 | */ 259 | 260 | /* Type declarations */ 261 | 262 | #ifndef OF /* function prototypes */ 263 | # ifdef STDC 264 | # define OF(args) args 265 | # else 266 | # define OF(args) () 267 | # endif 268 | #endif 269 | 270 | #ifndef Z_ARG /* function prototypes for stdarg */ 271 | # if defined(STDC) || defined(Z_HAVE_STDARG_H) 272 | # define Z_ARG(args) args 273 | # else 274 | # define Z_ARG(args) () 275 | # endif 276 | #endif 277 | 278 | /* The following definitions for FAR are needed only for MSDOS mixed 279 | * model programming (small or medium model with some far allocations). 280 | * This was tested only with MSC; for other MSDOS compilers you may have 281 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 282 | * just define FAR to be empty. 283 | */ 284 | #ifdef SYS16BIT 285 | # if defined(M_I86SM) || defined(M_I86MM) 286 | /* MSC small or medium model */ 287 | # define SMALL_MEDIUM 288 | # ifdef _MSC_VER 289 | # define FAR _far 290 | # else 291 | # define FAR far 292 | # endif 293 | # endif 294 | # if (defined(__SMALL__) || defined(__MEDIUM__)) 295 | /* Turbo C small or medium model */ 296 | # define SMALL_MEDIUM 297 | # ifdef __BORLANDC__ 298 | # define FAR _far 299 | # else 300 | # define FAR far 301 | # endif 302 | # endif 303 | #endif 304 | 305 | #if defined(WINDOWS) || defined(WIN32) 306 | /* If building or using zlib as a DLL, define ZLIB_DLL. 307 | * This is not mandatory, but it offers a little performance increase. 308 | */ 309 | # ifdef ZLIB_DLL 310 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 311 | # ifdef ZLIB_INTERNAL 312 | # define ZEXTERN extern __declspec(dllexport) 313 | # else 314 | # define ZEXTERN extern __declspec(dllimport) 315 | # endif 316 | # endif 317 | # endif /* ZLIB_DLL */ 318 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, 319 | * define ZLIB_WINAPI. 320 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 321 | */ 322 | # ifdef ZLIB_WINAPI 323 | # ifdef FAR 324 | # undef FAR 325 | # endif 326 | # include 327 | /* No need for _export, use ZLIB.DEF instead. */ 328 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 329 | # define ZEXPORT WINAPI 330 | # ifdef WIN32 331 | # define ZEXPORTVA WINAPIV 332 | # else 333 | # define ZEXPORTVA FAR CDECL 334 | # endif 335 | # endif 336 | #endif 337 | 338 | #if defined (__BEOS__) 339 | # ifdef ZLIB_DLL 340 | # ifdef ZLIB_INTERNAL 341 | # define ZEXPORT __declspec(dllexport) 342 | # define ZEXPORTVA __declspec(dllexport) 343 | # else 344 | # define ZEXPORT __declspec(dllimport) 345 | # define ZEXPORTVA __declspec(dllimport) 346 | # endif 347 | # endif 348 | #endif 349 | 350 | #ifndef ZEXTERN 351 | # define ZEXTERN extern 352 | #endif 353 | #ifndef ZEXPORT 354 | # define ZEXPORT 355 | #endif 356 | #ifndef ZEXPORTVA 357 | # define ZEXPORTVA 358 | #endif 359 | 360 | #ifndef FAR 361 | # define FAR 362 | #endif 363 | 364 | #if !defined(__MACTYPES__) 365 | typedef unsigned char Byte; /* 8 bits */ 366 | #endif 367 | typedef unsigned int uInt; /* 16 bits or more */ 368 | typedef unsigned long uLong; /* 32 bits or more */ 369 | 370 | #ifdef SMALL_MEDIUM 371 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 372 | # define Bytef Byte FAR 373 | #else 374 | typedef Byte FAR Bytef; 375 | #endif 376 | typedef char FAR charf; 377 | typedef int FAR intf; 378 | typedef uInt FAR uIntf; 379 | typedef uLong FAR uLongf; 380 | 381 | #ifdef STDC 382 | typedef void const *voidpc; 383 | typedef void FAR *voidpf; 384 | typedef void *voidp; 385 | #else 386 | typedef Byte const *voidpc; 387 | typedef Byte FAR *voidpf; 388 | typedef Byte *voidp; 389 | #endif 390 | 391 | /* ./configure may #define Z_U4 here */ 392 | 393 | #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) 394 | # include 395 | # if (UINT_MAX == 0xffffffffUL) 396 | # define Z_U4 unsigned 397 | # else 398 | # if (ULONG_MAX == 0xffffffffUL) 399 | # define Z_U4 unsigned long 400 | # else 401 | # if (USHRT_MAX == 0xffffffffUL) 402 | # define Z_U4 unsigned short 403 | # endif 404 | # endif 405 | # endif 406 | #endif 407 | 408 | #ifdef Z_U4 409 | typedef Z_U4 z_crc_t; 410 | #else 411 | typedef unsigned long z_crc_t; 412 | #endif 413 | 414 | #ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ 415 | # define Z_HAVE_UNISTD_H 416 | #endif 417 | 418 | #ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ 419 | # define Z_HAVE_STDARG_H 420 | #endif 421 | 422 | #ifdef STDC 423 | # ifndef Z_SOLO 424 | //# include /* for off_t */ 425 | # endif 426 | #endif 427 | 428 | #ifdef _WIN32 429 | # include /* for wchar_t */ 430 | #endif 431 | 432 | /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 433 | * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even 434 | * though the former does not conform to the LFS document), but considering 435 | * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as 436 | * equivalently requesting no 64-bit operations 437 | */ 438 | #if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 439 | # undef _LARGEFILE64_SOURCE 440 | #endif 441 | 442 | #if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) 443 | # define Z_HAVE_UNISTD_H 444 | #endif 445 | #ifndef Z_SOLO 446 | # if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) 447 | # include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ 448 | # ifdef VMS 449 | # include /* for off_t */ 450 | # endif 451 | # ifndef z_off_t 452 | # define z_off_t off_t 453 | # endif 454 | # endif 455 | #endif 456 | 457 | #if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 458 | # define Z_LFS64 459 | #endif 460 | 461 | #if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) 462 | # define Z_LARGE64 463 | #endif 464 | 465 | #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) 466 | # define Z_WANT64 467 | #endif 468 | 469 | #if !defined(SEEK_SET) && !defined(Z_SOLO) 470 | # define SEEK_SET 0 /* Seek from beginning of file. */ 471 | # define SEEK_CUR 1 /* Seek from current position. */ 472 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 473 | #endif 474 | 475 | #ifndef z_off_t 476 | # define z_off_t long 477 | #endif 478 | 479 | #if !defined(_WIN32) && defined(Z_LARGE64) 480 | # define z_off64_t off64_t 481 | #else 482 | # if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) 483 | # define z_off64_t __int64 484 | # else 485 | # define z_off64_t z_off_t 486 | # endif 487 | #endif 488 | 489 | /* MVS linker does not support external names larger than 8 bytes */ 490 | #if defined(__MVS__) 491 | #pragma map(deflateInit_,"DEIN") 492 | #pragma map(deflateInit2_,"DEIN2") 493 | #pragma map(deflateEnd,"DEEND") 494 | #pragma map(deflateBound,"DEBND") 495 | #pragma map(inflateInit_,"ININ") 496 | #pragma map(inflateInit2_,"ININ2") 497 | #pragma map(inflateEnd,"INEND") 498 | #pragma map(inflateSync,"INSY") 499 | #pragma map(inflateSetDictionary,"INSEDI") 500 | #pragma map(compressBound,"CMBND") 501 | #pragma map(inflate_table,"INTABL") 502 | #pragma map(inflate_fast,"INFA") 503 | #pragma map(inflate_copyright,"INCOPY") 504 | #endif 505 | 506 | #endif /* ZCONF_H */ 507 | -------------------------------------------------------------------------------- /XlogDecode/zlib/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | #ifndef Z_SOLO 10 | # include "gzguts.h" 11 | #endif 12 | 13 | #ifndef NO_DUMMY_DECL 14 | struct internal_state {int dummy;}; /* for buggy compilers */ 15 | #endif 16 | 17 | const char * const z_errmsg[10] = { 18 | "need dictionary", /* Z_NEED_DICT 2 */ 19 | "stream end", /* Z_STREAM_END 1 */ 20 | "", /* Z_OK 0 */ 21 | "file error", /* Z_ERRNO (-1) */ 22 | "stream error", /* Z_STREAM_ERROR (-2) */ 23 | "data error", /* Z_DATA_ERROR (-3) */ 24 | "insufficient memory", /* Z_MEM_ERROR (-4) */ 25 | "buffer error", /* Z_BUF_ERROR (-5) */ 26 | "incompatible version",/* Z_VERSION_ERROR (-6) */ 27 | ""}; 28 | 29 | 30 | const char * ZEXPORT zlibVersion() 31 | { 32 | return ZLIB_VERSION; 33 | } 34 | 35 | uLong ZEXPORT zlibCompileFlags() 36 | { 37 | uLong flags; 38 | 39 | flags = 0; 40 | switch ((int)(sizeof(uInt))) { 41 | case 2: break; 42 | case 4: flags += 1; break; 43 | case 8: flags += 2; break; 44 | default: flags += 3; 45 | } 46 | switch ((int)(sizeof(uLong))) { 47 | case 2: break; 48 | case 4: flags += 1 << 2; break; 49 | case 8: flags += 2 << 2; break; 50 | default: flags += 3 << 2; 51 | } 52 | switch ((int)(sizeof(voidpf))) { 53 | case 2: break; 54 | case 4: flags += 1 << 4; break; 55 | case 8: flags += 2 << 4; break; 56 | default: flags += 3 << 4; 57 | } 58 | switch ((int)(sizeof(z_off_t))) { 59 | case 2: break; 60 | case 4: flags += 1 << 6; break; 61 | case 8: flags += 2 << 6; break; 62 | default: flags += 3 << 6; 63 | } 64 | #ifdef DEBUG 65 | flags += 1 << 8; 66 | #endif 67 | #if defined(ASMV) || defined(ASMINF) 68 | flags += 1 << 9; 69 | #endif 70 | #ifdef ZLIB_WINAPI 71 | flags += 1 << 10; 72 | #endif 73 | #ifdef BUILDFIXED 74 | flags += 1 << 12; 75 | #endif 76 | #ifdef DYNAMIC_CRC_TABLE 77 | flags += 1 << 13; 78 | #endif 79 | #ifdef NO_GZCOMPRESS 80 | flags += 1L << 16; 81 | #endif 82 | #ifdef NO_GZIP 83 | flags += 1L << 17; 84 | #endif 85 | #ifdef PKZIP_BUG_WORKAROUND 86 | flags += 1L << 20; 87 | #endif 88 | #ifdef FASTEST 89 | flags += 1L << 21; 90 | #endif 91 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) 92 | # ifdef NO_vsnprintf 93 | flags += 1L << 25; 94 | # ifdef HAS_vsprintf_void 95 | flags += 1L << 26; 96 | # endif 97 | # else 98 | # ifdef HAS_vsnprintf_void 99 | flags += 1L << 26; 100 | # endif 101 | # endif 102 | #else 103 | flags += 1L << 24; 104 | # ifdef NO_snprintf 105 | flags += 1L << 25; 106 | # ifdef HAS_sprintf_void 107 | flags += 1L << 26; 108 | # endif 109 | # else 110 | # ifdef HAS_snprintf_void 111 | flags += 1L << 26; 112 | # endif 113 | # endif 114 | #endif 115 | return flags; 116 | } 117 | 118 | #ifdef DEBUG 119 | 120 | # ifndef verbose 121 | # define verbose 0 122 | # endif 123 | int ZLIB_INTERNAL z_verbose = verbose; 124 | 125 | void ZLIB_INTERNAL z_error (m) 126 | char *m; 127 | { 128 | fprintf(stderr, "%s\n", m); 129 | exit(1); 130 | } 131 | #endif 132 | 133 | /* exported to allow conversion of error code to string for compress() and 134 | * uncompress() 135 | */ 136 | const char * ZEXPORT zError(err) 137 | int err; 138 | { 139 | return ERR_MSG(err); 140 | } 141 | 142 | #if defined(_WIN32_WCE) 143 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 144 | * errno. We define it as a global variable to simplify porting. 145 | * Its value is always 0 and should not be used. 146 | */ 147 | int errno = 0; 148 | #endif 149 | 150 | #ifndef HAVE_MEMCPY 151 | 152 | void ZLIB_INTERNAL zmemcpy(dest, source, len) 153 | Bytef* dest; 154 | const Bytef* source; 155 | uInt len; 156 | { 157 | if (len == 0) return; 158 | do { 159 | *dest++ = *source++; /* ??? to be unrolled */ 160 | } while (--len != 0); 161 | } 162 | 163 | int ZLIB_INTERNAL zmemcmp(s1, s2, len) 164 | const Bytef* s1; 165 | const Bytef* s2; 166 | uInt len; 167 | { 168 | uInt j; 169 | 170 | for (j = 0; j < len; j++) { 171 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 172 | } 173 | return 0; 174 | } 175 | 176 | void ZLIB_INTERNAL zmemzero(dest, len) 177 | Bytef* dest; 178 | uInt len; 179 | { 180 | if (len == 0) return; 181 | do { 182 | *dest++ = 0; /* ??? to be unrolled */ 183 | } while (--len != 0); 184 | } 185 | #endif 186 | 187 | #ifndef Z_SOLO 188 | 189 | #ifdef SYS16BIT 190 | 191 | #ifdef __TURBOC__ 192 | /* Turbo C in 16-bit mode */ 193 | 194 | # define MY_ZCALLOC 195 | 196 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 197 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 198 | * must fix the pointer. Warning: the pointer must be put back to its 199 | * original form in order to free it, use zcfree(). 200 | */ 201 | 202 | #define MAX_PTR 10 203 | /* 10*64K = 640K */ 204 | 205 | local int next_ptr = 0; 206 | 207 | typedef struct ptr_table_s { 208 | voidpf org_ptr; 209 | voidpf new_ptr; 210 | } ptr_table; 211 | 212 | local ptr_table table[MAX_PTR]; 213 | /* This table is used to remember the original form of pointers 214 | * to large buffers (64K). Such pointers are normalized with a zero offset. 215 | * Since MSDOS is not a preemptive multitasking OS, this table is not 216 | * protected from concurrent access. This hack doesn't work anyway on 217 | * a protected system like OS/2. Use Microsoft C instead. 218 | */ 219 | 220 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) 221 | { 222 | voidpf buf = opaque; /* just to make some compilers happy */ 223 | ulg bsize = (ulg)items*size; 224 | 225 | /* If we allocate less than 65520 bytes, we assume that farmalloc 226 | * will return a usable pointer which doesn't have to be normalized. 227 | */ 228 | if (bsize < 65520L) { 229 | buf = farmalloc(bsize); 230 | if (*(ush*)&buf != 0) return buf; 231 | } else { 232 | buf = farmalloc(bsize + 16L); 233 | } 234 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 235 | table[next_ptr].org_ptr = buf; 236 | 237 | /* Normalize the pointer to seg:0 */ 238 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 239 | *(ush*)&buf = 0; 240 | table[next_ptr++].new_ptr = buf; 241 | return buf; 242 | } 243 | 244 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 245 | { 246 | int n; 247 | if (*(ush*)&ptr != 0) { /* object < 64K */ 248 | farfree(ptr); 249 | return; 250 | } 251 | /* Find the original pointer */ 252 | for (n = 0; n < next_ptr; n++) { 253 | if (ptr != table[n].new_ptr) continue; 254 | 255 | farfree(table[n].org_ptr); 256 | while (++n < next_ptr) { 257 | table[n-1] = table[n]; 258 | } 259 | next_ptr--; 260 | return; 261 | } 262 | ptr = opaque; /* just to make some compilers happy */ 263 | Assert(0, "zcfree: ptr not found"); 264 | } 265 | 266 | #endif /* __TURBOC__ */ 267 | 268 | 269 | #ifdef M_I86 270 | /* Microsoft C in 16-bit mode */ 271 | 272 | # define MY_ZCALLOC 273 | 274 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 275 | # define _halloc halloc 276 | # define _hfree hfree 277 | #endif 278 | 279 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) 280 | { 281 | if (opaque) opaque = 0; /* to make compiler happy */ 282 | return _halloc((long)items, size); 283 | } 284 | 285 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 286 | { 287 | if (opaque) opaque = 0; /* to make compiler happy */ 288 | _hfree(ptr); 289 | } 290 | 291 | #endif /* M_I86 */ 292 | 293 | #endif /* SYS16BIT */ 294 | 295 | 296 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 297 | 298 | #ifndef STDC 299 | extern voidp malloc OF((uInt size)); 300 | extern voidp calloc OF((uInt items, uInt size)); 301 | extern void free OF((voidpf ptr)); 302 | #endif 303 | 304 | voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) 305 | voidpf opaque; 306 | unsigned items; 307 | unsigned size; 308 | { 309 | if (opaque) items += size - size; /* make compiler happy */ 310 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 311 | (voidpf)calloc(items, size); 312 | } 313 | 314 | void ZLIB_INTERNAL zcfree (opaque, ptr) 315 | voidpf opaque; 316 | voidpf ptr; 317 | { 318 | free(ptr); 319 | if (opaque) return; /* make compiler happy */ 320 | } 321 | 322 | #endif /* MY_ZCALLOC */ 323 | 324 | #endif /* !Z_SOLO */ 325 | -------------------------------------------------------------------------------- /XlogDecode/zlib/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2012 Jean-loup Gailly. 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 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #ifdef HAVE_HIDDEN 17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 18 | #else 19 | # define ZLIB_INTERNAL 20 | #endif 21 | 22 | #include "zlib.h" 23 | 24 | #if defined(STDC) && !defined(Z_SOLO) 25 | # if !(defined(_WIN32_WCE) && defined(_MSC_VER)) 26 | # include 27 | # endif 28 | # include 29 | # include 30 | #endif 31 | 32 | #ifdef Z_SOLO 33 | typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ 34 | #endif 35 | 36 | #ifndef local 37 | # define local static 38 | #endif 39 | /* compile with -Dlocal if your debugger can't find static symbols */ 40 | 41 | typedef unsigned char uch; 42 | typedef uch FAR uchf; 43 | typedef unsigned short ush; 44 | typedef ush FAR ushf; 45 | typedef unsigned long ulg; 46 | 47 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 48 | /* (size given to avoid silly warnings with Visual C++) */ 49 | 50 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 51 | 52 | #define ERR_RETURN(strm,err) \ 53 | return (strm->msg = (char*)ERR_MSG(err), (err)) 54 | /* To be used only when the state is known to be valid */ 55 | 56 | /* common constants */ 57 | 58 | #ifndef DEF_WBITS 59 | # define DEF_WBITS MAX_WBITS 60 | #endif 61 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 62 | 63 | #if MAX_MEM_LEVEL >= 8 64 | # define DEF_MEM_LEVEL 8 65 | #else 66 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 67 | #endif 68 | /* default memLevel */ 69 | 70 | #define STORED_BLOCK 0 71 | #define STATIC_TREES 1 72 | #define DYN_TREES 2 73 | /* The three kinds of block type */ 74 | 75 | #define MIN_MATCH 3 76 | #define MAX_MATCH 258 77 | /* The minimum and maximum match lengths */ 78 | 79 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 80 | 81 | /* target dependencies */ 82 | 83 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 84 | # define OS_CODE 0x00 85 | # ifndef Z_SOLO 86 | # if defined(__TURBOC__) || defined(__BORLANDC__) 87 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 88 | /* Allow compilation with ANSI keywords only enabled */ 89 | void _Cdecl farfree( void *block ); 90 | void *_Cdecl farmalloc( unsigned long nbytes ); 91 | # else 92 | # include 93 | # endif 94 | # else /* MSC or DJGPP */ 95 | # include 96 | # endif 97 | # endif 98 | #endif 99 | 100 | #ifdef AMIGA 101 | # define OS_CODE 0x01 102 | #endif 103 | 104 | #if defined(VAXC) || defined(VMS) 105 | # define OS_CODE 0x02 106 | # define F_OPEN(name, mode) \ 107 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 108 | #endif 109 | 110 | #if defined(ATARI) || defined(atarist) 111 | # define OS_CODE 0x05 112 | #endif 113 | 114 | #ifdef OS2 115 | # define OS_CODE 0x06 116 | # if defined(M_I86) && !defined(Z_SOLO) 117 | # include 118 | # endif 119 | #endif 120 | 121 | #if defined(MACOS) || defined(TARGET_OS_MAC) 122 | # define OS_CODE 0x07 123 | # ifndef Z_SOLO 124 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 125 | # include /* for fdopen */ 126 | # else 127 | # ifndef fdopen 128 | # define fdopen(fd,mode) NULL /* No fdopen() */ 129 | # endif 130 | # endif 131 | # endif 132 | #endif 133 | 134 | #ifdef TOPS20 135 | # define OS_CODE 0x0a 136 | #endif 137 | 138 | #ifdef WIN32 139 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 140 | # define OS_CODE 0x0b 141 | # endif 142 | #endif 143 | 144 | #ifdef __50SERIES /* Prime/PRIMOS */ 145 | # define OS_CODE 0x0f 146 | #endif 147 | 148 | #if defined(_BEOS_) || defined(RISCOS) 149 | # define fdopen(fd,mode) NULL /* No fdopen() */ 150 | #endif 151 | 152 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX 153 | # if defined(_WIN32_WCE) 154 | # define fdopen(fd,mode) NULL /* No fdopen() */ 155 | # ifndef _PTRDIFF_T_DEFINED 156 | typedef int ptrdiff_t; 157 | # define _PTRDIFF_T_DEFINED 158 | # endif 159 | # else 160 | # define fdopen(fd,type) _fdopen(fd,type) 161 | # endif 162 | #endif 163 | 164 | #if defined(__BORLANDC__) && !defined(MSDOS) 165 | #pragma warn -8004 166 | #pragma warn -8008 167 | #pragma warn -8066 168 | #endif 169 | 170 | /* provide prototypes for these when building zlib without LFS */ 171 | #if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) 172 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 173 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 174 | #endif 175 | 176 | /* common defaults */ 177 | 178 | #ifndef OS_CODE 179 | # define OS_CODE 0x03 /* assume Unix */ 180 | #endif 181 | 182 | #ifndef F_OPEN 183 | # define F_OPEN(name, mode) fopen((name), (mode)) 184 | #endif 185 | 186 | /* functions */ 187 | 188 | #if defined(pyr) || defined(Z_SOLO) 189 | # define NO_MEMCPY 190 | #endif 191 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 192 | /* Use our own functions for small and medium model with MSC <= 5.0. 193 | * You may have to use the same strategy for Borland C (untested). 194 | * The __SC__ check is for Symantec. 195 | */ 196 | # define NO_MEMCPY 197 | #endif 198 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 199 | # define HAVE_MEMCPY 200 | #endif 201 | #ifdef HAVE_MEMCPY 202 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 203 | # define zmemcpy _fmemcpy 204 | # define zmemcmp _fmemcmp 205 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 206 | # else 207 | # define zmemcpy memcpy 208 | # define zmemcmp memcmp 209 | # define zmemzero(dest, len) memset(dest, 0, len) 210 | # endif 211 | #else 212 | void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 213 | int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 214 | void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); 215 | #endif 216 | 217 | /* Diagnostic functions */ 218 | #ifdef DEBUG 219 | # include 220 | extern int ZLIB_INTERNAL z_verbose; 221 | extern void ZLIB_INTERNAL z_error OF((char *m)); 222 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 223 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 224 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 225 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 226 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 227 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 228 | #else 229 | # define Assert(cond,msg) 230 | # define Trace(x) 231 | # define Tracev(x) 232 | # define Tracevv(x) 233 | # define Tracec(c,x) 234 | # define Tracecv(c,x) 235 | #endif 236 | 237 | #ifndef Z_SOLO 238 | voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, 239 | unsigned size)); 240 | void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); 241 | #endif 242 | 243 | #define ZALLOC(strm, items, size) \ 244 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 245 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 246 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 247 | 248 | /* Reverse the bytes in a 32-bit value */ 249 | #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 250 | (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 251 | 252 | #endif /* ZUTIL_H */ 253 | --------------------------------------------------------------------------------