def buildframe(numframes, packet): binary_string = htb(packet) firstpart = '{"startFlag":["7e"],"Address": ["ff"],"Information": ["' middlepart = '"],"FCS": ["' frames = [] if numframes == 1: frames.insert( 1, firstpart + packet.replace(' ', '') + middlepart + str(bth(checksum(binary_string))) + '"],"endFlag": ["7e"],"SeqNo":["' + str(1) + '"],"EndOfPacket":["' + str(1) + '"],"FrameId":["0"]}') else: # print "grapes" splitpoint = 0 for i in range(0, numframes): partofpacket = binary_string[splitpoint:splitpoint + 480] hexstring = bth(partofpacket) # print len(partofpacket),"\n" frames.insert( i + 1, firstpart + hexstring + middlepart + str(bth(checksum(partofpacket))) + '"],"endFlag": ["7e"],"SeqNo":["' + str(i + 1) + '"],"EndOfPacket":["00"],"FrameId":["0"]}') splitpoint += 480 if len(binary_string) % (60 * 8) > 0: partofpacket = binary_string[splitpoint:len(binary_string)] hexstring = bth(partofpacket) frames.insert( numframes + 1, firstpart + hexstring + middlepart + str(bth(checksum(partofpacket))) + '"],"endFlag": ["7e"],"SeqNo":["' + str(numframes + 1) + '"],"EndOfPacket":["01"],"FrameId":["0"]}') return frames
def isExpected(identifier): #try: id = identifier[0:9] #also checks for old checksums with lower case letters print "id: "+identifier print "id without checksum: "+id print "checksum: "+checksum.checksum(id) return checksum.checksum(id)==identifier[9]
def isExpected(identifier): #try: id = identifier[0:9] #also checks for old checksums with lower case letters print "id: " + identifier print "id without checksum: " + id print "checksum: " + checksum.checksum(id) return checksum.checksum(id) == identifier[9]
def enableMotorServo(robot, sw): # "CALL" GLOBAL VARIABLES global STX global RID global ETX global reservet # FUNCTION LOCAL VARIABLES DID = "1e" lengh = "01" # SWITCH FOR DATA if sw == 0: data = '00' else: data = '01' # CHECKSUM AND PACKET FOR TX check = checksum.checksum(RID, reservet, DID, lengh, data) packet = bytes.fromhex(STX + RID + reservet + DID + lengh + data + check + ETX) # IP SET AND SENDING setIP(robot=robot) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(('', 10001)) s.sendto(packet, (UDP_IP, 10001)) return 10001
def unpack(self, data): [ self.srcp, self.dstp, self.seqn, self.ackn, data_offset, flags, self.window ] = struct.unpack('!HHLLBBH', data[0:16]) # When unpack the checksum part, DON'T use network byte order ! [self.chksum] = struct.unpack('H', data[16:18]) [self.urgp] = struct.unpack('!H', data[18:20]) self.offset = data_offset >> 4 self.fin = flags & 0x01 self.syn = flags >> 1 & 0x01 self.rst = flags >> 2 & 0x01 self.psh = flags >> 3 & 0x01 self.ack = flags >> 4 & 0x01 self.urg = flags >> 5 & 0x01 self.data = data[self.offset * 4:] pse_header = struct.pack('!4s4sBBH', socket.inet_aton(self.src), socket.inet_aton(self.dst), 0, socket.IPPROTO_TCP, self.offset * 4 + len(self.data)) if checksum(pse_header + data) != 0: print("TCP: checksum error!") self.data = ''
def wrong_checksum(account): possible_accounts = [] for i in range(len(account)): index = account[i] hex = digits.digits_hex[index] to_check = translator.translate(hex) possibilities = check_possibilities(to_check) possible_digits = [] if (len(possible_digits)) == 0: break for entry in possibilities: if entry in digits.digits_hex: possible_digits.append(digits.digits_hex.index()) temp = account.copy() for j in possible_digits: temp[i] = j if checksum.checksum(temp) == True: possible_accounts.append(temp) if len(possible_accounts) == 1: account = possible_accounts[0] return account elif len(possible_accounts) == 0: account.append(" ERR") return account else: account.append(" AMB " + str(possible_accounts)) return account
def send(self, data, need_checksum=True): if __DEBUG__ is True: print "<- %s" % data if need_checksum: self.conn.sendall("$%s#%s" % (data, checksum(data))) else: self.conn.sendall(data) self.last_sent = (data, need_checksum)
def isExpected(code): try: id = code[0:9] #also checks for old checksums with lower case letters return checksum.checksum(id) == code[9] except: return False
def isExpected(identifier): try: id = identifier[0:9] #also checks for old checksums with lower case letters return checksum.checksum(id)==identifier[9] except: return False
def isExpected(identifier): try: id = identifier[0:9] #also checks for old checksums with lower case letters return checksum.checksum(id) == identifier[9] except: return False
def getNextFreeBarcode(projectcode, numberOfBarcodes): letters = string.ascii_uppercase numberOfBarcodes += 1 currentLetter = letters[numberOfBarcodes / 999] currentNumber = numberOfBarcodes % 999 code = projectcode + str(currentNumber).zfill(3) + currentLetter return code + checksum.checksum(code)
def handle_file(self,f,dev_id): #stores each uploaded file in the file system r = self.check_destiny(f) with open(r+f.name, 'wb+') as destination: for chunk in f.chunks(): destination.write(chunk) destination.close() chksum = checksum(r+f.name) return chksum
def sequence_handle(self, buf): if buf is None or len(buf) == 0: print "Waring: buf is None or empty." return while len(buf) > 0: if buf[0] == "+": buf = buf[1:] continue if buf[0] == "\x03": if __DEBUG__: print "recv \\x03, break." buf = buf[1:] self.machine.run_break() #self.send_cmd("T02thread:01;") continue if buf[0] == '-': if __DEBUG__: print "Got -, resend." self.resend() buf = buf[1:] continue if buf[0] == "$": if __DEBUG__: print "Got cmd, %s" % buf mobj = re.match(r'^\$([^#]+)#([0-9a-f]{2}$)', buf) if mobj is None: print "Waring: Bad format cmd found! cmd= %s" % buf continue cmd = mobj.groups()[0] chk_sum_value = mobj.groups()[1] if __DEBUG__: print "cmd = %s, checksum = %s" % (cmd, chk_sum_value) if len("$") + len(cmd) + len("#") + len(chk_sum_value) != len( buf): print "Waring: multi-cmd received! buf= %s" % (buf) if checksum(cmd) != chk_sum_value: print "Waring: checksum mismatch! checksum(cmd) = %s, chk_sum_value = %s" % ( checksum(cmd), chk_sum_value) self.send("-") #request gdb to send commmand again. break #ignore this pack. self.cmd_handle(cmd) break
def upload_with_hash(filename, username, **kwargs): print('upload_with_hash') assert type(filename) is StringType assert type(username) is StringType imagesha512 = checksum.checksum(filename) kwargs_with_hash = add_machine_tag('ktools', 'imagesha512', imagesha512, **kwargs) assert 'tags' in kwargs_with_hash assert 'ktools:imagesha512' in kwargs_with_hash['tags'] return upload(filename=filename, username=username, **kwargs_with_hash)
def check_data(line): # recorded checksum cs = re.split('[*]|_',line)[-2] # String to check str = line.lstrip("$").split("*")[0] # Compare with string checksum if int(cs,16) == int(checksum(str),16): return True else: return False
def test_fileChecksums(self): '''Checksum all sample items''' for thisFile in self.sampleFiles: for thisChecksumType in thisFile: if thisChecksumType in ['filePath', 'description']: continue result = checksum(thisFile['filePath'], checksumType=thisChecksumType, progressReporter=None) self.assertTrue(result is not None, 'Checksumming %s with %s returned None' % (thisFile['description'], thisChecksumType)) self.assertEqual(result['checksum'], thisFile[thisChecksumType], 'Checksumming %s using %s did not give the expected result (%s) rather: %s' % (thisFile['description'], thisChecksumType, thisFile[thisChecksumType], result['checksum']))
def is_valid(self): if self.command is None or self.checksum is None: if self.ack is not None: return True else: return False if checksum(self.command) == self.checksum: return True else: return False
def parse_dictionary(dic): index = 0 newfile = "account_numbers_after_cleaning.txt" while (index + 4) < len(dic): position = 0 account_numbers = [] # onelist for actual accounts to print to file line_1 = dic[index + 1] line_2 = dic[index + 2] line_3 = dic[index + 3] while position < 33: # 27 characters + 9 spaces = 36 digits single = [] single.append(line_1[position:position + 3]) single.append(line_2[position:position + 3]) single.append(line_3[position:position + 3]) single = translator.translate(single) if single in digits.translation: # check if single is value in translation_dic and if yes return key check = digits.translation.index(single) account_numbers.append(check) position += 4 else: account_numbers.append('?') questionmark = single position += 4 if '?' in account_numbers: account_numbers.append(" ILL") writer.write_file(account_numbers, "Accountnumbers_as_read.txt") account_numbers.pop() account_numbers = alternatives.illegible( account_numbers, questionmark) #-> add to second file writer.write_file(account_numbers, newfile) elif checksum.checksum(account_numbers) == False: account_numbers.append(" ERR") writer.write_file(account_numbers, "Accountnumbers_as_read.txt") account_numbers.pop() account_numbers = alternatives.wrong_checksum( account_numbers) #wrong checksum -> add to second file writer.write_file(account_numbers, newfile) else: writer.write_file(account_numbers, "Accountnumbers_as_read.txt") writer.write_file(account_numbers, newfile) index += 4
def ping(sock, dest_addr, id = os.getpid() & 0xffff, seq_num = 0, data = b'UNIX', timeout = 2): """ sock: the socket in this machine to use to ping dest_addr: the IP address to ping id: the desired id in the ICMP header seq_num: also used in the ICMP header data: the data to put and is echoed by the pinged address timeout: the timeout before giving up on the address typical use: ping(socket_to_host, host_ip_in_str) returns (travel_time, TTL) on success and returns (0, 0) on failure """ #SENDING PART #create ICMP header csum = 0 header = struct.pack("!BBHHH", ICMP_ECHO_REQUEST, 0, csum, id, seq_num) csum = checksum(header + data) header = struct.pack("!BBHHH", ICMP_ECHO_REQUEST, 0, csum, id, seq_num) #send the data #any exceptions recieved must be handled by the caller sock.sendto(header + data, (dest_addr, 1)) #port number is irrelevant #RECIEVING PART t = time.clock() ready_r, _, __ = select.select([sock], [], [], timeout) travel_time = time.clock() - t #if timedout if not ready_r: return 0, 0 data, addr = sock.recvfrom(MAX_REC_SIZE) ip_header = get_header(data) data = data[20:] return travel_time, ip_header.ttl
def send_one(load): tobytes = lambda x: bytearray.fromhex('{:04x}'.format(x)) tohex = lambda x: ' '.join(['{:02x}'.format(item) for item in x]) mesg = bytearray(load) type_code = bytearray('\x08\x00') ident = tobytes(randint(0, 65535)) fakecheck = bytearray('\x00\x00') seq = tobytes(0) realcheck = tobytes(checksum(type_code + fakecheck + ident + seq + mesg)) data = type_code + realcheck + ident + seq + mesg s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP) s.sendto(data, ('localhost', 0))
def createNewBarcode(project, tr): search_service = tr.getSearchService() offset = 0 exists = True while exists: n = str(len(newTestSamples)+1+offset) #for future programmers: sorry if this reaches > 999 ! code = project+n.zfill(3)+"X" # should go to other letters in that case code = code+checksum.checksum(code) pc = SearchCriteria() pc.addMatchClause(SearchCriteria.MatchClause.createAttributeMatch(SearchCriteria.MatchClauseAttribute.CODE, code)) found = search_service.searchForSamples(pc) print found if len(found) == 0: exists = False else: offset += 1 return code
def createPacket(data, remote_IP, remote_port, host, ack_port_num, window_size, seq_number, fin, ack): # tcp header fields tcp_ack_seq = 0 tcp_doff = 5 # 4 bit field, size of tcp header, 5 * 4 = 20 bytes # tcp flags tcp_fin = fin tcp_syn = 0 tcp_rst = 0 tcp_psh = 0 tcp_ack = ack tcp_urg = 0 tcp_window = window_size # maximum allowed window size tcp_check = 0 tcp_urg_ptr = 0 tcp_offset_res = (tcp_doff << 4) + 0 tcp_flags = tcp_fin + (tcp_syn << 1) + (tcp_rst << 2) + (tcp_psh << 3) + (tcp_ack << 4) + (tcp_urg << 5) # the ! in the pack format string means network order header = pack('!HHLLBBHHH', ack_port_num, remote_port, seq_number, tcp_ack_seq, tcp_offset_res, tcp_flags, tcp_window, tcp_check, tcp_urg_ptr) if data != 0: if len(data)% 2 == 0: padding = 0 else: padding =1 if data != 0: packet = header + data; else: packet = header tcp_check = c.checksum(packet) # print tcp_checksum # make the tcp header again and fill the correct checksum - remember checksum is NOT in network byte order tcp_header = pack('!HHLLBBHHH', ack_port_num, remote_port, seq_number, tcp_ack_seq, tcp_offset_res, tcp_flags, tcp_window, tcp_check, tcp_urg_ptr) if data != 0: packet = tcp_header + data else: packet = tcp_header return packet
def wrong_checksum(account): list_of_possibilities = [] account.pop() # remove ERR possible_account = account.copy() for i in range(len(possible_account)): for entry in possible_alternatives[possible_account[i]]: actual_number = possible_account[i] possible_account[i] = entry if checksum.checksum(possible_account) == True: to_add = possible_account.copy() list_of_possibilities.append(to_add) possible_account[i] = actual_number account = possible_outcomes(account, list_of_possibilities) return account
def test_fileChecksums(self): '''Checksum all sample items''' for thisFile in self.sampleFiles: for thisChecksumType in thisFile: if thisChecksumType in ['filePath', 'description']: continue result = checksum(thisFile['filePath'], checksumType=thisChecksumType, progressReporter=None) self.assertTrue( result is not None, 'Checksumming %s with %s returned None' % (thisFile['description'], thisChecksumType)) self.assertEqual( result['checksum'], thisFile[thisChecksumType], 'Checksumming %s using %s did not give the expected result (%s) rather: %s' % (thisFile['description'], thisChecksumType, thisFile[thisChecksumType], result['checksum']))
def comanda(self, pitch=0, roll=0, yaw=0, thrust=0): """ Envia una comanda de control al Drone. Retorna True si s'ha pogut enviar la comanda i False en cas contrari. :rtype: bool """ check = checksum.checksum([pitch, roll, yaw, thrust, self.ctrl]) estructura = { 'pitch': pitch, 'roll': roll, 'yaw': yaw, 'thrust': thrust, 'ctrl': self.ctrl, 'checksum': check } tx_data = {'tipus': 'di', 'estructura': estructura} data.tx_data(tx_data) rx_data = data.rx_data() return rx_data == 'OK'
def illegible(account, questionmark): position = account.index('?') possibilities = check_possibilities(questionmark) unique = [] [unique.append(x) for x in possibilities if x not in unique] if len(unique) == 1: account[position] = unique[0] if checksum.checksum(account) == False: account.append(" ERR") return account elif len(unique) == 0: account.append(" ILL") return account else: account.append( " AMB => " + str(unique)) # forgot first check id checksum is correct return account
def csButtonClicked(self): import checksum i = 1 header_body = '' # 消息头+消息体 while i < 6: header_body += self.edits[i].text().strip().replace(' ','') i += 1 cs = checksum.checksum(header_body) cs_text = '%02X' % cs self.edits[6].setText(cs_text) self.header_body_cs = header_body + cs_text # 消息头+消息体+校验码 # 自动显示完整消息 i = 0 result_text = '' while i < 8: result_text += self.edits[i].text().strip().replace(' ','') i += 1 self.result_text.setPlainText(result_text)
def pack(self): self.tl = self.ihl * 4 + len(self.data) self.id = randint(0, 65535) ver_ihl = (self.ver << 4) + self.ihl flag_offset = (self.flag << 13) + self.offset ip_header = struct.pack('!BBHHHBBH4s4s', ver_ihl, self.tos, self.tl, self.id, flag_offset, self.ttl, self.proto, self.chksum, socket.inet_aton(self.src), socket.inet_aton(self.dst)) self.chksum = checksum(ip_header) ip_header = struct.pack('!BBHHHBB', ver_ihl, self.tos, self.tl, self.id, flag_offset, self.ttl, self.proto) # When pack the checksum part, DON'T use network byte order ! ip_header += struct.pack('H', self.chksum) ip_header += struct.pack('!4s4s', socket.inet_aton(self.src), socket.inet_aton(self.dst)) #print "IP: header: " + str(['%02X' % ord(c) for c in ip_header]) return ip_header + self.data
def createNewBarcode(project, tr): search_service = tr.getSearchService() offset = 0 exists = True while exists: n = str(len(newTestSamples) + 1 + offset) #for future programmers: sorry if this reaches > 999 ! code = project + n.zfill( 3) + "X" # should go to other letters in that case code = code + checksum.checksum(code) pc = SearchCriteria() pc.addMatchClause( SearchCriteria.MatchClause.createAttributeMatch( SearchCriteria.MatchClauseAttribute.CODE, code)) found = search_service.searchForSamples(pc) print found if len(found) == 0: exists = False else: offset += 1 return code
def update_with_hash(filename, username, **kwargs): print('update_with_hash') assert type(filename) is StringType assert type(username) is StringType imagesha512 = checksum.checksum(filename) kwargs_with_hash = add_machine_tag(namespace, image_hash_predicate, imagesha512, **kwargs) assert 'tags' in kwargs_with_hash assert namespace + ':' + image_hash_predicate + '=' in kwargs_with_hash[ 'tags'] flickr = authenticate.get_flickr(username) photo_id = get_photo_id_by_hash(imagesha512, flickr) if photo_id: tags_str = tags.get_tags_str(filename) assert type( tags_str) is StringType, 'tags_str must be a string not <' + str( type(tags_str)) + '>' tags_str += ' ' + kwargs_with_hash['tags'] return update_tags(photo_id, flickr, tags_str) return upload(filename=filename, username=username, flickr=flickr, **kwargs_with_hash)
def pack(self, data=''): self.data = data data_offset = (self.offset << 4) + 0 flags = self.fin + (self.syn << 1) + (self.rst << 2) + ( self.psh << 3) + (self.ack << 4) + (self.urg << 5) tcp_header = struct.pack('!HHLLBBHHH', self.srcp, self.dstp, self.seqn, self.ackn, data_offset, flags, self.window, self.chksum, self.urgp) # Pseudo header for checksum pse_header = struct.pack('!4s4sBBH', socket.inet_aton(self.src), socket.inet_aton(self.dst), 0, socket.IPPROTO_TCP, self.offset * 4 + len(self.data)) self.chksum = checksum(pse_header + tcp_header + self.data) tcp_header = struct.pack("!HHLLBBH", self.srcp, self.dstp, self.seqn, self.ackn, data_offset, flags, self.window) # When pack the checksum part, DON'T use network byte order ! tcp_header += struct.pack('H', self.chksum) tcp_header += struct.pack('!H', self.urgp) #print "TCP: send header: " + str(['%02X' % ord(c) for c in tcp_header]) #print "TCP: send header checksum: " + str(hex(self.chksum)) return tcp_header + self.data
def unpack(self, data): [ ver_ihl, self.tos, self.tl, self.id, flag_offset, self.ttl, self.proto ] = struct.unpack('!BBHHHBB', data[0:10]) # When unpack the checksum part, DON'T use network byte order ! [self.chksum] = struct.unpack('H', data[10:12]) [src_ip, dst_ip] = struct.unpack('!4s4s', data[12:20]) self.ver = (ver_ihl & 0xf0) >> 4 self.ihl = ver_ihl & 0x0f # CAUTION!!! self.flag = (flag_offset & 0x6000) >> 13 self.offset = flag_offset & 0x1fff self.src = socket.inet_ntoa(src_ip) self.dst = socket.inet_ntoa(dst_ip) self.data = data[20:self.tl] # Check the checksum ip_header = data[0:20] if checksum(ip_header) != 0: #raise ChecksumError('IP') print("IP: Checksum error!") self.data = ''
def test_checksum(self): self.assertEqual(checksum('test_input'), 18)
Def = IVs % 32 IVs >>= 5; Spe = IVs % 32 IVs >>= 5; SpA = IVs % 32 IVs >>= 5; SpD = IVs % 32 IVs >>= 5; IsEgg = IVs %2; IsNick = IVs / 2; f.seek(8) bytes = f.read(2) DexNo = ( bytes[1] << 8 ) + bytes[0] DexName = pokedex[str(DexNo)].capitalize() f.seek(0x15) bytes = f.read(1) AbilityNo = bytes[0] Ability = abilitydex[str(AbilityNo)].capitalize() f.close() """ Display Data Stuffs """ print("#" + str(DexNo) + ": " + DexName) print("PID: " + hex(PID).upper() + " / " + str(PID)) print( str(HP) + " HP / " + str(Atk) + " Atk / " + str(Def) + \ " Def / " + str(SpA) + " SpA / " + str(SpD) + " SpD / " \ + str(Spe) + " Spe") print( "Is Egg: " + str(bool(IsEgg)) ) print( "Is Nicknamed: " + str(bool(IsNick)) ) print( "Ability: " + Ability ) checksum.checksum(filename)
def verify_checksum(self, data_bytes, checksum_bytes): data_crc = checksum(bytearray(data_bytes)) crc_msb = data_crc >> 8 crc_lsb = data_crc & 0xFF return checksum_bytes[0] == crc_lsb and checksum_bytes[1] == crc_msb
def checksum_bytes(self, data_bytes): crc = checksum(data_bytes) crc_msb = crc >> 8 crc_lsb = crc & 0xFF return bytearray([ crc_lsb, crc_msb ])
def findItemInCaches(myClass, nameOrLocation, checksumType, checksumValue, displayName=None, additionalSourceFolders=None, progressReporter=True, includeRemoteCaches=False): # ---- validate input # nameOrLocation if not hasattr(nameOrLocation, 'capitalize') and not nameOrLocation is None: raise ValueError('findItem requires a string or none as a nameOrLocation, but got: ' + nameOrLocation) if nameOrLocation is not None and nameOrLocation.startswith('file://'): nameOrLocation = nameOrLocation[len('file://'):] if nameOrLocation is not None and urlparse.urlparse(nameOrLocation).scheme != '': raise ValueError('findItemInCaches only works on file paths or names, got: ' + str(nameOrLocation)) # checksumType if not hasattr(checksumType, 'capitalize'): raise ValueError('findItem requires a string as a checksumType, but got: ' + checksumType) # checksumValue if not hasattr(checksumValue, 'capitalize'): raise ValueError('findItem requires a string as a checksumValue, but got: ' + checksumValue) # displayName if not hasattr(displayName, 'capitalize') and not displayName is None: raise ValueError('findItem requires a string or None as a displayName, but got: ' + displayName) # additionalSourceFolders foldersToSearch = myClass.getSourceFolders() if additionalSourceFolders is None: pass # nothing to do elif hasattr(additionalSourceFolders, 'capitalize') and os.path.isdir(additionalSourceFolders): foldersToSearch.append(pathHelpers.normalizePath(additionalSourceFolders, followSymlink=True)) elif hasattr(additionalSourceFolders, '__iter__'): # validate that these are all folders for thisFolder in additionalSourceFolders: if not os.path.isdir(thisFolder): raise ValueError('The folder given to findItemInCaches as an additionalSourceFolders either did not exist or was not a folder: ' + thisFolder) foldersToSearch.append(pathHelpers.normalizePath(thisFolder, followSymlink=True)) else: raise ValueError('Unable to understand the additionalSourceFolders given: ' + str(additionalSourceFolders)) # progressReporter if progressReporter is True: progressReporter = displayTools.statusHandler(statusMessage='Searching cache folders for ' + nameOrLocation) elif progressReporter is False: progressReporter = None # ---- search for the items # absolute paths if nameOrLocation is not None and os.path.isabs(nameOrLocation): if os.path.exists(nameOrLocation): if checksumValue == checksum.checksum(nameOrLocation, checksumType=checksumType, progressReporter=progressReporter)['checksum']: return nameOrLocation, False else: raise FileNotFoundException('The item at the path given does not match the checksum given: ' + nameOrLocation) else: raise FileNotFoundException('No file/folder existed at the absolute path: ' + nameOrLocation) # relative path elif nameOrLocation is not None and os.path.exists(nameOrLocation): if checksumValue == checksum.checksum(nameOrLocation, checksumType=checksumType, progressReporter=progressReporter)['checksum']: return pathHelpers.normalizePath(nameOrLocation, followSymlink=True), False # cache folders for thisCacheFolder in foldersToSearch: parsedLocation = urlparse.urlparse('') if nameOrLocation is not None: parsedLocation = urlparse.urlparse(thisCacheFolder) if parsedLocation.scheme in ['http', 'https'] and includeRemoteCaches is False: continue elif parsedLocation.scheme in ['http', 'https'] and includeRemoteCaches is True: # -- try different paths on the server urlsToTry = {} (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(thisCacheFolder) # simple name urlsToTry[urlparse.urlunparse((scheme, netloc, os.path.join(path, nameOrLocation), params, query, fragment))] = True urlsToTry[urlparse.urlunparse((scheme, netloc, os.path.join(path, urllib.quote(nameOrLocation)), params, query, fragment))] = True # name including checksum nameWithChecksum = os.path.splitext(nameOrLocation)[0] + " " + checksumType + "-" + checksumValue + os.path.splitext(nameOrLocation)[1] urlsToTry[urlparse.urlunparse((scheme, netloc, os.path.join(path, nameWithChecksum), params, query, fragment))] = True urlsToTry[urlparse.urlunparse((scheme, netloc, os.path.join(path, urllib.quote(nameWithChecksum)), params, query, fragment))] = True for thisURL in urlsToTry.keys(): try: readFile = urllib2.urlopen(thisURL) except IOError, error: continue remoteGuessedName = os.path.basename(urllib.unquote(urlparse.urlparse(thisURL).path)) targetFileName = remoteGuessedName if checksumType + "-" + checksumValue not in targetFileName: targetFileName = os.path.splitext(remoteGuessedName)[0] + " " + checksumType + "-" + checksumValue + os.path.splitext(remoteGuessedName)[1] # try to get the expected file length httpHeader = readFile.info() expectedLength = None if httpHeader.has_key("content-length"): try: expectedLength = int(httpHeader.getheader("content-length")) except: pass if progressReporter is not None: if expectedLength is None: progressReporter.update(statusMessage=' downloading from local web cache ') else: progressReporter.update(statusMessage=' downloading %s from local web cache ' % displayTools.bytesToRedableSize(expectedLength)) # download file hashGenerator = hashlib.new(checksumType) startTime = time.time() targetFilePath = os.path.join(myClass.getCacheFolder(), targetFileName) processedBytes, processSeconds = checksum.checksumFileObject(hashGenerator, readFile, remoteGuessedName, expectedLength, copyToPath=targetFilePath, progressReporter=progressReporter) if hashGenerator.hexdigest() != checksumValue: os.unlink(targetFilePath) else: if progressReporter is not None: progressReporter.update(statusMessage=' downloaded from local web cache and verified %s in %s (%s/sec)' % (displayTools.bytesToRedableSize(processedBytes), displayTools.secondsToReadableTime(time.time() - startTime), displayTools.bytesToRedableSize(processedBytes/processSeconds))) progressReporter.finishLine() myClass.addItemToVerifiedFiles('%s-%s' % (checksumType, checksumValue), targetFilePath) readFile.close() return targetFilePath, True readFile.close() elif parsedLocation.scheme == '': # relative paths from the source folders if nameOrLocation is not None and nameOrLocation.count(os.sep) > 0 and os.path.exists(os.path.join(thisCacheFolder, nameOrLocation)): if checksumValue == checksum.checksum(os.path.join(thisCacheFolder, nameOrLocation), checksumType=checksumType, progressReporter=progressReporter)['checksum']: return pathHelpers.normalizePath(os.path.join(thisCacheFolder, nameOrLocation), followSymlink=True), False # walk up through the whole set for currentFolder, dirs, files in os.walk(thisCacheFolder, topdown=True): # check each file to see if it is what we are looking for for thisItemPath, thisItemName in [[os.path.join(currentFolder, internalName), internalName] for internalName in (files + dirs)]: # checksum in name fileNameSearchResults = myClass.fileNameChecksumRegex.search(thisItemName) nameChecksumType = None nameChecksumValue = None if fileNameSearchResults is not None: nameChecksumType = fileNameSearchResults.group('checksumType') nameChecksumValue = fileNameSearchResults.group('checksumValue') if nameChecksumType is not None and nameChecksumType.lower() == checksumType.lower() and nameChecksumValue is not None and nameChecksumValue == checksumValue: if checksumValue == checksum.checksum(thisItemPath, checksumType=checksumType, progressReporter=progressReporter)['checksum']: return thisItemPath, False # file name if nameOrLocation is not None: if nameOrLocation in [thisItemName, os.path.splitext(thisItemName)[0]] or os.path.splitext(nameOrLocation)[0] in [thisItemName, os.path.splitext(thisItemName)[0]]: if checksumValue == checksum.checksum(thisItemPath, checksumType=checksumType, progressReporter=progressReporter)['checksum']: return thisItemPath, False # don't decend into folders that look like bundles or sparce dmg's if os.path.isdir(thisItemPath): if os.listdir(thisItemPath) == ["Contents"] or os.listdir(thisItemPath) == ["Info.bckup", "Info.plist", "bands", "token"]: dirs.remove(thisItemName)
def dochex(CO, ini): import math from checksum import checksum xoxo = len(CO) xox = math.floor((xoxo % 32) / 2) lns = math.floor(xoxo / 32) #print(xoxo,xox,lns) extra = 0 if (xox != 0): extra = 1 a = [] for i in range(lns + extra): a.append(":") k = 0 for i in range(lns): a[i] = a[i] + "10" + ini + "00" for j in range(32): a[i] = a[i] + CO[k] k = k + 1 ini = hex(int(ini, 16) + 16) if (len(ini) == 5): ini = ini.replace("0x", "0").upper() if (len(ini) == 4): ini = ini.replace("0x", "00").upper() if (len(ini) == 3): ini = ini.replace("0x", "000").upper() if (len(ini) == 2): ini = ini.replace("0x", "0000").upper() if (len(ini) == 6): ini = ini.replace("0x", "").upper() if (extra == 1): ini = hex(int(ini, 16)) #+xox-16#) if (len(ini) == 5): ini = ini.replace("0x", "0").upper() if (len(ini) == 4): ini = ini.replace("0x", "00").upper() if (len(ini) == 3): ini = ini.replace("0x", "000").upper() if (len(ini) == 2): ini = ini.replace("0x", "0000").upper() if (len(ini) == 6): ini = ini.replace("0x", "").upper() xxx = hex(xox).replace("x", "") a[lns] = a[lns] + xxx + ini + "00" for j in range(2 * xox): a[lns] = a[lns] + CO[k] k = k + 1 a.append(":00000001FF") #print(a) print("\n") for i in range(len(a) - 1): aux = "" for j in range(len(a[i]) - 1): aux = aux + a[i][j + 1] a[i] = a[i] + checksum(aux) print(a) f = open("HEX.hex", "w") for i in (range(len(a))): f.write(a[i]) f.write("\n") f = f.close
def vote_post(post_id, rating, cookies): c = checksum(str(post_id) + cookies['w3t_w3t_myid']) rating_request = requests.get(forum_url + rate_post_url % (post_id, rating, c), cookies=cookies) rating_request.connection.close() return int(rating_request.content)