Skip to content

Instantly share code, notes, and snippets.

@erikng
Forked from pudquick/unsign_plist.py
Created October 1, 2016 19:43
Show Gist options
  • Save erikng/753988edec18fbb43604e37a3ff3ec56 to your computer and use it in GitHub Desktop.
Save erikng/753988edec18fbb43604e37a3ff3ec56 to your computer and use it in GitHub Desktop.
Getting an unsigned plist / mobileconfig from a signed one in python on OS X with pyObjC
import objc
from Foundation import NSBundle
Security_bundle = NSBundle.bundleWithIdentifier_('com.apple.security')
CMSDecoderRef = objc.createOpaquePointerType("CMSDecoderRef", b"^{CMSDecoder}", None)
functions = [('CMSDecoderCreate', b'io^^{CMSDecoder}'),
('CMSDecoderUpdateMessage', b'i^{CMSDecoder}*I'),
('CMSDecoderFinalizeMessage', b'i^{CMSDecoder}',),
('CMSDecoderCopyContent', b'i^{CMSDecoder}o^^{__CFData}')]
objc.loadBundleFunctions(Security_bundle, globals(), functions)
f = open('Example.mobileconfig.signed', 'rb')
signed_plist = f.read()
f.close()
err, decoder = CMSDecoderCreate(None)
err = CMSDecoderUpdateMessage(decoder, signed_plist, len(signed_plist))
err = CMSDecoderFinalizeMessage(decoder)
err, unsigned_data = CMSDecoderCopyContent(decoder, None)
plist_bytes = unsigned_data.bytes().tobytes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment