MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / GenerateUploadChunks

Function GenerateUploadChunks

internal/sessions/transfer.go:186–218  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Chunk generation --------------------------------------------------------------------------- GenerateUploadChunks splits data into base64-encoded chunks and generates the shell commands. The first chunk creates the file (>),

(data []byte, targetPath string, plan TransferPlan)

Source from the content-addressed store, hash-verified

184// the shell commands. The first chunk creates the file (>), subsequent chunks
185// append (>>).
186func GenerateUploadChunks(data []byte, targetPath string, plan TransferPlan) []UploadChunk {
187 if plan.Strategy == StrategyDirectTool || len(data) == 0 {
188 return nil
189 }
190
191 chunkSize := plan.ChunkSize
192 if chunkSize <= 0 {
193 chunkSize = defaultProfile.ChunkSizeBytes
194 }
195
196 var chunks []UploadChunk
197 for offset := 0; offset < len(data); offset += chunkSize {
198 end := offset + chunkSize
199 if end > len(data) {
200 end = len(data)
201 }
202
203 b64 := base64.StdEncoding.EncodeToString(data[offset:end])
204 redirect := ">>"
205 if offset == 0 {
206 redirect = ">"
207 }
208
209 cmd := fmt.Sprintf("echo '%s' | base64 -d %s '%s'", b64, redirect, targetPath)
210
211 chunks = append(chunks, UploadChunk{
212 Index: len(chunks),
213 Base64Data: b64,
214 Command: cmd,
215 })
216 }
217 return chunks
218}
219
220// GenerateDownloadChunks generates shell commands that read sequential chunks
221// of a file via dd+base64.

Calls

no outgoing calls