672 lines
24 KiB
Plaintext
672 lines
24 KiB
Plaintext
[ENABLE]
|
|
{$lua}
|
|
if syntaxcheck then return end
|
|
local queryPatterns={Row="4C 8D 9C 24 30 02 00 00 49 8B 5B 10 49 8B 73 28 49 8B E3 5F C3",Dust="48 8B 5C 24 38 48 8B 74 24 40 48 8B 7C 24 48 41 89 06 48 83 C4 20 41 5E C3",Cycle="4C 03 C8 4C 89 4A 20 8B 81 38 02 00 00 41 89 00 C3 CC 48 89 5C 24 08 48 89 6C 24 18",Enough="48 8B 5C 24 40 88 06 48 83 C4 20 5F 5E 5D C3 CC CC CC CC CC CC CC CC"}
|
|
local querySizes={Row=16,Dust=15,Cycle=16,Enough=14}
|
|
local signatures={world="48 8B 05 ?? ?? ?? ?? 48 85 C0 75 ?? 80 3D ?? ?? ?? ?? 02 72 ?? 48 8D 15 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 33 C0 48 83 C4 20 5B C3",names="89 03 48 8B C3 89 7B 04 48 8B 5C 24 48 48 83 C4 30 5F C3 80 3D ?? ?? ?? ?? 00 74 09 48 8D 05 ?? ?? ?? ?? EB 13 48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? C6 05 ?? ?? ?? ?? 01 0F 28 44 24 20",objects="44 8B 49 04 45 85 C9 74 ?? 8B 01 85 C0 78 ?? 3B 05 ?? ?? ?? ?? 7D ?? 8B C8 0F B7 C0 48 C1 E9 10 48 8D 14 40 48 8B 05 ?? ?? ?? ?? 48 8B 0C C8 4C 8D 04 D1"}
|
|
local state={pid=getOpenedProcessID(),classCache={},nameCache={}}
|
|
local function ptr(p) return type(p)=='number' and p>0x10000 and p<0x7FFFFFFFFFFF end
|
|
local function q(p) return ptr(p) and readQword(p) or nil end
|
|
local function finite(x) return type(x)=='number' and x==x and math.abs(x)<1e12 end
|
|
local function vector(p)
|
|
if not ptr(p) then return end
|
|
local x,y,z=readDouble(p),readDouble(p+8),readDouble(p+16)
|
|
if finite(x) and finite(y) and finite(z) then return {x,y,z} end
|
|
end
|
|
local function array(p,limit)
|
|
local data,num,cap=q(p),readInteger(p+8),readInteger(p+12)
|
|
if not num or not cap or num>limit or cap<num or cap>1000000 then return end
|
|
if num>0 and not ptr(data) then return end
|
|
return data,num
|
|
end
|
|
local function exactString(p,n,wide)
|
|
local bytes=readBytes(p,n*(wide and 2 or 1),true)
|
|
if not bytes or #bytes~=n*(wide and 2 or 1) then return '' end
|
|
if not wide then return string.char(table.unpack(bytes)) end
|
|
local chars={};local i=1
|
|
while i<=#bytes do
|
|
local unit=bytes[i]+bytes[i+1]*256;i=i+2
|
|
if unit>=0xD800 and unit<=0xDBFF and i<#bytes then
|
|
local low=bytes[i]+bytes[i+1]*256
|
|
if low>=0xDC00 and low<=0xDFFF then unit=0x10000+(unit-0xD800)*1024+low-0xDC00;i=i+2
|
|
else unit=0xFFFD end
|
|
elseif unit>=0xD800 and unit<=0xDFFF then unit=0xFFFD end
|
|
if unit==0 then break end
|
|
chars[#chars+1]=utf8.char(unit)
|
|
end
|
|
return table.concat(chars)
|
|
end
|
|
local function fname(p)
|
|
local id=readInteger(p)
|
|
if not id then return '' end
|
|
local text=state.nameCache[id]
|
|
if not text then
|
|
local block=id>>16
|
|
if block>8191 then return '' end
|
|
local b=q(state.namePool+0x10+block*8)
|
|
if not ptr(b) then return '' end
|
|
local entry=b+(id&0xFFFF)*2
|
|
local h=readSmallInteger(entry)
|
|
if not h then return '' end
|
|
local n=h>>6
|
|
if n<1 or n>1023 then return '' end
|
|
text=exactString(entry+2,n,(h&1)~=0)
|
|
if not text then return '' end
|
|
state.nameCache[id]=text
|
|
end
|
|
local number=readInteger(p+4)
|
|
if number and number>0 then text=text..'_'..tostring(number-1) end
|
|
return text
|
|
end
|
|
local function fstring(p)
|
|
local data,n=array(p,1024)
|
|
if not data or n<2 then return '' end
|
|
return exactString(data,n-1,true)
|
|
end
|
|
local function meta(cl)
|
|
if not ptr(cl) then return end
|
|
local nameId=q(cl+0x18)
|
|
local super=q(cl+0x40)
|
|
if not nameId or super==nil then return end
|
|
local old=state.classCache[cl]
|
|
if old and old.nameId==nameId and old.super==super then return old end
|
|
local m={nameId=nameId,super=super,name=fname(cl+0x18)}
|
|
state.classCache[cl]=m
|
|
return m
|
|
end
|
|
local function properties(cl)
|
|
local m=meta(cl);if not m then return {} end
|
|
if m.fields then return m.fields end
|
|
local fields={};local f=q(cl+0x50);local seen={}
|
|
for i=1,512 do
|
|
if not ptr(f) or seen[f] then break end
|
|
seen[f]=true
|
|
local off,size=readInteger(f+0x44),readInteger(f+0x34)
|
|
if off and off<0x100000 and size and size<0x100000 then
|
|
fields[fname(f+0x20)]={offset=off,size=size,type=q(f+0x70),
|
|
byte=readBytes(f+0x71,1),mask=readBytes(f+0x72,1)}
|
|
end
|
|
f=q(f+0x10)
|
|
end
|
|
m.fields=fields;return fields
|
|
end
|
|
local function field(cl,name,required)
|
|
local seen={}
|
|
for i=1,32 do
|
|
if not ptr(cl) or seen[cl] then break end
|
|
seen[cl]=true
|
|
local p=properties(cl)[name];if p then return p end
|
|
local m=meta(cl);cl=m and m.super
|
|
end
|
|
if required then error('Missing reflected field: '..name) end
|
|
end
|
|
local function offset(cl,name) return field(cl,name,true).offset end
|
|
local function classOf(a) return q(a+0x10) end
|
|
local function nativeFunction(cl,name)
|
|
local visited={}
|
|
for i=1,32 do
|
|
if not ptr(cl) or visited[cl] then break end
|
|
visited[cl]=true
|
|
local f=q(cl+0x48);local seen={}
|
|
for j=1,1024 do
|
|
if not ptr(f) or seen[f] then break end
|
|
seen[f]=true
|
|
if fname(f+0x18)==name then return q(f+0x128) end
|
|
f=q(f+0x28)
|
|
end
|
|
local m=meta(cl);cl=m and m.super
|
|
end
|
|
end
|
|
local function flag(a,f)
|
|
if not f or not f.byte or not f.mask then return false end
|
|
local b=readBytes(a+f.offset+f.byte,1)
|
|
return b and (b&f.mask)~=0
|
|
end
|
|
local function uniqueScan(pattern)
|
|
local scan=createMemScan();local found=createFoundList(scan)
|
|
local ok,result=pcall(function()
|
|
local base=getAddress('PBZ.exe')
|
|
scan.firstScan(soExactValue,vtByteArray,rtRounded,pattern,'',base,base+getModuleSize('PBZ.exe')-1,
|
|
'+X',fsmNotAligned,'1',true,false,false,false)
|
|
scan.waitTillDone();found.initialize()
|
|
if found.Count~=1 then error('ESP signature expected 1 match; found '..found.Count) end
|
|
return getAddress(found.Address[0])
|
|
end)
|
|
found.destroy();scan.destroy()
|
|
if not ok then error(result) end
|
|
return result
|
|
end
|
|
local wr=uniqueScan(signatures.world)
|
|
state.worldSlot=wr+7+readInteger(wr+3,true)
|
|
local nr=uniqueScan(signatures.names)+0x1C
|
|
state.namePool=nr+7+readInteger(nr+3,true)
|
|
local function fail(s) error('Free Traits: '..s) end
|
|
local function bytes(p,n)
|
|
local b=readBytes(p,n,true);if not b or #b~=n then fail('unreadable memory') end;return b
|
|
end
|
|
local function matches(p,pattern)
|
|
local b=readBytes(p,#pattern,true);if not b or #b~=#pattern then return false end
|
|
for i,x in ipairs(pattern) do if x~=-1 and b[i]~=x then return false end end;return true
|
|
end
|
|
local function displacement(p,n,pattern,index)
|
|
local hits={}
|
|
for i=0,n-#pattern do if matches(p+i,pattern) then hits[#hits+1]=p+i end end
|
|
if #hits~=1 then fail('unsupported native field reference') end
|
|
local v=readInteger(hits[1]+index,true)
|
|
if not v or v<0 or v>0x10000 or v%8~=0 then fail('unsupported native field offset') end
|
|
return v
|
|
end
|
|
local function context()
|
|
if getOpenedProcessID()~=state.pid then return end
|
|
local world=q(state.worldSlot);if not ptr(world) then return end
|
|
local gi=q(world+offset(classOf(world),'OwningGameInstance'))
|
|
if not ptr(gi) then return end
|
|
local players,n=array(gi+offset(classOf(gi),'LocalPlayers'),8)
|
|
if not players or not n or n<1 then return end
|
|
local lp=q(players);if not ptr(lp) then return end
|
|
local pc=q(lp+offset(classOf(lp),'PlayerController'));if not ptr(pc) then return end
|
|
local pawn=q(pc+offset(classOf(pc),'Pawn'));if not ptr(pawn) then return end
|
|
local f=field(classOf(pawn),'PBZAbilityNodes')
|
|
if not f or f.size~=8 then return end
|
|
local component=q(pawn+f.offset)
|
|
if not ptr(component) or q(component+0x20)~=pawn or fname(classOf(component)+0x18)~='PBZAbilityNodesComponent' then return end
|
|
local gate=field(classOf(component),'bForceUnLockRongShuZhiXin',true)
|
|
if gate.size~=1 or not gate.byte or not gate.mask or gate.mask==0 then fail('invalid branch-unlock flag') end
|
|
local destroy=field(classOf(pawn),'bActorIsBeingDestroyed',true)
|
|
if flag(pawn,destroy) then return end
|
|
return {world=world,gi=gi,pawn=pawn,component=component,class=classOf(component),
|
|
name=q(component+0x18),index=readInteger(component+0xC),gate=component+gate.offset+gate.byte,mask=gate.mask}
|
|
end
|
|
local initial=context();if not initial then fail('load the local player before enabling') end
|
|
local ref=uniqueScan(signatures.objects)
|
|
local chunks=q(ref+0x2B+readInteger(ref+0x27,true))
|
|
local count=readInteger(ref+0x15+readInteger(ref+0x11,true))
|
|
if not ptr(chunks) or not count or count<1 or count>2000000 then fail('unsupported object array') end
|
|
local queryClasses={};local widgetClass;local last=-1;local chunk
|
|
for i=0,count-1 do
|
|
local c=i>>16;if c~=last then chunk=q(chunks+c*8);last=c end
|
|
if ptr(chunk) then
|
|
local slot=chunk+(i&0xFFFF)*24;local flags=readInteger(slot+4)
|
|
if flags and (flags&0x10200000)==0 then
|
|
local ob=q(slot+8)
|
|
if ptr(ob) then local n=fname(ob+0x18)
|
|
if (n=='PBZAbilityNodesManager' or n=='AbilityNodeHelpObj' or n=='PBZGameSystem' or n=='PBZBackPackSubsystem')
|
|
and fname(classOf(ob)+0x18)=='Class' then queryClasses[n]=ob end
|
|
if n=='AbilityNodeStruct' and fname(classOf(ob)+0x18)=='ScriptStruct' then queryClasses[n]=ob end
|
|
end
|
|
if ptr(ob) and readInteger(ob+0xC)==i and fname(ob+0x18)=='W_AbilityWidget_C'
|
|
and fname(classOf(ob)+0x18)=='WidgetBlueprintGeneratedClass' then
|
|
if widgetClass then fail('ambiguous Traits widget class') end;widgetClass=ob
|
|
end
|
|
end
|
|
end
|
|
end
|
|
if not widgetClass then fail('open the Traits menu once before enabling') end
|
|
local userWidget=widgetClass
|
|
for i=1,32 do
|
|
if not ptr(userWidget) then fail('Traits widget ancestry changed') end
|
|
if fname(userWidget+0x18)=='UserWidget' then break end
|
|
userWidget=q(userWidget+0x40)
|
|
end
|
|
if fname(userWidget+0x18)~='UserWidget' then fail('UserWidget class missing') end
|
|
local tick=q(widgetClass+0x48)
|
|
for i=1,512 do
|
|
if not ptr(tick) then fail('open the Traits menu before enabling') end
|
|
if fname(tick+0x18)=='Tick__puerts_mixin__' then break end
|
|
tick=q(tick+0x28)
|
|
end
|
|
if fname(tick+0x18)~='Tick__puerts_mixin__' or fname(classOf(tick)+0x18)~='JSGeneratedFunction' then fail('unsupported Traits binding') end
|
|
local exec=q(tick+0x128)
|
|
local dynOffset=displacement(exec,0x110,{0x48,0x8B,0xB3,-1,-1,-1,-1,0x48,0x89,0x74,0x24,0x30},3)
|
|
local dyn=q(tick+dynOffset)
|
|
local control=q(tick+dynOffset+8)
|
|
if not ptr(dyn) or not ptr(control) or not readInteger(control+8) or readInteger(control+8)<1 then fail('expired script environment') end
|
|
local dynVtable=q(dyn);local hook=q(dynVtable+0x18)
|
|
if not matches(hook,{0x48,0x8B,0x49,-1,0x48,0x85,0xC9,0x0F,0x85,-1,-1,-1,-1,0xC3}) then fail('mixin dispatch entry changed') end
|
|
local parentOffset=readBytes(hook+3,1)
|
|
local env=q(dyn+parentOffset)
|
|
local invoke=hook+13+readInteger(hook+9,true)
|
|
local mapOffset=displacement(invoke,0x200,{0x48,0x8B,0x96,-1,-1,-1,-1,0x48,0x98,0x48,0x8D,0x0C,0x40},3)
|
|
local map=env+mapOffset
|
|
local data,slots=array(map,8192)
|
|
if not data or not slots then fail('script function map unavailable') end
|
|
local bits=q(map+0x20);local bitCount=readInteger(map+0x28)
|
|
if not ptr(bits) then bits=map+0x10;if not bitCount or bitCount>128 then fail('script map allocation flags changed') end end
|
|
if not bitCount or bitCount<slots then fail('script map allocation flags invalid') end
|
|
local handle
|
|
for i=0,slots-1 do
|
|
local word=readInteger(bits+math.floor(i/32)*4)
|
|
if word and (word & (1<<(i%32)))~=0 then
|
|
local p=data+i*24
|
|
if q(p)==tick then if handle then fail('duplicate script binding') end;handle=q(p+8) end
|
|
end
|
|
end
|
|
if not ptr(handle) then fail('Traits script is not bound') end
|
|
if not ptr(handle) then fail("Traits binding missing") end
|
|
local function untag(v) if ptr(v) and v&1==1 then return v-1 end end
|
|
local function instanceType(v)
|
|
local a=untag(v);local m=a and untag(q(a));return m and readSmallInteger(m+0xC)
|
|
end
|
|
local function menuMethods()
|
|
local fn=untag(q(handle));if not fn or instanceType(fn+1)~=2065 then fail('Traits binding moved; reopen menu') end
|
|
local ctx=q(fn+0x20)
|
|
local shared=untag(q(fn+0x18));local script=shared and q(shared+0x20)
|
|
local constructor
|
|
for p=(fn&~0xFFFF)-0x10000,(fn&~0xFFFF)+0x10000-64,8 do
|
|
if q(p+0x20)==ctx and instanceType(p+1)==2080 then
|
|
local s=untag(q(p+0x18))
|
|
if s and q(s+0x20)==script then
|
|
if constructor then fail('ambiguous Traits class constructor') end;constructor=p
|
|
end
|
|
end
|
|
end
|
|
if not constructor then fail('Traits class relocated; reopen menu and re-enable') end
|
|
local proto=untag(q(constructor+0x38))
|
|
local properties=proto and untag(q(proto+8))
|
|
if not properties or instanceType(properties+1)~=251 then fail('Traits prototype property array changed') end
|
|
local encoded=q(properties+8);local n=encoded and ((encoded>>32)&0x3FF)
|
|
if not n or n<32 or n>256 then fail('Traits prototype property count changed') end
|
|
local methods={};local foundTick=false
|
|
for i=0,n-1 do
|
|
local v=q(properties+0x10+i*8)
|
|
if instanceType(v)==2065 then
|
|
local f=untag(v);local s=untag(q(f+0x18))
|
|
if s and q(s+0x20)==script and q(f+0x20)==ctx then
|
|
methods[#methods+1]=v;if v==fn+1 then foundTick=true end
|
|
end
|
|
end
|
|
end
|
|
if #methods<32 or #methods>256 or not foundTick then fail('Traits prototype validation failed') end
|
|
return methods
|
|
end
|
|
local methods=menuMethods()
|
|
local rowStruct=assert(queryClasses.AbilityNodeStruct,'AbilityNodeStruct reflection missing')
|
|
for _,def in ipairs({{'NodeType',0x10,1},{'ConsumeDust',0x130,4},{'NeedMaterials',0xE0,0x50}}) do
|
|
local p=field(rowStruct,def[1],true)
|
|
if p.offset~=def[2] or p.size~=def[3] then fail('AbilityNodeStruct layout changed: '..def[1]) end
|
|
end
|
|
local nativeAddresses={}
|
|
local queries={Row={'PBZAbilityNodesManager','GetAbilityTableNodeData',0xB1},
|
|
Dust={'AbilityNodeHelpObj','GetConsumeDust',0x80},Cycle={'PBZGameSystem','GetCycleCount',0xE},
|
|
Enough={'PBZBackPackSubsystem','HasEnoughItem',0x109}}
|
|
for name,def in pairs(queries) do
|
|
local cl=assert(queryClasses[def[1]],'Native Traits query class unavailable: '..def[1])
|
|
local entry=assert(nativeFunction(cl,def[2]),'Native Traits UFunction unavailable: '..def[2])
|
|
local at=entry+def[3];local expected={}
|
|
for v in queryPatterns[name]:gmatch('%x%x') do expected[#expected+1]=tonumber(v,16) end
|
|
if not matches(at,expected) then fail('Native query instructions changed: '..def[2]) end
|
|
nativeAddresses[name]=at
|
|
end
|
|
local codeSymbol='PBZ_NT_Code'
|
|
local owner={pid=state.pid,context=context,handles={handle},menuMethods=menuMethods,methods=methods,addresses=nativeAddresses}
|
|
owner.symbolNames={'Code','Enabled','Methods','MethodCount','Low','High','PID','RowHits','DustHits','CycleHits','EnoughHits'}
|
|
for name in pairs(nativeAddresses) do owner.symbolNames[#owner.symbolNames+1]='Entry'..name;owner.symbolNames[#owner.symbolNames+1]='Backup'..name end
|
|
local old=rawget(_G,'PBZ_NativeTraits')
|
|
if old and old.pid==owner.pid then fail('Native Traits manager already exists') end
|
|
if old then
|
|
if old.timer then old.timer.destroy() end
|
|
for _,name in ipairs(owner.symbolNames) do unregisterSymbol('PBZ_NT_'..name) end
|
|
_G.PBZ_NativeTraits=nil
|
|
end
|
|
if getAddressSafe(codeSymbol) then fail('Native Traits has unowned restore symbols') end
|
|
local template=[==[
|
|
label(PBZ_NT_ClearMaterial)
|
|
alloc(PBZ_NT_Code,$6000)
|
|
label(PBZ_NT_Enabled)
|
|
label(PBZ_NT_Methods)
|
|
label(PBZ_NT_MethodCount)
|
|
label(PBZ_NT_Low)
|
|
label(PBZ_NT_High)
|
|
label(PBZ_NT_PID)
|
|
label(PBZ_NT_Filter)
|
|
label(PBZ_NT_FilterReturn)
|
|
label(PBZ_NT_FilterYes)
|
|
label(PBZ_NT_Scan)
|
|
label(PBZ_NT_Next)
|
|
label(PBZ_NT_Match)
|
|
label(PBZ_NT_EntryRow)
|
|
label(PBZ_NT_BackupRow)
|
|
label(PBZ_NT_OriginalRow)
|
|
label(PBZ_NT_EntryDust)
|
|
label(PBZ_NT_BackupDust)
|
|
label(PBZ_NT_OriginalDust)
|
|
label(PBZ_NT_EntryCycle)
|
|
label(PBZ_NT_BackupCycle)
|
|
label(PBZ_NT_OriginalCycle)
|
|
label(PBZ_NT_EntryEnough)
|
|
label(PBZ_NT_BackupEnough)
|
|
label(PBZ_NT_OriginalEnough)
|
|
label(PBZ_NT_RowHits)
|
|
label(PBZ_NT_DustHits)
|
|
label(PBZ_NT_CycleHits)
|
|
label(PBZ_NT_EnoughHits)
|
|
registersymbol(PBZ_NT_Code)
|
|
registersymbol(PBZ_NT_Enabled)
|
|
registersymbol(PBZ_NT_Methods)
|
|
registersymbol(PBZ_NT_MethodCount)
|
|
registersymbol(PBZ_NT_Low)
|
|
registersymbol(PBZ_NT_High)
|
|
registersymbol(PBZ_NT_PID)
|
|
registersymbol(PBZ_NT_RowHits)
|
|
registersymbol(PBZ_NT_DustHits)
|
|
registersymbol(PBZ_NT_CycleHits)
|
|
registersymbol(PBZ_NT_EnoughHits)
|
|
registersymbol(PBZ_NT_EntryRow)
|
|
registersymbol(PBZ_NT_BackupRow)
|
|
registersymbol(PBZ_NT_EntryDust)
|
|
registersymbol(PBZ_NT_BackupDust)
|
|
registersymbol(PBZ_NT_EntryCycle)
|
|
registersymbol(PBZ_NT_BackupCycle)
|
|
registersymbol(PBZ_NT_EntryEnough)
|
|
registersymbol(PBZ_NT_BackupEnough)
|
|
assert(PBZ_NT_Row,4C)
|
|
assert(PBZ_NT_Dust,48)
|
|
assert(PBZ_NT_Cycle,4C)
|
|
assert(PBZ_NT_Enough,48)
|
|
PBZ_NT_Code:
|
|
PBZ_NT_EntryRow:
|
|
pushfq
|
|
push rax
|
|
push rcx
|
|
push rdx
|
|
push r8
|
|
push r9
|
|
push r10
|
|
push r11
|
|
lea rcx,[rsp+40]
|
|
call PBZ_NT_Filter
|
|
test eax,eax
|
|
je PBZ_NT_OriginalRow
|
|
lock inc dword ptr [PBZ_NT_RowHits]
|
|
mov byte ptr [rsi+10],FF
|
|
mov dword ptr [rsi+130],0
|
|
mov ecx,[rsi+E8]
|
|
cmp ecx,80
|
|
ja PBZ_NT_OriginalRow
|
|
mov rax,[rsi+E0]
|
|
test rax,rax
|
|
je PBZ_NT_OriginalRow
|
|
test ecx,ecx
|
|
je PBZ_NT_OriginalRow
|
|
PBZ_NT_ClearMaterial:
|
|
mov dword ptr [rax+8],0
|
|
add rax,14
|
|
dec ecx
|
|
jne PBZ_NT_ClearMaterial
|
|
PBZ_NT_OriginalRow:
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rdx
|
|
pop rcx
|
|
pop rax
|
|
popfq
|
|
readmem(PBZ_NT_Row,$10)
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_NT_Row+10
|
|
PBZ_NT_EntryDust:
|
|
pushfq
|
|
push rax
|
|
push rcx
|
|
push rdx
|
|
push r8
|
|
push r9
|
|
push r10
|
|
push r11
|
|
lea rcx,[rsp+40]
|
|
call PBZ_NT_Filter
|
|
test eax,eax
|
|
je PBZ_NT_OriginalDust
|
|
lock inc dword ptr [PBZ_NT_DustHits]
|
|
mov qword ptr [rsp+30],0
|
|
PBZ_NT_OriginalDust:
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rdx
|
|
pop rcx
|
|
pop rax
|
|
popfq
|
|
readmem(PBZ_NT_Dust,$F)
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_NT_Dust+F
|
|
PBZ_NT_EntryCycle:
|
|
pushfq
|
|
push rax
|
|
push rcx
|
|
push rdx
|
|
push r8
|
|
push r9
|
|
push r10
|
|
push r11
|
|
lea rcx,[rsp+40]
|
|
call PBZ_NT_Filter
|
|
test eax,eax
|
|
je PBZ_NT_OriginalCycle
|
|
lock inc dword ptr [PBZ_NT_CycleHits]
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rdx
|
|
pop rcx
|
|
pop rax
|
|
popfq
|
|
readmem(PBZ_NT_Cycle,7)
|
|
mov dword ptr [r8],7FFFFFFF
|
|
mov eax,7FFFFFFF
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_NT_Cycle+10
|
|
PBZ_NT_OriginalCycle:
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rdx
|
|
pop rcx
|
|
pop rax
|
|
popfq
|
|
readmem(PBZ_NT_Cycle,$10)
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_NT_Cycle+10
|
|
PBZ_NT_EntryEnough:
|
|
pushfq
|
|
push rax
|
|
push rcx
|
|
push rdx
|
|
push r8
|
|
push r9
|
|
push r10
|
|
push r11
|
|
lea rcx,[rsp+40]
|
|
call PBZ_NT_Filter
|
|
test eax,eax
|
|
je PBZ_NT_OriginalEnough
|
|
lock inc dword ptr [PBZ_NT_EnoughHits]
|
|
mov byte ptr [rsp+30],1
|
|
PBZ_NT_OriginalEnough:
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rdx
|
|
pop rcx
|
|
pop rax
|
|
popfq
|
|
readmem(PBZ_NT_Enough,$E)
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_NT_Enough+E
|
|
PBZ_NT_Filter:
|
|
xor eax,eax
|
|
cmp dword ptr [PBZ_NT_Enabled],1
|
|
jne PBZ_NT_FilterReturn
|
|
mov r9,gs:[08]
|
|
lea r8,[rcx+2000]
|
|
cmp r8,r9
|
|
cmova r8,r9
|
|
sub r8,20
|
|
add rcx,8
|
|
PBZ_NT_Scan:
|
|
cmp rcx,r8
|
|
jae PBZ_NT_FilterReturn
|
|
mov r10,[rcx]
|
|
cmp r10,[PBZ_NT_Low]
|
|
jb PBZ_NT_Next
|
|
cmp r10,[PBZ_NT_High]
|
|
ja PBZ_NT_Next
|
|
cmp qword ptr [rcx-8],40
|
|
ja PBZ_NT_Next
|
|
mov r11,[rcx+10]
|
|
lea rdx,[rcx+20]
|
|
cmp r11,rdx
|
|
jb PBZ_NT_Next
|
|
cmp r11,r9
|
|
jae PBZ_NT_Next
|
|
test r11,7
|
|
jne PBZ_NT_Next
|
|
mov rdx,PBZ_NT_Methods
|
|
mov r11d,[PBZ_NT_MethodCount]
|
|
PBZ_NT_Match:
|
|
test r11d,r11d
|
|
je PBZ_NT_Next
|
|
cmp r10,[rdx]
|
|
je PBZ_NT_FilterYes
|
|
add rdx,8
|
|
dec r11d
|
|
jmp PBZ_NT_Match
|
|
PBZ_NT_Next:
|
|
add rcx,8
|
|
jmp PBZ_NT_Scan
|
|
PBZ_NT_FilterYes:
|
|
mov eax,1
|
|
PBZ_NT_FilterReturn:
|
|
ret
|
|
PBZ_NT_Code+2000:
|
|
PBZ_NT_Enabled:
|
|
dd 0
|
|
PBZ_NT_PID:
|
|
dd PROCESS_ID
|
|
PBZ_NT_MethodCount:
|
|
dd METHOD_COUNT
|
|
align 8
|
|
PBZ_NT_Low:
|
|
dq METHOD_LOW
|
|
PBZ_NT_High:
|
|
dq METHOD_HIGH
|
|
PBZ_NT_RowHits:
|
|
dd 0
|
|
PBZ_NT_BackupRow:
|
|
readmem(PBZ_NT_Row,$10)
|
|
PBZ_NT_DustHits:
|
|
dd 0
|
|
PBZ_NT_BackupDust:
|
|
readmem(PBZ_NT_Dust,$F)
|
|
PBZ_NT_CycleHits:
|
|
dd 0
|
|
PBZ_NT_BackupCycle:
|
|
readmem(PBZ_NT_Cycle,$10)
|
|
PBZ_NT_EnoughHits:
|
|
dd 0
|
|
PBZ_NT_BackupEnough:
|
|
readmem(PBZ_NT_Enough,$E)
|
|
align 8
|
|
PBZ_NT_Methods:
|
|
METHOD_DATA
|
|
PBZ_NT_Row:
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_NT_EntryRow
|
|
nop 2
|
|
PBZ_NT_Dust:
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_NT_EntryDust
|
|
nop 1
|
|
PBZ_NT_Cycle:
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_NT_EntryCycle
|
|
nop 2
|
|
PBZ_NT_Enough:
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_NT_EntryEnough
|
|
]==]
|
|
template=template:gsub('METHOD_DATA',function()
|
|
local s={};for _,v in ipairs(methods) do s[#s+1]=('dq %X'):format(v) end
|
|
for i=#methods+1,256 do s[#s+1]='dq 0' end;return table.concat(s,'\n')
|
|
end)
|
|
local low,high=methods[1],methods[1]
|
|
for _,v in ipairs(methods) do low=math.min(low,v);high=math.max(high,v) end
|
|
template=template:gsub('METHOD_COUNT',('%X'):format(#methods)):gsub('METHOD_LOW',('%X'):format(low)):gsub('METHOD_HIGH',('%X'):format(high))
|
|
template=template:gsub('PROCESS_ID',('%X'):format(owner.pid))
|
|
for name,a in pairs(nativeAddresses) do template=('define(PBZ_NT_%s,%X)\n'):format(name,a)..template end
|
|
owner.originals={}
|
|
for name,a in pairs(nativeAddresses) do owner.originals[name]=bytes(a,querySizes[name]) end
|
|
owner.restoreGate=function()
|
|
local c=owner.gate
|
|
if c and getOpenedProcessID()==owner.pid and q(c.component+0x18)==c.name and readInteger(c.component+0xC)==c.index then
|
|
local b=readBytes(c.gate,1);if b then
|
|
local target=(b&(~c.mask&0xFF))|(c.original&c.mask)
|
|
if target~=b then assert(writeBytes(c.gate,target),'Native Traits: branch flag restore failed') end
|
|
end
|
|
end
|
|
owner.gate=nil
|
|
end
|
|
owner.refresh=function()
|
|
if owner.pid~=getOpenedProcessID() then return end
|
|
local enabled=getAddressSafe('PBZ_NT_Enabled');local target=getAddressSafe('PBZ_NT_Methods')
|
|
if not enabled or not target then return end
|
|
local current=menuMethods();local changed=not owner.cachedMethods or #current~=#owner.cachedMethods
|
|
if not changed then for i,v in ipairs(current) do if v~=owner.cachedMethods[i] then changed=true;break end end end
|
|
if changed then
|
|
assert(writeInteger(enabled,0),'Native Traits: scope pause failed')
|
|
local lo,hi=current[1],current[1]
|
|
for i,v in ipairs(current) do assert(writeQword(target+(i-1)*8,v));lo=math.min(lo,v);hi=math.max(hi,v) end
|
|
assert(writeQword(getAddress('PBZ_NT_Low'),lo));assert(writeQword(getAddress('PBZ_NT_High'),hi))
|
|
assert(writeInteger(getAddress('PBZ_NT_MethodCount'),#current));owner.cachedMethods=current
|
|
end
|
|
local c=context()
|
|
if owner.gate and (not c or c.component~=owner.gate.component) then owner.restoreGate() end
|
|
if c then
|
|
if not owner.gate then c.original=assert(readBytes(c.gate,1));owner.gate=c end
|
|
local b=assert(readBytes(c.gate,1));assert(writeBytes(c.gate,b|c.mask))
|
|
end
|
|
assert(writeInteger(enabled,1))
|
|
owner.lastError=nil
|
|
end
|
|
owner.stop=function()
|
|
if owner.pid~=getOpenedProcessID() then
|
|
if owner.timer then owner.timer.destroy();owner.timer=nil end
|
|
local out={};for _,name in ipairs(owner.symbolNames) do out[#out+1]='unregistersymbol(PBZ_NT_'..name..')' end
|
|
_G.PBZ_NativeTraits=nil;return table.concat(out,'\n')
|
|
end
|
|
local code=getAddressSafe('PBZ_NT_Code');assert(code,'Native Traits: code allocation missing')
|
|
local text={}
|
|
for name,a in pairs(owner.addresses) do
|
|
local p=readBytes(a,6,true);local expected=assert(getAddressSafe('PBZ_NT_Entry'..name))
|
|
assert(p and table.concat(p,',')=='255,37,0,0,0,0' and q(a+6)==expected,'Native Traits: hook ownership changed for '..name)
|
|
local backup=assert(getAddressSafe('PBZ_NT_Backup'..name));local b=readBytes(backup,querySizes[name],true)
|
|
assert(b and table.concat(b,',')==table.concat(owner.originals[name],','),'Native Traits: invalid backup for '..name)
|
|
text[#text+1]=('%X:\n readmem(%X,$%X)'):format(a,backup,querySizes[name])
|
|
end
|
|
assert(writeInteger(getAddress('PBZ_NT_Enabled'),0));owner.restoreGate()
|
|
if owner.timer then owner.timer.destroy();owner.timer=nil end
|
|
for _,name in ipairs(owner.symbolNames) do
|
|
text[#text+1]='unregistersymbol(PBZ_NT_'..name..')'
|
|
end
|
|
_G.PBZ_NativeTraits=nil;return table.concat(text,'\n')
|
|
end
|
|
local timer=createTimer(nil,false);owner.timer=timer;timer.Interval=1000
|
|
timer.OnTimer=function()
|
|
if owner.pid~=getOpenedProcessID() then timer.Enabled=false;return end
|
|
local ok,e=pcall(owner.refresh)
|
|
if not ok then owner.lastError=tostring(e);local enabled=getAddressSafe('PBZ_NT_Enabled');if enabled then writeInteger(enabled,0) end end
|
|
end
|
|
_G.PBZ_NativeTraits=owner;timer.Enabled=true
|
|
return template
|
|
{$asm}
|
|
[DISABLE]
|
|
{$lua}
|
|
if syntaxcheck then return end
|
|
local s=rawget(_G,"PBZ_NativeTraits");assert(s,"Native Traits restore manager missing");return s.stop()
|
|
{$asm}
|