private void ParseAndExecuteAction(CFDictionaryRef action) { string Action = action.GetValue("Action").ToString(); if (Action == "Add") { string localPath = WinFormPath.Combine(FirmwareBundlePath, action.GetValue("File").ToString()); string remotePath = "/" + action.GetValue("Path").ToString(); bool alreadyExists = Pwn.hfsplus_FileExists(DecryptedRootFS, remotePath); if (alreadyExists) { if (remotePath == "/sbin/launchd") Pwn.hfsplus_mv(DecryptedRootFS, remotePath, "/sbin/crunchd"); else Pwn.hfsplus_mv(DecryptedRootFS, remotePath, remotePath + "_orig"); } Pwn.hfsplus_add(DecryptedRootFS, localPath, remotePath); if (alreadyExists) { if (remotePath != "/sbin/launchd") { Pwn.hfsplus_chown(DecryptedRootFS, remotePath, Pwn.hfsplus_GETowner(DecryptedRootFS, remotePath + "_orig"), Pwn.hfsplus_GETgroup(DecryptedRootFS, remotePath + "_orig")); Pwn.hfsplus_chmod(DecryptedRootFS, remotePath, Pwn.hfsplus_GETchmod(DecryptedRootFS, remotePath + "_orig")); } } } else if (Action == "Patch") { string remotePath = "/" + action.GetValue("File").ToString(); string localPath = WinFormPath.Combine(FIRMWARE_EXTRACT_PATH, WinFormPath.GetFileName(action.GetValue("File").ToString())); string localPathPatched = localPath + ".patched"; string patchPath = WinFormPath.Combine(FirmwareBundlePath, action.GetValue("Patch").ToString()); Pwn.hfsplus_extract(DecryptedRootFS, remotePath, localPath); if (!File.Exists(localPath)) { Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal,new StatusLabelUpdateDelegate(StatusLabelUpdate), "ERROR: Unable to extract " + remotePath + " from Root Filesystem"); return; } Pwn.bspatch(localPath, localPathPatched, patchPath); if (!File.Exists(localPathPatched)) { Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal,new StatusLabelUpdateDelegate(StatusLabelUpdate), "ERROR: Unable to patch " + WinFormPath.GetFileName(localPath)); return; } Pwn.hfsplus_mv(DecryptedRootFS, remotePath, remotePath + "_orig"); Pwn.hfsplus_add(DecryptedRootFS, localPathPatched, remotePath); Pwn.hfsplus_chown(DecryptedRootFS, remotePath, Pwn.hfsplus_GETowner(DecryptedRootFS, remotePath + "_orig"), Pwn.hfsplus_GETgroup(DecryptedRootFS, remotePath + "_orig")); Pwn.hfsplus_chmod(DecryptedRootFS, remotePath, Pwn.hfsplus_GETchmod(DecryptedRootFS, remotePath + "_orig")); File.Delete(localPath); File.Delete(localPathPatched); } else if (Action == "SetPermission") { string remoteFile = "/" + action.GetValue("File").ToString(); string permission = action.GetValue("Permission").ToString(); Pwn.hfsplus_chmod(DecryptedRootFS, remoteFile, permission.Length == 3 ? "100" + permission : permission); } else if (Action == "SetOwner") { string remoteFile = "/" + action.GetValue("File").ToString(); string owner = action.GetValue("Owner").ToString(); Pwn.hfsplus_chown(DecryptedRootFS, remoteFile, owner.Split(':')[0], owner.Split(':')[1]); } else if (Action == "ReplaceKernel") { string remotePath = "/" + action.GetValue("Path").ToString(); string localPath = WinFormPath.Combine(FIRMWARE_EXTRACT_PATH, WinFormPath.GetFileName(action.GetValue("File").ToString())); Pwn.hfsplus_mv(DecryptedRootFS, remotePath, remotePath + "_orig"); Pwn.hfsplus_add(DecryptedRootFS, localPath, remotePath); Pwn.hfsplus_chown(DecryptedRootFS, remotePath, Pwn.hfsplus_GETowner(DecryptedRootFS, remotePath + "_orig"), Pwn.hfsplus_GETgroup(DecryptedRootFS, remotePath + "_orig")); Pwn.hfsplus_chmod(DecryptedRootFS, remotePath, Pwn.hfsplus_GETchmod(DecryptedRootFS, remotePath + "_orig")); } if (action.ContainsKey("MoreActions")) { foreach (CFDictionaryRef moreAction in ((CFArrayRef)action.GetValue("MoreActions")).Values) ParseAndExecuteAction(moreAction); } }
private bool IsFirmwareBundleValid(string bundlePath) { if (!WinFormFile.Exists(bundlePath)) { Dispatcher.Invoke(DispatcherPriority.Normal,new StatusLabelUpdateDelegate(StatusLabelUpdate), "ERROR: Bundle " + WinFormPath.GetFileName(bundlePath) + " is invalid !"); return false; } FirmwareBundleInfoNode = (CFDictionaryRef)CFPropertyListRef.CreateWithData(new CFDataRef(WinFormFile.ReadAllBytes(bundlePath)), CFPropertyListMutabilityOptions.kCFPropertyListImmutable); if (FirmwareBundleInfoNode.GetValue("SHA1").ToString() == FirmwareSHA1) { FirmwareBundlePath = bundlePath.Remove(bundlePath.Length - "\\Info.plist".Length); return true; } return false; }