struct.pack Format String Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joshua Forgione

    struct.pack Format String Question

    Hello. I am reverse engineering some Python Code. I am using the book
    "The Quick Python Book" as an aide.

    The following line exists in the code:

    msg = struct.pack('BB BB',word0, word1, word2, word3, word4)

    In this struct.pack command, the format string is 'BBBB.' In the book,
    it gives the following examples for characters that are meaningful to
    struct:

    'h' - short integer
    'd' - double-precision floating point
    's' - string

    In this case, 'B' is used. What does 'B' represent? What other
    characters can be used? Does a list of this exist somewhere?

    Thank you for your help.

    Josh

  • Erik Max Francis

    #2
    Re: struct.pack Format String Question

    Joshua Forgione wrote:
    [color=blue]
    > In this case, 'B' is used. What does 'B' represent? What other
    > characters can be used? Does a list of this exist somewhere?[/color]



    --
    __ Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    / \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    \__/ But you're not going to be there tomorrow. And it's all about
    tomorrow. -- Montgomery Brogan

    Comment

    • Larry Bates

      #3
      Re: struct.pack Format String Question

      "B" is unsigned character (from Python Library Reference).

      I'm hoping you copied the line down wrong, because it won't
      work (there is probably another B).

      See output below:

      import struct
      word0=1
      word1=2
      word2=3
      word3=4
      word4=5
      msg = struct.pack('BB BB',word0, word1, word2, word3, word4)
      Traceback (most recent call last):
      File "<interacti ve input>", line 1, in ?
      error: too many arguments for pack format

      Larry Bates
      Syscon, Inc.

      -------------------------------------------------------

      "Joshua Forgione" <jforgion@vt.ed u> wrote in message
      news:4069E5C6.B C5274E6@vt.edu. ..[color=blue]
      > Hello. I am reverse engineering some Python Code. I am using the book
      > "The Quick Python Book" as an aide.
      >
      > The following line exists in the code:
      >
      > msg = struct.pack('BB BB',word0, word1, word2, word3, word4)
      >
      > In this struct.pack command, the format string is 'BBBB.' In the book,
      > it gives the following examples for characters that are meaningful to
      > struct:
      >
      > 'h' - short integer
      > 'd' - double-precision floating point
      > 's' - string
      >
      > In this case, 'B' is used. What does 'B' represent? What other
      > characters can be used? Does a list of this exist somewhere?
      >
      > Thank you for your help.
      >
      > Josh
      >[/color]


      Comment

      Working...