arkanalyzer 1.0.7 → 1.0.9
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/config/arkanalyzer.json +8 -0
- package/lib/Config.d.ts +9 -1
- package/lib/Config.d.ts.map +1 -1
- package/lib/Config.js +24 -11
- package/lib/Scene.d.ts +49 -42
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +124 -93
- package/lib/callgraph/algorithm/AbstractAnalysis.js +1 -1
- package/lib/callgraph/common/Statistics.js +1 -1
- package/lib/callgraph/model/CallGraph.d.ts +3 -2
- package/lib/callgraph/model/CallGraph.d.ts.map +1 -1
- package/lib/callgraph/model/CallGraph.js +15 -5
- package/lib/callgraph/model/builder/CallGraphBuilder.js +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +35 -8
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +89 -8
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +32 -5
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +378 -83
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +3 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +71 -18
- package/lib/core/base/Constant.d.ts +25 -5
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +46 -8
- package/lib/core/base/Expr.d.ts +45 -40
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +236 -150
- package/lib/core/base/Local.d.ts +2 -2
- package/lib/core/base/Local.d.ts.map +1 -1
- package/lib/core/base/Local.js +2 -2
- package/lib/core/base/Ref.d.ts +38 -37
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +102 -70
- package/lib/core/base/Stmt.d.ts +4 -0
- package/lib/core/base/Stmt.d.ts.map +1 -1
- package/lib/core/base/Stmt.js +12 -1
- package/lib/core/base/Type.d.ts +4 -0
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +41 -17
- package/lib/core/common/ArkError.d.ts +15 -0
- package/lib/core/common/ArkError.d.ts.map +1 -0
- package/lib/core/common/ArkError.js +28 -0
- package/lib/core/common/ArkIRTransformer.d.ts +1 -1
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +24 -8
- package/lib/core/common/CfgBuilder.d.ts.map +1 -1
- package/lib/core/common/CfgBuilder.js +5 -0
- package/lib/core/common/Const.d.ts +15 -10
- package/lib/core/common/Const.d.ts.map +1 -1
- package/lib/core/common/Const.js +18 -11
- package/lib/core/common/DummyMainCreater.d.ts +2 -1
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +28 -15
- package/lib/core/common/EtsConst.d.ts +1 -0
- package/lib/core/common/EtsConst.d.ts.map +1 -1
- package/lib/core/common/EtsConst.js +2 -1
- package/lib/core/common/IRUtils.d.ts +6 -0
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +29 -2
- package/lib/core/common/ModelUtils.d.ts +1 -0
- package/lib/core/common/ModelUtils.d.ts.map +1 -1
- package/lib/core/common/ModelUtils.js +32 -32
- package/lib/core/common/TSConst.d.ts +10 -3
- package/lib/core/common/TSConst.d.ts.map +1 -1
- package/lib/core/common/TSConst.js +11 -4
- package/lib/core/common/TypeInference.d.ts +8 -2
- package/lib/core/common/TypeInference.d.ts.map +1 -1
- package/lib/core/common/TypeInference.js +218 -87
- package/lib/core/common/ValueUtil.d.ts +0 -4
- package/lib/core/common/ValueUtil.d.ts.map +1 -1
- package/lib/core/common/ValueUtil.js +8 -25
- package/lib/core/dataflow/DataflowSolver.d.ts.map +1 -1
- package/lib/core/dataflow/DataflowSolver.js +2 -4
- package/lib/core/dataflow/TiantAnalysis.js +2 -1
- package/lib/core/dataflow/Util.d.ts +1 -1
- package/lib/core/dataflow/Util.d.ts.map +1 -1
- package/lib/core/dataflow/Util.js +8 -7
- package/lib/core/graph/BasicBlock.d.ts +41 -0
- package/lib/core/graph/BasicBlock.d.ts.map +1 -1
- package/lib/core/graph/BasicBlock.js +132 -1
- package/lib/core/graph/Cfg.d.ts +30 -1
- package/lib/core/graph/Cfg.d.ts.map +1 -1
- package/lib/core/graph/Cfg.js +129 -6
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +3 -2
- package/lib/core/model/ArkBaseModel.d.ts +8 -0
- package/lib/core/model/ArkBaseModel.d.ts.map +1 -1
- package/lib/core/model/ArkBaseModel.js +55 -3
- package/lib/core/model/ArkClass.d.ts +36 -30
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +78 -39
- package/lib/core/model/ArkExport.d.ts +3 -0
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +10 -0
- package/lib/core/model/ArkField.d.ts +2 -0
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +3 -0
- package/lib/core/model/ArkFile.d.ts +4 -0
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +20 -0
- package/lib/core/model/ArkImport.d.ts +2 -0
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +3 -0
- package/lib/core/model/ArkMetadata.d.ts +20 -0
- package/lib/core/model/ArkMetadata.d.ts.map +1 -0
- package/lib/core/model/ArkMetadata.js +44 -0
- package/lib/core/model/ArkMethod.d.ts +156 -53
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +309 -54
- package/lib/core/model/ArkNamespace.d.ts +4 -0
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +13 -0
- package/lib/core/model/ArkSignature.d.ts +11 -5
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +38 -18
- package/lib/core/model/builder/ArkClassBuilder.d.ts +0 -1
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +9 -34
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkExportBuilder.js +6 -1
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.js +3 -0
- package/lib/core/model/builder/ArkFileBuilder.js +1 -1
- package/lib/core/model/builder/ArkImportBuilder.d.ts +2 -1
- package/lib/core/model/builder/ArkImportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkImportBuilder.js +12 -5
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +2 -1
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +87 -47
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +2 -0
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +25 -2
- package/lib/save/source/SourceClass.d.ts.map +1 -1
- package/lib/save/source/SourceClass.js +4 -0
- package/lib/save/source/SourceField.d.ts.map +1 -1
- package/lib/save/source/SourceField.js +4 -0
- package/lib/save/source/SourceMethod.d.ts.map +1 -1
- package/lib/save/source/SourceMethod.js +7 -0
- package/lib/save/source/SourceModule.d.ts.map +1 -1
- package/lib/save/source/SourceModule.js +14 -9
- package/lib/save/source/SourceNamespace.d.ts.map +1 -1
- package/lib/save/source/SourceNamespace.js +4 -0
- package/lib/save/source/SourceStmt.d.ts.map +1 -1
- package/lib/save/source/SourceStmt.js +15 -3
- package/lib/save/source/SourceTransformer.d.ts +6 -0
- package/lib/save/source/SourceTransformer.d.ts.map +1 -1
- package/lib/save/source/SourceTransformer.js +72 -41
- package/lib/save/source/SourceUtils.d.ts.map +1 -1
- package/lib/save/source/SourceUtils.js +3 -2
- package/lib/transformer/StaticSingleAssignmentFormer.js +1 -1
- package/lib/utils/CfgStructualAnalysis.d.ts +1 -0
- package/lib/utils/CfgStructualAnalysis.d.ts.map +1 -1
- package/lib/utils/CfgStructualAnalysis.js +41 -7
- package/lib/utils/callGraphUtils.d.ts.map +1 -1
- package/lib/utils/callGraphUtils.js +7 -10
- package/lib/utils/crypto_utils.d.ts +6 -0
- package/lib/utils/crypto_utils.d.ts.map +1 -0
- package/lib/utils/crypto_utils.js +57 -0
- package/lib/utils/getAllFiles.d.ts +1 -1
- package/lib/utils/getAllFiles.d.ts.map +1 -1
- package/lib/utils/getAllFiles.js +4 -5
- package/package.json +3 -2
|
@@ -62,26 +62,27 @@ class TypeInference {
|
|
|
62
62
|
const stmts = arkField.getInitializer();
|
|
63
63
|
let rightType;
|
|
64
64
|
let fieldRef;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.
|
|
69
|
-
this.
|
|
70
|
-
}
|
|
71
|
-
const lastStmt = stmts[stmts.length - 1];
|
|
72
|
-
if (lastStmt instanceof Stmt_1.ArkAssignStmt) {
|
|
73
|
-
rightType = lastStmt.getRightOp().getType();
|
|
74
|
-
if (lastStmt.getLeftOp() instanceof Ref_1.AbstractFieldRef) {
|
|
75
|
-
fieldRef = lastStmt.getLeftOp();
|
|
76
|
-
}
|
|
65
|
+
const method = arkClass.getMethodWithName(Const_1.INSTANCE_INIT_METHOD_NAME);
|
|
66
|
+
for (const stmt of stmts) {
|
|
67
|
+
if (method) {
|
|
68
|
+
this.resolveExprsInStmt(stmt, method);
|
|
69
|
+
this.resolveFieldRefsInStmt(stmt, method);
|
|
77
70
|
}
|
|
71
|
+
this.resolveArkAssignStmt(stmt, arkClass);
|
|
78
72
|
}
|
|
79
73
|
const beforeType = arkField.getType();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
fieldType = new Type_1.ClassType(arkClass.getSignature());
|
|
74
|
+
if (!this.isUnclearType(beforeType)) {
|
|
75
|
+
return;
|
|
83
76
|
}
|
|
84
|
-
|
|
77
|
+
const lastStmt = stmts[stmts.length - 1];
|
|
78
|
+
if (lastStmt instanceof Stmt_1.ArkAssignStmt) {
|
|
79
|
+
rightType = lastStmt.getRightOp().getType();
|
|
80
|
+
if (lastStmt.getLeftOp() instanceof Ref_1.AbstractFieldRef) {
|
|
81
|
+
fieldRef = lastStmt.getLeftOp();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let fieldType;
|
|
85
|
+
if (beforeType) {
|
|
85
86
|
fieldType = this.inferUnclearedType(beforeType, arkClass, rightType);
|
|
86
87
|
}
|
|
87
88
|
if (fieldType) {
|
|
@@ -96,7 +97,7 @@ class TypeInference {
|
|
|
96
97
|
static inferUnclearedType(leftOpType, declaringArkClass, rightType) {
|
|
97
98
|
let type;
|
|
98
99
|
if (leftOpType instanceof Type_1.UnclearReferenceType) {
|
|
99
|
-
type = this.
|
|
100
|
+
type = this.inferUnclearRefType(leftOpType, declaringArkClass);
|
|
100
101
|
}
|
|
101
102
|
else if (leftOpType instanceof Type_1.ClassType
|
|
102
103
|
&& leftOpType.getClassSignature().getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
|
|
@@ -116,10 +117,10 @@ class TypeInference {
|
|
|
116
117
|
else {
|
|
117
118
|
newType = optionType;
|
|
118
119
|
}
|
|
119
|
-
if (newType
|
|
120
|
+
if (newType) {
|
|
120
121
|
types[i] = newType;
|
|
121
122
|
}
|
|
122
|
-
if (rightType && newType && newType === rightType) {
|
|
123
|
+
if (rightType && newType && newType.constructor === rightType.constructor) {
|
|
123
124
|
leftOpType.setCurrType(rightType);
|
|
124
125
|
type = leftOpType;
|
|
125
126
|
}
|
|
@@ -145,24 +146,42 @@ class TypeInference {
|
|
|
145
146
|
return type;
|
|
146
147
|
}
|
|
147
148
|
static inferTypeInMethod(arkMethod) {
|
|
148
|
-
var _a;
|
|
149
|
+
var _a, _b;
|
|
150
|
+
const arkClass = arkMethod.getDeclaringArkClass();
|
|
151
|
+
this.inferGenericType(arkMethod.getGenericTypes(), arkClass);
|
|
152
|
+
const signatures = [];
|
|
153
|
+
(_a = arkMethod.getDeclareSignatures()) === null || _a === void 0 ? void 0 : _a.forEach(m => signatures.push(m));
|
|
154
|
+
const impl = arkMethod.getImplementationSignature();
|
|
155
|
+
if (impl) {
|
|
156
|
+
signatures.push(impl);
|
|
157
|
+
}
|
|
158
|
+
signatures.forEach(s => {
|
|
159
|
+
s.getMethodSubSignature().getParameters().forEach(p => {
|
|
160
|
+
const type = TypeInference.inferUnclearedType(p.getType(), arkClass);
|
|
161
|
+
if (type) {
|
|
162
|
+
p.setType(type);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const type = TypeInference.inferUnclearedType(s.getMethodSubSignature().getReturnType(), arkClass);
|
|
166
|
+
if (type) {
|
|
167
|
+
s.getMethodSubSignature().setReturnType(type);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
149
170
|
const body = arkMethod.getBody();
|
|
150
171
|
if (!body) {
|
|
151
172
|
logger.warn('empty body');
|
|
152
173
|
return;
|
|
153
174
|
}
|
|
154
|
-
|
|
155
|
-
(_a = body.getAliasTypeMap()) === null || _a === void 0 ? void 0 : _a.forEach((value) => this.inferUnclearedType(value[0], arkClass));
|
|
175
|
+
(_b = body.getAliasTypeMap()) === null || _b === void 0 ? void 0 : _b.forEach((value) => this.inferUnclearedType(value[0], arkClass));
|
|
156
176
|
this.inferGenericType(arkMethod.getGenericTypes(), arkClass);
|
|
157
177
|
const cfg = body.getCfg();
|
|
158
178
|
for (const block of cfg.getBlocks()) {
|
|
159
179
|
for (const stmt of block.getStmts()) {
|
|
160
|
-
this.resolveExprsInStmt(stmt,
|
|
161
|
-
this.resolveFieldRefsInStmt(stmt,
|
|
180
|
+
this.resolveExprsInStmt(stmt, arkMethod);
|
|
181
|
+
this.resolveFieldRefsInStmt(stmt, arkMethod);
|
|
162
182
|
this.resolveArkAssignStmt(stmt, arkClass);
|
|
163
183
|
}
|
|
164
184
|
}
|
|
165
|
-
this.inferMethodReturnType(arkMethod);
|
|
166
185
|
}
|
|
167
186
|
/**
|
|
168
187
|
* @Deprecated
|
|
@@ -185,10 +204,10 @@ class TypeInference {
|
|
|
185
204
|
* infer type for Exprs in stmt which invoke method.
|
|
186
205
|
* such as ArkInstanceInvokeExpr ArkStaticInvokeExpr ArkNewExpr
|
|
187
206
|
*/
|
|
188
|
-
static resolveExprsInStmt(stmt,
|
|
207
|
+
static resolveExprsInStmt(stmt, arkMethod) {
|
|
189
208
|
const exprs = stmt.getExprs();
|
|
190
209
|
for (const expr of exprs) {
|
|
191
|
-
const newExpr = expr.inferType(
|
|
210
|
+
const newExpr = expr.inferType(arkMethod);
|
|
192
211
|
if (stmt.containsInvokeExpr() && expr instanceof Expr_1.ArkInstanceInvokeExpr && newExpr instanceof Expr_1.ArkStaticInvokeExpr) {
|
|
193
212
|
if (stmt instanceof Stmt_1.ArkAssignStmt && stmt.getRightOp() instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
194
213
|
stmt.setRightOp(newExpr);
|
|
@@ -202,57 +221,50 @@ class TypeInference {
|
|
|
202
221
|
/**
|
|
203
222
|
* infer type for fieldRefs in stmt.
|
|
204
223
|
*/
|
|
205
|
-
static resolveFieldRefsInStmt(stmt,
|
|
206
|
-
var _a;
|
|
224
|
+
static resolveFieldRefsInStmt(stmt, arkMethod) {
|
|
207
225
|
for (const use of stmt.getUses()) {
|
|
208
226
|
if (use instanceof Ref_1.AbstractRef) {
|
|
209
|
-
|
|
210
|
-
if (fieldRef instanceof Ref_1.ArkStaticFieldRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
211
|
-
if (stmt.getRightOp() instanceof Ref_1.ArkInstanceFieldRef) {
|
|
212
|
-
stmt.setRightOp(fieldRef);
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
stmt.replaceUse(use, fieldRef);
|
|
216
|
-
stmt.setRightOp(stmt.getRightOp());
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else if (use instanceof Ref_1.ArkInstanceFieldRef && fieldRef instanceof Ref_1.ArkArrayRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
220
|
-
const index = fieldRef.getIndex();
|
|
221
|
-
if (index instanceof Constant_1.Constant && index.getType() instanceof Type_1.StringType) {
|
|
222
|
-
const local = (_a = arkMethod === null || arkMethod === void 0 ? void 0 : arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(index.getValue());
|
|
223
|
-
if (local) {
|
|
224
|
-
fieldRef.setIndex(local);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
stmt.replaceUse(use, fieldRef);
|
|
228
|
-
stmt.setRightOp(stmt.getRightOp());
|
|
229
|
-
}
|
|
227
|
+
this.processRef(use, stmt, arkMethod);
|
|
230
228
|
}
|
|
231
229
|
}
|
|
232
230
|
const stmtDef = stmt.getDef();
|
|
233
231
|
if (stmtDef && stmtDef instanceof Ref_1.AbstractRef) {
|
|
234
|
-
const fieldRef = stmtDef.inferType(
|
|
232
|
+
const fieldRef = stmtDef.inferType(arkMethod);
|
|
235
233
|
if (fieldRef instanceof Ref_1.ArkStaticFieldRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
236
234
|
stmt.setLeftOp(fieldRef);
|
|
237
235
|
}
|
|
238
236
|
}
|
|
239
237
|
}
|
|
240
|
-
static
|
|
238
|
+
static processRef(use, stmt, arkMethod) {
|
|
241
239
|
var _a;
|
|
240
|
+
const fieldRef = use.inferType(arkMethod);
|
|
241
|
+
if (fieldRef instanceof Ref_1.ArkStaticFieldRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
242
|
+
if (stmt.getRightOp() instanceof Ref_1.ArkInstanceFieldRef) {
|
|
243
|
+
stmt.setRightOp(fieldRef);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
stmt.replaceUse(use, fieldRef);
|
|
247
|
+
stmt.setRightOp(stmt.getRightOp());
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else if (use instanceof Ref_1.ArkInstanceFieldRef && fieldRef instanceof Ref_1.ArkArrayRef && stmt instanceof Stmt_1.ArkAssignStmt) {
|
|
251
|
+
const index = fieldRef.getIndex();
|
|
252
|
+
if (index instanceof Constant_1.Constant && index.getType() instanceof Type_1.StringType) {
|
|
253
|
+
const local = (_a = arkMethod === null || arkMethod === void 0 ? void 0 : arkMethod.getBody()) === null || _a === void 0 ? void 0 : _a.getLocals().get(index.getValue());
|
|
254
|
+
if (local) {
|
|
255
|
+
fieldRef.setIndex(local);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
stmt.replaceUse(use, fieldRef);
|
|
259
|
+
stmt.setRightOp(stmt.getRightOp());
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
static parseArkExport2Type(arkExport) {
|
|
242
263
|
if (!arkExport) {
|
|
243
264
|
return null;
|
|
244
265
|
}
|
|
245
266
|
if (arkExport instanceof ArkClass_1.ArkClass) {
|
|
246
|
-
return new Type_1.ClassType(arkExport.getSignature(),
|
|
247
|
-
let defaultType = x.getDefaultType();
|
|
248
|
-
if (defaultType instanceof Type_1.UnclearReferenceType) {
|
|
249
|
-
const newType = TypeInference.inferUnclearReferenceType(defaultType.getName(), arkExport);
|
|
250
|
-
if (newType) {
|
|
251
|
-
defaultType = newType;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return defaultType !== null && defaultType !== void 0 ? defaultType : Type_1.UndefinedType.getInstance();
|
|
255
|
-
}));
|
|
267
|
+
return new Type_1.ClassType(arkExport.getSignature(), arkExport.getGenericsTypes());
|
|
256
268
|
}
|
|
257
269
|
else if (arkExport instanceof ArkNamespace_1.ArkNamespace) {
|
|
258
270
|
let namespaceType = new Type_1.AnnotationNamespaceType(arkExport.getName());
|
|
@@ -298,28 +310,44 @@ class TypeInference {
|
|
|
298
310
|
}
|
|
299
311
|
}
|
|
300
312
|
const leftOp = stmt.getLeftOp();
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
else if (this.isUnclearType(leftOpType) && !this.isUnclearType(stmt.getRightOp().getType())) {
|
|
311
|
-
leftOp.setType(stmt.getRightOp().getType());
|
|
313
|
+
let type = leftOp.getType();
|
|
314
|
+
if (this.isUnclearType(type)) {
|
|
315
|
+
type = this.inferUnclearedType(type, arkClass, rightOp.getType());
|
|
316
|
+
}
|
|
317
|
+
if (type instanceof Type_1.UnionType &&
|
|
318
|
+
!this.isUnclearType(rightOp.getType()) && !(leftOp instanceof Ref_1.ArkArrayRef)) {
|
|
319
|
+
const cur = type.getTypes().find(t => rightOp.getType().constructor === t.constructor);
|
|
320
|
+
if (cur) {
|
|
321
|
+
type.setCurrType(cur);
|
|
312
322
|
}
|
|
313
323
|
}
|
|
324
|
+
if (this.isUnclearType(type) && !this.isUnclearType(rightOp.getType())) {
|
|
325
|
+
type = rightOp.getType();
|
|
326
|
+
}
|
|
327
|
+
if (type && leftOp instanceof Local_1.Local) {
|
|
328
|
+
leftOp.setType(type);
|
|
329
|
+
}
|
|
330
|
+
else if (type && leftOp instanceof Ref_1.AbstractFieldRef) {
|
|
331
|
+
leftOp.getFieldSignature().setType(type);
|
|
332
|
+
}
|
|
314
333
|
}
|
|
315
334
|
static isUnclearType(type) {
|
|
316
335
|
if (!type || type instanceof Type_1.UnknownType || type instanceof Type_1.UnclearReferenceType) {
|
|
317
336
|
return true;
|
|
318
337
|
}
|
|
319
338
|
else if (type instanceof Type_1.ClassType
|
|
320
|
-
&& type.getClassSignature().getDeclaringFileSignature().getFileName() ===
|
|
339
|
+
&& type.getClassSignature().getDeclaringFileSignature().getFileName() === Const_1.UNKNOWN_FILE_NAME) {
|
|
321
340
|
return true;
|
|
322
341
|
}
|
|
342
|
+
else if (type instanceof Type_1.UnionType) {
|
|
343
|
+
return !!type.getTypes().find(t => t instanceof Type_1.UnclearReferenceType);
|
|
344
|
+
}
|
|
345
|
+
else if (type instanceof Type_1.ArrayType) {
|
|
346
|
+
return (type.getBaseType() instanceof Type_1.UnclearReferenceType);
|
|
347
|
+
}
|
|
348
|
+
else if (type instanceof Type_1.AliasType) {
|
|
349
|
+
return (type.getOriginalType() instanceof Type_1.UnclearReferenceType);
|
|
350
|
+
}
|
|
323
351
|
return false;
|
|
324
352
|
}
|
|
325
353
|
static inferSimpleTypeInStmt(stmt) {
|
|
@@ -361,33 +389,50 @@ class TypeInference {
|
|
|
361
389
|
return new Type_1.UnclearReferenceType(typeStr);
|
|
362
390
|
}
|
|
363
391
|
}
|
|
364
|
-
static inferValueType(value,
|
|
392
|
+
static inferValueType(value, arkMethod) {
|
|
365
393
|
if (value instanceof Ref_1.ArkInstanceFieldRef || value instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
366
|
-
this.inferValueType(value.getBase(),
|
|
394
|
+
this.inferValueType(value.getBase(), arkMethod);
|
|
367
395
|
}
|
|
368
396
|
if (value instanceof Ref_1.AbstractRef || value instanceof Expr_1.AbstractExpr || value instanceof Local_1.Local) {
|
|
369
|
-
value.inferType(
|
|
397
|
+
value.inferType(arkMethod);
|
|
370
398
|
}
|
|
371
399
|
return value.getType();
|
|
372
400
|
}
|
|
373
401
|
static inferMethodReturnType(method) {
|
|
374
|
-
const oldMethodSignature = method.getSignature();
|
|
375
|
-
const oldMethodSubSignature = oldMethodSignature.getMethodSubSignature();
|
|
376
402
|
if (method.getName() === TSConst_1.CONSTRUCTOR_NAME) {
|
|
403
|
+
const oldMethodSignature = method.getSignature();
|
|
404
|
+
const oldMethodSubSignature = oldMethodSignature.getMethodSubSignature();
|
|
377
405
|
const newReturnType = new Type_1.ClassType(method.getDeclaringArkClass().getSignature());
|
|
378
406
|
const newMethodSubSignature = new ArkSignature_1.MethodSubSignature(oldMethodSubSignature.getMethodName(), oldMethodSubSignature.getParameters(), newReturnType, oldMethodSubSignature.isStatic());
|
|
379
|
-
method.
|
|
407
|
+
method.setImplementationSignature(new ArkSignature_1.MethodSignature(oldMethodSignature.getDeclaringClassSignature(), newMethodSubSignature));
|
|
380
408
|
return;
|
|
381
409
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
410
|
+
let implSignature = method.getImplementationSignature();
|
|
411
|
+
if (implSignature !== null) {
|
|
412
|
+
const newSignature = this.inferSignatureReturnType(implSignature, method.getDeclaringArkClass());
|
|
413
|
+
if (newSignature !== null) {
|
|
414
|
+
method.setImplementationSignature(newSignature);
|
|
415
|
+
}
|
|
386
416
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
417
|
+
let declareSignatures = method.getDeclareSignatures();
|
|
418
|
+
declareSignatures === null || declareSignatures === void 0 ? void 0 : declareSignatures.forEach((signature, index) => {
|
|
419
|
+
const newSignature = this.inferSignatureReturnType(signature, method.getDeclaringArkClass());
|
|
420
|
+
if (newSignature !== null) {
|
|
421
|
+
method.setDeclareSignatureWithIndex(newSignature, index);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
static inferSignatureReturnType(oldSignature, declaringClass) {
|
|
426
|
+
const currReturnType = oldSignature.getType();
|
|
427
|
+
if (currReturnType instanceof Type_1.UnclearReferenceType) {
|
|
428
|
+
const newReturnType = this.inferUnclearReferenceType(currReturnType.getName(), declaringClass);
|
|
429
|
+
if (newReturnType !== null) {
|
|
430
|
+
const oldSubSignature = oldSignature.getMethodSubSignature();
|
|
431
|
+
const newMethodSubSignature = new ArkSignature_1.MethodSubSignature(oldSubSignature.getMethodName(), oldSubSignature.getParameters(), newReturnType, oldSubSignature.isStatic());
|
|
432
|
+
return new ArkSignature_1.MethodSignature(oldSignature.getDeclaringClassSignature(), newMethodSubSignature);
|
|
433
|
+
}
|
|
390
434
|
}
|
|
435
|
+
return null;
|
|
391
436
|
}
|
|
392
437
|
static inferGenericType(types, arkClass) {
|
|
393
438
|
types === null || types === void 0 ? void 0 : types.forEach(type => {
|
|
@@ -407,6 +452,27 @@ class TypeInference {
|
|
|
407
452
|
}
|
|
408
453
|
});
|
|
409
454
|
}
|
|
455
|
+
static inferUnclearRefType(urType, arkClass) {
|
|
456
|
+
var _a;
|
|
457
|
+
const realTypes = urType.getGenericTypes();
|
|
458
|
+
this.inferRealGenericTypes(realTypes, arkClass);
|
|
459
|
+
if (urType.getName() === Builtin_1.Builtin.ARRAY) {
|
|
460
|
+
return new Type_1.ArrayType((_a = realTypes[0]) !== null && _a !== void 0 ? _a : Type_1.AnyType, 1);
|
|
461
|
+
}
|
|
462
|
+
const type = this.inferUnclearReferenceType(urType.getName(), arkClass);
|
|
463
|
+
if (realTypes.length === 0) {
|
|
464
|
+
return type;
|
|
465
|
+
}
|
|
466
|
+
if (type instanceof Type_1.ClassType) {
|
|
467
|
+
return new Type_1.ClassType(type.getClassSignature(), realTypes);
|
|
468
|
+
}
|
|
469
|
+
else if (type instanceof Type_1.FunctionType) {
|
|
470
|
+
return new Type_1.FunctionType(type.getMethodSignature(), realTypes);
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
return new Type_1.UnclearReferenceType(urType.getName(), realTypes);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
410
476
|
static inferUnclearReferenceType(refName, arkClass) {
|
|
411
477
|
var _a;
|
|
412
478
|
if (!refName) {
|
|
@@ -465,6 +531,10 @@ class TypeInference {
|
|
|
465
531
|
}
|
|
466
532
|
return propertyAndType;
|
|
467
533
|
}
|
|
534
|
+
if (arkClass.isAnonymousClass()) {
|
|
535
|
+
const fieldType = this.inferUnclearReferenceType(fieldName, arkClass);
|
|
536
|
+
return fieldType ? [null, fieldType] : null;
|
|
537
|
+
}
|
|
468
538
|
const property = ModelUtils_1.ModelUtils.findPropertyInClass(fieldName, arkClass);
|
|
469
539
|
let propertyType = null;
|
|
470
540
|
if (property instanceof ArkField_1.ArkField) {
|
|
@@ -521,5 +591,66 @@ class TypeInference {
|
|
|
521
591
|
}
|
|
522
592
|
}
|
|
523
593
|
}
|
|
594
|
+
static inferAnonymousClass(anon, declaredSignature, set = new Set()) {
|
|
595
|
+
var _a;
|
|
596
|
+
if (!anon) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const key = anon.getSignature().toString();
|
|
600
|
+
if (set.has(key)) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
set.add(key);
|
|
605
|
+
}
|
|
606
|
+
const scene = anon.getDeclaringArkFile().getScene();
|
|
607
|
+
const declaredClass = scene.getClass(declaredSignature);
|
|
608
|
+
if (!declaredClass) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
for (const anonField of anon.getFields()) {
|
|
612
|
+
const property = ModelUtils_1.ModelUtils.findPropertyInClass(anon.getName(), declaredClass);
|
|
613
|
+
if (property instanceof ArkField_1.ArkField) {
|
|
614
|
+
TypeInference.assignAnonField(property, anonField, scene, set);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
for (const anonMethod of anon.getMethods()) {
|
|
618
|
+
const methodSignature = (_a = declaredClass.getMethodWithName(anonMethod.getName())) === null || _a === void 0 ? void 0 : _a.matchMethodSignature(anonMethod.getSubSignature().getParameterTypes());
|
|
619
|
+
if (methodSignature) {
|
|
620
|
+
anonMethod.setImplementationSignature(methodSignature);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
static assignAnonField(property, anonField, scene, set) {
|
|
625
|
+
function deepInfer(anonType, declaredSignature) {
|
|
626
|
+
if (anonType instanceof Type_1.ClassType && anonType.getClassSignature().getClassName().startsWith(Const_1.ANONYMOUS_CLASS_PREFIX)) {
|
|
627
|
+
TypeInference.inferAnonymousClass(scene.getClass(anonType.getClassSignature()), declaredSignature, set);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
const type = property.getSignature().getType();
|
|
631
|
+
const lastStmt = anonField.getInitializer().at(-1);
|
|
632
|
+
if (lastStmt instanceof Stmt_1.ArkAssignStmt) {
|
|
633
|
+
const rightType = lastStmt.getRightOp().getType();
|
|
634
|
+
if (type instanceof Type_1.ClassType) {
|
|
635
|
+
deepInfer(rightType, type.getClassSignature());
|
|
636
|
+
}
|
|
637
|
+
else if (type instanceof Type_1.ArrayType && type.getBaseType() instanceof Type_1.ClassType &&
|
|
638
|
+
rightType instanceof Type_1.ArrayType) {
|
|
639
|
+
const baseType = rightType.getBaseType();
|
|
640
|
+
const classSignature = type.getBaseType().getClassSignature();
|
|
641
|
+
if (baseType instanceof Type_1.UnionType) {
|
|
642
|
+
baseType.getTypes().forEach(t => deepInfer(t, classSignature));
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
deepInfer(rightType, classSignature);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const leftOp = lastStmt.getLeftOp();
|
|
649
|
+
if (leftOp instanceof Ref_1.AbstractFieldRef) {
|
|
650
|
+
leftOp.setFieldSignature(property.getSignature());
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
anonField.setSignature(property.getSignature());
|
|
654
|
+
}
|
|
524
655
|
}
|
|
525
656
|
exports.TypeInference = TypeInference;
|
|
@@ -2,10 +2,6 @@ import { Constant } from '../base/Constant';
|
|
|
2
2
|
export declare const EMPTY_STRING = "";
|
|
3
3
|
export declare class ValueUtil {
|
|
4
4
|
private static readonly NumberConstantCache;
|
|
5
|
-
private static readonly UndefinedConstant;
|
|
6
|
-
private static readonly NullConstant;
|
|
7
|
-
private static readonly TrueConstant;
|
|
8
|
-
private static readonly FalseConstant;
|
|
9
5
|
private static readonly EMPTY_STRING_CONSTANT;
|
|
10
6
|
static getOrCreateNumberConst(n: number): Constant;
|
|
11
7
|
static createStringConst(str: string): Constant;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValueUtil.d.ts","sourceRoot":"","sources":["../../../src/core/common/ValueUtil.ts"],"names":[],"mappings":"AAeA,OAAO,
|
|
1
|
+
{"version":3,"file":"ValueUtil.d.ts","sourceRoot":"","sources":["../../../src/core/common/ValueUtil.ts"],"names":[],"mappings":"AAeA,OAAO,EAEH,QAAQ,EAKX,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,YAAY,KAAK,CAAC;AAE/B,qBAAa,SAAS;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAoC;IAC/E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAoC;WAEnE,sBAAsB,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ;WAS3C,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;WAOxC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;WAQlC,iBAAiB,IAAI,QAAQ;WAI7B,eAAe,IAAI,QAAQ;WAI3B,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ;CAG7D"}
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.ValueUtil = exports.EMPTY_STRING = void 0;
|
|
18
18
|
const Constant_1 = require("../base/Constant");
|
|
19
|
-
const Type_1 = require("../base/Type");
|
|
20
19
|
exports.EMPTY_STRING = '';
|
|
21
20
|
class ValueUtil {
|
|
22
21
|
static getOrCreateNumberConst(n) {
|
|
23
22
|
let constant = this.NumberConstantCache.get(n);
|
|
24
23
|
if (constant === undefined) {
|
|
25
|
-
constant = new Constant_1.
|
|
24
|
+
constant = new Constant_1.NumberConstant(n);
|
|
26
25
|
this.NumberConstantCache.set(n, constant);
|
|
27
26
|
}
|
|
28
27
|
return constant;
|
|
@@ -31,41 +30,25 @@ class ValueUtil {
|
|
|
31
30
|
if (str === exports.EMPTY_STRING) {
|
|
32
31
|
return this.EMPTY_STRING_CONSTANT;
|
|
33
32
|
}
|
|
34
|
-
return new Constant_1.
|
|
33
|
+
return new Constant_1.StringConstant(str);
|
|
35
34
|
}
|
|
36
35
|
static createConst(str) {
|
|
37
36
|
const n = Number(str);
|
|
38
37
|
if (!isNaN(n)) {
|
|
39
38
|
return this.getOrCreateNumberConst(n);
|
|
40
39
|
}
|
|
41
|
-
return new Constant_1.
|
|
40
|
+
return new Constant_1.StringConstant(str);
|
|
42
41
|
}
|
|
43
42
|
static getUndefinedConst() {
|
|
44
|
-
return
|
|
43
|
+
return Constant_1.UndefinedConstant.getInstance();
|
|
45
44
|
}
|
|
46
45
|
static getNullConstant() {
|
|
47
|
-
return
|
|
46
|
+
return Constant_1.NullConstant.getInstance();
|
|
48
47
|
}
|
|
49
48
|
static getBooleanConstant(value) {
|
|
50
|
-
return
|
|
49
|
+
return Constant_1.BooleanConstant.getInstance(value);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
exports.ValueUtil = ValueUtil;
|
|
54
|
-
ValueUtil.NumberConstantCache = new Map(
|
|
55
|
-
|
|
56
|
-
[1, new Constant_1.Constant('1', Type_1.NumberType.getInstance())],
|
|
57
|
-
[2, new Constant_1.Constant('2', Type_1.NumberType.getInstance())],
|
|
58
|
-
[3, new Constant_1.Constant('3', Type_1.NumberType.getInstance())],
|
|
59
|
-
[4, new Constant_1.Constant('4', Type_1.NumberType.getInstance())],
|
|
60
|
-
[5, new Constant_1.Constant('5', Type_1.NumberType.getInstance())],
|
|
61
|
-
[6, new Constant_1.Constant('6', Type_1.NumberType.getInstance())],
|
|
62
|
-
[7, new Constant_1.Constant('7', Type_1.NumberType.getInstance())],
|
|
63
|
-
[8, new Constant_1.Constant('8', Type_1.NumberType.getInstance())],
|
|
64
|
-
[9, new Constant_1.Constant('9', Type_1.NumberType.getInstance())],
|
|
65
|
-
[10, new Constant_1.Constant('10', Type_1.NumberType.getInstance())],
|
|
66
|
-
]);
|
|
67
|
-
ValueUtil.UndefinedConstant = new Constant_1.Constant('undefined', Type_1.UndefinedType.getInstance());
|
|
68
|
-
ValueUtil.NullConstant = new Constant_1.Constant('null', Type_1.NullType.getInstance());
|
|
69
|
-
ValueUtil.TrueConstant = new Constant_1.Constant('true', Type_1.BooleanType.getInstance());
|
|
70
|
-
ValueUtil.FalseConstant = new Constant_1.Constant('false', Type_1.BooleanType.getInstance());
|
|
71
|
-
ValueUtil.EMPTY_STRING_CONSTANT = new Constant_1.Constant(exports.EMPTY_STRING, Type_1.StringType.getInstance());
|
|
53
|
+
ValueUtil.NumberConstantCache = new Map();
|
|
54
|
+
ValueUtil.EMPTY_STRING_CONSTANT = new Constant_1.StringConstant(exports.EMPTY_STRING);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataflowSolver.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/DataflowSolver.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAoC,IAAI,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAgB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAa1F,KAAK,qBAAqB,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;AAE5C,8BAAsB,cAAc,CAAC,CAAC;IAElC,SAAS,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACtC,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,SAAS,CAAC,WAAW,EAAE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}
|
|
@@ -58,8 +58,6 @@ class DataflowSolver {
|
|
|
58
58
|
this.pathEdgeSet.add(edge);
|
|
59
59
|
// build CHA
|
|
60
60
|
let cg = new CallGraph_1.CallGraph(this.scene);
|
|
61
|
-
// let cgBuilder = new CallGraphBuilder(cg, this.scene)
|
|
62
|
-
// cgBuilder.buildClassHierarchyCallGraph([this.problem.getEntryMethod().getSignature()])
|
|
63
61
|
this.CHA = new ClassHierarchyAnalysis_1.ClassHierarchyAnalysis(this.scene, cg);
|
|
64
62
|
this.buildStmtMapInClass();
|
|
65
63
|
this.setCfg4AllStmt();
|
|
@@ -207,7 +205,7 @@ class DataflowSolver {
|
|
|
207
205
|
let callEdgePoint = edge.edgeEnd;
|
|
208
206
|
const invokeStmt = callEdgePoint.node;
|
|
209
207
|
let callees;
|
|
210
|
-
if (this.scene.
|
|
208
|
+
if (this.scene.getFile(invokeStmt.getInvokeExpr().getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature())) {
|
|
211
209
|
callees = this.getAllCalleeMethods(callEdgePoint.node);
|
|
212
210
|
}
|
|
213
211
|
else {
|
|
@@ -289,7 +287,7 @@ class DataflowSolver {
|
|
|
289
287
|
isCallStatement(stmt) {
|
|
290
288
|
for (const expr of stmt.getExprs()) {
|
|
291
289
|
if (expr instanceof Expr_1.AbstractInvokeExpr) {
|
|
292
|
-
if (this.scene.
|
|
290
|
+
if (this.scene.getFile(expr.getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature())) {
|
|
293
291
|
return true;
|
|
294
292
|
}
|
|
295
293
|
if (stmt instanceof Stmt_1.ArkInvokeStmt && (0, Util_1.getRecallMethodInParam)(stmt)) {
|
|
@@ -46,6 +46,7 @@ const Ref_1 = require("../base/Ref");
|
|
|
46
46
|
const DataflowSolver_1 = require("./DataflowSolver");
|
|
47
47
|
const Expr_1 = require("../base/Expr");
|
|
48
48
|
const Type_1 = require("../base/Type");
|
|
49
|
+
const ArkSignature_1 = require("../model/ArkSignature");
|
|
49
50
|
const fs = __importStar(require("fs"));
|
|
50
51
|
const Util_1 = require("./Util");
|
|
51
52
|
class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
@@ -259,7 +260,7 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
259
260
|
const data = fs.readFileSync(path, 'utf-8');
|
|
260
261
|
const objects = JSON.parse(data);
|
|
261
262
|
for (const object of objects) {
|
|
262
|
-
const file = this.scene.
|
|
263
|
+
const file = this.scene.getFile(new ArkSignature_1.FileSignature(object.sdkName, object.file));
|
|
263
264
|
if (!file) {
|
|
264
265
|
console.log("no file: " + object.file);
|
|
265
266
|
continue;
|
|
@@ -5,7 +5,7 @@ import { Local } from "../base/Local";
|
|
|
5
5
|
import { AbstractRef } from "../base/Ref";
|
|
6
6
|
export declare const INTERNAL_PARAMETER_SOURCE: string[];
|
|
7
7
|
export declare const INTERNAL_SINK_METHOD: string[];
|
|
8
|
-
export declare function Json2ArkMethod(str: string, scene: Scene): ArkMethod | null;
|
|
8
|
+
export declare function Json2ArkMethod(sdkName: string, str: string, scene: Scene): ArkMethod | null;
|
|
9
9
|
export declare function getRecallMethodInParam(stmt: ArkInvokeStmt): ArkMethod | null;
|
|
10
10
|
export declare function LocalEqual(local1: Local, local2: Local): boolean;
|
|
11
11
|
export declare function RefEqual(ref1: AbstractRef, ref2: AbstractRef): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/Util.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/Util.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,WAAW,EAA0C,MAAM,aAAa,CAAC;AAGlF,eAAO,MAAM,yBAAyB,EAAE,MAAM,EAE7C,CAAA;AAED,eAAO,MAAM,oBAAoB,EAAE,MAAM,EAMxC,CAAA;AAID,wBAAgB,cAAc,CAAC,OAAO,EAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAoF1F;AAGD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,CAW5E;AAGD,wBAAgB,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,OAAO,CAQhE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAOtE"}
|
|
@@ -16,19 +16,20 @@
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.RefEqual = exports.LocalEqual = exports.getRecallMethodInParam = exports.Json2ArkMethod = exports.INTERNAL_SINK_METHOD = exports.INTERNAL_PARAMETER_SOURCE = void 0;
|
|
18
18
|
const Type_1 = require("../base/Type");
|
|
19
|
+
const ArkSignature_1 = require("../model/ArkSignature");
|
|
19
20
|
const Ref_1 = require("../base/Ref");
|
|
20
21
|
exports.INTERNAL_PARAMETER_SOURCE = [
|
|
21
22
|
'@ohos.app.ability.Want.d.ts: Want'
|
|
22
23
|
];
|
|
23
24
|
exports.INTERNAL_SINK_METHOD = [
|
|
24
|
-
'console
|
|
25
|
-
'console
|
|
26
|
-
'console
|
|
27
|
-
'console
|
|
28
|
-
'console
|
|
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()>'
|
|
29
30
|
];
|
|
30
31
|
const filenamePrefix = '@etsSdk/api/';
|
|
31
|
-
function Json2ArkMethod(str, scene) {
|
|
32
|
+
function Json2ArkMethod(sdkName, str, scene) {
|
|
32
33
|
const mes = str.split(': ');
|
|
33
34
|
const fileName = filenamePrefix + mes[0] + ': ';
|
|
34
35
|
const otherMes = mes.slice(1).join(': ').split('.');
|
|
@@ -45,7 +46,7 @@ function Json2ArkMethod(str, scene) {
|
|
|
45
46
|
}
|
|
46
47
|
paramNames = otherMes[2].match(/\((.*?)\)/)[1].split(',').map((item) => item.replace(/\s/g, '')).filter((item) => item !== '');
|
|
47
48
|
}
|
|
48
|
-
const file = scene.
|
|
49
|
+
const file = scene.getFile(new ArkSignature_1.FileSignature(sdkName, fileName));
|
|
49
50
|
if (!file) {
|
|
50
51
|
return null;
|
|
51
52
|
}
|