# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # from macho.sections.section import Section, S_CSTRING_LITERALS from macho.utilities import readString from macho.symbol import SYMTYPE_CSTRING, Symbol def _stringReader(file, curAddr, final): while curAddr < final: (string, length) = readString(file, returnLength=True) if length: yield Symbol(string, curAddr, SYMTYPE_CSTRING) curAddr += length+1 class CStringSection(Section): """The C string (``__TEXT,__cstring``) section.""" def analyze(self, segment, machO): machO.addSymbols(_stringReader(machO.file, self.addr, self.addr + self.size)) Section.registerFactoryFType(S_CSTRING_LITERALS, CStringSection.byFType)
return False elif not dysymtab.isAnalyzed: # and loaded return True elif not dysymtab.indirectsymoff: # and has the indirect symbol table. return False symtab = machO.loadCommands.any('className', 'SymtabCommand') if symtab is None: return False elif not symtab.isAnalyzed: return True stride = self.reserved[1] or machO.pointerWidth count = self.size // stride symbols = machO.symbols symbols_append = symbols.append indirectSyms = dysymtab.indirectSymbols(self.reserved[0], self.size // stride, machO) addresses = list(range(self.addr, self.addr + count * stride, stride)) machO.provideAddresses(list(zip(indirectSyms, addresses))) Section.registerFactoryFType(S_NON_LAZY_SYMBOL_POINTERS, SymbolPtrSection.byFType) # Section.registerFactoryFType(S_LAZY_SYMBOL_POINTERS, SymbolPtrSection.byFType) # # - The __la_symbol_ptr adds nothing of value to the symbol table. # Section.registerFactoryFType(S_LAZY_DYLIB_SYMBOL_POINTERS, SymbolPtrSection.byFType) Section.registerFactoryFType(S_SYMBOL_STUBS, SymbolPtrSection.byFType)
if dysymtab is None: # Make sure the DYSYMTAB command exists. return False elif not dysymtab.isAnalyzed: # and loaded return True elif not dysymtab.indirectsymoff: # and has the indirect symbol table. return False symtab = machO.loadCommands.any('className', 'SymtabCommand') if symtab is None: return False elif not symtab.isAnalyzed: return True stride = self.reserved[1] or machO.pointerWidth count = self.size // stride symbols = machO.symbols symbols_append = symbols.append indirectSyms = dysymtab.indirectSymbols(self.reserved[0], self.size // stride, machO) addresses = range(self.addr, self.addr + count*stride, stride) machO.provideAddresses(zip(indirectSyms, addresses)) Section.registerFactoryFType(S_NON_LAZY_SYMBOL_POINTERS, SymbolPtrSection.byFType) # Section.registerFactoryFType(S_LAZY_SYMBOL_POINTERS, SymbolPtrSection.byFType) # # - The __la_symbol_ptr adds nothing of value to the symbol table. # Section.registerFactoryFType(S_LAZY_DYLIB_SYMBOL_POINTERS, SymbolPtrSection.byFType) Section.registerFactoryFType(S_SYMBOL_STUBS, SymbolPtrSection.byFType)
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # from macho.sections.section import Section, S_CSTRING_LITERALS from macho.utilities import readString from macho.symbol import SYMTYPE_CSTRING, Symbol def _stringReader(file, curAddr, final): while curAddr < final: (string, length) = readString(file, returnLength=True) if length: yield Symbol(string, curAddr, SYMTYPE_CSTRING) curAddr += length + 1 class CStringSection(Section): """The C string (``__TEXT,__cstring``) section.""" def analyze(self, segment, machO): machO.addSymbols( _stringReader(machO.file, self.addr, self.addr + self.size)) Section.registerFactoryFType(S_CSTRING_LITERALS, CStringSection.byFType)