Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Reading process total physical memory.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Mon Nov 25, 2013 4:10 pm    Post subject: Reading process total physical memory. Reply with quote

Hey DarkByte/mgr.inz.player.
Is there any feature to read process physical memory?
So sometimes users don't know what processes to pick, auto guess the process can work out well.

like let's say I have firefox, opera and chrome.
I have got all the processes list inside a table
Code:
 processes = {... processes}

So I'd love to do
Code:
 for _,proc in pairs(processes) do print(PhysicalMemoryUsage());  end

(useful if using high memory consuming games in your browser).

Or based the physical memory usage in the selected processes pick the 'best' process to attach.

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Nov 25, 2013 4:20 pm    Post subject: Reply with quote

Hmm, attach to process one by one.

Do "unknown initial value" 4-byte, writeable memory, newscan. Get number of results and quickly discard scan results. I say, it is possible.

I think I am able to create such Lua function - process suggester.

_________________
Back to top
View user's profile Send private message MSN Messenger
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Mon Nov 25, 2013 4:46 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
Hmm, attach to process one by one.

Do "unknown initial value" 4-byte, writeable memory, newscan. Get number of results and quickly discard scan results. I say, it is possible.

I think I am able to create such Lua function - process suggester.

newscan takes a while, and people who uses dual core or even laptops (average), it'll take them several minutes to attach.
That's why I asked this.

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25819
Location: The netherlands

PostPosted: Mon Nov 25, 2013 4:51 pm    Post subject: Reply with quote

execute tasklist.exe and parse it's output
_________________
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
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Nov 25, 2013 4:52 pm    Post subject: Reply with quote

@DaSpamer, I meant automated newscan, For example user press "suggest" button, and my Lua function will open each process from the list and do unknown scan.

