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 


How to use winapi function in CE script engine?

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

Joined: 24 Jul 2012
Posts: 145

PostPosted: Fri Nov 16, 2012 12:08 am    Post subject: How to use winapi function in CE script engine? Reply with quote

I think using "find_window" is better than using "filename" to find game's process. So, I want to use winapi.find_window in ce script?Well, it seems like that winapi does not work.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Fri Nov 16, 2012 6:53 am    Post subject: Reply with quote

Perhaps you can find a lua extension that adds this.
The Alien lua library might be of use here.

_________________
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
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Nov 17, 2012 9:36 pm    Post subject: Reply with quote

If you're using 32-bit ce you can use this:
http://cheatengine.org/temp/celua_alien.rar

just extract it to your cheat engine dir, and then you can do
Code:

require("alien")


an example of showing a messagebox:
Code:

require("alien")
user32=alien.load("user32.dll")
MessageBoxA = user32.MessageBoxA
MessageBoxA:types{abi = 'stdcall', ret = 'long', 'long', 'string', 'string', 'long' }
MessageBoxA(0, "BLA", "BLA", 0)

_________________
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
Alice0725
Expert Cheater
Reputation: 11

Joined: 24 Jul 2012
Posts: 145

PostPosted: Sat Nov 17, 2012 10:43 pm    Post subject: Reply with quote

I think should do that in CE .
As:
1.A running game must have a window.Mostly,different versions have the same class name and window name.Somebody like me may change the game's filename. I would like to change "Walking Dead" from walkingdead101.exe to walkingdead.exe.

2.When making a table, CE have to open game's process, then CE get that Game windows's class name and window name ,then save this to xml file.When we make a trainer , we do not have to get them mannually.
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Tue Nov 20, 2012 1:18 pm    Post subject: Reply with quote

Good suggestion :p..
you press attach button and then asking user to press at the game/flash/window/wateve.. and then it'll return message that it been attached :p.

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Tue Nov 20, 2012 3:02 pm    Post subject: Reply with quote

Alice0725 wrote:
I think should do that in CE .
As:
1.A running game must have a window.Mostly,different versions have the same class name and window name.Somebody like me may change the game's filename. I would like to change "Walking Dead" from walkingdead101.exe to walkingdead.exe.

2.When making a table, CE have to open game's process, then CE get that Game windows's class name and window name ,then save this to xml file.When we make a trainer , we do not have to get them mannually.


You're better off using the process name than the window class or title. An application can easily change its class and/or window name to eliminate the ability of FindWindow to easily locate it. A process name isn't as easily changed though and is typically not able to be changed at runtime.

You can use Cheat Engines auto-attach feature to attach to the process automatically as well.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
ablonevn
Advanced Cheater
Reputation: 1

Joined: 02 Oct 2011
Posts: 59

PostPosted: Sat Jan 12, 2013 3:20 am    Post subject: Re: How to use winapi function in CE script engine? Reply with quote

Alice0725 wrote:
I think using "find_window" is better than using "filename" to find game's process. So, I want to use winapi.find_window in ce script?Well, it seems like that winapi does not work.

yes, here i'm share you thing i'm lerned from db yesterday.
Code:

function findwindow()
   script=[[
      alloc(fwnd,2048)
      registersymbol(fwnd)
      label(wndname)
      registersymbol(wndname)
      label(hwnd)
      registersymbol(hwnd)

      fwnd:
      lea eax,[wndname]
      push eax
      lea eax,[classname]
      push eax
      call findwindowa //findwindoww
      mov [hwnd],eax
      ret 4
      hwnd:
      dd 0
      classname:
      db 0 dup(100)
      wndname:
      db 0 dup(100)
      
   ]]
   autoAssemble(script);   
   writeStringLocal(getAddress("wndname"),"tutorial-i386");
   autoAssemble("createthread(fwnd)");
   sleep(1000);--wait thread finish
   hwnd=readIntegerLocal(getAddress(hwnd))
end

i donot test it,yet but i'm believing this is the way without alient library Very Happy
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Jan 12, 2013 5:42 am    Post subject: Reply with quote

Add a ",true" after the autoassemble scripts, or remove the Local part from readInteger and writeString
_________________
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
Alice0725
Expert Cheater
Reputation: 11

Joined: 24 Jul 2012
Posts: 145

PostPosted: Sat Jan 12, 2013 10:30 am    Post subject: Reply with quote

Nice! It works with CE-i386 Laughing
But don't know why CE-x64 crashed.



Capture2.JPG
 Description:
 Filesize:  25.06 KB
 Viewed:  17285 Time(s)

Capture2.JPG



FindWindow.CT
 Description:
Attach CE itself. Find window of "Tutorial-i386.exe".

Download
 Filename:  FindWindow.CT
 Filesize:  2.71 KB
 Downloaded:  1137 Time(s)

Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Jan 12, 2013 11:31 am    Post subject: Reply with quote

@Alice0725


"But don't know why CE-x64 crashed."

Different calling convention.

_________________
Back to top
View user's profile Send private message MSN Messenger
ablonevn
Advanced Cheater
Reputation: 1

Joined: 02 Oct 2011
Posts: 59

PostPosted: Sun Jan 13, 2013 1:58 am    Post subject: Reply with quote

mgr.inz.Player wrote:
@Alice0725


"But don't know why CE-x64 crashed."

Different calling convention.

i donot known, on 64 bit, the "ret 4" will be "ret 8" on thread calling. and if the calling for "findwindowa" using "fastcall" style then re-change parameter.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sun Jan 13, 2013 4:30 am    Post subject: Reply with quote

64-bit uses microsoft's fastcall mechanism yes (not compatible with gnu's fastcall which uses different registers and doesn't use the stack)

anyhow, first allocate room for the parameters on the stack, always at least 32 bytes, but don't fill the parameters in the stack you just created, that'd be stupid...
Fill in the parameters in the integers in RCX, RDX, R8, R9.
If you use more than 4 integers, place it in the stack (not on stack spot 0 to 3, but start at 4)
For floating points use xmm0 to xmm3.
More info: http://msdn.microsoft.com/en-US/library/zthk2dkh%28v=vs.80%29.aspx

Anyhow, I still maintain that it's a lot easier to just inject and execute this code inside the target process instead of inside cheat engine.

_________________
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
ablonevn
Advanced Cheater
Reputation: 1

Joined: 02 Oct 2011
Posts: 59

PostPosted: Sun Jan 13, 2013 9:49 am    Post subject: Reply with quote

Dark Byte wrote:

Anyhow, I still maintain that it's a lot easier to just inject and execute this code inside the target process instead of inside cheat engine.

no, the target process not visible yet, he just calling findwindow to get processID Very Happy
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Jan 14, 2013 11:20 am    Post subject: This post has 1 review(s) Reply with quote

Example

autoAssemble("createthread(playit)",true)



32bit:
Code:

alloc(playit,2048)
registersymbol(playit)

playit:
push fdwSound
push 0
push pszSound
call winmm.PlaySoundA
ret


64bit:
Code:

alloc(playit,2048)
registersymbol(playit)

playit:
push rbp
mov rbp,rsp
sub rsp,30

mov r8d,fdwSound
mov rdx,0
mov rcx,pszSound
call winmm.PlaySoundA

leave
ret

_________________
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