MCPcopy
hub / github.com/gchq/CyberChef / continueUntil

Method continueUntil

src/core/lib/Stream.mjs:168–226  ·  view source on GitHub ↗

* Consume the stream until we reach the specified byte or sequence of bytes. * * @param {number|List } val

(val)

Source from the content-addressed store, hash-verified

166 * @param {number|List<number>} val
167 */
168 continueUntil(val) {
169 if (this.position > this.length) return;
170
171 this.bitPos = 0;
172
173 if (typeof val === "number") {
174 while (++this.position < this.length && this.bytes[this.position] !== val) {
175 continue;
176 }
177 return;
178 }
179
180 // val is an array
181
182 /**
183 * Builds the skip forward table from the value to be searched.
184 *
185 * @param {Uint8Array} val
186 * @param {Number} len
187 * @returns {Uint8Array}
188 */
189 function preprocess(val, len) {
190 const skiptable = new Array();
191 val.forEach((element, index) => {
192 skiptable[element] = len - index;
193 });
194 return skiptable;
195 }
196
197 const length = val.length;
198 const initial = val[length-1];
199 this.position = length;
200
201 // Get the skip table.
202 const skiptable = preprocess(val, length);
203 let found;
204
205 while (this.position < this.length) {
206 // Until we hit the final element of val in the stream.
207 while ((this.position < this.length) && (this.bytes[this.position++] !== initial));
208
209 found = true;
210
211 // Loop through the elements comparing them to val.
212 for (let x = length-1; x >= 0; x--) {
213 if (this.bytes[this.position - length + x] !== val[x]) {
214 found = false;
215
216 // If element is not equal to val's element then jump forward by the correct amount.
217 this.position += skiptable[val[x]];
218 break;
219 }
220 }
221 if (found) {
222 this.position -= length;
223 break;
224 }
225 }

Callers 8

extractJPEGFunction · 0.95
extractGIFFunction · 0.95
extractPDFFunction · 0.95
extractZIPFunction · 0.95
extractPListXMLFunction · 0.95
extractGZIPFunction · 0.95
extractBZIP2Function · 0.95
extractXZFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected