com.dd.plist.PropertyListParser Java Examples

The following examples show how to use com.dd.plist.PropertyListParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplicationIdentifierNotInInfoPlistForWatchOSApps() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  Path infoPlistPath = testdataDir.resolve("Info_WatchOS.plist");
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          infoPlistPath,
          ApplePlatform.IPHONEOS,
          Optional.empty(),
          Optional.empty(),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  byte[] infoPlistContents = projectFilesystem.getFileBytes(infoPlistPath);
  NSDictionary infoPlist = (NSDictionary) PropertyListParser.parse(infoPlistContents);
  assertNull(infoPlist.get("ApplicationIdentifier"));
}
 
Example #2
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplicationIdentifierNotInInfoPlistForFrameworks() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  Path infoPlistPath = testdataDir.resolve("Info_Framework.plist");
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          infoPlistPath,
          ApplePlatform.IPHONEOS,
          Optional.empty(),
          Optional.empty(),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  byte[] infoPlistContents = projectFilesystem.getFileBytes(infoPlistPath);
  NSDictionary infoPlist = (NSDictionary) PropertyListParser.parse(infoPlistContents);
  assertNull(infoPlist.get("ApplicationIdentifier"));
}
 
Example #3
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplicationIdentifierIsInInfoPlist() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  Path infoPlistPath = testdataDir.resolve("Info.plist");
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          infoPlistPath,
          ApplePlatform.IPHONEOS,
          Optional.empty(),
          Optional.empty(),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  byte[] infoPlistContents = projectFilesystem.getFileBytes(infoPlistPath);
  NSDictionary infoPlist = (NSDictionary) PropertyListParser.parse(infoPlistContents);
  assertEquals(
      infoPlist.get("ApplicationIdentifier"), new NSString("ABCDE12345.com.example.TestApp"));
}
 
Example #4
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplicationIdentifierIsValid() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          testdataDir.resolve("Info.plist"),
          ApplePlatform.IPHONEOS,
          Optional.of("00000000-0000-0000-0000-000000000000"),
          Optional.of(entitlementsFile),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  Optional<String> xcentContents = projectFilesystem.readFileIfItExists(xcentFile);
  assertTrue(xcentContents.isPresent());
  NSDictionary xcentPlist =
      (NSDictionary) PropertyListParser.parse(xcentContents.get().getBytes());
  assertEquals(
      xcentPlist.get("application-identifier"), new NSString("ABCDE12345.com.example.TestApp"));
}
 
Example #5
Source File: AirPlayAuth.java    From AirPlayAuth with MIT License 6 votes vote down vote up
private PairSetupPin1Response doPairSetupPin1(Socket socket) throws Exception {
    byte[] pairSetupPinRequestData = AuthUtils.createPList(new HashMap<String, String>() {{
        put("method", "pin");
        put("user", clientId);
    }});

    byte[] pairSetupPin1ResponseBytes = AuthUtils.postData(socket, "/pair-setup-pin", "application/x-apple-binary-plist", pairSetupPinRequestData);

    NSDictionary pairSetupPin1Response = (NSDictionary) PropertyListParser.parse(pairSetupPin1ResponseBytes);
    if (pairSetupPin1Response.containsKey("pk") && pairSetupPin1Response.containsKey("salt")) {
        byte[] pk = ((NSData) pairSetupPin1Response.get("pk")).bytes();
        byte[] salt = ((NSData) pairSetupPin1Response.get("salt")).bytes();
        return new PairSetupPin1Response(pk, salt);
    }
    throw new Exception();
}
 
Example #6
Source File: PropertyListResponseHandler.java    From InflatableDonkey with MIT License 6 votes vote down vote up
@Override
public T handleEntity(HttpEntity entity) throws IOException {
    NSObject nsObject;

    try {
        // Avoiding PropertyListParser#parse(InputStream) as the current Maven build (1.16) can bug out.
        nsObject = PropertyListParser.parse(EntityUtils.toByteArray(entity));

    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException ex) {
        throw new BadDataException("failed to parse property list", ex);
    }

    if (to.isAssignableFrom(nsObject.getClass())) {
        return to.cast(nsObject);
    }

    throw new BadDataException("failed to cast property list: " + nsObject.getClass());
}
 
