 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
gfetgkh Newbie cheater
Reputation: 0
Joined: 06 Apr 2018 Posts: 22
|
Posted: Mon Dec 23, 2019 9:07 am Post subject: How to use shellExecute to extract utf8 characters ? bug? |
|
|
How do I use shellExecute to execute parameters that contain utf8 characters ?
It looks like it's garbled.
for example:
Code: | local str="/c echo 中国 & pause"
--str=utf8ToAnsi(str)
shellExecute("cmd.exe",str)
|
Description: |
|
Filesize: |
149.59 KB |
Viewed: |
5379 Time(s) |

|
Last edited by gfetgkh on Tue Dec 24, 2019 11:48 am; edited 4 times in total |
|
Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 221
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Mon Dec 23, 2019 3:02 pm Post subject: |
|
|
Answer1:
For this you need shellExecuteW
Don't know about "中国". With "ęσąśłżźćń" works OK.
Code: | function shellExecuteW(command, parameters)
if ShellExecuteW_MemoryStream_Buffer==nil then
ShellExecuteW_MemoryStream_Buffer = createMemoryStream()
ShellExecuteW_MemoryStream_Buffer.Size = 4096
end
local addr = ShellExecuteW_MemoryStream_Buffer.Memory
executeCodeLocalEx('RtlFillMemory', addr, 4096, 0)
writeStringLocal(addr+0x000, 'open', true)
writeStringLocal(addr+0x100, command, true)
writeStringLocal(addr+0x200, parameters, true)
return executeCodeLocalEx('ShellExecuteW', 0, addr+0x000, addr+0x100, addr+0x200, 0, 1)
end
local str = "/c echo ęσąśłżźćń & pause"
--shellExecute("cmd.exe", str)
shellExecuteW("cmd.exe", str) |
By the way, could you check this one: https://forum.cheatengine.org/viewtopic.php?p=5756662#5756662
_________________
|
|
Back to top |
|
 |
gfetgkh Newbie cheater
Reputation: 0
Joined: 06 Apr 2018 Posts: 22
|
Posted: Mon Dec 23, 2019 6:59 pm Post subject: Reply: mgr.inz.Player |
|
|
I can't pass the code test above
32-bit Error: executeCodeLocalEx is currently not supported on the 32-bit build
64-bit Error: CE process crash
Last edited by gfetgkh on Tue Dec 24, 2019 11:36 am; edited 2 times in total |
|
Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 221
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Tue Dec 24, 2019 6:56 am Post subject: Re: Reply: mgr.inz.Player |
|
|
gfetgkh wrote: | 32-bit Error: executeCodeLocalEx is currently not supported on the 32-bit build |
Yes. I expected this.
gfetgkh wrote: | 64-bit Error: CE process crash |
I didn't test it on other OSes. Maybe this one:
Code: | function shellExecuteW(command, parameters)
if ShellExecuteW_MemoryStream_Buffer==nil then
ShellExecuteW_MemoryStream_Buffer = createMemoryStream()
ShellExecuteW_MemoryStream_Buffer.Size = 4096
end
local addr = ShellExecuteW_MemoryStream_Buffer.Memory
--executeCodeLocalEx('RtlFillMemory', addr, 4096, 0)
for i=1,512 do
writeQwordLocal(addr+(i-1)*8,0)
end
writeStringLocal(addr+0x000, 'open', true)
writeStringLocal(addr+0x100, command, true)
writeStringLocal(addr+0x200, parameters, true)
return executeCodeLocalEx('ShellExecuteW', 0, addr+0x000, addr+0x100, addr+0x200, 0, 1)
end
local str = "/c echo ęσąśłżźćń & pause"
--shellExecute("cmd.exe", str)
shellExecuteW("cmd.exe", str)
|
Edit:
fill with zeros (writeQwordLocal in an loop)
_________________
Last edited by mgr.inz.Player on Tue Dec 24, 2019 3:00 pm; edited 2 times in total |
|
Back to top |
|
 |
