aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/UI/Common/PropIDUtils.cpp
diff options
context:
space:
mode:
authorTetsuo Osaka <tetsugit@gmail.com>2016-10-18 15:12:28 +0200
committerTetsuo Osaka <tetsugit@gmail.com>2017-04-18 10:07:58 +0200
commitf955a79a9fffb09826cf7547f70d08c3798a2f50 (patch)
tree7ba3acdf7ba22cb749ffd9e6a868630e5a8382f2 /CPP/7zip/UI/Common/PropIDUtils.cpp
parent462f68aa279e25fda265a87c6d3c4da3318314f8 (diff)
downloadlzma-f955a79a9fffb09826cf7547f70d08c3798a2f50.tar.gz
Rebase LZMA SDK on 16.04 stable
This was downloaded from http://www.7-zip.org/a/lzma1604.7z The bin folder was excluded like in previous updates All files were deleted and replaced with those from the SDK. The embedded projects Tukaani, xz-embedded and android build files where not touched. The changelog since the 9.38 beta is: 16.04 2016-10-04 ------------------------- - The bug was fixed in DllSecur.c. 16.03 2016-09-28 ------------------------- - SFX modules now use some protection against DLL preloading attack. - Some bugs in 7z code were fixed. 16.02 2016-05-21 ------------------------- - The BUG in 16.00 - 16.01 was fixed: Split Handler (SplitHandler.cpp) returned incorrect total size value (kpidSize) for split archives. 16.01 2016-05-19 ------------------------- - Some internal changes to reduce the number of compiler warnings. 16.00 2016-05-10 ------------------------- - Some bugs were fixed. 15.12 2015-11-19 ------------------------- - The BUG in C version of 7z decoder was fixed: 7zDec.c : SzDecodeLzma2() 7z decoder could mistakenly report about decoding error for some 7z archives that use LZMA2 compression method. The probability to get that mistaken decoding error report was about one error per 16384 solid blocks for solid blocks larger than 16 KB (compressed size). - The BUG (in 9.26-15.11) in C version of 7z decoder was fixed: 7zArcIn.c : SzReadHeader2() 7z decoder worked incorrectly for 7z archives that contain empty solid blocks, that can be placed to 7z archive, if some file is unavailable for reading during archive creation. 15.09 beta 2015-10-16 ------------------------- - The BUG in LZMA / LZMA2 encoding code was fixed. The BUG in LzFind.c::MatchFinder_ReadBlock() function. If input data size is larger than (4 GiB - dictionary_size), the following code worked incorrectly: - LZMA : LzmaEnc_MemEncode(), LzmaEncode() : LZMA encoding functions for compressing from memory to memory. That BUG is not related to LZMA encoder version that works via streams. - LZMA2 : multi-threaded version of LZMA2 encoder worked incorrectly, if default value of chunk size (CLzma2EncProps::blockSize) is changed to value larger than (4 GiB - dictionary_size). Change-Id: I6b3974015c605fba3c0d4d897fab5a166174f441
Diffstat (limited to 'CPP/7zip/UI/Common/PropIDUtils.cpp')
-rw-r--r--CPP/7zip/UI/Common/PropIDUtils.cpp195
1 files changed, 108 insertions, 87 deletions
diff --git a/CPP/7zip/UI/Common/PropIDUtils.cpp b/CPP/7zip/UI/Common/PropIDUtils.cpp
index a9278cd..9633248 100644
--- a/CPP/7zip/UI/Common/PropIDUtils.cpp
+++ b/CPP/7zip/UI/Common/PropIDUtils.cpp
@@ -7,7 +7,6 @@
#include "../../../Common/IntToString.h"
#include "../../../Common/StringConvert.h"
-#include "../../../Windows/FileFind.h"
#include "../../../Windows/FileIO.h"
#include "../../../Windows/PropVariantConv.h"
@@ -41,20 +40,53 @@ static const char g_WinAttribChars[16 + 1] = "RHS8DAdNTsLCOnE_";
16 VIRTUAL
*/
-void ConvertWinAttribToString(char *s, UInt32 wa)
+static const char kPosixTypes[16] = { '0', 'p', 'c', '3', 'd', '5', 'b', '7', '-', '9', 'l', 'B', 's', 'D', 'E', 'F' };
+#define MY_ATTR_CHAR(a, n, c) ((a) & (1 << (n))) ? c : '-';
+
+static void ConvertPosixAttribToString(char *s, UInt32 a) throw()
+{
+ s[0] = kPosixTypes[(a >> 12) & 0xF];
+ for (int i = 6; i >= 0; i -= 3)
+ {
+ s[7 - i] = MY_ATTR_CHAR(a, i + 2, 'r');
+ s[8 - i] = MY_ATTR_CHAR(a, i + 1, 'w');
+ s[9 - i] = MY_ATTR_CHAR(a, i + 0, 'x');
+ }
+ if ((a & 0x800) != 0) s[3] = ((a & (1 << 6)) ? 's' : 'S');
+ if ((a & 0x400) != 0) s[6] = ((a & (1 << 3)) ? 's' : 'S');
+ if ((a & 0x200) != 0) s[9] = ((a & (1 << 0)) ? 't' : 'T');
+ s[10] = 0;
+
+ a &= ~(UInt32)0xFFFF;
+ if (a != 0)
+ {
+ s[10] = ' ';
+ ConvertUInt32ToHex8Digits(a, s + 11);
+ }
+}
+
+void ConvertWinAttribToString(char *s, UInt32 wa) throw()
{
for (int i = 0; i < 16; i++)
if ((wa & (1 << i)) && i != 7)
*s++ = g_WinAttribChars[i];
*s = 0;
-}
-static const char kPosixTypes[16] = { '0', 'p', 'c', '3', 'd', '5', 'b', '7', '-', '9', 'l', 'B', 's', 'D', 'E', 'F' };
-#define MY_ATTR_CHAR(a, n, c) ((a) & (1 << (n))) ? c : '-';
+ // we support p7zip trick that stores posix attributes in high 16 bits, and 0x8000 flag
+ // we also support ZIP archives created in Unix, that store posix attributes in high 16 bits without 0x8000 flag
+
+ // if (wa & 0x8000)
+ if ((wa >> 16) != 0)
+ {
+ *s++ = ' ';
+ ConvertPosixAttribToString(s, wa >> 16);
+ }
+}
void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID propID, bool full) throw()
{
*dest = 0;
+
if (prop.vt == VT_FILETIME)
{
FILETIME localFileTime;
@@ -65,6 +97,7 @@ void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID pr
ConvertFileTimeToString(localFileTime, dest, true, full);
return;
}
+
switch (propID)
{
case kpidCRC:
@@ -78,34 +111,21 @@ void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID pr
{
if (prop.vt != VT_UI4)
break;
- ConvertWinAttribToString(dest, prop.ulVal);
+ UInt32 a = prop.ulVal;
+
+ /*
+ if ((a & 0x8000) && (a & 0x7FFF) == 0)
+ ConvertPosixAttribToString(dest, a >> 16);
+ else
+ */
+ ConvertWinAttribToString(dest, a);
return;
}
case kpidPosixAttrib:
{
if (prop.vt != VT_UI4)
break;
- UString res;
- UInt32 a = prop.ulVal;
-
- dest[0] = kPosixTypes[(a >> 12) & 0xF];
- for (int i = 6; i >= 0; i -= 3)
- {
- dest[7 - i] = MY_ATTR_CHAR(a, i + 2, 'r');
- dest[8 - i] = MY_ATTR_CHAR(a, i + 1, 'w');
- dest[9 - i] = MY_ATTR_CHAR(a, i + 0, 'x');
- }
- if ((a & 0x800) != 0) dest[3] = ((a & (1 << 6)) ? 's' : 'S');
- if ((a & 0x400) != 0) dest[6] = ((a & (1 << 3)) ? 's' : 'S');
- if ((a & 0x200) != 0) dest[9] = ((a & (1 << 0)) ? 't' : 'T');
- dest[10] = 0;
-
- a &= ~(UInt32)0xFFFF;
- if (a != 0)
- {
- dest[10] = ' ';
- ConvertUInt32ToHex8Digits(a, dest + 11);
- }
+ ConvertPosixAttribToString(dest, prop.ulVal);
return;
}
case kpidINode:
@@ -122,16 +142,19 @@ void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID pr
case kpidVa:
{
UInt64 v = 0;
- if (ConvertPropVariantToUInt64(prop, v))
- {
- dest[0] = '0';
- dest[1] = 'x';
- ConvertUInt64ToHex(prop.ulVal, dest + 2);
- return;
- }
- break;
+ if (prop.vt == VT_UI4)
+ v = prop.ulVal;
+ else if (prop.vt == VT_UI8)
+ v = (UInt64)prop.uhVal.QuadPart;
+ else
+ break;
+ dest[0] = '0';
+ dest[1] = 'x';
+ ConvertUInt64ToHex(v, dest + 2);
+ return;
}
}
+
ConvertPropVariantToShortString(prop, dest);
}
@@ -139,29 +162,25 @@ void ConvertPropertyToString(UString &dest, const PROPVARIANT &prop, PROPID prop
{
if (prop.vt == VT_BSTR)
{
- dest = prop.bstrVal;
+ dest.SetFromBstr(prop.bstrVal);
return;
}
char temp[64];
ConvertPropertyToShortString(temp, prop, propID, full);
- int len = MyStringLen(temp);
- wchar_t *str = dest.GetBuffer(len);
- for (int i = 0; i < len; i++)
- str[i] = temp[i];
- dest.ReleaseBuffer(len);
+ dest.SetFromAscii(temp);
}
-static inline char GetHex(Byte value)
+static inline unsigned GetHex(unsigned v)
{
- return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));
+ return (v < 10) ? ('0' + v) : ('A' + (v - 10));
}
#ifndef _SFX
-static inline void AddHexToString(AString &res, Byte value)
+static inline void AddHexToString(AString &res, unsigned v)
{
- res += GetHex((Byte)(value >> 4));
- res += GetHex((Byte)(value & 0xF));
+ res += (char)GetHex(v >> 4);
+ res += (char)GetHex(v & 0xF);
res += ' ';
}
@@ -175,30 +194,30 @@ static AString Data_To_Hex(const Byte *data, size_t size)
}
*/
-static const char *sidNames[] =
+static const char * const sidNames[] =
{
- "0",
- "Dialup",
- "Network",
- "Batch",
- "Interactive",
- "Logon", // S-1-5-5-X-Y
- "Service",
- "Anonymous",
- "Proxy",
- "EnterpriseDC",
- "Self",
- "AuthenticatedUsers",
- "RestrictedCode",
- "TerminalServer",
- "RemoteInteractiveLogon",
- "ThisOrganization",
- "16",
- "IUserIIS",
- "LocalSystem",
- "LocalService",
- "NetworkService",
- "Domains"
+ "0"
+ , "Dialup"
+ , "Network"
+ , "Batch"
+ , "Interactive"
+ , "Logon" // S-1-5-5-X-Y
+ , "Service"
+ , "Anonymous"
+ , "Proxy"
+ , "EnterpriseDC"
+ , "Self"
+ , "AuthenticatedUsers"
+ , "RestrictedCode"
+ , "TerminalServer"
+ , "RemoteInteractiveLogon"
+ , "ThisOrganization"
+ , "16"
+ , "IUserIIS"
+ , "LocalSystem"
+ , "LocalService"
+ , "NetworkService"
+ , "Domains"
};
struct CSecID2Name
@@ -207,7 +226,7 @@ struct CSecID2Name
const char *sz;
};
-const CSecID2Name sid_32_Names[] =
+static const CSecID2Name sid_32_Names[] =
{
{ 544, "Administrators" },
{ 545, "Users" },
@@ -297,7 +316,7 @@ static void ParseSid(AString &s, const Byte *p, UInt32 lim, UInt32 &sidSize)
if (v0 == 32 && num == 2)
{
UInt32 v1 = Get32(p + 12);
- for (int i = 0; i < ARRAY_SIZE(sid_32_Names); i++)
+ for (unsigned i = 0; i < ARRAY_SIZE(sid_32_Names); i++)
if (sid_32_Names[i].n == v1)
{
s += sid_32_Names[i].sz;
@@ -307,7 +326,7 @@ static void ParseSid(AString &s, const Byte *p, UInt32 lim, UInt32 &sidSize)
if (v0 == 21 && num == 5)
{
UInt32 v4 = Get32(p + 8 + 4 * 4);
- for (int i = 0; i < ARRAY_SIZE(sid_21_Names); i++)
+ for (unsigned i = 0; i < ARRAY_SIZE(sid_21_Names); i++)
if (sid_21_Names[i].n == v4)
{
s += sid_21_Names[i].sz;
@@ -316,7 +335,7 @@ static void ParseSid(AString &s, const Byte *p, UInt32 lim, UInt32 &sidSize)
}
if (v0 == 80 && num == 6)
{
- for (int i = 0; i < ARRAY_SIZE(services_to_name); i++)
+ for (unsigned i = 0; i < ARRAY_SIZE(services_to_name); i++)
{
const CServicesToName &sn = services_to_name[i];
int j;
@@ -385,10 +404,11 @@ static void ParseAcl(AString &s, const Byte *p, UInt32 size, const char *strName
return;
if (Get16(p) != 2) // revision
return;
- // UInt32 aclSize = Get16(p + 2);
UInt32 num = Get32(p + 4);
AddUInt32ToString(s, num);
+
/*
+ UInt32 aclSize = Get16(p + 2);
if (num >= (1 << 16))
return;
if (aclSize > size)
@@ -409,14 +429,15 @@ static void ParseAcl(AString &s, const Byte *p, UInt32 size, const char *strName
UInt32 sidSize = 0;
s += ' ';
- s += ParseSid(p, size, sidSize);
+ ParseSid(s, p, size, sidSize);
if (sidSize == 0)
return;
p += sidSize;
size -= sidSize;
}
- if (size != 0)
- s += " ERROR";
+
+ // the tail can contain zeros. So (size != 0) is not ERROR
+ // if (size != 0) s += " ERROR";
*/
}
@@ -461,7 +482,7 @@ void ConvertNtSecureToString(const Byte *data, UInt32 size, AString &s)
#ifdef _WIN32
-static bool CheckSid(const Byte *data, UInt32 size, UInt32 pos)
+static bool CheckSid(const Byte *data, UInt32 size, UInt32 pos) throw()
{
if (pos >= size)
return false;
@@ -475,7 +496,7 @@ static bool CheckSid(const Byte *data, UInt32 size, UInt32 pos)
return (8 + num * 4 <= size);
}
-static bool CheckAcl(const Byte *p, UInt32 size, UInt32 flags, UInt32 offset)
+static bool CheckAcl(const Byte *p, UInt32 size, UInt32 flags, UInt32 offset) throw()
{
UInt32 control = Get16(p + 2);
if ((flags & control) == 0)
@@ -491,7 +512,7 @@ static bool CheckAcl(const Byte *p, UInt32 size, UInt32 flags, UInt32 offset)
return (aclSize <= size);
}
-bool CheckNtSecure(const Byte *data, UInt32 size)
+bool CheckNtSecure(const Byte *data, UInt32 size) throw()
{
if (size < 20)
return false;
@@ -515,11 +536,11 @@ bool ConvertNtReparseToString(const Byte *data, UInt32 size, UString &s)
if (attr.Parse(data, size))
{
if (!attr.IsSymLink())
- s += L"Junction: ";
+ s.AddAscii("Junction: ");
s += attr.GetPath();
if (!attr.IsOkNamePair())
{
- s += L" : ";
+ s.AddAscii(" : ");
s += attr.PrintName;
}
return true;
@@ -536,16 +557,16 @@ bool ConvertNtReparseToString(const Byte *data, UInt32 size, UString &s)
char hex[16];
ConvertUInt32ToHex8Digits(tag, hex);
- s.AddAsciiStr(hex);
- s += L' ';
+ s.AddAscii(hex);
+ s.Add_Space();
data += 8;
for (UInt32 i = 0; i < len; i++)
{
- Byte b = ((const Byte *)data)[i];
- s += (wchar_t)GetHex((Byte)((b >> 4) & 0xF));
- s += (wchar_t)GetHex((Byte)(b & 0xF));
+ unsigned b = ((const Byte *)data)[i];
+ s += (wchar_t)GetHex((b >> 4) & 0xF);
+ s += (wchar_t)GetHex(b & 0xF);
}
return true;
}