Lines 1-226
Link Here
|
1 |
Index: src/ole.c |
|
|
2 |
=================================================================== |
3 |
RCS file: /work/oss/catdoc/src/ole.c,v |
4 |
retrieving revision 1.14 |
5 |
diff -u -w -b -B -r1.14 ole.c |
6 |
--- src/ole.c 24 Dec 2003 12:20:46 -0000 1.14 |
7 |
+++ src/ole.c 26 Oct 2004 09:53:48 -0000 |
8 |
@@ -24,7 +24,7 @@ |
9 |
|
10 |
#define min(a,b) ((a) < (b) ? (a) : (b)) |
11 |
|
12 |
-long int sectorSize; |
13 |
+long int sectorSize, shortSectorSize; |
14 |
/* BBD Info */ |
15 |
long int bbdStart, bbdNumBlocks; |
16 |
unsigned char *BBD=NULL; |
17 |
@@ -39,6 +39,14 @@ |
18 |
|
19 |
static char ole_sign[]={0xD0,0xCF,0x11,0xE0,0xA1,0xB1,0x1A,0xE1,0}; |
20 |
|
21 |
+long int pow2(int n) { |
22 |
+ long int acc=1,i; |
23 |
+ for(i=0; i<n;i++) |
24 |
+ acc*=2; |
25 |
+ return acc; |
26 |
+} |
27 |
+ |
28 |
+ |
29 |
/** |
30 |
* Initializes ole structure |
31 |
* |
32 |
@@ -52,9 +60,10 @@ |
33 |
*/ |
34 |
FILE* ole_init(FILE *f, void *buffer, size_t bufSize) { |
35 |
unsigned char oleBuf[BBD_BLOCK_SIZE]; |
36 |
+ unsigned char *tmpBuf; |
37 |
FILE *newfile; |
38 |
int ret=0, i; |
39 |
- long int sbdMaxLen, sbdCurrent, propMaxLen, propCurrent; |
40 |
+ long int sbdMaxLen, sbdCurrent, propMaxLen, propCurrent, mblock; |
41 |
oleEntry *tEntry; |
42 |
|
43 |
/* deleting old data (if it was allocated) */ |
44 |
@@ -83,6 +92,7 @@ |
45 |
} |
46 |
fseek(newfile,0,SEEK_END); |
47 |
fileLength=ftell(newfile); |
48 |
+/* fprintf(stderr, "fileLength=%ld\n", fileLength); */ |
49 |
fseek(newfile,0,SEEK_SET); |
50 |
ret=fread(oleBuf,1,BBD_BLOCK_SIZE,newfile); |
51 |
if ( ret != BBD_BLOCK_SIZE ) { |
52 |
@@ -91,33 +101,61 @@ |
53 |
if (strncmp(oleBuf,ole_sign,8) != 0) { |
54 |
return NULL; |
55 |
} |
56 |
-/* if ( (sectorSize = BBD_BLOCK_SIZE * getlong(oleBuf,0x40)) == 0) */ |
57 |
- sectorSize = BBD_BLOCK_SIZE; |
58 |
+ sectorSize = pow2(getshort(oleBuf,0x1e)); |
59 |
+ shortSectorSize=pow2(getshort(oleBuf,0x20)); |
60 |
|
61 |
/* Read BBD into memory */ |
62 |
bbdStart=getlong(oleBuf,0x4c); |
63 |
bbdNumBlocks = getulong(oleBuf,0x2c); |
64 |
- if((BBD=malloc(bbdNumBlocks*BBD_BLOCK_SIZE)) == NULL ) { |
65 |
+ if((BBD=malloc(bbdNumBlocks*sectorSize)) == NULL ) { |
66 |
return NULL; |
67 |
} |
68 |
+ |
69 |
+ if((tmpBuf=malloc(MSAT_ORIG_SIZE)) == NULL ) { |
70 |
+ return NULL; |
71 |
+ } |
72 |
+ memcpy(tmpBuf,oleBuf+0x4c,MSAT_ORIG_SIZE); |
73 |
+ mblock=getulong(oleBuf,0x44); |
74 |
+ i=0; |
75 |
+/* fprintf(stderr, "i=%d mblock=%ld\n", i, mblock); */ |
76 |
+ while(mblock>=0) { |
77 |
+ char *newbuf; |
78 |
+ if ((newbuf=realloc(tmpBuf, sectorSize+MSAT_ORIG_SIZE)) != NULL) { |
79 |
+ tmpBuf=newbuf; |
80 |
+ } else { |
81 |
+ perror("BDB realloc error"); |
82 |
+ free(tmpBuf); |
83 |
+ ole_finish(); |
84 |
+ return NULL; |
85 |
+ } |
86 |
+ |
87 |
+ fseek(newfile, 512+mblock*sectorSize, SEEK_SET); |
88 |
+ fread(tmpBuf+MSAT_ORIG_SIZE+sectorSize*i, 1, sectorSize, newfile); |
89 |
+ i++; |
90 |
+ mblock=getulong(tmpBuf, MSAT_ORIG_SIZE+sectorSize*i-4); |
91 |
+/* fprintf(stderr, "i=%d mblock=%ld\n", i, mblock); */ |
92 |
+ }; |
93 |
+ |
94 |
/* fprintf(stderr, "bbdNumBlocks=%ld\n", bbdNumBlocks); */ |
95 |
for(i=0; i< bbdNumBlocks; i++) { |
96 |
- long int bbdSector=getlong(oleBuf,0x4c+4*i); |
97 |
+ long int bbdSector=getlong(tmpBuf,4*i); |
98 |
|
99 |
- if (bbdSector >= fileLength/sectorSize) { |
100 |
+/* fprintf(stderr, "bbdSector(%d)=%ld\n",i,bbdSector); */ |
101 |
+ if (bbdSector >= fileLength/sectorSize || bbdSector < 0) { |
102 |
fprintf(stderr, "Bad BBD entry!\n"); |
103 |
ole_finish(); |
104 |
return NULL; |
105 |
} |
106 |
-/* fprintf(stderr, "bbdSector=%ld\n",bbdSector); */ |
107 |
- fseek(newfile, (bbdSector+1)*BBD_BLOCK_SIZE, SEEK_SET); |
108 |
- if ( fread(BBD+i*BBD_BLOCK_SIZE, 1, BBD_BLOCK_SIZE, newfile) != |
109 |
- BBD_BLOCK_SIZE ) { |
110 |
+ fseek(newfile, 512+bbdSector*sectorSize, SEEK_SET); |
111 |
+ if ( fread(BBD+i*sectorSize, 1, sectorSize, newfile) != sectorSize ) { |
112 |
fprintf(stderr, "Can't read BBD!\n"); |
113 |
+ free(tmpBuf); |
114 |
ole_finish(); |
115 |
return NULL; |
116 |
} |
117 |
} |
118 |
+ free(tmpBuf); |
119 |
+ |
120 |
/* Read SBD into memory */ |
121 |
sbdLen=0; |
122 |
sbdMaxLen=10; |
123 |
@@ -128,8 +166,8 @@ |
124 |
return NULL; |
125 |
} |
126 |
while(1) { |
127 |
- fseek(newfile, (sbdCurrent+1)*sectorSize, SEEK_SET); |
128 |
- fread(SBD+sbdLen*BBD_BLOCK_SIZE, 1, sectorSize, newfile); |
129 |
+ fseek(newfile, 512+sbdCurrent*sectorSize, SEEK_SET); |
130 |
+ fread(SBD+sbdLen*sectorSize, 1, sectorSize, newfile); |
131 |
sbdLen++; |
132 |
if (sbdLen >= sbdMaxLen) { |
133 |
char *newSBD; |
134 |
@@ -148,7 +186,7 @@ |
135 |
sbdCurrent >= fileLength/sectorSize) |
136 |
break; |
137 |
} |
138 |
- sbdNumber = (sbdLen*sectorSize)/SBD_BLOCK_SIZE; |
139 |
+ sbdNumber = (sbdLen*sectorSize)/shortSectorSize; |
140 |
/* fprintf(stderr, "sbdLen=%ld sbdNumber=%ld\n",sbdLen, sbdNumber); */ |
141 |
} else { |
142 |
SBD=NULL; |
143 |
@@ -164,7 +202,7 @@ |
144 |
} |
145 |
while(1) { |
146 |
/* fprintf(stderr, "propCurrent=%ld\n",propCurrent); */ |
147 |
- fseek(newfile, (propCurrent+1)*sectorSize, SEEK_SET); |
148 |
+ fseek(newfile, 512+propCurrent*sectorSize, SEEK_SET); |
149 |
fread(properties+propLen*sectorSize, |
150 |
1, sectorSize, newfile); |
151 |
propLen++; |
152 |
@@ -279,7 +317,7 @@ |
153 |
if (e->startBlock >= 0 && |
154 |
e->length > 0 && |
155 |
(e->startBlock <= |
156 |
- fileLength/(e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE))) { |
157 |
+ fileLength/(e->isBigBlock ? sectorSize : shortSectorSize))) { |
158 |
if((e->blocks=malloc(chainMaxLen*sizeof(long int))) == NULL ) { |
159 |
return NULL; |
160 |
} |
161 |
@@ -308,18 +346,18 @@ |
162 |
} |
163 |
if(chainCurrent <= 0 || |
164 |
chainCurrent >= ( e->isBigBlock ? |
165 |
- ((bbdNumBlocks*BBD_BLOCK_SIZE)/4) |
166 |
- : ((sbdNumber*SBD_BLOCK_SIZE)/4) ) || |
167 |
+ ((bbdNumBlocks*sectorSize)/4) |
168 |
+ : ((sbdNumber*shortSectorSize)/4) ) || |
169 |
(e->numOfBlocks > |
170 |
- e->length/(e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE))) { |
171 |
+ e->length/(e->isBigBlock ? sectorSize : shortSectorSize))) { |
172 |
/* fprintf(stderr, "chain End=%ld\n", chainCurrent); */ |
173 |
break; |
174 |
} |
175 |
|
176 |
} |
177 |
} |
178 |
- if(e->length > (e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE)*e->numOfBlocks) |
179 |
- e->length = (e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE)*e->numOfBlocks; |
180 |
+ if(e->length > (e->isBigBlock ? sectorSize : shortSectorSize)*e->numOfBlocks) |
181 |
+ e->length = (e->isBigBlock ? sectorSize : shortSectorSize)*e->numOfBlocks; |
182 |
/* fprintf(stderr, "READDIR: e->name=%s e->numOfBlocks=%ld length=%ld\n", |
183 |
e->name, e->numOfBlocks, e->length);*/ |
184 |
|
185 |
@@ -354,13 +392,13 @@ |
186 |
long int calcFileBlockOffset(oleEntry *e, long int blk) { |
187 |
long int res; |
188 |
if ( e->isBigBlock ) { |
189 |
- res=(e->blocks[blk]+1)*sectorSize; |
190 |
+ res=512+e->blocks[blk]*sectorSize; |
191 |
} else { |
192 |
- long int sbdPerSector=sectorSize/SBD_BLOCK_SIZE; |
193 |
+ long int sbdPerSector=sectorSize/shortSectorSize; |
194 |
long int sbdSecNum=e->blocks[blk]/sbdPerSector; |
195 |
long int sbdSecMod=e->blocks[blk]%sbdPerSector; |
196 |
- res=(rootEntry->blocks[sbdSecNum]+1)*sectorSize + |
197 |
- sbdSecMod*SBD_BLOCK_SIZE; |
198 |
+ res=512+rootEntry->blocks[sbdSecNum]*sectorSize + |
199 |
+ sbdSecMod*shortSectorSize; |
200 |
} |
201 |
return res; |
202 |
} |
203 |
@@ -386,7 +424,7 @@ |
204 |
if( e->readed+llen > e->length ) |
205 |
llen= e->length - e->readed; |
206 |
|
207 |
- ssize = (e->isBigBlock ? sectorSize : SBD_BLOCK_SIZE); |
208 |
+ ssize = (e->isBigBlock ? sectorSize : shortSectorSize); |
209 |
blockNumber=e->readed/ssize; |
210 |
/* fprintf(stderr, "blockNumber=%ld e->numOfBlocks=%ld llen=%ld\n", */ |
211 |
/* blockNumber, e->numOfBlocks, llen); */ |
212 |
Index: src/ole.h |
213 |
=================================================================== |
214 |
RCS file: /work/oss/catdoc/src/ole.h,v |
215 |
retrieving revision 1.3 |
216 |
diff -u -w -b -B -r1.3 ole.h |
217 |
--- src/ole.h 14 Nov 2003 14:32:39 -0000 1.3 |
218 |
+++ src/ole.h 26 Oct 2004 09:53:48 -0000 |
219 |
@@ -17,6 +17,7 @@ |
220 |
#define SBD_BLOCK_SIZE 64 |
221 |
#define PROP_BLOCK_SIZE 128 |
222 |
#define OLENAMELENGHT 32 |
223 |
+#define MSAT_ORIG_SIZE 436 |
224 |
|
225 |
typedef enum { |
226 |
oleDir=1, |