Created
February 6, 2016 14:02
-
-
Save apangin/d3204345f3b08e6d0138 to your computer and use it in GitHub Desktop.
Dump all Java strings using JVMTI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <jvmti.h> | |
#include <stdio.h> | |
#include <wchar.h> | |
static jvmtiEnv* jvmti; | |
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { | |
(*vm)->GetEnv(vm, (void**)&jvmti, JVMTI_VERSION_1_0); | |
jvmtiCapabilities capabilities = {0}; | |
capabilities.can_tag_objects = 1; | |
jvmtiError err = (*jvmti)->AddCapabilities(jvmti, &capabilities); | |
return JNI_VERSION_1_4; | |
} | |
jint JNICALL stringCallback(jlong class_tag, jlong size, jlong* tag_ptr, | |
const jchar* value, jint value_length, void* user_data) { | |
wprintf(L"%.*s\n", value_length, value); | |
return 0; | |
} | |
JNIEXPORT void JNICALL Java_HeapIterator_printStrings(JNIEnv* env, jclass cls) { | |
jvmtiHeapCallbacks callbacks = {NULL, NULL, NULL, NULL, stringCallback}; | |
(*jvmti)->IterateThroughHeap(jvmti, 0, NULL, &callbacks, NULL); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HeapIterator { | |
static { | |
System.loadLibrary("heapIterator"); | |
} | |
private static native void printStrings(); | |
public static void main(String[] args) throws Exception { | |
printStrings(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment