-
Notifications
You must be signed in to change notification settings - Fork 23
/
HexViewCopyNBytes.lua
44 lines (37 loc) · 1.53 KB
/
HexViewCopyNBytes.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--this script adds "Copy N Bytes to Clipboard option"
-- based on http://forum.cheatengine.org/viewtopic.php?p=5735612#5735612
local mv=getMemoryViewForm()
local oldmemorypopuponpopup
if miCopyNBytes~=nil then
miCopyNBytes.destroy()
miCopyNBytes=nil
mv.memorypopup.OnPopup=oldmemorypopuponpopup
oldmemorypopuponpopup=nil
end
miCopyNBytes=createMenuItem(mv.memorypopup)
miCopyNBytes.Name="miCopyNBytes"
miCopyNBytes.Caption="Copy N Bytes to clipboard"
miCopyNBytes.ShortCut=textToShortCut("Ctrl+Shift+B")
miCopyNBytes.OnClick=function()
local hv=mv.HexadecimalView
-- start at current selection
local start = inputQuery('Start', 'Starting address', ('%X'):format(mv.HexadecimalView.SelectionStart))
if not start then return end
-- start with current selection or 32
local numbytes = mv.HexadecimalView.SelectionStop-mv.HexadecimalView.SelectionStart
if not numbytes or numbytes == 0 then numbytes = 32 end
numbytes = inputQuery('Number of Bytes', 'Number of Bytes', numbytes)
if not numbytes then return end
numbytes = tonumber(numbytes)
if not numbytes then return end -- if it failed to convert
local format = '%02X '
local bytes = readBytes(start, numbytes, true)
if not bytes then print('failed to read bytes') return end
writeToClipboard(format:rep(#bytes):format(unpack(bytes)))
end
mv.memorypopup.Items.insert(mv.Cut1.MenuIndex-1, miCopyNBytes)
oldmemorypopuponpopup=mv.memorypopup.OnPopup
mv.memorypopup.OnPopup=function(s)
miCopyNBytes.Visible=true
return oldmemorypopuponpopup(s)
end