mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
FIx File proccessing for Browser and Node
This commit is contained in:
parent
7f9d891ab7
commit
d7112ae322
2 changed files with 25 additions and 14 deletions
|
|
@ -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 )
|
||||
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue