Giter Club home page Giter Club logo

androidremotobridge's Introduction

AndroidRemotoBridge

这是一个用于特殊调用的RPC框架,用于Android应用程序和服务器。

例如需要使用某加固APP中的sign方法,但是又不想去破解加固,那么就可以使用这个框架。

1. 服务端

服务端通过Cglib动态代理,将需要调用的方法暴露出来,然后通过Socket通信,将方法名,参数,返回值传递给bridge-client

java代码如下:

        ServerBridgeBoostrap serverBridgeBoostrap=new ServerBridgeBoostrap();
        IServerBridge serverBridge=serverBridgeBoostrap.bridgeProtocol(new DefaultBridgeProtocol())
        .internalProtocol(new DefaultInternalProtocol())
        .registerBridge(TestRpcService.class)
        .start();//启动服务
        TestRpcService testrpcService=serverBridge.getBridge(TestRpcService.class);//获取代理对象
        testrpcService.test();//调用方法

2. 客户端

客户端实现接口,通过ClientBridgeBoostrap.registerBridge()注册接口,然后通过ClientBridgeBoostrap.start()启动服务。 代码如下:

        ClientBridgeBoostrap clientBridgeBoostrap=new ClientBridgeBoostrap();
        clientBridgeBoostrap.server("127.0.0.1",23333)//设置服务端地址
        .registerBridge(TestRpcService.class,new TestRpcServiceImpl())//注册接口
        .bridgeProtocol(new DefaultBridgeProtocol())
        .internalProtocol(new DefaultInternalProtocol())
        .start();//启动服务

3. 通信协议

通过实现IBridgeProtocol接口,可以自定义Invoke通信协议,框架默认使用的是DefaultBridgeProtocol

DefaultBridgeProtocol使用阿里的hessian-lite进行序列化。

通过实现IInternalProtocol接口,可以自定义server与client之间通信协议,框架默认使用的是DefaultInternalProtocol

DefaultInternalProtocol协议格式如下:

4byte 8byte 4byte 4byte ?byte
total id type data_len data

4.自定义ReqHandler

实现RegHandler接口

public interface ReqHandler {
    InternalData handle(ChannelHandlerContext channelHandlerContext, InternalData internalData, HandlerAttributes handlerAttributes);

    int getReqType();
}

5.自定义CmdHandler

实现CmdHandler接口

public interface CmdHandler {
    void handle(ChannelHandlerContext channelHandlerContext, byte[] data, HandlerAttributes handlerAttributes);

    int getCmdType();

}

6.注册自定义的CmdHandler,ReqHandler

        serverBridgeBoostrap.addCmdHandler(new RegisterSupportBridge())//server
        .addCmdHandler(new ClientReadyHandler());
       clientBridgeBoostrap.addReqHandler(new SayHelloHandler());//client

androidremotobridge's People

Contributors

tapiohuang avatar

Watchers

 avatar

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.