1
1
from binaryninja import PluginCommand , BinaryView , BackgroundTaskThread , log_alert
2
+ from .moduletype import identify_efi_module_type , set_efi_module_entry_type , EFIModuleType
2
3
from .protocols import (
3
4
init_protocol_mapping ,
4
5
define_handle_protocol_types ,
@@ -20,34 +21,26 @@ def __init__(self, bv: BinaryView):
20
21
super ().__init__ ("Initializing EFI protocol mappings..." , True )
21
22
self .bv = bv
22
23
23
- def run (self ):
24
- if not init_protocol_mapping ():
24
+ def _resolve_dxe (self ):
25
+ self .progress = "Propagating EFI system table pointers..."
26
+ if not propagate_system_table_pointers (self .bv , self ):
25
27
return
26
28
27
- if "EFI_SYSTEM_TABLE" not in self . bv . types :
28
- log_alert ( "This binary is not using the EFI platform. Use Open with Options when loading the binary to select the EFI platform." )
29
+ self . progress = "Defining types for uses of HandleProtocol..."
30
+ if not define_handle_protocol_types ( self . bv , self ):
29
31
return
30
32
31
- self .bv .begin_undo_actions ()
32
- try :
33
- self .progress = "Propagating EFI system table pointers..."
34
- if not propagate_system_table_pointers (self .bv , self ):
35
- return
36
-
37
- self .progress = "Defining types for uses of HandleProtocol..."
38
- if not define_handle_protocol_types (self .bv , self ):
39
- return
40
-
41
- self .progress = "Defining types for uses of OpenProtocol..."
42
- if not define_open_protocol_types (self .bv , self ):
43
- return
33
+ self .progress = "Defining types for uses of OpenProtocol..."
34
+ if not define_open_protocol_types (self .bv , self ):
35
+ return
44
36
45
- self .progress = "Defining types for uses of LocateProtocol..."
46
- if not define_locate_protocol_types (self .bv , self ):
47
- return
37
+ self .progress = "Defining types for uses of LocateProtocol..."
38
+ if not define_locate_protocol_types (self .bv , self ):
39
+ return
48
40
49
- # SMM/MM types cannot be propagated until EFI_BOOT_SERVICES types are propagated and the
50
- # EFI_MM_BASE_PROTOCOL or EFI_SMM_BASE2_PROTOCOL is resolved
41
+ # SMM/MM types cannot be propagated until EFI_BOOT_SERVICES types are propagated and the
42
+ # EFI_MM_BASE_PROTOCOL or EFI_SMM_BASE2_PROTOCOL is resolved
43
+ if "EFI_MM_SYSTEM_TABLE" in self .bv .types :
51
44
self .progress = "Defining types for SMM/MM system tables..."
52
45
if not define_locate_mm_system_table_types (self .bv , self ) or not define_locate_smm_system_table_types (
53
46
self .bv , self
@@ -65,6 +58,32 @@ def run(self):
65
58
self .bv , self
66
59
):
67
60
return
61
+
62
+ def run (self ):
63
+ if not init_protocol_mapping ():
64
+ return
65
+
66
+ if "EFI_SYSTEM_TABLE" not in self .bv .types :
67
+ log_alert ("This binary is not using the EFI platform. Use Open with Options when loading the binary to select the EFI platform." )
68
+ return
69
+
70
+ module_type = identify_efi_module_type (self .bv )
71
+ if module_type == EFIModuleType .UNKNOWN :
72
+ log_alert ("Could not identify the EFI module type." )
73
+ return
74
+
75
+ self .bv .begin_undo_actions ()
76
+ try :
77
+ try :
78
+ set_efi_module_entry_type (self .bv , module_type )
79
+ except SyntaxError :
80
+ log_alert ("Failed to set entry function type. Update Binary Ninja for latest EFI type definitions." )
81
+ return
82
+
83
+ if module_type == EFIModuleType .DXE :
84
+ self ._resolve_dxe ()
85
+ elif module_type == EFIModuleType .PEI :
86
+ log_alert ("TE PEI modules are not yet supported." )
68
87
finally :
69
88
self .bv .commit_undo_actions ()
70
89
0 commit comments