Reenable MachoNode

This commit is contained in:
Sam Carlton 2022-07-27 21:25:36 -05:00
parent 94b1849ba3
commit e008ad7ddf

View file

@ -2,7 +2,7 @@ import { Buffer } from 'buffer/index.js'
import parseMacho from '~/helpers/macho/index.js'
// import { Parser as MachoNodeParser } from './macho-node/parser.js'
import { Parser as MachoNodeParser } from './macho-node/parser.js'
function makeFileBuffer ( buffer ) {
const fileBuffer = new Buffer.alloc( buffer.byteLength )
@ -13,68 +13,68 @@ function makeFileBuffer ( buffer ) {
return fileBuffer
}
// const machoNodeParser = new MachoNodeParser()
const machoNodeParser = new MachoNodeParser()
// Tends to not support universal architecture
// but support some MachoManiac doesn't and fails faster
// so we run it first
// https://github.com/indutny/macho
// export class MachoNode {
// constructor ({ machoFileInstance, FileApi }) {
// this.machoFileInstance = machoFileInstance
// this.FileApi = FileApi
// }
export class MachoNode {
constructor ({ machoFileInstance, FileApi }) {
this.machoFileInstance = machoFileInstance
this.FileApi = FileApi
}
// // MachNode cpu types mapped to MachoManiac cpu types
// // MachoNode types - https://github.com/indutny/macho/blob/c9d02419b36a468ebb4dcef66d0f9b98b6f22dbd/lib/macho/constants.js#L9
// // MachoManiac types - https://github.com/MTJailed/MachoManiac/blob/98d2d31d38d3ea3c911468181eed6e5f445eb556/macho.cpu.js#L13
// cpuMap = new Map([
// ['vax', 'VAX'],
// ['mc680x0', 'MC680'],
// // https://superuser.com/a/74354/412612
// ['i386', 'X86'],
// ['x86_64', 'X86'],
// ['mc98000', 'MC98000'],
// ['hppa', 'HPPA'],
// ['arm', 'ARM'],
// ['arm64', 'ARM64'],
// // arm64_32 is a variant of arm64 with 32-bit pointer sizes, used on Apple Watch Series 4 and later.
// // https://stackoverflow.com/a/68248923/1397641
// ['arm64_32', 'ARM64'],
// ['mc88000', 'MC88000'],
// ['sparc', 'SPARC'],
// ['i860', 'I860'],
// // ['alpha', '???']
// ['powerpc', 'POWERPC'],
// ['powerpc64', 'POWERPC64']
// ])
// MachNode cpu types mapped to MachoManiac cpu types
// MachoNode types - https://github.com/indutny/macho/blob/c9d02419b36a468ebb4dcef66d0f9b98b6f22dbd/lib/macho/constants.js#L9
// MachoManiac types - https://github.com/MTJailed/MachoManiac/blob/98d2d31d38d3ea3c911468181eed6e5f445eb556/macho.cpu.js#L13
cpuMap = new Map([
['vax', 'VAX'],
['mc680x0', 'MC680'],
// https://superuser.com/a/74354/412612
['i386', 'X86'],
['x86_64', 'X86'],
['mc98000', 'MC98000'],
['hppa', 'HPPA'],
['arm', 'ARM'],
['arm64', 'ARM64'],
// arm64_32 is a variant of arm64 with 32-bit pointer sizes, used on Apple Watch Series 4 and later.
// https://stackoverflow.com/a/68248923/1397641
['arm64_32', 'ARM64'],
['mc88000', 'MC88000'],
['sparc', 'SPARC'],
['i860', 'I860'],
// ['alpha', '???']
['powerpc', 'POWERPC'],
['powerpc64', 'POWERPC64']
])
// mapNodeMetaTOManiacMeta ( machoNodeMeta ) {
mapNodeMetaTOManiacMeta ( machoNodeMeta ) {
// return {
// // Single entry since MachoNode doesn't support universal architectures
// architectures: [{
// bits: machoNodeMeta.bits,
// fileType: machoNodeMeta.filetype,
// // header: architecture.header,
// // loadCommandsInfo: architecture.loadCommandsInfo,
// magic: machoNodeMeta.magic,
// // offset: architecture.offset,
// processorSubType: machoNodeMeta.subtype,
// processorType: this.cpuMap.get( machoNodeMeta.cpu.type ),
// }]
// }
// }
return {
// Single entry since MachoNode doesn't support universal architectures
architectures: [{
bits: machoNodeMeta.bits,
fileType: machoNodeMeta.filetype,
// header: architecture.header,
// loadCommandsInfo: architecture.loadCommandsInfo,
magic: machoNodeMeta.magic,
// offset: architecture.offset,
processorSubType: machoNodeMeta.subtype,
processorType: this.cpuMap.get( machoNodeMeta.cpu.type ),
}]
}
}
// async run () {
async run () {
// // console.log( 'this.machoFileInstance.buffer.readUInt32LE(0)', this.machoFileInstance.buffer.readUInt32LE(0).toString(16), 4277009103 )
// console.log( 'this.machoFileInstance.buffer.readUInt32LE(0)', this.machoFileInstance.buffer.readUInt32LE(0).toString(16), 4277009103 )
// const machoNodeMeta = machoNodeParser.execute( this.machoFileInstance.buffer )
const machoNodeMeta = machoNodeParser.execute( this.machoFileInstance.buffer )
// return this.mapNodeMetaTOManiacMeta( machoNodeMeta )
// }
// }
return this.mapNodeMetaTOManiacMeta( machoNodeMeta )
}
}
// https://github.com/MTJailed/MachoManiac
@ -105,7 +105,7 @@ export class MachoManiac {
export async function extractMachoMeta ({ machoFileInstance, FileApi = null }) {
const parsers = [
// MachoNode,
MachoNode,
MachoManiac
]