1/* 2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { ArkInvokeStmt } from '../base/Stmt'; 17import { FunctionType } from '../base/Type'; 18import { ArkMethod } from '../model/ArkMethod'; 19import { Local } from '../base/Local'; 20import { AbstractRef, ArkStaticFieldRef, ArkInstanceFieldRef } from '../base/Ref'; 21 22export const INTERNAL_PARAMETER_SOURCE: string[] = ['@ohos.app.ability.Want.d.ts: Want']; 23 24export const INTERNAL_SINK_METHOD: string[] = [ 25 'console.<@%unk/%unk: .log()>', 26 'console.<@%unk/%unk: .error()>', 27 'console.<@%unk/%unk: .info()>', 28 'console.<@%unk/%unk: .warn()>', 29 'console.<@%unk/%unk: .assert()>', 30]; 31 32export function getRecallMethodInParam(stmt: ArkInvokeStmt): ArkMethod | null { 33 for (const param of stmt.getInvokeExpr().getArgs()) { 34 if (param.getType() instanceof FunctionType) { 35 const methodSignature = (param.getType() as FunctionType).getMethodSignature(); 36 const method = stmt.getCfg()?.getDeclaringMethod().getDeclaringArkClass().getMethod(methodSignature); 37 if (method) { 38 return method; 39 } 40 } 41 } 42 return null; 43} 44 45export function LocalEqual(local1: Local, local2: Local): boolean { 46 if (local1.getName() === 'this' && local2.getName() === 'this') { 47 return true; 48 } 49 const method1 = local1.getDeclaringStmt()?.getCfg()?.getDeclaringMethod(); 50 const method2 = local2.getDeclaringStmt()?.getCfg()?.getDeclaringMethod(); 51 const nameEqual = local1.getName() === local2.getName(); 52 return method1 === method2 && nameEqual; 53} 54 55export function RefEqual(ref1: AbstractRef, ref2: AbstractRef): boolean { 56 if (ref1 instanceof ArkStaticFieldRef && ref2 instanceof ArkStaticFieldRef) { 57 return ref1.getFieldSignature().toString() === ref2.getFieldSignature().toString(); 58 } else if (ref1 instanceof ArkInstanceFieldRef && ref2 instanceof ArkInstanceFieldRef) { 59 return LocalEqual(ref1.getBase(), ref2.getBase()) && ref1.getFieldSignature().toString() === ref2.getFieldSignature().toString(); 60 } 61 return false; 62} 63