| 
			
				|  | Cheat Engine The Official Site of Cheat Engine
 
 
 |  
 
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| Loset Cheater
 
 ![]() Reputation: 0 
 Joined: 18 Apr 2015
 Posts: 34
 
 
 | 
			
				|  Posted: Wed May 08, 2019 3:32 pm    Post subject: allocating local variables before entring a function? |   |  
				| 
 |  
				| A function I'm calling from a new thread has 9 local variables. But as soon as I'm using it, It crashes the game, I only allocated memory for the function arguments but not for the local variables(taken from the stack) because I'm not sure how is that going to work?
 
 Like do you need to do it? If it's a local variable of the function why doesn't it allocate it on it's own?
 
 and if I need to allocate those variables how would that go?
 like
 
  	  | Code: |  	  | alloc(var1, 8) alloc(var2, 8)
 alloc(var3, 8)
 push var1
 push var2
 push var3
 | 
 
 I'm not sure exactly what I'm looking for, Just need a point in the right direction.
 |  |  
		| Back to top |  |  
		|  |  
		| Roogue Newbie cheater
 
 ![]() Reputation: 0 
 Joined: 31 May 2019
 Posts: 14
 
 
 | 
			
				|  Posted: Sat Jun 01, 2019 6:19 am    Post subject: |   |  
				| 
 |  
				| I see. The local variables are not "allocated it on it's own", you SHOULD make place on top of the stack for this variables. 
 Let me get to the point, if you have a "call" instruction to go through a function, the function will look like this :
 
 
 push ebp             // calling conventions (stack frame)
 mov ebp, esp      // calling conventions (stack frame)
 sub esp, 4 // HERE you allocate those local variables. It's giving place on top of
 // the stack for the local variables
 
 Assuming every value on the stack is 4 bytes, you will do sub esp, 4 for one local variable ; sub esp, 8 for two ect... it's always +4
 
 Now if you didn't understand this very well, it's normal. I would suggest you reading this links and then you will be ok.
 
 pages . cs . wisc . edu /~remzi/Classes/354/Fall2012/Handouts/Handout-CallReturn . pdf
 
 cs . virginia . edu /~evans/cs216/guides/x86 . html
 |  |  
		| Back to top |  |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |  |