Конкатенация AOB в Lua

Мога да получа AOB от стойност от 4 байта (DWORD), като използвам тази функция на Cheat Engine Lua:

local bt = dwordToByteTable(1075734118)
for i, v in ipairs(bt) do
  print(i, string.format('%02x', v))
end

result = [[
1 66 
2 66 
3 1e 
4 40 
]]

но искам резултата като "66 66 1e 40".

  1. Как да зададете регулярния израз за това?.
  2. Ако имам таблица като тази:

    cd = { 1075734118, 1075734118, 1075996262, 1076953088, 1076651622, 1076953088, 1076835123 }

Как да получа AOB за всеки елемент на масата с изход номер 1?


person JoeFern    schedule 05.04.2020    source източник


Отговори (2)


Намерено решение:

cd = { 1075734118, 1075734118, 1075996262, 1076953088, 1076651622, 1076953088, 1076835123 }

function byte2aob(b) return type(b)=='number' and b<256 and b>=0 and string.format('%02X',b) or '??' end
function aob2byte(a) a = tonumber(a,16) return type(a)=='number' and a <256 and a>=0 and a or -1 end
function imap(t,f) local s={} for i=1,#t do s[i]=f(t[i]) end return s end
function n2bt(n,t) t=type(t)=='string' and t or 'dword'  return rawget(_G,t..'ToByteTable')(n) end
function t2aob(t,sep) return table.concat(imap(t,byte2aob),type(sep)=='string' and sep or ' ') end
function n2aob(n,t) return t2aob(n2bt(n,t)) end

for i = 1, #cd do
 print(n2aob(cd[i],'dword'))
end

result = [[
66 66 1E 40 
66 66 1E 40 
66 66 22 40 
00 00 31 40 
66 66 2C 40 
00 00 31 40 
33 33 2F 40 
]]
person JoeFern    schedule 05.04.2020

Опитайте този код:

print((string.format("%08x",1075734118):reverse():gsub("(.)(.)","%2%1 ")))
person lhf    schedule 05.04.2020
comment
Страхотно!, @lhf. Това е много просто. Ще го използвам. Благодаря - person JoeFern; 05.04.2020