Inspector
用于检查SQLite数据库和截获来自移动应用程序的网络请求的工具。
针对Android、iOS和Web使用C/C++、Java、Objective-C、Vue.js、WebSocket、SQLite和IndexedDB的项目。数据在Web界面上显示,并使用WebSocket通过本地网络直接与应用程序通信。为了保持网络日志历史记录,Web系统使用浏览器内置的IndexedDB。
前端仓库
https://github.com/pakerwreah/InspectorWeb
Android
设置
Gradle
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation "com.github.pakerwreah:Inspector:<release-tag>"
}
Proguard
-keep class br.newm.inspector.* { *; }
使用方法
应用程序
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"};
}
}
拦截网络请求
import br.newm.inspector.NetworkInterceptor;
new OkHttpClient.Builder().addInterceptor(new NetworkInterceptor());
静态插件
接受返回的JSON、HTML或纯文本。
Inspector.addPlugin("prefs", "Shared Preferences", new PluginAction() {
@Override
public String action() {
return new JSONObject(prefs.getAll()).toString();
}
});
实时插件
接受带有JavaScript支持的复杂HTML前端。
检查ExplorerPlugin.java以获取完整示例。
Inspector.addLivePlugin("explorer", "Explorer", new PluginAction() {
@Override
public String action() {
// return plugin frontend
}
});
插件API
带有参数的路由,可用于作为插件或独立API使用。
检查ExplorerPlugin.java以获取完整示例。
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
}
});
WebSocket
向您的实时插件发送消息。
new WebSocket(`ws://${location.hostname}:${location.port}/plugins/ws/mykey`)
Inspector.sendMessage("mykey", "Hello world!");
# same port number used to initialize the plugin
adb forward tcp:30000 tcp:30000
或将其网络配置为桥接模式并使用设备的IP地址
iPhone OS
设置
CocoaPods
target 'MyApp' do
pod "IOSInspector"
end
使用方法
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
}
}
}
拦截网络请求
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()
静态插件
接受返回的JSON、HTML或纯文本。
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"
}
动态插件
接受带有JavaScript支持的复杂HTML前端。
检查ExplorerPlugin.swift以获取完整示例
IOSInspector.addLivePlugin("explorer", name: "Explorer") {
// return plugin frontend
}
插件API
带有参数的路由,可用于作为插件或独立API使用。
检查ExplorerPlugin.swift以获取完整示例
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
向您的实时插件发送消息。
new WebSocket(`ws://${location.hostname}:${location.port}/plugins/ws/mykey`)
IOSInspector.sendMessage(to: "mykey", message: "Hello world!")