other-licenses/7zstub/src/7zip/Archive/7z/7zProperties.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 // 7zProperties.cpp
michael@0 2
michael@0 3 #include "StdAfx.h"
michael@0 4
michael@0 5 #include "7zProperties.h"
michael@0 6 #include "7zHeader.h"
michael@0 7 #include "7zHandler.h"
michael@0 8
michael@0 9 // #define _MULTI_PACK
michael@0 10
michael@0 11 namespace NArchive {
michael@0 12 namespace N7z {
michael@0 13
michael@0 14 struct CPropMap
michael@0 15 {
michael@0 16 UInt64 FilePropID;
michael@0 17 STATPROPSTG StatPROPSTG;
michael@0 18 };
michael@0 19
michael@0 20 CPropMap kPropMap[] =
michael@0 21 {
michael@0 22 { NID::kName, NULL, kpidPath, VT_BSTR},
michael@0 23 { NID::kSize, NULL, kpidSize, VT_UI8},
michael@0 24 { NID::kPackInfo, NULL, kpidPackedSize, VT_UI8},
michael@0 25
michael@0 26 #ifdef _MULTI_PACK
michael@0 27 { 100, L"Pack0", kpidPackedSize0, VT_UI8},
michael@0 28 { 101, L"Pack1", kpidPackedSize1, VT_UI8},
michael@0 29 { 102, L"Pack2", kpidPackedSize2, VT_UI8},
michael@0 30 { 103, L"Pack3", kpidPackedSize3, VT_UI8},
michael@0 31 { 104, L"Pack4", kpidPackedSize4, VT_UI8},
michael@0 32 #endif
michael@0 33
michael@0 34 { NID::kCreationTime, NULL, kpidCreationTime, VT_FILETIME},
michael@0 35 { NID::kLastWriteTime, NULL, kpidLastWriteTime, VT_FILETIME},
michael@0 36 { NID::kLastAccessTime, NULL, kpidLastAccessTime, VT_FILETIME},
michael@0 37 { NID::kWinAttributes, NULL, kpidAttributes, VT_UI4},
michael@0 38 { NID::kStartPos, NULL, kpidPosition, VT_UI4},
michael@0 39
michael@0 40
michael@0 41 { NID::kCRC, NULL, kpidCRC, VT_UI4},
michael@0 42
michael@0 43 { NID::kAnti, L"Anti", kpidIsAnti, VT_BOOL},
michael@0 44 // { 97, NULL, kpidSolid, VT_BOOL},
michael@0 45 #ifndef _SFX
michael@0 46 { 98, NULL, kpidMethod, VT_BSTR},
michael@0 47 { 99, L"Block", kpidBlock, VT_UI4}
michael@0 48 #endif
michael@0 49 // { L"ID", kpidID, VT_BSTR},
michael@0 50 // { L"UnPack Version", kpidUnPackVersion, VT_UI1},
michael@0 51 // { L"Host OS", kpidHostOS, VT_BSTR}
michael@0 52 };
michael@0 53
michael@0 54 static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);
michael@0 55
michael@0 56 static int FindPropInMap(UInt64 filePropID)
michael@0 57 {
michael@0 58 for (int i = 0; i < kPropMapSize; i++)
michael@0 59 if (kPropMap[i].FilePropID == filePropID)
michael@0 60 return i;
michael@0 61 return -1;
michael@0 62 }
michael@0 63
michael@0 64 static void CopyOneItem(CRecordVector<UInt64> &src,
michael@0 65 CRecordVector<UInt64> &dest, UInt32 item)
michael@0 66 {
michael@0 67 for (int i = 0; i < src.Size(); i++)
michael@0 68 if (src[i] == item)
michael@0 69 {
michael@0 70 dest.Add(item);
michael@0 71 src.Delete(i);
michael@0 72 return;
michael@0 73 }
michael@0 74 }
michael@0 75
michael@0 76 static void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)
michael@0 77 {
michael@0 78 for (int i = 0; i < src.Size(); i++)
michael@0 79 if (src[i] == item)
michael@0 80 {
michael@0 81 src.Delete(i);
michael@0 82 return;
michael@0 83 }
michael@0 84 }
michael@0 85
michael@0 86 static void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)
michael@0 87 {
michael@0 88 for (int i = 0; i < dest.Size(); i++)
michael@0 89 if (dest[i] == item)
michael@0 90 {
michael@0 91 dest.Delete(i);
michael@0 92 break;
michael@0 93 }
michael@0 94 dest.Insert(0, item);
michael@0 95 }
michael@0 96
michael@0 97 void CHandler::FillPopIDs()
michael@0 98 {
michael@0 99 _fileInfoPopIDs.Clear();
michael@0 100
michael@0 101 #ifdef _7Z_VOL
michael@0 102 if(_volumes.Size() < 1)
michael@0 103 return;
michael@0 104 const CVolume &volume = _volumes.Front();
michael@0 105 const CArchiveDatabaseEx &_database = volume.Database;
michael@0 106 #endif
michael@0 107
michael@0 108 CRecordVector<UInt64> fileInfoPopIDs = _database.ArchiveInfo.FileInfoPopIDs;
michael@0 109
michael@0 110 RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);
michael@0 111 RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);
michael@0 112
michael@0 113 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);
michael@0 114 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);
michael@0 115 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);
michael@0 116 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);
michael@0 117 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCreationTime);
michael@0 118 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastWriteTime);
michael@0 119 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastAccessTime);
michael@0 120 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);
michael@0 121 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);
michael@0 122 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);
michael@0 123 _fileInfoPopIDs += fileInfoPopIDs;
michael@0 124
michael@0 125 #ifndef _SFX
michael@0 126 _fileInfoPopIDs.Add(98);
michael@0 127 _fileInfoPopIDs.Add(99);
michael@0 128 #endif
michael@0 129 #ifdef _MULTI_PACK
michael@0 130 _fileInfoPopIDs.Add(100);
michael@0 131 _fileInfoPopIDs.Add(101);
michael@0 132 _fileInfoPopIDs.Add(102);
michael@0 133 _fileInfoPopIDs.Add(103);
michael@0 134 _fileInfoPopIDs.Add(104);
michael@0 135 #endif
michael@0 136
michael@0 137 #ifndef _SFX
michael@0 138 InsertToHead(_fileInfoPopIDs, NID::kLastWriteTime);
michael@0 139 InsertToHead(_fileInfoPopIDs, NID::kPackInfo);
michael@0 140 InsertToHead(_fileInfoPopIDs, NID::kSize);
michael@0 141 InsertToHead(_fileInfoPopIDs, NID::kName);
michael@0 142 #endif
michael@0 143 }
michael@0 144
michael@0 145 STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
michael@0 146 {
michael@0 147 *numProperties = _fileInfoPopIDs.Size();
michael@0 148 return S_OK;
michael@0 149 }
michael@0 150
michael@0 151 STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index,
michael@0 152 BSTR *name, PROPID *propID, VARTYPE *varType)
michael@0 153 {
michael@0 154 if((int)index >= _fileInfoPopIDs.Size())
michael@0 155 return E_INVALIDARG;
michael@0 156 int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);
michael@0 157 if (indexInMap == -1)
michael@0 158 return E_INVALIDARG;
michael@0 159 const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;
michael@0 160 *propID = srcItem.propid;
michael@0 161 *varType = srcItem.vt;
michael@0 162 *name = 0;
michael@0 163 return S_OK;
michael@0 164 }
michael@0 165
michael@0 166 }}

mercurial