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 


Freezthread with lua

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

Joined: 11 Mar 2016
Posts: 231

PostPosted: Mon Dec 11, 2017 12:59 pm    Post subject: Freezthread with lua Reply with quote

I know I can freez the thread from threadlist .
I want to do it with lua command .
some one write example please
in 1780 and 2cc



freez.PNG
 Description:
 Filesize:  17.16 KB
 Viewed:  4653 Time(s)

freez.PNG


Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Dec 11, 2017 5:55 pm    Post subject: Reply with quote

I'm not sure, I'd have expected something like this to work but it doesn't really seem to in my (limited) testing

Code:
sl = createStringlist()
getThreadList(sl)
local tid = tonumber(sl[0], 16)
res = executeCode('SuspendThread', tid)
sl.destroy()
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Mon Dec 11, 2017 6:41 pm    Post subject: Reply with quote

You need to call OpenThread on the TID first to obtain a handle
_________________
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
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Tue Dec 12, 2017 5:14 pm    Post subject: This post has 1 review(s) Reply with quote

@Twistedfate replying here instead of pm so others can find it, you'd use something like this (what DB was saying was that what I had was mostly correct but SuspendThread takes a handle to a thread rather than a thread id like I was giving it, which complicates the code a bit)

Code:
-- https://msdn.microsoft.com/en-us/library/windows/desktop/ms684335(v=vs.85).aspx
-- https://msdn.microsoft.com/en-us/library/windows/desktop/ms686769(v=vs.85).aspx
-- https://www.hellboundhackers.org/forum/need_value_of_windows_constants_for_python-22-15957_0.html
local THREAD_ALL_ACCESS = 0x001F03FF
local THREAD_SUSPEND_RESUME = 0x2
local THREAD_TERMINATE = 0x1
-- window's OpenThread API requires 3 args, excuteCode only allows 1 so
-- create a "stub" which calls it via a nice lua function interface :)
local function OpenThread(access, inherit, tid)
  -- create asm stub if not already done
  local stub = getAddressSafe('OpenThreadStub')
  if not stub or stub == 0 then
    local x86script = [[
    alloc(OpenThreadStub,1024)
    registerSymbol(OpenThreadStub)
    OpenThreadStub:
      push ebp
      mov ebp, esp
      mov eax, [ebp+8]
      push [eax]
      push [eax+4]
      push [eax+8]
      call OpenThread // stdcall
      mov esp, ebp
      pop ebp
      ret 4 // stdcall
    ]]
    local x64script = [[
    alloc(OpenThreadStub,1024)
    registerSymbol(OpenThreadStub)
    OpenThreadStub:
      push rbp
      mov rbp, rsp
      mov rax, rcx
      mov r8, [rax]
      mov rdx, [rax+4]
      mov rcx, [rax+8]
      sub rsp, 20 // shadowspace
      call OpenThread
      add rsp, 20
      mov rsp, rbp
      pop rbp
      ret
    ]]
    local success = autoAssemble(targetIs64Bit() and x64script or x86script)
    assert(success, "Failed to create OpenThread stub")
  end

  -- now write params to memory and call it
  local params = allocateMemory(12)
  writeInteger(params, tid)
  writeInteger(params+4, inherit and 1 or 0)
  writeInteger(params+8, access)
  local res = executeCode('OpenThreadStub', params)
  deAlloc(params)
  return res
end

-- get list of thread ids from CE
sl = createStringlist()
getThreadList(sl)
--print('threads', sl.Count)

-- select the first thread id
local tid = tonumber(sl[0], 16)

-- open a handle to that thread via create stub
local thandle = OpenThread(THREAD_SUSPEND_RESUME, false, tid)
assert(thandle and thandle ~= 0, 'failed to get thread handle for tid ' .. ('%X'):format(tid))

-- suspend thread
local res = executeCode('SuspendThread', thandle)
--print(res)
--res = executeCode('ResumeThread', thandle)
--print(res)
-- free handle now that we no longer need it
executeCode('CloseHandle', thandle)
-- free memory used for thread list
sl.destroy()


That'll suspend the first thread (sl[0]), if the thread ID is always '1780' then you can replace creating the string list, and filling it with getThreadList, with just tid = tonumber('1780', 16) or tid = 6016. If it changes each time then you'll need to get it as I did above, though in your image it's thread 2 so you'd use sl[1] instead of sl[0]
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