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 


Writing 20 MB of globalalloc'd memory to zeros

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
BanCheese
Cheater
Reputation: 0

Joined: 22 Oct 2014
Posts: 49

PostPosted: Thu Nov 20, 2014 2:36 am    Post subject: Writing 20 MB of globalalloc'd memory to zeros Reply with quote

I have a program that I wrote that reads a file into memory (using readRegionFromFile). This file could be rather large (up to 20 MB), so I'm using globalalloc. The problem is that, when I need to read the file into memory again, unless it has gotten longer or stayed the same length, there will be extra, leftover bytes at the end of the memory region. How can I make sure that it is zero'd before I read? I can use either assembly or lua, either one works. Thanks!
_________________
A guy who likes memory hacking.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Mon Nov 24, 2014 7:05 am    Post subject: Reply with quote

All you need to do is write one 0 at the end of the new filesize. That will terminate textfiles
_________________
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
BanCheese
Cheater
Reputation: 0

Joined: 22 Oct 2014
Posts: 49

PostPosted: Tue Nov 25, 2014 2:20 am    Post subject: Reply with quote

Hm, I suppose you're right. How, though, can I find the size of the file that I read in? I know I can use writeByte from there to zero-terminate it, but I need to know what address to terminate at.
_________________
A guy who likes memory hacking.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Nov 25, 2014 3:04 am    Post subject: Reply with quote

This lua function will get you the filesize in bytes
Code:

function getFileSize(filename)
  local f=io.open(filename)
  local length=f:seek("end")
  f:close()
  return length
end

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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