4242import soot .jimple .Jimple ;
4343import soot .jimple .NopStmt ;
4444import soot .jimple .NullConstant ;
45- import soot .jimple .StaticFieldRef ;
4645import soot .jimple .Stmt ;
4746import soot .jimple .infoflow .android .entryPointCreators .AndroidEntryPointUtils .ComponentType ;
4847import soot .jimple .infoflow .android .entryPointCreators .components .AbstractComponentEntryPointCreator ;
@@ -345,22 +344,18 @@ private void createJavascriptCallbacks() {
345344 Set <Stmt > statements = javascriptInterfaceStmts .get (m );
346345 for (Stmt s : statements ) {
347346 UnitPatchingChain units = m .retrieveActiveBody ().getUnits ();
348- Stmt succ = (Stmt ) units .getSuccOf (s );
349347 SootField f = null ;
350348 Value arg = s .getInvokeExpr ().getArg (0 );
351- if (succ .getTag (SimulatedCodeElementTag .TAG_NAME ) != null ) {
352- if (succ instanceof AssignStmt ) {
353- AssignStmt assign = (AssignStmt ) succ ;
354- if (assign .getRightOp () == arg && assign .getLeftOp () instanceof StaticFieldRef ) {
355- f = ((StaticFieldRef ) assign .getLeftOp ()).getField ();
356- }
357- }
349+ DummyMainFieldElementTag dm = (DummyMainFieldElementTag ) s .getTag (DummyMainFieldElementTag .TAG_NAME );
350+ if (dm != null ) {
351+ f = mainMethod .getDeclaringClass ().getFieldByNameUnsafe (dm .getFieldName ());
358352 }
359353 if (f == null ) {
360354 //create field
361355 f = createField (arg .getType (), "jsInterface" );
362356 AssignStmt assign = j .newAssignStmt (j .newStaticFieldRef (f .makeRef ()), arg );
363357 assign .addTag (SimulatedCodeElementTag .TAG );
358+ s .addTag (new DummyMainFieldElementTag (f .getName ()));
364359 units .insertAfter (assign , s );
365360 }
366361
@@ -369,21 +364,15 @@ private void createJavascriptCallbacks() {
369364 Stmt assignF = j .newAssignStmt (l , j .newStaticFieldRef (f .makeRef ()));
370365 body .getUnits ().add (assignF );
371366 SootClass cbtype = ((RefType ) f .getType ()).getSootClass ();
372- List <SootClass > allPossibleImpls ;
373- if (cbtype .isInterface ()) {
374- allPossibleImpls = h .getImplementersOf (cbtype );
375- } else {
376- allPossibleImpls = h .getSubclassesOfIncluding (cbtype );
377- }
378- for (SootClass c : allPossibleImpls ) {
379- for (SootMethod cbm : c .getMethods ()) {
380- if (AndroidEntryPointUtils .isCallableFromJS (cbm )) {
381- List <Value > args = new ArrayList <>();
382- for (Type t : cbm .getParameterTypes ())
383- args .add (getSimpleDefaultValue (t ));
384- InvokeStmt st = j .newInvokeStmt (j .newVirtualInvokeExpr (l , cbm .makeRef (), args ));
385- body .getUnits ().add (st );
386- }
367+ Set <SootMethod > allPossibleImpls = Scene .v ().getOrMakeFastHierarchy ().resolveAbstractDispatch (cbtype ,
368+ m );
369+ for (SootMethod cbm : allPossibleImpls ) {
370+ if (AndroidEntryPointUtils .isCallableFromJS (cbm )) {
371+ List <Value > args = new ArrayList <>();
372+ for (Type t : cbm .getParameterTypes ())
373+ args .add (getSimpleDefaultValue (t ));
374+ InvokeStmt st = j .newInvokeStmt (j .newVirtualInvokeExpr (l , cbm .makeRef (), args ));
375+ body .getUnits ().add (st );
387376 }
388377 }
389378 createIfStmt (assignF );
0 commit comments