Post your current work, I will add that "suggest" function (don't have time to create forms and etc.).




"it'll take them several minutes to attach."
It depends. We can try.
FlashPlayerPlugin which takes about 63MB have 974,848 results (unknown, 4-byte). It's pretty fast.

_________________
Back to top
View user's profile Send private message MSN Messenger
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Mon Nov 25, 2013 6:18 pm    Post subject: Reply with quote

@darkbyte, i'l check it out.
@mgr.inz.player, take for example chrome and laptop with dual core 1.2ghz.
id say itll take several minutes to scan through 10 processes.

im using my phone at the moment.

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Nov 25, 2013 7:36 pm    Post subject: Reply with quote

As I said, we have to try.

You know, we can configure "unknown initial value" scanning as we want, for example we can use flag "+W-X-C" and "alignmenttype fsmLastDigits" set to "00". It should be much faster.

Note:
"fsmLastDigits" set to "0" should be about 4 times faster than default "fsmAligned 4"
"fsmLastDigits" set to "00" should be about 16 times faster than "last digits set to 0" (64 times faster than default)

Maybe I'm wrong?




Launching tasklist.exe from Lua script. You will use os.execute
This function will always create a command window, and it will always halt your current process until the window finishes

_________________
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25819
Location: The netherlands

PostPosted: Mon Nov 25, 2013 8:33 pm    Post subject: Reply with quote

unknown initial value's first scan is not affected by fastscan
Also, io.popen works, which can open it without a command window and won't wait

_________________
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
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Nov 25, 2013 10:30 pm    Post subject: Reply with quote

"unknown initial value's first scan is not affected by fastscan"
Hmm, I thought it is, because:

For example, "first scan unknown":
fsmAligned 4 - I have "found: 735232"
fsmLastDigits 00 - I have "found: 11488"
(64 times less)

So, fastscan doesn't affect unknown, OK.




Maybe we can use this:
first scan, settings:
- value type: byte
- scan type: between
- HEX
- left value 00, right value FF
- +W-C-X
- fsmLastDigits 000 (three zeros)

Should be good right ?

_________________
Back to top
View user's profile Send private message MSN Messenger
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Tue Nov 26, 2013 12:41 am    Post subject: Reply with quote

Check the script below...
_________________
I'm rusty and getting older, help me re-learn lua.


Last edited by daspamer on Tue Nov 26, 2013 9:26 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Tue Nov 26, 2013 9:09 am    Post subject: Reply with quote

Full working script (example, you can test it using various browsers).
Got little bit lazy in.
Code:
local SmartAttach = {
                  wanted_processes = { 'chrome.exe'; 'plugin%-container.exe'; 'flashplayerplugin'; 'opera.exe'; 'iexplore.exe'; }; --> edit this.
                  currentprocesslist = { };
               };
function SmartAttach:Start()
   self.form = createForm(false);
   setProperty(self.form , "Position", "poScreenCenter")
   setProperty(self.form , "BiDiMode", "bdLeftToRight")
   self.form.Caption = 'Smart attach test';
   self.form.height = 70;
   self.form.width = 300;
   self.combobox = createComboBox(self.form);
   self.combobox.top = 10;
   self.combobox.left = 10;
   self.combobox.width = 120;
   self.button = createButton(self.form);
   self.button.Caption = 'Attach';
   self.button.top = 10;
   self.button.left = 140;
   self.button.onClick = function (sender) self:Attach(sender); end;
   self.button.width = 45;
   self.pickhighestmem = createButton(self.form);
   self.pickhighestmem.Caption = 'Pick Best Process';
   self.pickhighestmem.top = 10;
   self.pickhighestmem.left = 200;
   self.pickhighestmem.width = 95;
   self.pickhighestmem.onClick = function (sender) self:PickBestOne(sender) end;
   self:BuildFunctions();
   self.form.show();
   self.IntProcessData(); --> Building up the data.
   self.combobox.ItemIndex = 0;
end

function SmartAttach:BuildFunctions()
   self.SortByVarValue = function (t, var,method) method = method or '+'; local _t = {}; local __t = {}; local ___t = {}; for k, v in ipairs(t) do if _t[v[var]]==nil then _t[v[var]] = k else for i=1,100000 do if _t[v[var]+i*0.0000001] == nil then _t[v[var]+i*0.0000001] = k break end end end end for k, v in pairs(_t) do table.insert(__t, k); end if (method == '+' or method == nil) then table.sort(__t, function(a,b) return a > b end); elseif (method == '-') then table.sort(__t, function(a,b) return a < b end); end for k, v in ipairs(__t) do local varstart = v; local recno = _t[varstart]; local entry = t[recno]; ___t[k] = entry; end return ___t end;
   self.CompareProcess = function (Process) Process = self.RemoveCharacters(Process, ' '); for _,proc in pairs(self.wanted_processes) do if (string.find(Process:lower(),proc)) then return true,Process; end end return false end;
   self.RemoveCharacters = function (s,char,newchar) local output = s; newchar = newchar or ''; for i=1,output:len() do local pos = string.find(output:lower(), char:lower()); if pos then output = output:sub(1, pos-1) .. newchar .. output:sub(pos+1); end end return output; end;
   self.getPid = function (PID) PID = self.RemoveCharacters(PID, ' '); return tonumber(PID); end;
   self.getMemory = function (Memory) Memory = self.RemoveCharacters(Memory, ' '); Memory = self.RemoveCharacters(Memory, 'k'); Memory = self.RemoveCharacters(Memory, ','); return tonumber(Memory); end;
   self.getData = function () local handle = io.popen("tasklist.exe"); local output = handle:read("*a"); handle:close(); for line in string.gfind (output,"[^\n]+") do local _proccess = string.sub(line,1,30); local result,_process =  self.CompareProcess(_proccess); if result then local _pid = string.sub(line,31,35); local _pid = self.getPid(_pid); local _mem = string.sub(line,64,78); local _mem = self.getMemory(_mem); self.currentprocesslist[#self.currentprocesslist+1] = { process = _process; pid = _pid; mem = _mem;}; end end; self.currentprocesslist = self.SortByVarValue(self.currentprocesslist, 'mem'); end;
   self.IntProcessData = function () local items = self.combobox.items; strings_clear(items); self.currentprocesslist = {}; self.getData(); if (#self.currentprocesslist>0) then for _,tab in pairs(self.currentprocesslist) do strings_add(items, tab.process); end return; end return showMessage("Error, desired process was not found."); end;
end

function SmartAttach:PickBestOne()
   self.IntProcessData() --> building up the data again, incase it was updated
   self.combobox.ItemIndex = 0;
   -- Since we've sorted the process list based memory (first entry is the highest), we can instantly attach to the first process.
   -- Although we'd probably want to open the process and check what addresses that are specificly valid for it, works.
   -- But I'll with the lazy way.
   self:Attach(1) --> id
end

function SmartAttach:Attach(PID)
   local index = self.combobox.ItemIndex
   if index < 0 then
      return
   end
   openProcess(self.currentprocesslist[tonumber(PID) or index + 1].pid);
end
SmartAttach:Start()


mgr.inz.Player wrote:
@DaSpamer, I meant automated newscan, For example user press "suggest" button, and my Lua function will open each process from the list and do unknown scan.

Post your current work, I will add that "suggest" function (don't have time to create forms and etc.).




"it'll take them several minutes to attach."
It depends. We can try.
FlashPlayerPlugin which takes about 63MB have 974,848 results (unknown, 4-byte). It's pretty fast.

Try to make it fit with above function.
Also FlashPlayerPlugin takes 63 MB when it was started and the flash object has been closed (Like it's in Stand by mode..).
The moment you open a game, it jumps to 200MB to 1.5GB (depends on the game).

_________________
I'm rusty and getting older, help me re-learn lua.


Last edited by daspamer on Tue Nov 26, 2013 1:18 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Nov 26, 2013 10:20 am    Post subject: Reply with quote

If using external tool like tasklist.exe is OK for you. You can change topic to [SOLVED].

Btw. Could you post "sort" function again (with indentation), I see something weird there "*0.0000001"

_________________
Back to top
View user's profile Send private message MSN Messenger
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Tue Nov 26, 2013 1:03 pm    Post subject: Reply with quote

Heres the code.
Code:
function SortByVarValue(t, var,method)
   method = method or '+';
   local _t = {};
   local __t = {};
   local ___t = {};
   for k, v in ipairs(t) do
      if _t[v[var]]==nil then
         _t[v[var]] = k
      else
         for i=1,1000000 do
            if _t[v[var]+i*0.0000001] == nil then -->quick fix because if _t[v[var]] exists the value would get overwritten.
               _t[v[var]+i*0.0000001] = k
               break
            end
         end
      end
   end
   for k, v in pairs(_t) do
      table.insert(__t, k);
   end
   if (method == '+' or method == nil) then
      table.sort(__t, function(a,b) return a > b end);
   elseif (method == '-') then
      table.sort(__t, function(a,b) return a < b end);
   end

   for k, v in ipairs(__t) do
      local varstart = v;
      local recno = _t[varstart];
      local entry = t[recno];
      ___t[k] = entry;
   end
   return ___t
end

By using that script, I can do the following
Sort table based
Quote:
main_table->child_table->var.

Example
Code:

t =       {
         { name = 'Shon'; gender = 'Male'; age = 23  };
         { name = 'Amenda'; gender = 'Female'; age = 18 };
         { name = 'Nicole'; gender = 'Female'; age = 20 };
         { name = 'Charlie'; gender = 'Male'; age = 23 };
      };
t = SortByVarValue(t , 'age', '-'); --> sort table from the smallest to the biggest.
for _,tab in pairs(t) do
    print('name = ' .. tab.name .. '; gender = ' .. tab.gender .. '; age = '.. tab.age ..';');
end
--[[
   name = Amenda; gender = Female; age = 18;
   name = Nicole; gender = Female; age = 20;
   name = Shon; gender = Male; age = 23;
   name = Charlie; gender = Male; age = 23;
--]]


Detailed explanation of my script,
Code:
function SortByVarValue(t, var,method)
   method = method or '+';
   local _t = {};
   local __t = {};
   local ___t = {};
   for k, v in ipairs(t) do
      if _t[v[var]]==nil then --> checking if t[number] == equals to nil (example, t = table, v = child table, var = varible inside child tables (that holds a number), output example _t[18] (first table))
         _t[v[var]] = k --> storing the inside _t[age] the table entry position from the main table.
      else --> if the entry we want to use it taken already we must to store it somewhere that is not far (so it could be still sorted and be added right after the first value).
         for i=1,1000000 do --> so I use here this small loop (incase there's more cases like this).
            if _t[v[var]+i*0.0000001] == nil then --> we found empty entry to store the value (for example age is 5, and it position in the table is 5.0000001).
               _t[v[var]+i*0.0000001] = k --> storing the inside _t[age] the table entry position from the main table.
               break --> breaking out the loop.. duhh..
            end
         end
      end
   end
   for k, v in pairs(_t) do
      table.insert(__t, k); --> insert the entries to a new table.... (like the age position in the table before).
   end
   if (method == '+' or method == nil) then -->sorting the table the highest to the lowest or from the lowest to highest.. (based the 3rd parameter).
      table.sort(__t, function(a,b) return a > b end);
   elseif (method == '-') then
      table.sort(__t, function(a,b) return a < b end);
   end

   for k, v in ipairs(__t) do
      local varstart = v; --> age (as index inside the table).
      local recno = _t[varstart]; --> since the __t index is sorted by age, so we're basically getting the entry[age] from _t table.. anyway, it returns the table t, child tables in order.
      local entry = t[recno]; --> getting the actual table
      ___t[k] = entry; --> appending the table to the index k (1,2,3,4...n)..alt. I could do ___t[#___t+1].
   end
   return ___t
end


Also, I won't change yet the title, maybe let's try to create the memory scan based method?


Edit:
Update, I had an mistake.
I forgot I send the object who called the attach method too, which messes up the part where I do
Code:
pid or index+1

So change this function
Code:
function SmartAttach:Attach(pid)
   local index = self.combobox.ItemIndex
   if index < 0 then
      return
   end
   openProcess(self.currentprocesslist[pid or index+1].pid);
end

to this
Code:
function SmartAttach:Attach(PID)
   local index = self.combobox.ItemIndex
   if index < 0 then
      return
   end
   openProcess(self.currentprocesslist[tonumber(PID) or index + 1].pid);
end

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Nov 26, 2013 4:01 pm    Post subject: Reply with quote

I just asked because I'm using simpler sort function:
Code:

people = {
         { name = 'Shon'; gender = 'Male'; age = 23  };
         { name = 'Amenda'; gender = 'Female'; age = 18 };
         { name = 'Nicole'; gender = 'Female'; age = 20 };
         { name = 'Charlie'; gender = 'Male'; age = 23 };
    }

function sortthis(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

people = sortthis(people,'age')

for _,v in pairs(people) do
    print('name = ' .. v.name .. '; gender = ' .. v.gender .. '; age = '.. v.age ..';');
end

_________________
Back to top
View user's profile Send private message MSN Messenger
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Tue Nov 26, 2013 4:57 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
I just asked because I'm using simpler sort function:
Code:

people = {
         { name = 'Shon'; gender = 'Male'; age = 23  };
         { name = 'Amenda'; gender = 'Female'; age = 18 };
         { name = 'Nicole'; gender = 'Female'; age = 20 };
         { name = 'Charlie'; gender = 'Male'; age = 23 };
    }

function sortthis(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

people = sortthis(people,'age')

for _,v in pairs(people) do
    print('name = ' .. v.name .. '; gender = ' .. v.gender .. '; age = '.. v.age ..';');
end

Lmao, how did I miss that? D:

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites