A Read-Eval-Print-Loop server for Android and SQLite

Overview

Android Arsenal License: Apache2.0

Android DebugPort

Android DebugPort is a drop-in utility which allows you to write and execute code within your app's context, at runtime, and from the comfort of your computer's terminal. Think of it as a window into your application through which you can both inspect and modify its state.

You can connect to one of two REPL servers running within your app:

  • Debug REPL - Run java-like code and inspect/modify the state of your android application.
  • SQLite REPL - Execute queries against your app's SQLite databaases.

Getting Started - Drop-in

Configure Your Dependencies

Add the jitpack.io repository to your root build.gradle:

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

In your application's build.gradle file, add a dependency for Android DebugPort:

debugCompile 'com.github.jasonwyatt.Android-DebugPort:lib:2.1.0'
releaseCompile 'com.github.jasonwyatt.Android-DebugPort:lib-noop:2.1.0'

Note: The final line above will use a no-op version of the DebugPort library in production builds. This makes it impossible for people to run the DebugPort server on a production build.

Run Your App

When you start your app after building for debug, you will see a low-priority notification in your system tray which will allow you to start the debugport servers.

Connecting to the Debug Server

$ telnet 192.168.2.83 8562 # on MacOS High Sierra: `nc 192.168.2.83 8562`
Trying 192.168.2.83...
Connected to 192.168.2.83.
Escape character is '^]'.

Android DebugPort v1.0
Report issues at https://github.com/jasonwyatt/Android-DebugPort/issues

BeanShell 2.0b6 - by Pat Niemeyer ([email protected])
bsh %

There are a few built in commands, to see what they are, run help();

bsh % help();
Available Commands:
  Access:
      call(Object obj, String method, Object... params)
          Call a method, regardless of access modifiers, on the provided object.
      get(Object obj, String fieldName)
          Get the value of a field, regardless of access modifiers, on the provided object.
      set(Object obj, String fieldName, Object value)
          Set the value of a field on the provided object to the given value, regardless of access modifiers.

  Field Inspection:
      fields(Class class)
          List all of the fields available for a particular class.
      fields(Object obj)
          List all of the fields available for a particular object.
      fieldsLocal(Class class)
          List all of the fields defined locally for a particular class.
      fieldsLocal(Object obj)
          List all of the fields defined locally for an object.

  Method Inspection:
      methods(Class class)
          Get the available methods for the provided class.
      methods(Object obj)
          Get the available methods for the provided object.
      methodsLocal(Class class)
          Show all of the locally-declared methods for the provided class.
      methodsLocal(Object obj)
          Show all of the locally-declared methods for the provided object.

  Other:
      exit()
          Exit this interpreter.
      help()
          Show this help message.
      source(String scriptPath)
          Load and run a Beanshell script within your app's assets folder.

bsh %

Also, your application variable is automatically included as a global variable in the interpreter. It's called app. Try running methodsLocal(app);:

bsh % methodsLocal(app);
declared methods: {
  public void onCreate()
}
bsh %

Don't forget that you can execute whatever code you wish within the DebugPort. See the beanshell documentation for the full rundown.

You can exit at any time by running the exit(); command.

Connecting to the SQLite Server

$ telnet 192.168.0.100 8563 # on MacOS High Sierra: `nc 192.168.2.83 8563`
Trying 192.168.0.100...
Connected to 192.168.0.100.
Escape character is '^]'.

Android DebugPort v1.0
Report issues at https://github.com/jasonwyatt/Android-DebugPort/issues

SQLite Database REPL

sqlite>

As with the Debug server, there is a help command for the SQLite server:

sqlite> help;
Help:
  As you'd expect, you can execute any valid SQLite statements against the database to which you're
  currently connected (see: `USE [database name];` below).

  In addition to regular SQLite commands, Android DebugPort provides additional functionality via several
  additional commands.

  Available non-SQLite commands (case insensitive):
    Databases:
        CREATE DATABASE [database name];
            Create a new database called [database name].
        DROP DATABASE [database name];
            Drop the database named [database name] from the app's collection of databases.
        USE [database name];
            Connect to the database called [database name]. All SQL commands will be executed against
            this database until USE is called again.

    Inspection:
        SHOW CREATE TABLE [table name];
            Show the CREATE TABLE command used to create [table name].
        SHOW DATABASES;
            Show all available databases for the app, including temporary databases.
        SHOW TABLES;
            Show all of the tables defined for the database to which you are currently connected.

    Other:
        exit; or quit;
            Exit this interpreter.
        help;
            Show this help message.

sqlite>

Try running show databases; to see the available databases for your app:

sqlite> show databases;
+----------+
| Database |
+----------+
| blog     |
| projects |
+----------+

sqlite>

Run use [database name]; to connect to a database, and once you're connected, you can run any SQLite command you want. You can quit at any time by running the exit; command.

