ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Mon Mar 01, 2021 5:25 pm Post subject: |
|
|
It has been inherited from this topic.
https://forum.cheatengine.org/viewtopic.php?t=617226
A different approach is available in the code below.
Take what you need from within the code, leave the remaining code to other users.
Code: | if form2 then form2.destroy(); form2=nil end
form2 = createForm()
form2.Position = poDesktopCenter
form2.BorderStyle = bsDialog
form2.Width = 290
form2.Height = 300
form2.Caption = "All Process List"
local form2_listbox1 = createListBox(form2)
form2_listbox1.Left = 0
form2_listbox1.Top = 47
form2_listbox1.Width = form2.Width
form2_listbox1.Height = form2.Height - 85
local form2_listbox2 = createListBox(form2)
form2_listbox2.Left = 0
form2_listbox2.Top = 47
form2_listbox2.Width = form2.Width
form2_listbox2.Height = form2.Height - 85
form2_listbox2.visible = false
local form2_button1 = createButton(form2)
form2_button1.Left = 5
form2_button1.Top = form2.Height - 32
form2_button1.Width = 95
form2_button1.caption = "All Window List"
local form2_button2 = createButton(form2)
form2_button2.Left = 190
form2_button2.Top = form2.Height - 32
form2_button2.Width = 95
form2_button2.caption = "All Process List"
local form2_button3 = createButton(form2)
form2_button3.Left = 105
form2_button3.Top = form2.Height - 32
form2_button3.Width = 80
form2_button3.caption = "Memory Brow"
local form2_label1 = createLabel(form2)
form2_label1.Alignment="taCenter"
form2_label1.Left = 5
form2_label1.Top = 5
form2_label1.Width = 280
form2_label1.caption = "To activate the process, double click the selection\n(Press the 'F8' key to list the active window)"
form2_label1.Font.Style="fsBold"
form2_label1.Font.Size=9
form2_label1.AutoSize=false
------------------------------------------
local vsblist=1
local Desclist=1
function foreText()
pid = getForegroundProcess()
local Items = listbox_getItems(form2_listbox1)
strings_clear(Items)
local Items2 = listbox_getItems(form2_listbox2)
strings_clear(Items2)
local SL = createStringlist()
getWindowlist(SL)
all_handle = {}
list_process = {}
for i=0, strings_getCount(SL)-1 do
local string_handle = SL[i]
string_handle = string_handle:sub(10, 355)
all_handle[i] = findWindow(nil, string_handle)
--end
--for i=0, #all_handle-1 do
if executeCodeLocal('IsWindowVisible', all_handle[i-1]) == 1 then --User32. all_handle[i]
if vsblist==1 then
local pPID = (SL[i]:sub(1,8));
local pDesc=SL[i-1]
pDesc=pDesc:sub(10, 355)
strings_add(Items, pDesc)
strings_add(Items2, (SL[i]:sub(1,8)))
--print(Items2)
Desclist=2
else
if pid==PID then
strings_add(Items, SL[i-1])
end
end
end
end
if SL then SL.destroy(); Sl=nil end
end
form2_button2.OnClick=function()
local Items = listbox_getItems(form2_listbox1)
strings_clear(Items)
local SL = createStringlist()
getProcesslist(SL)
--list_process = {}
for i=0, strings_getCount(SL)-1 do
strings_add(Items, SL[i])
Desclist=1
end
if SL then SL.destroy(); Sl=nil end
end
--------------------------------------------------------
--Thanks Rafael
SmartAttach =
{
currentprocesslist = {}
}
pro11=""
function SmartAttach:process11(pro11)
if pro11=="" then
wanted_processes = { 'chrome.exe','plugin%-container.exe','Facebook Gameroom Browser.exe',
'Maxthon.exe','opera.exe','brave.exe','firefox.exe','torch.exe' }
else
wanted_processes = { pro11 }
end
return wanted_processes
end
function SmartAttach:Start(wanted11)
pro11=wanted11
SmartAttach:process11(wanted11)
self.form = (form2)
self.combobox = form2_listbox1 --UDF1.CEListBox1
--self:Attach(sender)
SmartAttach:RefreshList(wanted11)
end
------------------------------------------
local title=""
function windowTitle(pid)
w=getWindow(getForegroundWindow(), GW_HWNDFIRST)
pid=tonumber(pid)
prs=getWindowProcessID(getWindowCaption(pid))
while w and (w~=0) do
if getWindowProcessID(w)==pid then
result=(getWindowCaption(w)..' ('..getWindowClassName(w)..')')
title=result
Desclist=2
end
w=getWindow(w,GW_HWNDNEXT)
end
return result
end
---------------------------------------------
function SmartAttach.SortByKey(T,K,reverse)
if reverse==true then table.sort(T, function (a,b) return a[K] > b[K] end)
else table.sort(T, function (a,b) return a[K] < b[K] end) end
return T
end
function SmartAttach.ProcessMatch(s)
for _,v in pairs(SmartAttach:process11(pro11)) do--SmartAttach.wanted_processes) do
if s:match(v:lower()) then return true end
end
return false
end
function SmartAttach.gatherData()
local handle = io.popen( "tasklist.exe /fo csv" )
local processTable = {}
local skip = true
local tmp = nil
for line in handle:lines() do
if skip then skip = false
else
tmp = {}
for t in line:gmatch('\"(.-)\"') do
table.insert(tmp,t)
end
local processName = tmp[1]
if SmartAttach.ProcessMatch(processName:lower()) then
local PID = tmp[2]
local MemoryUsage = tmp[5]:gsub("[^%d]",'')+0 -- +0 converts to number
local entry = { processName=processName, PID=PID, MemoryUsage=MemoryUsage }
processTable[#processTable+1] = entry
end
end
end
handle:close()
return SmartAttach.SortByKey(processTable,'MemoryUsage',true)
end
function SmartAttach.RefreshList()
local items = SmartAttach.combobox.items
items.clear()
SmartAttach.currentprocesslist = SmartAttach.gatherData()
if ( #SmartAttach.currentprocesslist > 0 ) then
for _,v in ipairs( SmartAttach.currentprocesslist ) do
windowTitle(v.PID)
strings_add(items, string.format('%.1f',v.MemoryUsage/1024)..'MB - '..v.PID..' - '..v.processName)
Desclist=3
end
SmartAttach.combobox.ItemIndex = 0
else
return showMessage( "Couldn't find any useful process" )
end
end
-----------------------------------------------------------
form2_button1.OnClick=function()
vsblist=1 foreText()
end
local item=""
local item1=""
local opn=""
form2_listbox1.OnDblClick=function()
if Desclist==1 then
item = form2_listbox1.ItemIndex
item1 = form2_listbox1.Items
if item == -1 then return end
local process = item1[item]
process = process:sub(1,8)
process = "0x"..process
process = tonumber(process)
opn=openProcess(tonumber(process))
if opn~=nil then
--form2.Visible = false
else
showMessage("I could not open this transaction")
end
end
if Desclist==2 then
item = form2_listbox1.ItemIndex
--print(item)
item1 = form2_listbox2.items
if item == -1 then return end
local process = item1[item]
--print(process)
process = "0x"..process
process = tonumber(process)
opn=openProcess(tonumber(process))
if opn~=nil then
--form2.Visible = false
else
showMessage("I could not open this transaction")
end
end
if Desclist==3 then
item = form2_listbox1.ItemIndex
item1 = form2_listbox1.Items
if item == -1 then return end
local process = item1[item]
sleep(200)
process1 = string.match(process, '- (%d*) -')
process1 = tonumber(process1)
opn=openProcess(tonumber(process1))
if opn~=nil then
--form2.Visible = false
else
showMessage("I could not open this transaction")
end
end
end
form2_button3.OnClick=function() SmartAttach:Start("") end
if frm11 then frm11.destroy() frm11=nil end
frm11=createHotkey(function() sleep(200) vsblist=2 foreText() end, VK_F8)
|
For your questions, you can leave a comment on the relevant topic.
|
|