@@ -7,12 +7,13 @@ use base64::Engine;
77use binaryninja:: download:: DownloadProvider ;
88use serde:: Deserialize ;
99use serde_json:: json;
10- use std:: collections:: HashMap ;
10+ use std:: collections:: { HashMap , HashSet } ;
1111use std:: str:: FromStr ;
1212use uuid:: Uuid ;
1313use warp:: chunk:: ChunkKind ;
1414use warp:: r#type:: guid:: TypeGUID ;
1515use warp:: r#type:: { ComputedType , Type } ;
16+ use warp:: signature:: constraint:: ConstraintGUID ;
1617use warp:: signature:: function:: { Function , FunctionGUID } ;
1718use warp:: target:: Target ;
1819use warp:: WarpFile ;
@@ -30,7 +31,8 @@ pub struct NetworkClient {
3031impl NetworkClient {
3132 pub fn new ( server_url : String , server_token : Option < String > ) -> Self {
3233 // TODO: This might want to be kept for the request header?
33- let mut headers: Vec < ( String , String ) > = vec ! [ ] ;
34+ let mut headers: Vec < ( String , String ) > =
35+ vec ! [ ( "Content-Encoding" . to_string( ) , "gzip" . to_string( ) ) ] ;
3436 if let Some ( token) = & server_token {
3537 headers. push ( ( "authorization" . to_string ( ) , format ! ( "Bearer {}" , token) ) ) ;
3638 }
@@ -214,13 +216,14 @@ impl NetworkClient {
214216 source : Option < SourceId > ,
215217 source_tags : & [ SourceTag ] ,
216218 guids : & [ FunctionGUID ] ,
219+ constraints : & [ ConstraintGUID ] ,
217220 ) -> serde_json:: Value {
218- let guids_str: Vec < String > = guids. iter ( ) . map ( |g| g. to_string ( ) ) . collect ( ) ;
221+ let guids_str: HashSet < String > = guids. iter ( ) . map ( |g| g. to_string ( ) ) . collect ( ) ;
219222 // TODO: The limit here needs to be somewhat flexible. But 1000 will do for now.
220223 let mut body = json ! ( {
221224 "format" : "flatbuffer" ,
222225 "guids" : guids_str,
223- "limit" : 1000
226+ "limit" : 10000 ,
224227 } ) ;
225228 if let Some ( target_id) = target {
226229 body[ "target_id" ] = json ! ( target_id) ;
@@ -231,6 +234,11 @@ impl NetworkClient {
231234 if !source_tags. is_empty ( ) {
232235 body[ "source_tags" ] = json ! ( source_tags) ;
233236 }
237+ if !constraints. is_empty ( ) {
238+ let constraint_guids_str: HashSet < String > =
239+ constraints. iter ( ) . map ( |g| g. to_string ( ) ) . collect ( ) ;
240+ body[ "constraints" ] = json ! ( constraint_guids_str) ;
241+ }
234242 body
235243 }
236244
@@ -244,13 +252,13 @@ impl NetworkClient {
244252 target : Option < NetworkTargetId > ,
245253 source : Option < SourceId > ,
246254 guids : & [ FunctionGUID ] ,
255+ constraints : & [ ConstraintGUID ] ,
247256 ) -> Result < WarpFile < ' static > , String > {
248257 let query_functions_url = format ! ( "{}/api/v1/functions/query" , self . server_url) ;
249258 // TODO: Allow for source tags? We really only need this in query_functions_source as that
250259 // TODO: is what prevents a undesired source from being "known" to the container.
251- let payload = Self :: query_functions_body ( target, source, & [ ] , guids) ;
260+ let payload = Self :: query_functions_body ( target, source, & [ ] , guids, constraints ) ;
252261 let mut inst = self . provider . create_instance ( ) . unwrap ( ) ;
253-
254262 let resp = inst. post_json ( & query_functions_url, self . headers . clone ( ) , & payload) ?;
255263 if !resp. is_success ( ) {
256264 return Err ( format ! (
@@ -275,7 +283,10 @@ impl NetworkClient {
275283 ) -> Result < HashMap < SourceId , Vec < FunctionGUID > > , String > {
276284 let query_functions_source_url =
277285 format ! ( "{}/api/v1/functions/query/source" , self . server_url) ;
278- let payload = Self :: query_functions_body ( target, None , tags, guids) ;
286+ // NOTE: We do not filter by constraint guids here since this pass is only responsible for
287+ // returning the source ids, not the actual function data, see [`NetworkClient::query_functions`]
288+ // for the place where the constraints are applied, and _do_ matter.
289+ let payload = Self :: query_functions_body ( target, None , tags, guids, & [ ] ) ;
279290 let mut inst = self . provider . create_instance ( ) . unwrap ( ) ;
280291
281292 let resp = inst. post_json ( & query_functions_source_url, self . headers . clone ( ) , & payload) ?;
0 commit comments