freemyipod r237 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r236‎ | r237 | r238 >
Date:01:09, 31 October 2010
Author:farthen
Status:new
Tags:
Comment:
embios.py: run: check if the app baseaddress is within the user memory range otherwise refuse to run the app.
Modified paths:
  • /embios/trunk/tools/embios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/embios.py
@@ -566,7 +566,7 @@
567567 appheader = struct.unpack("<8sIIIIIIIIII", f.read(48))
568568 header = appheader[0]
569569 if header != "emBIexec":
570 - raise ArgumentError("The specified file is not an emBIOS application")
 570+ raise ArgumentError("The specified file is not an emBIOS application (header)")
571571 baseaddr = appheader[2]
572572 threadnameptr = appheader[8]
573573 f.seek(threadnameptr - baseaddr)
@@ -576,13 +576,16 @@
577577 if ord(char) == 0:
578578 break
579579 name += char
 580+ usermem = self.embios.getusermemrange()
 581+ if usermem.lower > baseaddr or usermem.upper < baseaddr + os.stat(filename).st_size:
 582+ raise ArgumentError("The baseaddress of the specified emBIOS application is out of range of the user memory range on the device. Are you sure that this application is compatible with your device?")
580583 self.logger.info("Writing emBIOS application \"" + name + "\" to the memory at " + self._hex(baseaddr) + "...")
581584 f.seek(0)
582585 self.embios.write(baseaddr, f.read())
583586 except IOError:
584 - raise ArgumentError("The specified file is not an emBIOS application")
 587+ raise ArgumentError("The specified file is not an emBIOS application (IOError)")
585588 except struct.error:
586 - raise ArgumentError("The specified file is not an emBIOS application")
 589+ raise ArgumentError("The specified file is not an emBIOS application (struct.error)")
587590 finally:
588591 f.close()
589592 self.logger.info("done\n")