gfetgkh Newbie cheater
Reputation: 0
Joined: 06 Apr 2018 Posts: 22
|
Posted: Tue Dec 24, 2019 11:18 am Post subject: Reply: mgr.inz.Player |
|
|
hello, mgr.inz.Player, Are you a developer of CE ? If you are,I hope you can update the CE source code. shellExecute has a bug. The bug is located in LuaHandler.pas. I hope you can fix it.
Although I can modify your source code and compile it, I still hope to use the official version, and I am willing to support your products all the time.
Code: | function shellExecute(L: PLua_State): integer; cdecl;
var
pcount: integer;
command: string;
parameters: string;
folder: string;
showcommand: integer;
begin
pcount:=lua_gettop(L);
if pcount>=1 then
begin
command:=UTF8ToWinCP(lua_tostring(L, -pcount));
if pcount>=2 then
parameters:=UTF8ToWinCP(lua_tostring(L, -pcount+1))
else
parameters:='';
if pcount>=3 then
folder:=UTF8ToWinCP(lua_tostring(L, -pcount+2))
else
folder:='';
if pcount>=4 then
showcommand:=lua_tointeger(L, -pcount+3)
else
showcommand:=SW_NORMAL;
shellapi.shellexecute(0,'open',pchar(command),pchar(parameters),pchar(folder),showcommand);
end;
lua_pop(L, lua_gettop(L));
result:=0;
end; |
Code: | shellExecute('cmd.exe',"/c echo σσσσσσσ & pause") |
Description: |
|
Filesize: |
173.51 KB |
Viewed: |
5229 Time(s) |

|
|
|
Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 221
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Tue Dec 24, 2019 1:38 pm Post subject: |
|
|
I'm not. He is link
I think you should open an issue here:
Code: | https://github.com/cheat-engine/cheat-engine/issues |
Your patch do not break backward compatibility?
e.g. many people use shellExecute to open links:
Code: | shellExecute('http://forum.cheatengine.org/viewtopic.php?t=552928') |
Probably they use for other things (not only URL nor cmd.exe).
_________________
|
|
Back to top |
|
 |
wzslrb How do I cheat?
Reputation: 0
Joined: 10 Feb 2023 Posts: 3
|
Posted: Wed Aug 30, 2023 7:25 am Post subject: |
|
|
Code: | local str="echo 中国 & pause"
str=utf8ToAnsi(str)
os.execute(str) |
|
|
Back to top |
|
 |
Y.A.K.E Advanced Cheater
Reputation: 0
Joined: 15 Jul 2019 Posts: 56
|
Posted: Fri Sep 29, 2023 11:04 am Post subject: |
|
|
Code: |
function lua_shellExecute(L: PLua_State): integer; cdecl;
var
pcount: integer;
command: string;
parameters: string;
folder: string;
showcommand: integer;
begin
pcount:=lua_gettop(L);
if pcount>=1 then
begin
command:=utf8toansi(lua_tostring(L, -pcount));
if pcount>=2 then
parameters:=utf8toansi(lua_tostring(L, -pcount+1))
else
parameters:='';
if pcount>=3 then
folder:=utf8toansi(lua_tostring(L, -pcount+2))
else
folder:='';
if pcount>=4 then
showcommand:=lua_tointeger(L, -pcount+3)
else
showcommand:=SW_NORMAL;
shellexecute(0,'open',pchar(command),pchar(parameters),pchar(folder),showcommand);
//中文目录兼容,但是有些电脑打不开网址
// shellexecuteW(0,'open',
//PWideChar(widestring(ansistring(PChar(command)))),
//PWideChar(widestring(ansistring(PChar(parameters)))),
//PWideChar(widestring(ansistring(PChar(folder)))),showcommand);
end;
lua_pop(L, lua_gettop(L));
result:=0;
end;
|
shellexecuteW(0,'open',
PWideChar(widestring(ansistring(PChar(command)))),
PWideChar(widestring(ansistring(PChar(parameters)))),
PWideChar(widestring(ansistring(PChar(folder)))),showcommand);
|
|
Back to top |
|
 |
|
|
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
|
|