Line data Source code
1 : use crate::common::FromFFI;
2 : use std::marker::PhantomData;
3 :
4 : use lief_ffi as ffi;
5 :
6 : pub struct String<'a> {
7 : ptr: cxx::UniquePtr<ffi::COFF_String>,
8 : _owner: PhantomData<&'a ()>,
9 : }
10 :
11 : impl<'a> FromFFI<ffi::COFF_String> for String<'a> {
12 320814 : fn from_ffi(ptr: cxx::UniquePtr<ffi::COFF_String>) -> Self {
13 320814 : Self {
14 320814 : ptr,
15 320814 : _owner: PhantomData,
16 320814 : }
17 320814 : }
18 : }
19 :
20 : /// This class represents a string located in the COFF string table.
21 : ///
22 : /// Some of these strings can be used for section names that are greater than 8
23 : /// bytes. See: [`crate::pe::Section::coff_string`]
24 : ///
25 : /// Reference: <https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#coff-string-table>
26 : impl String<'_> {
27 : /// The actual string
28 320723 : pub fn str(&self) -> std::string::String {
29 320723 : self.ptr.str().to_string()
30 320723 : }
31 :
32 : /// The offset of this string the in the COFF string table.
33 : /// This offset includes the first 4-bytes that holds the table size
34 320515 : pub fn offset(&self) -> u32 {
35 320515 : self.ptr.offset()
36 320515 : }
37 : }
|