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.wowa64_dispatch_indirect_call_cfg_function_pointer()
46 0 : }
47 :
48 0 : pub fn wowa64_dispatch_ret_function_pointer(&self) -> u32 {
49 0 : self.ptr.wowa64_dispatch_ret_function_pointer()
50 0 : }
51 :
52 0 : pub fn wowa64_dispatch_ret_leaf_function_pointer(&self) -> u32 {
53 0 : self.ptr.wowa64_dispatch_ret_leaf_function_pointer()
54 0 : }
55 :
56 0 : pub fn wowa64_dispatch_jump_function_pointer(&self) -> u32 {
57 0 : self.ptr.wowa64_dispatch_jump_function_pointer()
58 0 : }
59 :
60 0 : pub fn compiler_iat_pointer(&self) -> Option<u32> {
61 0 : to_opt!(&lief_ffi::PE_CHPEMetadataX86::compiler_iat_pointer, &self);
62 0 : }
63 :
64 0 : pub fn wowa64_rdtsc_function_pointer(&self) -> Option<u32> {
65 0 : to_opt!(&lief_ffi::PE_CHPEMetadataX86::wowa64_rdtsc_function_pointer, &self);
66 0 : }
67 : }
68 :
69 : impl AsCHPEMetadata for CHPEMetadata<'_> {
70 0 : fn as_generic(&self) -> &ffi::PE_CHPEMetadata {
71 0 : self.ptr.as_ref().unwrap().as_ref()
72 0 : }
73 : }
74 :
75 : impl std::fmt::Debug for CHPEMetadata<'_> {
76 0 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77 0 : f.debug_struct("CHPEMetadataX86")
78 0 : .field("chpe_code_address_range_offset", &self.chpe_code_address_range_offset())
79 0 : .field("chpe_code_address_range_count", &self.chpe_code_address_range_count())
80 0 : .field("wowa64_exception_handler_function_pointer", &self.wowa64_exception_handler_function_pointer())
81 0 : .field("wowa64_dispatch_call_function_pointer", &self.wowa64_dispatch_call_function_pointer())
82 0 : .field("wowa64_dispatch_indirect_call_function_pointer", &self.wowa64_dispatch_indirect_call_function_pointer())
83 0 : .field("wowa64_dispatch_indirect_call_cfg_function_pointer", &self.wowa64_dispatch_indirect_call_cfg_function_pointer())
84 0 : .field("wowa64_dispatch_ret_function_pointer", &self.wowa64_dispatch_ret_function_pointer())
85 0 : .field("wowa64_dispatch_ret_leaf_function_pointer", &self.wowa64_dispatch_ret_leaf_function_pointer())
86 0 : .field("wowa64_dispatch_jump_function_pointer", &self.wowa64_dispatch_jump_function_pointer())
87 0 : .field("compiler_iat_pointer", &self.compiler_iat_pointer())
88 0 : .field("wowa64_rdtsc_function_pointer", &self.wowa64_rdtsc_function_pointer())
89 0 : .finish()
90 0 : }
91 : }
92 :
|