@@ -8,6 +8,7 @@ use crate::convert::{
8
8
} ;
9
9
use crate :: matcher:: { Matcher , MatcherSettings } ;
10
10
use crate :: { get_warp_tag_type, relocatable_regions} ;
11
+ use binaryninja:: architecture:: RegisterId ;
11
12
use binaryninja:: background_task:: BackgroundTask ;
12
13
use binaryninja:: binary_view:: { BinaryView , BinaryViewExt } ;
13
14
use binaryninja:: command:: Command ;
@@ -16,6 +17,7 @@ use binaryninja::workflow::{Activity, AnalysisContext, Workflow};
16
17
use itertools:: Itertools ;
17
18
use std:: collections:: HashMap ;
18
19
use std:: time:: Instant ;
20
+ use warp:: r#type:: class:: function:: { Location , RegisterLocation , StackLocation } ;
19
21
use warp:: signature:: function:: { Function , FunctionGUID } ;
20
22
use warp:: target:: Target ;
21
23
@@ -68,6 +70,9 @@ impl Command for RunMatcher {
68
70
}
69
71
70
72
pub fn run_matcher ( view : & BinaryView ) {
73
+ // TODO: Create the tag type so we dont have UB in the apply function workflow.
74
+ let _ = get_warp_tag_type ( view) ;
75
+
71
76
// Alert the user if we have no actual regions (one comes from the synthetic section).
72
77
let regions = relocatable_regions ( view) ;
73
78
if regions. len ( ) <= 1 && view. memory_map ( ) . is_activated ( ) {
@@ -174,17 +179,41 @@ pub fn insert_workflow() {
174
179
let bn_comment = comment_to_bn_comment ( & function, comment) ;
175
180
function. set_comment_at ( bn_comment. addr , & bn_comment. comment ) ;
176
181
}
177
- // TODO: Fix this before release.
178
- // TODO: Any attempt to add a tag type will create a undo action
179
- // TODO: Those are currently not thread safe when running in headless python.
180
- // TODO: See Mason for more lore.
181
- // function.add_tag(
182
- // &get_warp_tag_type(&view),
183
- // &matched_function.guid.to_string(),
184
- // None,
185
- // false,
186
- // None,
187
- // );
182
+ if let Some ( mlil) = ctx. mlil_function ( ) {
183
+ for variable in matched_function. variables {
184
+ let decl_addr = ( ( function. start ( ) as i64 ) + variable. offset ) as u64 ;
185
+ if let Some ( decl_instr) = mlil. instruction_at ( decl_addr) {
186
+ let decl_var = match variable. location {
187
+ Location :: Register ( RegisterLocation { id, .. } ) => {
188
+ decl_instr. variable_for_register_after ( RegisterId ( id as u32 ) )
189
+ }
190
+ Location :: Stack ( StackLocation { offset, .. } ) => {
191
+ decl_instr. variable_for_stack_location_after ( offset)
192
+ }
193
+ } ;
194
+ let decl_ty = match variable. ty {
195
+ Some ( decl_ty) => to_bn_type ( & function. arch ( ) , & decl_ty) ,
196
+ None => {
197
+ let Some ( existing_var) = function. variable_type ( & decl_var) else {
198
+ continue ;
199
+ } ;
200
+ existing_var. contents
201
+ }
202
+ } ;
203
+ let decl_name = variable
204
+ . name
205
+ . unwrap_or_else ( || function. variable_name ( & decl_var) ) ;
206
+ mlil. create_auto_var ( & decl_var, & decl_ty, & decl_name, false )
207
+ }
208
+ }
209
+ }
210
+ function. add_tag (
211
+ & get_warp_tag_type ( & view) ,
212
+ & matched_function. guid . to_string ( ) ,
213
+ None ,
214
+ false ,
215
+ None ,
216
+ ) ;
188
217
}
189
218
} ;
190
219
@@ -208,12 +237,13 @@ pub fn insert_workflow() {
208
237
. register_activity ( & guid_activity)
209
238
. unwrap ( ) ;
210
239
// Because we are going to impact analysis with application we must make sure the function update is triggered to continue to update analysis.
211
- // TODO: need to ask why i cant do core.function.update like in the rtti plugin.
212
240
function_meta_workflow
213
- . register_activity_with_subactivities :: < Vec < String > > ( & apply_activity, vec ! [ ] )
241
+ . register_activity ( & apply_activity)
214
242
. unwrap ( ) ;
215
- function_meta_workflow. insert ( "core.function.runFunctionRecognizers" , [ GUID_ACTIVITY_NAME ] ) ;
216
- function_meta_workflow. insert ( "core.function.generateMediumLevelIL" , [ APPLY_ACTIVITY_NAME ] ) ;
243
+ function_meta_workflow
244
+ . insert_after ( "core.function.runFunctionRecognizers" , [ GUID_ACTIVITY_NAME ] ) ;
245
+ function_meta_workflow
246
+ . insert_after ( "core.function.generateMediumLevelIL" , [ APPLY_ACTIVITY_NAME ] ) ;
217
247
function_meta_workflow. register ( ) . unwrap ( ) ;
218
248
219
249
let old_module_meta_workflow = Workflow :: instance ( "core.module.metaAnalysis" ) ;
0 commit comments