darfink / detour-rs

A cross-platform detour library written in Rust
Other
389 stars 71 forks source link

Infinite recursion in static_detour macro #14

Closed CertainLach closed 4 years ago

CertainLach commented 4 years ago
use jni::JNIEnv;
use jni::sys::{jobject, jbyte, jsize, jclass};

static_detour! {
    static JVM_DefineClassWithSourceHook: unsafe extern "system" fn(env: JNIEnv, name: *const i8, loader: jobject, buf: usize, len: jsize, pd: jobject, source: *const i8) -> jclass;
}

Macro backtrace:

error: recursion limit reached while expanding the macro `static_detour`
   --> <::detour::macros::static_detour macros>:7:1
    |
1   |       / (
2   |       | @ parse_attributes ( $ ( $ input : tt ) * ) | # [ $ attribute : meta ] $ (
3   |       | $ rest : tt ) * ) => {
4   |       | static_detour ! (     
...         |
7   | /     | static_detour ! (
8   | |     | @ parse_access_modifier ( ( $ ( $ input ) * ) ) | $ ( $ rest ) * ) ; } ; (
    | |     |                                                                    ^ in this macro invocation (#3)
    | |_____|____________________________________________________________________|
    |       |
...         |
24  |       | static_detour ! ( @ parse_name ( $ ( $ input ) * (  ) ) | $ ( $ rest ) * ) ; }
    |       | ---------------------------------------------------------------------------- in this macro invocation (#4)
...         |
28  | /     | static_detour ! (
29  | |     | @ parse_unsafe ( $ ( $ input ) * ( $ name ) ) | $ ( $ rest ) * ) ; } ; (
    | |_____|__________________________________________________________________- in this macro invocation (#5)
30  |       | @ parse_unsafe ( $ ( $ input : tt ) * ) | unsafe $ ( $ rest : tt ) * ) => {
31  | /     | static_detour ! (
32  | |     | @ parse_calling_convention ( $ ( $ input ) * ) ( unsafe ) | $ ( $ rest ) * ) ;
    | |_____|______________________________________________________________________________- in this macro invocation (#6)
...         |
38  | /     | static_detour ! (
39  | |     | @ parse_prototype ( $ ( $ input ) * ( $ ( $ modifier ) * extern $ cc ) ) | $ (
40  | |     | $ rest ) * ) ; } ; (
    | |_____|______________- in this macro invocation (#7)
...         |
106 |       | @ generate $ item : item ) => { $ item } ; ( $ ( $ t : tt ) + ) => {
    |       | ---------------------------------------------------------------------------- in this macro invocation (#4)
...         |
28  | /     | static_detour ! (
29  | |     | @ parse_unsafe ( $ ( $ input ) * ( $ name ) ) | $ ( $ rest ) * ) ; } ; (
    | |_____|__________________________________________________________________- in this macro invocation (#5)
30  |       | @ parse_unsafe ( $ ( $ input : tt ) * ) | unsafe $ ( $ rest : tt ) * ) => {
31  | /     | static_detour ! (
32  | |     | @ parse_calling_convention ( $ ( $ input ) * ) ( unsafe ) | $ ( $ rest ) * ) ;
    | |_____|______________________________________________________________________________- in this macro invocation (#6)
...         |
38  | /     | static_detour ! (
39  | |     | @ parse_prototype ( $ ( $ input ) * ( $ ( $ modifier ) * extern $ cc ) ) | $ (
40  | |     | $ rest ) * ) ; } ; (
    | |_____|______________- in this macro invocation (#7)
...         |
107 |       | static_detour ! ( @ parse_attributes (  ) | $ ( $ t ) + ) ; } ;
    |       | -----------------------------------------------------------   -
    |       | |                                                             |
    |       | |                                                             in this expansion of `static_detour!` (#1)
    |       | |                                                             in this expansion of `static_detour!` (#2)
    |       | |                                                             in this expansion of `static_detour!` (#3)
    |       | |                                                             in this expansion of `static_detour!` (#4)
    |       | |                                                             in this expansion of `static_detour!` (#5)
    |       | |                                                             in this expansion of `static_detour!` (#6)
    |       |_|_____________________________________________________________in this expansion of `static_detour!` (#7)
    |         |                                                             in this expansion of `static_detour!` (#8)
    |         in this macro invocation (#2)
    |         in this macro invocation (#8)
    |
   ::: src\lib.rs:16:1
    |
16  | /       static_detour! {
17  | |           static JVMDefineClassWithSourceHook: unsafe extern "system" fn(env: JNIEnv, name: *const i8, loader: jobject, buf: usize, len: jsize, pd: jobject, source: *const i8) -> jclass;
18  | |
19  | |       }
    | |_______- in this macro invocation (#1)
    |
darfink commented 4 years ago

Yes, the macro expects a function type without any named parameters:

static_detour! {
    static JVM_DefineClassWithSourceHook: unsafe extern "system" fn(env: JNIEnv, name: *const i8, loader: jobject, buf: usize, len: jsize, pd: jobject, source: *const i8) -> jclass;
}

--->

static_detour! {
    static JVM_DefineClassWithSourceHook: unsafe extern "system" fn(JNIEnv, *const i8, jobject, usize, jsize, jobject, *const i8) -> jclass;
}

Although it highlights a potential improvement, support for optional named parameters may be of interest.

CertainLach commented 4 years ago

Missed that, thank you