Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pip package #19

Open
akshatgit opened this issue Apr 11, 2021 · 1 comment
Open

Pip package #19

akshatgit opened this issue Apr 11, 2021 · 1 comment

Comments

@akshatgit
Copy link

Hi,
Thanks for the awesome repo, I'm planning to use it in one of my projects. I have approx 300 apks to analyse, and I want to use this library from a script to get all the JSON data. Any idea how to do this?

@rovellipaolo
Copy link
Owner

rovellipaolo commented Apr 30, 2021

Hello! I'm deeply sorry for the late reply, somehow I've missed this. :(

To be honest, in the past, I thought more than once about making a python package. However, having a script-like nature and so many external dependencies (java, aapt, apktool, dex2jar, ...), I've opted for "packaging" it with docker and flatpak/snap instead.
That said, if you have time and are interested, I'm open for pull requests. :)

Now, coming to your original question, how can you automate NinjaDroid usage? Well, it depends a bit on what exactly you want to achieve but, at first sight, I can think of a couple of possible solutions:

  • Using a bash script:
#!/bin/bash
FILES=/path/to/apks/*
for file in $FILES 
do
  echo "Processing file: $file"
  ninjadroid $file --all --json
done

NOTE: the above is just an example, which simply executes the command, but you may want to store the output somewhere (e.g. redirecting the stdout to something like > "/path/to/output/$file.json" or using NinjaDroid --extract option).

  • Using a python script:
#!/usr/bin/env python3
import os
from subprocess import PIPE, Popen

def main():
    for file in os.listdir("/path/to/apks/"):
        print("Processing file: " + file)
        command = "ninjadroid " + file + " --all --json"
        with Popen(command, stdout=PIPE, stderr=None, shell=True) as process:
            output = process.communicate()[0].decode("utf-8")
            print(output)

if __name__ == "__main__":
    sys.exit(main())

NOTE: similarly to the previous example, also here it just prints the output of the command, but you may want to do something with it.

Note that, in both examples, I'm assuming that you've installed NinjaDroid locally (see make build and make install). That said, you can achieve the same also using the docker or flatpak or snap versions.
You can see some examples of automation here: https://github.com/rovellipaolo/NinjaDroid/blob/master/regression/

Let me know if this solves your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants