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 


Copy code snapshot

 
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: 457

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

PostPosted: Mon Feb 24, 2020 10:24 am    Post subject: Copy code snapshot Reply with quote

This will add a copy snapshot function to the memory viewer. It's similar to the one you get when you use generate aobscan script

Code:

function snapcode(address)
  local sl=createStringList()
  local results={}
  local selecteda=''
  local a=address
  local i
  local maxbytes=1
  for i=1,10 do
    a=getPreviousOpcode(a)
  end

  local d=createDisassembler()
  while a<address do
    local olda=a
    d.disassemble(a)
    local bytes=d.LastDisassembleData.bytes
    local instruction=d.LastDisassembleData.opcode..' '..d.LastDisassembleData.parameters

    a=a+#bytes
    if a>address then
      instruction='db '
      local c=address-olda
      local newbytes={}

      for i=1,c do
        newbytes[i]=bytes[i]
        instruction=instruction..string.format("%.2x ", bytes[i])
      end

      bytes=newbytes
    end



    local entry={}
    entry.address=getNameFromAddress(olda)
    entry.bytes=bytes
    entry.instruction=instruction

    maxbytes=math.max(maxbytes, #entry.bytes)

    results[#results+1]=entry
  end

  d.disassemble(address)
  local entry={}
  selecteda=getNameFromAddress(address)
  entry.address=getNameFromAddress(address)
  entry.bytes=d.LastDisassembleData.bytes
  entry.instruction=d.LastDisassembleData.opcode..' '..d.LastDisassembleData.parameters
  results[#results+1]=entry

  maxbytes=math.max(maxbytes, #entry.bytes)

  a=address+#d.LastDisassembleData.bytes
  for i=1,10 do
    d.disassemble(a)
    local bytes=d.LastDisassembleData.bytes
    local instruction=d.LastDisassembleData.opcode..' '..d.LastDisassembleData.parameters

    local entry={}
    entry.address=getNameFromAddress(a)
    entry.bytes=bytes
    entry.instruction=instruction
    maxbytes=math.max(maxbytes, #entry.bytes)

    results[#results+1]=entry

    a=a+#bytes
  end

  for i=1,#results do
    local isselection=results[i].address==selecteda

    if isselection then
      sl.add("// ---------- INJECTING HERE ----------")
    end

    local bytestring=''
    local j
    for j=1,#results[i].bytes do
      bytestring=bytestring..string.format("%.2x ",results[i].bytes[j])
    end

    while #bytestring<maxbytes*3 do
      bytestring=bytestring..'   '
    end

    sl.add(string.format("%s: %s %s", results[i].address, bytestring, results[i].instruction))

    if isselection then
      sl.add("// ---------- DONE INJECTING ----------")
    end
  end

  writeToClipboard(sl.Text)
  sl.destroy()
  d.destroy()
end


pm=getMemoryViewForm().DisassemblerView.PopupMenu
local mi=createMenuItem(pm)
mi.Caption='Copy snapshot'
mi.ShortCut=textToShortCut("Ctrl+Shift+Alt+C")
mi.OnClick=function(s)
  snapcode(getMemoryViewForm().DisassemblerView.SelectedAddress)
end

pm.Items.add(mi)


_________________
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