Line data Source code
1 : use super::load_configuration::AsCHPEMetadata;
2 : use crate::common::FromFFI;
3 : use crate::to_opt;
4 :
5 : use lief_ffi as ffi;
6 : use std::marker::PhantomData;
7 :
8 : /// This structure represents hybrid metadata for x86.
9 : pub struct CHPEMetadata<'a> {
10 : ptr: cxx::UniquePtr<ffi::PE_CHPEMetadataX86>,
11 : _owner: PhantomData<&'a ffi::PE_LoadConfiguration>,
12 : }
13 :
14 : impl<'a> FromFFI<ffi::PE_CHPEMetadataX86> for CHPEMetadata<'a> {
15 0 : fn from_ffi(ptr: cxx::UniquePtr<ffi::PE_CHPEMetadataX86>) -> Self {
16 0 : Self {
17 0 : ptr,
18 0 : _owner: PhantomData,
19 0 : }
20 0 : }
21 : }
22 :
23 : impl CHPEMetadata<'_> {
24 0 : pub fn chpe_code_address_range_offset(&self) -> u32 {
25 0 : self.ptr.chpe_code_address_range_offset()
26 0 : }
27 :
28 0 : pub fn chpe_code_address_range_count(&self) -> u32 {
29 0 : self.ptr.chpe_code_address_range_count()
30 0 : }
31 :
32 0 : pub fn wowa64_exception_handler_function_pointer(&self) -> u32 {
33 0 : self.ptr.wowa64_exception_handler_function_pointer()
34 0 : }
35 :
36 0 : pub fn wowa64_dispatch_call_function_pointer(&self) -> u32 {
37 0 : self.ptr.wowa64_dispatch_call_function_pointer()
38 0 : }
39 :
40 0 : pub fn wowa64_dispatch_indirect_call_function_pointer(&self) -> u32 {
41 0 : self.ptr.wowa64_dispatch_indirect_call_function_pointer()
42 0 : }
43 :
44 0 : pub fn wowa64_dispatch_indirect_call_cfg_function_pointer(&self) -> u32 {
45 0 : self.ptr
46 0 : .wowa64_dispatch_indirect_call_cfg_function_pointer()
47 0 : }
48 :
49 0 : pub fn wowa64_dispatch_ret_function_pointer(&self) -> u32 {
50 0 : self.ptr.wowa64_dispatch_ret_function_pointer()
51 0 : }
52 :
53 0 : pub fn wowa64_dispatch_ret_leaf_function_pointer(&self) -> u32 {
54 0 : self.ptr.wowa64_dispatch_ret_leaf_function_pointer()
55 0 : }
56 :
57 0 : pub fn wowa64_dispatch_jump_function_pointer(&self) -> u32 {
58 0 : self.ptr.wowa64_dispatch_jump_function_pointer()
59 0 : }
60 :
61 0 : pub fn compiler_iat_pointer(&self) -> Option<u32> {
62 0 : to_opt!(&lief_ffi::PE_CHPEMetadataX86::compiler_iat_pointer, &self);
63 0 : }
64 :
65 0 : pub fn wowa64_rdtsc_function_pointer(&self) -> Option<u32> {
66 0 : to_opt!(
67 0 : &lief_ffi::PE_CHPEMetadataX86::wowa64_rdtsc_function_pointer,
68 0 : &self
69 0 : );
70 0 : }
71 : }
72 :
73 : impl AsCHPEMetadata for CHPEMetadata<'_> {
74 0 : fn as_generic(&self) -> &ffi::PE_CHPEMetadata {
75 0 : self.ptr.as_ref().unwrap().as_ref()
76 0 : }
77 : }
78 :
79 : impl std::fmt::Debug for CHPEMetadata<'_> {
80 0 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81 0 : f.debug_struct("CHPEMetadataX86")
82 0 : .field(
83 0 : "chpe_code_address_range_offset",
84 0 : &self.chpe_code_address_range_offset(),
85 0 : )
86 0 : .field(
87 0 : "chpe_code_address_range_count",
88 0 : &self.chpe_code_address_range_count(),
89 0 : )
90 0 : .field(
91 0 : "wowa64_exception_handler_function_pointer",
92 0 : &self.wowa64_exception_handler_function_pointer(),
93 0 : )
94 0 : .field(
95 0 : "wowa64_dispatch_call_function_pointer",
96 0 : &self.wowa64_dispatch_call_function_pointer(),
97 0 : )
98 0 : .field(
99 0 : "wowa64_dispatch_indirect_call_function_pointer",
100 0 : &self.wowa64_dispatch_indirect_call_function_pointer(),
101 0 : )
102 0 : .field(
103 0 : "wowa64_dispatch_indirect_call_cfg_function_pointer",
104 0 : &self.wowa64_dispatch_indirect_call_cfg_function_pointer(),
105 0 : )
106 0 : .field(
107 0 : "wowa64_dispatch_ret_function_pointer",
108 0 : &self.wowa64_dispatch_ret_function_pointer(),
109 0 : )
110 0 : .field(
111 0 : "wowa64_dispatch_ret_leaf_function_pointer",
112 0 : &self.wowa64_dispatch_ret_leaf_function_pointer(),
113 0 : )
114 0 : .field(
115 0 : "wowa64_dispatch_jump_function_pointer",
116 0 : &self.wowa64_dispatch_jump_function_pointer(),
117 0 : )
118 0 : .field("compiler_iat_pointer", &self.compiler_iat_pointer())
119 0 : .field(
120 0 : "wowa64_rdtsc_function_pointer",
121 0 : &self.wowa64_rdtsc_function_pointer(),
122 0 : )
123 0 : .finish()
124 0 : }
125 : }
|