Git Product home page Git Product logo

classinjector's Introduction

ClassInjector

CircleCI Release
Java Android

A library that provides the ability to inject classes into a class loader.

Usage

ClassInjector.from(new ClassSource() {
    @Nullable
    @Override
    public ClassFile getClassFile(@Nonnull String className) throws IOException {
        // Find bytecode for the given class name from arbitrary sources.
        byte[] bytecode = ...
        // Return the ClassFile object with the given class name and its bytecode.
        // If no bytecode was found, return null.
        return bytecode == null ? null : new JvmClassFile(className, bytecode);
    }
}).into(getClass().getClassLoader());

For Android, use DexClassFile instead of JvmClassFile.

// Get a Context object.
final Context context = ...
ClassInjector.from(new ClassSource() {
    @Nullable
    @Override
    public ClassFile getClassFile(@NonNull String className) throws IOException {
        // Find a zip file containing "classes.dex" with the given class name.
        String sourcePath = ...
        // If not found, return null.
        if (sourcePath == null) {
            return null;
        }
        // Construct the path for the optimized dex data.
        File cacheDir = context.getDir("dex_cache", Context.MODE_PRIVATE);
        String optimizedPath = new File(cacheDir, "classes.dex").getCanonicalPath();
        // Open the dex file.
        DexFile dexFile = DexFile.loadDex(sourcePath, optimizedPath, 0);
        // Return the ClassFile object with the given class name and its dex file.
        return new DexClassFile(className, dexFile);
    }
}).into(context.getClassLoader());

Installation

First, add the JitPack repository to your build.gradle.

repositories {
    maven { url 'https://jitpack.io' }
}

And then, for Java (7 or later):

dependencies {
    implementation 'com.github.tmurakami.classinjector:classinjector:1.0.0'
}

Or for Android (2.3 or later):

android {
    defaultConfig {
        minSdkVersion 9 // 9 or higher
    }
}

dependencies {
    implementation 'com.github.tmurakami.classinjector:classinjector-android:1.0.0'
}

License

Copyright 2017 Tsuyoshi Murakami

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

classinjector's People

Contributors

tmurakami avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

abdualmenan

classinjector's Issues

lOGO OFFER FOR CLASSINJECTOR

Hi sir. I'm graphics designer. I have studied your work. Your current logo is very good but I think a new simple logo will make you more visible. I would like to offer logo. I can give you all the formats of the design free. If you want I send you PR or a change please specify.
Good luck...

classinjector

Best regard
Famil

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.