/* ExeProcessor.m This file relies upon, and steals code from, the cctools source code available from: http://www.opensource.apple.com/darwinsource/ This file is in the public domain. */ #import #import "ExeProcessor.h" #import "ArchSpecifics.h" #import "ListUtils.h" #import "ObjcAccessors.h" #import "ObjectLoader.h" #import "SysUtils.h" #import "UserDefaultKeys.h" @implementation ExeProcessor // ExeProcessor is a base class that handles processor-independent issues. // PPCProcessor and X86Processor are subclasses that add functionality // specific to those CPUs. The AppController class creates a new instance of // one of those subclasses for each processing, and deletes the instance as // soon as possible. Member variables may or may not be re-initialized before // destruction. Do not reuse a single instance of those subclasses for // multiple processings. // initWithURL:controller:options: // ---------------------------------------------------------------------------- - (id)initWithURL: (NSURL*)inURL controller: (id)inController options: (ProcOptions*)inOptions; { if (!inURL || !inController || !inOptions) return nil; if ((self = [super init]) == nil) return nil; return self; } // dealloc // ---------------------------------------------------------------------------- - (void)dealloc { if (iRAMFile) { free(iRAMFile); iRAMFile = nil; } if (iThunks) { free(iThunks); iThunks = nil; } if (iCPFiltPipe) { if (pclose(iCPFiltPipe) == -1) perror("otx: unable to close c++filt pipe"); } [super dealloc]; } #pragma mark - // sendTypeFromMsgSend: // ---------------------------------------------------------------------------- - (UInt8)sendTypeFromMsgSend: (char*)inString { UInt8 sendType = send; if (strlen(inString) != 13) // not _objc_msgSend { if (strstr(inString, "Super_stret")) sendType = sendSuper_stret; else if (strstr(inString, "Super")) sendType = sendSuper; else if (strstr(inString, "_stret")) sendType = send_stret; else if (strstr(inString, "_rtp")) sendType = send_rtp; else if (strstr(inString, "_fpret")) sendType = send_fpret; else sendType = send_variadic; } return sendType; } #pragma mark - - (BOOL)printDataSections { return NO; } - (void)printDataSection: (section_info*)inSect toFile: (FILE*)outFile {} #pragma mark - #ifdef OTX_DEBUG // printSymbol: // ---------------------------------------------------------------------------- // Used for symbol debugging. - (void)printSymbol: (nlist)inSym { fprintf(stderr, "----------------\n\n"); fprintf(stderr, " n_strx = 0x%08x\n", inSym.n_un.n_strx); fprintf(stderr, " n_type = 0x%02x\n", inSym.n_type); fprintf(stderr, " n_sect = 0x%02x\n", inSym.n_sect); fprintf(stderr, " n_desc = 0x%04x\n", inSym.n_desc); fprintf(stderr, "n_value = 0x%08x (%u)\n\n", inSym.n_value, inSym.n_value); if ((inSym.n_type & N_STAB) != 0) { // too complicated, see fprintf(stderr, "STAB symbol\n"); } else // not a STAB { if ((inSym.n_type & N_PEXT) != 0) fprintf(stderr, "Private external symbol\n\n"); else if ((inSym.n_type & N_EXT) != 0) fprintf(stderr, "External symbol\n\n"); UInt8 theNType = inSym.n_type & N_TYPE; UInt16 theRefType = inSym.n_desc & REFERENCE_TYPE; fprintf(stderr, "Symbol type: "); if (theNType == N_ABS) fprintf(stderr, "Absolute\n"); else if (theNType == N_SECT) fprintf(stderr, "Defined in section %u\n", inSym.n_sect); else if (theNType == N_INDR) fprintf(stderr, "Indirect\n"); else { if (theNType == N_UNDF) fprintf(stderr, "Undefined\n"); else if (theNType == N_PBUD) fprintf(stderr, "Prebound undefined\n"); switch (theRefType) { case REFERENCE_FLAG_UNDEFINED_NON_LAZY: fprintf(stderr, "REFERENCE_FLAG_UNDEFINED_NON_LAZY\n"); break; case REFERENCE_FLAG_UNDEFINED_LAZY: fprintf(stderr, "REFERENCE_FLAG_UNDEFINED_LAZY\n"); break; case REFERENCE_FLAG_DEFINED: fprintf(stderr, "REFERENCE_FLAG_DEFINED\n"); break; case REFERENCE_FLAG_PRIVATE_DEFINED: fprintf(stderr, "REFERENCE_FLAG_PRIVATE_DEFINED\n"); break; case REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY: fprintf(stderr, "REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY\n"); break; case REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY: fprintf(stderr, "REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY\n"); break; default: break; } } } fprintf(stderr, "\n"); } // printBlocks: // ---------------------------------------------------------------------------- // Used for block debugging. Sublclasses may override. - (void)printBlocks: (UInt32)inFuncIndex; {} #endif // OTX_DEBUG @end