freemyipod r108 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r107‎ | r108 | r109 >
Date:12:09, 12 August 2010
Author:theseven
Status:new
Tags:
Comment:
Fix some more bugs in libembios.py, it's still not working though
Modified paths:
  • /embios/trunk/tools/libembios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/libembios.py
@@ -498,7 +498,7 @@
499499 response = self.__getbulk(self.handle, self.__cinep, blocklen + 0x10)
500500 self.__checkstatus(response)
501501
502 - readbytes, buffersize, bytesleft = struct.unpack("<III", response[4:16])
 502+ readbytes, buffersize, bytesleft = struct.unpack("<III", response[4:])
503503 out_data += response[0x10:0x10+readbytes]
504504 size -= blocklen
505505
@@ -565,7 +565,7 @@
566566 response = self.__getbulk(self.handle, self.__cinep, 0x10)
567567 self.__checkstatus(response)
568568
569 - sendbytes = struct.unpack("<I", response[4:8])[0]
 569+ sendbytes = struct.unpack("<I", response[4:])[0]
570570 if sendbytes < blocklen: # not everything has been written, need to resent some stuff but wait a bit before doing so
571571 time.sleep(0.1)
572572 timeoutcounter += 1
@@ -617,7 +617,7 @@
618618 response = self.__getbulk(self.handle, self.__cinep, blocklen + 0x10)
619619 self.__checkstatus(response)
620620
621 - readbytes = struct.unpack("<III", response[4:8])[0]
 621+ readbytes = struct.unpack("<III", response[4:])[0]
622622 out_data += response[0x10:0x10+readbytes]
623623 size -= blocklen
624624
@@ -764,45 +764,45 @@
765765
766766 def procinfotolist(processinfo, structver):
767767 if (structver == 1): # Process information struct version == 1
768 - ptr = 0x10
 768+ ptr = 0
769769 process_n = 0
770770 retval = []
771771 while ptr < len(processinfo):
772772 retval.append({})
773773
774 - retval[process_n]['regs'] = struct.unpack("<IIIIIIIIIIIIIIII", processinfo[ptr:ptr+64])
 774+ retval[process_n]['regs'] = struct.unpack("<IIIIIIIIIIIIIIII", processinfo[ptr:ptr + 64])
