From 87f99873d957cfd1031fa6db141b68f7f0017f10 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 5 May 2020 20:22:53 +0200 Subject: [PATCH] v0.60 --- Makefile | 2 +- UnAlz.cpp | 182 +++++++++++++++++++++++++++---------------- UnAlz.h | 74 +++++++++++------- UnAlzBz2decompress.c | 1 - UnAlzUtils.cpp | 37 ++++++--- UnAlzbzlib.c | 5 ++ main.cpp | 31 +++----- readme.txt | 6 +- 8 files changed, 208 insertions(+), 130 deletions(-) diff --git a/Makefile b/Makefile index 703ae4c..2b280a2 100755 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ all: @echo "" @echo "TARGET_SYSTEM is one of" @echo "" - @echo " posix : POSIX system (FreeBSD/linux/OSX/sparc)" + @echo " posix : POSIX system (FreeBSD/linux/OSX/sparc/Win32)" @echo " posix-utf8 : POSIX with utf8 filesystem(e.g. OSX)" @echo " linux-utf8 : LINUX with utf8 filesystem(without -liconv option)" @echo " posix-noiconv : POSIX without libiconv (Windows(MINGW32,CYGWIN) or EUC-KR file system)" diff --git a/UnAlz.cpp b/UnAlz.cpp index 7fd93a3..296e5f2 100755 --- a/UnAlz.cpp +++ b/UnAlz.cpp @@ -1,4 +1,3 @@ -//#include "stdafx.h" #include "zlib/zlib.h" #include "bzip2/bzlib.h" #include "UnAlz.h" @@ -8,13 +7,11 @@ # include # include #endif - #ifdef __GNUC__ # include # include #endif - // mkdir #ifdef _WIN32 # include @@ -31,56 +28,43 @@ #endif #if defined(__NetBSD__) -# include // __NetBSD_Version__ +# include // __NetBSD_Version__ # include // iconv.h ¶§¹®¿¡ ÇÊ¿ä #endif -#define swapint64(Data) (INT64) ( (((Data)&0x00000000000000FFLL) << 56) | (((Data)&0x000000000000FF00LL) << 40) | (((Data)&0x0000000000FF0000LL) << 24) | (((Data)&0x00000000FF000000LL) << 8) | (((Data)&0x000000FF00000000LL) >> 8) | (((Data)&0x0000FF0000000000LL) >> 24) | (((Data)&0x00FF000000000000LL) >> 40) | (((Data)&0xFF00000000000000LL) >> 56) ) +#ifdef _WIN32 // string conversion +# include +# include +#endif + +#ifdef _WIN32 // safe string ó¸® +# include "strsafe.h" +#endif + + +// ENDIAN ó¸® +#ifdef _WIN32 // (L) +# define swapint64(a) (UINT64) ( (((a)&0x00000000000000FFL) << 56) | (((a)&0x000000000000FF00L) << 40) | (((a)&0x0000000000FF0000L) << 24) | (((a)&0x00000000FF000000L) << 8) | (((a)&0x000000FF00000000L) >> 8) | (((a)&0x0000FF0000000000L) >> 24) | (((a)&0x00FF000000000000L) >> 40) | (((a)&0xFF00000000000000L) >> 56) ) +#else // (LL) +# define swapint64(a) (UINT64) ( (((a)&0x00000000000000FFLL) << 56) | (((a)&0x000000000000FF00LL) << 40) | (((a)&0x0000000000FF0000LL) << 24) | (((a)&0x00000000FF000000LL) << 8) | (((a)&0x000000FF00000000LL) >> 8) | (((a)&0x0000FF0000000000LL) >> 24) | (((a)&0x00FF000000000000LL) >> 40) | (((a)&0xFF00000000000000LL) >> 56) ) +#endif #define swapint32(a) ((((a)&0xff)<<24)+(((a>>8)&0xff)<<16)+(((a>>16)&0xff)<<8)+(((a>>24)&0xff))) #define swapint16(a) (((a)&0xff)<<8)+(((a>>8)&0xff)) -//////////////////////////////////////////////////////////////////////////// -//// byte-order : little to host //// -//////////////////////////////////////////////////////////////////////////// +typedef UINT16 (*_unalz_le16toh)(UINT16 a); +typedef UINT32 (*_unalz_le32toh)(UINT32 a); +typedef UINT64 (*_unalz_le64toh)(UINT64 a); -#if defined(_WIN32) || defined(__CYGWIN__) // little to little - inline UINT16 unalz_le16toh(UINT16 a){return a;} - inline UINT32 unalz_le32toh(UINT32 a){return a;} - inline UINT64 unalz_le64toh(UINT64 a){return a;} -#endif - -#if defined(__FreeBSD__) || defined(__NetBSD__) -# include - inline UINT16 unalz_le16toh(UINT16 a){return le16toh(a);} - inline UINT32 unalz_le32toh(UINT32 a){return le32toh(a);} - inline UINT64 unalz_le64toh(UINT64 a){return le64toh(a);} -#endif - -#ifdef __APPLE__ -# include - inline UINT16 unalz_le16toh(UINT16 a){return NXSwapShort(a);} - inline UINT32 unalz_le32toh(UINT32 a){return NXSwapLong(a);} - inline UINT64 unalz_le64toh(UINT64 a){return NXSwapLongLong(a);} -#endif - - -#ifdef __linux__ -# include -# if __BYTE_ORDER == __BIG_ENDIAN - inline UINT16 unalz_le16toh(UINT16 a){return swapint16(a);} - inline UINT32 unalz_le32toh(UINT32 a){return swapint32(a);} - inline UINT64 unalz_le64toh(UINT64 a){return swapint64(a);} -# else // __LITTLE_ENDIAN - inline UINT16 unalz_le16toh(UINT16 a){return (a);} - inline UINT32 unalz_le32toh(UINT32 a){return (a);} - inline UINT64 unalz_le64toh(UINT64 a){return (a);} -# endif -//# include -// inline UINT16 unalz_le16toh(UINT16 a){return le16_to_cpu(a);} -// inline UINT32 unalz_le32toh(UINT32 a){return le32_to_cpu(a);} -// inline UINT64 unalz_le64toh(UINT64 a){return le64_to_cpu(a);} -#endif +static _unalz_le16toh unalz_le16toh=NULL; +static _unalz_le32toh unalz_le32toh=NULL; +static _unalz_le64toh unalz_le64toh=NULL; +static UINT16 le16tole(UINT16 a){return a;} +static UINT32 le32tole(UINT32 a){return a;} +static UINT64 le64tole(UINT64 a){return a;} +static UINT16 le16tobe(UINT16 a){return swapint16(a);} +static UINT32 le32tobe(UINT32 a){return swapint32(a);} +static UINT64 le64tobe(UINT64 a){return swapint64(a);} #ifndef MAX_PATH @@ -108,6 +92,44 @@ static time_t dosTime2TimeT(UINT32 dostime) // from INFO-ZIP src return mktime(&t); } +static BOOL IsBigEndian(void) +{ + union { + short a; + char b[2]; + } endian; + + endian.a = 0x0102; + if(endian.b[0] == 0x02) return FALSE; + return TRUE; +} + +// ¾ÈÀüÇÑ strcpy +static void safe_strcpy(char* dst, const char* src, size_t dst_size) +{ +#ifdef _WIN32 + lstrcpynA(dst, src, dst_size); +#else + strlcpy(dst, src, dst_size); +#endif +} + +static void safe_strcat(char* dst, const char* src, size_t dst_size) +{ +#ifdef _WIN32 + StringCchCatExA(dst, dst_size, src, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); + //lstrcatA(dst, src); // not safe!! +#else + strlcat(dst, src, dst_size); +#endif +} + +#ifdef _WIN32 +# define safe_sprintf StringCbPrintfA +#else +# define safe_sprintf snprintf +#endif + // error string table <- CUnAlz::ERR ÀÇ ¹ø¿ª static const char* errorstrtable[]= @@ -148,7 +170,6 @@ static const char* errorstrtable[]= }; - //////////////////////////////////////////////////////////////////////////////////////////////////// /// ctor /// @date 2004-03-06 ¿ÀÈÄ 11:19:49 @@ -173,13 +194,30 @@ CUnAlz::CUnAlz() #ifdef _UNALZ_ICONV #ifdef _UNALZ_UTF8 - strcpy(m_szToCodepage, "UTF-8") ; // ±âº»ÀûÀ¸·Î utf-8 + safe_strcpy(m_szToCodepage, "UTF-8",UNALZ_LEN_CODEPAGE) ; // ±âº»ÀûÀ¸·Î utf-8 #else - strcpy(m_szToCodepage, "CP949") ; // ±âº»ÀûÀ¸·Î CP949 + safe_strcpy(m_szToCodepage, "CP949",UNALZ_LEN_CODEPAGE) ; // ±âº»ÀûÀ¸·Î CP949 #endif // _UNALZ_UTF8 - strcpy(m_szFromCodepage, "CP949"); // alz ´Â 949 ¸¸ Áö¿ø + safe_strcpy(m_szFromCodepage, "CP949",UNALZ_LEN_CODEPAGE); // alz ´Â 949 ¸¸ Áö¿ø #endif // _UNALZ_ICONV + + // check endian + if(unalz_le16toh==NULL) + { + if(IsBigEndian()) + { + unalz_le16toh = le16tobe; + unalz_le32toh = le32tobe; + unalz_le64toh = le64tobe; + } + else + { + unalz_le16toh = le16tole; + unalz_le32toh = le32tole; + unalz_le64toh = le64tole; + } + } } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -209,8 +247,6 @@ void CUnAlz::SetCallback(_UnAlzCallback* pFunc, void* param) /// @return /// @date 2004-03-06 ¿ÀÈÄ 11:03:59 //////////////////////////////////////////////////////////////////////////////////////////////////// -#include -#include BOOL CUnAlz::Open(LPCWSTR szPathName) { USES_CONVERSION; @@ -327,7 +363,6 @@ CUnAlz::SIGNATURE CUnAlz::ReadSignature() UINT32 dwSig; if(FRead(&dwSig, sizeof(dwSig))==FALSE) { -//int pos = ftell(m_fp); if(FEof()) return SIG_EOF; m_nErr = ERR_CANT_READ_SIG; @@ -351,7 +386,6 @@ BOOL CUnAlz::ReadAlzFileHeader() m_nErr = ERR_CANT_READ_FILE; return FALSE; } - return TRUE; } @@ -574,7 +608,6 @@ BOOL CUnAlz::ReadCentralDirectoryStructure() FRead(header.fileComment, 1, header.head.fileCommentLength, m_fp); header.fileComment[header.head.fileCommentLength] = NULL; } - */ return TRUE; @@ -690,13 +723,13 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi } // °æ·Î¸í - strcpy(szDestPathFileName, szDestPathName); + safe_strcpy(szDestPathFileName, szDestPathName, MAX_PATH); if(szDestPathFileName[strlen(szDestPathFileName)]!=PATHSEPC) - strcat(szDestPathFileName, PATHSEP); + safe_strcat(szDestPathFileName, PATHSEP, MAX_PATH); // ÆÄÀϸí - if(szDestFileName) strcat(szDestPathFileName, szDestFileName); - else strcat(szDestPathFileName, m_posCur->fileName); + if(szDestFileName) safe_strcat(szDestPathFileName, szDestFileName, MAX_PATH); + else safe_strcat(szDestPathFileName, m_posCur->fileName, MAX_PATH); // ../../ Çü½ÄÀÇ º¸¾È ¹ö±× È®ÀÎ if( strstr(szDestPathFileName, "../")|| @@ -707,8 +740,6 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi return FALSE; } - - #ifndef _WIN32 { char* p = szDestPathFileName; // °æ·Î delimiter ¹Ù²Ù±â @@ -938,13 +969,15 @@ BOOL CUnAlz::DigPath(const char* szPathName) if(strlen(path)==0) { if(szPathName[0]=='/') // is absolute path ? - strcpy(path,"/"); - strcat(path, token); + safe_strcpy(path,"/", MAX_PATH); + else if(szPathName[0]=='\\' && szPathName[1]=='\\') // network drive ? + safe_strcpy(path,"\\\\", MAX_PATH); + safe_strcat(path, token, MAX_PATH); } else { - strcat(path, PATHSEP); - strcat(path, token); + safe_strcat(path, PATHSEP,MAX_PATH); + safe_strcat(path, token,MAX_PATH); } if(IsFolder(path)==FALSE) @@ -1464,7 +1497,9 @@ BOOL CUnAlz::FOpen(const char* szPathName) m_bIsEOF = FALSE; for(i=0;i0) sprintf(temp+nLen-3, "%c%02d", (i-1)/100+'a', (i-1)%100); + if(i>0) + safe_sprintf(temp+nLen-3, 4, "%c%02d", (i-1)/100+'a', (i-1)%100); + #ifdef _WIN32 m_files[i].fp = CreateFileA(temp, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if(m_files[i].fp==INVALID_HANDLE_VALUE) break; @@ -1689,7 +1724,6 @@ BOOL CUnAlz::chkValidPassword() /* - //////////////////////////////////////////////////////////////////////////////////////////////////// // from CZipArchive // Copyright (C) 2000 - 2004 Tadeusz Dracz @@ -1756,7 +1790,6 @@ UINT32 CUnAlz::CryptCRC32(UINT32 l, CHAR c) const ULONG *CRC_TABLE = get_crc_table(); return CRC_TABLE[(l ^ c) & 0xff] ^ (l >> 8); } - */ //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1877,8 +1910,21 @@ void CUnAlz::DecryptingData(int nSize, BYTE* data) //////////////////////////////////////////////////////////////////////////////////////////////////// UINT32 CUnAlz::CRC32(UINT32 l, BYTE c) { - const ULONG *CRC_TABLE = get_crc_table(); + const unsigned long *CRC_TABLE = get_crc_table(); return CRC_TABLE[(l ^ c) & 0xff] ^ (l >> 8); } +void CUnAlz::SetPassword(char *passwd) +{ + if(strlen(passwd) == 0) return; + safe_strcpy(m_szPasswd, passwd, UNALZ_LEN_PASSWORD); +} + +#ifdef _UNALZ_ICONV +void CUnAlz::SetDestCodepage(const char* szToCodepage) +{ + safe_strcpy(m_szToCodepage, szToCodepage, UNALZ_LEN_CODEPAGE); +} +#endif + diff --git a/UnAlz.h b/UnAlz.h index 3a65b94..b976a9b 100755 --- a/UnAlz.h +++ b/UnAlz.h @@ -1,12 +1,41 @@ /* + UNALZ : read and extract module for ALZ format. - COPYRIGHT(C) 2004-2006 hardkoder@gmail , http://www.kipple.pe.kr + LICENSE (zlib License) + Copyright (C) 2004-2005 hardkoder@gmail , http://www.kipple.pe.kr - ÀúÀÛ±Ç Á¤º¸ : ( BSD License ) - - ÀÌ ¼Ò½º´Â ÀÚÀ¯·ÎÀÌ »ç¿ë/¼öÁ¤/Àç¹èÆ÷ °¡´ÉÇÕ´Ï´Ù. - - ´Ü, ´ç½ÅÀÌ ¸¸µé¾ú´Ù°í ÁÖÀåÇϰųª °ÅÁþ¸»ÇÏ¸é ¾ÈµÊ. + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + ÀÌ ¼ÒÇÁÆ®¿þ¾î´Â ¾î¶°ÇÑ ¸í½ÃÀû ¶Ç´Â ¹¬½ÃÀû º¸Áõµµ ¾øÀÌ "ÀÖ´Â ±×´ë·Î" Á¦°øµË´Ï´Ù. ±× + ¾î¶² °æ¿ì¿¡µµ ÀÛ¼ºÀÚ´Â ÀÌ ¼ÒÇÁÆ®¿þ¾îÀÇ »ç¿ëÀ¸·Î ÀÎÇÑ ¼ÕÇØ¿¡ ´ëÇØ Ã¥ÀÓÀ» ÁöÁö ¾Ê½À´Ï´Ù. + + ´ÙÀ½ Á¦ÇÑ ±ÔÁ¤À» ÁؼöÇÏ´Â °æ¿ì¿¡ ÇÑÇÏ¿© »ó¾÷ÀûÀÎ ÀÀ¿ë ÇÁ·Î±×·¥À» Æ÷ÇÔÇÏ´Â ¸ðµç ¿ëµµ·Î ÀÌ ¼ÒÇÁÆ®¿þ¾î¸¦ + »ç¿ëÇÏ°í ÀÚÀ¯·Ó°Ô ¼öÁ¤ ¹× Àç¹èÆ÷ÇÒ ¼ö ÀÖ´Â ±ÇÇÑÀÌ ´©±¸¿¡°Ô³ª ºÎ¿©µË´Ï´Ù. + + 1. ÀÌ ¼ÒÇÁÆ®¿þ¾îÀÇ Ãâó¸¦ À߸ø Ç¥½ÃÇϰųª ¿ø·¡ ¼ÒÇÁÆ®¿þ¾î¸¦ ÀÚ½ÅÀÌ ÀÛ¼ºÇß´Ù°í ÁÖÀåÇؼ­´Â ¾È µË´Ï´Ù. Á¦Ç°¿¡ + ÀÌ ¼ÒÇÁÆ®¿þ¾î¸¦ »ç¿ëÇÏ´Â °æ¿ì ¿ä±¸ »çÇ×Àº ¾Æ´ÏÁö¸¸ Á¦Ç° ¼³¸í¼­¿¡ ÀÎÁ¤ Á¶Ç×À» ³Ö¾î ÁÖ½Ã¸é °¨»çÇÏ°Ú½À´Ï´Ù. + 2. ¼öÁ¤µÈ ¼Ò½º ¹öÀüÀº ¹Ýµå½Ã ¸íÈ®ÇÏ°Ô Ç¥½ÃµÇ¾î¾ß ÇÏ¸ç ¿ø·¡ ¼ÒÇÁÆ®¿þ¾î·Î ¿ÀÀεǵµ·Ï À߸ø Ç¥½ÃÇؼ­´Â ¾È µË´Ï´Ù. + 3. ¸ðµç ¼Ò½º ¹èÆ÷ ½Ã ÀÌ °øÁö¸¦ »èÁ¦Çϰųª ¼öÁ¤ÇÒ ¼ö ¾ø½À´Ï´Ù. + + ============================================================================================================= + + ±ÇÀå»çÇ× : - ¼Ò½ºÀÇ ¿À·ù¸¦ ã¾Ò°Å³ª, ¹®Á¦Á¡À» ¼öÁ¤ÇÏ¿´À» °æ¿ì ÀÌ¿¡ ´ëÇÑ ³»¿ëÀ» ¾Ë·ÁÁÖ¸é Á¤¸» °í¸¶¿ï²¬.. - - ÀÚ½ÅÀÇ ÇÁ·Î±×·¥¿¡ ÀÌ ¼Ò½º¸¦ »ç¿ëÇÏ¿´À» °æ¿ì ¿ø ÀúÀÛÀÚ¿¡°Ô ¾Ë·ÁÁÖ¸é ¿ø ÀúÀÛÀÚ°¡ °í¸¶¿ö ÇÒ²¬.. + - ÀÚ½ÅÀÇ ÇÁ·Î±×·¥¿¡ ÀÌ ¼Ò½º¸¦ »ç¿ëÇÏ¿´À» °æ¿ì ³ªÇÑÅ× ¸ÞÀÏÇÑÅë ¶§·ÁÁÖ¸é ³»°¡ °í¸¶¿ö ÇÒ²¬.. ¼Ò½º ¼³¸í : - .ALZ ÀÇ ¾ÐÃàÀ» ÇØÁ¦Çϱâ À§ÇÑ ¸ðµâ. @@ -49,7 +78,7 @@ - ¾ÏÈ£°É¸° ÆÄÀÏ°ú ¾È°É¸° ÆÄÀÏ ¼¯¿´À»¶§ ó¸® - ÆÄÀÏÀÇ µÞºÎºÐÀÌ Àß·Á¼­ ¼Õ»óµÈ ÆÄÀϵµ ¸ÖÂÄÇÑ ºÎºÐ±îÁö´Â ¾ÐÃàÀ» Ç®µµ·Ï ¼öÁ¤ - unalz 0.31 - 2005/01/08 - ¾ÏÈ£ À߸ø ÀԷ½à Çѹø üũÈÄ µÎ¹ø°´Â Á¤»ó ¾ÏÈ£¸¦ ÀÔ·ÂÇؼ­ Ç®Áö ¸øÇÏ°Ô µÇ´ø ¹ö±× ¼öÁ¤ + 2005/01/08 - ¾ÏÈ£ À߸ø ÀԷ½à Çѹø üũÈÄ µÎ¹ø°´Â Á¤»ó ¾ÏÈ£¸¦ ÀÔ·ÂÇصµ Ç®Áö ¸øÇÏ°Ô µÇ´ø ¹ö±× ¼öÁ¤ 2005/02/05 - ¾ÐÃà ÇØÁ¦ÈÄ deflate ÀÇ ÆÄÀÏ CRC È®ÀÎ ±â´É Ãß°¡ 2005/03/07 - bzip2, raw ÆÄÀÏ¿¡ ´ëÇÑ ÆÄÀÏ CRC È®ÀÎ ±â´É Ãß°¡ 2005/03/13 - ALZ ÆÄÀÏÀÌ ¾Æ´Ò°æ¿ì ¿¡·¯ ÄÚµå(ERR_NOT_ALZ_FILE) Ãß°¡ @@ -75,6 +104,9 @@ - unalz 0.53 2006/03/10 - .. Æú´õ °ü·Ã º¸¾È ¹®Á¦ ¼öÁ¤ (by vuln@secunia ) - unalz 0.55 + 2006/04/23 - ¿£µð¾È 󸮸¦ ·±Å¸ÀÓ¿¡ Çϵµ·Ï ¼öÁ¤ + 2006/12/31 - strcpy/strcat/sprintf ¿Í °°Àº ¹öÆÛ ¿À¹öÇÃ·Î¿ì °¡´É¼ºÀÌ ÀÖ´Â ÇÔ¼ö Á¦°Å (by liam.joo@gmail) + - unalz 0.60 ±â´É : - alz ÆÄÀÏÀÇ ¾ÐÃà ÇØÁ¦ (deflate/º¯Çü bzip2/raw) @@ -142,9 +174,6 @@ using namespace std; #ifndef LONG typedef long LONG; #endif -#ifndef ULONG - typedef unsigned long ULONG; // same as DWORD? i don't know. -#endif #ifndef BOOL # ifndef BOOL_DEFINED // ÀÌ¹Ì BOOL ÀÌ DEFINE µÇ¾î ÀÖÀ¸¸é BOOL_DEFINED ¸¦ define Çؼ­ ÄÄÆÄÀÏ ¿¡·¯¸¦ ¸·À» ¼ö ÀÖ´Ù. typedef int BOOL; @@ -181,7 +210,7 @@ namespace UNALZ # pragma pack(1) #endif -static const char UNALZ_VERSION[] = "CUnAlz0.55"; +static const char UNALZ_VERSION[] = "CUnAlz0.60"; static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004-2006 by hardkoder@gmail ( http://www.kipple.pe.kr ) "; enum {ENCR_HEADER_LEN=12}; // xf86 @@ -256,15 +285,6 @@ struct _SLocalFileHeaderHead ///< */ }; -/* -struct _SDataDescriptor -{ - UINT32 crc32; - UINT32 compressed; - UINT32 uncompressed; -}; -*/ - struct SLocalFileHeader { SLocalFileHeader() { memset(this, 0, sizeof(*this)); } @@ -281,7 +301,6 @@ struct SLocalFileHeader CHAR* fileName; BYTE* extraField; -// _SDataDescriptor dataDescriptor; INT64 dwFileDataPos; ///< file data °¡ ÀúÀåµÈ À§Ä¡.. BYTE encChk[ENCR_HEADER_LEN]; // xf86 @@ -360,7 +379,7 @@ struct SEndOfCentralDirectoryRecord ///< PROGRESS CALLBACK FUNCTION - ¾ÐÃà ÇØÁ¦ ÁøÇà »óȲÀ» ¾Ë°í ½ÍÀ¸¸é ÀÌ°É ¾²¸é µÈ´Ù. -typedef void (_UnAlzCallback)(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt); +typedef void (_UnAlzCallback)(const char* szFileName, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt); class CUnAlz @@ -377,12 +396,12 @@ public: void SetCallback(_UnAlzCallback* pFunc, void* param=NULL); void SetPipeMode(BOOL bPipeMode) {m_bPipeMode=bPipeMode;} - void setPassword(char *passwd) { if(strlen(passwd) == 0) return; strcpy(m_szPasswd, passwd); }; // xf86 + void SetPassword(char *passwd); // xf86 BOOL chkValidPassword(); // xf86 BOOL IsEncrypted() { return m_bIsEncrypted; }; #ifdef _UNALZ_ICONV - void SetDestCodepage(const char* szToCodepage) { strcpy(m_szToCodepage, szToCodepage); } + void SetDestCodepage(const char* szToCodepage); #endif public : ///< WIN32 Àü¿ë ( UNICODE 󸮿ë ) @@ -534,7 +553,8 @@ private : // BOOL m_bIsEncrypted; // xf86 BOOL m_bIsDataDescr; - char m_szPasswd[512]; +#define UNALZ_LEN_PASSWORD 512 + char m_szPasswd[UNALZ_LEN_PASSWORD]; BOOL m_bPipeMode; ///< pipemode - ¸Þ½ÃÁö Ãâ·Â¾øÀÌ stdout À¸·Î¸¸ Ãâ·Â private : @@ -568,8 +588,10 @@ private : BOOL m_bHalt; #ifdef _UNALZ_ICONV - char m_szToCodepage[256]; ///< codepage - char m_szFromCodepage[256]; ///< "CP949" + +#define UNALZ_LEN_CODEPAGE 256 + char m_szToCodepage[UNALZ_LEN_CODEPAGE]; ///< codepage + char m_szFromCodepage[UNALZ_LEN_CODEPAGE]; ///< "CP949" #endif }; } diff --git a/UnAlzBz2decompress.c b/UnAlzBz2decompress.c index 821cb0d..35e021c 100755 --- a/UnAlzBz2decompress.c +++ b/UnAlzBz2decompress.c @@ -279,7 +279,6 @@ Int32 BZ2_decompress ( DState* s ) GET_UCHAR(BZ_X_BLKHDR_1, uc); // [ALZ] - º¯ÇüµÈ Çì´õ - if (uc != 'D') RETURN(BZ_DATA_ERROR_MAGIC); diff --git a/UnAlzUtils.cpp b/UnAlzUtils.cpp index a425bc1..bea22f2 100755 --- a/UnAlzUtils.cpp +++ b/UnAlzUtils.cpp @@ -2,6 +2,9 @@ #include #include "UnAlzUtils.h" +#ifdef _WIN32 // safe string ó¸® +# include "strsafe.h" +#endif #ifdef _WIN32 # define I64FORM(x) "%"#x"I64d" @@ -11,6 +14,8 @@ # define U64FORM(x) "%"#x"llu" #endif +#define LEN_ATTR 6 + time_t dosTime2TimeT(UINT32 dostime) // from INFO-ZIP src { struct tm t; @@ -24,6 +29,16 @@ time_t dosTime2TimeT(UINT32 dostime) // from INFO-ZIP src return mktime(&t); } +static void safe_strcat(char* dst, const char* src, size_t dst_size) +{ +#ifdef _WIN32 + StringCchCatExA(dst, dst_size, src, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); + //lstrcatA(dst, src); // not safe!! +#else + strlcat(dst, src, dst_size); +#endif +} + //////////////////////////////////////////////////////////////////////////////////////////////////// /// fileAttribute ¸¦ ½ºÆ®¸µÀ¸·Î ¹Ù²ãÁØ´Ù. /// @param buf - 5byte ÀÌ»ó @@ -31,29 +46,29 @@ time_t dosTime2TimeT(UINT32 dostime) // from INFO-ZIP src /// @return /// @date 2005-06-23 ¿ÀÈÄ 10:12:35 //////////////////////////////////////////////////////////////////////////////////////////////////// -void FileAttr2Str(char* buf, BYTE fileAttribute) +void FileAttr2Str(char szAttr[LEN_ATTR], BYTE fileAttribute) { - buf[0] = 0; + szAttr[0] = 0; if(fileAttribute&ALZ_FILEATTR_FILE) - strcat(buf, "A"); + safe_strcat(szAttr, "A", LEN_ATTR); else - strcat(buf, "_"); + safe_strcat(szAttr, "_", LEN_ATTR); if(fileAttribute&ALZ_FILEATTR_DIRECTORY) - strcat(buf, "D"); + safe_strcat(szAttr, "D", LEN_ATTR); else - strcat(buf, "_"); + safe_strcat(szAttr, "_", LEN_ATTR); if(fileAttribute&ALZ_FILEATTR_READONLY) - strcat(buf, "R"); + safe_strcat(szAttr, "R", LEN_ATTR); else - strcat(buf, "_"); + safe_strcat(szAttr, "_", LEN_ATTR); if(fileAttribute&ALZ_FILEATTR_HIDDEN) - strcat(buf, "H"); + safe_strcat(szAttr, "H", LEN_ATTR); else - strcat(buf, "_"); + safe_strcat(szAttr, "_", LEN_ATTR); } @@ -72,7 +87,7 @@ int ListAlz(CUnAlz* pUnAlz, const char* src) // char szDate[64]; char szTime[64]; - char szAttr[6]; + char szAttr[LEN_ATTR]; UINT64 totalUnCompressedSize = 0; UINT64 totalCompressedSize = 0; unsigned fileNum = 0; diff --git a/UnAlzbzlib.c b/UnAlzbzlib.c index db46e2a..c297f06 100755 --- a/UnAlzbzlib.c +++ b/UnAlzbzlib.c @@ -1444,8 +1444,13 @@ BZFILE * bzopen_or_bzdopen } mode++; } +#ifndef __OpenBSD__ strcat(mode2, writing ? "w" : "r" ); strcat(mode2,"b"); /* binary mode */ +#else // by liam.joo@gmail 2006/12 + strlcat(mode2, writing ? "w" : "r", sizeof(mode2) ); + strlcat(mode2,"b",sizeof(mode2)); +#endif if (open_mode==0) { if (path==NULL || strcmp(path,"")==0) { diff --git a/main.cpp b/main.cpp index 42eeb5d..574beac 100755 --- a/main.cpp +++ b/main.cpp @@ -28,7 +28,8 @@ void Copyright() // printf("unalz v0.52 (2005/07/27) \n"); // printf("unalz v0.53 (2005/10/15) \n"); // printf("unalz v0.54 (2005/11/21) \n"); - printf("unalz v0.55 (2006/03/10) \n"); +// printf("unalz v0.55 (2006/03/10) \n"); + printf("unalz v0.60 (2006/12/31) \n"); printf("Copyright(C) 2004-2006 by hardkoder@gmail (http://www.kipple.pe.kr) \n"); } @@ -81,25 +82,26 @@ void Usage() -void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt) +void UnAlzCallback(const char* szFileName, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt) { if(g_bPipeMode) return; // slient +#define MSG_BUF_LEN 1024 // progress - static char szFileName[1024]={0}; + static char szMessage[MSG_BUF_LEN]={0}; + static INT64 nPrevPercent = -1; INT64 percent; - static INT64 nPrevPercent = -1; // ÆÄÀϸí Ãâ·Â.. if(szMessage) { printf("\n"); #ifdef _WIN32 - sprintf(szFileName, "unalziiiing : %s (%I64dbytes) ", szMessage, nRange); + _snprintf(szMessage, MSG_BUF_LEN, "unalziiiing : %s (%I64dbytes) ", szFileName, nRange); #else - sprintf(szFileName, "unalziiiing : %s (%lldbytes) ", szMessage, nRange); + snprintf(szMessage, MSG_BUF_LEN, "unalziiiing : %s (%lldbytes) ", szFileName, nRange); #endif - printf("%s", szFileName); + printf("%s", szMessage); fflush(stdout); nPrevPercent = -1; return; @@ -113,17 +115,6 @@ void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* pa printf("."); fflush(stdout); - /* - char buf[1024]; -#ifdef _WIN32 - sprintf(buf, "\r%s %I64d/%I64d (%I64d%%)", szFileName, nCurrent, nRange, percent); -#else -// sprintf(buf, "\r%s %d/%d (%d%%)", szMessage, (int)nCurrent, (int)nRange, (int)percent); // int64 ¸¦ Ãâ·ÂÇÒ¶ó¸é ¾îÂîÇØ¾ß µÇ´ÂÁö? - sprintf(buf, "\r%s %lld/%lld (%lld%%)", szFileName, nCurrent, Range, percent); -#endif - puts(buf); - fflush(stdout); - */ } @@ -277,14 +268,14 @@ int main(int argc, char* argv[]) { if(password) // command line À¸·Î ¾ÏÈ£°¡ ÁöÁ¤µÇ¾úÀ» °æ¿ì. { - unalz.setPassword(password); + unalz.SetPassword(password); } else { char pwd[256]; printf("Enter Password : "); fgets(pwd,256,stdin); - unalz.setPassword(pwd); + unalz.SetPassword(pwd); } } diff --git a/readme.txt b/readme.txt index 643e8e5..864a138 100755 --- a/readme.txt +++ b/readme.txt @@ -1,14 +1,14 @@ - unalz v0.5 + unalz v0.60 - Copyright(C) 2004-2005 by hardkoder (http://www.kipple.pe.kr) + Copyright(C) 2004-2006 by hardkoder (http://www.kipple.pe.kr) - ÃÖÃÊ ÀÛ¼ºÀÏ : v0.20 - 2004/10/22 - ¶óÀ̼±½º - . ÀÚÀ¯·ÎÀÌ º¯Çü/¹èÆ÷ °¡´É (BSD-license) + . ÀÚÀ¯·ÎÀÌ º¯Çü/¹èÆ÷ °¡´É (zlib-license)