arkanalyzer 1.0.30 → 1.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts +9 -3
- package/lib/callgraph/pointerAnalysis/PTAUtils.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PTAUtils.js +32 -18
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +17 -1
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +48 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +48 -18
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +424 -257
- package/lib/core/base/Local.js +2 -2
- package/lib/core/common/IRInference.d.ts.map +1 -1
- package/lib/core/common/IRInference.js +7 -6
- package/lib/core/common/TypeInference.d.ts +1 -0
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +18 -3
- package/lib/utils/AstTreeUtils.d.ts +20 -1
- package/lib/utils/AstTreeUtils.d.ts.map +1 -1
- package/lib/utils/AstTreeUtils.js +65 -1
- package/package.json +2 -2
package/lib/core/base/Local.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Copyright (c) 2024-2025 Huawei Device Co., Ltd.
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
6
6
|
* You may obtain a copy of the License at
|
|
@@ -37,7 +37,7 @@ class Local {
|
|
|
37
37
|
inferType(arkMethod) {
|
|
38
38
|
var _a, _b;
|
|
39
39
|
if (TypeInference_1.TypeInference.isUnclearType(this.type)) {
|
|
40
|
-
const type = (_a = TypeInference_1.TypeInference.
|
|
40
|
+
const type = (_a = TypeInference_1.TypeInference.inferBaseType(this.name, arkMethod.getDeclaringArkClass())) !== null && _a !== void 0 ? _a : (_b = ModelUtils_1.ModelUtils.findDeclaredLocal(this, arkMethod)) === null || _b === void 0 ? void 0 : _b.getType();
|
|
41
41
|
if (type) {
|
|
42
42
|
this.type = type;
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IRInference.d.ts","sourceRoot":"","sources":["../../../src/core/common/IRInference.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAKH,SAAS,EAKT,IAAI,EAKP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EACH,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EAErB,mBAAmB,EACtB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAI7C,OAAO,EAGH,cAAc,EAEd,eAAe,EAElB,MAAM,uBAAuB,CAAC;AAK/B,OAAO,EAEH,WAAW,EAEX,mBAAmB,EACnB,eAAe,EAElB,MAAM,aAAa,CAAC;AAYrB,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAoB,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAKlF,qBAAa,WAAW;IAEpB,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAY/B,OAAO,CAAC,MAAM,CAAC,gBAAgB;WAMjB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;WAwB9B,qBAAqB,CAAC,IAAI,EAAE,mBAAmB,EAAE,SAAS,EAAE,SAAS,GAAG,kBAAkB;IAqCxG,OAAO,CAAC,MAAM,CAAC,iCAAiC;WAuClC,uB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EAAE,GAAG,GAAE,GAAG,CAAC,MAAM,CAAa,GAAG,IAAI;IAkC/H,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAM/B,OAAO,CAAC,MAAM,CAAC,eAAe;WAiChB,kBAAkB,CAAC,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,GAAG,YAAY;WAiC3E,kBAAkB,CAAC,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;WA2CnE,kBAAkB,CAAC,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;WAcnE,iBAAiB,CAAC,GAAG,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,GAAG,WAAW;CAmB3F"}
|
|
@@ -125,7 +125,7 @@ class IRInference {
|
|
|
125
125
|
}
|
|
126
126
|
const className = expr.getMethodSignature().getDeclaringClassSignature().getClassName();
|
|
127
127
|
if (className && className !== Const_1.UNKNOWN_CLASS_NAME) {
|
|
128
|
-
const baseType = TypeInference_1.TypeInference.
|
|
128
|
+
const baseType = TypeInference_1.TypeInference.inferBaseType(className, arkClass);
|
|
129
129
|
if (baseType) {
|
|
130
130
|
let result = this.inferInvokeExpr(expr, baseType, methodName, arkClass.getDeclaringArkFile().getScene());
|
|
131
131
|
if (result) {
|
|
@@ -326,10 +326,11 @@ class IRInference {
|
|
|
326
326
|
realTypes.push(argType);
|
|
327
327
|
}
|
|
328
328
|
else if (paramType instanceof Type_1.FunctionType && argType instanceof Type_1.FunctionType) {
|
|
329
|
-
if (paramType.getMethodSignature().getType() instanceof Type_1.GenericType) {
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
329
|
+
if (paramType.getMethodSignature().getParamLength() > 0 && paramType.getMethodSignature().getType() instanceof Type_1.GenericType) {
|
|
330
|
+
const paramMethod = scene.getMethod(expr.getMethodSignature());
|
|
331
|
+
const argMethod = scene.getMethod(argType.getMethodSignature());
|
|
332
|
+
if (paramMethod && paramMethod.getGenericTypes() && argMethod) {
|
|
333
|
+
TypeInference_1.TypeInference.inferTypeInMethod(argMethod);
|
|
333
334
|
}
|
|
334
335
|
}
|
|
335
336
|
const realTypes = expr.getRealGenericTypes();
|
|
@@ -742,7 +743,7 @@ class IRInference {
|
|
|
742
743
|
return;
|
|
743
744
|
}
|
|
744
745
|
if (opValue instanceof Local_1.Local) {
|
|
745
|
-
const newOpValueType = TypeInference_1.TypeInference.
|
|
746
|
+
const newOpValueType = TypeInference_1.TypeInference.inferBaseType(opValue.getName(), arkMethod.getDeclaringArkClass());
|
|
746
747
|
const scene = arkMethod.getDeclaringArkFile().getScene();
|
|
747
748
|
if (newOpValueType instanceof Type_1.ClassType) {
|
|
748
749
|
const newOpValue = ModelUtils_1.ModelUtils.findArkModelBySignature(newOpValueType.getClassSignature(), scene);
|
|
@@ -97,6 +97,7 @@ export declare class TypeInference {
|
|
|
97
97
|
* @returns
|
|
98
98
|
*/
|
|
99
99
|
static inferBaseType(baseName: string, arkClass: ArkClass): Type | null;
|
|
100
|
+
static inferTypeByName(typeName: string, arkClass: ArkClass): Type | null;
|
|
100
101
|
static inferRealGenericTypes(realTypes: Type[] | undefined, arkClass: ArkClass): void;
|
|
101
102
|
static inferDynamicImportType(from: string, arkClass: ArkClass): Type | null;
|
|
102
103
|
static replaceTypeWithReal(type: Type, realTypes?: Type[], visited?: Set<Type>): Type;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeInference.d.ts","sourceRoot":"","sources":["../../../src/core/common/TypeInference.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAwD,IAAI,EAAE,MAAM,cAAc,CAAC;AAC1F,OAAO,EASH,YAAY,EACZ,WAAW,EAOX,IAAI,EACJ,oBAAoB,EAKvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAiB,MAAM,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EAAE,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI;WAkC9E,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;WASlC,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,GAAG,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,SAAS,GAAG,IAAI;IAuB9I,OAAO,CAAC,MAAM,CAAC,oBAAoB;CAatC"}
|
|
@@ -245,7 +245,8 @@ class TypeInference {
|
|
|
245
245
|
const stmtDef = stmt.getDef();
|
|
246
246
|
if (stmtDef && stmtDef instanceof Ref_1.AbstractRef) {
|
|
247
247
|
if (arkMethod.getName() === Const_1.INSTANCE_INIT_METHOD_NAME && stmtDef instanceof Ref_1.ArkInstanceFieldRef &&
|
|
248
|
-
stmtDef.getBase().getName() === TSConst_1.THIS_NAME && arkMethod.getDeclaringArkClass().isAnonymousClass()
|
|
248
|
+
stmtDef.getBase().getName() === TSConst_1.THIS_NAME && arkMethod.getDeclaringArkClass().isAnonymousClass() &&
|
|
249
|
+
stmtDef.getFieldName().indexOf('.') === -1) {
|
|
249
250
|
return;
|
|
250
251
|
}
|
|
251
252
|
const fieldRef = stmtDef.inferType(arkMethod);
|
|
@@ -605,7 +606,7 @@ class TypeInference {
|
|
|
605
606
|
return ValueUtil_1.EMPTY_STRING;
|
|
606
607
|
});
|
|
607
608
|
if (i === 0) {
|
|
608
|
-
type = this.inferBaseType(name, arkClass);
|
|
609
|
+
type = singleNames.length > 1 ? this.inferBaseType(name, arkClass) : this.inferTypeByName(name, arkClass);
|
|
609
610
|
}
|
|
610
611
|
else if (type) {
|
|
611
612
|
type = (_a = this.inferFieldType(type, name, arkClass)) === null || _a === void 0 ? void 0 : _a[1];
|
|
@@ -615,7 +616,7 @@ class TypeInference {
|
|
|
615
616
|
}
|
|
616
617
|
if (genericName) {
|
|
617
618
|
const realTypes = genericName.split(',').map(generic => {
|
|
618
|
-
const realType = this.
|
|
619
|
+
const realType = this.inferUnclearRefName(generic, arkClass);
|
|
619
620
|
return realType !== null && realType !== void 0 ? realType : new Type_1.UnclearReferenceType(generic);
|
|
620
621
|
});
|
|
621
622
|
if (type instanceof Type_1.ClassType) {
|
|
@@ -727,6 +728,20 @@ class TypeInference {
|
|
|
727
728
|
}
|
|
728
729
|
return this.parseArkExport2Type(arkExport);
|
|
729
730
|
}
|
|
731
|
+
static inferTypeByName(typeName, arkClass) {
|
|
732
|
+
var _a, _b, _c, _d, _e;
|
|
733
|
+
let arkExport = (_e = (_a = ModelUtils_1.ModelUtils.getClassWithName(typeName, arkClass)) !== null && _a !== void 0 ? _a : (_d = (_c = (_b = ModelUtils_1.ModelUtils.getDefaultClass(arkClass)) === null || _b === void 0 ? void 0 : _b.getDefaultArkMethod()) === null || _c === void 0 ? void 0 : _c.getBody()) === null || _d === void 0 ? void 0 : _d.getAliasTypeByName(typeName)) !== null && _e !== void 0 ? _e : ModelUtils_1.ModelUtils.getArkExportInImportInfoWithName(typeName, arkClass.getDeclaringArkFile());
|
|
734
|
+
if (arkExport instanceof ArkClass_1.ArkClass || arkExport instanceof Type_1.AliasType) {
|
|
735
|
+
return this.parseArkExport2Type(arkExport);
|
|
736
|
+
}
|
|
737
|
+
if (!arkClass.getDeclaringArkFile().getImportInfoBy(typeName)) {
|
|
738
|
+
arkExport = arkClass.getDeclaringArkFile().getScene().getSdkGlobal(typeName);
|
|
739
|
+
}
|
|
740
|
+
if (arkExport instanceof ArkClass_1.ArkClass || arkExport instanceof Type_1.AliasType) {
|
|
741
|
+
return this.parseArkExport2Type(arkExport);
|
|
742
|
+
}
|
|
743
|
+
return null;
|
|
744
|
+
}
|
|
730
745
|
static inferRealGenericTypes(realTypes, arkClass) {
|
|
731
746
|
if (!realTypes) {
|
|
732
747
|
return;
|
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import { ts } from '..';
|
|
1
|
+
import { ArkFile, ts } from '..';
|
|
2
2
|
export declare class AstTreeUtils {
|
|
3
|
+
/**
|
|
4
|
+
* get source file from code segment
|
|
5
|
+
* @param fileName source file name
|
|
6
|
+
* @param code source code
|
|
7
|
+
* @returns ts.SourceFile
|
|
8
|
+
*/
|
|
3
9
|
static getASTNode(fileName: string, code: string): ts.SourceFile;
|
|
10
|
+
/**
|
|
11
|
+
* get source file from ArkFile
|
|
12
|
+
* @param arkFile ArkFile
|
|
13
|
+
* @returns ts.SourceFile
|
|
14
|
+
*/
|
|
15
|
+
static getSourceFileFromArkFile(arkFile: ArkFile): ts.SourceFile;
|
|
16
|
+
static createSourceFile(fileName: string, code: string): ts.SourceFile;
|
|
17
|
+
/**
|
|
18
|
+
* convert source code to hash string
|
|
19
|
+
* @param code source code
|
|
20
|
+
* @returns string
|
|
21
|
+
*/
|
|
22
|
+
private static getKeyFromCode;
|
|
4
23
|
}
|
|
5
24
|
//# sourceMappingURL=AstTreeUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AstTreeUtils.d.ts","sourceRoot":"","sources":["../../src/utils/AstTreeUtils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,EAAE,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"AstTreeUtils.d.ts","sourceRoot":"","sources":["../../src/utils/AstTreeUtils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,IAAI,CAAC;AAMjC,qBAAa,YAAY;IACrB;;;;;OAKG;WACW,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU;IAWvE;;;;OAIG;WACW,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,EAAE,CAAC,UAAU;WAYzD,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU;IAW7E;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;CAGhC"}
|
|
@@ -13,14 +13,78 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
16
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
40
|
exports.AstTreeUtils = void 0;
|
|
18
41
|
const __1 = require("..");
|
|
19
42
|
const EtsConst_1 = require("../core/common/EtsConst");
|
|
43
|
+
const crypto = __importStar(require("crypto"));
|
|
44
|
+
const sourceFileCache = new Map();
|
|
20
45
|
class AstTreeUtils {
|
|
46
|
+
/**
|
|
47
|
+
* get source file from code segment
|
|
48
|
+
* @param fileName source file name
|
|
49
|
+
* @param code source code
|
|
50
|
+
* @returns ts.SourceFile
|
|
51
|
+
*/
|
|
21
52
|
static getASTNode(fileName, code) {
|
|
22
|
-
const
|
|
53
|
+
const key = this.getKeyFromCode(code);
|
|
54
|
+
let sourceFile = sourceFileCache.get(key);
|
|
55
|
+
if (sourceFile) {
|
|
56
|
+
return sourceFile;
|
|
57
|
+
}
|
|
58
|
+
sourceFile = this.createSourceFile(fileName, code);
|
|
59
|
+
sourceFileCache.set(key, sourceFile);
|
|
60
|
+
return sourceFile;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* get source file from ArkFile
|
|
64
|
+
* @param arkFile ArkFile
|
|
65
|
+
* @returns ts.SourceFile
|
|
66
|
+
*/
|
|
67
|
+
static getSourceFileFromArkFile(arkFile) {
|
|
68
|
+
const signature = arkFile.getFileSignature().toString();
|
|
69
|
+
const key = this.getKeyFromCode(signature);
|
|
70
|
+
let sourceFile = sourceFileCache.get(key);
|
|
71
|
+
if (sourceFile) {
|
|
72
|
+
return sourceFile;
|
|
73
|
+
}
|
|
74
|
+
sourceFile = this.createSourceFile(arkFile.getName(), arkFile.getCode());
|
|
75
|
+
sourceFileCache.set(key, sourceFile);
|
|
23
76
|
return sourceFile;
|
|
24
77
|
}
|
|
78
|
+
static createSourceFile(fileName, code) {
|
|
79
|
+
return __1.ts.createSourceFile(fileName, code, __1.ts.ScriptTarget.Latest, true, undefined, EtsConst_1.ETS_COMPILER_OPTIONS);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* convert source code to hash string
|
|
83
|
+
* @param code source code
|
|
84
|
+
* @returns string
|
|
85
|
+
*/
|
|
86
|
+
static getKeyFromCode(code) {
|
|
87
|
+
return crypto.createHash('sha256').update(code).digest('hex');
|
|
88
|
+
}
|
|
25
89
|
}
|
|
26
90
|
exports.AstTreeUtils = AstTreeUtils;
|