-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
324 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020 Jean-David Gadina - www.xs-labs.com | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
******************************************************************************/ | ||
|
||
/*! | ||
* @header Symbol.hpp | ||
* @copyright (c) 2020, Jean-David Gadina - www.xs-labs.com | ||
*/ | ||
|
||
#ifndef MACHO_SYMBOL_HPP | ||
#define MACHO_SYMBOL_HPP | ||
|
||
#include <memory> | ||
#include <algorithm> | ||
#include <string> | ||
#include <cstdint> | ||
#include <XS.hpp> | ||
#include <MachO/File.hpp> | ||
|
||
namespace MachO | ||
{ | ||
class Symbol: public XS::Info::Object | ||
{ | ||
public: | ||
|
||
Symbol( File::Kind kind, uint32_t stringTableOffset, XS::IO::BinaryStream & stream ); | ||
Symbol( const Symbol & o ); | ||
Symbol( Symbol && o ) noexcept; | ||
virtual ~Symbol() override; | ||
|
||
Symbol & operator =( Symbol o ); | ||
|
||
XS::Info getInfo() const override; | ||
|
||
std::string name() const; | ||
uint32_t nameIndex() const; | ||
uint8_t type() const; | ||
uint8_t section() const; | ||
uint16_t description() const; | ||
uint64_t value() const; | ||
|
||
friend void swap( Symbol & o1, Symbol & o2 ); | ||
|
||
private: | ||
|
||
class IMPL; | ||
|
||
std::unique_ptr< IMPL > impl; | ||
}; | ||
} | ||
|
||
#endif /* MACHO_SYMBOL_HPP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/******************************************************************************* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020 Jean-David Gadina - www.xs-labs.com | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
******************************************************************************/ | ||
|
||
/*! | ||
* @file Symbol.cpp | ||
* @copyright (c) 2020, Jean-David Gadina - www.xs-labs.com | ||
*/ | ||
|
||
#include <MachO/LoadCommands/SymTab.hpp> | ||
#include <MachO/ToString.hpp> | ||
#include <XS.hpp> | ||
|
||
namespace MachO | ||
{ | ||
class Symbol::IMPL | ||
{ | ||
public: | ||
|
||
IMPL( File::Kind kind, uint32_t stringTableOffset, XS::IO::BinaryStream & stream ); | ||
IMPL( const IMPL & o ); | ||
~IMPL(); | ||
|
||
std::string _name; | ||
uint32_t _nameIndex; | ||
uint8_t _type; | ||
uint8_t _section; | ||
uint16_t _description; | ||
uint64_t _value; | ||
}; | ||
|
||
Symbol::Symbol( File::Kind kind, uint32_t stringTableOffset, XS::IO::BinaryStream & stream ): | ||
impl( std::make_unique< IMPL >( kind, stringTableOffset, stream ) ) | ||
{} | ||
|
||
Symbol::Symbol( const Symbol & o ): | ||
impl( std::make_unique< IMPL >( *( o.impl ) ) ) | ||
{} | ||
|
||
Symbol::Symbol( Symbol && o ) noexcept: | ||
impl( std::move( o.impl ) ) | ||
{} | ||
|
||
Symbol::~Symbol() | ||
{} | ||
|
||
Symbol & Symbol::operator =( Symbol o ) | ||
{ | ||
swap( *( this ), o ); | ||
|
||
return *( this ); | ||
} | ||
|
||
XS::Info Symbol::getInfo() const | ||
{ | ||
XS::Info i( "Symbol" ); | ||
|
||
i.addChild( { "Name", this->name() } ); | ||
i.addChild( { "Name Index", XS::ToString::Hex( this->nameIndex() ) } ); | ||
i.addChild( { "Type", XS::ToString::Hex( this->type() ) } ); | ||
i.addChild( { "Section", XS::ToString::Hex( this->section() ) } ); | ||
i.addChild( { "Description", XS::ToString::Hex( this->description() ) } ); | ||
i.addChild( { "Value", XS::ToString::Hex( this->value() ) } ); | ||
|
||
return i; | ||
} | ||
|
||
std::string Symbol::name() const | ||
{ | ||
return this->impl->_name; | ||
} | ||
|
||
uint32_t Symbol::nameIndex() const | ||
{ | ||
return this->impl->_nameIndex; | ||
} | ||
|
||
uint8_t Symbol::type() const | ||
{ | ||
return this->impl->_type; | ||
} | ||
|
||
uint8_t Symbol::section() const | ||
{ | ||
return this->impl->_section; | ||
} | ||
|
||
uint16_t Symbol::description() const | ||
{ | ||
return this->impl->_description; | ||
} | ||
|
||
uint64_t Symbol::value() const | ||
{ | ||
return this->impl->_value; | ||
} | ||
|
||
void swap( Symbol & o1, Symbol & o2 ) | ||
{ | ||
using std::swap; | ||
|
||
swap( o1.impl, o2.impl ); | ||
} | ||
|
||
Symbol::IMPL::IMPL( File::Kind kind, uint32_t stringTableOffset, XS::IO::BinaryStream & stream ): | ||
_nameIndex( stream.readUInt32() ), | ||
_type( stream.readUInt8() ), | ||
_section( stream.readUInt8() ), | ||
_description( stream.readUInt16() ), | ||
_value( kind == File::Kind::MachO32 ? stream.readUInt32() : stream.readUInt64() ) | ||
{ | ||
if( this->_nameIndex != 0 ) | ||
{ | ||
size_t offset = stream.tell(); | ||
|
||
stream.seek( stringTableOffset + this->_nameIndex, XS::IO::BinaryStream::SeekDirection::Begin ); | ||
|
||
this->_name = stream.readNULLTerminatedString(); | ||
|
||
stream.seek( offset, XS::IO::BinaryStream::SeekDirection::Begin ); | ||
} | ||
} | ||
|
||
Symbol::IMPL::IMPL( const IMPL & o ): | ||
_name( o._name ), | ||
_nameIndex( o._nameIndex ), | ||
_type( o._type ), | ||
_section( o._section ), | ||
_description( o._description ), | ||
_value( o._value ) | ||
{} | ||
|
||
Symbol::IMPL::~IMPL() | ||
{} | ||
} |
Oops, something went wrong.