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 


Pointer string to Address

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
SleepiDreamer
Cheater
Reputation: 0

Joined: 27 Aug 2021
Posts: 41

PostPosted: Tue Aug 31, 2021 2:16 am    Post subject: Pointer string to Address Reply with quote

This should be relatively simple, yet I can't seem to find a solution:
I want to go from string
Code:
'[Minecraft.Windows.exe+4030538]+3CA51F0'

To the address it is pointing to (which obviously changes in each new instance of the game)
Code:
0x18EFBAA51F0

And store it in a local variable.

My main problem is that I can convert it to a hex using
Code:
'0x'..(toHex(getAddress(address1))

But that's simply a string, which cannot be used for most celua functions.

_________________
Hope you're having a great day!
Back to top
View user's profile Send private message
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Tue Aug 31, 2021 2:41 am    Post subject: Reply with quote

I believe you can just use
Code:

Ptr = '0x'..(toHex(getAddress(address1))
Var = tonumber(Ptr)
and it would work.
_________________
Trying to learn!

Add me on Discord if you want hands-on help: Birdi#0007
Back to top
View user's profile Send private message Visit poster's website
SleepiDreamer
Cheater
Reputation: 0

Joined: 27 Aug 2021
Posts: 41

PostPosted: Tue Aug 31, 2021 2:51 am    Post subject: Reply with quote

This won't really help me:
If I use it on the pointer string, it prints nothing
If I use it on what I sent, it doesn't work
If I use it on the address without 0x, it converts to a string.

_________________
Hope you're having a great day!
Back to top
View user's profile Send private message
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Tue Aug 31, 2021 2:56 am    Post subject: Reply with quote

Try omitting the '0x'.. concatenation. Just get the hex of the address and run it through tonumber().
Lua should just convert string literals to hex like that, afaik.
If you're really stuck you can just push it as an address of a memrec and pull it via memrec.address so it's absolutely literal, but you shouldn't have to.

_________________
Trying to learn!

Add me on Discord if you want hands-on help: Birdi#0007
Back to top
View user's profile Send private message Visit poster's website
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Tue Aug 31, 2021 2:59 am    Post subject: Reply with quote

You haven't posted your "toHex" function; however, it should be something like this:
Code:

function toHex(s)
  if s ~= nil then
    local s = string.format("0x%X", s)
    return s
 end
end


Then you can use it like this example:
Code:

address = '0xDEADBEEF'
local pointer = toHex(getAddressSafe(address))
print(pointer)
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Tue Aug 31, 2021 3:07 am    Post subject: Reply with quote

Most of the CE Lua functions can take the first string as an address. Why do you need to convert it? If you aren't doing math with the number, I don't think you need to convert it. And why do you need to have it as hex, and not just a number?
_________________
Back to top
View user's profile Send private message Visit poster's website
SleepiDreamer
Cheater
Reputation: 0

Joined: 27 Aug 2021
Posts: 41

PostPosted: Tue Aug 31, 2021 3:21 am    Post subject: Reply with quote

I'll just post all my code I have rn:
Code:
function toHex(s)
  local s = string.format("%X", s)
  return s
end
function toAddress(ad)
  local ad = '0x'..ad
  return ad
end
local address1 = 0x215A3AA5218
addresses = {0x215A3AA5218, 0x215A3AA4F0, 0x215A3AA54EC}

--writeBytes(address, 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90)
-- 0x90 = nop, here it writes 5 nop instructions. Just make sure to delimit each byte instruction with a comma for however many you require to write. Although, should it be a large amount of bytes, I recommend you pass a table that holds the byte data instead.

function findAddress(address, iter)
  debug_setBreakpoint(address, 4, bptWrite, function()
    print(string.format("%X: %X accessed %X", iter, RIP-8, address))
    debug_continueFromBreakpoint(co_run)
    debug_removeBreakpoint(address)
    NOP(RIP-8)
    return 0
end)
end
function NOP(address)
  writeBytes(address, 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90)
end


for listCount = 1, #addresses do
  findAddress(address1+listCount*4, listCount)
end


In the list addresses I have all the addresses I want to NOP. If I use addresses = {'Minecraft.Windows.exe+4030538+3CA51F0'}, it simply doesn't do anything.

_________________
Hope you're having a great day!
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Tue Aug 31, 2021 4:21 am    Post subject: Reply with quote

Your for loop uses math on the address, so it needs to be a number. Just use getAddress and don't convert it to a hex string. And your findAddress function assumes the address is a number.
_________________
Back to top
View user's profile Send private message Visit poster's website
SleepiDreamer
Cheater
Reputation: 0

Joined: 27 Aug 2021
Posts: 41

PostPosted: Tue Aug 31, 2021 4:46 am    Post subject: Reply with quote

thank you guys so much!
_________________
Hope you're having a great day!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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