Line data Source code
1 : use std::marker::PhantomData;
2 : use crate::common::FromFFI;
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 296136 : fn from_ffi(ptr: cxx::UniquePtr<ffi::COFF_String>) -> Self {
13 296136 : Self {
14 296136 : ptr,
15 296136 : _owner: PhantomData,
16 296136 : }
17 296136 : }
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 296052 : pub fn str(&self) -> std::string::String {
29 296052 : self.ptr.str().to_string()
30 296052 : }
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 295860 : pub fn offset(&self) -> u32 {
35 295860 : self.ptr.offset()
36 295860 : }
37 : }
|