Skip to content

Commit

Permalink
Added archOffset and archLength
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Jan 19, 2025
1 parent de73251 commit f9d45f1
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions macho/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Universal {
*
* @param reader Reader.
* @param offset Offset for subsection.
* @param length Length of subsection, requires offset.
* @param length Length of subsection.
*/
public async open(reader: Reader, offset = 0, length = 0): Promise<void> {
offset = (+offset || 0) - (offset % 1 || 0);
Expand Down Expand Up @@ -231,6 +231,38 @@ export class Universal {
return !!this.mReader;
}

/**
* Get offset or architecture.
*
* @param arch Architecture to get the offset of.
* @returns Architecture offset.
*/
public archOffset(arch: Const<Architecture>): number {
if (this.isUniversal()) {
return this.mBase + this.findArch(arch).offset;
}
if (this.mThinArch!.matches(arch)) {
return 0;
}
throw new RangeError('Architecture not found');
}

/**
* Get length of architecture.
*
* @param arch Architecture to get the length of.
* @returns Architecture length.
*/
public archLength(arch: Const<Architecture>): number {
if (this.isUniversal()) {
return this.mBase + this.findArch(arch).size;
}
if (this.mThinArch!.matches(arch)) {
return this.mReader!.size;
}
throw new RangeError('Architecture not found');
}

/**
* Is part of a FAT file.
*
Expand Down Expand Up @@ -343,7 +375,7 @@ export class Universal {
return a;
}
}
throw new RangeError('No matching architecture');
throw new RangeError('Architecture not found');
}

/**
Expand Down

0 comments on commit f9d45f1

Please sign in to comment.