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 


Calling and use windows apps library function via CE Lua
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Jan 14, 2020 6:26 am    Post subject: Calling and use windows apps library function via CE Lua Reply with quote

Hi, are there easy ways (including tutorial if any) to call windows apps library function and use in CE Lua script.

Say, I knew what is a windows apps library (dll) functions including the parameters (easy to be found on MSDN), then how the easy way to call it via CE Lua script?.

Say for example: call 'mciSendCommandA' a function own by winmm.dll

Any helps, tutorial or suggestions from CE Lua experts?.



dll function viewer.JPG
 Description:
 Filesize:  91.87 KB
 Viewed:  4473 Time(s)

dll function viewer.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Jan 14, 2020 6:47 am    Post subject: Reply with quote

ce already has winmm loaded by default, so you can just do
Code:

memorystore=createMemoryStream()

--use memorystore.writeByte/Word/Dword to fill in the memorystore

executeCodeLocalEx('mciSendCommandA', IDDevice, msg, flags, memorystore.Memory)

_________________
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
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Jan 14, 2020 8:50 am    Post subject: Reply with quote

Thanks, DB for the answer and sample.
Anyway, is CE loaded all windows libraries functions or only some libs. by default, I mean in CE 7.0 ?. Thanks

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Tue Jan 14, 2020 9:14 am    Post subject: Reply with quote

CE 7.0; It all started with "executeCodeLocalEx()".
Now I miss some old functions. Smile
Please DB; 32-bit Trainer.exe must have code that supports 32-64 bit scanners!

is "targetIs64Bit ()" in the .exe installation: does not work in a 32-bit browser.
Or, while "targetIs32Bit" is: 64 bit does not work in the browser.
2 separate Trainer produce and determine the area of use, + process is happening. Smile

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sun Jan 19, 2020 5:20 am    Post subject: Reply with quote

Follows DB information, I try using executeCodeLocalEx() for learn purpose.

Code:
function MessageBox()
 memorystore=createMemoryStream()
 executeCodeLocalEx("user32.MessageBoxA", HWND, LPCSTR, LPCSTR, UINT, memorystore.Memory)
end

MessageBox(0, "Hello From Lua", "User32 Message Box", 0)


Not work. How use executeCodeLocalEx() properly?. Any example / tutorial?

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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: Sun Jan 19, 2020 5:55 am    Post subject: Reply with quote

executeCodeLocalEx() for now only 64bit CE

Code:

function MessageBox(title,text,uType)
 return executeCodeLocalEx("user32.MessageBoxA", MainForm.Handle, text, title, uType)
end

local a = MessageBox("The title", "the text", 1) -- MB_OKCANCEL
print(a) -- 1 - OK, 2 - cancel

local a = MessageBox("The title", "the text", 2) -- MB_ABORTRETRYIGNORE
print(a) -- 3 - ABORT 4 - RETRY 5 - IGNORE

local a = MessageBox("The title", "the text", 4) -- MB_YESNO
print(a) -- 6 - YES 7 - NO

_________________
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sun Jan 19, 2020 8:16 am    Post subject: Reply with quote

mgr.inz.Player wrote:
executeCodeLocalEx() for now only 64bit CE


Thank you for the example, that is I need to understand the concept while using executeCodeLocalEx().
Anyhow when executing your example code above, CE suddenly stops working. What's wrong?.

My system: Win 7 Ultimate (64bit) and CE 7.0 (running cheatengine-x86_64,exe).

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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: Sun Jan 19, 2020 8:27 am    Post subject: Reply with quote

Hmm. Something's wrong.

After you said you have CE freeze issues I tried executing my examples many many times in row. And CE closed itself without any errors.

I will check it with GDB.

_________________
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Sun Jan 19, 2020 8:28 am    Post subject: Reply with quote

Corroder wrote:
mgr.inz.Player wrote:
executeCodeLocalEx() for now only 64bit CE


Thank you for the example, that is I need to understand the concept while using executeCodeLocalEx().
Anyhow when executing your example code above, CE suddenly stops working. What's wrong?.

My system: Win 7 Ultimate (64bit) and CE 7.0 (running cheatengine-x86_64,exe).


It works for me.
my system: Win 10 (64bit) and CE 7.0 (running cheatengine-x86_64,exe)

result:
1
4
6



Ekran3.PNG
 Description:
 Filesize:  24.17 KB
 Viewed:  4360 Time(s)

Ekran3.PNG



_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
mgr.inz.Player
I post too much
Reputation: 218

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

PostPosted: Sun Jan 19, 2020 8:47 am    Post subject: Reply with quote

Play with it a little more. Execute MessageBox function.
With messagebox still visible try to click other CE windows ('Lua Engine', 'MemoryViewer').


