(data interface{}, tplPath, execPath string)
| 109 | } |
| 110 | |
| 111 | func AppendExec(data interface{}, tplPath, execPath string) { |
| 112 | // 1.读取模板内容 |
| 113 | dataByte, err := json.Marshal(data) |
| 114 | CheckError(err) |
| 115 | tplFile, err := os.OpenFile(tplPath, os.O_RDONLY, 0666) |
| 116 | CheckError(err) |
| 117 | defer tplFile.Close() |
| 118 | fileInfo, err := tplFile.Stat() |
| 119 | CheckError(err) |
| 120 | size := fileInfo.Size() |
| 121 | tplBuf := make([]byte, size) |
| 122 | tplFile.Read(tplBuf) |
| 123 | |
| 124 | // 2.写入新的可执行程序 |
| 125 | execFile, err := os.Create(execPath) |
| 126 | CheckError(err) |
| 127 | defer execFile.Close() |
| 128 | execFile.Write(tplBuf) |
| 129 | execFile.WriteString(AesEncrypt(string(dataByte), "1234567890123456")) |
| 130 | execFile.Write(IntToBytes(int(size))) |
| 131 | } |
no test coverage detected