1- import { BaseJavaCstVisitorWithDefaults } from 'java-parser'
2- import { ManifestPlugin } from '../ManifestPlugin'
3- import { Severity , getRelativePath , searchKeywordInFile } from '../util'
4- import path from 'node:path' ;
5- import { execFileSync } from 'node:child_process' ;
6- const { execFile } = require ( 'child_process' ) ;
7-
1+ import { BaseJavaCstVisitorWithDefaults } from 'java-parser'
2+ import { ManifestPlugin } from '../ManifestPlugin'
3+ import { Severity , getRelativePath , searchKeywordInFile } from '../util'
4+ import path from 'node:path'
5+ import { execFileSync } from 'node:child_process'
6+ const { execFile} = require ( 'child_process' )
87
98export default class ExportedComponentRule extends ManifestPlugin {
109 BAD_EXPORTED_TAGS = [
@@ -275,7 +274,6 @@ if the Intent carries data that is tainted (2nd order injection)`;
275274 // });
276275
277276 // }
278-
279277 }
280278
281279 checkManifestIssue ( exported_tag : string , tag : any ) : void {
@@ -293,36 +291,51 @@ if the Intent carries data that is tainted (2nd order injection)`;
293291 }
294292
295293 if ( ManifestPlugin . isASTEnabled ) {
296- const resourceDir = path . resolve ( path . join ( __dirname , ".." , ".." , "resource" ) )
294+ const resourceDir = path . resolve (
295+ path . join ( __dirname , '..' , '..' , 'resource' ) ,
296+ )
297+
298+ const javaPath = 'java'
299+ const jarPath = path . join (
300+ resourceDir ,
301+ 'android-project-parser-1.0-SNAPSHOT-shaded.jar' ,
302+ )
303+ const lastDotIndex = name . lastIndexOf ( '.' )
304+ const className = name . slice ( Math . max ( 0 , lastDotIndex + 1 ) )
297305
298- const javaPath = 'java' ;
299- const jarPath = path . join ( resourceDir , 'android-project-parser-1.0-SNAPSHOT-shaded.jar' ) ;
300- let lastDotIndex = name . lastIndexOf ( '.' ) ;
301- const className = name . substring ( lastDotIndex + 1 ) ;
302-
303306 const args = [
304307 '-jar' ,
305308 jarPath ,
306309 'find-methods-declaration-invocations-arguments' ,
307310 ManifestPlugin . androidProjectDirectory ,
308- className
309- ] ;
311+ className ,
312+ ]
310313
311- const result = execFileSync ( javaPath , args ) ;
314+ const result = execFileSync ( javaPath , args )
312315
313316 if ( result ) {
314- methodResults = JSON . parse ( result . toString ( ) ) ;
317+ methodResults = JSON . parse ( result . toString ( ) )
315318 if ( ! methodResults . errorMessage && methodResults . length > 0 ) {
316- let declaredMethods = methodResults ;
317- declaredMethods . forEach ( ( declaredMethod : { methodInvocations : any [ ] ; } ) => {
318- if ( declaredMethod . methodInvocations . length > 0 ) {
319- declaredMethod . methodInvocations . forEach ( ( methodInvocation : { methodName : string , arguments : [ ] } ) => {
320- if ( this . EXTRAS_METHOD_NAMES . includes ( methodInvocation . methodName ) ) {
321- argumentVal = argumentVal . concat ( methodInvocation . arguments )
322- }
323- } ) ;
324- }
325- } ) ;
319+ const declaredMethods = methodResults
320+ declaredMethods . forEach (
321+ ( declaredMethod : { methodInvocations : any [ ] } ) => {
322+ if ( declaredMethod . methodInvocations . length > 0 ) {
323+ declaredMethod . methodInvocations . forEach (
324+ ( methodInvocation : { methodName : string ; arguments : [ ] } ) => {
325+ if (
326+ this . EXTRAS_METHOD_NAMES . includes (
327+ methodInvocation . methodName ,
328+ )
329+ ) {
330+ argumentVal = argumentVal . concat (
331+ methodInvocation . arguments ,
332+ )
333+ }
334+ } ,
335+ )
336+ }
337+ } ,
338+ )
326339 }
327340 }
328341 }
@@ -355,9 +368,9 @@ if the Intent carries data that is tainted (2nd order injection)`;
355368 ManifestPlugin . manifestPath ,
356369 ) ,
357370 exploit : {
358- " exported_enum" : name ,
359- " tag_name" : exported_tag ,
360- " arguments" : argumentVal ,
371+ exported_enum : name ,
372+ tag_name : exported_tag ,
373+ arguments : argumentVal ,
361374 } ,
362375 line : result ?. line ,
363376 start_column : result ?. start_column ,
@@ -383,10 +396,10 @@ if the Intent carries data that is tainted (2nd order injection)`;
383396 ManifestPlugin . manifestPath ,
384397 ) ,
385398 exploit : {
386- " exported_enum" : name ,
387- " tag_name" : exported_tag ,
388- " package_name" : ManifestPlugin . packageName ,
389- " arguments" : argumentVal
399+ exported_enum : name ,
400+ tag_name : exported_tag ,
401+ package_name : ManifestPlugin . packageName ,
402+ arguments : argumentVal ,
390403 } ,
391404 line : result ?. line ,
392405 start_column : result ?. start_column ,
@@ -407,7 +420,6 @@ if the Intent carries data that is tainted (2nd order injection)`;
407420 )
408421
409422 if ( this . PROTECTED_BROADCASTS . includes ( actionName ) ) {
410-
411423 let description = this . EXPORTED_IN_PROTECTED
412424 description = description . replaceAll ( '{tag}' , exported_tag )
413425 description = description . replace ( '{tag_name}' , name )
@@ -422,17 +434,16 @@ if the Intent carries data that is tainted (2nd order injection)`;
422434 ManifestPlugin . manifestPath ,
423435 ) ,
424436 exploit : {
425- " exported_enum" : name ,
426- " tag_name" : exported_tag ,
427- " package_name" : ManifestPlugin . packageName ,
428- " arguments" : argumentVal
437+ exported_enum : name ,
438+ tag_name : exported_tag ,
439+ package_name : ManifestPlugin . packageName ,
440+ arguments : argumentVal ,
429441 } ,
430442 line : result ?. line ,
431443 start_column : result ?. start_column ,
432444 end_column : result ?. end_column ,
433445 } )
434446 } else if ( permission && ManifestPlugin . minSdk < 20 ) {
435-
436447 let description = this . EXPORTED_AND_PERMISSION_TAG
437448 description = description . replaceAll ( '{tag}' , exported_tag )
438449 description = description . replace ( '{tag_name}' , name )
@@ -447,17 +458,16 @@ if the Intent carries data that is tainted (2nd order injection)`;
447458 ManifestPlugin . manifestPath ,
448459 ) ,
449460 exploit : {
450- " exported_enum" : name ,
451- " tag_name" : exported_tag ,
452- " package_name" : ManifestPlugin . packageName ,
453- " arguments" : argumentVal
461+ exported_enum : name ,
462+ tag_name : exported_tag ,
463+ package_name : ManifestPlugin . packageName ,
464+ arguments : argumentVal ,
454465 } ,
455466 line : result ?. line ,
456467 start_column : result ?. start_column ,
457468 end_column : result ?. end_column ,
458469 } )
459470 } else {
460-
461471 let description = this . EXPORTED
462472 description = description . replaceAll ( '{tag}' , exported_tag )
463473 description = description . replace ( '{tag_name}' , name )
@@ -471,10 +481,10 @@ if the Intent carries data that is tainted (2nd order injection)`;
471481 ManifestPlugin . manifestPath ,
472482 ) ,
473483 exploit : {
474- " exported_enum" : name ,
475- " tag_name" : exported_tag ,
476- " package_name" : ManifestPlugin . packageName ,
477- " arguments" : argumentVal
484+ exported_enum : name ,
485+ tag_name : exported_tag ,
486+ package_name : ManifestPlugin . packageName ,
487+ arguments : argumentVal ,
478488 } ,
479489 name : 'Exported Components Check' ,
480490 line : result ?. line ,
@@ -526,4 +536,4 @@ const TAG_INFO: any = {
526536 activity : Activity ,
527537 'activity-alias' : Activity ,
528538 service : Service ,
529- }
539+ }
0 commit comments