MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / ApplyHeaderDataVariables

Method ApplyHeaderDataVariables

view/sharedcache/core/MachOProcessor.cpp:265–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263}
264
265void SharedCacheMachOProcessor::ApplyHeaderDataVariables(SharedCacheMachOHeader& header)
266{
267 // TODO: By using a binary reader we assume the sections have all been mapped.
268 // TODO: Maybe we should just use the virtual memory reader...
269 // TODO: We can define symbols and data variables even if there is no backing region FWIW
270 BinaryReader reader(m_view);
271 // TODO: Do we support non 64 bit header?
272 reader.Seek(header.textBase + sizeof(mach_header_64));
273
274 m_view->DefineDataVariable(header.textBase, Type::NamedType(m_view, QualifiedName("mach_header_64")));
275 m_view->DefineAutoSymbol(
276 new Symbol(DataSymbol, "__macho_header::" + header.identifierPrefix, header.textBase, LocalBinding));
277
278 auto applyLoadCommand = [&](uint64_t cmdAddr, const load_command& load) {
279 switch (load.cmd)
280 {
281 case LC_SEGMENT:
282 {
283 m_view->DefineDataVariable(cmdAddr, Type::NamedType(m_view, QualifiedName("segment_command")));
284 reader.SeekRelative(5 * 8);
285 size_t numSections = reader.Read32();
286 reader.SeekRelative(4);
287 for (size_t j = 0; j < numSections; j++)
288 {
289 m_view->DefineDataVariable(reader.GetOffset(), Type::NamedType(m_view, QualifiedName("section")));
290 auto sectionSymName =
291 fmt::format("__macho_section::{}_[{}]", header.identifierPrefix, std::to_string(j));
292 auto sectionSym = new Symbol(DataSymbol, sectionSymName, reader.GetOffset(), LocalBinding);
293 m_view->DefineAutoSymbol(sectionSym);
294 reader.SeekRelative((8 * 8) + 4);
295 }
296 break;
297 }
298 case LC_SEGMENT_64:
299 {
300 m_view->DefineDataVariable(cmdAddr, Type::NamedType(m_view, QualifiedName("segment_command_64")));
301 reader.SeekRelative(7 * 8);
302 size_t numSections = reader.Read32();
303 reader.SeekRelative(4);
304 for (size_t j = 0; j < numSections; j++)
305 {
306 m_view->DefineDataVariable(reader.GetOffset(), Type::NamedType(m_view, QualifiedName("section_64")));
307 auto sectionSymName =
308 fmt::format("__macho_section_64::{}_[{}]", header.identifierPrefix, std::to_string(j));
309 auto sectionSym = new Symbol(DataSymbol, sectionSymName, reader.GetOffset(), LocalBinding);
310 m_view->DefineAutoSymbol(sectionSym);
311 reader.SeekRelative(10 * 8);
312 }
313 break;
314 }
315 case LC_SYMTAB:
316 m_view->DefineDataVariable(cmdAddr, Type::NamedType(m_view, QualifiedName("symtab")));
317 break;
318 case LC_DYSYMTAB:
319 m_view->DefineDataVariable(cmdAddr, Type::NamedType(m_view, QualifiedName("dysymtab")));
320 break;
321 case LC_UUID:
322 m_view->DefineDataVariable(cmdAddr, Type::NamedType(m_view, QualifiedName("uuid")));

Callers

nothing calls this directly

Calls 10

ArrayTypeClass · 0.85
IntegerTypeClass · 0.85
DefineDataVariableMethod · 0.80
DefineAutoSymbolMethod · 0.80
LogErrorMethod · 0.80
QualifiedNameClass · 0.50
SeekMethod · 0.45
SeekRelativeMethod · 0.45
Read32Method · 0.45
GetOffsetMethod · 0.45

Tested by

no test coverage detected