Git Product home page Git Product logo

pakerwreah / inspector Goto Github PK

View Code? Open in Web Editor NEW
17.0 6.0 3.0 9.43 MB

Tool to inspect SQLite databases and intercept network requests from mobile applications.

Home Page: https://pakerwreah.github.io/InspectorWeb

License: MIT License

Ruby 0.04% Java 0.86% Shell 0.03% CMake 0.10% C++ 63.42% C 23.51% Swift 0.36% Objective-C 0.11% Objective-C++ 0.23% HTML 0.97% Dockerfile 0.02% Python 10.36%
stetho flipper sqlite jni mobile cross-platform inspect sqlcipher cpp debug

inspector's Introduction

Inspector

release c++ android ios codecov ci ci ci

Tool to inspect SQLite databases and intercept network requests from mobile applications.

Project targeting Android, iOS and Web using C/C++, Java, Objective-C, Vue.js, WebSocket, SQLite and IndexedDB. The data is shown in a web interface and uses WebSocket to communicate directly with the app via local network. To keep network log history the web system uses the built-in IndexedDB from the browser.

Frontend repository

https://github.com/pakerwreah/InspectorWeb

Android

Version

Setup

Gradle

repositories {
    maven { url "https://jitpack.io" }
}
dependencies {
    implementation "com.github.pakerwreah:Inspector:<release-tag>"
}

Proguard

-keep class br.newm.inspector.* { *; }
Usage

Application

import br.newm.inspector.Inspector;

public class Application extends android.app.Application {
    @Override
    public void onCreate() {
        super.onCreate();

        Inspector.initializeWith(this);

        // SQLCipher support
        // database name, password, sqlcipher major version
        Inspector.setCipherKey("database_cipher3.db", "123456", 3);
        Inspector.setCipherKey("database_cipher4.db", "123456", 4);
    }

    // Optional: if you want to specify databases names to show
    @Override
    public String[] databaseList() {
        return new String[]{"database.db", "database_cipher3.db", "database_cipher4.db"};
    }
}

Intercept network requests

⚠️ if you use addNetworkInterceptor it won't intercept timeouts

import br.newm.inspector.NetworkInterceptor;

new OkHttpClient.Builder().addInterceptor(new NetworkInterceptor());

Static plugins

Accepts returning JSON, HTML or plain text

Inspector.addPlugin("prefs", "Shared Preferences", new PluginAction() {
    @Override
    public String action() {
        return new JSONObject(prefs.getAll()).toString();
    }
});

Live plugins

Accepts complex HTML frontend with javascript support
Check ExplorerPlugin.java for a full example

Inspector.addLivePlugin("explorer", "Explorer", new PluginAction() {
    @Override
    public String action() {
        // return plugin frontend
    }
});

Plugin API

Route with parameters to be used as a plugin or standalone api
Check ExplorerPlugin.java for a full example

Inspector.addPluginAPI("GET", "filesystem/list", new PluginAPIAction() {
    @Override
    public String action(Map<String, String> params) {
        // return json array with list of files
    }
});

Inspector.addPluginAPI("GET", "filesystem/open", new PluginAPIActionBinary() {
    @Override
    public byte[] action(Map<String, String> params) {
        // return file contents
    }
});

Websockets

Send messages to your live plugins

new WebSocket(`ws://${location.hostname}:${location.port}/plugins/ws/mykey`)
Inspector.sendMessage("mykey", "Hello world!");

⚠️ You should run this command to work with emulators

# same port number used to initialize the plugin
adb forward tcp:30000 tcp:30000

Or configure its network as bridge and use the device's IP

iOS

Version

Setup

CocoaPods

target 'MyApp' do
   pod "IOSInspector"
end
Usage

