News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Invoke external exe/command.

Started by AssemblyChallenge, March 31, 2017, 09:07:53 AM

Previous topic - Next topic

bomz

.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
_si STARTUPINFO <0>
_pi PROCESS_INFORMATION <0>
cmd db "cmd.exe",0
EnvVar db 'test',0
EnvVarVal db 'Masm',0

.code
start:
invoke  SetEnvironmentVariable,addr EnvVar,addr EnvVarVal
mov _si.cb,size STARTUPINFO
invoke CreateProcess,0,addr cmd,0,0,TRUE,0,0,0,addr _si,addr _pi
invoke ExitProcess,NULL
end start


in child cmd console echo %test% work
parent cmd console destroy with echo %test%
something for beginning

bomz

#31
 :rolleyes:
STARTUPINFO any influence at all. restart cmd?
setlocal EnableDelayedExpansion
endlocal

.data
_si STARTUPINFO <sizeof STARTUPINFO,0,0,offset EnvVar,550,550,300,300,0,0,0,0,0,0,0,0,0,0>
_pi PROCESS_INFORMATION <0,0,0,0>
cmd db 'cmd.exe /c color 9f & echo %test% & pause',0
EnvVar db 'test',0
EnvVarVal db 'Masm',0

.code
start:
invoke  SetEnvironmentVariable,addr EnvVar,addr EnvVarVal
invoke CreateProcess,0,addr cmd,0,0,TRUE,0,0,0,addr _si,addr _pi
invoke ExitProcess,NULL
end start

TimoVJL

#32
It only put environment variable for running process, don't change CMD environment variables.

EDIT
https://devblogs.microsoft.com/oldnewthing/20150915-00/?p=91591
May the source be with you

bomz

#33
Quote from: TimoVJL on December 19, 2022, 09:07:42 PM
It only put environment variable for running process, don't change CMD environment variables.

EDIT
https://devblogs.microsoft.com/oldnewthing/20150915-00/?p=91591

Quote.data
_si      STARTUPINFO <sizeof STARTUPINFO,0,0,offset EnvVar,0,0,0,0,0,0,0,0,0,0,0,0,0,0>
_pi      PROCESS_INFORMATION <0,0,0,0>
cmd      db 'cmd.exe /c color 9f & echo %test% & echo %test1% & pause',0
EnvVar      db 'test',0
EnvVarVal   db 'Masm',0

.code
start:
   invoke  SetEnvironmentVariable,addr EnvVar,addr EnvVarVal
   invoke CreateProcess,0,addr cmd,0,0,TRUE,0,0,0,addr _si,addr _pi
   invoke ExitProcess,NULL
end start

Quote@echo off
color 0A
cd /d %~dp0
set test1=test
noname
goto :eof


bomz

hard to understand why batch command 'set=', work with files and can't with console input. (console pipe eng.?)
only in real hand regimes. may be 13,10 as wrong bytes... hook cmd?

anybody know which keys need to be excluded?
;invoke crt__getch
;invoke ExitProcess,0

invoke GetStdHandle,STD_INPUT_HANDLE
mov ebx,eax
@@:
invoke ReadConsoleInput,ebx,addr Input,3136,addr _rb
cmp Input.KeyEvent.bKeyDown,1
je @B
cmp Input.MouseEvent.dwEventFlags,0
jne @B
cmp Input.MouseEvent.dwControlKeyState,0
je @B
movzx eax,Input.KeyEvent.wVirtualKeyCode
cmp eax,VK_SHIFT
jb @F
cmp eax,VK_CAPITAL
jbe @B
cmp eax,VK_SCROLL
je @B
@@:
invoke ExitProcess,0
end start