I get this under GDB
Code:
gdb: unknown target exception 0xc0000028 at 0x7fffbfe9eb78

Program received signal ?, Unknown signal.
0x00007fffbfe9eb78 in ?? ()
(gdb) bt
#0  0x00007fffbfe9eb78 in ?? ()
#1  0x12020e2100000000 in ?? ()
#2  0x0000000000450e21 in SYSUTILS$_$TUNICODEENCODING_$__$$_GETPREAMBLE$$TBYTES ()
#3  0x0000000000f328c0 in VMT_$STDCTRLS_$$_TCUSTOMBUTTON ()
#4  0x0000000000f31f88 in VMT_$STDCTRLS_$$_TBUTTONACTIONLINK$indirect ()
#5  0x00000000000602ff in ?? ()
#6  0x0000000000000000 in ?? ()
(gdb)

Probably above backtrace also is wrong because of stack corruption...


EDIT:
Stacktrace shown from another CE instance attached to crashed CE:

_________________


Last edited by mgr.inz.Player on Sun Jan 19, 2020 9:30 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sun Jan 19, 2020 9:18 am    Post subject: Reply with quote

Probably above backtrace also is wrong because of stack corruption or libraries conflict when loading, incase in windows 64 system there are two user32.dll (in System32 and SysWOW64).

Code:
--local path = "C:\\Windows\\SysWOW64\\user32.dll"
local path = "C:\\Windows\\System32\\user32.dll"
local f = assert(package.loadlib(path, "luaopen_user32"))
f()

memorystore=createMemoryStream()

function MessageBox(title,text,uType)
 return executeCodeLocalEx("user32.MessageBoxA", MainForm.Handle, text, title, uType)
end

local a = MessageBox("The title", "the text", 1, memorystore.Memory) -- MB_OKCANCEL
print(a) -- 1 - OK, 2 - cancel

local a = MessageBox("The title", "the text", 2, memorystore.Memory) -- MB_ABORTRETRYIGNORE
print(a) -- 3 - ABORT 4 - RETRY 5 - IGNORE

local a = MessageBox("The title", "the text", 4, memorystore.Memory) -- MB_YESNO
print(a) -- 6 - YES 7 - NO


The code above makes CE hang/crash. Anyhow, the important point for this topic is how to implementing executeCodeLocalEx() by the example given.

EDIT: which GDB version you use?. 8.3 ?

@Aylin: The code works on your machine. Is it show a 'message box' GUI?

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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: Sun Jan 19, 2020 9:32 am    Post subject: Reply with quote

Quote:
which GDB version you use?. 8.3 ?

GDB shipped with Lazarus.


Those message windows do not crash CE:
Code:
-- messageDialog(text,messagetype,buttons,...)
-- messagetype:
-- 0 - mtWarning;
-- 1 - mtError;
-- 2 - mtInformation;
-- 3 - mtConfirmation;

messageDialog('Test1',0,mbYes,mbNo)
showMessage('Test2')

_________________
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sun Jan 19, 2020 10:48 am    Post subject: Reply with quote

mgr.inz.Player wrote:

EDIT:
Stacktrace shown from another CE instance attached to crashed CE:


So, how to fix the problem?. Any chance?

EDIT:
I found this using VS Debugger

Unhandled exception at 0x00000000778D96F8 (ntdll.dll) in cheatengine-x86_64.exe: 0xC0000028: An invalid or unaligned stack was encountered during an unwind operation.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sun Jan 19, 2020 11:31 am    Post subject: Reply with quote

Messagebox will start it's own messageloop dispatcher (dispatchmessage) while it's still inside lua's stack
so, it will invoke lua's cleanup routines while some of it's internal locks are still held, and while the current thread is the owner thread, this will be allowed.

look into re-entrant code and functions, I don't think lua is one of these

also, if an exception happens and it would backtrace, it would end up crashing as it's not in an actual stack

(could of course be that the stack is not properly setup, but do some tests with easier functions that don't end up calling all of CE)

_________________
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
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Sun Jan 19, 2020 12:12 pm    Post subject: Reply with quote

@Aylin: The code works on your machine. Is it show a 'message box' GUI?[/quote]

I am sorry for my late answer.
Yes, Windows warning message is coming.
It looks like you have enabled VB.Script. Smile



Ek3.png
 Description:
 Filesize:  32.99 KB
 Viewed:  4299 Time(s)

Ek3.png



Ek2.png
 Description:
 Filesize:  32.46 KB
 Viewed:  4299 Time(s)

Ek2.png



Ek1.png
 Description:
 Filesize:  31.13 KB
 Viewed:  4299 Time(s)

Ek1.png



_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website 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
Goto page 1, 2  Next
Page 1 of 2

 
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