Skip to content

Commit c630906

Browse files
committed
XLuaHook::invoke() must copy all Varargs elements used by the hook.
The Varargs object passed to invoke() seems to be reused by the Lua interpreter and capturing it as is when defining the hook leads to accessing other elements than intended when the hook runs. Instead, copy all the function object in fun and the the extra arguments in xargs, and use these when defining the hook.
1 parent 28f66d9 commit c630906

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/src/main/java/eu/faircode/xlua/XLua.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,10 @@ public Varargs invoke(final Varargs args) {
829829
String m = args.arg(2).checkjstring();
830830
args.arg(3).checkfunction();
831831
Log.i(TAG, "Dynamic hook " + cls.getName() + "." + m);
832+
final LuaValue fun = args.arg(3);
833+
final List<LuaValue> xargs = new ArrayList<>();
834+
for (int i = 4; i <= args.narg(); i++)
835+
xargs.add(args.arg(i));
832836

833837
XposedBridge.hookAllMethods(cls, m, new XC_MethodHook() {
834838
@Override
@@ -846,9 +850,9 @@ private void execute(String when, MethodHookParam param) {
846850
List<LuaValue> values = new ArrayList<>();
847851
values.add(LuaValue.valueOf(when));
848852
values.add(CoerceJavaToLua.coerce(new XParam(context, param, settings)));
849-
for (int i = 4; i <= args.narg(); i++)
850-
values.add(args.arg(i));
851-
args.arg(3).invoke(values.toArray(new LuaValue[0]));
853+
for (int i = 0; i < xargs.size(); i++)
854+
values.add(xargs.get(i));
855+
fun.invoke(values.toArray(new LuaValue[0]));
852856
}
853857
});
854858

0 commit comments

Comments
 (0)