70#define CHM_ACQUIRE_LOCK(a) do { \
71 EnterCriticalSection(&(a)); \
73#define CHM_RELEASE_LOCK(a) do { \
74 LeaveCriticalSection(&(a)); \
77#define CHM_NULL_FD (INVALID_HANDLE_VALUE)
78#define CHM_CLOSE_FILE(fd) CloseHandle((fd))
83#ifndef CHM_MAX_BLOCKS_CACHED
84#define CHM_MAX_BLOCKS_CACHED 5
86#define CHM_PARAM_MAX_BLOCKS_CACHED 0
110 unsigned int *pLenRemain,
114 if (
count <= 0 || (
unsigned int)
count > *pLenRemain)
118 *pLenRemain -=
count;
123 unsigned int *pLenRemain,
127 if (
count <= 0 || (
unsigned int)
count > *pLenRemain)
131 *pLenRemain -=
count;
136 unsigned int *pLenRemain,
141 *
dest = (*pData)[0] | (*pData)[1]<<8 | (*pData)[2]<<16 | (*pData)[3]<<24;
148 unsigned int *pLenRemain,
153 *
dest = (*pData)[0] | (*pData)[1]<<8 | (*pData)[2]<<16 | (*pData)[3]<<24;
160 unsigned int *pLenRemain,
171 temp |= (*pData)[
i-1];
180 unsigned int *pLenRemain,
191 temp |= (*pData)[
i-1];
200 unsigned int *pDataLen,
211#define _CHM_ITSF_V2_LEN (0x58)
212#define _CHM_ITSF_V3_LEN (0x60)
231 unsigned int *pDataLen,
258 if (
dest->version == 2)
263 else if (
dest->version == 3)
274 if (
dest->version == 3)
288#define _CHM_ITSP_V1_LEN (0x54)
309 unsigned int *pDataLen,
336 if (
dest->version != 1)
346#define _CHM_PMGL_LEN (0x14)
357 unsigned int *pDataLen,
380#define _CHM_PMGI_LEN (0x08)
388 unsigned int *pDataLen,
407#define _CHM_LZXC_RESETTABLE_V1_LEN (0x28)
420 unsigned int *pDataLen,
437 if (
dest->version != 2)
444#define _CHM_LZXC_MIN_LEN (0x18)
445#define _CHM_LZXC_V2_LEN (0x1c)
458 unsigned int *pDataLen,
476 dest->unknown_18 = 0;
478 if (
dest->version == 2)
480 dest->resetInterval *= 0x8000;
481 dest->windowSize *= 0x8000;
483 if (
dest->windowSize == 0 ||
dest->resetInterval == 0)
487 if (
dest->windowSize == 1)
489 if ((
dest->resetInterval % (
dest->windowSize/2)) != 0)
596 if (paramVal !=
h->cache_num_blocks)
605 for (
i=0;
i<paramVal;
i++)
614 for (
i=0;
i<
h->cache_num_blocks;
i++)
616 int newSlot = (
int)(
h->cache_block_indices[
i] % paramVal);
618 if (
h->cache_blocks[
i])
621 if (newBlocks[newSlot])
624 h->cache_blocks[
i] =
NULL;
628 newBlocks[newSlot] =
h->cache_blocks[
i];
629 newIndices[newSlot] =
630 h->cache_block_indices[
i];
640 h->cache_blocks = newBlocks;
641 h->cache_block_indices = newIndices;
642 h->cache_num_blocks = paramVal;
655 unsigned char sbuffer[256];
656 unsigned int sremain;
657 unsigned char *sbufpos;
744 L"::DataSpace/Storage/MSCompressed/Transform/"
745 "{7FC28940-9D31-11D0-9B27-00A0C91E9C7C}/"
746 "InstanceData/ResetTable",
750 L"::DataSpace/Storage/MSCompressed/Content",
754 L"::DataSpace/Storage/MSCompressed/ControlData",
767 0, sremain) != sremain ||
781 0, sremain) != sremain ||
808 *newHandle = *oldHandle;
843 h->mutex.DebugInfo->Spare[0] = 0;
845 h->lzx_mutex.DebugInfo->Spare[0] = 0;
847 h->cache_mutex.DebugInfo->Spare[0] = 0;
857 for (
i=0;
i<
h->cache_num_blocks;
i++)
862 h->cache_blocks =
NULL;
866 h->cache_block_indices =
NULL;
879 while (*(*
pEntry)++ >= 0x80)
899 accum +=
temp & 0x7f;
902 return (accum << 7) +
temp;
938 const WCHAR *objPath)
944 unsigned int hremain;
956 end = page_buf + block_len - (
header.free_space);
980 const WCHAR *objPath)
986 unsigned int hremain;
998 end = page_buf + block_len - (
header.free_space);
1021 const WCHAR *objPath,
1034 curPage =
h->index_root;
1037 while (curPage != -1)
1042 h->dir_offset + (
UInt64)curPage*
h->block_len,
1043 h->block_len) !=
h->block_len)
1096 unsigned int remain;
1099 if (block < h->reset_table.block_count-1)
1107 +
h->reset_table.table_offset
1109 remain) != remain ||
1119 +
h->reset_table.table_offset
1121 remain) != remain ||
1135 +
h->reset_table.table_offset
1137 remain) != remain ||
1141 *
len =
h->reset_table.compressed_len;
1146 *
start +=
h->data_offset +
h->cn_unit.start;
1157 ((
unsigned int)
h->reset_table.block_len + 6144));
1166 if (
block - blockAlign <= h->lzx_last_block &&
1167 block >=
h->lzx_last_block)
1168 blockAlign = (
block -
h->lzx_last_block);
1171 if (blockAlign != 0)
1174 for (
i = blockAlign;
i > 0;
i--)
1179 if (
h->lzx_last_block != curBlockIdx)
1181 if ((curBlockIdx %
h->reset_blkcount) == 0)
1189 indexSlot = (
int)((curBlockIdx) %
h->cache_num_blocks);
1190 h->cache_block_indices[indexSlot] = curBlockIdx;
1191 if (!
h->cache_blocks[indexSlot])
1192 h->cache_blocks[indexSlot] =
1194 (
unsigned int)(
h->reset_table.block_len));
1195 lbuffer =
h->cache_blocks[indexSlot];
1199 fprintf(
stderr,
"Decompressing block #%4d (EXTRA)\n", curBlockIdx);
1204 (
int)
h->reset_table.block_len) !=
DECR_OK)
1213 h->lzx_last_block = (
int)curBlockIdx;
1219 if ((
block %
h->reset_blkcount) == 0)
1229 indexSlot = (
int)(
block %
h->cache_num_blocks);
1230 h->cache_block_indices[indexSlot] =
block;
1231 if (!
h->cache_blocks[indexSlot])
1232 h->cache_blocks[indexSlot] =
1234 lbuffer =
h->cache_blocks[indexSlot];
1244 (
int)
h->reset_table.block_len) !=
DECR_OK)
1258 return h->reset_table.block_len;
1276 nBlock =
start /
h->reset_table.block_len;
1277 nOffset =
start %
h->reset_table.block_len;
1279 if (nLen > (
h->reset_table.block_len - nOffset))
1280 nLen =
h->reset_table.block_len - nOffset;
1285 if (
h->cache_block_indices[nBlock %
h->cache_num_blocks] == nBlock &&
1286 h->cache_blocks[nBlock %
h->cache_num_blocks] !=
NULL)
1289 h->cache_blocks[nBlock %
h->cache_num_blocks] + nOffset,
1290 (
unsigned int)nLen);
1300 h->lzx_last_block = -1;
1308 memcpy(
buf, ubuffer+nOffset, (
unsigned int)nLen);
1338 h->data_offset +
ui->start +
addr,
1348 if (!
h->compression_enabled)
1389 unsigned int lenRemain;
1406 curPage =
h->index_head;
1410 prefixLen =
lstrlenW(prefixRectified);
1413 if (prefixRectified[prefixLen-1] !=
'/')
1415 prefixRectified[prefixLen] =
'/';
1416 prefixRectified[prefixLen+1] =
'\0';
1424 while (curPage != -1)
1430 h->dir_offset + (
UInt64)curPage*
h->block_len,
1431 h->block_len) !=
h->block_len)
1445 end = page_buf +
h->block_len - (
header.free_space);
1459 if (
ui.length == 0 &&
wcsnicmp(
ui.path, prefixRectified, prefixLen) == 0)
1460 it_has_begun =
TRUE;
1464 if (
ui.path[prefixLen] ==
'\0')
1471 if (
wcsnicmp(
ui.path, prefixRectified, prefixLen) != 0)
1479 if (lastPathLen != -1)
1481 if (
wcsnicmp(
ui.path, lastPath, lastPathLen) == 0)
1499 if (
ui.path[0] ==
'/')
1503 if (
ui.path[1] ==
'#' ||
ui.path[1] ==
'$')
1510 if (! (what &
flag))
1533 curPage =
header.block_next;
static Int32 _chm_find_in_PMGI(UChar *page_buf, UInt32 block_len, const WCHAR *objPath)
static BOOL _unmarshal_int32(unsigned char **pData, unsigned int *pLenRemain, Int32 *dest)
#define CHM_RELEASE_LOCK(a)
static void _chm_skip_PMGL_entry_data(UChar **pEntry)
#define _CHM_LZXC_RESETTABLE_V1_LEN
static BOOL _unmarshal_uint32(unsigned char **pData, unsigned int *pLenRemain, UInt32 *dest)
#define CHM_ACQUIRE_LOCK(a)
static void chm_set_param(struct chmFile *h, int paramType, int paramVal)
LONGINT64 chm_retrieve_object(struct chmFile *h, struct chmUnitInfo *ui, unsigned char *buf, LONGUINT64 addr, LONGINT64 len)
static BOOL _unmarshal_uuid(unsigned char **pData, unsigned int *pDataLen, unsigned char *dest)
#define CHM_MAX_BLOCKS_CACHED
int chm_resolve_object(struct chmFile *h, const WCHAR *objPath, struct chmUnitInfo *ui)
static BOOL _unmarshal_pmgl_header(unsigned char **pData, unsigned int *pDataLen, struct chmPmglHeader *dest)
#define CHM_PARAM_MAX_BLOCKS_CACHED
#define CHM_CLOSE_FILE(fd)
static const char _chm_pmgi_marker[4]
static Int64 _chm_decompress_region(struct chmFile *h, UChar *buf, UInt64 start, Int64 len)
static UChar * _chm_find_in_PMGL(UChar *page_buf, UInt32 block_len, const WCHAR *objPath)
static BOOL _unmarshal_itsp_header(unsigned char **pData, unsigned int *pDataLen, struct chmItspHeader *dest)
static BOOL _unmarshal_pmgi_header(unsigned char **pData, unsigned int *pDataLen, struct chmPmgiHeader *dest)
static BOOL _unmarshal_lzxc_reset_table(unsigned char **pData, unsigned int *pDataLen, struct chmLzxcResetTable *dest)
static BOOL _unmarshal_char_array(unsigned char **pData, unsigned int *pLenRemain, char *dest, int count)
static BOOL _unmarshal_uchar_array(unsigned char **pData, unsigned int *pLenRemain, unsigned char *dest, int count)
struct chmFile * chm_dup(struct chmFile *oldHandle)
static BOOL _unmarshal_int64(unsigned char **pData, unsigned int *pLenRemain, Int64 *dest)
BOOL chm_enumerate_dir(struct chmFile *h, const WCHAR *prefix, int what, CHM_ENUMERATOR e, void *context)
static void _chm_skip_cword(UChar **pEntry)
static Int64 _chm_decompress_block(struct chmFile *h, UInt64 block, UChar **ubuffer)
static BOOL _unmarshal_uint64(unsigned char **pData, unsigned int *pLenRemain, UInt64 *dest)
#define _CHM_LZXC_MIN_LEN
static BOOL _unmarshal_lzxc_control_data(unsigned char **pData, unsigned int *pDataLen, struct chmLzxcControlData *dest)
static BOOL _chm_parse_UTF8(UChar **pEntry, UInt64 count, WCHAR *path)
struct chmFile * chm_openW(const WCHAR *filename)
static BOOL _unmarshal_itsf_header(unsigned char **pData, unsigned int *pDataLen, struct chmItsfHeader *dest)
void chm_close(struct chmFile *h)
static UInt64 _chm_parse_cword(UChar **pEntry)
static BOOL _chm_parse_PMGL_entry(UChar **pEntry, struct chmUnitInfo *ui)
static BOOL _chm_get_cmpblock_bounds(struct chmFile *h, UInt64 block, UInt64 *start, Int64 *len)
static const char _chm_pmgl_marker[4]
static Int64 _chm_fetch_bytes(struct chmFile *h, UChar *buf, UInt64 os, Int64 len)
#define CHM_ENUMERATE_NORMAL
#define CHM_RESOLVE_FAILURE
#define CHM_ENUMERATOR_CONTINUE
#define CHM_ENUMERATE_META
#define CHM_ENUMERATE_SPECIAL
#define CHM_RESOLVE_SUCCESS
#define CHM_ENUMERATE_DIRS
int(* CHM_ENUMERATOR)(struct chmFile *h, struct chmUnitInfo *ui, void *context)
#define CHM_ENUMERATE_FILES
#define CHM_ENUMERATOR_SUCCESS
#define CHM_ENUMERATOR_FAILURE
#define ReadFile(a, b, c, d, e)
#define GetCurrentProcess()
#define HeapFree(x, y, z)
#define FILE_ATTRIBUTE_NORMAL
#define MultiByteToWideChar
BOOL WINAPI SetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
BOOL WINAPI InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount, IN DWORD flags)
int WINAPIV fprintf(FILE *file, const char *format,...)
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
GLuint GLuint GLsizei count
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLsizei GLsizei * length
GLenum const GLvoid * addr
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
void LZXteardown(struct LZXstate *pState)
int LZXdecompress(struct LZXstate *pState, unsigned char *inpos, unsigned char *outpos, int inlen, int outlen)
struct LZXstate * LZXinit(int wndsize)
int LZXreset(struct LZXstate *pState)
#define memcpy(s1, s2, n)
PRTL_CRITICAL_SECTION_DEBUG DebugInfo
Int64 * cache_block_indices
struct chmUnitInfo rt_unit
CRITICAL_SECTION cache_mutex
struct chmUnitInfo cn_unit
struct LZXstate * lzx_state
CRITICAL_SECTION lzx_mutex
struct chmLzxcResetTable reset_table
Character const *const prefix
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO
#define DUPLICATE_SAME_ACCESS
static unsigned int block