我尝试使用python和dll从内存中投射一些数据。
但是有些“ unicode”使我疯狂地使用结构“广播”数据。
我尝试过decode('utf-8')
,但遇到过UnicodeDecodeError
我更改了一些结构类型,但没有任何改变。
如何解决此问题?
class NH0__OutBlock(Structure):
_fields_ = [
("hotime", c_char*6),
("hotime1", c_char*6),
("offerho1", c_char*6),
("bidho1", c_char*6),
("offerrem1", c_char*6),
("bidrem1", c_char*6),
("offercnt1", c_char*5),
("bidcnt1", c_char*5),
("offerho2", c_char*6),
("bidho2", c_char*6),
("offerrem2", c_char*6),
("bidrem2", c_char*6),
("offercnt2", c_char*5),
("bidcnt2", c_char*5),
("offerho3", c_char*6),
("bidho3", c_char*6),
("offerrem3", c_char*6),
("bidrem3", c_char*6),
("offercnt3", c_char*5),
("bidcnt3", c_char*5),
("offerho4", c_char*6),
("bidho4", c_char*6),
("offerrem4", c_char*6),
("bidrem4", c_char*6),
("offercnt4", c_char*5),
("bidcnt4", c_char*5),
("offerho5", c_char*6),
("bidho5", c_char*6),
("offerrem5", c_char*6),
("bidrem5", c_char*6),
("offercnt5", c_char*5),
("bidcnt5", c_char*5),
("totofferrem", c_char*6),
("totbidrem", c_char*6),
("totoffercnt", c_char*5),
("totbidcnt", c_char*5),
("futcode", c_char*8)
]
...
# RealMsgPacket.contents.pszData Type is ctypes.c_char_p
elif RealMsgPacket.contents.szTrCode.decode('euc-kr') == "NH0":
Casted = cast(RealMsgPacket.contents.pszData, POINTER(c_char*int(RealMsgPacket.contents.nDataLength)))
print(Casted.contents.value.strip())
...
b'035822 275822 028345\xb0028340\xb0000012 000019 00004 00016 028350\xb0028335\xb0000014 000025 00007 00022 028355\xb002
8330\xb0000007 000020 00004 00015 028360\xb0028325\xb0000007 000022 00005 00011 028365\xb0028320\xc0000010 000037 00010
00015 000050 000123 00030 00079 101PC000'