Browse Source

Remove EFFS presence flag

Nicola Corna 7 years ago
parent
commit
b31012373c
2 changed files with 13 additions and 4 deletions
  1. 1 0
      README.md
  2. 12 4
      me_cleaner.py

+ 1 - 0
README.md

@@ -10,6 +10,7 @@ Currently this tool:
  * Scans the FPT (partition table) and checks that everything is correct
  * Removes any partition entry (except for FTPR) from FPT
  * Removes any partition except for the fundamental one (FTPR)
+ * Removes the EFFS presence flag
  * Corrects the FPT checksum
 
 Current status:

+ 12 - 4
me_cleaner.py

@@ -71,20 +71,28 @@ else:
                 f.write(ftpr_header)
                 f.seek(0x14, 0)
                 f.write(pack("<I", 1))
-                f.seek(0x00, 0)
-                checksum_bytes = f.read(0x30)
-                f.seek(0x1b, 0)
+
+                print("Removing EFFS presence flag...")
+                f.seek(0x24, 0)
+                flags = unpack("<I", f.read(4))[0]
+                flags &= ~(0x00000001)
+                f.seek(0x24, 0)
+                f.write(pack("<I", flags))
 
                 print("Correcting checksum...")
                 # The checksum is just the two's complement of the sum of the
                 # first 0x30 bytes (except for 0x1b, the checksum itself). In
                 # other words, the sum of the first 0x30 bytes must be always
                 # 0x00.
+                f.seek(0x00, 0)
+                checksum_bytes = f.read(0x30)
+                f.seek(0x1b, 0)
                 f.write(pack("B", (0x100 -
                              (sum(checksum_bytes) - checksum_bytes[0x1b]) &
                              0xff) & 0xff))
 
-                print("All done! Good luck!")
+                print("Done! The ME code ends at {0} (0x{0:0x}). Good luck!"
+                      .format(ftpr_offset + ftpr_lenght))
 
             else:
                 print("FTPR header not found, this image doesn't seem to be "