How to use the template.office.storage.DWORD function in template

To help you get started, we’ve selected a few template examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arizvisa / syringe / template / office / storage.py View on Github external
@Sector.define
class REGSECT(Sector.Pointer): symbol, type = '+', None
Sector.default = REGSECT
@Sector.define
class MAXREGSECT(REGSECT): symbol, type = '+', 0xfffffffa
@Sector.define
class NotApplicable(DWORD): symbol, type = '-', 0xfffffffb
@Sector.define
class DIFSECT(DWORD): symbol, type = 'D', 0xfffffffc
@Sector.define
class FATSECT(DWORD): symbol, type = 'F', 0xfffffffd
@Sector.define
class ENDOFCHAIN(DWORD): symbol, type = '$', 0xfffffffe
@Sector.define
class FREESECT(DWORD): symbol, type = '.', 0xffffffff

class SECT(Sector.Pointer): pass

### File-allocation tables that populate a single sector
class AllocationTable(parray.type):
    def summary(self, **options):
        return str().join(Sector.withdefault(entry.int(), type=entry.int()).symbol for entry in self)
    def _object_(self):
        return dyn.clone(Sector.Pointer, _object_=self.Pointer)

class FAT(AllocationTable):
    Pointer = lambda s: dyn.block(s._uSectorSize)

    # Walk the linked-list of fat sectors
    def chain(self, index):
        yield index
github arizvisa / syringe / template / office / storage.py View on Github external
(__cond('DM_PAPERLENGTH', WORD), 'dmPaperLength'),
                (__cond('DM_PAPERWIDTH', WORD), 'dmPaperWidth'),
                (__cond('DM_SCALE', WORD), 'dmScale'),
                (__cond('DM_COPIES', WORD), 'dmCopies'),
                (__cond('DM_DEFAULTSOURCE', WORD), 'dmDefaultSource'),
                (__cond('DM_PRINTQUALITY', WORD), 'dmPrintQuality'),
                (__cond('DM_COLOR', WORD), 'dmColor'),
                (__cond('DM_DUPLEX', WORD), 'dmDuplex'),
                (__cond('DM_YRESOLUTION', WORD), 'dmYResolution'),
                (__cond('DM_TTOPTION', WORD), 'dmTTOptions'),
                (__cond('DM_COLLATE', WORD), 'dmCollate'),
                (WORD, 'reserved0'),
                (DWORD, 'reserved1'),
                (DWORD, 'reserved2'),
                (DWORD, 'reserved3'),
                (__cond('DM_NUP', DWORD), 'dmNup'),
                (DWORD, 'reserved4'),
                (__cond('DM_ICMMETHOD', DWORD), 'dmICMMethod'),
                (__cond('DM_ICMINTENT', DWORD), 'dmICMIntent'),
                (__cond('DM_MEDIATYPE', DWORD), 'dmMediaType'),
                (__cond('DM_DITHERTYPE', DWORD), 'dmDitherType'),
                (DWORD, 'reserved5'),
                (DWORD, 'reserved6'),
                (DWORD, 'reserved7'),
                (DWORD, 'reserved8'),
            ]

        def __Padding(self):
            sz = self['dmSize'].li.int()
            total = 32+32+2+2+2+2
            res = sz - (total+s['fields'].li.size())
            return dyn.block(res)
github arizvisa / syringe / template / office / storage.py View on Github external
class LengthPrefixedUnicodeString(pstruct.type):
    _fields_ = [
        (DWORD, 'Length'),
        (lambda s: dyn.clone(pstr.wstring, length=s['Length'].li.int()), 'String')
    ]
    def summary(self):
        res = self['String'].str()
        return "(length={:d}) {!r}".format(self['Length'].int(), res)

### Sector types
class Sector(ptype.definition):
    cache = {}
    class Pointer(ptype.opointer_t):
        def _calculate_(self, index):
            return self._uSectorSize + index * self._uSectorSize
        class _value_(pint.enum, DWORD):
            _values_ = [
                ('MAXREGSECT', 0xfffffffa),
                ('NotApplicable', 0xfffffffb),
                ('DIFSECT', 0xfffffffc),
                ('FATSECT', 0xfffffffd),
                ('ENDOFCHAIN', 0xfffffffe),
                ('FREESECT', 0xffffffff),
            ]
        def _object_(self):
            return dyn.block(self._uSectorSize)
        def summary(self, **options):
            return self.object.summary(**options)

