MCPcopy Create free account
hub / github.com/ThatGuySam/doesitarm / MachoParser

Function MachoParser

helpers/macho/macho.js:70–315  ·  view source on GitHub ↗
(file, callback)

Source from the content-addressed store, hash-verified

68};
69
70export function MachoParser(file, callback) {
71
72 const machoOutputData = {}
73
74 const hasFileReader = typeof FileReader !== 'undefined'
75
76 //properties
77 this.reader = hasFileReader ? new FileReader() : new FileApi.FileReader()
78
79 function writeToCallback(val) {
80 return
81
82 // if(callbackElement) {
83 // callbackElement.innerHTML +='<tr>'+val+'</tr>';
84 // } else {
85 // throw new Error('Invalid callback.');
86 // }
87 }
88
89 /*
90 @Function FindMagic
91 @Params (Uint8Array) buffer, (bool) breakwhenfound
92 @Return (Array) offsets of found magics
93 */
94 function FindMagic(data, breakwhenfound = false) {
95 var results = [];
96 for(var byte = 0; byte < (data.length - uint32_t); byte++) { //Read 32-bits at a time until the end of the buffer
97 var magic = ReadUint32(data, byte); //Read the next 32-bit magic value
98 if(MAGIC.VALIDATE(magic)) {
99 results.push(byte);
100 if(breakwhenfound) {
101 break;
102 }
103 }
104 }
105 return results;
106 }
107
108
109 /*
110 @Function MapFlags
111 @Params (Uint8Array)flags, (Object)map
112 @Return (Object) key-value mapped dictionary
113 */
114 function MapFlags(value, map) {
115 var res = {};
116 for (var bit = 1; (value < 0 || bit <= value) && bit !== 0; bit <<= 1)
117 if (value & bit) res[map[bit]] = true; //If value and the bit are equal then map the value to the result
118
119 return res;
120 }
121
122 function ParseCommand(type, data, size, off) {
123 var cmd = null;
124 if(type == LOAD_COMMAND_TYPE.LC_SEGMENT) {
125 if(data.length < 48) {
126 // if(process.env.VERBOSE){ console.log('Segment command OOB'); }
127 return new LoadCommand(type, data, size, off);

Callers

nothing calls this directly

Calls 2

addEventListenerMethod · 0.80
readAsArrayBufferMethod · 0.80

Tested by

no test coverage detected