| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		HenryEx Expert Cheater
  Reputation: 2
  Joined: 18 Dec 2011 Posts: 100
 
  | 
		
			
				 Posted: Thu Sep 17, 2020 5:57 pm    Post subject: Get file size of an opened file | 
				       | 
			 
			
				
  | 
			 
			
				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 | 
		 | 
	
	
		  | 
	
	
		Corroder Grandmaster Cheater Supreme
  Reputation: 75
  Joined: 10 Apr 2015 Posts: 1668
 
  | 
		
			
				 Posted: Thu Sep 17, 2020 7:41 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				 	  | 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 | 
		 | 
	
	
		  | 
	
	
		atom0s Moderator
  Reputation: 205
  Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
  | 
		
			
				 Posted: Thu Sep 17, 2020 7:41 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				 	  | 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 | 
		 | 
	
	
		  | 
	
	
		Corroder Grandmaster Cheater Supreme
  Reputation: 75
  Joined: 10 Apr 2015 Posts: 1668
 
  | 
		
			
				 Posted: Thu Sep 17, 2020 7:48 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				@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 | 
		 | 
	
	
		  | 
	
	
		atom0s Moderator
  Reputation: 205
  Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
  | 
		
			
				 Posted: Thu Sep 17, 2020 8:00 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				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 | 
		 | 
	
	
		  | 
	
	
		Corroder Grandmaster Cheater Supreme
  Reputation: 75
  Joined: 10 Apr 2015 Posts: 1668
 
  | 
		
			
				 Posted: Thu Sep 17, 2020 8:24 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				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 | 
		 | 
	
	
		  | 
	
	
		 |