本文整理汇总了Python中utils.hexdump函数的典型用法代码示例。如果您正苦于以下问题:Python hexdump函数的具体用法?Python hexdump怎么用?Python hexdump使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hexdump函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cmd_fancy
def cmd_fancy(self, *args):
"Parse a fancy APDU and print the result"
apdu = utils.C_APDU.parse_fancy(*args)
data = apdu.render()
if hasattr(self, "card"):
self.card.last_result = utils.R_APDU(data+"\x00\x00")
print utils.hexdump(data)
示例2: parse_file
def parse_file(fname):
fp = file(fname)
in_block = False
is_rfid = False
line_no = 0
direction = 0
data = []
last_was_transfer_buffer = False
for line in fp.readlines():
if not in_block:
if last_was_transfer_buffer:
parts = line.split(":")
if parts[0] == " 00000000":
if parts[1][:3] == " 6f":
in_block = True
direction = 0
line_no = 0
is_rfid = False
data = []
elif parts[1][:3] == " 80":
in_block = True
direction = 1
line_no = 0
is_rfid = False
data = []
elif parts[1][:3] == " 6b":
in_block = True
direction = 0
line_no = 0
is_rfid = True
data = []
elif parts[1][:3] == " 83":
in_block = True
direction = 1
line_no = 0
is_rfid = True
data = []
if in_block and (not is_rfid or line_no > 0):
data = [ parts[1][31:] ]
else:
if not ":" in line:
in_block = False
data_binary = binascii.a2b_hex("".join("".join(data).split()))
if not is_rfid:
print (direction and "<< " or ">> ") + utils.hexdump(data_binary, indent=3)
if direction == 1: print
elif len("".join(data).strip()) > (direction == 0 and 8 or 2) and data_binary not in ("\x00"*5, "\x70\x08\x35\x2d\x66\x76", "\x43\x4f\x53\x73\x01\x02\x01"):
print (direction and "лл " or "╗╗ ") + utils.hexdump(data_binary, indent=3)
if direction == 1: print
else:
line_no = line_no + 1
if (not is_rfid or line_no > 1):
data.append( line.split(":")[1] )
elif is_rfid and line_no == 1:
data.append( line.split(":")[1][6:] )
last_was_transfer_buffer = "TransferBufferMDL" in line
示例3: handle_read
def handle_read(self):
read = self.recv(4096)
if debug == 1 or debug == 4 or debug == 5:
print (term.render(" ${BOLD}${CYAN}Sender: %i bytes read:${NORMAL}") % len(read))
if debug == 4 or debug >= 5:
print hexdump(read, indent=True)
self.receiver.to_remote_buffer += read
示例4: cmd_pn532
def cmd_pn532(self, *cmd):
"Transmit a command to the PN532 and receive the response"
result = self.pn532_transceive(binascii.unhexlify("".join("".join(cmd).split())))
print utils.hexdump(result.data)
parsed = self.pn532_parse(result.data)
if len(parsed) > 0:
print "\n".join(parsed) + "\n"
示例5: hexdump
def hexdump(self, lfilter=None):
"""Same as nsummary(), except that packets are also hexdumped
lfilter: a truth function that decides whether a packet must be displayed"""
for i in range(len(self.res)):
p = self._elt2pkt(self.res[i])
if lfilter is not None and not lfilter(p):
continue
print "%s %s %s" % (conf.color_theme.id(i, fmt="%04i"), p.sprintf("%.time%"), self._elt2sum(self.res[i]))
hexdump(p)
示例6: hexraw
def hexraw(self, lfilter=None):
"""Same as nsummary(), except that if a packet has a Raw layer, it will be hexdumped
lfilter: a truth function that decides whether a packet must be displayed"""
for i in range(len(self.res)):
p = self._elt2pkt(self.res[i])
if lfilter is not None and not lfilter(p):
continue
print "%s %s %s" % (conf.color_theme.id(i, fmt="%04i"), p.sprintf("%.time%"), self._elt2sum(self.res[i]))
if p.haslayer(conf.raw_layer):
hexdump(p.getlayer(conf.raw_layer).load)
示例7: padding
def padding(self, lfilter=None):
"""Same as hexraw(), for Padding layer"""
for i in range(len(self.res)):
p = self._elt2pkt(self.res[i])
if p.haslayer(Padding):
if lfilter is None or lfilter(p):
print "%s %s %s" % (conf.color_theme.id(i,fmt="%04i"),
p.sprintf("%.time%"),
self._elt2sum(self.res[i]))
hexdump(p.getlayer(Padding).load)
示例8: padding
def padding(self, lfilter=None):
"""Same as hexraw(), for Padding layer"""
for i in enumerate(self.res):
p = self._elt2pkt(res)
if p.haslayer(conf.padding_layer):
if lfilter is None or lfilter(p):
print "%s %s %s" % (conf.color_theme.id(i,fmt="%04i"),
p.sprintf("%.time%"),
self._elt2sum(res))
hexdump(p.getlayer(conf.padding_layer).load)
示例9: dump
def dump(data):
print "Dump following (%i bytes)" % (len(data))
print utils.hexdump(data)
try:
print "Trying TLV parse:"
print TLV_utils.decode(data, tags=card.TLV_OBJECTS, context = card.DEFAULT_CONTEXT)
print "TLV parsed successfully"
except (SystemExit, KeyboardInterrupt):
raise
except:
print "TLV error"
pass
示例10: nzpadding
def nzpadding(self, lfilter=None):
"""Same as padding() but only non null padding"""
for i in range(len(self.res)):
p = self._elt2pkt(self.res[i])
if p.haslayer(Padding):
pad = p.getlayer(Padding).load
if pad == pad[0]*len(pad):
continue
if lfilter is None or lfilter(p):
print "%s %s %s" % (conf.color_theme.id(i,fmt="%04i"),
p.sprintf("%.time%"),
self._elt2sum(self.res[i]))
hexdump(p.getlayer(Padding).load)
示例11: cmd_enc
def cmd_enc(self, *args):
"Encrypt or decrypt with openssl-like interface"
args = list(args)
MODE_DECRYPT = "-d"
MODE_ENCRYPT = "-e"
mode = MODE_ENCRYPT
if "-d" in args:
mode = MODE_DECRYPT
input = None
if "-in" in args:
i = args.index("-in")
input = args[i+1]
if "-K" not in args:
raise ValueError, "Must specify key with -K"
i = args.index("-K")
key = args[i+1]
key = binascii.a2b_hex("".join(key.split()))
iv = None
if "-iv" in args:
i = args.index("-iv")
iv = args[i+1]
iv = binascii.a2b_hex("".join(iv.split()))
cipher = "des"
if args[0][0] != "-":
cipher = args[0]
text = None
if "-text" in args:
if input is not None:
raise ValueError, "Can't give -in and -text"
i = args.index("-text")
text = binascii.a2b_hex("".join(args[i+1].split()))
if text is None:
if input is None:
text = self.card.last_result.data
else:
fp = file(input)
text = fp.read()
fp.close()
result = crypto_utils.cipher(mode == MODE_ENCRYPT, cipher, key, text, iv)
self.card.last_result = utils.R_APDU(result+"\x00\x00")
print utils.hexdump(result)
示例12: _real_send
def _real_send(self, apdu):
apdu_binary = apdu.render()
if DEBUG:
print ">> " + utils.hexdump(apdu_binary, indent = 3)
result_binary = self.reader.transceive(apdu_binary)
result = apdu.RESPONSE_CLASS(result_binary)
self.last_apdu = apdu
if DEBUG:
print "<< " + utils.hexdump(result_binary, indent = 3)
return result
示例13: generate_package
def generate_package(bid=0, bulkstate=1, dbg=False):
# Generate bulk_info array
bulk_info_array = ""
for i in range(0, 2):
bulk_info = init_bulk_info(i, bulkstate)
bulk_info_array += buffer(bulk_info)[:]
# Generate botbulk_info
botbulk_info = init_botbulk_info(1, i+1)
# Generate bot_rheader
size = 20 + 8 * botbulk_info.logsize
bot_rheader = init_bot_rheader(bid, size)
# Construct data package
data = buffer(bot_rheader)[:] \
+ pencrypt(buffer(botbulk_info)[:] + bulk_info_array, bot_rheader.size)
# Print package content
if dbg:
cprint("BOT_RHEADER\n", "yellow"); print hexdump(buffer(bot_rheader)[:])
cprint("BOTBULK_INFO\n", "yellow"); print hexdump(buffer(botbulk_info)[:])
cprint("BULK_INFO\n", "yellow"); print hexdump(buffer(bulk_info_array)[:])
cprint("Data Package\n", "yellow"); print hexdump(data)
return data
示例14: encrypt_command
def encrypt_command(self, tlv_data):
config = self.get_config(SE_APDU, TEMPLATE_CT)
if config.algorithm is None: ## FIXME: Find out the correct way to determine this
return tlv_data
result = []
for data in tlv_data:
tag, length, value, marks = data
if self.MARK_ENCRYPT in marks and tag not in (0xff, 0x00):
t = tag & ~(0x01)
if t == 0x84:
value_ = self.pad(value)
if generic_card.DEBUG:
print "| Tag 0x%02x, length 0x%02x, encrypting (with ISO padding): " % (tag, length)
print "|| " + "\n|| ".join( utils.hexdump( value_ ).splitlines() )
value = crypto_utils.cipher( True,
self.get_cipherspec(config),
self.get_key(config),
value_,
self.get_iv(config) )
if generic_card.DEBUG:
print "| Encrypted result of length 0x%02x:" % len(value)
print "|| " + "\n|| ".join( utils.hexdump(value).splitlines() )
print
elif t == 0x86:
pi = value[0]
value_ = self.pad(value[1:], ord(pi))
if generic_card.DEBUG:
print "| Tag 0x%02x, length 0x%02x, encrypting (with padding type %x): " % (tag, length, ord(pi))
print "|| " + "\n|| ".join( utils.hexdump( value_ ).splitlines() )
value = pi + crypto_utils.cipher( True,
self.get_cipherspec(config),
self.get_key(config),
value_,
self.get_iv(config) )
if generic_card.DEBUG:
print "| Encrypted result of length 0x%02x:" % len(value)
print "|| " + "\n|| ".join( utils.hexdump(value).splitlines() )
print
result.append( (tag, length, value) )
else: # Ignore
result.append(data[:3])
return result
示例15: cmd_passive_auth
def cmd_passive_auth(self, verbose=1):
"Perform passive authentication"
hashes = {}
result = ""
i = 0
for name in ("DG1", "DG2", "SOD"):
fid = None
for n, f in self.INTERESTING_FILES:
if n == name:
fid = f
break
if fid is None:
return
i += 1
result = self.open_file(fid, 0x0c)
if self.check_sw(result.sw):
contents, sw = self.read_binary_file()
#self.last_result = R_APDU(contents + self.last_sw)
if name != "SOD":
hashes[i] = crypto_utils.hash("SHA", contents)
else:
result = self.verify_cms(contents[4:])
#print hexdump(result)
#print "DG1: %s" % hexdump(hashes[i])
#print "DG2: %s" % hexdump(hashes[2])
res = TLV_utils.tlv_find_tag(TLV_utils.unpack(result), 0x04)
if len(res) == 0:
print "failed to verify EF.SOD"
return
else:
print "verified EF.SOD"
i = 0
for tag, length, hash in res:
i += 1
if hexdump(hashes[i]) == hexdump(hash):
print "DG%d hash verified: %s" % (i, binascii.b2a_hex(hash))
else:
print "DG%d hash failed:" % i
print "was: %s" % binascii.b2a_hex(hashes[i])
print "expected: %s" % binascii.b2a_hex(hash)
return