Advertisement
Guest User

cpkunf.py

a guest
Sep 16th, 2017
2,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. # cpkunf.py - PES2018 CPK unfucker by f4r - 17/9/17 - v0.1
  2. # Some CPKs in PES2018 have the header about halfway though the file, like they have been cut in half and swapped.
  3. # I call thses "fucked" cpks. This is a quick-and-dirty un-fucker so you can browse and edit them again.
  4. # Unfucked CPKs are written as .unf.cpk.
  5. # Thanks to Tomato and Shakes.
  6. # This has only been tested on python2.
  7. import mmap
  8. import sys
  9.  
  10. infile = sys.argv[1]
  11. outfilen = infile[:-4] + ".unf.cpk"
  12.  
  13. with open(infile, "r+b") as f:
  14.     mm = mmap.mmap(f.fileno(), 0)
  15.     loc = mm.find('\x43\x50\x4b\x20\x00\x00\x00\x00')
  16.     if loc == 0:
  17.         print "CPK header found at offset 0, this isn't a fucked CPK. Exiting..."
  18.         sys.exit(0)
  19.     elif loc == -1:
  20.         print "No valid CPK header found. Exiting..."
  21.         sys.exit(0)
  22.    
  23.     print "CPK header found at offset", format(loc, '#04x') + ", unfucking.",
  24.     outfile = open(outfilen, "wb")
  25.     f.seek(loc)
  26.     outfile.write(f.read())
  27.     print ".",
  28.     f.seek(0)
  29.     outfile.write(f.read(loc))
  30.     print ".",
  31.     outfile.close()
  32.  
  33. print " done."
  34. sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement