 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Reaper79 Advanced Cheater
Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Sat Nov 28, 2020 6:25 pm Post subject: LUA access user defined symbols ? |
|
|
Hi,
don't want to dig out an old thread:
https://www.cheatengine.org/forum/viewtopic.php?t=588191&start=0&postdays=0&postorder=asc&highlight=&sid=2c001b93b9b0f926eb15bf9984bfb94d
So my question in 2020 is, is it possible to access the current "user defined symbols" with LUA ?
My first approach to get the user defined symbols and clear them all, works only if you open the user defined symbols form once...
| Code: | function _clearSymbols()
local frm = nil
for i = 0, getFormCount() - 1 do
frm = getForm(i)
if (frm.Caption == 'Symbol config' and frm.ClassName == 'TfrmSymbolhandler') then break end
frm = nil
end
if frm ~= nil then
for i = 0, frm.Listview1.Items.Count - 1 do
unregisterSymbol(frm.Listview1.Items.Item[i].Caption)
end
end
end |
if you put it in following, it works:
| Code: | MainForm.OnProcessOpened = function(pid, handle, name)
_clearSymbols()
end |
But how i said, it works only, if you opened the symbol form once....
Maybe you could open the form at start and hide it with script ^^
PS: Don't ask why i want to delete all symbols, it's just cosmetic
|
|
| Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Sun Nov 29, 2020 1:38 pm Post subject: |
|
|
Well, it was quite tricky, unless you define a new registersymbol2, as you cannot really override the original command, nor use the lua registerSymbol function.
registerSymbolLookupCallback can be improved, as it passes addresses for to be defined symbols, and symbols for already defined symbols.
Anyway here's a code hopefully it suits your needs
| Code: | -- one way is to define registersymbol2 to capture the symbol name;
local capturedSymbols = {};
registerAutoAssemblerCommand('registersymbol2',function(symbol,syntaxcheck)
if (syntaxcheck) then
return true;
end
capturedSymbols[symbol] = true;
return ('registersymbol(%s)'):format(symbol);
end);
function clearSymbols(param, syntaxcheck)
if (not syntaxcheck) then
for symbol in pairs(capturedSymbols) do
unregistersymbol(symbol);
end
end
return true;
end
registerAutoAssemblerCommand('clearSymbols',clearSymbols);
-- different way is perhaps using registerSymbolLookupCallback; place in autorun;
local possibleSymbols = {};
local registersymbol_callback = function(symbol,int)
local isAddr = tonumber(symbol,16);
if (isAddr) then
print('added new addr',symbol);
-- it seems that cheat engine passes new defined symbols as addresses; would be much better if it passed as symbol:address;
if (not possibleSymbols[isAddr]) then
table.insert(possibleSymbols,isAddr);
possibleSymbols[isAddr] = true; -- cache; avoid duplicate items;
end
end
return symbol;
end
function clearSymbols2()
local addr = possibleSymbols[1];
while (addr) do
local isSymbol = getNameFromAddress(addr,false,true); -- addr can be hexadecimal and getNameFromAddress will return hexadecimal..
while isSymbol do
if (tonumber(isSymbol,16)) then -- no more symbols...
break;
end
unregisterSymbol(isSymbol);
isSymbol = getNameFromAddress(addr,false,true);
end
table.remove(possibleSymbols,1);
addr = possibleSymbols[1]
end
end
if (callback_id) then
unregisterSymbolLookupCallback(callback_id);
end
callback_id = registerSymbolLookupCallback(registersymbol_callback,slStart); |
Edit:
Just wanted to clarify, that the reason why I placed a second while loop in clearSymbols2 function is because I registered several symbols that point to the very same location (I'm lazy), so running it in a loop ensures that nothing remains pointing to any captured address
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
panraven Grandmaster Cheater
Reputation: 62
Joined: 01 Oct 2008 Posts: 959
|
Posted: Sun Nov 29, 2020 4:25 pm Post subject: |
|
|
My attemp:
https://pastebin.com/RAQt4KC2
can be save as an autorun extension.
_________________
- Retarded. |
|
| Back to top |
|
 |
Reaper79 Advanced Cheater
Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Thu Dec 03, 2020 11:00 am Post subject: |
|
|
Thank you very much, both of you.
I will try out the solutions
|
|
| Back to top |
|
 |
Reaper79 Advanced Cheater
Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Sun Dec 06, 2020 7:37 pm Post subject: |
|
|
Quick and dirty solution:
| Code: |
local DEBUG = true
function clearUserDefinedSymbols()
local mv,sf = getMemoryViewForm()
if not mv.frmSymbolhandler then
local mvHidden
if not mv.Visible then mvHidden=true,mv.Show() end
mv.miuserdefinedsymbols:OnClick()
if mvHidden then mv.hide()end
sf = mv.frmSymbolhandler
sf.Hide()
else
sf = mv.frmSymbolhandler
end
if sf ~= nil then
local symbol
for i = 0, sf.Listview1.Items.Count - 1 do
symbol = sf.Listview1.Items.Item[i].Caption
unregisterSymbol(symbol)
if DEBUG then print(('Unregistering symbol %s'):format(symbol)) end
end
end
end
MainForm.OnProcessOpened = function(pid, handle, name)
clearUserDefinedSymbols()
end |
This works if the target or CE crashes. The user-defined-symbols will be cleared / deleted
Thanks to panraven !!!
|
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 98
Joined: 14 Jul 2007 Posts: 3340
|
Posted: Mon Dec 07, 2020 3:43 am Post subject: |
|
|
| Reaper79 wrote: | Quick and dirty solution:
...
Thanks to panraven !!! |
You know, I was just about to ask if this exists.
Good work guys, I think you should ask Dark Byte to build this into the CE distribution.
Took a copy and will shamelessly use it in my auto-attach scripts in the future
Like so:
| Code: | PROCESS_NAME = 'MyEXE.exe'
--------
-------- Check for process and auto attach if need be
--------
local autoAttachTimer = nil ---- Declaration for our static timer object (no destroy here!)
local autoAttachTimerInterval = 5000 ---- Timer in milliseconds
function clearUserDefinedSymbols()
local mv,sf = getMemoryViewForm()
if not mv.frmSymbolhandler then
local mvHidden
if not mv.Visible then mvHidden=true,mv.Show() end
mv.miuserdefinedsymbols:OnClick()
if mvHidden then mv.hide()end
sf = mv.frmSymbolhandler
sf.Hide()
else
sf = mv.frmSymbolhandler
end
if sf ~= nil then
local symbol
for i = 0, sf.Listview1.Items.Count - 1 do
symbol = sf.Listview1.Items.Item[i].Caption
unregisterSymbol(symbol)
end
end
end
local function autoAttachTimer_tick(timer) ---- Timer callback
---- Check to see if we are attached to the right process
if getProcessIDFromProcessName(PROCESS_NAME) ~= getOpenedProcessID() then
---- If not the right process, check if process is running and attach if exists
AddressList.disableAllWithoutExecute()
if getProcessIDFromProcessName(PROCESS_NAME) ~= nil then
clearUserDefinedSymbols()
openProcess(PROCESS_NAME) ---- Open the process
end
end
end
autoAttachTimer = createTimer(getMainForm()) ---- Create timer with the main form as it's parent
autoAttachTimer.Interval = autoAttachTimerInterval ---- Set timer interval
autoAttachTimer.OnTimer = autoAttachTimer_tick ---- Set timer tick call back
|
|
|
| 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
|
|