Skip to content

astola-studio/ClassBridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClassBridge

ClassBridge is a dynamic proxy library for Java and Android. It enables seamless interaction with hidden, dynamically loaded, or unavailable-at-compile-time classes using proxy mechanisms.


Features

  • Dynamic Class Loading: Loads classes at runtime using custom annotations.
  • Proxy-Based Invocation: Enables method calls on classes that may not exist at compile time.
  • Constructor Matching: Instantiates objects dynamically by resolving constructor parameters.
  • Field & Method Access: Supports dynamic invocation of fields and methods, including get_ and set_ conventions.
  • Supports Hidden/Internal APIs: Useful for interacting with restricted APIs (e.g., in Android frameworks).
  • Easy Integration: Lightweight and dependency-free.

Installation

Download

Download the latest JAR from GitHub Releases

Java Project

Add it to your classpath.

Android Project

Add it to libs folder and make sure your build.gradle has:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

Usage

1. Initializing ClassBridge

import dd.astolastudio.ClassBridge;

ClassBridge bridge = ClassBridge.Get();

2. Creating a Proxy for a Static Class

package com.package;

public class Test {
    // Example of a static function
    private static void doSomething(){
        System.out.println();
    }
}

@ClassName("com.package.Test")
public interface MyInterface {
    @Static void doSomething();
}

MyInterface proxy = bridge.Static(MyInterface.class);
proxy.doSomething();

Or non constant approach (dynamic):

MyInterface proxy = bridge.Static("com.package.Test", MyInterface.class);
proxy.doSomething();

3. Instantiating an Object Dynamically

package com.package;

public class Test {
    // Example of a constructor
    private Test(String text){
        // ...
    }

    protected void run(){
        // ...
    }

}

@ClassName("com.package.Test")
public interface MyInterface {
    void run();
}

MyInterface instance = bridge.New(MyInterface.class, new Object[]{"param"});
instance.run();

Or non constant approach (dynamic):

MyInterface instance = bridge.New("com.package.Test", MyInterface.class, new Object[]{"param"});
instance.run();

4. Accessing Fields

package com.package;

public class Test {
    // Example of a field
    private String text;

    private Test(String text){
        this.text = text;
    }
}

@ClassName("com.package.Test")
public interface MyInterface {

    @Field String get_text();

    @Field void set_text(String value);

}

MyInterface instance = ...

String value = proxy.get_text();
proxy.set_text("New Value");

5. Working with Custom ClassLoader

ClassLoader customLoader = new CustomClassLoader();
ClassBridge bridge = ClassBridge.Get(customLoader);

Annotations

ClassBridge relies on the following annotations:

@ClassName (Required)

Specifies the fully qualified name of the real class that should be proxied.

@ClassName("com.example.HiddenClass")
public interface HiddenAPI {}

Or If you are lazy like me, the following corresponds to android.app.Application :

@ClassName("android.app.")
public interface Application {}

And so does:

@ClassName("android.app.*")
public interface Application {}

@Static (Optional)

Marks a method as a static method when calling through a proxy.

@Static
void staticMethod();

@Field (Depends)

Used to identify that a method is a field (set/get) method when calling through a proxy.

@Field Object get_field();

@Field void set_field(Object value);

Code Examples

There are some code examples you can find Here. There are many usecases, but i am too lazy to write them all in here. It wouldn't even be fun, if i tell you everything. You'll love it more, if you try it yourself. You'll learn more, find more.


Supported Platforms

Platform Minimum Version
Java 7+
Android API 1+

License

ClassBridge is licensed under the MIT License.


Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch (feature-branch).
  3. Commit your changes.
  4. Open a Pull Request.

Resources

For any questions or feature requests, open an issue or contact me at astolastudio@gmail.com.

About

A dynamic proxy library for Java and Android

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages