Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Memory Viewer mass address Edit

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 384

Joined: 09 May 2003
Posts: 22967
Location: The netherlands

PostPosted: Sat Aug 22, 2020 10:11 am    Post subject: Memory Viewer mass address Edit Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites