| View previous topic :: View next topic |
| Author |
Message |
icp Newbie cheater
Reputation: 0
Joined: 09 Dec 2021 Posts: 24
|
Posted: Fri Apr 22, 2022 5:40 am Post subject: <<Failure allocating memory near XXXXX>> err |
|
|
Recently, the problem with memory allocation has become more frequent. Here is a screenshot of the table for the game oxygen-not-included. As you can see, there is free memory in the region, but the allocation gives an error. This happens when the game has allocated a lot of memory already after the desired code. If you use the same selection as soon as the game created the desired function, the selection works fine. If later, when it already writes about the impossibility of selection, disable one of the previously enabled injections, thereby freeing up memory, then enabling another injection will be fine, but then enabling the disabled one will already write an error. The game is somehow blocking memory allocation next to its regions.
How to solve this problem?
[RUS]
В последнее время участилась проблема с выделением памяти. Привожу скриншот таблицы для игры oxygen-not-included. Как видим память свободная в регионе есть, а вот выделение выдаёт ошибку. Происходит это когда игра выделила достаточно много памяти уже после искомого кода. Если использовать то же выделение сразу, как игра создала нужную функцию, выделение проходит нормально. Если потом, когда уже пишет о невозможности выделения отключить одну из ранее включенных инъекций, освободив тем самым память, то включение другой инъекции пройдёт нормально, но тогда включение отключенной уже напишет ошибку. Т.е. игра как-то блокирует выделение памяти рядом со своими регионами.
Как решить данную проблему?
| Description: |
|
| Filesize: |
59.15 KB |
| Viewed: |
10645 Time(s) |

|
|
|
| Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1069 Location: 0x90
|
Posted: Fri Apr 22, 2022 8:03 am Post subject: |
|
|
| It looks as if those regions don't have access permissions. That could potentially explain why you cannot allocate memory in that region.
|
|
| Back to top |
|
 |
icp Newbie cheater
Reputation: 0
Joined: 09 Dec 2021 Posts: 24
|
Posted: Fri Apr 22, 2022 8:45 am Post subject: |
|
|
I assumed, probably the inscription "no access" prompted me. I'm not interested in the cause of what is happening.
I'm not interested in how and why the game closes free memory regions, but how to fix this situation and allow the alloc command to work with them.
p.s. The most logical way out would be to use a far jmp. But it requires more work on injection. And there are free regions nearby, so I want to follow a simple path.
|
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3334
|
Posted: Fri Apr 22, 2022 10:58 am Post subject: |
|
|
| Why do you need memory in that specific region?
|
|
| Back to top |
|
 |
icp Newbie cheater
Reputation: 0
Joined: 09 Dec 2021 Posts: 24
|
Posted: Fri Apr 22, 2022 11:17 am Post subject: |
|
|
| Csimbi wrote: | | Why do you need memory in that specific region? |
To use a short jmp of five bytes. It is easier to replace one command in the code than 3-4 as far.
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4717
|
Posted: Fri Apr 22, 2022 11:46 am Post subject: |
|
|
In a 64-bit process, if the target of a branch (i.e. jmp) is within 2 GiB of the address of the instruction following the branch (RIP), the branch target can be encoded using a signed 32-bit relative displacement. This means you only need 5 bytes to jump to your code.
If the destination isn't within 2 GiB, CE has to do some trickery to make it work. This involves 14 bytes instead of 5, making the injection point take up far more space and increases the likelihood of running into problems.
This is what the third parameter to alloc is for.
OP:
First of all, CE uses VirtualProtectEx to allocate memory in the target process. This only works on addresses that are a multiple of Windows's allocation granularity (64 KiB, 0x10000 bytes). Any free regions you see with a size of less than that can't be used.
I'm not sure why the first two regions you marked aren't being used. They're well within 2 GiB and have plenty of memory (unless you're trying to allocate a large amount of memory). I doubt it's a race condition between CE and the game allocating memory- CE tries multiple times to reduce this chance IIRC. Maybe it's a bug in how CE searches for free regions.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
icp Newbie cheater
Reputation: 0
Joined: 09 Dec 2021 Posts: 24
|
Posted: Fri Apr 22, 2022 12:34 pm Post subject: |
|
|
| These are not the only large free windows within reach. I am requesting 0x100 bytes. I have to choose the closest range 0x1000. But writes an error. It looks like the game is somehow blocking intermediate memory areas. I need to somehow get around this.
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25830 Location: The netherlands
|
Posted: Fri Apr 22, 2022 2:29 pm Post subject: |
|
|
Is kernelmode querymemoryregions enabled or disabled in settings? (Should be disabled as it really screws up the preferred allocation routine)
Free memory should look like this screenshot, yours seems to have weird data
| Description: |
|
| Filesize: |
52.65 KB |
| Viewed: |
10522 Time(s) |

|
_________________
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
Last edited by Dark Byte on Fri Apr 22, 2022 3:32 pm; edited 1 time in total |
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3334
|
Posted: Fri Apr 22, 2022 3:01 pm Post subject: |
|
|
I see you are trying to hack a mono game, so there is one more thing for you to consider.
Mono generates the executable (byte) code in runtime.
The later a piece of code is used, the later it will be generated and the farther away it will be in the memory.
As such, there's no guarantee that you will have chance to do a jmp5 next time you start that process, or, when your script is used on another machine.
I found this out the hard way: the game kept crashing randomly and I was pulling my hair out.
Eventually I noticed that the jmp5s became jmp14s randomly, overwriting used code and returning at the wrong address, too.
I had a chat with Dark Byte and he recommended that I force the jmp14 every time instead of assuming I get lucky with a jmp5 every time.
So, think about that a bit and don't be lazy
|
|
| Back to top |
|
 |
gid2525 Expert Cheater
Reputation: 2
Joined: 21 Oct 2013 Posts: 103
|
Posted: Sat Apr 23, 2022 10:42 pm Post subject: |
|
|
| Csimbi wrote: | I see you are trying to hack a mono game, so there is one more thing for you to consider.
Mono generates the executable (byte) code in runtime.
The later a piece of code is used, the later it will be generated and the farther away it will be in the memory.
As such, there's no guarantee that you will have chance to do a jmp5 next time you start that process, or, when your script is used on another machine.
I found this out the hard way: the game kept crashing randomly and I was pulling my hair out.
Eventually I noticed that the jmp5s became jmp14s randomly, overwriting used code and returning at the wrong address, too.
I had a chat with Dark Byte and he recommended that I force the jmp14 every time instead of assuming I get lucky with a jmp5 every time.
So, think about that a bit and don't be lazy  |
I got a really cool script from Panraven over at fearless that automagically creates trampolines. You REALLY don't want to use 14 byte jumps directly from the methods because 14 bytes is just too many due to the fact that mono can be different on different machines and even on the same (instead of mov using lea for instance) and the more bytes you use for the jump the more likely it is that you may end up using code that may change. Even IN the prologue (with 14 byte jumps). I had that happen several times (in the prologue with 14byte jumps for a few games) before i started using the script from panraven.
Yes, cheat engine now has that 14 byte jump when using CTL but its just not optimal with mono. Given that the 14 byte jumps are what we actually need with mono and given that its TOO many bytes to use in the method (could be 4-5 instructions long) Cheat Engine really needs trampoline templates.
It would be nice if the template did what Panravens script does..(except maybe better if possible). It should:
Do a standard near jump as close to the method as possible scanning for the needed 14 empty bytes both before the method and after the method. When it finds the needed empty usable 14 bytes, it then creates a 14 byte jump there to the code cave. Panravens makes you put in the whole script into the table plus it makes you stipulate whether to look for the 14 empty bytes before or after (would be cool if it did both without stipulating). Would be REALLY nice if this was built into cheat engine and automatically did this.
Thread that talks about this:
https://fearlessrevolution.com/viewtopic.php?t=16864
Panravens GREAT Script:
https://fearlessrevolution.com/viewtopic.php?p=204222#p204222
|
|
| Back to top |
|
 |
icp Newbie cheater
Reputation: 0
Joined: 09 Dec 2021 Posts: 24
|
Posted: Sun Apr 24, 2022 1:46 am Post subject: |
|
|
| Dark Byte wrote: | Is kernelmode querymemoryregions enabled or disabled in settings? (Should be disabled as it really screws up the preferred allocation routine)
Free memory should look like this screenshot, yours seems to have weird data |
I checked, it seems to help. My script stopped reporting an error, even when the code I looking for was added by the game a long time ago. But that's wrong. Why should the table depend on the CE settings? Why is the alloc command bound to the debug method?.. If there are frames of free memory, then the script should receive them, even without using the kernelmode. Am I wrong?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25830 Location: The netherlands
|
Posted: Sun Apr 24, 2022 3:03 am Post subject: |
|
|
kwrnelmode virtualqueryex is not debug related, it's memory related
that means that scanning for free memory goes through there and kernelmode vqe only detects touched memory. So if it tries to allocate in untouched but allocated memory it fails
_________________
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 |
|
 |
icp Newbie cheater
Reputation: 0
Joined: 09 Dec 2021 Posts: 24
|
Posted: Sun Apr 24, 2022 3:21 am Post subject: |
|
|
| Dark Byte wrote: | kwrnelmode virtualqueryex is not debug related, it's memory related
that means that scanning for free memory goes through there and kernelmode vqe only detects touched memory. So if it tries to allocate in untouched but allocated memory it fails |
Apparently I did not find where to switch it correctly in CE 7.3. At the moment, the problem was solved by changing the debugger. The picture of the memory regions has become like in your screenshot. The allocate began to proceed correctly. Explain plz what I did wrong.
|
|
| Back to top |
|
 |
|