本文整理汇总了Python中hex函数的典型用法代码示例。如果您正苦于以下问题:Python hex函数的具体用法?Python hex怎么用?Python hex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writefirefoxtrees
def writefirefoxtrees(repo):
"""Write the firefoxtrees node mapping to the filesystem."""
lines = []
trees = {}
for tree, node in sorted(repo.firefoxtrees.items()):
assert len(node) == 20
lines.append('%s %s' % (tree, hex(node)))
trees[tree] = hex(node)
_firefoxtreesrepo(repo).vfs.write('firefoxtrees', '\n'.join(lines))
# Old versions of firefoxtrees stored labels in the localtags file. Since
# this file is read by Mercurial and has no relevance to us any more, we
# prune relevant entries from this file so the data isn't redundant with
# what we now write.
localtags = repo.opener.tryread('localtags')
havedata = len(localtags) > 0
taglines = []
for line in localtags.splitlines():
line = line.strip()
node, tag = line.split()
tree, uri = resolve_trees_to_uris([tag])[0]
if not uri:
taglines.append(line)
if havedata:
repo.vfs.write('localtags', '\n'.join(taglines))
示例2: __repr__
def __repr__(self):
"""
Return information about image.
"""
adr = self._pixels.ptr()
return '<ImagePRGBA object at %s Width=%i, Height=%i, Pitch=%i, Pixels=%s>' % \
(hex(id(self)), self.width, self.height, self.pitch, hex(adr))
示例3: _expand_regname
def _expand_regname(self,name,offset,var):
"""
Expand register name according to loop variable found in the *.xls sheet
CRI_LH_CR_DA_LO_$k => CRI_LH_CR_DA_LO_0
Args:
name: name of register
offset: address offset value
var : loop variable found in *.xls sheet.
"""
if (var == 0):
hexaddress = str(hex(offset))
res = '{0:35} {1:10}'.format(name,offset)
print res
self.outfile.write(res + ' ' + hexaddress + '\n')
else:
for addr in range(0,var):
b = name.find('$')
hexaddress = str(hex(offset+addr))
res = '{0:35} {1:10}'.format((name[0:b]+ str(addr)),(offset+addr))
print res
# print to outfile
self.outfile.write(res + ' ' + hexaddress + '\n')
print ''
self.outfile.write('\n')
示例4: create_cursor
def create_cursor(self):
# TODO: coverage for server side cursors + select.for_update()
if self.dialect.server_side_cursors:
is_server_side = \
self.execution_options.get('stream_results', True) and (
(self.compiled and isinstance(self.compiled.statement, expression.Selectable) \
or \
(
(not self.compiled or
isinstance(self.compiled.statement, expression._TextClause))
and self.statement and SERVER_SIDE_CURSOR_RE.match(self.statement))
)
)
else:
is_server_side = self.execution_options.get('stream_results', False)
self.__is_server_side = is_server_side
if is_server_side:
# use server-side cursors:
# http://lists.initd.org/pipermail/psycopg/2007-January/005251.html
ident = "c_%s_%s" % (hex(id(self))[2:], hex(_server_side_id())[2:])
return self._dbapi_connection.cursor(ident)
else:
return self._dbapi_connection.cursor()
示例5: main
def main():
# Instantiate the Infrared-Thermopile Sensor on I2C on bus 1
mySensor = TMP006.TMP006(1)
## Exit handlers ##
# This stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This lets you run code on exit,
# including functions from mySensor
def exitHandler():
print("Exiting")
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
# activate periodic measurements
mySensor.setActive();
# Print out temperature value and config-reg in hex every 0.5 seconds
while(1):
mySensor.getTemperature(True)
hex(mySensor.getConfig())
time.sleep(.5)
示例6: __add__
def __add__(self, other):
"""Combine two faked frames.
The expected left operand should be either
a starting faked frame or a resulting frame constructed by
previous combination, while the right operand a normal frame.
"""
if isinstance(other, Shellcode):
# TODO: Support adding shellcode.
# This is not supported at present.
address = hex(int(self.address, 16) + len(other.sc))
payload = (
self.filling_byte*(
self.offset-self.POINTER_SIZE) +
p32(address) + p32(self.leave_ret) + other.sc)
elif other.next_address:
address = other.next_address
payload = (
self.payload + p32(address) + p32(address) +
p32(self.leave_ret))
else:
address = hex((int(self.address, 16) +
3*self.POINTER_SIZE +
len(other.args)*self.POINTER_SIZE))
payload = (self.payload +
p32(address) +
p32(self.resolver.get(other.name)) +
p32(self.leave_ret) + other.make_args())
# Construct a resulting frame.
return self.__class__(address=address, payload=payload)
示例7: GetBase
def GetBase(drvname=None):
EVIL_ARRAY = 1024
myarray = c_ulong * EVIL_ARRAY
lpImageBase = myarray()
cb = c_int(1024)
lpcbNeeded = c_long()
drivername_size = c_long()
drivername_size.value = 48
Psapi.EnumDeviceDrivers(byref(lpImageBase), cb, byref(lpcbNeeded))
for baseaddr in lpImageBase:
drivername = c_char_p("\x00"*drivername_size.value)
if baseaddr:
Psapi.GetDeviceDriverBaseNameA(baseaddr, drivername,
drivername_size.value)
if drvname:
if drivername.value.lower() == drvname:
print "[>] Retrieving %s information." % drvname
print "[>] %s base address: %s" % (drvname, hex(baseaddr))
return baseaddr
else:
if drivername.value.lower().find("krnl") !=-1:
print "[>] Retrieving Kernel information."
print "[>] Kernel version: ", drivername.value
print "[>] Kernel base address: %s" % hex(baseaddr)
return (baseaddr, drivername.value)
return None
示例8: idt
def idt(self):
"""Volatility idt plugin.
@see volatility/plugins/malware/idt.py
"""
results = []
command = self.plugins["idt"](self.config)
for n, entry, addr, module in command.calculate():
if module:
module_name = str(module.BaseDllName or "")
sect_name = command.get_section_name(module, addr)
else:
module_name = "UNKNOWN"
sect_name = ''
# The parent is IDT. The grand-parent is _KPCR.
cpu_number = entry.obj_parent.obj_parent.ProcessorBlock.Number
new = {
"cpu_number": int(cpu_number),
"index": int(n),
"selector": hex(int(entry.Selector)),
"address": hex(int(addr)),
"module": module_name,
"section": sect_name,
}
results.append(new)
return dict(config={}, data=results)
示例9: timers
def timers(self):
"""Volatility timers plugin.
@see volatility/plugins/malware/timers.py
"""
results = []
command = self.plugins["timers"](self.config)
for timer, module in command.calculate():
if timer.Header.SignalState.v():
signaled = "Yes"
else:
signaled = "-"
if module:
module_name = str(module.BaseDllName or "")
else:
module_name = "UNKNOWN"
due_time = "{0:#010x}:{1:#010x}".format(timer.DueTime.HighPart, timer.DueTime.LowPart)
new = {
"offset": hex(timer.obj_offset),
"due_time": due_time,
"period": int(timer.Period),
"signaled": signaled,
"routine": hex(int(timer.Dpc.DeferredRoutine)),
"module": module_name,
}
results.append(new)
return dict(config={}, data=results)
示例10: _parse_range
def _parse_range(self, value_range):
(lb, ub) = value_range
if lb == ub:
if lb > 0xffff:
return "== %s" % hex(lb)
else:
return "== %d" % lb
elif ub == MAX_S64 or ub == MAX_S32 or ub == MAX_S16 or ub == MAX_S8:
if lb == 1:
return "> 0"
else:
return ">= %d" % lb
elif lb == MIN_S64 or lb == MIN_S32 or ub == MIN_S16 or ub == MIN_S8:
if ub == -1:
return "< 0"
else:
return "<= %d" % ub
elif ub == MAX_U64 or ub == MAX_U32 or ub == MAX_U16 or ub == MAX_U8:
assert(lb >= 0)
if lb == MAX_ERRNO:
return "== ERROR_VALUE"
elif lb == 1:
return "!= 0"
else:
return ">= %d" % lb
elif lb == 0 and ub == (MAX_ERRNO-1):
return "!= ERROR_VALUE"
elif lb == 1 and ub == (MAX_ERRNO-1):
return "!= 0 && != ERROR_VALUE"
else:
if ub > 0xffff:
return ">= %d && <= %s" % (lb, hex(ub))
else:
return ">= %d && <= %d" % (lb, ub)
示例11: convert_to_hex
def convert_to_hex():
""" convert one or more arguments from decimal to hex """
print sys.argv
args = sys.argv
del args[0]
for num in args:
print hex(int(num))
示例12: print
def print(self):
if self.chan_type == 'P':
channel_str = self.chan_type + self.chan_id + ']'
else:
channel_str = self.chan_type + self.chan_id + ']' + ' peer=' + self.peer_ip + ':' + self.peer_pid + '/' + self.peer_id
print(" CHANNEL: [channel", channel_str)
socket_dict = {}
for socket in self.sockets:
socket_dict[socket.pri] = (socket.paused, socket.connected, socket.state)
socket_str = ""
for i in [0,1,2,3,4]:
try:
socket_str += 'pri-'+str(i)+' '+str(['-', 'P'][socket_dict[0][0]])+'/'+str(['-','C'][socket_dict[0][1]])+'/'+str(socket_dict[0][2])+' '
except:
pass
print(" SOCKETS:", socket_str)
if len(self.methbindings) > 0:
print(" METHODS:")
method_dict = {}
for methbinding in self.methbindings:
try:
method_dict[hex(methbinding.pathhash).rstrip("L")][1].append(tuple((methbinding.payt, methbinding.methno)))
except KeyError:
method_dict[hex(methbinding.pathhash).rstrip("L")] = tuple((methbinding.path, [tuple((methbinding.payt, methbinding.methno))]))
#THE FOLLOWING CODE PRINTS METHODS IN A DIFFERENT STYLE
#method_dict[methbinding.pathhash] = method_dict[methbinding.pathhash].append((methbinding.payt, methbinding.methno))
#method_str = hex(methbinding.pathhash).rstrip("L") + ' payt ' + str(methbinding.payt) + ' methno ' + str(methbinding.methno) + ' path=' + methbinding.path
#print(" ", method_str)
for phash in method_dict.keys():
method_str = ""
count = 0
for i in method_dict[phash][1]:
count+=1
method_str += str(i) + ['\n ', ' '][int(count%4!=0)]
print(" path=%s (%s)\n (payt, methno)s: %s" %(method_dict[phash][0], phash, method_str))
示例13: __init__
def __init__(self, context):
# Align file to nearest word
file_object = context.file_object
align(file_object)
out(context,'Object Header @ %s' % hex(file_object.tell()) )
context.indent()
self.mtype = read_num(file_object.read(2))
out(context,'Type: %s' % hex(self.mtype))
self.size = read_num(file_object.read(2))
out(context,'Size: %s' % self.size)
self.flags = read_num(file_object.read(1))
file_object.read(3) # Reserved
end_offset = file_object.tell() + self.size
if self.mtype == 0x00: # NIL Block
out(context,'Nil Block')
elif self.mtype == 0x01:
self.dataspace_message = DataspaceMessage(context)
elif self.mtype == 0x03:
self.datatype_message = DatatypeMessage(context)
elif self.mtype == 0x05:
self.fill_value_message = FillValueMessage(context)
elif self.mtype == 0x0010: # Continuation block
self.continuation = ContinuationMessage(context)
context.object_eof[-1] = self.continuation.continuation_length + self.continuation.continuation_offset
# Go to the offset
file_object.seek(self.continuation.continuation_offset)
elif self.mtype == 0x0011:
self.symbol_table_message = SymbolTableMessage(context)
elif self.mtype == 0x000C:
self.attr = AttributeMessage(context)
if self.attr.is_vlen_str():
foffset = file_object.tell()
file_object.seek(self.attr.global_heap_addr)
global_heap = GlobalHeap(context)
self.attr.vlen_str = global_heap.objects[ self.attr.global_heap_index ].data
file_object.seek(foffset)
out(context,'Vlen-str Value: %s' % self.attr.vlen_str)
else:
out(context,'Unknown type')
file_object.read(self.size) #
if self.mtype != 0x0010:
file_object.seek(end_offset) # Properly move to the end even if all the fields weren't read
context.unindent()
示例14: WriteDACs
def WriteDACs(scanstart, scanstop, scanstep):
DAC_Chip = range(0,8,1)
DAC_Channel = ("CMD0", "CMD1", "CMD2", "CMD3")
scanstart = 0
scanstop = 2500
scanstep = 250
scanstart = int(scanstart)
scanstop = int(scanstop)
scanstep = int(scanstep)
TestVoltages = range(scanstart, scanstop, scanstep)
TestVoltages.append(2490)
print "Test voltages: ", TestVoltages
for chip in DAC_Chip:
chip = str(chip)
print "chip:", chip
for channel in DAC_Channel:
for mVolts in range(scanstart, scanstop, scanstep):
print "new mV setting:", mVolts
stepdata = int(mVolts*4096/2500)
# -> INCREMENT DAC VOLTAGES:
proc.writeAD5624_adcboard(channel,hex(stepdata),chip)
proc.writeAD5624_adcboard(channel,hex(stepdata),chip)
time.sleep(1)
time.sleep(60)
示例15: GetMediaSvrPort
def GetMediaSvrPort(target):
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((target,111))
sock.send(rpc_portmap_req)
rec = sock.recv(256)
sock.close()
port1 = rec[-4]
port2 = rec[-3]
port3 = rec[-2]
port4 = rec[-1]
port1 = hex(ord(port1))
port2 = hex(ord(port2))
port3 = hex(ord(port3))
port4 = hex(ord(port4))
port = '%02x%02x%02x%02x' % (int(port1,16),int(port2,16),int(port3,16),int(port4,16))
port = int(port,16)
if port < 1100:
print '[+] Fresh Meat: Mediasvr.exe has not been restarted, Sending Packet 1 to: Target: %s Port: %s' %(target,port)
ExploitMediaSvr(target,port,1)
else:
print '[+] Mediasvr.exe has been restarted, Sending Packet 2 to: Target: %s Port: %s' % (target,port)
ExploitMediaSvr(target,port,2)