Ejemplo n.º 1
0
 def unpack64Bit(self, wantSigned=False):
     """
     Unpacks a single 64-bit value, signed or not as indicated.
     
     This method works with nonzero phases as well.
     
     >>> w = FileWalker(_tempPath, start=128)
     >>> w.unpack64Bit(wantSigned=False), w.unpack64Bit(wantSigned=True)
     (9259825810226120327, -8608196880778817905)
     >>> w.getOffset(), w.getPhase()
     (144, 0)
     >>> bitString = w.unpackBits(5)
     >>> w.getOffset(), w.getPhase()
     (144, 5)
     >>> w.unpack64Bit(wantSigned=False), w.unpack64Bit(wantSigned=True)
     (1311201093559177971, 1383541266397254644)
     >>> w.getOffset(), w.getPhase()
     (160, 5)
     
     >>> w = FileWalker(_tempPath, start=128, endian='<')
     >>> w.unpack64Bit(wantSigned=False), w.unpack64Bit(wantSigned=True)
     (9765639646188044672, -8102383044816893560)
     >>> bitString = w.unpackBits(5)
     >>> w.unpack64Bit(wantSigned=False), w.unpack64Bit(wantSigned=True)
     (17569301438378684946, -805102462492789997)
     """
     
     return filewalkerbackend.fwkUnpack(
       self.context,
       ('q' if wantSigned else 'Q'),
       True,
       True)
Ejemplo n.º 2
0
 def unpack32Bit(self, wantSigned=False):
     """
     Returns a 32-bit quantity, signed or not as specified. The global
     endian state is used.
     
     This method works with nonzero phases as well.
     
     >>> w = FileWalker(_tempPath, start=128)
     >>> print(w.unpack32Bit())
     2155971203
     >>> w.unpack32Bit(True)
     -2071624057
     
     >>> w = FileWalker(_tempPath, start=128, endian='<')
     >>> print(w.unpack32Bit())
     2206368128
     >>> w.unpack32Bit(True)
     -2021227132
     """
     
     return filewalkerbackend.fwkUnpack(
       self.context,
       ('l' if wantSigned else 'L'),
       True,
       True)
Ejemplo n.º 3
0
 def unpack24Bit(self, wantSigned=False):
     """
     Unpacks a single 24-bit value, signed or not as indicated.
     
     This method works with nonzero phases as well.
     
     >>> w = FileWalker(_tempPath, start=128)
     >>> w.unpack24Bit(wantSigned=False), w.unpack24Bit(wantSigned=True)
     (8421762, -8158075)
     >>> w.getOffset(), w.getPhase()
     (134, 0)
     >>> bitString = w.unpackBits(5)
     >>> w.getOffset(), w.getPhase()
     (134, 5)
     >>> w.unpack24Bit(wantSigned=False), w.unpack24Bit(wantSigned=True)
     (13693201, 3232113)
     >>> w.getOffset(), w.getPhase()
     (140, 5)
     
     >>> w = FileWalker(_tempPath, start=128, endian='<')
     >>> w.unpack24Bit(wantSigned=False), w.unpack24Bit(wantSigned=True)
     (8552832, -8027005)
     >>> bitString = w.unpackBits(5)
     >>> w.unpack24Bit(wantSigned=False), w.unpack24Bit(wantSigned=True)
     (1176016, 7426353)
     """
     
     # Note we use our custom format code here, 'T' or 't'.
     
     return filewalkerbackend.fwkUnpack(
       self.context,
       ('t' if wantSigned else 'T'),
       True,
       True)
Ejemplo n.º 4
0
 def unpack16Bit(self, wantSigned=False):
     """
     Returns a 16-bit quantity, signed or not as specified. The global
     endian state is used.
     
     This method works with nonzero phases as well.
     
     >>> w = FileWalker(_tempPath, start=127)
     >>> w.unpack16Bit()
     32640
     >>> w.unpack16Bit(True)
     -32382
     
     >>> w = FileWalker(_tempPath, start=127, endian='<')
     >>> w.unpack16Bit()
     32895
     >>> w.unpack16Bit(True)
     -32127
     """
     
     return filewalkerbackend.fwkUnpack(
       self.context,
       ('h' if wantSigned else 'H'),
       True,
       True)
Ejemplo n.º 5
0
 def unpack8Bit(self, wantSigned=False):
     """
     Returns an 8-bit quantity, signed or not as specified.
     
     This method works with nonzero phases as well.
     
     >>> w = FileWalker(_tempPath, start=127)
     >>> print(w.unpack8Bit())
     127
     >>> print(w.unpack8Bit())
     128
     >>> print(w.unpack8Bit(True))
     -127
     
     >>> w = FileWalker(_tempPath, start=127)
     >>> bitString = w.unpackBits(5)
     >>> print(w.unpack8Bit(True))
     -16
     >>> print(w.unpack8Bit())
     16
     >>> print(w.unpack8Bit())
     48
     """
     
     return filewalkerbackend.fwkUnpack(
       self.context,
       ('b' if wantSigned else 'B'),
       True,
       True)
Ejemplo n.º 6
0
    def unpack(self, format, coerce=True, advance=True):
        """
        Unpacks one or more values from the filewalker and returns them in a
        tuple. If only a single value is being unpacked and coerce is True (the
        default) then the value itself will be returned, instead of a
        one-element tuple.

        If advance is False, the walker is not moved after the items are read,
        so a subsequent unpack() call will re-process the same location.
        
        >>> w = FileWalker(_tempPath, start=128)  # bytes with high bit set
        >>> w.unpack("BbHhLlTt")
        (128, -127, 33411, -31611, 2257029257, -1970566003, 9342864, -7236973)
        >>> w.unpack(">fd")
        (-1.5104552404603995e-26, -3.5916126958448044e-190)
        >>> w.unpack("<fd")
        (-1.763252604431516e-17, -2.4380131109097072e-98)
        """
        
        return filewalkerbackend.fwkUnpack(
          self.context,
          format,
          coerce,
          advance)