Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mach: Implement LC_NOTE #342

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/mach/load_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,22 @@ pub struct DataInCodeEntry {
pub kind: u16,
}

/// LC_NOTE commands describe a region of arbitrary data included in a Mach-O
/// file. Its initial use is to record extra data in MH_CORE files.
#[repr(C)]
#[derive(Debug, Clone, Copy, Pread, Pwrite, IOread, IOwrite, SizeWith)]
pub struct NoteCommand {
/// LC_NOTE
pub cmd: u32,
pub cmdsize: u32,
/// owner name for this LC_NOTE
pub data_owner: [u8; 16],
/// file offset of this data
pub offset: u64,
/// length of data region
pub size: u64,
}

///////////////////////////////////////
// Constants, et. al
///////////////////////////////////////
Expand Down Expand Up @@ -1377,6 +1393,7 @@ pub fn cmd_to_str(cmd: u32) -> &'static str {

#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
#[non_exhaustive]
/// The various load commands as a cast-free variant/enum
pub enum CommandVariant {
Segment32(SegmentCommand32),
Expand Down Expand Up @@ -1431,6 +1448,7 @@ pub enum CommandVariant {
VersionMinWatchos(VersionMinCommand),
DyldExportsTrie(LinkeditDataCommand),
DyldChainedFixups(LinkeditDataCommand),
Note(NoteCommand),
m4b marked this conversation as resolved.
Show resolved Hide resolved
Unimplemented(LoadCommandHeader),
}

Expand Down Expand Up @@ -1657,8 +1675,11 @@ impl<'a> ctx::TryFromCtx<'a, Endian> for CommandVariant {
let comm = bytes.pread_with::<LinkeditDataCommand>(0, le)?;
Ok((DyldChainedFixups(comm), size))
}
// TODO: LC_NOTE (NoteCommand) is unimplemented.
LC_NOTE | _ => Ok((Unimplemented(lc), size)),
LC_NOTE => {
let comm = bytes.pread_with::<NoteCommand>(0, le)?;
Ok((Note(comm), size))
}
_ => Ok((Unimplemented(lc), size)),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think load commands are added very often, so maybe this should now become a bad lc command error in future PR?

}
}
}
Expand Down Expand Up @@ -1719,6 +1740,7 @@ impl CommandVariant {
VersionMinWatchos(comm) => comm.cmdsize,
DyldExportsTrie(comm) => comm.cmdsize,
DyldChainedFixups(comm) => comm.cmdsize,
Note(comm) => comm.cmdsize,
Unimplemented(comm) => comm.cmdsize,
};
cmdsize as usize
Expand Down Expand Up @@ -1778,6 +1800,7 @@ impl CommandVariant {
VersionMinWatchos(comm) => comm.cmd,
DyldExportsTrie(comm) => comm.cmd,
DyldChainedFixups(comm) => comm.cmd,
Note(comm) => comm.cmd,
Unimplemented(comm) => comm.cmd,
}
}
Expand Down