• Stars
    star
    341
  • Rank 119,891 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy reflection for Java and Android

MirrorMirror

Easy reflection for Java and Android

Introduction

Mirror turns a private class you want to use reflection on into a Java interface.

@Class("com.framework.PrivateCoolClass")
public interface CoolClass {
    @Constructor
    void callConstructor(String aString);

    // A cool method, we want to call
    String doCoolStuff(int value);
}

The Mirror class generates an implementation of the CoolClass interface.

CoolClass coolClass = Mirror.create(CoolClass.class)

You'll need to set up the wrapper with an instance first, for example by calling a constructor.

coolClass.callConstructor("Super"); // this call the PrivateCoolClass(String) constructor;

Each call on the generated CoolClass wrapper makes a call on the instance of PrivateCoolClass.

// This will call the method doCoolStuff(int) on the PrivateCoolClass Object
String cool = coolClass.doCoolStuff(42);

Refection annotations

Use Mirror's annotations to describe your object wrapper and how you want to interact with it.

Declaring the private Class

Use the Class annotation to setup the class you want to use reflection on.

@Class("com.framework.private.PrivateClass")
public interface NotSoPrivateClass {
  ...
}

Instance management

Each wrapper needs to be fed with an instance before any other call.

@Constructor
void callConstructor(String aString);
// or
@SetInstance
void setInstance(Object object);

There are two way for setting an instance into a wrapper:

  • Calling a Constructor annotated method that will create the instance using the constructor matching the exact same parameters.
  • Calling a SetInstance annotated method that will use this object as the instance.

If you need to retrieve the instance, simply add a method annotated with GetInstance returning an object.

@GetInstance
Object getInstance();

Calling methods

If not annotated, a method will be directly called on the instance using the exact same signature.

Playing with fields

SetField and GetField can be used to set and get fields from the instance. Both annotation needs the name of the field to work.

@GetField("aField")
Object getField();

@SetField("aField")
void setField(String aString);

Download

Gradle:

compile 'com.genymobile:mirror:1.0.0'

Mirror requires at minimum Java 7.

Cool but wait... Warning!

This is super slow. Everything is done at runtime (internal reflexion, wrapping...) so don't use this for intensive work. The main goal of this library is to give a tool to quickly play with reflexion and private APIs, classes... and software prototyping.

What next?

There is still some refactoring to do, plenty of bugs to fix, safety checks to implements. Maybe a v2 with code generation to get rid of the performance issue. Anyway, do not hesitate to file bugs or contribute.

License

Copyright 2016 Genymobile

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.

More Repositories

1

scrcpy

Display and control your Android device
C
99,612
star
2

gnirehtet

Gnirehtet provides reverse tethering for Android
Java
5,807
star
3

genymotion-gradle-plugin

A plugin that allows you to control, simply, all your Genymotion devices from your Gradle scripts
Groovy
161
star
4

genymotion-kernel

C
89
star
5

genymotion-device-web-player

Genymotion Virtual Device Web Player
JavaScript
77
star
6

copydeps

Analyze and copy library dependencies of ELF binaries
Python
76
star
7

genymotion-binocle

Java
43
star
8

gm_pr

A multi project Github pull request viewer
Python
42
star
9

genymotion-saas-github-action

Set up your GitHub Actions workflow with a specific Genymotion Cloud SaaS
JavaScript
9
star
10

genymotion-cloud-ssl-tool

Shell
3
star
11

genymotion_platform_vendor_genymotion_security_public

This repo contains dev-keys and release-keys to sign Genymotion Desktop/Paas images.
Makefile
3
star
12

bitrise-step-genymotion-cloud-saas-stop

Go
2
star
13

f2ut_device_fairphone_FP2

C
2
star
14

bitrise-step-genymotion-cloud-saas-start

Go
2
star
15

genymotion-saas-orb

Shell
2
star
16

.github

Android as a Service
2
star
17

hiredis

C
2
star
18

f2ut_private_platform_manifest

2
star
19

f2ut_system_qcom

1
star
20

f2ut_platform_build

Makefile
1
star
21

f2ut_device_fairphone_sepolicy

1
star
22

f2ut_platform_frameworks_native

C++
1
star
23

f2ut_platform_vendor_fairphone

Makefile
1
star
24

f2ut_device_qcom_common

C
1
star
25

terraform-provider-genymotion

Terraform Genymotion provider. Please note: This Terraform provider is archived per our provider archiving process: https://terraform.io/docs/internals/archiving.html
Go
1
star
26

f2ut_platform_hardware_qcom_display

1
star
27

f2ut_platform_system_extras

1
star
28

f2ut_device_fairphone_common

1
star
29

f2ut_platform_vendor_cm

1
star
30

f2ut_platform_platform_bionic

C
1
star
31

f2ut_system_vold

1
star
32

f2ut_device_fairphone

1
star
33

f2ut_platform_frameworks_base

1
star
34

f2ut_system_core

C
1
star
35

f2ut_kernel_fairphone

C
1
star
36

f2ut_platform_frameworks_av

C++
1
star
37

bitrise-step-genymotion-saas-install-gmsaas-cli

Go
1
star
38

f2ut_platform_hardware_qcom_audio

1
star