unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

arccmt.cpp
Go to the documentation of this file.
1static bool IsAnsiEscComment(const wchar *Data,size_t Size);
2
4{
5 if (!MainComment)
6 return false;
7 int64 SavePos=Tell();
8 bool Success=DoGetComment(CmtData);
9 Seek(SavePos,SEEK_SET);
10 return Success;
11}
12
13
15{
16#ifndef SFX_MODULE
17 uint CmtLength;
18 if (Format==RARFMT14)
19 {
21 CmtLength=GetByte();
22 CmtLength+=(GetByte()<<8);
23 }
24 else
25#endif
26 {
28 {
29 // Old style (RAR 2.9) archive comment embedded into the main
30 // archive header.
33 return false;
34 }
35 else
36 {
37 // Current (RAR 3.0+) version of archive comment.
38 Seek(GetStartPos(),SEEK_SET);
39 return SearchSubBlock(SUBHEAD_TYPE_CMT)!=0 && ReadCommentData(CmtData);
40 }
41#ifndef SFX_MODULE
42 // Old style (RAR 2.9) comment header embedded into the main
43 // archive header.
45 {
47 return false;
48 }
50#endif
51 }
52#ifndef SFX_MODULE
54 {
56 return false;
57 ComprDataIO DataIO;
58 DataIO.SetTestMode(true);
59 uint UnpCmtLength;
60 if (Format==RARFMT14)
61 {
62#ifdef RAR_NOCRYPT
63 return false;
64#else
65 UnpCmtLength=GetByte();
66 UnpCmtLength+=(GetByte()<<8);
67 if (CmtLength<2)
68 return false;
69 CmtLength-=2;
70 DataIO.SetCmt13Encryption();
72#endif
73 }
74 else
75 UnpCmtLength=CommHead.UnpSize;
76 DataIO.SetFiles(this,NULL);
77 DataIO.EnableShowProgress(false);
78 DataIO.SetPackedSizeToRead(CmtLength);
79 DataIO.UnpHash.Init(HASH_CRC32,1);
80 DataIO.SetNoFileHeader(true); // this->FileHead is not filled yet.
81
82 Unpack CmtUnpack(&DataIO);
83 CmtUnpack.Init(0x10000,false);
84 CmtUnpack.SetDestSize(UnpCmtLength);
85 CmtUnpack.DoUnpack(CommHead.UnpVer,false);
86
87 if (Format!=RARFMT14 && (DataIO.UnpHash.GetCRC32()&0xffff)!=CommHead.CommCRC)
88 {
90 return false;
91 }
92 else
93 {
94 byte *UnpData;
95 size_t UnpDataSize;
96 DataIO.GetUnpackedData(&UnpData,&UnpDataSize);
97 if (UnpDataSize>0)
98 {
99#ifdef _WIN_ALL
100 // If we ever decide to extend it to Android, we'll need to alloc
101 // 4x memory for OEM to UTF-8 output here.
102 OemToCharBuffA((char *)UnpData,(char *)UnpData,(DWORD)UnpDataSize);
103#endif
104 CmtData->Alloc(UnpDataSize+1);
105 memset(CmtData->Addr(0),0,CmtData->Size()*sizeof(wchar));
106 CharToWide((char *)UnpData,CmtData->Addr(0),CmtData->Size());
107 CmtData->Alloc(wcslen(CmtData->Addr(0)));
108 }
109 }
110 }
111 else
112 {
113 if (CmtLength==0)
114 return false;
115 Array<byte> CmtRaw(CmtLength);
116 int ReadSize=Read(&CmtRaw[0],CmtLength);
117 if (ReadSize>=0 && (uint)ReadSize<CmtLength) // Comment is shorter than declared.
118 {
119 CmtLength=ReadSize;
120 CmtRaw.Alloc(CmtLength);
121 }
122
123 if (Format!=RARFMT14 && CommHead.CommCRC!=(~CRC32(0xffffffff,&CmtRaw[0],CmtLength)&0xffff))
124 {
126 return false;
127 }
128 CmtData->Alloc(CmtLength+1);
129 CmtRaw.Push(0);
130#ifdef _WIN_ALL
131 // If we ever decide to extend it to Android, we'll need to alloc
132 // 4x memory for OEM to UTF-8 output here.
133 OemToCharA((char *)&CmtRaw[0],(char *)&CmtRaw[0]);
134#endif
135 CharToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtData->Size());
136 CmtData->Alloc(wcslen(CmtData->Addr(0)));
137 }
138#endif
139 return CmtData->Size() > 0;
140}
141
142
144{
145 Array<byte> CmtRaw;
146 if (!ReadSubData(&CmtRaw,NULL,false))
147 return false;
148 size_t CmtSize=CmtRaw.Size();
149 CmtRaw.Push(0);
150 CmtData->Alloc(CmtSize+1);
151 if (Format==RARFMT50)
152 UtfToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtData->Size());
153 else
155 {
156 RawToWide(&CmtRaw[0],CmtData->Addr(0),CmtSize/2);
157 (*CmtData)[CmtSize/2]=0;
158
159 }
160 else
161 {
162 CharToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtData->Size());
163 }
164 CmtData->Alloc(wcslen(CmtData->Addr(0))); // Set buffer size to actual comment length.
165 return true;
166}
167
168
170{
171 if (Cmd->DisableComment)
172 return;
173 Array<wchar> CmtBuf;
174 if (GetComment(&CmtBuf)) // In GUI too, so "Test" command detects broken comments.
175 {
176 size_t CmtSize=CmtBuf.Size();
177 wchar *ChPtr=wcschr(&CmtBuf[0],0x1A);
178 if (ChPtr!=NULL)
179 CmtSize=ChPtr-&CmtBuf[0];
180 mprintf(L"\n");
181 OutComment(&CmtBuf[0],CmtSize);
182 }
183}
184
185
static bool IsAnsiEscComment(const wchar *Data, size_t Size)
@ RARFMT50
Definition: archive.hpp:13
@ RARFMT14
Definition: archive.hpp:13
RAROptions * Cmd
Definition: archive.hpp:48
int64 GetStartPos()
Definition: arcread.cpp:1420
size_t ReadHeader()
Definition: arcread.cpp:3
bool BrokenHeader
Definition: archive.hpp:128
HEADER_TYPE GetHeaderType()
Definition: archive.hpp:85
bool GetComment(Array< wchar > *CmtData)
Definition: arccmt.cpp:3
bool ReadCommentData(Array< wchar > *CmtData)
Definition: arccmt.cpp:143
void ViewComment()
Definition: arccmt.cpp:169
bool MainComment
Definition: archive.hpp:120
RARFORMAT Format
Definition: archive.hpp:117
size_t SearchSubBlock(const wchar *Type)
Definition: arcread.cpp:64
size_t SFXSize
Definition: archive.hpp:127
FileHeader SubHead
Definition: archive.hpp:107
bool DoGetComment(Array< wchar > *CmtData)
Definition: arccmt.cpp:14
MainHeader MainHead
Definition: archive.hpp:102
bool ReadSubData(Array< byte > *UnpData, File *DestFile, bool TestMode)
Definition: arcread.cpp:1431
CommentHeader CommHead
Definition: archive.hpp:108
size_t Size()
Definition: array.hpp:94
void Alloc(size_t Items)
Definition: array.hpp:139
void Push(T Item)
Definition: array.hpp:177
T * Addr(size_t Item)
Definition: array.hpp:30
void SetCmt13Encryption()
Definition: rdwrfn.cpp:272
DataHash UnpHash
Definition: rdwrfn.hpp:99
void GetUnpackedData(byte **Data, size_t *Size)
Definition: rdwrfn.cpp:242
void SetNoFileHeader(bool Mode)
Definition: rdwrfn.hpp:69
void SetPackedSizeToRead(int64 Size)
Definition: rdwrfn.hpp:66
void SetFiles(File *SrcFile, File *DestFile)
Definition: rdwrfn.cpp:232
void EnableShowProgress(bool Show)
Definition: rdwrfn.hpp:64
void SetTestMode(bool Mode)
Definition: rdwrfn.hpp:67
void Init(HASH_TYPE Type, uint MaxThreads)
Definition: hash.cpp:67
uint GetCRC32()
Definition: hash.cpp:122
virtual void Seek(int64 Offset, int Method)
Definition: file.cpp:514
virtual int Read(void *Data, size_t Size)
Definition: file.cpp:374
virtual int64 Tell()
Definition: file.cpp:576
byte GetByte()
Definition: file.cpp:626
wchar FileName[NM]
Definition: file.hpp:88
bool DisableComment
Definition: options.hpp:144
void Init(size_t WinSize, bool Solid)
Definition: unpack.cpp:73
void DoUnpack(uint Method, bool Solid)
Definition: unpack.cpp:149
void SetDestSize(int64 DestSize)
Definition: unpack.hpp:381
void OutComment(const wchar *Comment, size_t Size)
Definition: consio.cpp:392
void mprintf(const wchar *fmt,...)
Definition: consio.cpp:118
uint CRC32(uint StartCRC, const void *Addr, size_t Size)
Definition: crc.cpp:62
@ HASH_CRC32
Definition: hash.hpp:4
#define SIZEOF_COMMHEAD
Definition: headers.hpp:12
#define VER_UNPACK
Definition: headers.hpp:19
#define SIZEOF_MAINHEAD3
Definition: headers.hpp:6
#define SIZEOF_MAINHEAD14
Definition: headers.hpp:5
@ HEAD3_CMT
Definition: headers.hpp:80
#define SIZEOF_MARKHEAD3
Definition: headers.hpp:4
#define SUBHEAD_FLAGS_CMT_UNICODE
Definition: headers.hpp:126
#define SUBHEAD_TYPE_CMT
Definition: headers.hpp:114
wchar_t wchar
Definition: rartypes.hpp:13
int64_t int64
Definition: rartypes.hpp:12
unsigned int uint
Definition: rartypes.hpp:8
uint HeadSize
Definition: headers.hpp:143
ushort UnpSize
Definition: headers.hpp:308
ushort CommCRC
Definition: headers.hpp:311
uint SubFlags
Definition: headers.hpp:182
bool PackComment
Definition: headers.hpp:165
bool CommentInHeader
Definition: headers.hpp:164
void uiMsg(UIMESSAGE_CODE Code)
Definition: ui.hpp:148
@ UIERROR_CMTBROKEN
Definition: ui.hpp:29
bool CharToWide(const char *Src, wchar *Dest, size_t DestSize)
Definition: unicode.cpp:85
wchar * RawToWide(const byte *Src, wchar *Dest, size_t DestSize)
Definition: unicode.cpp:246
bool UtfToWide(const char *Src, wchar *Dest, size_t DestSize)
Definition: unicode.cpp:324