### map example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to use map to apply a function to the Ok value of a Result. The example parses each line of a string and prints the number multiplied by two. ```rust let line = "1\n2\n3\n4\n"; for num in line.lines() { match num.parse::().map(|i| i * 2) { Ok(n) => println!("{n}"), Err(..) => {} } } ``` -------------------------------- ### as_mut example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Demonstrates using as_mut to get mutable references to the Ok or Err values. The example defines a mutate function that modifies the contained value based on the variant. ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### unwrap_or example: returns Ok value or default Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Demonstrates unwrap_or, which returns the contained Ok value or a provided default. The example shows both Ok and Err cases. ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` -------------------------------- ### is_err_and example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to use is_err_and to check if a Result is Err and the error value matches a predicate. The example uses std::io::Error and demonstrates true/false cases for different error kinds and an Ok case. ```rust use std::io::{Error, ErrorKind}; let x: Result = Err(Error::new(ErrorKind::NotFound, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), true); let x: Result = Err(Error::new(ErrorKind::PermissionDenied, "!")); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Ok(123); assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); let x: Result = Err("ownership".to_string()); assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### ok example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Demonstrates converting a Result to an Option using the ok method. Shows that Ok becomes Some and Err becomes None. ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` -------------------------------- ### as_ref example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to convert a Result to a Result of references using as_ref. The original Result is left in place. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` -------------------------------- ### Example: is_ok() on Result Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Returns true if the result is Ok. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` -------------------------------- ### map_or_else example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to use map_or_else to apply a fallback function to Err or a function to Ok. The example uses a constant k for the fallback. ```rust let k = 21; let x : Result<_, &str> = Ok("foo"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 3); let x : Result<&str, _> = Err("bar"); assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 42); ``` -------------------------------- ### unwrap_or_else example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to use unwrap_or_else to provide a fallback value when the Result is Err. ```rust assert_eq!(Ok(2).unwrap_or_else(count), 2); assert_eq!(Err("foo").unwrap_or_else(count), 3); ``` -------------------------------- ### and_then example: chaining fallible operations Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how and_then chains operations that may return Err. The first example uses a function sq_then_to_string that returns Result. The second example uses metadata() and modified() to demonstrate error handling with io::ErrorKind::NotFound. ```rust assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### unwrap_unchecked example (Ok case) Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to use unwrap_unchecked to get the Ok value without checking for Err. Calling on Err is undefined behavior. ```rust let x: Result = Ok(2); assert_eq!(unsafe { x.unwrap_unchecked() }, 2); ``` -------------------------------- ### expect method usage and recommended style Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Returns the contained Ok value or panics. Includes examples of basic usage and recommended message style. ```rust let x: Result = Err("emergency failure"); x.expect("Testing expect"); // panics with `Testing expect: emergency failure` ``` ```rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` -------------------------------- ### BindIter::step_by Source: https://docs.rs/darwinscope/latest/darwinscope/fixup/struct.BindIter.html Creates an iterator starting at the same point, but stepping by the given amount at each iteration. ```APIDOC ## BindIter::step_by ### Description Creates an iterator starting at the same point, but stepping by the given amount at each iteration. ### Method step_by ### Signature fn step_by(self, step: usize) -> StepBy ### Parameters - **self** (self) - Required - The iterator instance. - **step** (usize) - Required - The step size. ### Returns - **StepBy** - An iterator that steps by the given amount. ``` -------------------------------- ### or example: returns res if Err, otherwise Ok value Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Demonstrates the or method, which returns the provided res if self is Err, otherwise returns the Ok value of self. The example shows four cases covering combinations of Ok and Err. ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` -------------------------------- ### IntoIterator example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to iterate over a Result, yielding one value if Ok and none if Err. ```rust let x: Result = Ok(5); let v: Vec = x.into_iter().collect(); assert_eq!(v, [5]); let x: Result = Err("nothing!"); let v: Vec = x.into_iter().collect(); assert_eq!(v, []); ``` -------------------------------- ### err example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Demonstrates converting a Result to an Option using the err method. Shows that Ok becomes None and Err becomes Some with the error value. ```rust let x: Result = Ok(2); assert_eq!(x.err(), None); let x: Result = Err("Nothing here"); assert_eq!(x.err(), Some("Nothing here")); ``` -------------------------------- ### Product example: multiply parsed numbers from vector Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Uses the Product implementation for Result to multiply parsed numbers from a vector of strings. If any parse fails, the operation returns Err. ```rust let nums = vec!["5", "10", "1", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert_eq!(total, Ok(100)); let nums = vec!["5", "10", "one", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert!(total.is_err()); ``` -------------------------------- ### or_else example: control flow based on result values Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how or_else calls a closure if the result is Err, otherwise returns the Ok value. The example uses functions sq and err to demonstrate chaining or_else calls. ```rust fn sq(x: u32) -> Result { Ok(x * x) } fn err(x: u32) -> Result { Err(x) } assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); assert_eq!(Err(3).or_else(sq).or_else(err), Ok(9)); assert_eq!(Err(3).or_else(err).or_else(err), Err(3)); ``` -------------------------------- ### map_or_default example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Demonstrates using map_or_default to apply a function to Ok or return the default value for the type U on Err. The example shows a length calculation and default 0. ```rust let x: Result<_, &str> = Ok("foo"); let y: Result<&str, _> = Err("bar"); assert_eq!(x.map_or_default(|x| x.len()), 3); assert_eq!(y.map_or_default(|y| y.len()), 0); ``` -------------------------------- ### FromIterator example: subtract with underflow check Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to collect an iterator of Results into a Result, stopping at the first Err. ```rust let v = vec![1, 2, 0]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_sub(1).ok_or("Underflow!") ).collect(); assert_eq!(res, Err("Underflow!")); ``` -------------------------------- ### PrespecializationIter::step_by Source: https://docs.rs/darwinscope/latest/darwinscope/swift/struct.PrespecializationIter.html Creates an iterator starting at the same point, but stepping by the given amount at each iteration. ```APIDOC ## PrespecializationIter::step_by ### Description Creates an iterator starting at the same point, but stepping by the given amount at each iteration. ### Method `fn step_by(self, step: usize) -> StepBy` ### Parameters - `step` (usize) - The step amount. ### Returns - `StepBy` - A new iterator that steps by the given amount. ``` -------------------------------- ### FromIterator example: increment with overflow check Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to collect an iterator of Results into a Result, stopping at the first Err. ```rust let v = vec![1, 2]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_add(1).ok_or("Overflow!") ).collect(); assert_eq!(res, Ok(vec![2, 3])); ``` -------------------------------- ### Example: cloned() on Result<&mut T, E> Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Maps a Result<&mut T, E> to Result by cloning the contents of the Ok part. Requires T: Clone. ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### unwrap_err_unchecked example (Ok case - undefined behavior) Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Demonstrates that calling unwrap_err_unchecked on an Ok is undefined behavior. ```rust let x: Result = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior! ``` -------------------------------- ### Example: transpose() on Result, E> Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Transposes a Result of an Option into an Option of a Result. Ok(None) maps to None, Ok(Some(_)) to Some(Ok(_)), and Err(_) to Some(Err(_)). ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` -------------------------------- ### Example: cloned() on Result<&T, E> Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Maps a Result<&T, E> to Result by cloning the contents of the Ok part. Requires T: Clone. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### Example: copied() on Result<&mut T, E> Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Maps a Result<&mut T, E> to Result by copying the contents of the Ok part. Requires T: Copy. ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### unwrap_unchecked example (Err case - undefined behavior) Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Demonstrates that calling unwrap_unchecked on an Err is undefined behavior. ```rust let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` -------------------------------- ### pub fn offset(&self) -> Option Source: https://docs.rs/darwinscope/latest/darwinscope/objc/struct.Ivar.html Returns the literal ivar offset in bytes from the start of the instance, dereferencing the on-disk pointer to the offset slot. ```APIDOC ## pub fn offset(&self) -> Option ### Description Returns the literal ivar offset in bytes from the start of the instance. On disk, the ivar table stores a pointer to the 32-bit offset slot; this method dereferences it. Returns `None` when the slot pointer is null or fails to resolve (heavily stripped / corrupt input). ### Method `offset` ### Parameters - `self` - The `Ivar` instance. ### Returns - `Option` - The offset in bytes, or `None` if unavailable. ``` -------------------------------- ### Example: copied() on Result<&T, E> Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Maps a Result<&T, E> to Result by copying the contents of the Ok part. Requires T: Copy. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### Sum example: sum integers, reject on negative Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Uses the Sum implementation for Result to sum integers from a vector, returning Err if any element is negative. ```rust let f = |&x: &i32| if x < 0 { Err("Negative element found") } else { Ok(x) }; let v = vec![1, 2]; let res: Result = v.iter().map(f).sum(); assert_eq!(res, Ok(3)); let v = vec![1, -2]; let res: Result = v.iter().map(f).sum(); assert_eq!(res, Err("Negative element found")); ``` -------------------------------- ### map_or example Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Demonstrates using map_or to provide a default value for Err or apply a function to Ok. Note that the default is eagerly evaluated. ```rust let x: Result<_, &str> = Ok("foo"); assert_eq!(x.map_or(42, |v| v.len()), 3); let x: Result<&str, _> = Err("bar"); assert_eq!(x.map_or(42, |v| v.len()), 42); ``` -------------------------------- ### function_starts Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Returns an iterator over the VM addresses encoded in LC_FUNCTION_STARTS. The on-disk encoding is a ULEB128 stream of deltas from a running address that starts at the first __TEXT segment's vmaddr; a delta of zero terminates the stream. Returns the empty iterator when the binary has no LC_FUNCTION_STARTS, when the data slice is out of bounds, or when no __TEXT segment is present. ```APIDOC ## function_starts ### Description Returns an iterator over the VM addresses encoded in LC_FUNCTION_STARTS. The on-disk encoding is a ULEB128 stream of deltas from a running address that starts at the first __TEXT segment's vmaddr; a delta of zero terminates the stream. Returns the empty iterator when the binary has no LC_FUNCTION_STARTS, when the data slice is out of bounds, or when no __TEXT segment is present. ### Method function_starts ### Parameters None ### Returns - **FunctionStartIter<'a, '_>** - Iterator over absolute VM addresses. ``` -------------------------------- ### Example: is_ok_and() on Result Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Returns true if the result is Ok and the value inside matches a predicate. The predicate takes ownership of the value unless using as_ref(). ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Parse a Mach-O binary and print header info Source: https://docs.rs/darwinscope Parses a Mach-O binary from a byte slice using `MachoBinary::parse`, then prints the header's cputype, number of load commands, and UUID if present. The example reads `/usr/bin/codesign` and uses the `?` operator, so it must be called from a function returning a `Result`. ```rust use darwinscope::MachoBinary; let bytes = std::fs::read("/usr/bin/codesign")?; let binary = MachoBinary::parse(&bytes)?; let header = binary.header(); println!("cputype=0x{:x} ncmds={}", header.cputype(), header.ncmds()); if let Some(uuid) = header.uuid() { println!("uuid={:02x?}", uuid); } ``` -------------------------------- ### unwrap_err_unchecked example (Err case) Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows how to use unwrap_err_unchecked to get the Err value without checking for Ok. ```rust let x: Result = Err("emergency failure"); assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure"); ``` -------------------------------- ### Segment::initprot Source: https://docs.rs/darwinscope/latest/src/darwinscope/segment.rs.html Returns the initial VM protection flags. ```APIDOC ## Segment::initprot ### Description Returns the initial VM protection (`VM_PROT_*`). ### Method `pub fn initprot(&self) -> u32` ### Parameters None. ### Returns - `u32` - The initial VM protection flags. ### Example ```rust let prot = segment.initprot(); ``` ``` -------------------------------- ### ClassRo::instance_start Source: https://docs.rs/darwinscope/latest/src/darwinscope/objc/class.rs.html Returns the `instanceStart` offset where this class's ivars begin in the instance. ```APIDOC ## ClassRo::instance_start ### Description Returns the `instanceStart` offset where this class's ivars begin in the instance. ### Method `pub fn instance_start(&self) -> u32` ### Parameters None. ### Returns - **u32** - The offset where this class's ivars begin. ``` -------------------------------- ### swift() Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Builds a SwiftRuntime walker for Swift 5 runtime metadata. Returns None if the image has no Swift content or is 32-bit. ```APIDOC ## swift() ### Description Aggregate Swift 5 runtime walker. Returns `None` when the image carries no Swift content (none of `__swift5_types`, `__swift5_protos`, `__swift5_proto`, `__swift5_fieldmd` is present) or when the slice is 32-bit - the v0.1 Swift walker is 64-bit only. On success the returned `SwiftRuntime` owns parsed-once metadata (cached section lookups, segment table for VA translation, chained-fixup rebase / bind indices) so iterators can drain it independently of the originating `MachoBinary` borrow. ### Method swift ### Signature `pub fn swift(&self) -> Option>` ### Parameters - `self` (reference) - The `MachoBinary` instance. ### Returns - `Option>` - `Some` with a runtime walker on success, `None` if no Swift content or 32-bit slice. ``` -------------------------------- ### objc() Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Builds an ObjcRuntime walker for the Mach-O binary. Returns None if the image carries no Objective-C metadata or is 32-bit. ```APIDOC ## objc() ### Description Builds an `ObjcRuntime` walker for the Mach-O binary. Returns `None` when the image carries no Objective-C metadata or when the slice is 32-bit (the v0.1 walker is 64-bit only). ### Method objc ### Signature `pub fn objc(&self) -> Option>` ### Parameters - `self` (reference) - The `MachoBinary` instance. ### Returns - `Option>` - `Some` with a runtime walker on success, `None` if no Objective-C metadata or 32-bit slice. ``` -------------------------------- ### unwrap_or_else example: computes value from closure Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows unwrap_or_else, which returns the contained Ok value or computes it from a closure. The example defines a function count that returns the length of a string. ```rust fn count(x: &str) -> usize { x.len() } ``` -------------------------------- ### Example: is_err() on Result Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Returns true if the result is Err. ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Method::implementation Source: https://docs.rs/darwinscope/latest/darwinscope/objc/struct.Method.html Returns the IMP target virtual address (post-PAC-strip), or None for abstract methods. ```APIDOC ## Method::implementation ### Description Returns the IMP target VA (post-PAC-strip). `None` for abstract methods - protocols emit method declarations with `imp = 0`. ### Method `pub fn implementation(&self) -> Option` ### Parameters None ### Returns - `Option` - The IMP target VA, or `None` for abstract methods. ``` -------------------------------- ### Rebase::segment_offset Source: https://docs.rs/darwinscope/latest/darwinscope/fixup/struct.Rebase.html Returns the byte offset of the rebase slot from the start of its segment. ```APIDOC ## Rebase::segment_offset ### Description Returns the byte offset of the rebase slot from the start of its segment. ### Method pub fn segment_offset(&self) -> u64 ### Parameters None ### Returns - **u64** - The segment offset. ``` -------------------------------- ### Header::min_os Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Returns the minimum OS version this image targets, preferring `LC_BUILD_VERSION` and falling back to legacy `LC_VERSION_MIN_*`. ```APIDOC ## Header::min_os ### Description Returns the minimum OS version this image targets, preferring `LC_BUILD_VERSION` (modern) and falling back to `LC_VERSION_MIN_*` (legacy). Only the first match wins. ### Method min_os ### Signature pub fn min_os(&self) -> Option ### Parameters None ### Returns - **Option** - The minimum OS version, or `None` if not present. ``` -------------------------------- ### pub fn swift(&self) -> Option> Source: https://docs.rs/darwinscope/latest/darwinscope/binary/struct.MachoBinary.html Returns an aggregate Swift 5 runtime walker. Returns `None` when the image carries no Swift content or when the slice is 32-bit (v0.1 Swift walker is 64-bit only). ```APIDOC ## pub fn swift(&self) -> Option> ### Description Aggregate Swift 5 runtime walker. Returns `None` when the image carries no Swift content (none of `__swift5_types`, `__swift5_protos`, `__swift5_proto`, `__swift5_fieldmd` is present) or when the slice is 32-bit - the v0.1 Swift walker is 64-bit only. On success the returned `SwiftRuntime` owns parsed-once metadata (cached section lookups, segment table for VA translation, chained-fixup rebase / bind indices) so iterators can drain it independently of the originating `MachoBinary` borrow. ### Method pub fn swift(&self) -> Option> ### Parameters None. ### Returns - **Option>** - Aggregate Swift 5 runtime walker, or `None` if not applicable. ``` -------------------------------- ### Module documentation and imports for refs.rs Source: https://docs.rs/darwinscope/latest/src/darwinscope/objc/refs.rs.html The module-level documentation describes the four reference sections and their resolution semantics. The imports bring in PhantomData and the ObjcRuntime, class name decoding, protocol decoding, and symbol prefix stripping utilities. ```rust //! Cross-section reference walkers. //! //! ObjC images carry four reference sections that each hold an //! array of 64-bit pointer slots: //! //! - `__objc_selrefs` - selectors referenced at runtime. Each slot //! resolves (after PAC strip) to a NUL-terminated UTF-8 string in //! `__TEXT,__objc_methname`. //! - `__objc_classrefs` - class references (e.g. `[NSObject foo]`). //! Resolves to a `class_t` in this image, or to a chained-fixup //! bind for foreign classes (`_OBJC_CLASS_$_`). //! - `__objc_superrefs` - super-class references for messaging //! patterns; same resolution semantics as `__objc_classrefs`. //! - `__objc_protorefs` - protocol references (i.e. `@protocol(X)`). //! Resolves to a `protocol_t` in this image, or to a chained-fixup //! bind for foreign protocols (`_OBJC_PROTOCOL_$_` / //! `_OBJC_LABEL_PROTOCOL_$_`). use std::marker::PhantomData; use crate::objc::{ ObjcRuntime, class::decode_class_name, protocol::decode_protocol, strip_objc_symbol_prefix, }; ``` -------------------------------- ### FromIterator example: stops after first Err Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows that no further elements are taken from the iterator after the first Err is encountered. ```rust let v = vec![3, 2, 1, 10]; let mut shared = 0; let res: Result, &'static str> = v.iter().map(|x: &u32| { shared += x; x.checked_sub(2).ok_or("Underflow!") }).collect(); assert_eq!(res, Err("Underflow!")); assert_eq!(shared, 6); ``` -------------------------------- ### CodeDirectory::code_limit_64 Source: https://docs.rs/darwinscope/latest/darwinscope/codesign/struct.CodeDirectory.html Returns codeLimit64 if present (version >= 0x20300), otherwise None. ```APIDOC ## CodeDirectory::code_limit_64 ### Description Returns `codeLimit64` - present only in CDs of version `≥ 0x20300`. Returns `None` for older CDs. ### Method `pub fn code_limit_64(&self) -> Option` ### Returns - `Option` - The 64-bit code limit, or `None` if not present. ``` -------------------------------- ### imports Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Returns an iterator over dyld bind targets (imports). Folds two on-disk encodings into a single sequence: legacy LC_DYLD_INFO[_ONLY] bind-opcode rows (decoded by goblin) and chained binds from LC_DYLD_CHAINED_FIXUPS (decoded in-house by crate::fixup). Order: legacy first, then chained. Real binaries ship exactly one encoding (never both), so consumers can treat the iterator as a flat list without dispatching on which encoding produced each row. ```APIDOC ## imports ### Description Returns an iterator over dyld bind targets (imports). Folds two on-disk encodings into a single sequence: legacy LC_DYLD_INFO[_ONLY] bind-opcode rows (decoded by goblin) and chained binds from LC_DYLD_CHAINED_FIXUPS (decoded in-house by crate::fixup). Order: legacy first, then chained. Real binaries ship exactly one encoding (never both), so consumers can treat the iterator as a flat list without dispatching on which encoding produced each row. ### Method imports ### Parameters None ### Returns - **ImportIter<'_>** - Iterator over imported symbols. ``` -------------------------------- ### header() Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Returns a view over the mach_header plus absorbed metadata such as UUID, build version, source version, and dylinker info. ```APIDOC ## header() ### Description View over the `mach_header` plus absorbed metadata (`LC_UUID`, `LC_BUILD_VERSION` / `LC_VERSION_MIN_*`, `LC_SOURCE_VERSION`, `LC_LOAD_DYLINKER`, `LC_FUNCTION_STARTS` presence). ### Method header ### Signature `pub fn header(&self) -> Header<'_>` ### Parameters - `self` (reference) - The `MachoBinary` instance. ### Returns - `Header<'_>` - A header view containing the raw header and absorbed metadata. ``` -------------------------------- ### raw Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Returns the on-disk bytes that back this Mach-O slice. For thin binaries this is the same byte slice passed to parse. For fat wrappers it is just the bytes of the selected architecture slice. ```APIDOC ## raw ### Description Returns the on-disk bytes that back this Mach-O slice. For thin binaries this is the same byte slice the caller passed to `parse`. For fat (universal) wrappers it is *just* the bytes of the selected architecture slice - segment / section file offsets translate inside this slice, not inside the surrounding fat archive. Escape hatch for callers that need ungated access (e.g. to compute a digest over the file image). Most consumers should prefer the higher-level accessors. ### Method `pub fn raw(&self) -> &'a [u8]` ### Parameters None. ### Returns - `&'a [u8]` - The raw bytes of the Mach-O slice. ``` -------------------------------- ### SwiftRuntime::has_entry_point Source: https://docs.rs/darwinscope/latest/darwinscope/swift/struct.SwiftRuntime.html Returns `true` when the image carries an `__swift5_entry` section (Swift `@main` entry-point info). ```APIDOC ## SwiftRuntime::has_entry_point ### Description Returns `true` when the image carries an `__swift5_entry` section (Swift `@main` entry-point info). ### Method `pub fn has_entry_point(&self) -> bool` ### Returns - `bool` - `true` if the section is present. ``` -------------------------------- ### SwiftRuntime::conformances Source: https://docs.rs/darwinscope/latest/darwinscope/swift/struct.SwiftRuntime.html Returns an iterator over every protocol-conformance row in the `__swift5_proto` section. ```APIDOC ## SwiftRuntime::conformances ### Description Returns an iterator over every protocol-conformance row in the `__swift5_proto` section. This is the single most attribution-bearing Swift section. ### Method `pub fn conformances(&self) -> ConformanceIter<'a, '_>` ### Returns - `ConformanceIter<'a, '_>` - Iterator over protocol-conformance rows. ``` -------------------------------- ### LoadCommandIter Source: https://docs.rs/darwinscope/latest/src/darwinscope/dylib.rs.html Flat summary of every load command (one row per LC_*), including cmd id, byte offset, size, and raw bytes. ```APIDOC ## LoadCommandIter ### Description Flat summary of every load command (one row per LC_*), including cmd id, byte offset, size, and raw bytes. ### Type Rust Iterator ### Item Type LoadCommand<'a, 'p> ### Fields of LoadCommand - **kind** (u32) - LC_* identifier. - **offset** (usize) - Byte offset of this load command inside the binary. - **size** (u32) - Total size in bytes (cmdsize). - **bytes** (&'a [u8]) - The command's raw bytes (data[offset..offset+size]). Empty when bounds are violated by a malformed image. ``` -------------------------------- ### unwrap_err: Returns Err value Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Returns the contained Err value, consuming self. This example shows a successful unwrap_err on an Err value. ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` -------------------------------- ### pub fn objc(&self) -> Option> Source: https://docs.rs/darwinscope/latest/darwinscope/binary/struct.MachoBinary.html Returns an aggregate Objective-C runtime walker. Returns `None` when the image carries no ObjC content or when the slice is 32-bit (v0.1 Obj-C walker is 64-bit only). ```APIDOC ## pub fn objc(&self) -> Option> ### Description Aggregate Objective-C runtime walker. Returns `None` when the image carries no ObjC content (`__objc_imageinfo` missing) or when the slice is 32-bit - the v0.1 Obj-C walker is 64-bit only. On success the returned `ObjcRuntime` owns parsed-once metadata (image info, cached section lookups, segment table for VA translation, chained-fixup bind index) so iterators can drain it independently of the originating `MachoBinary` borrow. ### Method pub fn objc(&self) -> Option> ### Parameters None. ### Returns - **Option>** - Aggregate Objective-C runtime walker, or `None` if not applicable. ``` -------------------------------- ### unwrap: Basic usage Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Returns the contained Ok value, consuming self. Panics if the value is an Err. This example shows a successful unwrap. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` -------------------------------- ### take Source: https://docs.rs/darwinscope/latest/darwinscope/binary/struct.FunctionStartIter.html Creates an iterator that yields the first n elements, or fewer if the underlying iterator ends sooner. ```APIDOC ## take ### Description Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ### Method take ### Signature fn take(self, n: usize) -> Take ⓘ where Self: Sized, ### Parameters - **n** (usize) - Required - The number of elements to take. ### Returns Take - An iterator adapter that yields the first n elements. ### Availability 1.0.0 (const: unstable) ``` -------------------------------- ### Get end address from unwind table Source: https://docs.rs/darwinscope/latest/src/darwinscope/unwind.rs.html Returns the address one past the last function described by the table, using the first-level sentinel. ```rust pub fn end(&self) -> Option { self.index().last().map(|&(end, _, _)| self.address(end)) } ``` -------------------------------- ### unwrap: Panics on Err Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Panics if the value is an Err, with a panic message provided by the Err's value. This example shows a panic with 'emergency failure'. ```rust let x: Result = Err("emergency failure"); x.unwrap(); // panics with `emergency failure` ``` -------------------------------- ### SwiftProtocol::runtime Source: https://docs.rs/darwinscope/latest/darwinscope/swift/struct.SwiftProtocol.html Returns the owning SwiftRuntime borrow. ```APIDOC ## SwiftProtocol::runtime ### Description Returns the owning SwiftRuntime borrow. ### Method runtime ### Signature pub fn runtime(&self) -> &'p SwiftRuntime<'a> ### Returns &'p SwiftRuntime<'a> - The owning SwiftRuntime borrow. ``` -------------------------------- ### Example: flatten() removing one level at a time Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Shows that flatten() only removes one level of nesting, requiring multiple calls for deeply nested results. ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ``` -------------------------------- ### blocks() Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Builds a BlockRuntime walker for Apple Blocks runtime. Returns None if the image binds neither _NSConcreteGlobalBlock nor _NSConcreteStackBlock, or is 32-bit. ```APIDOC ## blocks() ### Description Aggregate Apple Blocks-runtime walker. Returns `None` when the image binds neither `_NSConcreteGlobalBlock` nor `_NSConcreteStackBlock` (i.e. makes no use of the Blocks runtime) or when the slice is 32-bit - the v0.1 walker is 64-bit only. On success the returned `BlockRuntime` owns parsed-once metadata (bind site index, segment table, chained-fixup rebase index) so iterators can drain it independently of the originating `MachoBinary` borrow. ### Method blocks ### Signature `pub fn blocks(&self) -> Option>` ### Parameters - `self` (reference) - The `MachoBinary` instance. ### Returns - `Option>` - `Some` with a runtime walker on success, `None` if no Blocks runtime usage or 32-bit slice. ``` -------------------------------- ### Header::sdk_version Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Returns the SDK version this image was built against, sourced from `LC_BUILD_VERSION.sdk` or `LC_VERSION_MIN_*.sdk`. ```APIDOC ## Header::sdk_version ### Description Returns the SDK version this image was built against, sourced from `LC_BUILD_VERSION.sdk` or `LC_VERSION_MIN_*.sdk`. ### Method sdk_version ### Signature pub fn sdk_version(&self) -> Option ### Parameters None ### Returns - **Option** - The SDK version, or `None` if not present. ``` -------------------------------- ### pub fn header(&self) -> Header<'_> Source: https://docs.rs/darwinscope/latest/darwinscope/binary/struct.MachoBinary.html Returns a view over the `mach_header` plus absorbed metadata such as `LC_UUID`, `LC_BUILD_VERSION`, `LC_SOURCE_VERSION`, `LC_LOAD_DYLINKER`, and `LC_FUNCTION_STARTS` presence. ```APIDOC ## pub fn header(&self) -> Header<'_> ### Description View over the `mach_header` plus absorbed metadata (`LC_UUID`, `LC_BUILD_VERSION` / `LC_VERSION_MIN_*`, `LC_SOURCE_VERSION`, `LC_LOAD_DYLINKER`, `LC_FUNCTION_STARTS` presence). ### Method pub fn header(&self) -> Header<'_> ### Parameters None. ### Returns - **Header<'_>** - View over the Mach-O header and absorbed metadata. ``` -------------------------------- ### unwrap_or_default: Convert string to integer Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Returns the contained Ok value or a default value for the type. This example converts strings to integers, turning poorly-formed strings into 0. ```rust let good_year_from_input = "1909"; let bad_year_from_input = "190blarg"; let good_year = good_year_from_input.parse().unwrap_or_default(); let bad_year = bad_year_from_input.parse().unwrap_or_default(); assert_eq!(1909, good_year); assert_eq!(0, bad_year); ``` -------------------------------- ### Example: flatten() on Result, E> Source: https://docs.rs/darwinscope/latest/darwinscope/error/type.Result.html Converts from Result, E> to Result. Flattening only removes one level of nesting at a time. ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` -------------------------------- ### pub fn runtime(&self) -> &'p SwiftRuntime<'a> Source: https://docs.rs/darwinscope/latest/darwinscope/swift/struct.Conformance.html Returns the owning SwiftRuntime borrow for this conformance descriptor. ```APIDOC ## pub fn runtime(&self) -> &'p SwiftRuntime<'a> ### Description Returns the owning `SwiftRuntime` borrow for this conformance descriptor. ### Method `runtime` ### Parameters None ### Returns - `&'p SwiftRuntime<'a>` - The owning `SwiftRuntime` borrow. ``` -------------------------------- ### protocol_list_t layout comment Source: https://docs.rs/darwinscope/latest/src/darwinscope/objc/protocol.rs.html Shows the memory layout of the protocol_list_t structure as documented in objc4/runtime/objc-runtime-new.h. The count is a uintptr_t at offset 0, and the list is an array of protocol_ref_t (u64) starting at offset 8. ```text count uintptr_t (u64 on LP64) @ 0 list[] protocol_ref_t[] @ 8 each entry is u64 ``` -------------------------------- ### Header::is_64 Source: https://docs.rs/darwinscope/latest/src/darwinscope/binary.rs.html Indicates whether the underlying container is 64-bit. ```APIDOC ## Header::is_64 ### Description Returns whether the underlying container is 64-bit (`MH_MAGIC_64` / `MH_CIGAM_64`). ### Method is_64 ### Signature pub fn is_64(&self) -> bool ### Parameters None ### Returns - **bool** - `true` if 64-bit, `false` otherwise. ``` -------------------------------- ### Iterator for SectionIter Source: https://docs.rs/darwinscope/latest/darwinscope/segment/struct.SectionIter.html Implements the Iterator trait for SectionIter, yielding Section<'a, 'p> items. Provides methods to advance the iterator, get size hints, count, and retrieve the last element. ```APIDOC ## Iterator for SectionIter ### Description Implements the Iterator trait for SectionIter, yielding Section<'a, 'p> items. Provides methods to advance the iterator, get size hints, count, and retrieve the last element. ### Type Item - **Section<'a, 'p>** - The type of the elements being iterated over. ### Methods #### next - **Signature**: `fn next(&mut self) -> Option` - **Description**: Advances the iterator and returns the next value. #### size_hint - **Signature**: `fn size_hint(&self) -> (usize, Option)` - **Description**: Returns the bounds on the remaining length of the iterator. #### count - **Signature**: `fn count(self) -> usize` - **Description**: Consumes the iterator, counting the number of iterations and returning it. #### last - **Signature**: `fn last(self) -> Option` - **Description**: Consumes the iterator, returning the last element. #### nth - **Signature**: `fn nth(&mut self, n: usize) -> Option` - **Description**: Returns the `n`th element of the iterator. ### Example ```rust let mut iter = section_iter; while let Some(section) = iter.next() { // process section } ``` ``` -------------------------------- ### read_context_name function (partial) Source: https://docs.rs/darwinscope/latest/src/darwinscope/swift/parent.rs.html Function to read the Name field of a context descriptor. The provided code is truncated; it starts with the function signature and a match on the descriptor kind, but the full implementation is not shown in the source. ```rust fn read_context_name<'a>( rt: &SwiftRuntime<'a>, descriptor_va: u64, flags: ContextDescriptorFlags, ) -> Option<&'a str> { match flags.kind() { ContextDescriptorKind::Module | ContextDescriptorKind::Class | ContextDescriptorKind::Struct | ContextDescriptorKind::Enum ```