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 


Lua: Find if memory address is writable by the game

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
fakuivan
Newbie cheater
Reputation: 0

Joined: 27 Dec 2018
Posts: 17

PostPosted: Sun Jan 06, 2019 9:35 pm    Post subject: Lua: Find if memory address is writable by the game Reply with quote

I made the following script, that works similarly to a pointerscan, except it's not limited to a static address as the base address for the pointer (the base address is arbitrary).

To filter potential pointers on the struct I made a basic "non zero pointer" filter and implemented it in ``usableAddress``, while this cuts down somehow on the bloat, it still interprets anything that is not zero as a possible struct, even if the game can't access it.

I wasn't able to find any functions in the Lua API that could suggest checking if a memory location is accesible by the game. Is such thing possible to implement in Lua? how so?

Code:

function scanTree(address, maxOffset, comparator, structValidator, maxDepth)
    print(string.format(
        "scanning for address 0x%X with max offset 0x%X and max depth %d",
        address, maxOffset, maxDepth))
    local offsetTree = {}
    address = getAddress(address)
    for currentOffset = 0, maxOffset, 1 do
        local currentAddress = address + currentOffset
        if comparator(currentAddress) then
            print(string.format("Offset found at 0x%X", currentOffset))
            offsetTree[currentOffset] = true
        end
        if maxDepth > 0 then
           local nextNode = readPointer(currentAddress)
           if structValidator(nextNode) then
               -- If this is a valid offset, then we'll overwrite it
               offsetTree[currentOffset] = scanTree(nextNode,
                                                    maxOffset,
                                                    comparator,
                                                    structValidator,
                                                    maxDepth - 1)
           end
        end
    end
    return offsetTree
end

function floatMemComparator(address, value, radius)
    local toCompare = readFloat(address)
    if not toCompare then return false else
        if compareFloat(toCompare, value, radius) then return true
        else return false end
    end
end

function usableAddress(address)
    return not (address == 0 or address == nil)
end

function compareFloat(float1, float2, radius)
    local lower_limit = float2 - radius
    local upper_limit = float2 + radius
    if float1 <= upper_limit and float1 >= lower_limit then
        return true
    end
    return false
end

scanTree(getAddress("21437861688"),
         4000,
         function(address) return floatMemComparator(address, 29.2, 0.1) end,
         usableAddress,
         1)
print("Finished")
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Mon Jan 07, 2019 2:04 am    Post subject: Reply with quote

not really(i'll see about adding a getMemoryRanges function) ,but if readFloat (or readInteger) returns nil instead of 0 then the address was inaccessible. (all bytes in that 4kb range would be inaccessible then)
_________________
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
fakuivan
Newbie cheater
Reputation: 0

Joined: 27 Dec 2018
Posts: 17

PostPosted: Wed Jan 09, 2019 12:56 am    Post subject: Reply with quote

I added a ``readBytes(address, 1) == nil`` to the checks, it's much quicker now, thanks Dark Byte!. Here's the complete script
(link on the "File Comment", stupid url blockers, all they accomplish is to make people mangle urls)

I really hope something like this gets added to CE's pointerscan (this method is very crude and slow compared to something written in C), as the limitation to just use static addresses seems quite artificial to me.



OOF.png
 Description:
https://gist.github.com/fakuivan/61b3bb9e59d8ac724cedf1e8910de8e3
 Filesize:  13.84 KB
 Viewed:  29100 Time(s)

OOF.png


Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Wed Jan 09, 2019 1:26 am    Post subject: Reply with quote

the pointerscan has an option to say that the base addresss must be in a static address or not, and also lets you specify the range if you like

then there's also the structure spider and compare

_________________
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 Wed Jan 09, 2019 2:56 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
fakuivan
Newbie cheater
Reputation: 0

Joined: 27 Dec 2018
Posts: 17

PostPosted: Wed Jan 09, 2019 1:39 am    Post subject: Reply with quote

Would you mind sharing a screenshot of the option to specify a non static base address? I can't seem to find it.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Wed Jan 09, 2019 2:53 am    Post subject: Reply with quote

Deselect
Code:

advanced options->"Only find paths with a static address"

or check advanced options->"Base address must be in range" and give the range you accept as base (can be a non-static range)

_________________
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 -> General Gamehacking 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