【问题标题】:What's most efficient way to remove obfuscated names (Minecraft)?删除混淆名称(Minecraft)的最有效方法是什么?
【发布时间】:2013-03-09 18:10:18
【问题描述】:

我为 Minecraft 制作了一个允许 Lua 修改的模组。一切正常,但通常方法的名称在 MC 中被混淆了。使普通函数名称重定向到混淆名称的最佳方法是什么?

例如,用户为一个在右键单击时打印 hello world 的块编写脚本:

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

addChatMessage 应该调用 Java 方法 EntityPlayer.func_71035_c(String text)

【问题讨论】:

  • 尝试使用require'libname' 访问原始库。例如,(require'math').pi 获得非混淆 math.pi
  • 我说的是 Minecraft 方法。通常,所有方法都被混淆(func_number_a)。因此,如果我将 Player 对象作为参数,我将不得不调用 player:func_34323_c(text) 而不是 player:addChatMessage()。 MC 编码器包将方法/字段/类名称转换为逻辑名称(我有名称的文件)。
  • 您是否可以访问翻译算法(将func_34323_c 转换为addChatMessage)?是秘密吗?
  • 我有包含混淆名称和逻辑名称(用于字段、类和方法)的文件。真正的未混淆名称是未知的,但 MCP 的创建者只是为 func_34323_c 之类的方法命名。
  • 请显示此类文件的示例。

标签: java lua minecraft


【解决方案1】:
-- 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)
...

【讨论】:

  • 通常 MC 是混淆的,所以我需要对逻辑函数名称进行混淆,这样用户就不必知道混淆的名称。问题是我不能在每个滴答声(每秒 20 次)中混淆 Lua 文件。我需要以某种方式将函数重定向到混淆函数。
  • @Hackingroelz - 这需要更改大量的元表(对于使用的每个类)。
  • 那么,我将不得不更改我赋予函数的每个对象的元表?这真的会导致很多滞后吗?我可以添加一个全局函数来调用 Java 方法,但当然最好不要。
  • @Hackingroelz - 请参阅我附加的答案。这是一种纠正类元表的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-29
  • 1970-01-01
  • 2016-05-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多