diff --git a/helpers/scanner/client.js b/helpers/scanner/client.js index 5f22b33..a0c992f 100644 --- a/helpers/scanner/client.js +++ b/helpers/scanner/client.js @@ -6,8 +6,7 @@ import * as FileApi from '~/helpers/scanner/file-api.js' import { isString, isNonEmptyString } from '~/helpers/check-types.js' import { parsePlistBuffer } from '~/helpers/scanner/parsers/plist.js' -// import { extractMachoMeta } from '~/helpers/scanner/parsers/macho.js' - +import { extractMachoMeta } from '~/helpers/scanner/parsers/macho.js' import { Buffer } from 'buffer/' // For some reason inline 'import()' works better than 'import from' @@ -229,7 +228,7 @@ export class AppScan { this.sendMessage({ message: 'ℹ️ Found Info.plist', - data: this.infoPlist, + // data: this.infoPlist }) } @@ -273,19 +272,24 @@ export class AppScan { throw new Error( 'More than one primary Macho executable found' ) } - // Get blob data from zip - // https://gildas-lormeau.github.io/zip.js/core-api.html#zip-entry + // Get zip as Uint8Array const bundleExecutableUint8Array = await this.readFileEntryData( fileEntry, zip.Uint8ArrayWriter ) - // console.log( 'bundleExecutableBlob', bundleExecutableBlob.buffer ) - const machoFileInstance = new FileApi.File({ name: this.bundleExecutable.filename, type: 'application/x-mach-binary', - buffer: Buffer.from( bundleExecutableUint8Array ), + buffer: Buffer.from( bundleExecutableUint8Array ) }) - this.machoMeta = await extractMachoMeta({ machoFileInstance, FileApi }) + // Get zip as blob + // so we can use it in for the File API when we're in the browser context + // https://gildas-lormeau.github.io/zip.js/core-api.html#zip-entry + machoFileInstance.blob = await this.readFileEntryData( fileEntry, zip.BlobWriter ) + + this.machoMeta = await extractMachoMeta({ + machoFileInstance, + FileApi + }) // console.log( 'this.machoMeta', this.machoMeta ) diff --git a/helpers/scanner/parsers/macho.js b/helpers/scanner/parsers/macho.js index 5f17264..1558cfe 100644 --- a/helpers/scanner/parsers/macho.js +++ b/helpers/scanner/parsers/macho.js @@ -66,11 +66,9 @@ export class MachoNode { async run () { - // console.log( 'machoNodeParser', machoNodeParser ) + // console.log( 'this.machoFileInstance.buffer.readUInt32LE(0)', this.machoFileInstance.buffer.readUInt32LE(0).toString(16), 4277009103 ) - const machoNodeMeta = machoNodeParser.execute( makeFileBuffer( this.machoFileInstance.buffer ) ) - - // console.log( 'machoNodeMeta', machoNodeMeta.cpu ) + const machoNodeMeta = machoNodeParser.execute( this.machoFileInstance.buffer ) return this.mapNodeMetaTOManiacMeta( machoNodeMeta ) } @@ -88,7 +86,16 @@ export class MachoManiac { // import parseMacho from '~/helpers/macho/index.js' const { default: parseMacho } = await import( '~/helpers/macho/index.js' ) - return await parseMacho( this.machoFileInstance, this.FileApi ) + const contextHasFileGlobal = typeof File === 'function' + + // In the Browser, MachManiac uses the File API to read the file + // so we check if the global File API is available and convert our machoFileInstance to File API + // + // In the NodeJS environment, MachManiac uses the FileApi module to read the file + // so we pass through the machoFileInstance as is + const fileInstance = contextHasFileGlobal ? (new File( [this.machoFileInstance.blob], 'App' )) : this.machoFileInstance + + return await parseMacho( fileInstance, this.FileApi ) } }