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 


Get file size of an opened file

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
HenryEx
Advanced Cheater
Reputation: 1

Joined: 18 Dec 2011
Posts: 76

PostPosted: Thu Sep 17, 2020 5:57 pm    Post subject: Get file size of an opened file Reply with quote

Pretty much what the subject line says - is there a way to retrieve the file size of a file you open with openFileAsProcess() ?

I scanned the celua file but didn't find anything that seems to do that.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Sep 17, 2020 7:41 pm    Post subject: Reply with quote

Code:
function fsize (file)
 local current = file:seek()
 local size = file:seek("end")
 file:seek("set", current)
 return size
end


function OpenFile()
 dialog = createOpenDialog(self)
 dialog.Title = "Select File"
 dialog.InitalDir = os.getenv('%USERPROFILE%')
 dialog.DefaultExt=".exe"
 dialog.Options ='[ofEnableSizing]'
 if dialog.execute() == false then return end
 FileName= dialog.FileName
 file = io.open(FileName,"r")
 print(fsize(file)..' bytes')
 file:close()
 dialog.destroy()
 openFileAsProcess(FileName,false)
 print('test a')
 version = AOBScan("00")
 if (version ~= nil) then
     print('test b ')
 end
end

OpenFile()

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 199

Joined: 25 Jan 2006
Posts: 8519
Location: 127.0.0.1

PostPosted: Thu Sep 17, 2020 7:41 pm    Post subject: Reply with quote

Code:

local modules = enumModules(process);
local mainModule = modules[1];
local size = getModuleSize(mainModule.Name);

print(size);


Has no error checking, so would suggest adding checks for valid returns. This will ask for the current selected process module list, then use the first (main module) to obtain the size of. (The first entry in the module list should always be the process that owns the module list being requested.)

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Sep 17, 2020 7:48 pm    Post subject: Reply with quote

@atom0s, is that using enumModules return the memory usage by opened process, not the file size?
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 199

Joined: 25 Jan 2006
Posts: 8519
Location: 127.0.0.1

PostPosted: Thu Sep 17, 2020 8:00 pm    Post subject: Reply with quote

To get on-disk size, you can use:
Code:

local modules = enumModules(process);
local mainModule = modules[1];
local f = io.open(mainModule.PathToFile, 'rb');
local size = f:seek('end');
f:close();

print(size);

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Sep 17, 2020 8:24 pm    Post subject: Reply with quote

Thanks atom0s...
I try open cheatengine.exe as process, the return size is size of CE Module.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
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