551 lines
20 KiB
Plaintext
551 lines
20 KiB
Plaintext
[ENABLE]
|
|
{$lua}
|
|
local function inspectReturnHook()
|
|
local names={code='PBZ_RD_Code',hook='PBZ_RD_Hook',original='PBZ_RD_Original',
|
|
block='PBZ_RD_Block',parry='PBZ_RD_Parry',config='PBZ_RD_Config'}
|
|
local out={};local count=0
|
|
for k,n in pairs(names) do local a=getAddressSafe(n);if a and a~=0 then out[k]=a;count=count+1 end end
|
|
if count==0 then return end
|
|
if count~=6 then error('Return Defense: restore symbols are incomplete') end
|
|
for _,k in ipairs({'original','block','parry','config'}) do
|
|
if out[k]<out.code or out[k]+32>=out.code+0x2000 then error('Return Defense: symbol outside its allocation') end
|
|
end
|
|
if readQword(out.config)~=0x50425A5245543033 then error('Return Defense: incompatible hook version') end
|
|
if readInteger(out.config+8)~=getOpenedProcessID() then error('Return Defense: process changed; refusing writes') end
|
|
local b=readBytes(out.hook,14,true)
|
|
if not b or #b~=14 or b[1]~=0xFF or b[2]~=0x25 or b[3]~=0 or b[4]~=0 or b[5]~=0 or b[6]~=0
|
|
or readQword(out.hook+6)~=out.code then error('Return Defense: jump ownership changed') end
|
|
local original=readBytes(out.original,14,true)
|
|
local expected={0x48,0x8B,0x42,0x20,0x4D,0x8B,0xC8,0x48,0x8B,0x08,0x48,0x83,0xC0,0x08}
|
|
if not original or #original~=14 then error('Return Defense: saved bytes unreadable') end
|
|
for i=1,14 do if original[i]~=expected[i] then error('Return Defense: original bytes mismatch') end end
|
|
local tail=readBytes(out.hook+14,11,true)
|
|
local expectedTail={0x48,0x89,0x42,0x20,0x48,0x8B,0x82,0x80,0,0,0}
|
|
if not tail or #tail~=11 then error('Return Defense: continuation unreadable') end
|
|
for i=1,11 do if tail[i]~=expectedTail[i] then error('Return Defense: continuation changed') end end
|
|
out.blockValue=readBytes(out.block,1);out.parryValue=readBytes(out.parry,1)
|
|
if (out.blockValue~=0 and out.blockValue~=1) or (out.parryValue~=0 and out.parryValue~=1) then error('Return Defense: invalid mode flags') end
|
|
return out
|
|
end
|
|
local mode='parry'
|
|
local existing=inspectReturnHook()
|
|
if existing then
|
|
if existing[mode..'Value']~=0 then error('This Auto Defense mode is already enabled') end
|
|
return ('%X:\n db 1\n'):format(existing[mode])
|
|
end
|
|
if rawget(_G,'PBZ_AutoDefense') or (getAddressSafe('PBZ_AP_Code') or 0)~=0 or (getAddressSafe('PBZ_ID_Code') or 0)~=0 then
|
|
error('Disable the previous defense entries before using return-based v3')
|
|
end
|
|
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",executor="48 8B 42 20 4D 8B C8 48 8B 08 48 83 C0 08 48 89 42 20 48 8B 82 80 00 00 00 48 89 4A 30 48 39 08 74 ?? 48 8B 40 10 48 39 08 75 ?? 4C 8B 40 08 4C 89 42 38 4D 85 C9"}
|
|
local state={pid=getOpenedProcessID(),nameCache={},classCache={}}
|
|
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)]={address=f,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)
|
|
local worldSlot=wr+7+readInteger(wr+3,true)
|
|
local nr=uniqueScan(signatures.names)+0x1C
|
|
state.namePool=nr+7+readInteger(nr+3,true)
|
|
local function derives(cl,name)
|
|
local seen={}
|
|
for i=1,32 do
|
|
if not ptr(cl) or seen[cl] then return end;seen[cl]=true
|
|
if fname(cl+0x18)==name then return cl end
|
|
cl=q(cl+0x40)
|
|
end
|
|
end
|
|
local function functionObject(cl,name)
|
|
local seen={}
|
|
for d=1,32 do
|
|
if not ptr(cl) or seen[cl] then return end;seen[cl]=true
|
|
local f=q(cl+0x48);local visited={}
|
|
for i=1,2048 do
|
|
if not ptr(f) or visited[f] then break end;visited[f]=true
|
|
if fname(f+0x18)==name then return f end
|
|
f=q(f+0x28)
|
|
end
|
|
cl=q(cl+0x40)
|
|
end
|
|
end
|
|
local world=q(worldSlot);assert(ptr(world),'Load a save before enabling Auto Defense')
|
|
local giOffset=offset(classOf(world),'OwningGameInstance')
|
|
local gi=q(world+giOffset);assert(ptr(gi),'No local game instance')
|
|
local playersOffset=offset(classOf(gi),'LocalPlayers')
|
|
local players,n=array(gi+playersOffset,8);assert(players and n>0,'No local player')
|
|
local lp=q(players);assert(ptr(lp),'No first local player')
|
|
local controllerOffset=offset(classOf(lp),'PlayerController')
|
|
local pc=q(lp+controllerOffset);assert(ptr(pc),'No local controller')
|
|
local pawnOffset=offset(classOf(pc),'Pawn');local pawn=q(pc+pawnOffset)
|
|
assert(ptr(pawn) and derives(classOf(pawn),'BP_Player_Base_C'),'No supported local pawn')
|
|
local asc=q(pawn+offset(classOf(pawn),'AbilitySystemComponent'))
|
|
assert(ptr(asc) and q(asc+0x20)==pawn,'No locally owned ability system')
|
|
local container=field(classOf(asc),'ActivatableAbilities',true)
|
|
local items=field(container.type,'Items',true)
|
|
local inner=q(items.address+0x78)
|
|
local specType=ptr(inner) and q(inner+0x70)
|
|
local stride=ptr(inner) and readInteger(inner+0x34)
|
|
assert(ptr(specType) and stride and stride>=0x40 and stride<=0x1000,'Unsupported ability spec layout')
|
|
local specs,count=array(asc+container.offset+items.offset,1024)
|
|
assert(specs and count>0,'No granted abilities')
|
|
local canClass,resultClass,canFunction,resultFunction,ownerOffset
|
|
for i=0,count-1 do
|
|
local ability=q(specs+i*stride+offset(specType,'Ability'))
|
|
local cl=ptr(ability) and classOf(ability)
|
|
if ptr(cl) then
|
|
local passive=derives(cl,'BP_PlayerDeflectPassive_C')
|
|
local stance=derives(cl,'BP_StanceAction_Base_Player_C')
|
|
if passive then canClass=passive;canFunction=functionObject(cl,'Can Activate Ability On Frame') end
|
|
if stance then resultClass=stance;resultFunction=functionObject(cl,'Get Deflect Result') end
|
|
if passive or stance then
|
|
local f=field(cl,'CharacterBase',true)
|
|
assert(f.size==8 and (not ownerOffset or ownerOffset==f.offset),'Incompatible ability owner layout')
|
|
ownerOffset=f.offset
|
|
end
|
|
end
|
|
end
|
|
assert(canClass and resultClass and canFunction and resultFunction,'Equip a supported stance weapon first')
|
|
local canReturn=field(canFunction,'ReturnValue',true)
|
|
local resultReturn=field(resultFunction,'ReturnValue',true)
|
|
assert(canReturn.size==1 and canReturn.byte==0 and canReturn.mask==1,'Incoming-frame return ABI changed')
|
|
assert(resultReturn.size==8 and ptr(resultReturn.type) and fname(resultReturn.type+0x18)=='GameplayTag','Deflect result ABI changed')
|
|
assert(q(canFunction+0x128)==q(resultFunction+0x128),'Defense queries no longer share the expected script dispatcher')
|
|
local script,num=array(resultFunction+0xB0,100000)
|
|
assert(script and num>13,'Missing deflect result bytecode')
|
|
local bytes=readBytes(script,num,true);local tags={}
|
|
for i=1,num-13 do
|
|
if bytes[i]==0x21 and q(script+i+4)==0 then
|
|
local name=fname(script+i)
|
|
if name=='Deflect.Result.Normal' or name=='Deflect.Result.Perfect' then tags[name]=readInteger(script+i) end
|
|
end
|
|
end
|
|
assert(tags['Deflect.Result.Normal'] and tags['Deflect.Result.Perfect'],'Expected normal/perfect result tags not found')
|
|
local hook=uniqueScan(signatures.executor)
|
|
local cfg={hook=hook,worldSlot=worldSlot,gi=giOffset,players=playersOffset,
|
|
controller=controllerOffset,pawn=pawnOffset,owner=ownerOffset,
|
|
canName=q(canFunction+0x18),resultName=q(resultFunction+0x18),
|
|
canClassName=q(canClass+0x18),resultClassName=q(resultClass+0x18),
|
|
normalTag=tags['Deflect.Result.Normal'],perfectTag=tags['Deflect.Result.Perfect']}
|
|
local returnName
|
|
for _,f in ipairs({canFunction,resultFunction}) do
|
|
local start,n=array(f+0xB0,100000)
|
|
assert(start and n>=11,'Missing defense query return expression')
|
|
local operand=start+n-9
|
|
assert(readBytes(operand-2,1)==4 and readBytes(operand-1,1)==0x48 and readBytes(operand+8,1)==0x53,'Unsupported defense return expression')
|
|
local property=q(operand)
|
|
assert(ptr(property) and fname(property+0x20)=='ReturnValue','Defense return operand changed')
|
|
local name=q(property+0x20)
|
|
assert(not returnName or name==returnName,'Mismatched ReturnValue field names')
|
|
returnName=name
|
|
end
|
|
cfg.returnName=returnName
|
|
local definitions={}
|
|
local function define(k,v) definitions[#definitions+1]=('define(PBZ_RD_%s,%X)'):format(k,v) end
|
|
define('Hook',cfg.hook);define('WorldSlot',cfg.worldSlot);define('GI',cfg.gi)
|
|
define('Players',cfg.players);define('Controller',cfg.controller);define('Pawn',cfg.pawn)
|
|
define('Owner',cfg.owner);define('PID',state.pid);define('CanNameValue',cfg.canName)
|
|
define('ResultNameValue',cfg.resultName);define('CanClassValue',cfg.canClassName)
|
|
define('ResultClassValue',cfg.resultClassName);define('ReturnNameValue',cfg.returnName)
|
|
define('NormalValue',cfg.normalTag);define('PerfectValue',cfg.perfectTag)
|
|
define('BlockInitial',mode=='block' and 1 or 0);define('ParryInitial',mode=='parry' and 1 or 0)
|
|
return table.concat(definitions,'\n')..'\n'..[====[
|
|
alloc(PBZ_RD_Code,$2000)
|
|
label(PBZ_RD_Original)
|
|
label(PBZ_RD_Block)
|
|
label(PBZ_RD_Parry)
|
|
label(PBZ_RD_Config)
|
|
label(PBZ_RD_CanName)
|
|
label(PBZ_RD_ResultName)
|
|
label(PBZ_RD_CanClass)
|
|
label(PBZ_RD_ResultClass)
|
|
label(PBZ_RD_ReturnName)
|
|
label(PBZ_RD_Normal)
|
|
label(PBZ_RD_Perfect)
|
|
label(PBZ_RD_Eligible)
|
|
label(PBZ_RD_Blocks)
|
|
label(PBZ_RD_Parries)
|
|
label(PBZ_RD_Pass)
|
|
label(PBZ_RD_Can)
|
|
label(PBZ_RD_Result)
|
|
label(PBZ_RD_Tail)
|
|
label(PBZ_RD_CheckResultSize)
|
|
label(PBZ_RD_Class)
|
|
label(PBZ_RD_ClassLoop)
|
|
label(PBZ_RD_ResultClassCheck)
|
|
label(PBZ_RD_NextClass)
|
|
label(PBZ_RD_Local)
|
|
label(PBZ_RD_OutLoop)
|
|
label(PBZ_RD_Value)
|
|
label(PBZ_RD_ResultValue)
|
|
label(PBZ_RD_UseNormal)
|
|
registersymbol(PBZ_RD_Hook)
|
|
registersymbol(PBZ_RD_Code)
|
|
registersymbol(PBZ_RD_Original)
|
|
registersymbol(PBZ_RD_Block)
|
|
registersymbol(PBZ_RD_Parry)
|
|
registersymbol(PBZ_RD_Config)
|
|
registersymbol(PBZ_RD_Eligible)
|
|
registersymbol(PBZ_RD_Blocks)
|
|
registersymbol(PBZ_RD_Parries)
|
|
PBZ_RD_Code:
|
|
pushfq
|
|
push rax
|
|
push r9
|
|
push r10
|
|
push r11
|
|
cmp word ptr [PBZ_RD_Block],0
|
|
je PBZ_RD_Pass
|
|
test rdx,rdx
|
|
je PBZ_RD_Pass
|
|
test r8,r8
|
|
je PBZ_RD_Pass
|
|
cmp [rdx+18],rcx
|
|
jne PBZ_RD_Pass
|
|
mov rax,[rdx+10]
|
|
test rax,rax
|
|
je PBZ_RD_Pass
|
|
mov r10,[rax+18]
|
|
cmp r10,[PBZ_RD_CanName]
|
|
je PBZ_RD_Can
|
|
cmp r10,[PBZ_RD_ResultName]
|
|
je PBZ_RD_Result
|
|
jmp PBZ_RD_Pass
|
|
PBZ_RD_Can:
|
|
mov r9d,1
|
|
jmp PBZ_RD_Tail
|
|
PBZ_RD_Result:
|
|
mov r9d,2
|
|
PBZ_RD_Tail:
|
|
mov r10,[rdx+20]
|
|
mov r11,[rax+B0]
|
|
test r11,r11
|
|
je PBZ_RD_Pass
|
|
mov eax,[rax+B8]
|
|
cmp eax,B
|
|
jb PBZ_RD_Pass
|
|
cmp eax,186A0
|
|
ja PBZ_RD_Pass
|
|
add r11,rax
|
|
sub r11,9
|
|
cmp r10,r11
|
|
jne PBZ_RD_Pass
|
|
cmp word ptr [r10-2],4804
|
|
jne PBZ_RD_Pass
|
|
cmp byte ptr [r10+8],53
|
|
jne PBZ_RD_Pass
|
|
mov r11,[r10]
|
|
test r11,r11
|
|
je PBZ_RD_Pass
|
|
mov rax,[r11+20]
|
|
cmp rax,[PBZ_RD_ReturnName]
|
|
jne PBZ_RD_Pass
|
|
cmp r9d,1
|
|
jne PBZ_RD_CheckResultSize
|
|
cmp dword ptr [r11+34],1
|
|
jne PBZ_RD_Pass
|
|
jmp PBZ_RD_Class
|
|
PBZ_RD_CheckResultSize:
|
|
cmp dword ptr [r11+34],8
|
|
jne PBZ_RD_Pass
|
|
PBZ_RD_Class:
|
|
mov rax,[rcx+10]
|
|
mov r10d,20
|
|
PBZ_RD_ClassLoop:
|
|
test rax,rax
|
|
je PBZ_RD_Pass
|
|
mov r11,[rax+18]
|
|
cmp r9d,1
|
|
jne PBZ_RD_ResultClassCheck
|
|
cmp r11,[PBZ_RD_CanClass]
|
|
je PBZ_RD_Local
|
|
jmp PBZ_RD_NextClass
|
|
PBZ_RD_ResultClassCheck:
|
|
cmp r11,[PBZ_RD_ResultClass]
|
|
je PBZ_RD_Local
|
|
PBZ_RD_NextClass:
|
|
mov rax,[rax+40]
|
|
dec r10d
|
|
jne PBZ_RD_ClassLoop
|
|
jmp PBZ_RD_Pass
|
|
PBZ_RD_Local:
|
|
mov r11,PBZ_RD_WorldSlot
|
|
mov rax,[r11]
|
|
test rax,rax
|
|
je PBZ_RD_Pass
|
|
mov rax,[rax+PBZ_RD_GI]
|
|
test rax,rax
|
|
je PBZ_RD_Pass
|
|
cmp dword ptr [rax+PBZ_RD_Players+8],1
|
|
jl PBZ_RD_Pass
|
|
cmp dword ptr [rax+PBZ_RD_Players+8],8
|
|
ja PBZ_RD_Pass
|
|
mov rax,[rax+PBZ_RD_Players]
|
|
test rax,rax
|
|
je PBZ_RD_Pass
|
|
mov rax,[rax]
|
|
test rax,rax
|
|
je PBZ_RD_Pass
|
|
mov rax,[rax+PBZ_RD_Controller]
|
|
test rax,rax
|
|
je PBZ_RD_Pass
|
|
mov rax,[rax+PBZ_RD_Pawn]
|
|
test rax,rax
|
|
je PBZ_RD_Pass
|
|
cmp [rcx+PBZ_RD_Owner],rax
|
|
jne PBZ_RD_Pass
|
|
mov r11,[rdx+20]
|
|
mov r11,[r11]
|
|
mov r10,[rdx+80]
|
|
mov eax,40
|
|
PBZ_RD_OutLoop:
|
|
test r10,r10
|
|
je PBZ_RD_Pass
|
|
cmp [r10],r11
|
|
je PBZ_RD_Value
|
|
mov r10,[r10+10]
|
|
dec eax
|
|
jne PBZ_RD_OutLoop
|
|
jmp PBZ_RD_Pass
|
|
PBZ_RD_Value:
|
|
mov r10,[r10+8]
|
|
test r10,r10
|
|
je PBZ_RD_Pass
|
|
cmp r9d,1
|
|
jne PBZ_RD_ResultValue
|
|
mov byte ptr [r10],1
|
|
lock inc qword ptr [PBZ_RD_Eligible]
|
|
jmp PBZ_RD_Pass
|
|
PBZ_RD_ResultValue:
|
|
cmp byte ptr [PBZ_RD_Parry],0
|
|
je PBZ_RD_UseNormal
|
|
mov rax,[PBZ_RD_Perfect]
|
|
mov [r10],rax
|
|
lock inc qword ptr [PBZ_RD_Parries]
|
|
jmp PBZ_RD_Pass
|
|
PBZ_RD_UseNormal:
|
|
mov rax,[PBZ_RD_Normal]
|
|
mov [r10],rax
|
|
lock inc qword ptr [PBZ_RD_Blocks]
|
|
PBZ_RD_Pass:
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop rax
|
|
popfq
|
|
readmem(PBZ_RD_Hook,$0E)
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_RD_Hook+0E
|
|
align 10
|
|
PBZ_RD_Original:
|
|
readmem(PBZ_RD_Hook,$0E)
|
|
align 8
|
|
PBZ_RD_Config:
|
|
dq 50425A5245543033
|
|
dd PBZ_RD_PID
|
|
dd 0
|
|
PBZ_RD_Block:
|
|
db PBZ_RD_BlockInitial
|
|
PBZ_RD_Parry:
|
|
db PBZ_RD_ParryInitial
|
|
align 8
|
|
PBZ_RD_CanName:
|
|
dq PBZ_RD_CanNameValue
|
|
PBZ_RD_ResultName:
|
|
dq PBZ_RD_ResultNameValue
|
|
PBZ_RD_CanClass:
|
|
dq PBZ_RD_CanClassValue
|
|
PBZ_RD_ResultClass:
|
|
dq PBZ_RD_ResultClassValue
|
|
PBZ_RD_ReturnName:
|
|
dq PBZ_RD_ReturnNameValue
|
|
PBZ_RD_Normal:
|
|
dq PBZ_RD_NormalValue
|
|
PBZ_RD_Perfect:
|
|
dq PBZ_RD_PerfectValue
|
|
PBZ_RD_Eligible:
|
|
dq 0
|
|
PBZ_RD_Blocks:
|
|
dq 0
|
|
PBZ_RD_Parries:
|
|
dq 0
|
|
PBZ_RD_Hook:
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_RD_Code
|
|
]====]
|
|
{$asm}
|
|
[DISABLE]
|
|
{$lua}
|
|
if syntaxcheck then return end
|
|
local function inspectReturnHook()
|
|
local names={code='PBZ_RD_Code',hook='PBZ_RD_Hook',original='PBZ_RD_Original',
|
|
block='PBZ_RD_Block',parry='PBZ_RD_Parry',config='PBZ_RD_Config'}
|
|
local out={};local count=0
|
|
for k,n in pairs(names) do local a=getAddressSafe(n);if a and a~=0 then out[k]=a;count=count+1 end end
|
|
if count==0 then return end
|
|
if count~=6 then error('Return Defense: restore symbols are incomplete') end
|
|
for _,k in ipairs({'original','block','parry','config'}) do
|
|
if out[k]<out.code or out[k]+32>=out.code+0x2000 then error('Return Defense: symbol outside its allocation') end
|
|
end
|
|
if readQword(out.config)~=0x50425A5245543033 then error('Return Defense: incompatible hook version') end
|
|
if readInteger(out.config+8)~=getOpenedProcessID() then error('Return Defense: process changed; refusing writes') end
|
|
local b=readBytes(out.hook,14,true)
|
|
if not b or #b~=14 or b[1]~=0xFF or b[2]~=0x25 or b[3]~=0 or b[4]~=0 or b[5]~=0 or b[6]~=0
|
|
or readQword(out.hook+6)~=out.code then error('Return Defense: jump ownership changed') end
|
|
local original=readBytes(out.original,14,true)
|
|
local expected={0x48,0x8B,0x42,0x20,0x4D,0x8B,0xC8,0x48,0x8B,0x08,0x48,0x83,0xC0,0x08}
|
|
if not original or #original~=14 then error('Return Defense: saved bytes unreadable') end
|
|
for i=1,14 do if original[i]~=expected[i] then error('Return Defense: original bytes mismatch') end end
|
|
local tail=readBytes(out.hook+14,11,true)
|
|
local expectedTail={0x48,0x89,0x42,0x20,0x48,0x8B,0x82,0x80,0,0,0}
|
|
if not tail or #tail~=11 then error('Return Defense: continuation unreadable') end
|
|
for i=1,11 do if tail[i]~=expectedTail[i] then error('Return Defense: continuation changed') end end
|
|
out.blockValue=readBytes(out.block,1);out.parryValue=readBytes(out.parry,1)
|
|
if (out.blockValue~=0 and out.blockValue~=1) or (out.parryValue~=0 and out.parryValue~=1) then error('Return Defense: invalid mode flags') end
|
|
return out
|
|
end
|
|
local mode='parry'
|
|
local existing=inspectReturnHook()
|
|
if not existing then error('Return Defense: missing restore state; no code changed') end
|
|
if existing[mode..'Value']~=1 then error('Return Defense: this mode is not owned by the entry') end
|
|
local other=mode=='block' and 'parry' or 'block'
|
|
if existing[other..'Value']==1 then return ('%X:\n db 0\n'):format(existing[mode]) end
|
|
return ('%X:\n readmem(%X,$0E)\n'):format(existing.hook,existing.original)..[====[
|
|
unregistersymbol(PBZ_RD_Hook)
|
|
unregistersymbol(PBZ_RD_Code)
|
|
unregistersymbol(PBZ_RD_Original)
|
|
unregistersymbol(PBZ_RD_Block)
|
|
unregistersymbol(PBZ_RD_Parry)
|
|
unregistersymbol(PBZ_RD_Config)
|
|
unregistersymbol(PBZ_RD_Eligible)
|
|
unregistersymbol(PBZ_RD_Blocks)
|
|
unregistersymbol(PBZ_RD_Parries)
|
|
dealloc(PBZ_RD_Code)
|
|
]====]
|
|
{$asm}
|