Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook Crash with makeText method of Toast #12

Open
TheKop opened this issue Apr 16, 2015 · 0 comments
Open

Hook Crash with makeText method of Toast #12

TheKop opened this issue Apr 16, 2015 · 0 comments

Comments

@TheKop
Copy link

TheKop commented Apr 16, 2015

Hi
I'm trying to hook method makeText of class android/widget/Toast
But it crash.
Please let me know code is wrong or current your library still not support?

////////Code Start

void do_patch()
{
dalvik_hook_setup(&sb1, "Landroid/widget/Toast;", "makeText", "(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;", 4, makeText);
dalvik_hook(&d, &sb1);

}

// patches
static void* makeText(JNIEnv *env, jobject context ,jobject txt, jint time)
{
log("Prepare Hook Toast\n")
dalvik_prepare(&d, &sb1, env);
jclass Toast = NULL;
jobject toast = NULL;
jmethodID makeText = NULL;

log("FindClass Toast\n")
Toast = (*env)->FindClass(env, "android/widget/Toast");
if(NULL == Toast)
{
    log("FindClass failed")
    return;
}
log("Method name = %s\n",sb1.method_name)

log("Get parameters\n")

jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, txt), "toString", "()Ljava/lang/String;");
jstring string = (jstring)((*env)->CallObjectMethod(env, txt, mid));
const char* utf = (*env)->GetStringUTFChars(env, string, 0);
if (utf) {
    log("txt : %s , time = %d\n", utf,time)
    (*env)->ReleaseStringUTFChars(env, string, utf);
}

log("Prepare CallStaticObjectMethod\n")
toast = (*env)->CallStaticObjectMethod(env, Toast, sb1.mid, context,txt,time);  //Crash at this line of code
if ( NULL == toast) 
{
    log("CALLSTATICOBJECT FAILED")
    return;
}

log("dalvik_postcall\n")
dalvik_postcall(&d, &sb1);

//Just test
return NULL;

}

/////Code End
Thanks you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant