473,237 Members | 1,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

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('BBBB',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

Jul 18 '05 #1
2 3612
Joshua Forgione wrote:
In this case, 'B' is used. What does 'B' represent? What other
characters can be used? Does a list of this exist somewhere?


http://www.python.org/doc/current/li...le-struct.html

--
__ Erik Max Francis && ma*@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
Jul 18 '05 #2
"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('BBBB',word0, word1, word2, word3, word4)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
error: too many arguments for pack format

Larry Bates
Syscon, Inc.

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

"Joshua Forgione" <jf******@vt.edu> wrote in message
news:40***************@vt.edu...
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('BBBB',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

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gordon Scott | last post by:
Hi All, I've got a problem I'm seeing when trying to use the struct module to send data to a different machine. Actually I'm making a condensed file that gets transferred to and read on a BREW...
0
by: Josiah Carlson | last post by:
Good day everyone, I have produced a patch against the latest CVS to add support for two new formatting characters in the struct module. It is currently an RFE, which I include a link to at the...
2
by: Sergey Dorofeev | last post by:
I can use string.unpack if string in struct uses fixed amount of bytes. But is there some extension to struct modue, which allows to unpack zero-terminated string, size of which is unknown? E.g....
16
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
3
by: Chandu | last post by:
In using the following struct format I get the size as 593. The same C struct is 590 if packed on byte boundary and 596 when using pragma pack(4). I am using pack(4) and added 3 spares at the end...
10
by: Giovanni Bajo | last post by:
Hello, given the ongoing work on struct (which I thought was a dead module), I was wondering if it would be possible to add an API to register custom parsing codes for struct. Whenever I use it...
3
by: David Bear | last post by:
I found this simple recipe for converting a dotted quad ip address to a string of a long int. struct.unpack('L',socket.inet_aton(ip)) trouble is when I use this, I get struct.error: unpack...
2
by: Tom Plunket | last post by:
I am building a file with the help of the struct module. I would like to be able to put Unicode strings into this file, but I'm not sure how to do it. The format I'm trying to write is...
2
by: Jansson Christer | last post by:
Hi all, I have discovered that in my Python 2.4.1 installation (on Solaris 8), struct.pack handles things in a way that seems inconsistent to me. I haven't found any comprehensible...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.