python中struct.unpack结构指针的解决方法
首先声明,我这个方法也只是“曲线救国”,好了,先介绍下我要unpack的结构:
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
st1\:*{behavior:url(#ieooui) }
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
typedef struct _st_DataInfo{
char ReportTime[20];
char
GUID[41];
char
UserName[33];
char UserIp[50];
int ItemNumber;
DATAITEM *data;
} DATAINFO;
Typedef struct _st_DataItem{
char
Infohash[41];
int TotalPeers;
int UploadPeers;
int DownloadPeers;
int StandbyPeers;
long long Upload;
long long Download;
int UploadSpeed;
int DownloadSpeed;
} DATAITEM;
里面的itemnumber是后面DATAITEM结构的个数,而最后的那个DATAITEM *data真是困扰我多时啊,查了半天,也没琢磨出结构指针用哪种format解析,python2.5手册解析格式如下:
Format
C Type
Python
Notes
x
pad byte
no value
c
char
string of length
1
b
signed char
integer
B
unsigned char
integer
h
short
integer
H
unsigned short
integer
i
int
integer
I
unsigned int
long
l
long
integer
L
unsigned long
long
q
long long
long
(1)
Q
unsigned long long
long
(1)
f
float
float
d
double
float
s
char[]
string
p
char[]
string
P
void *
integer
后来转头一想,算了,把指针长度大小的数据忽略掉吧,四个字节,self.buf = self.buf[:184]+self.buf[188:],后来就成功了
注:谁知道怎么unpack这种的,一定要告诉我啊,多谢了:)