Skip to content

Commit

Permalink
fix: read macho size (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyg603 authored Jan 11, 2024
1 parent 78dbb93 commit 606f052
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/fat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,17 @@ export class FatFile {
const numberOfMachos = buffer.readUInt32BE(0);

for (let i = 0; i < numberOfMachos; i++) {
const numberOfBytesToRead = lengthOfMachoStartOffset + lengthOfMachoSize;
const machoStartOffset = sizeOfFatMagic + sizeOfNumberOfMachosSection + (i * lengthOfFatArchSection);
const machoFileOffsetOffset = machoStartOffset + lengthOfCpuType + lengthOfCpuSubType;
const { buffer, bytesRead } = await fileHandle.read(Buffer.alloc(lengthOfMachoStartOffset), 0, lengthOfMachoStartOffset, machoFileOffsetOffset);
const { buffer, bytesRead } = await fileHandle.read(Buffer.alloc(numberOfBytesToRead), 0, numberOfBytesToRead, machoFileOffsetOffset);

if (bytesRead !== lengthOfMachoStartOffset) {
if (bytesRead !== numberOfBytesToRead) {
throw new Error('Could not read Fat header.');
}

const machoFileOffset = buffer.readUInt32BE(0);
const machoFileSize = buffer.readUInt32BE(0);
const machoFileOffset = buffer.readUInt32BE(0);
const machoFileSize = buffer.readUInt32BE(lengthOfMachoStartOffset);
const machoFile = new MachoFile(this.path, machoFileOffset, machoFileSize);
const valid = await machoFile.isValid();

Expand Down

0 comments on commit 606f052

Please sign in to comment.