Example #7
Source File: InflatableData.java    From InflatableDonkey with MIT License 6 votes vote down vote up
public static Optional<InflatableData> from(byte[] bs) {
    InflatableData data;
    try {
        NSDictionary parse = (NSDictionary) PropertyListParser.parse(bs);
        byte[] escrowedKeys = ((NSData) parse.get("escrowedKeys")).bytes();
        UUID deviceUuid = UUID.fromString(((NSString) parse.get("deviceUuid")).getContent());
        String deviceHardWareId = ((NSString) parse.get("deviceHardWareId")).getContent();
        data = new InflatableData(escrowedKeys, deviceUuid, deviceHardWareId);

    } catch (ClassCastException | IllegalArgumentException | IOException | NullPointerException
            | PropertyListFormatException | ParseException | ParserConfigurationException | SAXException ex) {
        logger.warn("-- from() - exception: ", ex);
        data = null;
    }
    return Optional.ofNullable(data);
}
 
Example #8
Source File: WorkspaceGeneratorTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void workspaceEnabledForLegacyBuildSystem() throws Exception {
  AppleConfig appleConfig =
      FakeBuckConfig.builder()
          .setSections("[apple]", "use_modern_build_system = false")
          .build()
          .getView(AppleConfig.class);

  WorkspaceGenerator generator =
      new WorkspaceGenerator(projectFilesystem, "ws", Paths.get("."), appleConfig);

  Path workspacePath = generator.writeWorkspace();
  Optional<String> settings =
      projectFilesystem.readFileIfItExists(
          workspacePath.resolve("xcshareddata/WorkspaceSettings.xcsettings"));
  assertThat(settings.isPresent(), equalTo(true));
  NSObject object = PropertyListParser.parse(settings.get().getBytes(Charsets.UTF_8));
  assertThat(object, instanceOf(NSDictionary.class));
  NSObject buildSystemType = ((NSDictionary) object).get("BuildSystemType");
  assertThat(buildSystemType, instanceOf(NSString.class));
  assertThat(buildSystemType, equalTo(new NSString("Original")));
}
 
Example #9
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoesNotFailInDryRunMode() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  Path emptyDir =
      TestDataHelper.getTestDataDirectory(this).resolve("provisioning_profiles_empty");

  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          testdataDir.resolve("Info.plist"),
          ApplePlatform.IPHONEOS,
          Optional.empty(),
          Optional.empty(),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, emptyDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.of(dryRunResultFile));

  Future<Optional<ProvisioningProfileMetadata>> profileFuture =
      step.getSelectedProvisioningProfileFuture();
  step.execute(executionContext);
  assertTrue(profileFuture.isDone());
  assertNotNull(profileFuture.get());
  assertFalse(profileFuture.get().isPresent());

  Optional<String> resultContents = projectFilesystem.readFileIfItExists(dryRunResultFile);
  assertTrue(resultContents.isPresent());
  NSDictionary resultPlist =
      (NSDictionary) PropertyListParser.parse(resultContents.get().getBytes(Charsets.UTF_8));

  assertEquals(new NSString("com.example.TestApp"), resultPlist.get("bundle-id"));
}
 
Example #10
Source File: PropertyLists.java    From LiquidDonkey with MIT License 5 votes vote down vote up
static <T> T parse(byte[] data) throws BadDataException {
    try {
        return (T) PropertyListParser.parse(data);

    } catch (ClassCastException |
            IOException |
            PropertyListFormatException |
            ParseException |
            ParserConfigurationException |
            SAXException ex) {

        throw new BadDataException("Failed to parse property list", ex);
    }
}
 
Example #11
Source File: IPAModifyPlist.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void readPlist() {
	try {
		File file = new File(this.plistFile);
		this.rootDict = ((NSDictionary) PropertyListParser.parse(file));
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #12
Source File: IPAModifyPlist.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void savePlistFile() {
	File plist = new File(this.plistFile);
	try {
		PropertyListParser.saveAsXML(this.rootDict, plist);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example #13
Source File: WorkspaceGeneratorTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void workspaceDisablesSchemeAutoCreation() throws Exception {
  Path workspacePath = generator.writeWorkspace();
  Optional<String> settings =
      projectFilesystem.readFileIfItExists(
          workspacePath.resolve("xcshareddata/WorkspaceSettings.xcsettings"));
  assertThat(settings.isPresent(), equalTo(true));
  NSObject object = PropertyListParser.parse(settings.get().getBytes(Charsets.UTF_8));
  assertThat(object, instanceOf(NSDictionary.class));
  NSObject autocreate =
      ((NSDictionary) object).get("IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
  assertThat(autocreate, instanceOf(NSNumber.class));
  assertThat(autocreate, equalTo(new NSNumber(false)));
}
 
Example #14
Source File: WorkspaceGeneratorTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void workspaceDisablesSchemeAutoCreation() throws Exception {
  Path workspacePath = generator.writeWorkspace();
  Optional<String> settings =
      projectFilesystem.readFileIfItExists(
          workspacePath.resolve("xcshareddata/WorkspaceSettings.xcsettings"));
  assertThat(settings.isPresent(), equalTo(true));
  NSObject object = PropertyListParser.parse(settings.get().getBytes(Charsets.UTF_8));
  assertThat(object, instanceOf(NSDictionary.class));
  NSObject autocreate =
      ((NSDictionary) object).get("IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
  assertThat(autocreate, instanceOf(NSNumber.class));
  assertThat(autocreate, equalTo(new NSNumber(false)));
}
 
Example #15
Source File: AppleBundleIntegrationTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void infoPlistSubstitutionsAreApplied() throws Exception {
  ProjectWorkspace workspace =
      TestDataHelper.createProjectWorkspaceForScenario(
          this, "application_bundle_with_substitutions", tmp);
  workspace.setUp();

  BuildTarget target = workspace.newBuildTarget("//:DemoApp#iphonesimulator-x86_64,no-debug");
  workspace.runBuckCommand("build", target.getFullyQualifiedName()).assertSuccess();

  workspace.verify(
      Paths.get("DemoApp_output.expected"),
      BuildTargetPaths.getGenPath(
          filesystem,
          target.withAppendedFlavors(AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR),
          "%s"));

  Path appPath =
      BuildTargetPaths.getGenPath(
              filesystem,
              target.withAppendedFlavors(AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR),
              "%s")
          .resolve(target.getShortName() + ".app");
  assertTrue(Files.exists(workspace.getPath(appPath.resolve(target.getShortName()))));

  NSDictionary plist =
      (NSDictionary)
          PropertyListParser.parse(
              Files.readAllBytes(workspace.getPath(appPath.resolve("Info.plist"))));
  assertThat(
      "Should contain xcode build version",
      (String) plist.get("DTXcodeBuild").toJavaObject(),
      not(emptyString()));
}
 
Example #16
Source File: NSDictionaries.java    From InflatableDonkey with MIT License 5 votes vote down vote up
static Optional<NSObject> parseNSObject(byte[] data) {
    try {
        NSObject nsObject = PropertyListParser.parse(data);
        return Optional.of(nsObject);

    } catch (IOException | PropertyListFormatException | ParseException | ParserConfigurationException |
            SAXException ex) {
        logger.warn("-- parseNSObject() - failed to parse data: {} 0x{}", ex.getMessage(), Hex.toHexString(data));
        return Optional.empty();
    }
}
 
Example #17
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoEntitlementsDoesNotMergeInvalidProfileKeys() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          testdataDir.resolve("Info.plist"),
          ApplePlatform.IPHONEOS,
          Optional.of("00000000-0000-0000-0000-000000000000"),
          Optional.empty(),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  ProvisioningProfileMetadata selectedProfile =
      step.getSelectedProvisioningProfileFuture().get().get();
  ImmutableMap<String, NSObject> profileEntitlements = selectedProfile.getEntitlements();
  assertTrue(
      profileEntitlements.containsKey(
          "com.apple.developer.icloud-container-development-container-identifiers"));

  Optional<String> xcentContents = projectFilesystem.readFileIfItExists(xcentFile);
  assertTrue(xcentContents.isPresent());
  NSDictionary xcentPlist =
      (NSDictionary) PropertyListParser.parse(xcentContents.get().getBytes());
  assertFalse(
      xcentPlist.containsKey(
          "com.apple.developer.icloud-container-development-container-identifiers"));
  assertEquals(
      xcentPlist.get("com.apple.developer.team-identifier"),
      profileEntitlements.get("com.apple.developer.team-identifier"));
}
 
Example #18
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntitlementsDoesNotMergeInvalidProfileKeys() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          testdataDir.resolve("Info.plist"),
          ApplePlatform.IPHONEOS,
          Optional.of("00000000-0000-0000-0000-000000000000"),
          Optional.of(entitlementsFile),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  ProvisioningProfileMetadata selectedProfile =
      step.getSelectedProvisioningProfileFuture().get().get();
  ImmutableMap<String, NSObject> profileEntitlements = selectedProfile.getEntitlements();
  assertTrue(
      profileEntitlements.containsKey(
          "com.apple.developer.icloud-container-development-container-identifiers"));

  Optional<String> xcentContents = projectFilesystem.readFileIfItExists(xcentFile);
  assertTrue(xcentContents.isPresent());
  NSDictionary xcentPlist =
      (NSDictionary) PropertyListParser.parse(xcentContents.get().getBytes());
  assertFalse(
      xcentPlist.containsKey(
          "com.apple.developer.icloud-container-development-container-identifiers"));
  assertEquals(
      xcentPlist.get("com.apple.developer.team-identifier"),
      profileEntitlements.get("com.apple.developer.team-identifier"));
}
 
Example #19
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntitlementsMergesValidProfileKeys() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          testdataDir.resolve("Info.plist"),
          ApplePlatform.IPHONEOS,
          Optional.of("00000000-0000-0000-0000-000000000000"),
          Optional.of(entitlementsFile),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  ProvisioningProfileMetadata selectedProfile =
      step.getSelectedProvisioningProfileFuture().get().get();
  ImmutableMap<String, NSObject> profileEntitlements = selectedProfile.getEntitlements();
  assertTrue(profileEntitlements.containsKey("get-task-allow"));

  Optional<String> entitlementsContents = projectFilesystem.readFileIfItExists(entitlementsFile);
  assertTrue(entitlementsContents.isPresent());
  NSDictionary entitlementsPlist =
      (NSDictionary) PropertyListParser.parse(entitlementsContents.get().getBytes());
  assertFalse(entitlementsPlist.containsKey("get-task-allow"));

  Optional<String> xcentContents = projectFilesystem.readFileIfItExists(xcentFile);
  assertTrue(xcentContents.isPresent());
  NSDictionary xcentPlist =
      (NSDictionary) PropertyListParser.parse(xcentContents.get().getBytes());
  assertTrue(xcentPlist.containsKey("get-task-allow"));
}
 
Example #20
Source File: DdPlistTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testXMLWriting() throws Exception {
  InputStream in = getClass().getResourceAsStream("test-files/test1.plist");
  NSDictionary x = (NSDictionary) PropertyListParser.parse(in);
  PropertyListParser.saveAsXML(x, outputFile);
  NSDictionary y = (NSDictionary) PropertyListParser.parse(outputFile);
  assertEquals(x, y);
}
 
Example #21
Source File: AuthUtils.java    From AirPlayAuth with MIT License 5 votes vote down vote up
static byte[] createPList(Map<String, ? extends Object> properties) throws IOException {
    ByteArrayOutputStream plistOutputStream = new ByteArrayOutputStream();
    NSDictionary root = new NSDictionary();
    for (Map.Entry<String, ? extends Object> property : properties.entrySet()) {
        root.put(property.getKey(), property.getValue());
    }
    PropertyListParser.saveAsBinary(root, plistOutputStream);
    return plistOutputStream.toByteArray();
}
 
Example #22
Source File: IpaLoader.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private static String parseVersion(File ipa, String appDir) throws IOException {
    try {
        byte[] data = loadZip(ipa, appDir + "Info.plist");
        if (data == null) {
            throw new IllegalStateException("Find Info.plist failed");
        }
        NSDictionary info = (NSDictionary) PropertyListParser.parse(data);
        NSString bundleVersion = (NSString) info.get("CFBundleVersion");
        return bundleVersion.getContent();
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        throw new IllegalStateException("load ipa failed", e);
    }
}
 
Example #23
Source File: IpaLoader.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private static String parseCFBundleIdentifier(File ipa, String appDir) throws IOException {
    try {
        byte[] data = loadZip(ipa, appDir + "Info.plist");
        if (data == null) {
            throw new IllegalStateException("Find Info.plist failed");
        }
        NSDictionary info = (NSDictionary) PropertyListParser.parse(data);
        NSString bundleIdentifier = (NSString) info.get("CFBundleIdentifier");
        return bundleIdentifier.getContent();
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        throw new IllegalStateException("load ipa failed", e);
    }
}
 
Example #24
Source File: NSUserDefaultsResolver.java    From unidbg with Apache License 2.0 5 votes vote down vote up
@Override
public FileResult<DarwinFileIO> resolve(Emulator<DarwinFileIO> emulator, String pathname, int oflags) {
    if (pathname.endsWith(("/Library/Preferences/" + bundleIdentifier + ".plist"))) {
        NSDictionary root = (NSDictionary) NSDictionary.fromJavaObject(map);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            PropertyListParser.saveAsBinary(root, outputStream);
        } catch (IOException e) {
            throw new IllegalStateException("save plist failed", e);
        }
        return FileResult.<DarwinFileIO>success(new ByteArrayFileIO(oflags, pathname, outputStream.toByteArray()));
    }
    return null;
}
 
Example #25
Source File: DarwinResolver.java    From unidbg with Apache License 2.0 5 votes vote down vote up
@Override
public FileResult<DarwinFileIO> resolve(Emulator<DarwinFileIO> emulator, String path, int oflags) {
    if ("".equals(path)) {
        return FileResult.failed(UnixEmulator.ENOENT);
    }

    FileSystem<DarwinFileIO> fileSystem = emulator.getFileSystem();
    if (".".equals(path)) {
        return FileResult.success(createFileIO(fileSystem.createWorkDir(), path, oflags));
    }

    if (path.endsWith("/Library/Preferences/.GlobalPreferences.plist")) {
        if (_GlobalPreferences == null) {
            Locale locale = Locale.getDefault();
            Map<String, Object> map = new HashMap<>();
            map.put("AppleICUForce24HourTime", true);
            map.put("AppleLanguages", new String[] { locale.getLanguage() });
            map.put("AppleLocale", locale.toString());
            NSDictionary root = (NSDictionary) NSDictionary.fromJavaObject(map);
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            try {
                PropertyListParser.saveAsBinary(root, outputStream);
            } catch (IOException e) {
                throw new IllegalStateException("save .GlobalPreferences.plist failed", e);
            }
            _GlobalPreferences = outputStream.toByteArray();
        }
        return FileResult.<DarwinFileIO>success(new ByteArrayFileIO(oflags, path, _GlobalPreferences));
    }

    String iosResource = FilenameUtils.normalize("/ios/" + version + "/" + path, true);
    File file = ResourceUtils.extractResource(DarwinResolver.class, iosResource, path);
    if (file != null) {
        return FileResult.fallback(createFileIO(file, path, oflags));
    }

    return null;
}
 
Example #26
Source File: PListTest.java    From unidbg with Apache License 2.0 5 votes vote down vote up
public void testPList() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("AppleICUForce24HourTime", 1);
    map.put("AppleLanguages", new String[] { "zh-Hans", "en" });
    map.put("AppleLocale", "zh_CN");
    NSDictionary root = (NSDictionary) NSDictionary.fromJavaObject(map);
    PropertyListParser.saveAsBinary(root, new File("target/plist_test.plist"));
}
 
Example #27
Source File: ApplicationInfoService.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
protected NSDictionary getDictionary(File path) {
  try {
    return (NSDictionary) PropertyListParser.parse(path);
  } catch (IOException
      | PropertyListFormatException
      | ParseException
      | ParserConfigurationException
      | SAXException exception) {
    String errorMessage = String.format("Error reading dictionary from %s", path);
    LOG.error(errorMessage, exception);
    throw new MobileToolsException(errorMessage, exception);
  }
}
 
Example #28
Source File: AirPlayAuth.java    From AirPlayAuth with MIT License 5 votes vote down vote up
private PairSetupPin2Response doPairSetupPin2(Socket socket, final byte[] publicClientValueA, final byte[] clientEvidenceMessageM1) throws Exception {
    byte[] pairSetupPinRequestData = AuthUtils.createPList(new HashMap<String, byte[]>() {{
        put("pk", publicClientValueA);
        put("proof", clientEvidenceMessageM1);
    }});

    byte[] pairSetupPin2ResponseBytes = AuthUtils.postData(socket, "/pair-setup-pin", "application/x-apple-binary-plist", pairSetupPinRequestData);

    NSDictionary pairSetupPin2Response = (NSDictionary) PropertyListParser.parse(pairSetupPin2ResponseBytes);
    if (pairSetupPin2Response.containsKey("proof")) {
        byte[] proof = ((NSData) pairSetupPin2Response.get("proof")).bytes();
        return new PairSetupPin2Response(proof);
    }
    throw new Exception();
}
 
Example #29
Source File: AirPlayAuth.java    From AirPlayAuth with MIT License 5 votes vote down vote up
private PairSetupPin3Response doPairSetupPin3(Socket socket, final byte[] sessionKeyHashK) throws Exception {

        MessageDigest sha512Digest = MessageDigest.getInstance("SHA-512");
        sha512Digest.update("Pair-Setup-AES-Key".getBytes(StandardCharsets.UTF_8));
        sha512Digest.update(sessionKeyHashK);
        byte[] aesKey = Arrays.copyOfRange(sha512Digest.digest(), 0, 16);

        sha512Digest.update("Pair-Setup-AES-IV".getBytes(StandardCharsets.UTF_8));
        sha512Digest.update(sessionKeyHashK);
        byte[] aesIV = Arrays.copyOfRange(sha512Digest.digest(), 0, 16);

        int lengthB;
        int lengthA = lengthB = aesIV.length - 1;
        for (; lengthB >= 0 && 256 == ++aesIV[lengthA]; lengthA = lengthB += -1) ;

        Cipher aesGcm128Encrypt = Cipher.getInstance("AES/GCM/NoPadding");
        SecretKeySpec secretKey = new SecretKeySpec(aesKey, "AES");
        aesGcm128Encrypt.init(Cipher.ENCRYPT_MODE, secretKey, new GCMParameterSpec(128, aesIV));
        final byte[] aesGcm128ClientLTPK = aesGcm128Encrypt.doFinal(authKey.getAbyte());

        byte[] pairSetupPinRequestData = AuthUtils.createPList(new HashMap<String, byte[]>() {{
            put("epk", Arrays.copyOfRange(aesGcm128ClientLTPK, 0, aesGcm128ClientLTPK.length - 16));
            put("authTag", Arrays.copyOfRange(aesGcm128ClientLTPK, aesGcm128ClientLTPK.length - 16, aesGcm128ClientLTPK.length));
        }});

        byte[] pairSetupPin3ResponseBytes = AuthUtils.postData(socket, "/pair-setup-pin", "application/x-apple-binary-plist", pairSetupPinRequestData);

        NSDictionary pairSetupPin3Response = (NSDictionary) PropertyListParser.parse(pairSetupPin3ResponseBytes);

        if (pairSetupPin3Response.containsKey("epk") && pairSetupPin3Response.containsKey("authTag")) {
            byte[] epk = ((NSData) pairSetupPin3Response.get("epk")).bytes();
            byte[] authTag = ((NSData) pairSetupPin3Response.get("authTag")).bytes();

            return new PairSetupPin3Response(epk, authTag);
        }
        throw new Exception();
    }
 
Example #30
Source File: IpaLoader.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private static String parseExecutable(File ipa, String appDir) throws IOException {
    try {
        byte[] data = loadZip(ipa, appDir + "Info.plist");
        if (data == null) {
            throw new IllegalStateException("Find Info.plist failed");
        }
        NSDictionary info = (NSDictionary) PropertyListParser.parse(data);
        NSString bundleExecutable = (NSString) info.get("CFBundleExecutable");
        return bundleExecutable.getContent();
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        throw new IllegalStateException("load ipa failed", e);
    }
}