0

I have been trying to copy memory from a module from base to module size without it taking 5 years and my computer's CPU raising taller than the sky.

This script I put together is in Cheat Engine LUA, and it's copying memory via reading, then printing each byte on a single line so that I can use it to write to allocated space (memcopy // newmem2):

autoAssemble[[
    alloc(newmem2, 2048)
    label(memcopy)
    registerSymbol(memcopy)

    newmem2:
    memcopy:
]]

for i = 0x00, getModuleSize("Notepad.exe") do
    x = readBytes(getAddress("Notepad.exe+0" .. string.format("%x", i)))
    if (string.len(x) == 1) then
        print(x .. "0")
    else
        print(string.upper(string.format("%x", x)))
    end
    if (isKeyPressed(VK_F) == true) then break end
end

I am basically trying to re-create the exact module in allocated space (I don't write the memory within the script).

Help is much appreciated!

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
HueHueKing
  • 13
  • 3

1 Answers1

0

This document has a particular chapter termed 'About strings' it recommends against the concatenation in the loop. Here's quote of alternative solution from the article:

local t = {}
for line in io.lines() do
t[#t + 1] = line
end
s = table.concat(t, "\n")

It considers the txt-file reading. In essence, it puts each obtained string into a table element and then uses built-in function to compose single megastring from it.

Those string alterations in you loop seem to be vital to the code, but maybe you could perform them as a regex on bigger string rather than individual operations.

And I'd bet even more on that writing to disk has a significant overhead too, and if you invoke a single print() with big table where lines are separated with escape characters \n you'd have a speedup. If it is a file on disk you're printing to.

Dimitry
  • 2,204
  • 1
  • 16
  • 24