net.dongliu.apk.parser.ApkFile Java Examples

The following examples show how to use net.dongliu.apk.parser.ApkFile. 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: BaseVM.java    From unidbg with Apache License 2.0 5 votes vote down vote up
@Override
public LibraryFile resolveLibrary(Emulator<?> emulator, String soName) throws IOException {
    try (ApkFile apkFile = new ApkFile(this.apkFile)) {
        byte[] libData = findLibrary(apkFile, soName);
        return libData == null ? null : new ApkLibraryFile(this.apkFile, soName, libData, packageName);
    }
}
 
Example #2
Source File: BaseVM.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private ApkLibraryFile findLibrary(File file, String soName) {
    try (ApkFile apkFile = new ApkFile(file)) {
        byte[] libData = findLibrary(apkFile, soName);
        if (libData == null) {
            return null;
        }

        return new ApkLibraryFile(file, soName, libData, apkFile.getApkMeta().getPackageName());
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #3
Source File: DalvikVM.java    From unidbg with Apache License 2.0 5 votes vote down vote up
byte[] findLibrary(ApkFile apkFile, String soName) throws IOException {
    byte[] soData = apkFile.getFileData("lib/armeabi-v7a/" + soName);
    if (soData != null) {
        log.debug("resolve armeabi-v7a library: " + soName);
        return soData;
    }
    soData = apkFile.getFileData("lib/armeabi/" + soName);
    if (soData != null) {
        log.debug("resolve armeabi library: " + soName);
    }
    return soData;
}
 
Example #4
Source File: DalvikVM64.java    From unidbg with Apache License 2.0 5 votes vote down vote up
byte[] findLibrary(ApkFile apkFile, String soName) throws IOException {
    byte[] soData = apkFile.getFileData("lib/arm64-v8a/" + soName);
    if (soData != null) {
        log.debug("resolve arm64-v8a library: " + soName);
        return soData;
    } else {
        return null;
    }
}
 
Example #5
Source File: Main.java    From ratel with Apache License 2.0 5 votes vote down vote up
private static boolean checkAPKFile(File file) {
    try (ApkFile apkFile = new ApkFile(file)) {
        apkFile.getApkMeta();
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example #6
Source File: App.java    From java-play-store-uploader with MIT License 4 votes vote down vote up
/**
 * Perform apk upload an release on given track
 *
 * @throws Exception Upload error
 */
private void upload() throws Exception {
    // configure proxy
    if (this.proxyHost != null && !this.proxyHost.isEmpty()) {
        System.setProperty("https.proxyHost", this.proxyHost);
    }

    if (this.proxyPort != null && !this.proxyPort.isEmpty()) {
        System.setProperty("https.proxyPort", this.proxyPort);
    }

    // load key file credentials
    System.out.println("Loading account credentials...");
    Path jsonKey = FileSystems.getDefault().getPath(this.jsonKeyPath).normalize();
    GoogleCredential cred = GoogleCredential.fromStream(new FileInputStream(jsonKey.toFile()));
    cred = cred.createScoped(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER));

    // load apk file info
    System.out.println("Loading apk file information...");
    Path apkFile = FileSystems.getDefault().getPath(this.apkPath).normalize();
    ApkFile apkInfo = new ApkFile(apkFile.toFile());
    ApkMeta apkMeta = apkInfo.getApkMeta();
    final String applicationName = this.appName == null ? apkMeta.getName() : this.appName;
    final String packageName = apkMeta.getPackageName();
    System.out.println(String.format("App Name: %s", apkMeta.getName()));
    System.out.println(String.format("App Id: %s", apkMeta.getPackageName()));
    System.out.println(String.format("App Version Code: %d", apkMeta.getVersionCode()));
    System.out.println(String.format("App Version Name: %s", apkMeta.getVersionName()));
    apkInfo.close();

    // load release notes
    System.out.println("Loading release notes...");
    List<LocalizedText> releaseNotes = new ArrayList<LocalizedText>();
    if (this.notesPath != null) {
        Path notesFile = FileSystems.getDefault().getPath(this.notesPath).normalize();
        String notesContent = new String(Files.readAllBytes(notesFile));
        releaseNotes.add(new LocalizedText().setLanguage(Locale.US.toString()).setText(notesContent));
    } else if (this.notes != null) {
        releaseNotes.add(new LocalizedText().setLanguage(Locale.US.toString()).setText(this.notes));
    }

    // init publisher
    System.out.println("Initialising publisher service...");
    AndroidPublisher.Builder ab = new AndroidPublisher.Builder(cred.getTransport(), cred.getJsonFactory(), cred);
    AndroidPublisher publisher = ab.setApplicationName(applicationName).build();

    // create an edit
    System.out.println("Initialising new edit...");
    AppEdit edit = publisher.edits().insert(packageName, null).execute();
    final String editId = edit.getId();
    System.out.println(String.format("Edit created. Id: %s", editId));

    try {
        // upload the apk
        System.out.println("Uploading apk file...");
        AbstractInputStreamContent apkContent = new FileContent(MIME_TYPE_APK, apkFile.toFile());
        Apk apk = publisher.edits().apks().upload(packageName, editId, apkContent).execute();
        System.out.println(String.format("Apk uploaded. Version Code: %s", apk.getVersionCode()));

        // create a release on track
        System.out.println(String.format("On track:%s. Creating a release...", this.trackName));
        TrackRelease release = new TrackRelease().setName("Automated upload").setStatus("completed")
                .setVersionCodes(Collections.singletonList((long) apk.getVersionCode()))
                .setReleaseNotes(releaseNotes);
        Track track = new Track().setReleases(Collections.singletonList(release));
        track = publisher.edits().tracks().update(packageName, editId, this.trackName, track).execute();
        System.out.println(String.format("Release created on track: %s", this.trackName));

        // commit edit
        System.out.println("Commiting edit...");
        edit = publisher.edits().commit(packageName, editId).execute();
        System.out.println(String.format("Success. Commited Edit id: %s", editId));

        // Success
    } catch (Exception e) {
        // error message
        String msg = "Operation Failed: " + e.getMessage();

        // abort
        System.err.println("Opertaion failed due to an error!, Deleting edit...");
        try {
            publisher.edits().delete(packageName, editId).execute();
        } catch (Exception e2) {
            // log abort error as well
            msg += "\nFailed to delete edit: " + e2.getMessage();
        }

        // forward error with message
        throw new IOException(msg, e);
    }
}
 
Example #7
Source File: APKUtility.java    From Flashtool with GNU General Public License v3.0 4 votes vote down vote up
public static String getPackageName(String apkname) throws Exception {

		try (ApkFile apkFile = new ApkFile(new File(apkname))) {
		    return apkFile.getApkMeta().getPackageName();
		}
	}
 
Example #8
Source File: BaseVM.java    From unidbg with Apache License 2.0 votes vote down vote up
abstract byte[] findLibrary(ApkFile apkFile, String soName) throws IOException;