From 5146877f58727f255c203856d271b3975388513b Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Mon, 18 Jul 2022 16:56:30 -0500 Subject: [PATCH] Enable using multiple macho parsers --- helpers/scanner/client.js | 4 ++-- helpers/scanner/parsers/macho.js | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 helpers/scanner/parsers/macho.js diff --git a/helpers/scanner/client.js b/helpers/scanner/client.js index 61c3d7a..26249d7 100644 --- a/helpers/scanner/client.js +++ b/helpers/scanner/client.js @@ -4,8 +4,8 @@ import prettyBytes from 'pretty-bytes' // import zip from '@zip.js/zip.js' import FileApi, { File } from 'file-api' -import parseMacho from '~/helpers/macho/index.js' import { isString } from '~/helpers/check-types.js' +import { extraMachoMeta } from '~/helpers/scanner/parsers/macho.js' // For some reason inline 'import()' works better than 'import from' // https://gildas-lormeau.github.io/zip.js/ @@ -290,7 +290,7 @@ export class AppScan { buffer: bundleExecutableBlob, }) - this.machoMeta = await parseMacho( machoFileInstance, FileApi ) //await this.parseMachOBlob( bundleExecutableBlob, file.name ) + this.machoMeta = await extraMachoMeta({ machoFileInstance, FileApi }) //await this.parseMachOBlob( bundleExecutableBlob, file.name ) // console.log( 'this.machoMeta', this.machoMeta ) } diff --git a/helpers/scanner/parsers/macho.js b/helpers/scanner/parsers/macho.js new file mode 100644 index 0000000..29b2475 --- /dev/null +++ b/helpers/scanner/parsers/macho.js @@ -0,0 +1,40 @@ + + +export class MachoManiac { + constructor ({ machoFileInstance, FileApi }) { + this.machoFileInstance = machoFileInstance + this.FileApi = FileApi + } + + async run () { + // import parseMacho from '~/helpers/macho/index.js' + const { default: parseMacho } = await import( '~/helpers/macho/index.js' ) + + return await parseMacho( this.machoFileInstance, this.FileApi ) + } +} + + +export async function extraMachoMeta ({ machoFileInstance, FileApi = null }) { + const parsers = [ + MachoManiac + ] + + // Run through each parser + for ( const Parser of parsers ) { + try { + // Run the parser + const parserInstance = new Parser({ + machoFileInstance, + FileApi + }) + const meta = await parserInstance.run() + + return meta + } catch ( err ) { + // console.log( 'err', err ) + } + } + + return null +}