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)  

encname.cpp
Go to the documentation of this file.
1#include "rar.hpp"
2
4{
5 Flags=0;
6 FlagBits=0;
7 FlagsPos=0;
8 DestSize=0;
9}
10
11
12
13
14void EncodeFileName::Decode(char *Name,size_t NameSize,byte *EncName,size_t EncSize,
15 wchar *NameW,size_t MaxDecSize)
16{
17 size_t EncPos=0,DecPos=0;
18 byte HighByte=EncPos<EncSize ? EncName[EncPos++] : 0;
19 while (EncPos<EncSize && DecPos<MaxDecSize)
20 {
21 if (FlagBits==0)
22 {
23 Flags=EncName[EncPos++];
24 FlagBits=8;
25 }
26 switch(Flags>>6)
27 {
28 case 0:
29 if (EncPos>=EncSize)
30 break;
31 NameW[DecPos++]=EncName[EncPos++];
32 break;
33 case 1:
34 if (EncPos>=EncSize)
35 break;
36 NameW[DecPos++]=EncName[EncPos++]+(HighByte<<8);
37 break;
38 case 2:
39 if (EncPos+1>=EncSize)
40 break;
41 NameW[DecPos++]=EncName[EncPos]+(EncName[EncPos+1]<<8);
42 EncPos+=2;
43 break;
44 case 3:
45 {
46 if (EncPos>=EncSize)
47 break;
48 int Length=EncName[EncPos++];
49 if ((Length & 0x80)!=0)
50 {
51 if (EncPos>=EncSize)
52 break;
53 byte Correction=EncName[EncPos++];
54 for (Length=(Length&0x7f)+2;Length>0 && DecPos<MaxDecSize && DecPos<NameSize;Length--,DecPos++)
55 NameW[DecPos]=((Name[DecPos]+Correction)&0xff)+(HighByte<<8);
56 }
57 else
58 for (Length+=2;Length>0 && DecPos<MaxDecSize && DecPos<NameSize;Length--,DecPos++)
59 NameW[DecPos]=Name[DecPos];
60 }
61 break;
62 }
63 Flags<<=2;
64 FlagBits-=2;
65 }
66 NameW[DecPos<MaxDecSize ? DecPos:MaxDecSize-1]=0;
67}
size_t DestSize
Definition: encname.hpp:12
size_t FlagsPos
Definition: encname.hpp:11
void Decode(char *Name, size_t NameSize, byte *EncName, size_t EncSize, wchar *NameW, size_t MaxDecSize)
Definition: encname.cpp:14
wchar_t wchar
Definition: rartypes.hpp:13