Commit 20ca1d2c8fae68b3f1a31b63e0b1e0810d9ec507
1 parent
f8664a4f
oleform: unify *datablock processing
Showing
1 changed file
with
30 additions
and
44 deletions
oletools/oleform.py
| ... | ... | @@ -24,6 +24,11 @@ class Mask(object): |
| 24 | 24 | def __getitem__(self, key): |
| 25 | 25 | return self._val[self._names.index(key)] |
| 26 | 26 | |
| 27 | + def consume(self, stream, props): | |
| 28 | + for (name, size) in props: | |
| 29 | + if self[name]: | |
| 30 | + stream.read(size) | |
| 31 | + | |
| 27 | 32 | class FormPropMask(Mask): |
| 28 | 33 | """FormPropMask: [MS-OFORMS] 2.2.10.2""" |
| 29 | 34 | _size = 28 |
| ... | ... | @@ -253,19 +258,14 @@ def consume_OleSiteConcreteControl(stream): |
| 253 | 258 | tag_len = consume_CountOfBytesWithCompressionFlag(stream) |
| 254 | 259 | if propmask.fID: |
| 255 | 260 | id = stream.unpack('<L', 4) |
| 256 | - for prop in ['fHelpContextID', 'fBitFlags', 'fObjectStreamSize']: | |
| 257 | - if propmask[prop]: | |
| 258 | - stream.read(4) | |
| 261 | + propmask.consume(stream, [('fHelpContextID', 4), ('fBitFlags', 4), ('fObjectStreamSize', 4)]) | |
| 259 | 262 | tabindex = ClsidCacheIndex = 0 |
| 260 | 263 | if propmask.fTabIndex: |
| 261 | 264 | tabindex = stream.unpack('<H', 2) |
| 262 | 265 | if propmask.fClsidCacheIndex: |
| 263 | 266 | ClsidCacheIndex = stream.unpack('<H', 2) |
| 264 | - if propmask.fGroupID: | |
| 265 | - stream.read(2) | |
| 266 | - for prop in ['fControlTipText', 'fRuntimeLicKey', 'fControlSource', 'fRowSource']: | |
| 267 | - if propmask[prop]: | |
| 268 | - stream.read(4) | |
| 267 | + propmask.consume(stream, [('fGroupID', 2), ('fControlTipText', 4), ('fRuntimeLicKey', 4), | |
| 268 | + ('fControlSource', 4), ('fRowSource', 4)]) | |
| 269 | 269 | # SiteExtraDataBlock: [MS-OFORMS] 2.2.10.12.4 |
| 270 | 270 | name = stream.read(name_len) |
| 271 | 271 | tag = stream.read(tag_len) |
| ... | ... | @@ -279,9 +279,7 @@ def consume_FormControl(stream): |
| 279 | 279 | with stream.will_jump_to(cbform): |
| 280 | 280 | propmask = FormPropMask(stream.unpack('<L', 4)) |
| 281 | 281 | # FormDataBlock: [MS-OFORMS] 2.2.10.3 |
| 282 | - for prop in ['fBackColor', 'fForeColor', 'fNextAvailableID']: | |
| 283 | - if propmask[prop]: | |
| 284 | - stream.read(4) | |
| 282 | + propmask.consume(stream, [('fBackColor', 4), ('fForeColor', 4), ('fNextAvailableID', 4)]) | |
| 285 | 283 | if propmask.fBooleanProperties: |
| 286 | 284 | BooleanProperties = stream.unpack('<L', 4) |
| 287 | 285 | FORM_FLAG_DONTSAVECLASSTABLE = (BooleanProperties & (1<<15)) >> 15 |
| ... | ... | @@ -317,37 +315,24 @@ def consume_MorphDataControl(stream): |
| 317 | 315 | propmask = MorphDataPropMask(stream.unpack('<Q', 8)) |
| 318 | 316 | # MorphDataDataBlock: [MS-OFORMS] 2.2.5.3 |
| 319 | 317 | with stream.padded_struct(): |
| 320 | - for prop in ['fVariousPropertyBits', 'fBackColor', 'fForeColor', 'fMaxLength']: | |
| 321 | - if propmask[prop]: | |
| 322 | - stream.read(4) | |
| 323 | - for prop in ['fBorderStyle', 'fScrollBars', 'fDisplayStyle', 'fMousePointer']: | |
| 324 | - if propmask[prop]: | |
| 325 | - stream.read(1) | |
| 326 | - if propmask['fPasswordChar']: | |
| 327 | - stream.read(2) | |
| 328 | - if propmask['fListWidth']: | |
| 329 | - stream.read(4) | |
| 330 | - for prop in ['fBoundColumn', 'fTextColumn', 'fColumnCount', 'fListRows']: | |
| 331 | - if propmask[prop]: | |
| 332 | - stream.read(2) | |
| 333 | - if propmask.fcColumnInfo: | |
| 334 | - stream.read(2) | |
| 335 | - for prop in ['fMatchEntry', 'fListStyle', 'fShowDropButtonWhen', | |
| 336 | - 'fDropButtonStyle', 'fMultiSelect']: | |
| 337 | - if propmask[prop]: | |
| 338 | - stream.read(1) | |
| 318 | + propmask.consume(stream, [('fVariousPropertyBits', 4), ('fBackColor', 4), | |
| 319 | + ('fForeColor', 4), ('fMaxLength', 4), | |
| 320 | + ('fBorderStyle', 1), ('fScrollBars', 1), | |
| 321 | + ('fDisplayStyle', 1), ('fMousePointer', 1), | |
| 322 | + ('fPasswordChar', 2), ('fListWidth', 4), | |
| 323 | + ('fBoundColumn', 2), ('fTextColumn', 2), | |
| 324 | + ('fColumnCount', 2), ('fListRows', 2), | |
| 325 | + ('fcColumnInfo', 2), ('fMatchEntry', 1), | |
| 326 | + ('fListStyle', 1), ('fShowDropButtonWhen', 1), | |
| 327 | + ('fDropButtonStyle', 1), ('fMultiSelect', 1)]) | |
| 339 | 328 | if propmask.fValue: |
| 340 | 329 | value_size = consume_CountOfBytesWithCompressionFlag(stream) |
| 341 | 330 | else: |
| 342 | 331 | value_size = 0 |
| 343 | - for prop in ['fCaption', 'fPicturePosition', 'fBorderColor', 'fSpecialEffect']: | |
| 344 | - if propmask[prop]: | |
| 345 | - stream.read(4) | |
| 346 | - for prop in ['fMouseIcon', 'fPicture', 'fAccelerator']: | |
| 347 | - if propmask[prop]: | |
| 348 | - stream.read(2) | |
| 349 | - if propmask['fGroupName']: | |
| 350 | - stream.read(4) | |
| 332 | + propmask.consume(stream, [('fCaption', 4), ('fPicturePosition', 4), | |
| 333 | + ('fBorderColor', 4), ('fSpecialEffect', 4), | |
| 334 | + ('fMouseIcon', 2), ('fPicture', 2), | |
| 335 | + ('fAccelerator', 2), ('fGroupName', 4)]) | |
| 351 | 336 | # MorphDataExtraDataBlock: [MS-OFORMS] 2.2.5.4 |
| 352 | 337 | stream.read(8) |
| 353 | 338 | value = stream.read(value_size) |
| ... | ... | @@ -404,12 +389,13 @@ def consume_TabStripControl(stream): |
| 404 | 389 | with stream.will_jump_to(cbTabStrip): |
| 405 | 390 | propmask = TabStripPropMask(stream.unpack('<L', 4)) |
| 406 | 391 | # TabStripDataBlock: [MS-OFORMS] 2.2.9.3 |
| 407 | - # All are 4B (or 4B + pad = 4B), except MousePointer, which is 1B + pad = 4b | |
| 408 | - for prop in ['fListIndex', 'fBackColor', 'fForeColor', 'fSize', 'fTabOrientation' | |
| 409 | - 'fTabStyle', 'fTabFixedWidth', 'fTabFixedHeight', 'fTipStrings', | |
| 410 | - 'fNames', 'fVariousPropertyBits', 'fTabsAllocated', 'fTags']: | |
| 411 | - if propmask[prop]: | |
| 412 | - stream.read(4) | |
| 392 | + propmask.consume(stream, [('fListIndex', 4), ('fBackColor', 4), | |
| 393 | + ('fForeColor', 4), ('fSize', 4), | |
| 394 | + ('fMousePointer', 1), ('fTabOrientation', 4), | |
| 395 | + ('fTabStyle', 4), ('fTabFixedWidth', 4), | |
| 396 | + ('fTabFixedHeight', 4), ('fTipStrings', 4), | |
| 397 | + ('fNames', 4), ('fVariousPropertyBits', 4), | |
| 398 | + ('fTabsAllocated', 4), ('fTags', 4)]) | |
| 413 | 399 | tabData = 0 |
| 414 | 400 | if propmask['fTabData']: |
| 415 | 401 | tabData = stream.unpack('<L', 4) | ... | ... |