Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Parse MachO LC_FUNCTION_STARTS
- Loading branch information
1 parent
f7cc518
commit 18d8919
Showing
20 changed files
with
474 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* Copyright 2017 R. Thomas | ||
* Copyright 2017 Quarkslab | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <algorithm> | ||
|
||
#include <string> | ||
#include <sstream> | ||
|
||
#include "LIEF/visitors/Hash.hpp" | ||
#include "LIEF/MachO/FunctionStarts.hpp" | ||
|
||
#include "pyMachO.hpp" | ||
|
||
template<class T> | ||
using getter_t = T (FunctionStarts::*)(void) const; | ||
|
||
template<class T> | ||
using setter_t = void (FunctionStarts::*)(T); | ||
|
||
|
||
void init_MachO_FunctionStarts_class(py::module& m) { | ||
|
||
py::class_<FunctionStarts, LoadCommand>(m, "FunctionStarts") | ||
|
||
.def_property("data_offset", | ||
static_cast<getter_t<uint32_t>>(&FunctionStarts::data_offset), | ||
static_cast<setter_t<uint32_t>>(&FunctionStarts::data_offset), | ||
"Offset in the binary where *start functions* are located") | ||
|
||
.def_property("data_size", | ||
static_cast<getter_t<uint32_t>>(&FunctionStarts::data_size), | ||
static_cast<setter_t<uint32_t>>(&FunctionStarts::data_size), | ||
"Size of the functions list in the binary") | ||
|
||
.def_property("functions", | ||
static_cast<getter_t<const std::vector<uint64_t>&>>(&FunctionStarts::functions), | ||
static_cast<setter_t<const std::vector<uint64_t>&>>(&FunctionStarts::functions), | ||
"Addresses of every function entry point in the executable\n\n" | ||
|
||
"This allows for functions to exist that have no entries in the symbol table.\n\n" | ||
|
||
".. warning::\n\n" | ||
"\tThe address is relative to the ``__TEXT`` segment\n\n", | ||
py::return_value_policy::reference_internal) | ||
|
||
.def("add_function", | ||
&FunctionStarts::add_function, | ||
"Add a new function", | ||
"address"_a) | ||
|
||
.def("__eq__", &FunctionStarts::operator==) | ||
.def("__ne__", &FunctionStarts::operator!=) | ||
.def("__hash__", | ||
[] (const FunctionStarts& func) { | ||
return LIEF::Hash::hash(func); | ||
}) | ||
|
||
|
||
.def("__str__", | ||
[] (const FunctionStarts& func) | ||
{ | ||
std::ostringstream stream; | ||
stream << func; | ||
std::string str = stream.str(); | ||
return str; | ||
}); | ||
|
||
} |
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
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,79 @@ | ||
/* Copyright 2017 R. Thomas | ||
* Copyright 2017 Quarkslab | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef LIEF_MACHO_FUNCTION_STARTS_COMMAND_H_ | ||
#define LIEF_MACHO_FUNCTION_STARTS_COMMAND_H_ | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <array> | ||
|
||
#include "LIEF/visibility.h" | ||
#include "LIEF/types.hpp" | ||
|
||
#include "LIEF/MachO/LoadCommand.hpp" | ||
|
||
namespace LIEF { | ||
namespace MachO { | ||
|
||
class DLL_PUBLIC FunctionStarts : public LoadCommand { | ||
public: | ||
FunctionStarts(void); | ||
FunctionStarts(const linkedit_data_command *cmd); | ||
|
||
FunctionStarts& operator=(const FunctionStarts& copy); | ||
FunctionStarts(const FunctionStarts& copy); | ||
|
||
//! @brief Offset in the binary where *start functions* are located | ||
uint32_t data_offset(void) const; | ||
|
||
//! @brief Size of the functions list in the binary | ||
uint32_t data_size(void) const; | ||
|
||
//! @brief Addresses of every function entry point in the executable. | ||
//! | ||
//! This allows for functions to exist that have no entries in the symbol table. | ||
//! | ||
//! @warning The address is relative to the ``__TEXT`` segment | ||
const std::vector<uint64_t>& functions(void) const; | ||
|
||
std::vector<uint64_t>& functions(void); | ||
|
||
//! @brief Add a new function | ||
void add_function(uint64_t address); | ||
|
||
void data_offset(uint32_t offset); | ||
void data_size(uint32_t size); | ||
void functions(const std::vector<uint64_t>& funcs); | ||
|
||
virtual ~FunctionStarts(void); | ||
|
||
bool operator==(const FunctionStarts& rhs) const; | ||
bool operator!=(const FunctionStarts& rhs) const; | ||
|
||
virtual void accept(Visitor& visitor) const override; | ||
|
||
virtual std::ostream& print(std::ostream& os) const override; | ||
|
||
private: | ||
uint32_t data_offset_; | ||
uint32_t data_size_; | ||
std::vector<uint64_t> functions_; | ||
|
||
}; | ||
|
||
} | ||
} | ||
#endif |
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
Oops, something went wrong.