Skip to content

Commit

Permalink
WIp
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed May 7, 2024
1 parent 99c4ee7 commit d0b0c9e
Show file tree
Hide file tree
Showing 20 changed files with 787 additions and 674 deletions.
1,063 changes: 588 additions & 475 deletions api/python/lief/MachO.pyi

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/python/src/MachO/objects/pyHeader.cpp
Expand Up @@ -16,7 +16,7 @@
#include <string>
#include <sstream>
#include <nanobind/stl/string.h>
#include <nanobind/stl/set.h>
#include <nanobind/stl/vector.h>
#include <nanobind/operators.h>

#include "LIEF/MachO/Header.hpp"
Expand Down
2 changes: 1 addition & 1 deletion api/python/src/MachO/objects/pyRelocation.cpp
Expand Up @@ -39,7 +39,7 @@ struct relocations_typing : public nanobind::object {
"lief.MachO.PPC_RELOCATION, "
"lief.MachO.ARM_RELOCATION, "
"lief.MachO.ARM64_RELOCATION, "
"lief.MachO.REBASE_TYPES, "
"lief.MachO.DyldInfo.REBASE_TYPE, "
"]", check)

static bool check(handle h) {
Expand Down
2 changes: 1 addition & 1 deletion include/LIEF/MachO/DyldBindingInfo.hpp
Expand Up @@ -58,7 +58,7 @@ class LIEF_API DyldBindingInfo : public BindingInfo {
DyldBindingInfo& operator=(const DyldBindingInfo& other) = default;
DyldBindingInfo(const DyldBindingInfo& other) = default;

DyldBindingInfo(DyldBindingInfo&&) noexcept;
DyldBindingInfo(DyldBindingInfo&&) noexcept = default;

void swap(DyldBindingInfo& other) noexcept;

Expand Down
7 changes: 3 additions & 4 deletions include/LIEF/MachO/DynamicSymbolCommand.hpp
Expand Up @@ -122,14 +122,14 @@ class LIEF_API DynamicSymbolCommand : public LoadCommand {
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t external_reference_symbol_offset() const {
return external_relocation_offset_;
return external_reference_symbol_offset_;
}

//! Number of entries in the external reference table
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t nb_external_reference_symbols() const {
return nb_external_define_symbols_;
return nb_external_reference_symbols_;
}

//! Byte offset from the start of the file to the indirect symbol table data.
Expand Down Expand Up @@ -180,7 +180,6 @@ class LIEF_API DynamicSymbolCommand : public LoadCommand {
return nb_local_relocations_;
}


void idx_local_symbol(uint32_t value) {
idx_local_symbol_ = value;
}
Expand Down Expand Up @@ -220,7 +219,7 @@ class LIEF_API DynamicSymbolCommand : public LoadCommand {
external_reference_symbol_offset_ = value;
}
void nb_external_reference_symbols(uint32_t value) {
nb_external_define_symbols_ = value;
nb_external_reference_symbols_ = value;
}

void indirect_symbol_offset(uint32_t value) {
Expand Down
2 changes: 1 addition & 1 deletion include/LIEF/MachO/SubFramework.hpp
Expand Up @@ -71,7 +71,7 @@ class LIEF_API SubFramework : public LoadCommand {
std::ostream& print(std::ostream& os) const override;

static bool classof(const LoadCommand* cmd) {
return cmd->command() == LoadCommand::TYPE::SUB_UMBRELLA;
return cmd->command() == LoadCommand::TYPE::SUB_FRAMEWORK;
}

private:
Expand Down
2 changes: 1 addition & 1 deletion src/MachO/BinaryParser.tcc
Expand Up @@ -1723,7 +1723,7 @@ ok_error_t BinaryParser::parse_dyldinfo_generic_bind() {
}
const ThreadedBindData& th_bind_data = ordinal_table[ordinal];
do_bind<MACHO_T>(
DyldBindingInfo::CLASS::STANDARD,
DyldBindingInfo::CLASS::THREADED,
th_bind_data.type,
segment_idx,
segment_offset,
Expand Down
8 changes: 4 additions & 4 deletions tests/macho/test_bin2lib.py
Expand Up @@ -7,22 +7,22 @@
def test_bin2lib(tmp_path):
file_path = "MachO/mbedtls_selftest_arm64.bin" if is_aarch64() else "MachO/mbedtls_selftest_x86_64.bin"
bin_path = pathlib.Path(get_sample(file_path))
original = lief.parse(bin_path.as_posix())
original = lief.MachO.parse(bin_path.as_posix()).at(0)
output = f"{tmp_path}/libtest.dylib"

header: lief.MachO.Header = original.header
header.file_type = lief.MachO.FILE_TYPES.DYLIB
header.file_type = lief.MachO.Header.FILE_TYPE.DYLIB

# Create LC_ID_DYLIB command
original.add(lief.MachO.DylibCommand.id_dylib(output, 0, 1, 2))

# Create a new export :)
ADDR = 0x10000D782 if header.cpu_type == lief.MachO.CPU_TYPES.x86_64 else 0x10004F3F4
ADDR = 0x10000D782 if header.cpu_type == lief.MachO.Header.CPU_TYPE.X86_64 else 0x10004F3F4
assert original.add_exported_function(ADDR, "_lief_test_export")

original.write(output)

new = lief.parse(output)
new = lief.MachO.parse(output).at(0)
checked, err = lief.MachO.check_layout(new)
assert checked, err
if is_osx():
Expand Down

0 comments on commit d0b0c9e

Please sign in to comment.