@@ -8,6 +8,7 @@ use crate::convert::{
88} ;
99use crate :: matcher:: { Matcher , MatcherSettings } ;
1010use crate :: { get_warp_tag_type, relocatable_regions} ;
11+ use binaryninja:: architecture:: RegisterId ;
1112use binaryninja:: background_task:: BackgroundTask ;
1213use binaryninja:: binary_view:: { BinaryView , BinaryViewExt } ;
1314use binaryninja:: command:: Command ;
@@ -16,6 +17,7 @@ use binaryninja::workflow::{Activity, AnalysisContext, Workflow};
1617use itertools:: Itertools ;
1718use std:: collections:: HashMap ;
1819use std:: time:: Instant ;
20+ use warp:: r#type:: class:: function:: { Location , RegisterLocation , StackLocation } ;
1921use warp:: signature:: function:: { Function , FunctionGUID } ;
2022use warp:: target:: Target ;
2123
@@ -68,6 +70,9 @@ impl Command for RunMatcher {
6870}
6971
7072pub 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+
7176 // Alert the user if we have no actual regions (one comes from the synthetic section).
7277 let regions = relocatable_regions ( view) ;
7378 if regions. len ( ) <= 1 && view. memory_map ( ) . is_activated ( ) {
@@ -174,17 +179,41 @@ pub fn insert_workflow() {
174179 let bn_comment = comment_to_bn_comment ( & function, comment) ;
175180 function. set_comment_at ( bn_comment. addr , & bn_comment. comment ) ;
176181 }
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+ ) ;
188217 }
189218 } ;
190219
@@ -208,12 +237,13 @@ pub fn insert_workflow() {
208237 . register_activity ( & guid_activity)
209238 . unwrap ( ) ;
210239 // 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.
212240 function_meta_workflow
213- . register_activity_with_subactivities :: < Vec < String > > ( & apply_activity, vec ! [ ] )
241+ . register_activity ( & apply_activity)
214242 . 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 ] ) ;
217247 function_meta_workflow. register ( ) . unwrap ( ) ;
218248
219249 let old_module_meta_workflow = Workflow :: instance ( "core.module.metaAnalysis" ) ;
0 commit comments