-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathxtar.cpp
executable file
·145 lines (110 loc) · 3.83 KB
/
xtar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Copyright (c) 2017-2024 hors<[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "xtar.h"
XTAR::XTAR(QIODevice *pDevice) : XArchive(pDevice)
{
}
bool XTAR::isValid(PDSTRUCT *pPdStruct)
{
_MEMORY_MAP memoryMap = XBinary::getMemoryMap(MAPMODE_UNKNOWN, pPdStruct);
return _isValid(&memoryMap, 0, pPdStruct);
}
bool XTAR::_isValid(_MEMORY_MAP *pMemoryMap, qint64 nOffset, PDSTRUCT *pPdStruct)
{
// TODO more checks
bool bResult = false;
if ((getSize() - nOffset) >= 0x200) // TODO const
{
if (compareSignature(pMemoryMap, "00'ustar'", nOffset + 0x100, pPdStruct)) {
bResult = true;
}
}
return bResult;
}
bool XTAR::isValid(QIODevice *pDevice)
{
XTAR xtar(pDevice);
return xtar.isValid();
}
quint64 XTAR::getNumberOfRecords(PDSTRUCT *pPdStruct)
{
quint64 nResult = 0;
_MEMORY_MAP memoryMap = XBinary::getMemoryMap(MAPMODE_UNKNOWN, pPdStruct);
qint64 nOffset = 0;
while (!(pPdStruct->bIsStop)) {
XTAR::posix_header header = read_posix_header(nOffset);
if (!compareMemory(header.magic, "ustar", 6)) {
break;
}
nResult++;
nOffset += (0x200);
nOffset += align_up(QString(header.size).toULongLong(0, 8), 0x200);
}
return nResult;
}
QList<XArchive::RECORD> XTAR::getRecords(qint32 nLimit, PDSTRUCT *pPdStruct)
{
QList<XArchive::RECORD> listResult;
qint64 nOffset = 0;
qint32 nIndex = 0;
while (!(pPdStruct->bIsStop)) {
XTAR::posix_header header = read_posix_header(nOffset);
if (!compareMemory(header.magic, "ustar", 6)) {
break;
}
RECORD record = {};
record.compressMethod = COMPRESS_METHOD_STORE;
record.nDataOffset = nOffset + 0x200;
record.nHeaderOffset = nOffset;
record.nHeaderSize = 0x200;
record.nUncompressedSize = QString(header.size).toULongLong(0, 8);
record.sFileName = header.name;
record.nCompressedSize = record.nUncompressedSize;
listResult.append(record);
nIndex++;
if ((nLimit != -1) && (nIndex > nLimit)) {
break;
}
nOffset += (0x200);
nOffset += align_up(record.nCompressedSize, 0x200);
}
return listResult;
}
QString XTAR::getFileFormatExt()
{
return "tar";
}
QList<XBinary::MAPMODE> XTAR::getMapModesList()
{
QList<MAPMODE> listResult;
listResult.append(MAPMODE_REGIONS);
return listResult;
}
XBinary::FT XTAR::getFileType()
{
return FT_TAR;
}
XTAR::posix_header XTAR::read_posix_header(qint64 nOffset)
{
posix_header record = {};
read_array(nOffset, (char *)&record, sizeof(record));
return record;
}