15Ağu
execute command in go without storing the command in a .exe file
I am trying to do a go program to execute a .exe
file, but without be actually a .exe
file. The idea is to read the executable from a .txt
file and decode it (it is in base64). Once I hava that code stored in a variale, I want to execute it directecly, without having to write it in disk.
In this line why do you decode and store the code in the variable decodedDataBytes:
decodedDataBytes, err := base64.StdEncoding.DecodeString(decodedData)
Then I write it in a temp file and execute it like this:
tempFilePath := "temp.exe"
err = ioutil.WriteFile(tempFilePath, decodedDataBytes, 0644)
if err != nil {
log.Fatal(err)
}
cmd := exec.Command("D:\temp.exe")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
This works just fine, but I need to do it without storing the code in the file temp.exe
.
How can I do this??
I am using go, but if this can be done with other language, I accept ideas too.