775775 ptr += 16 * 0x4
776 - retval[process_n]['cpsr'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 776+ retval[process_n]['cpsr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
777777 ptr += 1 * 0x4
778 - retval[process_n]['state'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 778+ retval[process_n]['state'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
779779 ptr += 1 * 0x4
780 - retval[process_n]['name_ptr'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 780+ retval[process_n]['name_ptr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
781781 ptr += 1 * 0x4
782 - retval[process_n]['cputime_current'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 782+ retval[process_n]['cputime_current'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
783783 ptr += 1 * 0x4
784 - retval[process_n]['cputime_total'] = struct.unpack("<Q", processinfo[ptr:ptr+8])[0]
 784+ retval[process_n]['cputime_total'] = struct.unpack("<Q", processinfo[ptr:ptr + 8])[0]
785785 ptr += 1 * 0x8
786 - retval[process_n]['startusec'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 786+ retval[process_n]['startusec'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
787787 ptr += 1 * 0x4
788 - retval[process_n]['queue_next_ptr'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 788+ retval[process_n]['queue_next_ptr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
789789 ptr += 1 * 0x4
790 - retval[process_n]['timeout'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 790+ retval[process_n]['timeout'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
791791 ptr += 1 * 0x4
792 - retval[process_n]['blocked_since'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 792+ retval[process_n]['blocked_since'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
793793 ptr += 1 * 0x4
794 - retval[process_n]['blocked_by_ptr'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 794+ retval[process_n]['blocked_by_ptr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
795795 ptr += 1 * 0x4
796 - retval[process_n]['stack_ptr'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 796+ retval[process_n]['stack_ptr'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
797797 ptr += 1 * 0x4
798 - retval[process_n]['err_no'] = struct.unpack("<I", processinfo[ptr:ptr+4])[0]
 798+ retval[process_n]['err_no'] = struct.unpack("<I", processinfo[ptr:ptr + 4])[0]
799799 ptr += 1 * 0x4
800 - retval[process_n]['block_type'] = struct.unpack("<B", processinfo[ptr:ptr+1])[0]
 800+ retval[process_n]['block_type'] = struct.unpack("<B", processinfo[ptr:ptr + 1])[0]
801801 ptr += 1 * 0x1
802 - retval[process_n]['thread_type'] = struct.unpack("<B", processinfo[ptr:ptr+1])[0]
 802+ retval[process_n]['thread_type'] = struct.unpack("<B", processinfo[ptr:ptr + 1])[0]
803803 ptr += 1 * 0x1
804 - retval[process_n]['priority'] = struct.unpack("<B", processinfo[ptr:ptr+1])[0]
 804+ retval[process_n]['priority'] = struct.unpack("<B", processinfo[ptr:ptr + 1])[0]
805805 ptr += 1 * 0x1
806 - retval[process_n]['cpuload'] = struct.unpack("<B", processinfo[ptr:ptr+1])[0]
 806+ retval[process_n]['cpuload'] = struct.unpack("<B", processinfo[ptr:ptr + 1])[0]
807807 ptr += 1 * 0x1
808808
809809 process_n += 1
@@ -818,12 +818,12 @@
819819 processinfoprint += "R0: 0x%08x, R1: 0x%08x, R2: 0x%08x, R3: 0x%08x,\n\
820820 R4: 0x%08x, R5: 0x%08x, R6: 0x%08x, R7: 0x%08x,\n\
821821 R8: 0x%08x, R9: 0x%08x, R10: 0x%08x, R11: 0x%08x,\n\
822 - R12: 0x%08x, R13: 0x%08x, LR: 0x%08x, PC: 0x%08x\n" \
 822+ R12: 0x%08x, SP: 0x%08x, LR: 0x%08x, PC: 0x%08x\n" \
823823 % (procinfolist[ptr]['regs'][0], procinfolist[ptr]['regs'][1], procinfolist[ptr]['regs'][2], procinfolist[ptr]['regs'][3], \
824824 procinfolist[ptr]['regs'][4], procinfolist[ptr]['regs'][5], procinfolist[ptr]['regs'][6], procinfolist[ptr]['regs'][7], \
825825 procinfolist[ptr]['regs'][8], procinfolist[ptr]['regs'][9], procinfolist[ptr]['regs'][10], procinfolist[ptr]['regs'][11], \
826826 procinfolist[ptr]['regs'][12], procinfolist[ptr]['regs'][13], procinfolist[ptr]['regs'][14], procinfolist[ptr]['regs'][15] )
827 - processinfoprint += "cpsr: 0b%032b " % (procinfolist[ptr]['cpsr'])
 827+ processinfoprint += "cpsr: 0x%08x " % (procinfolist[ptr]['cpsr'])
828828 states = ("THREAD_FREE", "THREAD_SUSPENDED", "THREAD_READY", "THREAD_RUNNING", "THREAD_BLOCKED", "THREAD_DEFUNCT", "THREAD_DEFUNCT_ACK")
829829 processinfoprint += "state: %s " % (states[procinfolist[ptr]['state']])
830830 processinfoprint += "nameptr: 0x%08x\n" % (procinfolist[ptr]['name_ptr'])
@@ -853,33 +853,28 @@
854854 self.__myprint("Retrieving process information...", silent)
855855
856856 offset = 0
857 - blocklen = size = self.cin_maxsize - 0x10
 857+ blocklen = tablesize = self.cin_maxsize - 0x10
858858 procinfo = ""
859859 structversion = 0
860 - tablesize = 0
861860
862861 # reading loop
863 - while (offset < size):
 862+ while (offset < tablesize):
864863 self.handle.bulkWrite(self.__coutep, struct.pack("<IIII", 15, offset, blocklen, 0))
865864 response = self.__getbulk(self.handle, self.__cinep, blocklen + 0x10)
866865 self.__checkstatus(response)
867866
868 - size = struct.unpack("<I", response[8:12])[0]
 867+ tablesize = struct.unpack("<I", response[8:12])[0]
 868+ procinfo += response[0x10:0x10 + blocklen]
869869
870 - if size <= offset + blocklen:
871 - procinfo += response[0x10:0x10 + size]
 870+ if tablesize <= offset + blocklen:
872871 structversion = struct.unpack("<I", response[4:8])[0]
873872 tablesize = struct.unpack("<I", response[8:12])[0]
874 - break
875 - else:
876 - procinfo += response[0x10:0x10 + blocklen]
877873
878 - size -= blocklen
879874 offset += blocklen
880875
881876 blocklen = self.cin_maxsize - 0x10
882 - if blocklen > size:
883 - blocklen = size
 877+ if blocklen > tablesize - offset:
 878+ blocklen = tablesize - offset
884879
885880
886881 out = (structversion, tablesize, procinfotolist(procinfo, structversion))