Copy copies the data from src to dst, injecting the Payload if Sniff found the marker.
(dst io.Writer)
| 139 | // Copy copies the data from src to dst, injecting the Payload if Sniff found |
| 140 | // the marker. |
| 141 | func (injector *realInjector) Copy(dst io.Writer) (int64, error) { |
| 142 | var preludeLen int64 |
| 143 | if injector.found { |
| 144 | startn, err := io.Copy( |
| 145 | dst, |
| 146 | bytes.NewBuffer( |
| 147 | injector.sniffedData[:injector.offset], |
| 148 | ), |
| 149 | ) |
| 150 | if err != nil { |
| 151 | return startn, err |
| 152 | } |
| 153 | payloadn, err := io.Copy(dst, bytes.NewBuffer(injector.conf.Payload)) |
| 154 | if err != nil { |
| 155 | return startn + payloadn, err |
| 156 | } |
| 157 | endn, err := io.Copy( |
| 158 | dst, bytes.NewBuffer(injector.sniffedData[injector.offset:]), |
| 159 | ) |
| 160 | if err != nil { |
| 161 | return startn + payloadn + endn, err |
| 162 | } |
| 163 | preludeLen = startn + payloadn + endn |
| 164 | } else { |
| 165 | n, err := io.Copy(dst, bytes.NewBuffer(injector.sniffedData)) |
| 166 | if err != nil { |
| 167 | return n, err |
| 168 | } |
| 169 | preludeLen = int64(len(injector.sniffedData)) |
| 170 | } |
| 171 | n, err := io.Copy(dst, injector.src) |
| 172 | return n + preludeLen, err |
| 173 | } |