Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/UI/Common/PropIDUtils.cpp')
-rw-r--r--CPP/7zip/UI/Common/PropIDUtils.cpp177
1 files changed, 98 insertions, 79 deletions
diff --git a/CPP/7zip/UI/Common/PropIDUtils.cpp b/CPP/7zip/UI/Common/PropIDUtils.cpp
index c2ceceae..32001624 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:
@@ -132,6 +152,7 @@ void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID pr
break;
}
}
+
ConvertPropVariantToShortString(prop, dest);
}
@@ -139,29 +160,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 +192,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 +224,7 @@ struct CSecID2Name
const char *sz;
};
-const CSecID2Name sid_32_Names[] =
+static const CSecID2Name sid_32_Names[] =
{
{ 544, "Administrators" },
{ 545, "Users" },
@@ -297,7 +314,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 +324,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 +333,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 +402,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 +427,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 +480,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 +494,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 +510,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 +534,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 +555,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;
}