AppDelegate

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, IOSInspectorProtocol {

    func applicationDidFinishLaunching(_ application: UIApplication) {

        IOSInspector.initialize(withDelegate: self)

        // SQLCipher support
        IOSInspector.setCipherKey("database_cipher3.db", password: "123456", version: 3)
        IOSInspector.setCipherKey("database_cipher4.db", password: "123456", version: 4)
    }

    // Required: specify databases paths
    func databaseList() -> [String] {
        let documentsPathURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

        return ["database.db", "database_cipher3.db", "database_cipher4.db"].map {
            documentsPathURL.appendingPathComponent($0).absoluteString
        }
    }
}

Intercept network requests

let uid = UUID().uuidString

let request = URLRequest(url: url)

// send request to the frontend
IOSInspector.sendRequest(withUID: uid, request: request)

URLSession.shared.dataTask(with: request) { data, response, error in

    if let data = data, let response = response as? HTTPURLResponse {
        // send response to the frontend
        IOSInspector.sendResponse(withUID: uid, response: response, body: data)
    }

}.resume()

Static plugins

Accepts returning JSON, HTML or plain text

IOSInspector.addPlugin("prefs", name: "User Defaults") {
    let dict = UserDefaults.standard.dictionaryRepresentation()
    if let data = try? JSONSerialization.data(withJSONObject: dict),
        let json = String(data: data, encoding: .utf8) {
        return json
    }
    return "No data"
}

Live plugins

Accepts complex HTML frontend with javascript support
Check ExplorerPlugin.swift for a full example

IOSInspector.addLivePlugin("explorer", name: "Explorer") {
    // return plugin frontend
}

Plugin API

Route with parameters to be used as a plugin or standalone api
Check ExplorerPlugin.swift for a full example

IOSInspector.addPluginAPI(forMethod: "GET", path: "filesystem/list") { params -> String in
    // return json array with list of files
}

IOSInspector.addPluginAPI(forMethod: "GET", path: "filesystem/open") { params -> Data? in
    // return file contents
}

Websockets

Send messages to your live plugins

new WebSocket(`ws://${location.hostname}:${location.port}/plugins/ws/mykey`)
IOSInspector.sendMessage(to: "mykey", message: "Hello world!")

inspector's People

Contributors

pakerwreah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

inspector's Issues

Plugin websocket support

Ability to push messages from app to web in real time using websockets.

Developer notes

  • Check if compression works natively (Sec-WebSocket-Extensions)
    Safari: x-webkit-deflate-frame
    Chrome: permessage-deflate

How I can see the database logger ?

I downloaded the android app sample and ran it on my mobile device then I don't know how to see the database logs .
I went to this link http://localhost:30000/ but no avail , it shows this message : {"msg":"Route not found"}

So could you please clarify how to see them?

Workflow CI

Create workflow to test building for Android, iOS and run Unit Tests.

Transactions are not rolling back automatically when query fails

When executing a script with multiple queries inside a transaction, it won't auto rollback when one of the queries fails.
This is, in fact, the default behavior for SQLite, but since it's not intuitive it should not be happening within Inspector.

  • In a single script, every query before the error will be committed to the database.
  • Executing multiple queries inside a transaction (in c++ code), all queries (ignoring errors) will be committed to the database.

Can't receive UDP broadcast from Android emulator

I used to test this with Genymotion and it worked well at the time, but now that I have an M1 Macbook I have to use the built in emulator, which apparently does not broadcast UDP datagrams to the host machine.

Since I don't have a real device available anymore, I can only hope this feature still works 😞

Inspector stops responding after the app is minimized and the device is locked

Inspector stops responding after the app is minimized and the device is locked.
When this happens, it gets a broken pipe signal and should recreate the socket before trying to bind to the port again.

Steps to reproduce (iOS)

  1. Open the app that is running Inspector
  2. Verify that the web interface gets populated
  3. Minimize the app and lock the device
  4. Unlock the device and reopen the app
  5. Try to reload anything on the web interface and verify that it doesn't work anymore

ps.: This is not time sensitive, it happens immediately.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.