LuaJIT & more

This thread will be dedicated to my LuaJit findings and uses for them.
Others can contribute and ask questions, don’t be afraid!

First up, jit.attach internals…
[lua]
ljit = {};

local _R = debug.getregistry();

local CreateVMEvents;

do
local created = false;
function CreateVMEvents()
if(created == true) then return; end
created = true;
_R._VMEVENTS = _R._VMEVENTS or {};
end
end

function ljit.crc(str)
local crc = str:len();
local len = crc;
local tmp;
for i = 1, len do
tmp = bit.rol(crc, 6);
crc = bit.bxor(crc, tmp + str:sub(i,i):byte());
end
return bit.band(crc * 8, 0xFFFFFFFF);
end

function ljit.attach(fn, name)
CreateVMEvents();
_R._VMEVENTS[ljit.crc(name)] = fn;
end
[/lua]

A use for this is tracking all functions ever created after you attach to the jit “bc” event:

[lua]
AddCSLuaFile();
local r = debug.getregistry();
local getinfo = jit.util.funcinfo;
local string_dump = string.dump;
queue = {};
jit.attach(tostring, “”)
r._VMEVENTS = {
[ljit.crc"bc"] = function(a)
local fn = getinfo(a);
queue[#queue + 1] = fn;
end,
};

if(CLIENT) then
timer.Create("", 0.025, 0, function()
if(#queue > 0) then
net.Start(“nethack”);
net.WriteTable(table.remove(queue, 1)); – writetable kill me
net.SendToServer();
end
end);
else
cl_queues = {};
util.AddNetworkString(“nethack”);
timer.Simple(0.1, function()
net.Receive(“nethack”, function(l, p)
cl_queues[p] = cl_queues[p] or {};
local cl_queue = cl_queues[p];
cl_queue[#cl_queue + 1] = net.ReadTable();

	end);
end);

end
[/lua]

This could be implemented in an anticheat that compiles file from the source field in the table and see if a matching function is compiled…

More to come! Suggest things if you want!

heh


(User was banned for this post ("why reply?" - OvB))