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