Dark Byte Site Admin
  Reputation: 470
  Joined: 09 May 2003 Posts: 25807 Location: The netherlands
  | 
		
			
				 Posted: Mon Feb 24, 2020 10:24 am    Post subject: Copy code snapshot | 
				       | 
			 
			
				
  | 
			 
			
				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  | 
			 
		  |