Jump to content
Sign in to follow this  

help to change a function's pipe example

Recommended Posts

I found this pipe's example in:

client & server

I believe this is the same files in this >topic.

Ok, this is not doubt.

I know AutoIt, but DllStruct (Send, Get and cia) it's unknow for me...
It's alien!

But, someone can show a example how to change the function ExecuteCmd($sCmd) to make something like this:

; from server script
Func ExecuteCmd($sCmd)
    If StringInStr($sCmd, "#InternalCmd") Then
        Local $aCmd = StringSplit($sCmd, " ", 2)
        Switch $aCmd[1]
            Case 1
                Return "one"
            Case 2
                Return "two"
            Case Else
                Return "unknow"
        Local $tProcess, $tSecurity, $tStartup, $hWritePipe

        ; Set up security attributes
        $tSecurity = DllStructCreate($tagSECURITY_ATTRIBUTES)
        DllStructSetData($tSecurity, "Length", DllStructGetSize($tSecurity))
        DllStructSetData($tSecurity, "InheritHandle", True)

        ; Create a pipe for the child process's STDOUT
        If Not _NamedPipes_CreatePipe($hReadPipe, $hWritePipe, $tSecurity) Then
            LogError("ExecuteCmd ........: _NamedPipes_CreatePipe failed")
            Return False

        ; Create child process
        $tProcess = DllStructCreate($tagPROCESS_INFORMATION)
        $tStartup = DllStructCreate($tagSTARTUPINFO)
        DllStructSetData($tStartup, "Size", DllStructGetSize($tStartup))
        DllStructSetData($tStartup, "Flags", BitOR($STARTF_USESTDHANDLES, $STARTF_USESHOWWINDOW))
        DllStructSetData($tStartup, "StdOutput", $hWritePipe)
        DllStructSetData($tStartup, "StdError", $hWritePipe)
        If Not _WinAPI_CreateProcess("", $sCmd, 0, 0, True, 0, 0, "", DllStructGetPtr($tStartup), DllStructGetPtr($tProcess)) Then
            LogError("ExecuteCmd ........: _WinAPI_CreateProcess failed")
            Return False
        _WinAPI_CloseHandle(DllStructGetData($tProcess, "hProcess"))
        _WinAPI_CloseHandle(DllStructGetData($tProcess, "hThread"))

        ; Close the write end of the pipe so that we can read from the read end

        LogMsg("ExecuteCommand ....: " & $sCmd)
        Return True
EndFunc   ;==>ExecuteCmd

I believe the $sCmd is a string, full content a DOS command, like: "cmd.exe /c dir c:windows /s"

I want from client send to server a string too, but, this string is (It's simple, only for example):
InternalCmd 1

InternalCmd 2

InternalCmd other thing...

I cant read, understand or change this function to intercept and make this.
I want mantain the original code (execute a DOS command), but, include new commands.

Br, Detefon

Edited by Detefon

Visit my repository

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...