@Sector.define
class REGSECT(Sector.Pointer): symbol, type = '+', None
Sector.default = REGSECT
github arizvisa / syringe / template / office / storage.py View on Github external
('FREESECT', 0xffffffff),
            ]
        def _object_(self):
            return dyn.block(self._uSectorSize)
        def summary(self, **options):
            return self.object.summary(**options)

@Sector.define
class REGSECT(Sector.Pointer): symbol, type = '+', None
Sector.default = REGSECT
@Sector.define
class MAXREGSECT(REGSECT): symbol, type = '+', 0xfffffffa
@Sector.define
class NotApplicable(DWORD): symbol, type = '-', 0xfffffffb
@Sector.define
class DIFSECT(DWORD): symbol, type = 'D', 0xfffffffc
@Sector.define
class FATSECT(DWORD): symbol, type = 'F', 0xfffffffd
@Sector.define
class ENDOFCHAIN(DWORD): symbol, type = '$', 0xfffffffe
@Sector.define
class FREESECT(DWORD): symbol, type = '.', 0xffffffff

class SECT(Sector.Pointer): pass

### File-allocation tables that populate a single sector
class AllocationTable(parray.type):
    def summary(self, **options):
        return str().join(Sector.withdefault(entry.int(), type=entry.int()).symbol for entry in self)
    def _object_(self):
        return dyn.clone(Sector.Pointer, _object_=self.Pointer)
github arizvisa / syringe / template / office / storage.py View on Github external
(DWORD, 'csectDifat'),                          # Number of difat sectors
    ]

### Directory types
class DirectoryEntryData(ptype.block):
    def properties(self):
        parent, res = self.parent, super(DirectoryEntryData, self).properties()
        if isinstance(parent, DirectoryEntry):
            res['index'] = int(parent.__name__)
            res['type'] = parent['Type'].str()
        return res
class DirectoryEntryType(pint.enum, BYTE):
    _values_=[('Unknown', 0), ('Storage', 1), ('Stream', 2), ('Root', 5)]
class DirectoryEntryFlag(pint.enum, BYTE):
    _values_=[('red', 0), ('black', 1)]
class DirectoryEntryIdentifier(pint.enum, DWORD):
    _values_=[('MAXREGSID', 0xfffffffa), ('NOSTREAM', 0xffffffff)]

class DirectoryEntry(pstruct.type):
    _fields_ = [
        (dyn.clone(pstr.wstring, length=32), 'Name'),
        (USHORT, 'uName'),
        (DirectoryEntryType, 'Type'),
        (DirectoryEntryFlag, 'Flag'),
        (DirectoryEntryIdentifier, 'iLeftSibling'),
        (DirectoryEntryIdentifier, 'iRightSibling'),
        (DirectoryEntryIdentifier, 'iChild'),
        (CLSID, 'clsid'),
        (DWORD, 'dwState'),
        (FILETIME, 'ftCreation'),
        (FILETIME, 'ftModified'),
        (SECT, 'sectLocation'),     # FIXME: This pointer only supports regular sectors and not mini-sectors
github arizvisa / syringe / template / office / storage.py View on Github external
def _object_(self):
            return dyn.block(self._uSectorSize)
        def summary(self, **options):
            return self.object.summary(**options)

@Sector.define
class REGSECT(Sector.Pointer): symbol, type = '+', None
Sector.default = REGSECT
@Sector.define
class MAXREGSECT(REGSECT): symbol, type = '+', 0xfffffffa
@Sector.define
class NotApplicable(DWORD): symbol, type = '-', 0xfffffffb
@Sector.define
class DIFSECT(DWORD): symbol, type = 'D', 0xfffffffc
@Sector.define
class FATSECT(DWORD): symbol, type = 'F', 0xfffffffd
@Sector.define
class ENDOFCHAIN(DWORD): symbol, type = '$', 0xfffffffe
@Sector.define
class FREESECT(DWORD): symbol, type = '.', 0xffffffff

class SECT(Sector.Pointer): pass

### File-allocation tables that populate a single sector
class AllocationTable(parray.type):
    def summary(self, **options):
        return str().join(Sector.withdefault(entry.int(), type=entry.int()).symbol for entry in self)
    def _object_(self):
        return dyn.clone(Sector.Pointer, _object_=self.Pointer)

class FAT(AllocationTable):
    Pointer = lambda s: dyn.block(s._uSectorSize)
github arizvisa / syringe / template / office / storage.py View on Github external
('FATSECT', 0xfffffffd),
                ('ENDOFCHAIN', 0xfffffffe),
                ('FREESECT', 0xffffffff),
            ]
        def _object_(self):
            return dyn.block(self._uSectorSize)
        def summary(self, **options):
            return self.object.summary(**options)

