Skip to content

Commit

Permalink
Added the architecture method
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Jan 20, 2025
1 parent bf9ae8e commit b33683c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions macho/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,48 @@ export class Universal {
return !!this.mReader;
}

/**
* Get Mach-O for architecture.
*
* @param arch Architecture to get.
* @returns Mach-O.
*/
public async architecture(arch: Const<Architecture>): Promise<MachO>;

/**
* Get Mach-O for offset.
*
* @param arch Offset of binary.
* @returns Mach-O.
*/
public async architecture(offset: number): Promise<MachO>;

public async architecture(a: Const<Architecture> | number): Promise<MachO> {
if (typeof a === 'number') {
if (this.isUniversal()) {
const length = this.lengthOfSlice(a);
const macho = new MachO();
await macho.open(this.mReader!, a, length);
return this.make(macho);
}
if (a === this.mBase) {
const macho = new MachO();
await macho.open(this.mReader!);
return macho;
}
} else {
if (this.isUniversal()) {
return this.findImage(a);
}
if (this.mThinArch!.matches(a)) {
const macho = new MachO();
await macho.open(this.mReader!, this.mBase, this.mLength);
return macho;
}
}
throw new Error('Architecture not found');
}

/**
* Get offset or architecture.
*
Expand Down

0 comments on commit b33683c

Please sign in to comment.