mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-11 10:07:11 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -10,7 +10,7 @@
|
||||
namespace NArchive {
|
||||
namespace NTar {
|
||||
|
||||
HRESULT CInArchive::ReadBytes(void *data, UINT32 size, UINT32 &processedSize)
|
||||
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
|
||||
{
|
||||
RINOK(m_Stream->Read(data, size, &processedSize));
|
||||
m_Position += processedSize;
|
||||
@@ -24,7 +24,7 @@ HRESULT CInArchive::Open(IInStream *inStream)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static UINT32 OctalToNumber(const char *srcString)
|
||||
static UInt32 OctalToNumber(const char *srcString)
|
||||
{
|
||||
char *endPtr;
|
||||
return(strtoul(srcString, &endPtr, 8));
|
||||
@@ -47,86 +47,131 @@ static bool CheckOctalString(const char *srcString, int numChars)
|
||||
|
||||
#define ReturnIfBadOctal(x, y) { if (!CheckOctalString((x), (y))) return S_FALSE; }
|
||||
|
||||
static bool IsRecordLast(const NFileHeader::CRecord &record)
|
||||
static bool IsRecordLast(const char *record)
|
||||
{
|
||||
for (int i = 0; i < sizeof(record); i++)
|
||||
if (record.Padding[i] != 0)
|
||||
for (int i = 0; i < NFileHeader::kRecordSize; i++)
|
||||
if (record[i] != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ReadString(const char *s, int size, AString &result)
|
||||
{
|
||||
if (size > NFileHeader::kNameSize)
|
||||
size = NFileHeader::kNameSize;
|
||||
char tempString[NFileHeader::kNameSize + 1];
|
||||
strncpy(tempString, s, size);
|
||||
tempString[size] = '\0';
|
||||
result = tempString;
|
||||
}
|
||||
|
||||
static char GetHex(Byte value)
|
||||
{
|
||||
return (value < 10) ? ('0' + value) : ('A' + (value - 10));
|
||||
}
|
||||
|
||||
HRESULT CInArchive::GetNextItemReal(bool &filled, CItemEx &item)
|
||||
{
|
||||
item.LongLinkSize = 0;
|
||||
NFileHeader::CRecord record;
|
||||
// NFileHeader::CRecord record;
|
||||
char record[NFileHeader::kRecordSize];
|
||||
char *cur = record;
|
||||
|
||||
filled = false;
|
||||
|
||||
UINT32 processedSize;
|
||||
UInt32 processedSize;
|
||||
item.HeaderPosition = m_Position;
|
||||
RINOK(ReadBytes(&record, sizeof(record), processedSize));
|
||||
RINOK(ReadBytes(record, NFileHeader::kRecordSize, processedSize));
|
||||
if (processedSize == 0 ||
|
||||
(processedSize == sizeof(record) && IsRecordLast(record)))
|
||||
(processedSize == NFileHeader::kRecordSize && IsRecordLast(record)))
|
||||
return S_OK;
|
||||
if (processedSize < sizeof(record))
|
||||
if (processedSize < NFileHeader::kRecordSize)
|
||||
return S_FALSE;
|
||||
|
||||
NFileHeader::CHeader &header = record.Header;
|
||||
// NFileHeader::CHeader &header = record.Header;
|
||||
|
||||
char tempString[NFileHeader::kNameSize + 1];
|
||||
strncpy(tempString, header.Name, NFileHeader::kNameSize);
|
||||
tempString[NFileHeader::kNameSize] = '\0';
|
||||
item.Name = tempString;
|
||||
AString name;
|
||||
ReadString(cur, NFileHeader::kNameSize, name);
|
||||
cur += NFileHeader::kNameSize;
|
||||
|
||||
item.Name.Empty();
|
||||
int i;
|
||||
for (i = 0; i < item.Name.Length(); i++)
|
||||
if (((BYTE)item.Name[i]) < 0x20)
|
||||
for (i = 0; i < name.Length(); i++)
|
||||
{
|
||||
char c = name[i];
|
||||
if (((Byte)c) < 0x08)
|
||||
{
|
||||
return S_FALSE;
|
||||
item.LinkFlag = header.LinkFlag;
|
||||
}
|
||||
if (((Byte)c) < 0x20)
|
||||
{
|
||||
item.Name += '[';
|
||||
item.Name += GetHex(((Byte)c) >> 4);
|
||||
item.Name += GetHex(((Byte)c) & 0xF);
|
||||
item.Name += ']';
|
||||
}
|
||||
else
|
||||
item.Name += c;
|
||||
}
|
||||
|
||||
BYTE linkFlag = item.LinkFlag;
|
||||
ReturnIfBadOctal(cur, 8);
|
||||
item.Mode = OctalToNumber(cur);
|
||||
cur += 8;
|
||||
|
||||
ReturnIfBadOctal(header.Mode, 8);
|
||||
ReturnIfBadOctal(header.UID, 8);
|
||||
ReturnIfBadOctal(header.GID, 8);
|
||||
ReturnIfBadOctal(header.Size, 12);
|
||||
ReturnIfBadOctal(header.ModificationTime, 12);
|
||||
ReturnIfBadOctal(header.CheckSum, 8);
|
||||
ReturnIfBadOctal(header.DeviceMajor, 8);
|
||||
ReturnIfBadOctal(header.DeviceMinor, 8);
|
||||
ReturnIfBadOctal(cur, 8);
|
||||
item.UID = OctalToNumber(cur);
|
||||
cur += 8;
|
||||
|
||||
item.Mode = OctalToNumber(header.Mode);
|
||||
item.UID = OctalToNumber(header.UID);
|
||||
item.GID = OctalToNumber(header.GID);
|
||||
ReturnIfBadOctal(cur, 8);
|
||||
item.GID = OctalToNumber(cur);
|
||||
cur += 8;
|
||||
|
||||
ReturnIfBadOctal(cur, 12);
|
||||
item.Size = OctalToNumber(cur);
|
||||
cur += 12;
|
||||
|
||||
ReturnIfBadOctal(cur, 12);
|
||||
item.ModificationTime = OctalToNumber(cur);
|
||||
cur += 12;
|
||||
|
||||
item.Size = OctalToNumber(header.Size);
|
||||
ReturnIfBadOctal(cur, 8);
|
||||
UInt32 checkSum = OctalToNumber(cur);
|
||||
memmove(cur, NFileHeader::kCheckSumBlanks, 8);
|
||||
cur += 8;
|
||||
|
||||
item.LinkFlag = *cur++;
|
||||
Byte linkFlag = item.LinkFlag;
|
||||
|
||||
ReadString(cur, NFileHeader::kNameSize, item.LinkName);
|
||||
cur += NFileHeader::kNameSize;
|
||||
|
||||
memmove(item.Magic, cur, 8);
|
||||
cur += 8;
|
||||
|
||||
ReadString(cur, NFileHeader::kUserNameSize, item.UserName);
|
||||
cur += NFileHeader::kUserNameSize;
|
||||
ReadString(cur, NFileHeader::kUserNameSize, item.GroupName);
|
||||
cur += NFileHeader::kUserNameSize;
|
||||
|
||||
ReturnIfBadOctal(cur, 8);
|
||||
item.DeviceMajorDefined = (cur[0] != 0);
|
||||
if (item.DeviceMajorDefined)
|
||||
item.DeviceMajor = OctalToNumber(cur);
|
||||
|
||||
ReturnIfBadOctal(cur, 8);
|
||||
item.DeviceMinorDefined = (cur[0] != 0);
|
||||
if (item.DeviceMinorDefined)
|
||||
item.DeviceMinor = OctalToNumber(cur);
|
||||
cur += 8;
|
||||
|
||||
|
||||
if (item.LinkFlag == NFileHeader::NLinkFlag::kLink)
|
||||
item.Size = 0;
|
||||
|
||||
item.ModificationTime = OctalToNumber(header.ModificationTime);
|
||||
|
||||
|
||||
|
||||
item.LinkName = header.LinkName;
|
||||
memmove(item.Magic, header.Magic, 8);
|
||||
|
||||
item.UserName = header.UserName;
|
||||
item.GroupName = header.GroupName;
|
||||
|
||||
|
||||
item.DeviceMajorDefined = (header.DeviceMajor[0] != 0);
|
||||
if (item.DeviceMajorDefined)
|
||||
item.DeviceMajor = OctalToNumber(header.DeviceMajor);
|
||||
|
||||
item.DeviceMinorDefined = (header.DeviceMinor[0] != 0);
|
||||
if (item.DeviceMinorDefined)
|
||||
item.DeviceMinor = OctalToNumber(header.DeviceMinor);
|
||||
|
||||
UINT32 checkSum = OctalToNumber(header.CheckSum);
|
||||
|
||||
memmove(header.CheckSum, NFileHeader::kCheckSumBlanks, 8);
|
||||
|
||||
UINT32 checkSumReal = 0;
|
||||
UInt32 checkSumReal = 0;
|
||||
for(i = 0; i < NFileHeader::kRecordSize; i++)
|
||||
checkSumReal += BYTE(record.Padding[i]);
|
||||
checkSumReal += Byte(record[i]);
|
||||
|
||||
if (checkSumReal != checkSum)
|
||||
return S_FALSE;
|
||||
@@ -145,12 +190,12 @@ HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
|
||||
{
|
||||
if (item.Name.Compare(NFileHeader::kLongLink) != 0)
|
||||
return S_FALSE;
|
||||
UINT64 headerPosition = item.HeaderPosition;
|
||||
UInt64 headerPosition = item.HeaderPosition;
|
||||
|
||||
UINT32 processedSize;
|
||||
UInt32 processedSize;
|
||||
AString fullName;
|
||||
char *buffer = fullName.GetBuffer((UINT32)item.Size + 1);
|
||||
RINOK(ReadBytes(buffer, (UINT32)item.Size, processedSize));
|
||||
char *buffer = fullName.GetBuffer((UInt32)item.Size + 1);
|
||||
RINOK(ReadBytes(buffer, (UInt32)item.Size, processedSize));
|
||||
buffer[item.Size] = '\0';
|
||||
fullName.ReleaseBuffer();
|
||||
if (processedSize != item.Size)
|
||||
@@ -166,9 +211,9 @@ HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CInArchive::Skeep(UINT64 numBytes)
|
||||
HRESULT CInArchive::Skeep(UInt64 numBytes)
|
||||
{
|
||||
UINT64 newPostion;
|
||||
UInt64 newPostion;
|
||||
RINOK(m_Stream->Seek(numBytes, STREAM_SEEK_CUR, &newPostion));
|
||||
m_Position += numBytes;
|
||||
if (m_Position != newPostion)
|
||||
@@ -177,15 +222,9 @@ HRESULT CInArchive::Skeep(UINT64 numBytes)
|
||||
}
|
||||
|
||||
|
||||
HRESULT CInArchive::SkeepDataRecords(UINT64 dataSize)
|
||||
HRESULT CInArchive::SkeepDataRecords(UInt64 dataSize)
|
||||
{
|
||||
return Skeep((dataSize + 511) &
|
||||
#if ( __GNUC__)
|
||||
0xFFFFFFFFFFFFFE00LL
|
||||
#else
|
||||
0xFFFFFFFFFFFFFE00
|
||||
#endif
|
||||
);
|
||||
return Skeep((dataSize + 0x1FF) & (~((UInt64)0x1FF)));
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user