| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package cdf |
| 7 |
|
| 8 |
import ( |
| 9 |
"bytes" |
| 10 |
"encoding/binary" |
| 11 |
|
| 12 |
"github.com/gabriel-vasile/mimetype/internal/scan" |
| 13 |
) |
| 14 |
|
| 15 |
type CDFType int8 |
| 16 |
|
| 17 |
const ( |
| 18 |
CDFTypeGeneric CDFType = iota |
| 19 |
CDFTypeInstaller |
| 20 |
CDFTypeDoc |
| 21 |
CDFTypePpt |
| 22 |
CDFTypeXls |
| 23 |
CDFTypeMsg |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
func Detect(raw []byte) CDFType { |
| 30 |
if len(raw) < 512 { |
| 31 |
return CDFTypeGeneric |
| 32 |
} |
| 33 |
var c cdf |
| 34 |
if !parse(raw, &c) { |
| 35 |
return CDFTypeGeneric |
| 36 |
} |
| 37 |
return c.detect() |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
type cdf struct { |
| 42 |
data []byte |
| 43 |
secSize int |
| 44 |
shortSecSize int |
| 45 |
minStdStream uint32 |
| 46 |
satSecs int32s |
| 47 |
satEntries int |
| 48 |
firstSSAT int32 |
| 49 |
dirRaw []byte |
| 50 |
sst []byte |
| 51 |
sstBuilt bool |
| 52 |
rootStreamFirst int32 |
| 53 |
rootStreamSize uint32 |
| 54 |
rootStorageUUID []byte |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
func parse(raw []byte, c *cdf) bool { |
| 62 |
if len(raw) < 512 || binary.LittleEndian.Uint64(raw) != cdfMagic { |
| 63 |
return false |
| 64 |
} |
| 65 |
secP2 := binary.LittleEndian.Uint16(raw[30:32]) |
| 66 |
shortP2 := binary.LittleEndian.Uint16(raw[32:34]) |
| 67 |
if secP2 > 20 || shortP2 > 20 { |
| 68 |
return false |
| 69 |
} |
| 70 |
c.data = raw |
| 71 |
c.secSize = 1 << secP2 |
| 72 |
c.shortSecSize = 1 << shortP2 |
| 73 |
c.minStdStream = binary.LittleEndian.Uint32(raw[56:60]) |
| 74 |
if c.secSize < dirEntrySize { |
| 75 |
return false |
| 76 |
} |
| 77 |
firstDirSec := readSecID(raw[48:52]) |
| 78 |
c.firstSSAT = readSecID(raw[60:64]) |
| 79 |
firstMSAT := readSecID(raw[68:72]) |
| 80 |
nMSAT := binary.LittleEndian.Uint32(raw[72:76]) |
| 81 |
masterSAT := int32s{b: raw[76 : 76+4*masterSATSize]} |
| 82 |
|
| 83 |
c.buildSAT(masterSAT, firstMSAT, nMSAT) |
| 84 |
c.dirRaw = c.readLong(firstDirSec, 0) |
| 85 |
|
| 86 |
c.rootStreamFirst = -1 |
| 87 |
var d dirEntry |
| 88 |
for i, n := 0, c.dirLen(); i < n; i++ { |
| 89 |
c.dirAt(i, &d) |
| 90 |
if d.typ != dirTypeRootStorage || d.streamFirst < 0 { |
| 91 |
continue |
| 92 |
} |
| 93 |
c.rootStorageUUID = d.storageUUID[:] |
| 94 |
|
| 95 |
|
| 96 |
c.rootStreamFirst = d.streamFirst |
| 97 |
c.rootStreamSize = d.size |
| 98 |
break |
| 99 |
} |
| 100 |
return true |
| 101 |
} |
| 102 |
|
| 103 |
func (c *cdf) detect() CDFType { |
| 104 |
for _, name := range []string{"\x05SummaryInformation", "\x05DocumentSummaryInformation"} { |
| 105 |
if t, ok := c.detectFromSummary(name); ok { |
| 106 |
return t |
| 107 |
} |
| 108 |
} |
| 109 |
var d dirEntry |
| 110 |
for i, n := 0, c.dirLen(); i < n; i++ { |
| 111 |
c.dirAt(i, &d) |
| 112 |
if t, ok := lookupSection(d.nameBytes(), d.typ); ok { |
| 113 |
return t |
| 114 |
} |
| 115 |
} |
| 116 |
return CDFTypeGeneric |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
func (c *cdf) detectFromSummary(streamName string) (CDFType, bool) { |
| 123 |
if c.rootStorageUUID != nil && bytes.Equal(c.rootStorageUUID, msiCLSID) { |
| 124 |
return CDFTypeInstaller, true |
| 125 |
} |
| 126 |
raw, ok := c.userStream(streamName) |
| 127 |
if !ok { |
| 128 |
return CDFTypeGeneric, false |
| 129 |
} |
| 130 |
if app := summaryAppName(raw); len(app) > 0 { |
| 131 |
if t, ok := lookupSubstring(app, app2type); ok { |
| 132 |
return t, true |
| 133 |
} |
| 134 |
} |
| 135 |
for i, n := 0, c.dirLen(); i < n; i++ { |
| 136 |
var d dirEntry |
| 137 |
c.dirAt(i, &d) |
| 138 |
if d.nameLen == 0 { |
| 139 |
continue |
| 140 |
} |
| 141 |
if t, ok := lookupSubstring(d.nameBytes(), name2type); ok { |
| 142 |
return t, true |
| 143 |
} |
| 144 |
} |
| 145 |
return CDFTypeGeneric, true |
| 146 |
} |
| 147 |
|
| 148 |
const ( |
| 149 |
cdfMagic uint64 = 0xE11AB1A1E011CFD0 |
| 150 |
|
| 151 |
dirTypeUserStorage = 1 |
| 152 |
dirTypeUserStream = 2 |
| 153 |
dirTypeRootStorage = 5 |
| 154 |
|
| 155 |
dirEntrySize = 128 |
| 156 |
masterSATSize = 109 |
| 157 |
) |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
type dirEntry struct { |
| 164 |
name [32]byte |
| 165 |
nameLen uint8 |
| 166 |
typ uint8 |
| 167 |
streamFirst int32 |
| 168 |
size uint32 |
| 169 |
storageUUID [16]byte |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
func (d *dirEntry) nameBytes() []byte { return d.name[:d.nameLen] } |
| 174 |
|
| 175 |
func (c *cdf) ssatAt(i int32) int32 { |
| 176 |
for sid := c.firstSSAT; sid >= 0; { |
| 177 |
if int(sid) >= c.satLen() { |
| 178 |
break |
| 179 |
} |
| 180 |
buf, ok := c.sector(sid) |
| 181 |
if !ok { |
| 182 |
break |
| 183 |
} |
| 184 |
lbuf := int32(len(buf) / 4) |
| 185 |
if i < lbuf { |
| 186 |
return int32(binary.LittleEndian.Uint32(buf[4*i:])) |
| 187 |
} |
| 188 |
i -= lbuf |
| 189 |
sid = c.satAt(sid) |
| 190 |
} |
| 191 |
return -1 |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
func (c *cdf) shortStream() []byte { |
| 199 |
if !c.sstBuilt { |
| 200 |
c.sstBuilt = true |
| 201 |
if c.rootStreamFirst >= 0 { |
| 202 |
c.sst = c.readLong(c.rootStreamFirst, c.rootStreamSize) |
| 203 |
} |
| 204 |
} |
| 205 |
return c.sst |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
type int32s struct { |
| 213 |
b []byte |
| 214 |
} |
| 215 |
|
| 216 |
func (b int32s) at(i int) int32 { |
| 217 |
|
| 218 |
return int32(binary.LittleEndian.Uint32(b.b[4*i:])) |
| 219 |
} |
| 220 |
func (b int32s) len() int { |
| 221 |
return len(b.b) / 4 |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
func readSecID(b []byte) int32 { |
| 229 |
return int32(binary.LittleEndian.Uint32(b)) |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
func (c *cdf) satLen() int { return c.satEntries } |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
func (c *cdf) satAt(i int32) int32 { |
| 239 |
perSec := c.secSize / 4 |
| 240 |
secIdx := int(i) / perSec |
| 241 |
entryIdx := int(i) % perSec |
| 242 |
secID := c.satSecs.at(secIdx) |
| 243 |
off := c.secSize*(1+int(secID)) + 4*entryIdx |
| 244 |
return readSecID(c.data[off:]) |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
func (c *cdf) sector(secid int32) (_ []byte, ok bool) { |
| 251 |
if secid < 0 { |
| 252 |
return nil, false |
| 253 |
} |
| 254 |
off := int64(c.secSize) * (1 + int64(secid)) |
| 255 |
if off >= int64(len(c.data)) { |
| 256 |
return nil, false |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
end := min(off+int64(c.secSize), int64(len(c.data))) |
| 261 |
|
| 262 |
if end-off < 4 { |
| 263 |
return nil, false |
| 264 |
} |
| 265 |
return c.data[off:end], true |
| 266 |
} |
| 267 |
|
| 268 |
func (c *cdf) sectorIDs(secid int32) (int32s, bool) { |
| 269 |
buf, ok := c.sector(secid) |
| 270 |
if !ok { |
| 271 |
return int32s{}, ok |
| 272 |
} |
| 273 |
return int32s{b: buf}, true |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
func (c *cdf) buildSAT(masterSAT int32s, firstMSAT int32, nMSAT uint32) { |
| 282 |
|
| 283 |
|
| 284 |
if firstMSAT < 0 || nMSAT == 0 { |
| 285 |
c.satSecs = masterSAT |
| 286 |
c.satEntries = c.computeSATLen() |
| 287 |
return |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
maxIDs := len(c.data)/c.secSize + 1 |
| 294 |
buf := make([]byte, 0, 4*masterSATSize) |
| 295 |
for i := 0; i < masterSAT.len(); i++ { |
| 296 |
if masterSAT.at(i) < 0 { |
| 297 |
break |
| 298 |
} |
| 299 |
buf = append(buf, masterSAT.b[4*i:4*i+4]...) |
| 300 |
} |
| 301 |
perSec := c.secSize/4 - 1 |
| 302 |
mid := firstMSAT |
| 303 |
chain: |
| 304 |
for j := uint32(0); j < nMSAT && mid >= 0; j++ { |
| 305 |
msa, ok := c.sectorIDs(mid) |
| 306 |
if !ok { |
| 307 |
break |
| 308 |
} |
| 309 |
for k := 0; k < perSec; k++ { |
| 310 |
if k >= msa.len() || msa.at(k) < 0 { |
| 311 |
break chain |
| 312 |
} |
| 313 |
buf = append(buf, msa.b[4*k:4*k+4]...) |
| 314 |
if len(buf)/4 > maxIDs { |
| 315 |
break chain |
| 316 |
} |
| 317 |
} |
| 318 |
if perSec >= msa.len() { |
| 319 |
break |
| 320 |
} |
| 321 |
mid = msa.at(perSec) |
| 322 |
} |
| 323 |
c.satSecs = int32s{b: buf} |
| 324 |
c.satEntries = c.computeSATLen() |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
func (c *cdf) computeSATLen() int { |
| 331 |
perSec := c.secSize / 4 |
| 332 |
total := 0 |
| 333 |
for i := 0; i < c.satSecs.len(); i++ { |
| 334 |
sec := c.satSecs.at(i) |
| 335 |
if sec < 0 { |
| 336 |
break |
| 337 |
} |
| 338 |
off := int64(c.secSize) * (1 + int64(sec)) |
| 339 |
if off >= int64(len(c.data)) { |
| 340 |
break |
| 341 |
} |
| 342 |
avail := int64(len(c.data)) - off |
| 343 |
if avail >= int64(c.secSize) { |
| 344 |
total += perSec |
| 345 |
continue |
| 346 |
} |
| 347 |
total += int(avail / 4) |
| 348 |
break |
| 349 |
} |
| 350 |
return total |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
func (c *cdf) readLong(sid int32, length uint32) []byte { |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
if sid >= 0 { |
| 362 |
maxSec := len(c.data)/c.secSize + 1 |
| 363 |
n, s := 0, sid |
| 364 |
contiguous := true |
| 365 |
for s >= 0 { |
| 366 |
if int(s) >= c.satLen() { |
| 367 |
break |
| 368 |
} |
| 369 |
n++ |
| 370 |
if n > maxSec { |
| 371 |
contiguous = false |
| 372 |
break |
| 373 |
} |
| 374 |
next := c.satAt(s) |
| 375 |
if next >= 0 && int64(next) != int64(s)+1 { |
| 376 |
contiguous = false |
| 377 |
break |
| 378 |
} |
| 379 |
s = next |
| 380 |
} |
| 381 |
if contiguous { |
| 382 |
off64 := int64(c.secSize) * (1 + int64(sid)) |
| 383 |
if off64 >= int64(len(c.data)) { |
| 384 |
return nil |
| 385 |
} |
| 386 |
end64 := min(off64+int64(n)*int64(c.secSize), int64(len(c.data))) |
| 387 |
out := c.data[off64:end64] |
| 388 |
if length > 0 && int64(length) < int64(len(out)) { |
| 389 |
out = out[:length] |
| 390 |
} |
| 391 |
return out |
| 392 |
} |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
maxBytes := len(c.data) |
| 400 |
out := make([]byte, 0, c.secSize) |
| 401 |
for sid >= 0 { |
| 402 |
if int(sid) >= c.satLen() { |
| 403 |
break |
| 404 |
} |
| 405 |
buf, ok := c.sector(sid) |
| 406 |
if !ok { |
| 407 |
break |
| 408 |
} |
| 409 |
out = append(out, buf...) |
| 410 |
if len(out) >= maxBytes { |
| 411 |
break |
| 412 |
} |
| 413 |
sid = c.satAt(sid) |
| 414 |
} |
| 415 |
if length > 0 && int64(length) < int64(len(out)) { |
| 416 |
out = out[:length] |
| 417 |
} |
| 418 |
return out |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
func (c *cdf) readShort(sid int32, length uint32) []byte { |
| 425 |
sst := c.shortStream() |
| 426 |
if sst == nil { |
| 427 |
return nil |
| 428 |
} |
| 429 |
|
| 430 |
out := make([]byte, 0, c.shortSecSize) |
| 431 |
for sid >= 0 { |
| 432 |
off64 := int64(sid) * int64(c.shortSecSize) |
| 433 |
if off64+int64(c.shortSecSize) > int64(len(sst)) { |
| 434 |
break |
| 435 |
} |
| 436 |
off := int(off64) |
| 437 |
out = append(out, sst[off:off+c.shortSecSize]...) |
| 438 |
if len(out) >= len(sst) { |
| 439 |
break |
| 440 |
} |
| 441 |
sid = c.ssatAt(sid) |
| 442 |
} |
| 443 |
if length > 0 && int64(length) < int64(len(out)) { |
| 444 |
out = out[:length] |
| 445 |
} |
| 446 |
return out |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
func (c *cdf) readChain(sid int32, length uint32) []byte { |
| 451 |
if length < c.minStdStream && c.rootStreamFirst >= 0 { |
| 452 |
return c.readShort(sid, length) |
| 453 |
} |
| 454 |
return c.readLong(sid, length) |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
func (c *cdf) dirLen() int { return len(c.dirRaw) / dirEntrySize } |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
func (c *cdf) dirAt(i int, out *dirEntry) { |
| 464 |
raw := c.dirRaw[i*dirEntrySize:] |
| 465 |
nameLen := min(int(binary.LittleEndian.Uint16(raw[64:])), 64) |
| 466 |
k := uint8(0) |
| 467 |
for j := 0; j < nameLen/2; j++ { |
| 468 |
|
| 469 |
|
| 470 |
lo, hi := raw[2*j], raw[2*j+1] |
| 471 |
if lo == 0 && hi == 0 { |
| 472 |
break |
| 473 |
} |
| 474 |
out.name[k] = lo |
| 475 |
k++ |
| 476 |
} |
| 477 |
out.nameLen = k |
| 478 |
out.typ = raw[66] |
| 479 |
out.streamFirst = readSecID(raw[116:120]) |
| 480 |
out.size = binary.LittleEndian.Uint32(raw[120:]) |
| 481 |
copy(out.storageUUID[:], raw[80:96]) |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
func (c *cdf) userStream(name string) ([]byte, bool) { |
| 486 |
var d dirEntry |
| 487 |
for i, n := 0, c.dirLen(); i < n; i++ { |
| 488 |
c.dirAt(i, &d) |
| 489 |
if d.typ == dirTypeUserStream && string(d.nameBytes()) == name { |
| 490 |
buf := c.readChain(d.streamFirst, d.size) |
| 491 |
if buf == nil { |
| 492 |
return nil, false |
| 493 |
} |
| 494 |
return buf, true |
| 495 |
} |
| 496 |
} |
| 497 |
return nil, false |
| 498 |
} |
| 499 |
|
| 500 |
const ( |
| 501 |
propIDNameOfApplication = 0x12 |
| 502 |
|
| 503 |
typeMask = 0x0fff |
| 504 |
typeVector = 0x1000 |
| 505 |
typeStringASCII = 0x1e |
| 506 |
typeStringWide = 0x1f |
| 507 |
|
| 508 |
sectionDeclOffset = 0x1c |
| 509 |
) |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
func summaryAppName(stream []byte) []byte { |
| 516 |
if len(stream) < sectionDeclOffset+20 { |
| 517 |
return nil |
| 518 |
} |
| 519 |
sdOff := binary.LittleEndian.Uint32(stream[sectionDeclOffset+16:]) |
| 520 |
if uint64(sdOff)+8 > uint64(len(stream)) { |
| 521 |
return nil |
| 522 |
} |
| 523 |
section := stream[sdOff:] |
| 524 |
shLen := binary.LittleEndian.Uint32(section[0:]) |
| 525 |
nProps := binary.LittleEndian.Uint32(section[4:]) |
| 526 |
if uint64(shLen) > uint64(len(section)) || nProps > 1<<16 || 8+8*nProps > shLen { |
| 527 |
return nil |
| 528 |
} |
| 529 |
for i := uint32(0); i < nProps; i++ { |
| 530 |
base := 8 + 8*i |
| 531 |
id := binary.LittleEndian.Uint32(section[base:]) |
| 532 |
if id != propIDNameOfApplication { |
| 533 |
continue |
| 534 |
} |
| 535 |
off := binary.LittleEndian.Uint32(section[base+4:]) |
| 536 |
if uint64(off)+8 > uint64(shLen) { |
| 537 |
return nil |
| 538 |
} |
| 539 |
typ := binary.LittleEndian.Uint32(section[off:]) |
| 540 |
if typ&typeVector != 0 { |
| 541 |
return nil |
| 542 |
} |
| 543 |
step := uint32(0) |
| 544 |
switch typ & typeMask { |
| 545 |
case typeStringASCII: |
| 546 |
step = 1 |
| 547 |
case typeStringWide: |
| 548 |
step = 2 |
| 549 |
default: |
| 550 |
return nil |
| 551 |
} |
| 552 |
slen := binary.LittleEndian.Uint32(section[off+4:]) |
| 553 |
start := uint64(off) + 8 |
| 554 |
end := start + uint64(slen)*uint64(step) |
| 555 |
if end > uint64(shLen) { |
| 556 |
return nil |
| 557 |
} |
| 558 |
return printableLowBytes(section[start:end], int(step)) |
| 559 |
} |
| 560 |
return nil |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
func printableLowBytes(b []byte, step int) []byte { |
| 566 |
out := make([]byte, 0, len(b)/step) |
| 567 |
for i := 0; i+step <= len(b); i += step { |
| 568 |
c := b[i] |
| 569 |
if c == 0 { |
| 570 |
break |
| 571 |
} |
| 572 |
if c >= 0x20 && c < 0x7f { |
| 573 |
out = append(out, c) |
| 574 |
} |
| 575 |
} |
| 576 |
return out |
| 577 |
} |
| 578 |
|
| 579 |
re |
| 580 |
|
| 581 |
|
| 582 |
type pattern struct { |
| 583 |
needle []byte |
| 584 |
typ CDFType |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
var app2type = []pattern{ |
| 591 |
{[]byte("WORD"), CDFTypeDoc}, |
| 592 |
{[]byte("EXCEL"), CDFTypeXls}, |
| 593 |
{[]byte("POWERPOINT"), CDFTypePpt}, |
| 594 |
{[]byte("ADVANCED INSTALLER"), CDFTypeInstaller}, |
| 595 |
{[]byte("INSTALLSHIELD"), CDFTypeInstaller}, |
| 596 |
{[]byte("MICROSOFT PATCH COMPILER"), CDFTypeInstaller}, |
| 597 |
{[]byte("NANT"), CDFTypeInstaller}, |
| 598 |
{[]byte("WINDOWS INSTALLER"), CDFTypeInstaller}, |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
var name2type = []pattern{ |
| 605 |
{[]byte("BOOK"), CDFTypeXls}, |
| 606 |
{[]byte("WORKBOOK"), CDFTypeXls}, |
| 607 |
{[]byte("WORDDOCUMENT"), CDFTypeDoc}, |
| 608 |
{[]byte("POWERPOINT"), CDFTypePpt}, |
| 609 |
{[]byte("DIGITALSIGNATURE"), CDFTypeInstaller}, |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
func lookupSubstring(v []byte, t []pattern) (CDFType, bool) { |
| 617 |
s := scan.Bytes(v) |
| 618 |
for _, p := range t { |
| 619 |
if i, _ := s.Search(p.needle, scan.IgnoreCase); i != -1 { |
| 620 |
return p.typ, true |
| 621 |
} |
| 622 |
} |
| 623 |
return CDFTypeGeneric, false |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
var msiCLSID = []byte{ |
| 629 |
0x84, 0x10, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 630 |
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, |
| 631 |
} |
| 632 |
|
| 633 |
g. |
| 634 |
type section struct { |
| 635 |
name string |
| 636 |
typ uint8 |
| 637 |
cdf CDFType |
| 638 |
} |
| 639 |
|
| 640 |
ed |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
var sectionTypes = []section{ |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
{"Book", dirTypeUserStream, CDFTypeXls}, |
| 650 |
{"Workbook", dirTypeUserStream, CDFTypeXls}, |
| 651 |
{"WordDocument", dirTypeUserStream, CDFTypeDoc}, |
| 652 |
{"PowerPoint Document", dirTypeUserStream, CDFTypePpt}, |
| 653 |
{"__properties_version1.0", dirTypeUserStream, CDFTypeMsg}, |
| 654 |
{"__recip_version1.0_#00000000", dirTypeUserStorage, CDFTypeMsg}, |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
func lookupSection(name []byte, typ uint8) (CDFType, bool) { |
| 661 |
for _, s := range sectionTypes { |
| 662 |
if s.typ == typ && string(name) == s.name { |
| 663 |
return s.cdf, true |
| 664 |
} |
| 665 |
} |
| 666 |
return CDFTypeGeneric, false |
| 667 |
} |