From d18339f4d60de6532b0f596beaf401cd77170ef1 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 16 Jul 2022 21:58:30 -0500 Subject: [PATCH] Enable passing custom FileApi --- helpers/macho/macho.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/helpers/macho/macho.js b/helpers/macho/macho.js index cfe8712..d8e38b3 100644 --- a/helpers/macho/macho.js +++ b/helpers/macho/macho.js @@ -1,6 +1,6 @@ -//macho.js -//Written by Sem Voigtländer -//Licensed under the MIT License +// macho.js +// Written by Sem Voigtländer, modified by Sam Carlton +// Licensed under the MIT License import { mime_binary } from './mimetypes.js' import { ReadUint32, ReadUint16LE, ReadUint32LE, ReadUint16 } from './memory.js' @@ -14,6 +14,8 @@ import { FILE_FLAGS, FILE_TYPE } from './macho.file.js' import Cstr from './macho.cstr.js' import { SegmentCommand } from './macho.segment.js' +let FileApi = undefined + function default_callback(buffer) { console.log('Received ' + buffer.byteLength / (1024 * 1024) + ' MB'); } @@ -69,8 +71,10 @@ export function MachoParser(file, callback) { const machoOutputData = {} + const hasFileReader = typeof FileReader !== 'undefined' + //properties - this.reader = new FileReader(); + this.reader = hasFileReader ? new FileReader() : new FileApi.FileReader() function writeToCallback(val) { return @@ -151,7 +155,9 @@ export function MachoParser(file, callback) { } } - this.reader.onloadend = function(e) { + const onloadend = function (e) { + + // console.log( 'Load complete', e ) let fileType = mime_binary; @@ -298,7 +304,11 @@ export function MachoParser(file, callback) { }).catch(console.log.bind(console)); }; - this.reader.readAsArrayBuffer(file); + // console.log( 'this.reader', this.reader ) + + this.reader.addEventListener( 'load', onloadend ) + + this.reader.readAsArrayBuffer( file ) // console.log('Parsing, please wait...'); @@ -306,7 +316,10 @@ export function MachoParser(file, callback) { -export default async function ( file ) { +export default async function ( file, fileApi ) { + + FileApi = fileApi + return new Promise( ( resolve, reject ) => { try { (new MachoParser( file, resolve ))