mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Modify stream library to support reading until a null byte
This commit is contained in:
parent
64eae37788
commit
d3de91de85
2 changed files with 5 additions and 6 deletions
|
@ -48,12 +48,14 @@ export default class Stream {
|
||||||
* Interpret the following bytes as a string, stopping at the next null byte or
|
* Interpret the following bytes as a string, stopping at the next null byte or
|
||||||
* the supplied limit.
|
* the supplied limit.
|
||||||
*
|
*
|
||||||
* @param {number} numBytes
|
* @param {number} [numBytes=-1]
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
readString(numBytes) {
|
readString(numBytes=-1) {
|
||||||
if (this.position > this.length) return undefined;
|
if (this.position > this.length) return undefined;
|
||||||
|
|
||||||
|
if (numBytes === -1) numBytes = this.length - this.position;
|
||||||
|
|
||||||
let result = "";
|
let result = "";
|
||||||
for (let i = this.position; i < this.position + numBytes; i++) {
|
for (let i = this.position; i < this.position + numBytes; i++) {
|
||||||
const currentByte = this.bytes[i];
|
const currentByte = this.bytes[i];
|
||||||
|
|
|
@ -66,10 +66,7 @@ class ELFInfo extends Operation {
|
||||||
const preMove = stream.position;
|
const preMove = stream.position;
|
||||||
stream.moveTo(namesOffset + nameOffset);
|
stream.moveTo(namesOffset + nameOffset);
|
||||||
|
|
||||||
let nameResult = "";
|
let nameResult = stream.readString();
|
||||||
let elem = 0;
|
|
||||||
while ((elem = stream.readInt(1, endianness)) !== 0)
|
|
||||||
nameResult += String.fromCharCode(elem);
|
|
||||||
stream.moveTo(preMove);
|
stream.moveTo(preMove);
|
||||||
return nameResult;
|
return nameResult;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue