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 


Thread Local Storage of the Thread Hitting a Break Point

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

Joined: 14 Feb 2009
Posts: 30
Location: Planet 3 Solar System Orion Arm Spiral Galaxy Milky Way

PostPosted: Sun Mar 29, 2026 3:16 pm    Post subject: Thread Local Storage of the Thread Hitting a Break Point Reply with quote

Target game is storing some info in the Thread Local Storage instead of static memory, presumably as a way to hinder debugger analysis.

Is it possible to read the Thread Local Storage or better get a pointer to the TEB of the thread hitting a break point inside debugger_onBreakpoint()?

I can get the TEB from cheat engine menu command. But is it possible to do it purely inside a lua script.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 473

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

PostPosted: Sun Mar 29, 2026 3:57 pm    Post subject: Reply with quote

Code:

function getTEB(tid)
  local result
  local th=executeCodeLocalEx('OpenThread',64 | 8, 0, tid)

  if th~=0 then
    local tbims=createMemoryStream()
    tbims.size=48

    local nresult=createMemoryStream()
    nresult.size=8 --4 should be enough, but lets be safe

    local hr=ExecuteCodeLocalEx('NtQueryInformationThread', th, 0, tbims.Memory, tbims.size, nresult.Memory)

    if hr==0 then
      tbims.Position=8
      result=tbims.readQword()
    end

    tbims.destroy()
    nresult.destroy()

    executeCodeLocalEx('CloseHandle',th)
  end

  return result
end


during debugger_onBreakpoint the variable THREADID will contain the threadid of the thread

_________________
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
lylcheat
Cheater
Reputation: 0

Joined: 14 Feb 2009
Posts: 30
Location: Planet 3 Solar System Orion Arm Spiral Galaxy Milky Way

PostPosted: Mon Mar 30, 2026 7:19 am    Post subject: Reply with quote

Wouldn't the whole thing a lot simpler if the FS/GS registers are exposed to script too?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 473

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

PostPosted: Mon Mar 30, 2026 5:51 pm    Post subject: Reply with quote

Internally you'd still end up executing the above script for each breakpoint as the fs/gs base is not part of the windows context record
_________________
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 -> 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