~ubuntu-branches/ubuntu/precise/p7zip/precise-updates

« back to all changes in this revision

Viewing changes to CPP/7zip/Archive/RPM/RpmIn.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2009-02-14 20:12:27 UTC
  • mfrom: (1.1.11 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090214201227-go63qxm9ozfdma60
Tags: 4.65~dfsg.1-1
* New upstream release.
* Remove wx2.8 Build-Depends added by mistakes (7zG is not yet
  intended to be built).
* Use dh_clean without -k.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Archive/RpmIn.cpp
2
 
 
3
 
#include "StdAfx.h"
4
 
 
5
 
#include "RpmIn.h"
6
 
 
7
 
#include "RpmHeader.h"
8
 
 
9
 
#include "Windows/Defs.h"
10
 
#include "Common/MyCom.h"
11
 
 
12
 
#include "../../Common/StreamUtils.h"
13
 
 
14
 
namespace NArchive {
15
 
namespace NRpm {
16
 
 
17
 
static UInt16 GetUInt16(const char *data)
18
 
{
19
 
  return (UInt16)((Byte)data[1] | (((UInt16)(Byte)data[0]) << 8));
20
 
}
21
 
 
22
 
static UInt32 GetUInt32(const char *data)
23
 
{
24
 
  return 
25
 
      ((UInt32)(Byte)data[3]) |
26
 
      (((UInt32)(Byte)data[2]) << 8) |
27
 
      (((UInt32)(Byte)data[1]) << 16) |
28
 
      (((UInt32)(Byte)data[0]) << 24);
29
 
}
30
 
 
31
 
static HRESULT RedSigHeaderSig(IInStream *inStream, CSigHeaderSig &h)
32
 
{
33
 
  char dat[kCSigHeaderSigSize];
34
 
  char *cur = dat;
35
 
  RINOK(ReadStream_FALSE(inStream, dat, kCSigHeaderSigSize));
36
 
  memmove(h.Magic, cur, 4);
37
 
  cur += 4;
38
 
  cur += 4;
39
 
  h.IndexLen = GetUInt32(cur);
40
 
  cur += 4;
41
 
  h.DataLen = GetUInt32(cur);
42
 
  return S_OK;
43
 
}
44
 
 
45
 
HRESULT OpenArchive(IInStream *inStream)
46
 
{
47
 
  UInt64 pos;
48
 
  char leadData[kLeadSize];
49
 
  char *cur = leadData;
50
 
  CLead lead;
51
 
  RINOK(ReadStream_FALSE(inStream, leadData, kLeadSize));
52
 
  memmove(lead.Magic, cur, 4);
53
 
  cur += 4;
54
 
  lead.Major = *cur++;
55
 
  lead.Minor = *cur++;
56
 
  lead.Type = GetUInt16(cur);
57
 
  cur += 2;
58
 
  lead.ArchNum = GetUInt16(cur);
59
 
  cur += 2;
60
 
  memmove(lead.Name, cur, sizeof(lead.Name));
61
 
  cur += sizeof(lead.Name);
62
 
  lead.OSNum = GetUInt16(cur);
63
 
  cur += 2;
64
 
  lead.SignatureType = GetUInt16(cur);
65
 
  cur += 2;
66
 
 
67
 
  if (!lead.MagicCheck() || lead.Major < 3)
68
 
    return S_FALSE;
69
 
 
70
 
  CSigHeaderSig sigHeader, header;
71
 
  if(lead.SignatureType == RPMSIG_NONE)
72
 
  {
73
 
    ;
74
 
  }
75
 
  else if(lead.SignatureType == RPMSIG_PGP262_1024)
76
 
  {
77
 
    UInt64 pos;
78
 
    RINOK(inStream->Seek(256, STREAM_SEEK_CUR, &pos));
79
 
  }
80
 
  else if(lead.SignatureType == RPMSIG_HEADERSIG)
81
 
  {
82
 
    RINOK(RedSigHeaderSig(inStream, sigHeader));
83
 
    if(!sigHeader.MagicCheck())
84
 
      return S_FALSE;
85
 
    UInt32 len = sigHeader.GetLostHeaderLen();
86
 
    RINOK(inStream->Seek(len, STREAM_SEEK_CUR, &pos));
87
 
    if((pos % 8) != 0)
88
 
    {
89
 
      RINOK(inStream->Seek((pos / 8 + 1) * 8 - pos, 
90
 
          STREAM_SEEK_CUR, &pos));
91
 
    }
92
 
  }
93
 
  else
94
 
    return S_FALSE;
95
 
 
96
 
  RINOK(RedSigHeaderSig(inStream, header));
97
 
  if(!header.MagicCheck())
98
 
    return S_FALSE;
99
 
  int headerLen = header.GetLostHeaderLen();
100
 
  if(headerLen == -1)
101
 
    return S_FALSE;
102
 
  RINOK(inStream->Seek(headerLen, STREAM_SEEK_CUR, &pos));
103
 
  return S_OK;
104
 
}
105
 
 
106
 
}}