Advanced Configuration

You can configure Android-DebugPort by setting any of the following <meta-data> values in your Application's AndroidManifest.xml.

<application 
    name=".MyApplication"
    label="@string/app_name"
    >
    
    <!-- Customize the port on which the BeanShell REPL will be exposed. -->
    <meta-data android:name="jwf.debugport.METADATA_DEBUG_PORT" android:value="8000"/>
    <!-- Customize the port on which the SQLite REPL will be exposed. -->
    <meta-data android:name="jwf.debugport.METADATA_SQLITE_PORT" android:value="9000"/>
    <!-- Provide any startup commands for the BeanShell REPL by referencing a string array resource. -->
    <meta-data android:name="jwf.debugport.METADATA_STARTUP_COMMANDS" android:resource="@array/startup_commands"/>
    
    <!-- ... -->
</application>

Note: It is recommended that if you wish to supply these meta-data values, you should consider setting them within an AndroidManifest.xml file for the debug build variant.

License

This library is released under the Apache 2.0 License.

Comments
  • Make DebugPort a full drop-in library

    Make DebugPort a full drop-in library

    Hey! Thanks for that awesome library. I think it would be nice to make this library behave like a drop-in, e.g. just write

    debugCompile 'com.github.jasonwyatt:Android-DebugPort:1.1.0'
    

    in your build.gradle, without any needs for noop-versions and manual initialization in the Application class.

    Getting the context and initialization can be done the Google Firebase-way: https://firebase.googleblog.com/2016/12/how-does-firebase-initialize-on-android.html

    And including the <service> can be done via including the library as AAR and then via manifest merger. What do you think about that?

    enhancement 
    opened by nohum 5
  • Make it possible to access/inspect/modify the values of non-public fields.

    Make it possible to access/inspect/modify the values of non-public fields.

    The interpreter doesn't allow you to directly access or modify non-public fields of objects, it would be nice to have a way to do this. The first approach that springs to mind is a new command.

    enhancement 
    opened by jasonwyatt 2
  • Document Usage via `debug` Sourceset

    Document Usage via `debug` Sourceset

    As a long-ago fan of Beanshell, kudos for using it!

    However, given the name and role, ideally we would only add this library into our debug builds. At best, your existing instructions will add bloat to release builds without some custom ProGuard rules. At worst, this might exacerbate other security issues (e.g., another hack leveraging Beanshell to run arbitrary scripts).

    For example, you could:

    • use debugCompile instead of compile for the dependency
    • have a custom Application class in the debug sourceset that starts the service
    • have a custom manifest in the debug sourceset that uses the custom Application and adds the <service>

    Then, a release build will be unaffected.

    opened by commonsguy 2
  • Make Android-DebugPort a drop-in library.

    Make Android-DebugPort a drop-in library.

    Reference #11

    This branch removes the responsibility from the user to do anything other than define Android-DebugPort as a debug dependency. A min-priority notification will be displayed in the system tray which will allow the user to start/stop the telnet servers at will.

    Also, the user may specify <meta-data> values in their AndroidManifest.xml to configure Android-DebugPort.

    opened by jasonwyatt 0
  • Clear out the Application Manifest XML for the library

    Clear out the Application Manifest XML for the library

    There are some issues with the manifest, the first I noticed being that it causes the downstream consumer of the library to have android:supportsRtl="true", which seems like we're overstepping our bounds.

    opened by jasonwyatt 0
  • Pasting a method causes crash

    Pasting a method causes crash

    I've created an empty app, enabled debugport and then run from Android Studio on a real device.

    04-15 19:51:42.065 8126-8132/com.example.live.myapplication I/zygote64: After code cache collection, code=61KB, data=51KB
        Increasing code cache capacity to 256KB
    04-15 19:51:46.384 8126-9149/com.example.live.myapplication I/DebugClientConnection: Client closing:Socket[address=/10.1.1.10,port=3678,localPort=8562]
    04-15 19:51:46.390 8126-9149/com.example.live.myapplication E/AndroidRuntime: FATAL EXCEPTION: Thread-9
        Process: com.example.live.myapplication, PID: 8126
        bsh.Parser$LookaheadSuccess
            at bsh.Parser.<init>(Parser.java:5981)
            at bsh.Interpreter.<init>(Interpreter.java:181)
            at bsh.Interpreter.<init>(Interpreter.java:221)
            at bsh.Interpreter.<init>(Interpreter.java:236)
            at bsh.Interpreter.<init>(Interpreter.java:247)
            at jwf.debugport.internal.debug.DebugClientConnection.run(DebugClientConnection.java:32)
            at java.lang.Thread.run(Thread.java:764)
    

    Pasting the code from https://stackoverflow.com/a/40566060/229631 appears to cause a crash.

    I'm using netcat to connect if that makes a difference.

    Doing some more testing, it seems like pasting public static ArrayList<String> getConnectedDevicesMac() is enough to cause a crash.

    Also seems to affect upstream.

    opened by ghost 0
  • Tips on reaching objects

    Tips on reaching objects

    Could you provide some tips on how we can reach our objects? I guess we only have the app object. Some scenarios that come to mind are to derive my own application object with fields, or use static fields in my classes. If there is a simpler option, I would love to learn about it.

    Thank you for this great tool.

    opened by gazialankus 1
  • Change from mysql-like metadata queries to sqlite-style.

    Change from mysql-like metadata queries to sqlite-style.

    Currently DebugPort uses MySQL-ish queries to get metadata about the current database or its tables:

    • SHOW CREATE TABLE
    • SHOW DATABASES
    • SHOW TABLES
    • EXIT;

    I think it would be better to move to queries/commands that are more similar to how SQLite itself works..

    • .schema [table name]
    • .databases (not really part of SQLite's lexicon, but would apply for android dbs)
    • .quit
    • etc.
    enhancement 
    opened by jasonwyatt 0
  • Crash while app is in the background

    Crash while app is in the background

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getAction()' on a null object reference
    at jwf.debugport.DebugPortService.onStartCommand(DebugPortService.java:142)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3327)
    at android.app.ActivityThread.-wrap21(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1583) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6121) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) ```
    bug 
    opened by jasonwyatt 0
  • Add support for displaying SharedPreferences

    Add support for displaying SharedPreferences

    It would be nice to be able to use DebugPort to inspect and modify SharedPreferences within the app without requiring a bunch of beanshell commands to access them.

    Would it be better to add a new telnet server for this, or to create an in-memory SQLite database with all the preference data? (each shared preferences file would have its own table)

    enhancement question 
    opened by jasonwyatt 0
Releases(2.1.0)
  • 2.1.0(Sep 26, 2017)

    Bumps the compileSdkVersion and targetSdkVersion to 26 for Oreo. Also introduces a notification channel for the debugport notification.

    Note: this version also now has a minSdkVersion of 14.

    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(May 14, 2017)

    Android DebugPort is now a drop-in tool. All you need to do is define your dependencies in your build.gradle as defined in the README, and you're good to go!

    Also, the project now contains the no-op variant, and no longer requires using the old separate-project.

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(May 15, 2016)

    • Jitpack will now create JavaDocs and a Sources Jar
    • Changed to licensing Beanshell with Apache 2.0
    • Grouped help() output in the Debug REPL.
    • Added a help; command to the SQLite REPL.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(May 11, 2016)

    This release fixes a bug which could occur if there was a collision with the @string/app_name resource used in the Manifest's android:label attribute on the Application.

    Source code(tar.gz)
    Source code(zip)
  • 1.0(May 10, 2016)

    Major new feature: SQLite REPL

    You can now connect to a telnet server running on your device and run ad-hoc SQLite queries on your app's databases.

    Incremental Improvements

    • New command source(String assetFileName) will load and run a Beanshell script contained within your app's assets directory.
    Source code(tar.gz)
    Source code(zip)
  • 0.5(May 6, 2016)

    • New commands:
      • get(Object obj, String fieldName) - gets the value of any field on the given object, regardless of access
      • set(Object obj, String fieldName, Object value) - sets the value of any field on the given object, regardless of access
      • call(Object obj, String method, Object... params) - calls a method on the given object, regardless of access
    • Updated help() output
    • Improved support for showing VarArgs parameters in methods and methodsLocal
    Source code(tar.gz)
    Source code(zip)
  • 0.4(May 6, 2016)

    • Upgraded to beanshell 2.0b6
      • The interpreter session will now print the results of commands you enter, like a real REPL.
    • Fixed a bug where the notification drawable could collide with one in a client app.
    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(May 5, 2016)

  • 0.3(May 1, 2016)

    • A notification will now be shown whenever the DebugPortService is active.
    • A crash which would occur when the DebugPortService would be restarted is now resolved.
    • Two new commands are now available from the telnet client: fields and fieldsLocal. They will display a class or object's member fields.
    • The output for the following commands has been vastly improved to include member modifiers and to display types in a more readable manner:
      • methods
      • methodsLocal
      • fields
      • fieldsLocal
    Source code(tar.gz)
    Source code(zip)
  • 0.2(Apr 27, 2016)

    Added two new key pieces of functionality:

    • DebugPortService.stop(Context);
      This really should've been in the original release.
    • params.setStartupCommands(String[])
      A new method on the Params class (optional argument for DebugPortService.start) which lets you provide a list of commands which should be run on each client's interpreter before that client is handed control. This can be useful to automate a lot of tedious imports or can allow you to set up some variables.

    This version also makes the test application a bit easier to use. It introduces a toggle button for enabling/disabling the DebugPort service, as well as a TextView which shows the IP and port on which the service is running.

    Source code(tar.gz)
    Source code(zip)
  • 0.1(Apr 25, 2016)

Owner
Jason Feinstein
Software Engineer @ Google
Jason Feinstein
Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.

Stetho Stetho is a sophisticated debug bridge for Android applications. When enabled, developers have access to the Chrome Developer Tools feature nat

Facebook 12.6k Jan 7, 2023
A library for debugging android databases and shared preferences - Make Debugging Great Again

Android Debug Database Android Debug Database is a powerful library for debugging databases and shared preferences in Android applications Android Deb

AMIT SHEKHAR 8.1k Dec 29, 2022
🔪Swiss-army knife for Android testing and development 🔪 ⛺

ADB Enhanced ADB-Enhanced is a Swiss-army knife for Android testing and development. A command-line interface to trigger various scenarios like screen

Ashish Bhatia 938 Dec 20, 2022
Under the Hood is a flexible and powerful Android debug view library. It uses a modular template system that can be easily extended to your needs, although coming with many useful elements built-in.

Under the Hood - Android App Debug View Library Under the Hood is a flexible and powerful Android debug view library. It uses a modular template syste

Patrick Favre-Bulle 217 Nov 25, 2022
Easy android exception tracer and handler.

Introduction Lup is a small android library that can help you to tracking bug that causes application stopped working (force close). Whiting this libr

icodeu 4 Sep 29, 2022
Android QA/Debug tools to speed up and streamline the development progress.

Android Dev Tools is a library that contains various QA/Debug tools to speed up and streamline the development progress.

Trendyol Open Source 105 Dec 5, 2022
Cordova plugin for Android Serial USB communication (easily connect an Arduino board to an Android device).

PR-DC cordova-plugin-serialusb Cordova plugin for Android Serial USB communication. This plugin makes a connection to the external board trivial, for

PR-DC 3 May 8, 2022
Android library to record the network calls through the interceptor mechanism of the http clients.

Android Snooper Introduction Android Snooper is a library which helps in debugging issues while running the applications on android devices. One of th

Prateek 151 Nov 25, 2022
traffic debugging library for android

TrafficMonitor About Display traffic per Activity.Observing traffic is used by TrafficStats API. OkHttp Interceptor observer is implementing. Demo Bai

Tetsuya Masuda 17 Feb 4, 2022
Sources for the LiveBoot app for rooted Android devices

This is the sauce for the LiveBoot app. License Copyright © 2011-2020 Jorrit Chainfire Jongma This code is released under the GPLv3. LICENSE, COPYING.

Chainfire 131 Jan 9, 2023
android logcat

android logcat

Ji Sungbin 3 Dec 2, 2022
A local ADB shell for Android!

LADB A local ADB shell for Android! How does it work? LADB bundles an ADB server within the app libraries. Normally, this server cannot connect to the

Tyler 1.1k Jan 2, 2023
btrace(AKA RheaTrace) is a high performance Android trace tool which is based on Systrace

btrace README 中文版 btrace(AKA RheaTrace) is a high performance Android trace tool

Bytedance Inc. 1.2k Jan 4, 2023
Pluto: An on-device debugging framework for Android applications

Pluto is an on-device debugging framework for Android applications, which helps in the inspection of HTTP requests/responses, captures Crashes, and ANRs, and manipulates application data on the go.

Pluto 550 Dec 27, 2022
kotlin eval command for minestom

k Kotlin debugging evaulator in Minestom. Usage /k is shorthand, /ko is longhand requires the permission "k.ok" and "k.store" for running scripts and

Cepi 3 Dec 20, 2022
This project created just for help developer who want to and ability of read VISA, UNION PAY, HUMO, ATTO and some other cards data read.

If you enjoy my content, please consider supporting what I do. Thank you. By me a Coffee To get a Git project into your build: Step 1. Add the JitPack

Fozilbek Imomov 1 Oct 15, 2022
Loop Habit Tracker, a mobile app for creating and maintaining long-term positive habits

Loop is a mobile app that helps you create and maintain good habits, allowing you to achieve your long-term goals. Detailed graphs and statistics show you how your habits improved over time.

Alinson S. Xavier 5.8k Jan 7, 2023
This is An Android Project. in which we use SqLite Database. We perform Insert,delete,update and Show The existing data. operations using SqLite.

SqLite Database Keywords : SqLite, Android, Database This is An Android Project. in which we use SqLite Database. We perform Insert,delete,update and

Rudra_deep 1 Nov 7, 2021
App demonstrates how to use Room to save, read, update, and delete inventory items in a SQLite database.

Inventory - Solution Code Solution code for Android Basics in Kotlin. Codelab: Android Jetpack - Room. Introduction This app is an Inventory tracking

Google Developer Training 75 Dec 30, 2022