Java Code Examples for com.dd.plist.NSDictionary#fromJavaObject()

The following examples show how to use com.dd.plist.NSDictionary#fromJavaObject() . 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: 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 2
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 3
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"));
}