什么是最有效的方式来删除混淆名称(我的世界)?

问题描述:

我已经为Minecraft制作了一个允许Lua修改的mod。一切工作正常,但通常方法的名称在MC中被混淆。使正常函数名称重定向到混淆名称的最佳方式是什么?什么是最有效的方式来删除混淆名称(我的世界)?

例如,用户使得脚本,这是打印Hello World块时右点击:

function onActivated(world, x, y, z, player) player:addChatMessage("hello world") end

addChatMessage应该调用Java方法EntityPlayer.func_71035_c(字符串文本)

+1

尝试使用'require'libname'来访问原始库。例如,'(require'math')。pi'获得非混淆的'math.pi'。 – 2013-03-20 15:10:44

+0

我正在谈论Minecraft的方法。通常情况下,所有方法都被模糊处理(func_number_a)。所以如果我给Player对象作为参数,我必须调用player:func_34323_c(text)而不是player:addChatMessage()。 MC编码器包将方法/字段/类名称转换为逻辑名称(我拥有名称文件)。 – Rule 2013-03-20 15:18:44

+1

你有权访问翻译算法(将'func_34323_c'转换为'addChatMessage')吗?这是一个秘密吗? – 2013-03-20 15:27:51

-- translation file (translation.txt) 
func_70912_b,setTameSkin,2, 
func_70913_u,getTameSkin,2, 
func_70915_j,getShadingWhileShaking,2,Used when calculating the amount of shading to apply while the wolf is shaking. 
func_70916_h,setAngry,2,Sets whether this wolf is angry. 


-- obfuscated program (script.lua) 
x:func_70913_u(y, z) 
x:func_70915_j(y, z) 


-- your preprocessor (preprocessor.lua) 
local transl = {} 
for line in io.lines'translation.txt' do 
    local obf, orig = line:match'^(.-),(.-),' 
    transl[obf] = orig 
end 
local script = assert(io.open('script.lua','rb')):read'*a' 
local output = assert(io.open('script2.lua','wb')) 
output:write((script:gsub('[%w_]+',transl))) 
output:close() 


-- preprocessor output (script2.lua) 
x:getTameSkin(y, z) 
x:getShadingWhileShaking(y, z) 

编辑:

local obfuscations = {} 
for line in io.lines'translation.txt' do 
    local obf, orig = line:match'^(.-),(.-),' 
    obfuscations[orig] = obf 
end 

local function get_obf_key_value(t, k, __index) 
    local value = __index and __index(t, k) 
    if value == nil and obfuscations[k] then 
     value = t[obfuscations[k]] 
    end 
    return value 
end 

local cache = {get_obf_key_value = true} 

local function __index_constructor(__index) 
    if not __index then 
     return get_obf_key_value 
    end 
    local old__index = cache[__index] 
    if old__index then 
     return old__index == true and __index or old__index 
    else 
     local function new__index(t, k) 
     return get_obf_key_value(t, k, __index) 
     end 
     cache[__index] = new__index 
     cache[new__index] = true 
     return new__index 
    end 
end 

local obf_mt = {__index = get_obf_key_value} 

local function correct_metatable(object) 
    local mt = getmetatable(object) 
    if mt == nil then 
     setmetatable(object, obf_mt) 
    else 
     local __index = mt.__index 
     if __index == nil or type(__index) == 'function' then 
      mt.__index = __index_constructor(__index) 
     else 
     correct_metatable(__index) 
     end 
    end 
end 

-- you should call correct_metatable(class_or_object_of_that_class) 
-- at least once for every class 
correct_metatable(wolf) 
correct_metatable(goat) 
correct_metatable(cabbage) 
... 
+0

通常情况下,MC被混淆了,所以我需要将逻辑函数名称模糊化,以便用户不必知道混淆的名称。问题是我无法每嘀嘀嘀咕Lua文件(每秒20次)。我需要以某种方式将函数重定向到混淆函数。 – Rule 2013-03-20 16:04:35

+1

@Hackingroelz - 它需要改变大量metatables(每个类使用)。 – 2013-03-20 16:15:42

+0

那么,我将不得不改变我给一个函数的每个对象的metatable?这是否会造成很多滞后?我可以添加一个调用Java方法的全局函数,但是如果没有,当然会更好。 – Rule 2013-03-20 16:23:37