我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用string.atol()。
def get_mod_from_tpm(keyhandle): (retout,code) = tpm_exec.run("getpubkey -ha %s -pwdk %s"%(keyhandle,get_tpm_metadata('aik_pw')),raiseOnError=False) if code!=tpm_exec.EXIT_SUCESS and len(retout)>0 and retout[0].startswith("Error Authentication failed (Incorrect Password) from TPM_GetPubKey"): return None # now to parse things! inMod = False public_modulus = [] for line in retout: if line.startswith("Modulus"): inMod = True continue if inMod: tokens = line.split() for token in tokens: public_modulus.append(string.atol(token,base=16)) return base64.b64encode(bytearray(public_modulus))
def addr (self, mytab): l = [] for i in mytab : l.append(str(hex(ord(i)))) if(len(l) > 0) : l.reverse() var = l.pop(0) for i in l : if(len(i) == 3) : if(i == "0x0") : i = i + "0" else : i = i[:2] + "0" + i[2] var = var + i[2:] #print "VAR %s" % var addresse = string.atol(var, 16) else : addresse = 0 return (addresse)
def _verify(self, conn, address): import string challenge = self._generate_challenge() conn.send("%d\n" % challenge) response = "" while "\n" not in response and len(response) < 100: data = conn.recv(100) if not data: break response = response + data try: response = string.atol(string.strip(response)) except string.atol_error: if self._verbose > 0: print "Invalid response syntax", repr(response) return 0 if not self._compare_challenge_response(challenge, response): if self._verbose > 0: print "Invalid response value", repr(response) return 0 if self._verbose > 1: print "Response matches challenge. Go ahead!" return 1
def _getBase(self) : base = ulibzeppoo.idtr() return string.atol(base, 16)
def checkFingerprints(self, fd) : syscalls_hijack = [] end = 0 self.getSyscalls() self.getOpcodes() i = fd.readline() liste = i.split() while(liste != [] and end == 0): if(liste[0] != '#') : self.syscalls_fingerprints.map_syscalls[int(liste[0])] = [string.atol(liste[1], 16), liste[3] + " " + liste[4]] else : if(len(liste) > 1) : if(liste[1] == "END"): end = -1 i = fd.readline() liste = i.split() print "++ Checking Syscalls Fingerprints !!!" for i in self.lists_syscalls: if((self.syscalls_fingerprints.map_syscalls[i[0]][0] != self.syscalls_mem.map_syscalls[i[0]][0]) or (self.syscalls_fingerprints.map_syscalls[i[0]][1] != self.syscalls_mem.map_syscalls[i[0]][1])): syscalls_hijack.append([i[0], i[1]]) if(syscalls_hijack != []): print "\t** LISTS OF SYSCALLS HIJACK !!" for i in syscalls_hijack: print "\t\t** %d\t %-15s" %(i[0], i[1]) print "\n\t** PLEASE REINSTALL YOUR SYSTEM NOW !!!" else: print "\t** NO SYSCALLS HIJACK"
def _iphexatodec(self, iphexa) : ipdec="" for i in range(0, 8, 2) : ipdec = "%d" % string.atol(iphexa[i:i+2], 16) + "." + ipdec if(iphexa[9:] == "0000") : ipdec = ipdec[:-1] + ":" + "*" else : ipdec = ipdec[:-1] + ":" + "%d" % string.atol(iphexa[9:], 16) return ipdec
def strtocidr(ips): """returns CIDR start + length from string""" rng = 32 pos = string.find(ips, '/') if not pos == -1: rng = string.atoi(ips[pos+1:]) ips = ips[:pos] if string.find(ips, '.') == -1: ip = string.atol(ips) else: ip = strtoip(ips) if rng < 0 or rng > 32: raise ValueError, "CIDR length out of range" return (ip, rng)
def integervalidator(text): if text in ('', '-', '+'): return PARTIAL try: string.atol(text) return OK except ValueError: return ERROR
def hexadecimalvalidator(text): if text in ('', '0x', '0X', '+', '+0x', '+0X', '-', '-0x', '-0X'): return PARTIAL try: string.atol(text, 16) return OK except ValueError: return ERROR
def _changeNumber(text, factor, increment): value = string.atol(text) if factor > 0: value = (value / increment) * increment + increment else: value = ((value - 1) / increment) * increment # Get rid of the 'L' at the end of longs (in python up to 1.5.2). rtn = str(value) if rtn[-1] == 'L': return rtn[:-1] else: return rtn
def test_atol(self): self.assertEqual(string.atol(" 1 "), 1L) self.assertRaises(ValueError, string.atol, " 1x ") self.assertRaises(ValueError, string.atol, " x1 ")
def main(options, arguments): #print 'options %s' % options #print 'arguments %s' % arguments if(options.device != None) : if(options.device == '/dev/mem') : mmemory = Mem() elif(options.device == '/dev/kmem') : mmemory = Kmem() else: usage() else : mmemory = Kmem() if(options.usemmap == None): options.usemmap = 0 if(options.view != None): if(options.view == 'tasks'): ttasks = GVTasks(mmemory, options.usemmap) ttasks.viewTasks() elif(options.view == 'syscalls'): mysyscalls = GVSyscalls(mmemory, options.usemmap) mysyscalls.viewSyscalls() elif(options.view == 'networks'): nnetworks = GVNetworks(mmemory, options.usemmap) nnetworks.viewNetworks() elif(options.check != None): if(options.check == 'tasks'): ttasks = GVTasks(mmemory, options.usemmap) ttasks.checkViewTasks() elif(options.check == 'networks'): nnetworks = GVNetworks(mmemory, options.usemmap) nnetworks.checkViewNetworks() elif(options.fingerprints != None): ffingerprints = Fingerprints(mmemory) if(options.fingerprints[1] == 'create'): ffingerprints.doFingerprints(options.fingerprints[0]) elif(options.fingerprints[1] == 'check'): ffingerprints.checkFingerprints(options.fingerprints[0]) elif(options.bump != None): mmemory.open("r", options.usemmap) mmemory.dump(string.atol(options.bump[0], 16), int(options.bump[1]), options.bump[2]) mmemory.close() else: usage()