Move makeFileBuffer logic to function

This commit is contained in:
Sam Carlton 2022-07-19 22:26:19 -05:00
parent 3d05017809
commit 5bce0c5dc3

View file

@ -1,5 +1,13 @@
import { Buffer } from 'buffer'; import bufferApi from 'buffer'
function makeFileBuffer ( buffer ) {
const fileBuffer = new bufferApi.Buffer.alloc( buffer.byteLength )
for (var i = 0; i < buffer.length; i++)
fileBuffer[i] = buffer[i];
return fileBuffer
}
// 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
@ -35,17 +43,6 @@ export class MachoNode {
['powerpc64', 'POWERPC64'] ['powerpc64', 'POWERPC64']
]) ])
fileBuffer () {
const machoBuffer = new Buffer.alloc( this.machoFileInstance.buffer.byteLength )
for (var i = 0; i < this.machoFileInstance.buffer.length; i++)
machoBuffer[i] = this.machoFileInstance.buffer[i];
// console.log( 'this.machoFileInstance', this.machoFileInstance.buffer.byteLength )
return machoBuffer
}
mapNodeMetaTOManiacMeta ( machoNodeMeta ) { mapNodeMetaTOManiacMeta ( machoNodeMeta ) {
return { return {
@ -66,7 +63,7 @@ export class MachoNode {
async run () { async run () {
const { parse } = await import( 'macho' ) const { parse } = await import( 'macho' )
const machoNodeMeta = parse( this.fileBuffer() ) const machoNodeMeta = machoNodeParser.execute( makeFileBuffer( this.machoFileInstance.buffer ) )
// console.log( 'machoNodeMeta', machoNodeMeta.cpu ) // console.log( 'machoNodeMeta', machoNodeMeta.cpu )