/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththisfile,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
pubmod errors;
usecrate::errors::*; #[cfg(any(target_os = "linux", target_os = "android"))] use memoffset::offset_of; use process_reader::error::ProcessReaderError; use process_reader::ProcessReader;
#[cfg(any(target_os = "windows", target_os = "macos"))] use mozannotation_client::ANNOTATION_SECTION; use mozannotation_client::{
Annotation, AnnotationMutex, ANNOTATION_CONTENTS_BYTEBUFFER, ANNOTATION_CONTENTS_CSTRING,
ANNOTATION_CONTENTS_CSTRINGPOINTER, ANNOTATION_CONTENTS_EMPTY,
ANNOTATION_CONTENTS_NSCSTRINGPOINTER, ANNOTATION_CONTENTS_OWNEDBYTEBUFFER,
}; #[cfg(any(target_os = "linux", target_os = "android"))] use mozannotation_client::{MozAnnotationNote, ANNOTATION_NOTE_NAME, ANNOTATION_TYPE}; use std::cmp::min; use std::ffi::CString; use std::mem::{size_of, ManuallyDrop};
#[derive(Clone)] pubstruct CAnnotation { #[allow(dead_code)] // This is implicitly stored to and used externally pub id: u32, pub data: AnnotationData,
}
// TODO: we should clear the poison value here before getting the mutex // contents. Right now we have to fail if the mutex was poisoned. let annotation_table = mutex
.get_mut()
.map_err(|_e| AnnotationsRetrievalError::InvalidData)?;
if !annotation_table.verify() { return Err(AnnotationsRetrievalError::InvalidAnnotationTable);
}
let vec_pointer = annotation_table.get_ptr(); let length = annotation_table.len(); letmut annotations = Vec::<CAnnotation>::with_capacity(min(max_annotations, length));
for i in0..length { let annotation_address = unsafe { vec_pointer.add(i) }; iflet Ok(annotation) = read_annotation(&reader, annotation_address as usize) {
annotations.push(annotation);
}
}
fn copy_nscstring(
reader: &ProcessReader,
address: usize,
) -> Result<CString, process_reader::error::ReadError> { // HACK: This assumes the layout of the nsCString object let length_address = address + size_of::<usize>(); let length = reader.copy_object::<u32>(length_address)?;
if length > 0 { let data_address = reader.copy_object::<usize>(address)?; letmut vec = reader.copy_array::<u8>(data_address, length as _)?;
// We can't assume the string is a valid C string, as it might have // been corrupted during the crash. Ensure that it contains no nul // characters. let nul_byte_pos = vec.iter().position(|&c| c == 0); iflet Some(nul_byte_pos) = nul_byte_pos {
vec.truncate(nul_byte_pos);
}
// SAFETY: This is safe because we verified that there are no nul // characters inside the string.
Ok(unsafe { CString::from_vec_unchecked(vec) })
} else {
Ok(CString::default())
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.