@Sector.define
class REGSECT(Sector.Pointer): symbol, type = '+', None
Sector.default = REGSECT
@Sector.define
class MAXREGSECT(REGSECT): symbol, type = '+', 0xfffffffa
@Sector.define
class NotApplicable(DWORD): symbol, type = '-', 0xfffffffb
@Sector.define
class DIFSECT(DWORD): symbol, type = 'D', 0xfffffffc
@Sector.define
class FATSECT(DWORD): symbol, type = 'F', 0xfffffffd
@Sector.define
class ENDOFCHAIN(DWORD): symbol, type = '$', 0xfffffffe
@Sector.define
class FREESECT(DWORD): symbol, type = '.', 0xffffffff

class SECT(Sector.Pointer): pass

### File-allocation tables that populate a single sector
class AllocationTable(parray.type):
    def summary(self, **options):
        return str().join(Sector.withdefault(entry.int(), type=entry.int()).symbol for entry in self)
    def _object_(self):
github arizvisa / syringe / template / office / storage.py View on Github external
def summary(self, **options):
            return self.object.summary(**options)

@Sector.define
class REGSECT(Sector.Pointer): symbol, type = '+', None
Sector.default = REGSECT
@Sector.define
class MAXREGSECT(REGSECT): symbol, type = '+', 0xfffffffa
@Sector.define
class NotApplicable(DWORD): symbol, type = '-', 0xfffffffb
@Sector.define
class DIFSECT(DWORD): symbol, type = 'D', 0xfffffffc
@Sector.define
class FATSECT(DWORD): symbol, type = 'F', 0xfffffffd
@Sector.define
class ENDOFCHAIN(DWORD): symbol, type = '$', 0xfffffffe
@Sector.define
class FREESECT(DWORD): symbol, type = '.', 0xffffffff

class SECT(Sector.Pointer): pass

### File-allocation tables that populate a single sector
class AllocationTable(parray.type):
    def summary(self, **options):
        return str().join(Sector.withdefault(entry.int(), type=entry.int()).symbol for entry in self)
    def _object_(self):
        return dyn.clone(Sector.Pointer, _object_=self.Pointer)

class FAT(AllocationTable):
    Pointer = lambda s: dyn.block(s._uSectorSize)

    # Walk the linked-list of fat sectors
github arizvisa / syringe / template / office / storage.py View on Github external
def __FormatOrUnicodeString(self):
        marker = self['MarkerOrLength'].li.int()
        if marker in (0x00000000, ):
            return ptype.undefined
        elif marker in (0xfffffffe, 0xffffffff):
            return DWORD
        return dyn.clone(pstr.wstring, length=marker)
github arizvisa / syringe / template / office / storage.py View on Github external
(__FormatOrUnicodeString, 'FormatOrUnicodeString'),
    ]

class MONIKERSTREAM(pstruct.type):
    class Stream(pstruct.type):
        _fields_ = [
            (CLSID, 'Clsid'),
            (lambda s: dyn.block(s.blocksize() - s['Clsid'].li.size()), 'Data'),
        ]
    _fields_ = [
        (DWORD, 'Size'),
        (lambda s: ptype.undefined if s['Size'].li.int() == 0 else dyn.clone(MONIKERSTREAM.Stream, blocksize=lambda _:s['Size'].li.int()), 'Stream'),
    ]

class OLEStream(pstruct.type):
    class StreamFlags(pint.enum, DWORD):
        _values_ = [
            ('Embedded', 0x00000000),
            ('Linked', 0x00000001),
            ('Implementation-Specific', 0x00001000),
        ]

    _fields_ = [
        (DWORD, 'Version'),
        (StreamFlags, 'Flags'),
        (DWORD, 'LinkUpdateOption'),
        (DWORD, 'Reserved1'),
        (MONIKERSTREAM, 'ReservedMoniker'),
        (MONIKERSTREAM, 'RelativeSourceMoniker'),
        (MONIKERSTREAM, 'AbsoluteSourceMoniker'),
        (LONG, 'ClsidIndicator'),
        (CLSID, 'Clsid'),