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