Last active
January 17, 2022 22:53
-
-
Save Autoplay1999/5c683989202cc30f5b67343c89579e32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function var_dump(v) | |
function table_dump(val,num) | |
local space = ""; | |
if num == nil then | |
num = 0; | |
else | |
for i = 0, num - 1 do | |
space = space .. " "; | |
end | |
end | |
for k, v in pairs(val) do | |
local vt = type(v); | |
if vt == "table" then | |
print(space .. "[" .. k .. "] => Table"); | |
print(space .. "("); | |
table_dump(v, num + 1); | |
print(space .. ")"); | |
elseif vt == "boolean" then | |
if v then | |
print(space .. "[" .. k .. "] => true"); | |
else | |
print(space .. "[" .. k .. "] => false"); | |
end | |
elseif vt == "string" then | |
print(space .. "[" .. k .. "] => \"" .. v .. "\""); | |
elseif vt == "nil" then | |
print("nil"); | |
else | |
print(space .. "[" .. k .. "] => " .. v); | |
end | |
end | |
end | |
local vt = type(v); | |
if vt == "table" then | |
table_dump(v,0); | |
elseif vt == "boolean" then | |
if v then | |
print("true"); | |
else | |
print("false"); | |
end | |
elseif vt == "nil" then | |
print("nil"); | |
else | |
print(v); | |
end | |
end | |
function CreateStructNode(Base, Offset, Level, Parent) | |
if Offset == nil then | |
Offset = 0 | |
end | |
if Level == nil then | |
Level = 0 | |
end | |
return { Base = Base, Offset = Offset, Level = Level, Scanned = false, Locked = false, ParentNode = Parent, ChildNodes = {}, FoundOffset = {} } | |
end | |
function IsInRegion(Address, VisitedList, RegionSize) | |
for x,y in ipairs(VisitedList) do | |
if Address >= y and Address < (y + RegionSize) then | |
return true | |
end | |
end | |
table.insert(VisitedList, Address) | |
return false | |
end | |
function ScanValue(Value, StartAddress, StructSize, MaxLevel) | |
local path = {} | |
local out = {} | |
local buffer = {} | |
local visitedList = {} | |
local root = CreateStructNode(StartAddress) | |
local curNode = root | |
table.insert(visitedList, curNode.Base) | |
while curNode ~= nil do | |
if not curNode.Scanned then | |
buffer = readBytes(curNode.Base, StructSize, true) | |
if buffer == nil then | |
return nil | |
end | |
for i = 0, (StructSize / 4) - 1 do | |
local curValue = buffer[i*4+1] | (buffer[i*4+2] << 0x8) | (buffer[i*4+3] << 0x10) | (buffer[i*4+4] << 0x18) | |
if curValue ~= 0 and readInteger(curValue) ~= nil then | |
if curValue == Value then | |
table.insert(curNode.FoundOffset, i * 4) | |
curNode.Locked = true | |
end | |
if curNode.Level < MaxLevel and not IsInRegion(curValue, visitedList, StructSize) then | |
table.insert(curNode.ChildNodes, CreateStructNode(curValue, i * 4, curNode.Level + 1, curNode)) | |
end | |
end | |
end | |
curNode.Scanned = true | |
end | |
local res = nil | |
if #curNode.ChildNodes ~= 0 then | |
for nid, n in ipairs(curNode.ChildNodes) do | |
if not n.Scanned then | |
res = n | |
break | |
end | |
end | |
end | |
if res == nil then | |
local curBase = curNode.Base | |
local isLock = curNode.Locked | |
curNode = curNode.ParentNode | |
if curNode ~= nil then | |
if not isLock then | |
if #curNode.ChildNodes ~= 0 then | |
for nid, n in ipairs(curNode.ChildNodes) do | |
if n.Base == curBase then | |
table.remove(curNode.ChildNodes, nid) | |
break | |
end | |
end | |
end | |
else | |
curNode.Locked = true | |
end | |
end | |
else | |
curNode = res | |
end | |
end | |
curNode = root | |
while curNode ~= nil do | |
local res = nil | |
if #curNode.ChildNodes ~= 0 then | |
for nid, n in ipairs(curNode.ChildNodes) do | |
if n.Scanned then | |
res = n | |
break | |
end | |
end | |
end | |
if res == nil then | |
for index, offset in ipairs(curNode.FoundOffset) do | |
local newPath = {} | |
table.insert(path, offset) | |
for x,y in pairs(path) do | |
table.insert(newPath, y) | |
end | |
table.insert(out, newPath) | |
table.remove(path, #path) | |
end | |
curNode = curNode.ParentNode | |
if curNode ~= nil then | |
table.remove(curNode.ChildNodes, 1) | |
table.remove(path, #path) | |
end | |
else | |
curNode = res | |
table.insert(path, curNode.Offset) | |
end | |
end | |
return out | |
end | |
function DumpResultScanValue(Result) | |
local str = "" | |
local out = {} | |
if Result ~= nil then | |
for x,y in ipairs(Result) do | |
for z,w in ipairs(y) do | |
if z > 1 then | |
str = str.. " - > " | |
end | |
str = str .. string.format("%X", w) | |
end | |
table.insert(out, str) | |
str = "" | |
end | |
end | |
return out | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment