diff --git a/src/core/lib/Stream.mjs b/src/core/lib/Stream.mjs index b2a183f4..18ce71c3 100644 --- a/src/core/lib/Stream.mjs +++ b/src/core/lib/Stream.mjs @@ -48,12 +48,14 @@ export default class Stream { * Interpret the following bytes as a string, stopping at the next null byte or * the supplied limit. * - * @param {number} numBytes + * @param {number} [numBytes=-1] * @returns {string} */ - readString(numBytes) { + readString(numBytes=-1) { if (this.position > this.length) return undefined; + if (numBytes === -1) numBytes = this.length - this.position; + let result = ""; for (let i = this.position; i < this.position + numBytes; i++) { const currentByte = this.bytes[i]; diff --git a/src/core/operations/ELFInfo.mjs b/src/core/operations/ELFInfo.mjs index 9153e24f..e5e63094 100644 --- a/src/core/operations/ELFInfo.mjs +++ b/src/core/operations/ELFInfo.mjs @@ -66,10 +66,7 @@ class ELFInfo extends Operation { const preMove = stream.position; stream.moveTo(namesOffset + nameOffset); - let nameResult = ""; - let elem = 0; - while ((elem = stream.readInt(1, endianness)) !== 0) - nameResult += String.fromCharCode(elem); + let nameResult = stream.readString(); stream.moveTo(preMove); return nameResult; }