xref: /aosp_15_r20/art/tools/jvmti-agents/simple-force-redefine/README.md (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker# forceredfine
2*795d594fSAndroid Build Coastguard Worker
3*795d594fSAndroid Build Coastguard WorkerForceRedefine is a JVMTI agent designed for testing how redefiniton affects running processes. It
4*795d594fSAndroid Build Coastguard Workerallows one to force classes to be redefined by writing to a fifo or give a process a list of
5*795d594fSAndroid Build Coastguard Workerclasses to try redefining. Currently the redefinition is limited to adding (or removing) a single
6*795d594fSAndroid Build Coastguard WorkerNOP at the beginning of every function in the class.
7*795d594fSAndroid Build Coastguard Worker
8*795d594fSAndroid Build Coastguard Worker# Usage
9*795d594fSAndroid Build Coastguard Worker### Build
10*795d594fSAndroid Build Coastguard Worker>    `m libforceredefine`
11*795d594fSAndroid Build Coastguard Worker
12*795d594fSAndroid Build Coastguard WorkerThe libraries will be built for 32-bit, 64-bit, host and target. Below examples
13*795d594fSAndroid Build Coastguard Workerassume you want to use the 64-bit version.
14*795d594fSAndroid Build Coastguard Worker
15*795d594fSAndroid Build Coastguard Worker#### ART
16*795d594fSAndroid Build Coastguard Worker>    `adb shell setenforce 0`
17*795d594fSAndroid Build Coastguard Worker>
18*795d594fSAndroid Build Coastguard Worker>    `adb push $ANDROID_PRODUCT_OUT/system/lib64/libforceredefine.so /data/local/tmp/`
19*795d594fSAndroid Build Coastguard Worker>
20*795d594fSAndroid Build Coastguard Worker>    `echo java/util/ArrayList > /tmp/classlist`
21*795d594fSAndroid Build Coastguard Worker>    `echo java/util/Arrays >> /tmp/classlist`
22*795d594fSAndroid Build Coastguard Worker>    `adb push /tmp/classlist /data/local/tmp/`
23*795d594fSAndroid Build Coastguard Worker>
24*795d594fSAndroid Build Coastguard Worker>    `adb shell am attach-agent $(adb shell pidof some.deubggable.app) /data/local/tmp/libforceredefine.so=/data/local/tmp/classlist`
25*795d594fSAndroid Build Coastguard Worker
26*795d594fSAndroid Build Coastguard WorkerSince the agent has no static state it can be attached multiple times to the same process.
27*795d594fSAndroid Build Coastguard Worker
28*795d594fSAndroid Build Coastguard Worker>    `adb shell am attach-agent $(adb shell pidof some.deubggable.app) /data/local/tmp/libforceredefine.so=/data/local/tmp/classlist`
29*795d594fSAndroid Build Coastguard Worker>    `adb shell am attach-agent $(adb shell pidof some.deubggable.app) /data/local/tmp/libforceredefine.so=/data/local/tmp/classlist2`
30*795d594fSAndroid Build Coastguard Worker>    `adb shell am attach-agent $(adb shell pidof some.deubggable.app) /data/local/tmp/libforceredefine.so=/data/local/tmp/classlist`
31*795d594fSAndroid Build Coastguard Worker
32*795d594fSAndroid Build Coastguard WorkerOne can also use fifos to send classes interactively to the process. (TODO: Have the agent
33*795d594fSAndroid Build Coastguard Workercontinue reading from the fifo even after it gets an EOF.)
34