Code: Select all
cp:=new ChildProcess_ConsoleSend("aescrypt.exe -d -o - x.txt.aes")
while (cp.Peek()!=="E n t e r p a s s w o r d : ") {
Sleep 100
}
cp.Reset_Peek()
cp.ConsoleSend("apples`r")
response:=cp.ReadUntilClosed()
AesPassword:=SubStr(response,5)
if (InStr(AesPassword, "this_is_the_password")) {
MsgBox % "It's Working"
}
class ChildProcess_ConsoleSend {
__New(CmdLine, WorkingDir:=0, Codepage:="UTF-8", includeStdErr:=true) {
(WorkingDir==0 && WorkingDir:=A_WorkingDir)
DllCall("CreatePipe","Ptr*",hReadPipe:=0,"Ptr*",hWritePipe:=0,"Ptr",0,"Uint",0)
DllCall("SetHandleInformation","Ptr",hWritePipe,"Uint",1,"Uint",1) ;HANDLE_FLAG_INHERIT:1
DllCall("SetNamedPipeHandleState","Ptr",hReadPipe,"Uint*",lpMode:=1,"Ptr",0,"Ptr",0) ;PIPE_NOWAIT
VarSetCapacity(STARTUPINFOW,9*A_PtrSize+0x20,0)
NumPut(9*A_PtrSize+0x20,STARTUPINFOW,0x0,"Uint") ;cb
;NumPut(0,STARTUPINFOW,4*A_PtrSize+0x20,"uShort") ;wShowWindow:SW_HIDE
NumPut(hWritePipe,STARTUPINFOW,4*A_PtrSize+0x20,"Ptr") ;hStdOutput
NumPut(0x00000101,STARTUPINFOW,4*A_PtrSize+0x1c,"Uint") ;dwFlags:STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW
NumPut(hWritePipe,STARTUPINFOW,7*A_PtrSize+0x20,"Ptr") ;hStdOutput
(includeStdErr && NumPut(hWritePipe,STARTUPINFOW,8*A_PtrSize+0x20,"Ptr")) ;hStdError
VarSetCapacity(PROCESS_INFORMATION,2*A_PtrSize+0x8)
success:=DllCall("CreateProcessW","Ptr",0,"WStr",CmdLine,"Ptr",0,"Ptr",0,"Int",1,"Uint",0x00000410,"Ptr",0,"WStr",WorkingDir,"Ptr",&STARTUPINFOW,"Ptr",&PROCESS_INFORMATION) ;CREATE_NO_WINDOW|CREATE_NEW_CONSOLE
if (!success) {
throw Exception("failed to create process",0,"command:" CmdLine "`nWorkingDir:" WorkingDir)
}
DllCall("CloseHandle","Ptr",hWritePipe)
this.fileObj:=FileOpen(hReadPipe,"h",Codepage)
this.PID:=NumGet(PROCESS_INFORMATION,2*A_PtrSize,"Uint")
this.Codepage:=Codepage
this.peekStr:=""
}
_Read() {
if (this.Codepage=="UTF-8") {
VarSetCapacity(buf,4096)
bytesRead:=this.fileObj.RawRead(buf,4095)
if (!bytesRead) {
return ""
}
i:=0
while (i<bytesRead) {
if (NumGet(buf,i,"UChar")==0) {
NumPut(0x20,buf,i,"UChar")
}
++i
}
NumPut(0x00,buf,i,"UChar")
retStr:=StrGet(&buf,"UTF-8")
VarSetCapacity(buf,0)
return retStr
} else {
return this.fileObj.Read()
}
}
Reset_Peek() {
this.peekStr:=""
}
Peek() {
this.peekStr.=this._Read()
return this.peekStr
}
ReadUntilClosed() {
while (DllCall("PeekNamedPipe","Ptr",this.fileObj.Handle,"Ptr",0,"Uint",0,"Ptr",0,"Uint*",lpTotalBytesAvail:=0,"Ptr",0)) {
if (!lpTotalBytesAvail) {
Sleep 1
}
this.peekStr.=this._Read()
}
return this.peekStr
}
ConsoleSend(text) { ;https://www.autohotkey.com/boards/viewtopic.php?style=17&t=107780
if (!DllCall("AttachConsole","uint",this.PID)) {
DllCall("FreeConsole")
if (!DllCall("AttachConsole","uint",this.PID)) {
Sleep 100
DllCall("FreeConsole")
if (!DllCall("AttachConsole","uint",this.PID)) {
throw Exception("Script is already attached to a console.")
}
}
}
hConIn:=DllCall("CreateFileA","AStr","CONIN$","Uint",0x40000000,"Uint",0x00000007,"Ptr",0,"Uint",3,"Uint",0,"Ptr",0) ;GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, OPEN_EXISTING
if (hConIn == -1) {
throw Exception("CreateFileA")
}
length:=StrLen(text)
VarSetCapacity(INPUT_RECORD,0x14*2*length,0)
; wVirtualKeyCode, wVirtualScanCode and dwControlKeyState are not needed,
; so are left at the default value of zero.
c:=1,i:=0
while (c<=length) {
NumPut(1,INPUT_RECORD,i+0x4,"Int") ; ir.KeyEvent.bKeyDown := true
NumPut(0,INPUT_RECORD,i+0x4+0x14,"Int") ; ir.KeyEvent.bKeyDown := false
wchar:=Ord(SubStr(text,c,1))
loop 2 {
NumPut(wchar,INPUT_RECORD,i+0xe,"uShort") ; ir.KeyEvent.uChar.UnicodeChar := text[c]
NumPut(1,INPUT_RECORD,i+0x0,"uShort") ; ir.EventType := KEY_EVENT
NumPut(1,INPUT_RECORD,i+0x8,"uShort") ; ir.KeyEvent.wRepeatCount := 1
i+=0x14
}
++c
}
DllCall("WriteConsoleInput","Ptr",hconin,"Ptr",&INPUT_RECORD,"Uint",2*length,"Uint*",0)
}
}