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

fix: hook lua_newstate insteadof luaL_newstate #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void HookLoadLibrary(Action<IntPtr> callBack)
static IntPtr dlopen_replace(string libfile, int flag)
{
var ret = dlopenF(libfile, flag);
if (!isLoadLuaSo && dlsym(ret, "luaL_newstate") != IntPtr.Zero)
if (!isLoadLuaSo && dlsym(ret, "lua_newstate") != IntPtr.Zero)
{
isLoadLuaSo = true;
_callBack.Invoke(ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void HookLoadLibrary(Action<IntPtr> callBack)
fun = (IntPtr lpFileName, IntPtr hFile, int dwFlags) =>
{
var ret = LoadLibraryExW_dll(lpFileName, hFile, dwFlags);
if (GetProcAddressByHandle(ret, "luaL_newstate") != IntPtr.Zero)
if (GetProcAddressByHandle(ret, "lua_newstate") != IntPtr.Zero)
{
callBack(ret);
hooker.Uninstall();
Expand Down
32 changes: 16 additions & 16 deletions LuaProfiler/Runtime/Core/Driver/LuaDLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void lua_unref(IntPtr luaState, int reference)
#endregion

#region hooks
private static INativeHooker luaL_newstate_hook;
private static INativeHooker lua_newstate_hook;
private static INativeHooker lua_close_hook;
private static INativeHooker lua_gc_hook;
private static INativeHooker lua_call_hook;
Expand All @@ -131,8 +131,8 @@ public static void lua_unref(IntPtr luaState, int reference)

#region 通用操作
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate IntPtr luaL_newstate_fun();
public static luaL_newstate_fun luaL_newstate;
public delegate IntPtr lua_newstate_fun(IntPtr f, IntPtr ud);
public static lua_newstate_fun lua_newstate;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void lua_close_fun(IntPtr L);
Expand Down Expand Up @@ -383,10 +383,10 @@ public static void lua_pushstdcallcfunction(IntPtr luaState, LuaCSFunction func)

public static void Uninstall()
{
if (luaL_newstate_hook != null)
if (lua_newstate_hook != null)
{
luaL_newstate_hook.Uninstall();
luaL_newstate_hook = null;
lua_newstate_hook.Uninstall();
lua_newstate_hook = null;
}

if (lua_close_hook != null)
Expand Down Expand Up @@ -509,15 +509,15 @@ public static void BindEasyHook(IntPtr module)

UnityEngine.Debug.Log("lua versin:" + LUA_VERSION);

if (luaL_newstate_hook == null)
if (lua_newstate_hook == null)
{
IntPtr handle = GetProcAddress(module, "luaL_newstate");
luaL_newstate_fun luaFun = new luaL_newstate_fun(luaL_newstate_replace);
IntPtr handle = GetProcAddress(module, "lua_newstate");
lua_newstate_fun luaFun = new lua_newstate_fun(lua_newstate_replace);
INativeHooker hooker = nativeUtil.CreateHook();
hooker.Init(handle, Marshal.GetFunctionPointerForDelegate(luaFun));
hooker.Install();
luaL_newstate = (luaL_newstate_fun)hooker.GetProxyFun(typeof(luaL_newstate_fun));
luaL_newstate_hook = hooker;
lua_newstate = (lua_newstate_fun)hooker.GetProxyFun(typeof(lua_newstate_fun));
lua_newstate_hook = hooker;
}

if (lua_close_hook == null)
Expand Down Expand Up @@ -984,25 +984,25 @@ public static IntPtr CheckHasLuaDLL()
var modules = process.Modules;
foreach (ProcessModule item in modules)
{
result = GetProcAddress(item.BaseAddress, "luaL_newstate");
result = GetProcAddress(item.BaseAddress, "lua_newstate");
if (result != IntPtr.Zero)
{
return item.BaseAddress;
}
}
#else
result = GetProcAddress(IntPtr.Zero, "luaL_newstate");
result = GetProcAddress(IntPtr.Zero, "lua_newstate");
#endif
return result;
}

[MonoPInvokeCallbackAttribute(typeof(luaL_newstate_fun))]
public static IntPtr luaL_newstate_replace()
[MonoPInvokeCallbackAttribute(typeof(lua_newstate_fun))]
public static IntPtr lua_newstate_replace(IntPtr f, IntPtr ud)
{
UnityEngine.Debug.Log("test newstate success");
lock (m_Lock)
{
IntPtr intPtr = luaL_newstate();
IntPtr intPtr = lua_newstate(f, ud);
if (isHook)
{
MikuLuaProfilerLuaProfilerWrap.RegisterError(intPtr);
Expand Down