本文整理匯總了Python中six.iterbytes方法的典型用法代碼示例。如果您正苦於以下問題:Python six.iterbytes方法的具體用法?Python six.iterbytes怎麽用?Python six.iterbytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類six
的用法示例。
在下文中一共展示了six.iterbytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: gnu_as_mutable_data_finalizer
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def gnu_as_mutable_data_finalizer(get_pc, comment_char, align=True):
def data_finalizer(env, code, data):
return (get_pc(env, code) if data or env.buffers else []) + code + [
'',
'.pool',
] + ([
'.align',
] if align else []) + [
'__data:',
] + [
'\t.byte %s %s %r' % (
', '.join(hex(b) for b in six.iterbytes(datum)),
comment_char,
orig_datum,
)
for datum, (_, orig_datum) in six.iteritems(data)
]
return data_finalizer
示例2: checksum
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def checksum(msg):
"""
Calculate CRC-16 (16-bit ISO 13239 1st complement) checksum.
(see Yubikey-Manual - Chapter 6: Implementation details)
:param msg: input byte string for crc calculation
:type msg: bytes
:return: crc16 checksum of msg
:rtype: int
"""
crc = 0xffff
for b in six.iterbytes(msg):
crc = crc ^ (b & 0xff)
for _j in range(0, 8):
n = crc & 1
crc = crc >> 1
if n != 0:
crc = crc ^ 0x8408
return crc
示例3: test_protocol_magic_scan_single_byte
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def test_protocol_magic_scan_single_byte(self):
rx = []
def cb(packet):
rx.append(packet)
protocol_handler = StreamProtocolHandler(MagicSchema, cb)
test_sequence = MagicSchema()
test_sequence.value = -29939
pack = test_sequence.pack()
# garbage with our bytes in the middle
test_bytes = b'\x1A\x3fadbsfkasdf;aslkfjasd;f' + pack + b'\x00\x00asdfn234r'
for b in six.iterbytes(test_bytes):
protocol_handler.feed(six.b(chr(b)))
self.assertEqual(len(rx), 1)
self.assertEqual(rx[0].value, -29939)
示例4: crc24
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def crc24(data):
# CRC24 computation, as described in the RFC 4880 section on Radix-64 Conversions
#
# The checksum is a 24-bit Cyclic Redundancy Check (CRC) converted to
# four characters of radix-64 encoding by the same MIME base64
# transformation, preceded by an equal sign (=). The CRC is computed
# by using the generator 0x864CFB and an initialization of 0xB704CE.
# The accumulation is done on the data before it is converted to
# radix-64, rather than on the converted data.
crc = Armorable.__crc24_init
if not isinstance(data, bytearray):
data = six.iterbytes(data)
for b in data:
crc ^= b << 16
for i in range(8):
crc <<= 1
if crc & 0x1000000:
crc ^= Armorable.__crc24_poly
return crc & 0xFFFFFF
示例5: memory
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def memory(ea, op):
'''Operand type decoder for returning a memory reference on either the AArch32 or AArch64 architectures.'''
get_dtype_attribute = operator.attrgetter('dtyp' if idaapi.__version__ < 7.0 else 'dtype')
get_dtype_size = idaapi.get_dtyp_size if idaapi.__version__ < 7.0 else idaapi.get_dtype_size
get_bytes = idaapi.get_many_bytes if idaapi.__version__ < 7.0 else idaapi.get_bytes
# get the address and the operand size
addr, size = op.addr, get_dtype_size(get_dtype_attribute(op))
maxval = 1<<size*8
# dereference the address and return its integer.
res = get_bytes(addr, size) or ''
res = reversed(res) if database.config.byteorder() == 'little' else iter(res)
res = reduce(lambda agg, n: (agg*0x100)|n, six.iterbytes(res), 0)
sf = bool(res & maxval>>1)
return armops.memory(long(addr), long(res-maxval) if sf else long(res))
示例6: _pack_data
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def _pack_data(data):
return ['__data:'] + [
'\tdb ' + ','.join(hex(b) for b in six.iterbytes(datum)) + ' ; ' + repr(orig_datum)
for datum, (_, orig_datum) in six.iteritems(data)
]
示例7: xor
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def xor(key, data):
"""
Perform cyclical exclusive or operations on ``data``.
The ``key`` can be a an integer *(0 <= key < 256)* or a byte sequence. If
the key is smaller than the provided ``data``, the ``key`` will be
repeated.
Args:
key(int or bytes): The key to xor ``data`` with.
data(bytes): The data to perform the xor operation on.
Returns:
bytes: The result of the exclusive or operation.
Examples:
>>> from pwny import *
>>> xor(5, b'ABCD')
b'DGFA'
>>> xor(5, b'DGFA')
b'ABCD'
>>> xor(b'pwny', b'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
b'15-=51)19=%5=9!)!%=-%!9!)-'
>>> xor(b'pwny', b'15-=51)19=%5=9!)!%=-%!9!)-')
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
"""
if type(key) is int:
key = six.int2byte(key)
key_len = len(key)
return b''.join(
six.int2byte(c ^ six.indexbytes(key, i % key_len))
for i, c in enumerate(six.iterbytes(data))
)
示例8: frequency_app
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def frequency_app(parser, cmd, args): # pragma: no cover
"""
perform frequency analysis on a value.
"""
parser.add_argument('value', help='the value to analyse, read from stdin if omitted', nargs='?')
args = parser.parse_args(args)
data = frequency(six.iterbytes(pwnypack.main.binary_value_or_stdin(args.value)))
return '\n'.join(
'0x%02x (%c): %d' % (key, chr(key), value)
if key >= 32 and chr(key) in string.printable else
'0x%02x ---: %d' % (key, value)
for key, value in data.items()
)
示例9: _display
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def _display(self, screen, observations, score, elapsed):
"""Redraw the game board onto the screen, with elapsed time and score.
Args:
screen: the main, full-screen curses window.
observations: a list of `rendering.Observation` objects containing
subwindows of the current game board.
score: the total return earned by the player, up until now.
elapsed: a `datetime.timedelta` with the total time the player has spent
playing this game.
"""
screen.erase() # Clear the screen
# Display the game clock and the current score.
screen.addstr(0, 2, _format_timedelta(elapsed), curses.color_pair(0))
screen.addstr(0, 20, 'Score: {}'.format(score), curses.color_pair(0))
# Display cropped observations side-by-side.
leftmost_column = 0
for observation in observations:
# Display game board rows one-by-one.
for row, board_line in enumerate(observation.board, start=1):
screen.move(row, leftmost_column) # Move to start of this board row.
# Display game board characters one-by-one. We iterate over them as
# integer ASCII codepoints for easiest compatibility with python2/3.
for codepoint in six.iterbytes(board_line.tostring()):
screen.addch(
codepoint, curses.color_pair(self._colour_pair[codepoint]))
# Advance the leftmost column for the next observation.
leftmost_column += observation.board.shape[1] + 3
# Redraw the game screen (but in the curses memory buffer only).
screen.noutrefresh()
示例10: _generate_kernel_bin
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def _generate_kernel_bin(self, k, ctx):
gk = gpuarray.GpuKernel(k.code, k.name, k.params, context=ctx,
**k.flags)
bin = gk._binary
bcode = ','.join(hex(c) for c in iterbytes(bin))
return ("""static const char %(bname)s[] = { %(bcode)s };""" %
dict(bname=k.binvar, bcode=bcode))
示例11: _set_next_blob
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def _set_next_blob(data):
"""
update ``data._obj.Blob``: Increment the contents by 1.
i.e. "XXX...X" is replaced with "YYY...Y".
"""
data._obj.Blob = b"".join(six.int2byte(x + 1) for x in six.iterbytes(data._obj.Blob))
示例12: decrypt
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def decrypt(self, str):
# block - UChar[]
block = []
for i in six.iterbytes(str):
block.append(i)
# print block
block = des_ecb_encrypt(block, self.KeySched, 0)
res = b''
for i in block:
res = res + six.int2byte(i)
return res
示例13: str_to_key56
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def str_to_key56(key_str):
if not type(key_str) == six.binary_type:
# TODO rsanders high - figure out how to make this not necessary
key_str = key_str.encode('ascii')
if len(key_str) < 7:
key_str = key_str + b'\000\000\000\000\000\000\000'[:(7 - len(key_str))]
key_56 = []
for i in six.iterbytes(key_str[:7]):
key_56.append(i)
return key_56
示例14: bytes_to_long
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def bytes_to_long(s):
n = 0
for b in six.iterbytes(s):
n = (n << 8) | b
return n
示例15: _serialize_clob
# 需要導入模塊: import six [as 別名]
# 或者: from six import iterbytes [as 別名]
def _serialize_clob(ion_event):
value = ion_event.value
return _bytes_text(six.iterbytes(value), _DOUBLE_QUOTE, prefix=_LOB_START, suffix=_LOB_END)