Jump to content
  • 0

How to allocate more then 4kb?


Rxhacker
 Share

Question

4 answers to this question

Recommended Posts

  • 0

I reason is i have to write some code which is longer then 4kb , using your concept i can write the code. But what happened is i had to write a jump code at the end of 4kb to another allocated space, so i was wondering if there was any way to allocate an continues block of memory more then 4kb. But turns but there isn't such option. I think i will move forward with jump code. Thank you

Link to comment
Share on other sites

  • 0

 

On 4/2/2024 at 12:41 AM, Rxhacker said:

Is there any way to allocate more then 4kb in the memory using game guardian ?

I don't believe that's directly possible, but you can allocate as many pages as you need and chain them together. To do this calculate how many pages you need by dividing by 4KB, and in a loop allocate a block and add the return address of the allocated block to a list. You can then combine all of your memory into a table of values by looping over the list and adding the 1000 values (taking the start address and adding 4 each time, 1000 times) to the table for each address. If you don't understand, I can code that for you - it's pretty simple to do.

Though I wonder what you're writing to memory that takes so much space? An image or save code, or something?

Link to comment
Share on other sites

  • 0

There is good chance that in some cases it may work by allocating as many pages as needed one after another. Example implementation: 

local PAGE_SIZE = 0x1000
function allocateConsecutivePages(count, mode, address)
  count = count or 1
  mode = mode or gg.PROT_READ | gg.PROT_EXEC
  address = address or 0
  local firstPageAddress = gg.allocatePage(mode, address)
  if type(firstPageAddress) == "string" then
    return firstPageAddress
  end
  for i = 1, count - 1 do
    local desiredPageAddress = firstPageAddress + i * PAGE_SIZE
    local pageAddress = gg.allocatePage(mode, desiredPageAddress)
    if pageAddress ~= desiredPageAddress then
      -- failed to allocate page right after previous one, handle as needed
    end
  end
  return firstPageAddress
end
Link to comment
Share on other sites

  • 0
On 4/17/2024 at 9:35 PM, Rxhacker said:

I reason is i have to write some code which is longer then 4kb , using your concept i can write the code. But what happened is i had to write a jump code at the end of 4kb to another allocated space, so i was wondering if there was any way to allocate an continues block of memory more then 4kb. But turns but there isn't such option. I think i will move forward with jump code. Thank you

Okay, that's what I figured. You're right about the block not being continuous; sorry. @CmPprovided actual code which solves that problem by trying to allocate continuously, but I have no idea how often that would work and the tendency of it to fail (I'm unaware of how the kernel decides where to allocate the memory). A solution to that might be to allocate the first block in an obscure region (maybe an unused memory region, like c++ heap, would work? This is a gray area for me, so I wouldn't really know.) where you are sure there's enough consecutive space.

If I were you, I would first take CmP's code and play around with it, seeing if you encounter any issues.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.