Giter Site home page Giter Site logo

adbproxy's Introduction

ADB Proxy

ADB Proxy is a simple, unobtrusive TCP proxy that proxies traffic between ADB client and ADB server without modification. Its only purpose is to parse ADB packets to understand when port forwarding commands are being sent. So it is made to understand the following ADB commands:

$ adb reverse tcp:<port> tcp:<port>
$ adb forward tcp:<port> tcp:<port>
$ adb forward --remove tcp:<port>
$ adb reverse --remove tcp:<port>
$ adb reverse --remove-all
$ adb forward --remove-all

This is useful for scenarios when ADB client and ADB server are running on separate hosts (or even separate network interfaces), where ports between ADB client host and ADB server host will need to be forwarded accordingly in order for the above commands to work as expected.

For example, say we have Host A running ADB client commands and Host B running an ADB server with an Android device attached. If Host A runs adb reverse tcp:3001 tcp:3002, it should expect that traffic from the Android device's port 3001 would reach its (Host A's) port 3002. However, traffic from port 3002 on Host B will need to be forwarded to port 3002 on Host A in order for this to function as expecte
d.

This is where ADB Proxy is useful, since it can be used to capture port forwarding commands so port forwarding can be setup appropriately (via SSH or whatnot).

For more background, see this blog post.

Installing

ADB Proxy has the following dependencies:

Usage

API is straightforward. Start the proxy server by passing proxy port, adb server port (should already be running), and handler function. Then you can write your own custom logic within your handler, like forwarding ports between hosts . See example.c for more details.

(TIP: If you intend on forwarding ports via ssh, consider SSH multiplexing to reduce latency)

#include "adbp.h"
#include "adbp_types.h"

void *handler(adbp_forward_req req)
{
    if (req.valid) {
		// Do something!
    }
}

int main(int argc, char const *argv[])
{
    int proxy_port = 5038;
    int adb_server_port = 5037;
    adbp_start_server(proxy_port, adb_server_port, handler);
    return 0;
}

Make

Build library:

$ make # optional 'debug' target for verbose logging

Build and run example:

$ make example
$ ./adb_proxy_example # starts proxy on port 5038

To test the proxy, you can run adb command against the proxy:

$ adb -P 5038 forward --remove-all

You should see the example proxy print FORWARD KILL ALL

Resources

ADB client <---> ADB server

ADB server <---> ADBD on device

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.