|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 211
|
Posted: Sat Apr 20, 2024 5:44 am Post subject: Import/Export Data |
|
|
Hello Hitler,
I was trying to export referenced strings as text. I once asked if I could export symbols and got helped by @ParkourPenguin. And he made me this code. Now I realise I need to export referenced strings and referenced functions (separately) as text.
Is it possible to help me add four more drop-down options:
- Export strings
- Export functions
- Export dissect code
- Import dissect code
And is it possible for those to be exported to where the CheatTable is saved, and be named according to the process's title?
e.g.:[Title] - Dissect code.txt
Thank you, in advance.
Code: | local savedialog = createSaveDialog()
savedialog.Title = 'Save Symbols'
savedialog.DefaultExt = '.txt'
savedialog.Filter = 'textfiles (*.txt)|*.txt'
savedialog.Options = '[ofOverwritePrompt, ofHideReadOnly, ofEnableSizing]'
function exportMainSymbols()
local sd_result = savedialog.Execute()
if not sd_result then return end
local filename = savedialog.FileName
if not filename or filename == '' then return end
local t = {}
for k,v in pairs(getSymbolList().getSymbolList()) do
t[#t+1] = { address = v, name = k }
end
table.sort(t, function(lhs, rhs) return lhs.address < rhs.address end)
local sl = createStringList()
for _,sym in ipairs(t) do
sl.add(('%08X: %s'):format(sym.address, sym.name))
end
local saveResult = sl.saveToFile(filename)
sl.destroy()
if not saveResult then
showMessage('Could not save to file '..filename)
end
end
local miExtensions = MainForm.findComponentByName'miLuaExtensions'
if not miExtensions then
miExtensions = createMenuItem(MainForm)
miExtensions.Name = 'miLuaExtensions'
miExtensions.Caption = 'Lua Extensions'
MainForm.Menu.Items.insert(MainForm.Menu.Items.Count - 1, miExtensions)
end
local mi = createMenuItem(MainForm)
mi.Name = 'miExportSymbols'
mi.Caption = 'Export Symbols'
mi.OnClick = exportMainSymbols
miExtensions.add(mi) |
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 147
Joined: 06 Jul 2014 Posts: 4518
|
Posted: Sat Apr 20, 2024 2:01 pm Post subject: |
|
|
Game Hacking Dojo wrote: | Code: | for k,v in pairs(getSymbolList().getSymbolList()) do |
|
Should be:
Code: | for k,v in pairs(getMainSymbolList().getSymbolList()) do | related topic here:
https://forum.cheatengine.org/viewtopic.php?t=621523
Open the "Dissect Code" window in memory viewer -> tools -> dissect code
Under the "File" menu should be open / save
If you need it to save as plain text (e.g. viewing in notepad), you can encode it as text yourself:
celua.txt wrote: | DissectCode class: (Inheritance: Object)
getDissectCode() : Creates or returns the current code DissectCode object
properties:
methods:
...
getReferences(address) : Returns a table containing the addresses that reference this address and the type
getReferencedStrings(): Returns a table of addresses and their strings that have been referenced. Use getReferences to find out which addresses that are
getReferencedFunctions(): Returns a table of functions that have been referenced. Use getReferences to find out which callers that are
|
I don't know how you want them formatted, but the general idea is something like:
Code: | local refStrings = {}
for k,v in pairs(getDissectCode().getReferencedStrings()) do
refStrings[#refStrings+1] = { address = k, val = v }
end
table.sort(refStrings, function(lhs, rhs) return lhs.address < rhs.address end)
local sl = createStringlist()
for _,ref in ipairs(refStrings) do
sl.add(('%s : %s'):format(getNameFromAddress(ref.address), ref.val)
end
... |
Code: | local refFunctions = getDissectCode().getReferencedFunctions() -- returns a sorted Lua array
local sl = createStringlist()
for _,addr in ipairs(refStrings) do
sl.add(getNameFromAddress(addr))
end
... |
If you also want the addresses that reference the strings/functions, as the documentation says, use getReferences(address). The type is one of jtCall, jtUnconditional, jtConditional, jtMemory as defined in defines.lua. I have no idea how you'd want to format that information.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 211
|
Posted: Sat Apr 20, 2024 3:03 pm Post subject: |
|
|
Okay, thank you I'll see what I can do about it. I do not know why I do not like Lua haha.
I didn't know about the dissect code one. Good to know.
|
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 211
|
Posted: Wed May 01, 2024 2:49 pm Post subject: |
|
|
Could you please help me with this?
I want to make an extension that would check if there is a dissect code in the cheat table directory. If there is not, get the dissect code and save it there.
But that is almost hitting my limits regarding cheat engine Lua scripting.
I want to add checks like:
- Is the process attached? (the name of the process could be returned even if it is detached so that does not work as a check)
- Did the dissect code succeed?
- Is there a cheat table saved?
Code: | local lfs = require("lfs")
local cheatTableDir = MainForm.OpenDialog1.InitialDir
local pattern = " - Dissect Code%.CDC$"
local function isDissectCodeAvailable()
for file in lfs.dir(cheatTableDir) do
if file:match(pattern) then
getDissectCode().loadFromFile(file)
print("Dissect Code has been loaded")
end
end
getDissectCode()
getDissectCode().saveToFile(cheatTableDir.."\\"..process:gsub('%.exe','').." - Dissect Code.CDC")
print("Dissect Code has been saved")
end |
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 34
Joined: 16 Feb 2017 Posts: 1418
|
Posted: Wed May 01, 2024 3:45 pm Post subject: |
|
|
You may want to connect this code to a timer that will constantly loop and read the selected process and put it in the autorun folder.
If you have such a thought, you should code it carefully to avoid getting a message loop that gets triggered again and again.
The code below will prompt you to load if there is a record with the selected action name. If there is no registration, it will warn you for registration.
Code: | local lfs = require("lfs")
local cheatTableDir = MainForm.OpenDialog1.InitialDir
local pattern = " - Dissect Code.CDC"
local check1 = false
local function isDissectCodeAvailable()
for file in lfs.dir(cheatTableDir) do
filenm1 = process:gsub('.exe','')..pattern
if file==filenm1 then
local ansver = messageDialog("Code with the same name was found in the list!\nLoad the found code?",mtConfirmation, mbYes, mbNo)
if ansver==mrYes then
getDissectCode().loadFromFile(file)
print("Dissect Code has been loaded")
check1=true
end
end
end
--getDissectCode()
if check1==false then
local ansver = messageDialog("No code record found in the list!\nSave existing code?",mtConfirmation, mbYes, mbNo)
if ansver==mrYes then
getDissectCode().saveToFile(cheatTableDir.."\\"..process:gsub('%.exe','').." - Dissect Code.CDC")
print("Dissect Code has been saved")
end
end
end
isDissectCodeAvailable() |
_________________
|
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 211
|
Posted: Wed May 01, 2024 4:32 pm Post subject: |
|
|
Yes, I want to add it to the autorun folder. However, I only want it to run when I attach the process. So, I want to check if the process is attached. And I could not find a check like that in the code you gave me. Thank you for the help. The check could be so simple and I think there are many ways to do it.
Edit:
I missed something important that I cannot result I am looking for by just using getDissectCode() I need to use the window. Or I am checking the source code and I found this:
Code: | for i:=0 to lbModuleList.items.count-1 do
begin
if lbModuleList.Selected[i] then
begin
getexecutablememoryregionsfromregion(tmoduledata(lbModuleList.Items.Objects[i]).moduleaddress,tmoduledata(lbModuleList.Items.Objects[i]).moduleaddress+tmoduledata(lbModuleList.Items.Objects[i]).modulesize,tempregions);
setlength(dissectcode.memoryregion,length(dissectcode.memoryregion)+length(tempregions));
for j:=0 to length(tempregions)-1 do
dissectcode.memoryregion[length(dissectcode.memoryregion)-length(tempregions)+j]:=tempregions[j];
end;
end;
//sort the regions so they are from big to small (bubblesort)
n:=length(dissectcode.memoryregion);
for i:=0 to n-1 do
begin
flipped:=false;
for j:=0 to n-2-i do
begin
if dissectcode.memoryregion[j+1].BaseAddress<dissectcode.memoryregion[j].BaseAddress then//swap
begin
temp:=dissectcode.memoryregion[j+1];
dissectcode.memoryregion[j+1]:=dissectcode.memoryregion[j];
dissectcode.memoryregion[j]:=temp;
flipped:=true;
end;
end;
if not flipped then break;
end;
btnStart.Caption:=rsStop;
timer1.Enabled:=true;
starttime:=gettickcount;
dissectcode.dowork; |
This is taking the module data but is it possible to make this in Lua?
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 34
Joined: 16 Feb 2017 Posts: 1418
|
Posted: Wed May 01, 2024 5:44 pm Post subject: |
|
|
autorun lua code:
Code: | local lfs = require("lfs")
local cheatTableDir = MainForm.OpenDialog1.InitialDir
local pattern = " - Dissect Code.CDC"
local check1 = false
local procName = ""
local function isDissectCodeAvailable()
for file in lfs.dir(cheatTableDir) do
filenm1 = process:gsub('.exe','')..pattern
procName = filenm1 -- save check name
if file==filenm1 then
local ansver = messageDialog("Code with the same name was found in the list!\nLoad the found code?",mtConfirmation, mbYes, mbNo)
if ansver==mrYes then
getDissectCode().loadFromFile(file)
--print("Dissect Code has been loaded")
check1=true
end
end
end
--getDissectCode()
if check1==false then
local ansver = messageDialog("No code record found in the list!\nSave existing code?",mtConfirmation, mbYes, mbNo)
if ansver==mrYes then
getDissectCode().saveToFile(cheatTableDir.."\\"..process:gsub('%.exe','').." - Dissect Code.CDC")
--print("Dissect Code has been saved")
end
end
end
MainForm.OnProcessOpened=function() -- CE Menu >> Help >> Lua Documentation >> Line:371
local ansver = messageDialog("Before exiting this process:\nDo you want to save the existing code?",mtConfirmation, mbYes, mbNo)
if ansver==mrYes then
getDissectCode().saveToFile(cheatTableDir.."\\"..procName)
end
isDissectCodeAvailable() -- CE Menu >> Help >> Lua Documentation >> line: 3112
end |
_________________
|
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 211
|
Posted: Thu May 02, 2024 6:29 am Post subject: |
|
|
Thank you, that worked.
This is exactly what I needed
Code: | MainForm.OnProcessOpened=function()
...
end |
|
|
Back to top |
|
|
|
|
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
|
|