Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25291 Location: The netherlands
|
Posted: Sat Aug 22, 2020 10:11 am Post subject: Memory Viewer mass address Edit |
|
|
This extension replaces the Edit function in the memoryview hexeditor with a version that replaces ALL bytes in the selection with the new value you've chosen
As requested by Branimir at https://forum.cheatengine.org/viewtopic.php?t=614951
Code: |
function fillMemory(address, length, bytetable)
--fills the memory from address to address+ength with the given bytetable
local i=0
while i<length do
local l=#bytetable
if i+l>length then
--cut down bytetable
local bytestoremove=(i+l)-length
for i=1,bytestoremove do
bytetable[1+l-i]=nil
end
end
writeBytes(address+i, bytetable)
i=i+#bytetable
end
end
StringToByteTable={} --table containing functions to convert a string formatted in a specific vartype to a bytetable
StringToByteTable[0]=function(v) return {math.floor(tonumber(v)) & 0xff} end --byte
StringToByteTable[1]=function(v) return wordToByteTable(math.floor(tonumber(v)) & 0xffff) end --word
StringToByteTable[2]=function(v) return dwordToByteTable(math.floor(tonumber(v)) & 0xffffffff) end --dword
StringToByteTable[3]=function(v) return qwordToByteTable(math.floor(tonumber(v))) end --qword
StringToByteTable[4]=function(v) return floatToByteTable(tonumber(v)) end --float
StringToByteTable[5]=function(v) return doubleToByteTable(tonumber(v)) end --double
StringToByteTable[6]=function(v) return stringToByteTable(v) end --double
StringToByteTable[7]=function(v)
local bytes = {}
for byte in v:gmatch("%w+") do table.insert(bytes, math.floor(tonumber(byte))) end
return bytes
end --aob
function forEachAndEveryNewForm(formclass, functiontocall)
local i
for i=0,getFormCount()-1 do
local f=getForm(i)
if f.ClassName==formclass then
functiontocall(f)
end
end
registerFormAddNotification(function(frm)
if frm.ClassName==formclass then
frm.registerFirstShowCallback(function(frm)
functiontocall(frm)
end)
end
end)
end
forEachAndEveryNewForm('TMemoryBrowser',function(frm)
local oldEditMenu=frm.Change1.OnClick
frm.Change1.OnClick=function(s)
_G.LastMemoryViewFormThatClickedEdit=frm
if oldEditMenu then
oldEditMenu(s)
end
end
--find the paintbox (doubleclick the hexview also starts the editor)
local i
for i=0,frm.ComponentCount-1 do
local c=frm.Component[i]
if c.ClassName=='TPaintBox' then
--found it
local oldDblClick=c.OnDblClick
c.OnDblClick=function(s)
_G.LastMemoryViewFormThatClickedEdit=frm --good thing that the editor is modal so there is only one at a time
if oldDblClick then
oldDblClick()
end
end
break;
end
end
end)
forEachAndEveryNewForm('TValueChangeForm',function(frm)
local mv=_G.LastMemoryViewFormThatClickedEdit
if mv==nil then
mv=getMemoryViewForm()
end
local startAddress
local stopAddress
if mv then
startAddress=mv.HexadecimalView.SelectionStart
stopAddress=mv.HexadecimalView.SelectionStop
end
frm.Caption=string.format("%x - %x", startAddress, stopAddress)
--override what happens when ok is clicked
local oldclick=frm.Button1.OnClick
frm.Button1.OnClick=function(s)
local vartype=frm.cbVarType.ItemIndex
local newvalue=frm.valuetext.Text
local bt=StringToByteTable[vartype](newvalue)
if bt==nil then
return oldclick(s)
else
print("#bt="..#bt)
fillMemory(startAddress, 1+(stopAddress-startAddress), bt)
frm.ModalResult=mrOK
end
end
end)
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|