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
|
// Archive/RpmIn.cpp
#include "StdAfx.h"
#include "RpmIn.h"
#include "RpmHeader.h"
#include "Windows/Defs.h"
#include "Common/MyCom.h"
#include "../../Common/StreamUtils.h"
namespace NArchive {
namespace NRpm {
static UInt16 GetUInt16(const char *data)
{
return (UInt16)((Byte)data[1] | (((UInt16)(Byte)data[0]) << 8));
}
static UInt32 GetUInt32(const char *data)
{
return
((UInt32)(Byte)data[3]) |
(((UInt32)(Byte)data[2]) << 8) |
(((UInt32)(Byte)data[1]) << 16) |
(((UInt32)(Byte)data[0]) << 24);
}
static HRESULT RedSigHeaderSig(IInStream *inStream, CSigHeaderSig &h)
{
char dat[kCSigHeaderSigSize];
char *cur = dat;
RINOK(ReadStream_FALSE(inStream, dat, kCSigHeaderSigSize));
memmove(h.Magic, cur, 4);
cur += 4;
cur += 4;
h.IndexLen = GetUInt32(cur);
cur += 4;
h.DataLen = GetUInt32(cur);
return S_OK;
}
HRESULT OpenArchive(IInStream *inStream)
{
UInt64 pos;
char leadData[kLeadSize];
char *cur = leadData;
CLead lead;
RINOK(ReadStream_FALSE(inStream, leadData, kLeadSize));
memmove(lead.Magic, cur, 4);
cur += 4;
lead.Major = *cur++;
lead.Minor = *cur++;
lead.Type = GetUInt16(cur);
cur += 2;
lead.ArchNum = GetUInt16(cur);
cur += 2;
memmove(lead.Name, cur, sizeof(lead.Name));
cur += sizeof(lead.Name);
lead.OSNum = GetUInt16(cur);
cur += 2;
lead.SignatureType = GetUInt16(cur);
cur += 2;
if (!lead.MagicCheck() || lead.Major < 3)
return S_FALSE;
CSigHeaderSig sigHeader, header;
if(lead.SignatureType == RPMSIG_NONE)
{
;
}
else if(lead.SignatureType == RPMSIG_PGP262_1024)
{
UInt64 pos;
RINOK(inStream->Seek(256, STREAM_SEEK_CUR, &pos));
}
else if(lead.SignatureType == RPMSIG_HEADERSIG)
{
RINOK(RedSigHeaderSig(inStream, sigHeader));
if(!sigHeader.MagicCheck())
return S_FALSE;
UInt32 len = sigHeader.GetLostHeaderLen();
RINOK(inStream->Seek(len, STREAM_SEEK_CUR, &pos));
if((pos % 8) != 0)
{
RINOK(inStream->Seek((pos / 8 + 1) * 8 - pos,
STREAM_SEEK_CUR, &pos));
}
}
else
return S_FALSE;
RINOK(RedSigHeaderSig(inStream, header));
if(!header.MagicCheck())
return S_FALSE;
int headerLen = header.GetLostHeaderLen();
if(headerLen == -1)
return S_FALSE;
RINOK(inStream->Seek(headerLen, STREAM_SEEK_CUR, &pos));
return S_OK;
}
}}
|