arkanalyzer 1.0.6 → 1.0.8
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/docs/IR2ts-stmt.md +81 -0
- package/docs/IR2ts.md +82 -0
- package/lib/Config.d.ts +29 -1
- package/lib/Config.d.ts.map +1 -1
- package/lib/Config.js +44 -11
- package/lib/Scene.d.ts +152 -9
- package/lib/Scene.d.ts.map +1 -1
- package/lib/Scene.js +233 -66
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +2 -1
- package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/AbstractAnalysis.js +14 -7
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +2 -4
- package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -1
- package/lib/callgraph/algorithm/RapidTypeAnalysis.js +2 -3
- package/lib/callgraph/common/Statistics.js +1 -1
- package/lib/callgraph/model/BaseGraph.js +2 -2
- 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 +23 -14
- package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +2 -2
- package/lib/callgraph/model/builder/CallGraphBuilder.js +3 -3
- package/lib/callgraph/pointerAnalysis/Context.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Context.js +0 -1
- package/lib/callgraph/pointerAnalysis/Pag.d.ts +36 -9
- package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/Pag.js +130 -37
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +34 -5
- package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PagBuilder.js +479 -126
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +6 -0
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +107 -45
- package/lib/callgraph/pointerAnalysis/PtsDS.d.ts.map +1 -1
- package/lib/callgraph/pointerAnalysis/PtsDS.js +0 -2
- package/lib/core/base/Constant.d.ts +37 -5
- package/lib/core/base/Constant.d.ts.map +1 -1
- package/lib/core/base/Constant.js +58 -8
- package/lib/core/base/Expr.d.ts +98 -13
- package/lib/core/base/Expr.d.ts.map +1 -1
- package/lib/core/base/Expr.js +295 -127
- package/lib/core/base/Local.d.ts +70 -5
- package/lib/core/base/Local.d.ts.map +1 -1
- package/lib/core/base/Local.js +77 -4
- package/lib/core/base/Ref.d.ts +79 -5
- package/lib/core/base/Ref.d.ts.map +1 -1
- package/lib/core/base/Ref.js +143 -38
- package/lib/core/base/Stmt.d.ts +126 -12
- package/lib/core/base/Stmt.d.ts.map +1 -1
- package/lib/core/base/Stmt.js +135 -28
- package/lib/core/base/Type.d.ts +11 -2
- package/lib/core/base/Type.d.ts.map +1 -1
- package/lib/core/base/Type.js +47 -42
- package/lib/core/base/Value.d.ts +24 -2
- package/lib/core/base/Value.d.ts.map +1 -1
- 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 +12 -5
- package/lib/core/common/ArkIRTransformer.d.ts.map +1 -1
- package/lib/core/common/ArkIRTransformer.js +90 -45
- package/lib/core/common/BodyBuilder.d.ts +2 -0
- package/lib/core/common/BodyBuilder.d.ts.map +1 -1
- package/lib/core/common/BodyBuilder.js +5 -2
- package/lib/core/common/Builtin.js +1 -1
- package/lib/core/common/CfgBuilder.d.ts +12 -7
- package/lib/core/common/CfgBuilder.d.ts.map +1 -1
- package/lib/core/common/CfgBuilder.js +336 -140
- 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 +5 -4
- package/lib/core/common/DummyMainCreater.d.ts.map +1 -1
- package/lib/core/common/DummyMainCreater.js +43 -28
- 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/ExprUseReplacer.js +8 -8
- package/lib/core/common/IRUtils.d.ts +7 -0
- package/lib/core/common/IRUtils.d.ts.map +1 -1
- package/lib/core/common/IRUtils.js +34 -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 +39 -36
- package/lib/core/common/RefUseReplacer.js +3 -3
- package/lib/core/common/StmtUseReplacer.js +4 -4
- 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 +222 -90
- 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 +10 -27
- package/lib/core/common/VisibleValue.js +1 -1
- package/lib/core/dataflow/DataflowProblem.d.ts +1 -0
- package/lib/core/dataflow/DataflowProblem.d.ts.map +1 -1
- package/lib/core/dataflow/DataflowProblem.js +4 -4
- package/lib/core/dataflow/DataflowSolver.d.ts +20 -16
- package/lib/core/dataflow/DataflowSolver.d.ts.map +1 -1
- package/lib/core/dataflow/DataflowSolver.js +67 -78
- package/lib/core/dataflow/TiantAnalysis.d.ts +1 -0
- package/lib/core/dataflow/TiantAnalysis.d.ts.map +1 -1
- package/lib/core/dataflow/TiantAnalysis.js +42 -28
- package/lib/core/dataflow/UndefinedVariable.d.ts +15 -1
- package/lib/core/dataflow/UndefinedVariable.d.ts.map +1 -1
- package/lib/core/dataflow/UndefinedVariable.js +122 -76
- package/lib/core/dataflow/Util.d.ts +5 -1
- package/lib/core/dataflow/Util.d.ts.map +1 -1
- package/lib/core/dataflow/Util.js +43 -22
- package/lib/core/graph/BasicBlock.d.ts +72 -0
- package/lib/core/graph/BasicBlock.d.ts.map +1 -1
- package/lib/core/graph/BasicBlock.js +165 -3
- 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 +131 -11
- package/lib/core/graph/DominanceFinder.js +7 -7
- package/lib/core/graph/DominanceTree.js +4 -4
- package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -1
- package/lib/core/graph/builder/ViewTreeBuilder.js +6 -5
- package/lib/core/model/ArkBaseModel.d.ts +59 -0
- package/lib/core/model/ArkBaseModel.d.ts.map +1 -0
- package/lib/core/model/ArkBaseModel.js +271 -0
- package/lib/core/model/ArkBody.d.ts +3 -9
- package/lib/core/model/ArkBody.d.ts.map +1 -1
- package/lib/core/model/ArkBody.js +3 -14
- package/lib/core/model/ArkClass.d.ts +107 -13
- package/lib/core/model/ArkClass.d.ts.map +1 -1
- package/lib/core/model/ArkClass.js +152 -54
- package/lib/core/model/ArkExport.d.ts +8 -7
- package/lib/core/model/ArkExport.d.ts.map +1 -1
- package/lib/core/model/ArkExport.js +16 -18
- package/lib/core/model/ArkField.d.ts +16 -13
- package/lib/core/model/ArkField.d.ts.map +1 -1
- package/lib/core/model/ArkField.js +18 -62
- package/lib/core/model/ArkFile.d.ts +42 -0
- package/lib/core/model/ArkFile.d.ts.map +1 -1
- package/lib/core/model/ArkFile.js +58 -0
- package/lib/core/model/ArkImport.d.ts +9 -7
- package/lib/core/model/ArkImport.d.ts.map +1 -1
- package/lib/core/model/ArkImport.js +11 -12
- 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 +195 -17
- package/lib/core/model/ArkMethod.d.ts.map +1 -1
- package/lib/core/model/ArkMethod.js +363 -46
- package/lib/core/model/ArkNamespace.d.ts +6 -8
- package/lib/core/model/ArkNamespace.d.ts.map +1 -1
- package/lib/core/model/ArkNamespace.js +16 -20
- package/lib/core/model/ArkSignature.d.ts +41 -0
- package/lib/core/model/ArkSignature.d.ts.map +1 -1
- package/lib/core/model/ArkSignature.js +76 -19
- package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkClassBuilder.js +60 -49
- package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkExportBuilder.js +12 -6
- package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkFieldBuilder.js +13 -9
- package/lib/core/model/builder/ArkFileBuilder.js +1 -3
- 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 +16 -13
- package/lib/core/model/builder/ArkMethodBuilder.d.ts +3 -1
- package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkMethodBuilder.js +105 -45
- package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -1
- package/lib/core/model/builder/ArkNamespaceBuilder.js +4 -5
- package/lib/core/model/builder/builderUtils.d.ts +2 -1
- package/lib/core/model/builder/builderUtils.d.ts.map +1 -1
- package/lib/core/model/builder/builderUtils.js +63 -43
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -3
- package/lib/save/ArkStream.js +1 -1
- package/lib/save/DotPrinter.d.ts.map +1 -1
- package/lib/save/DotPrinter.js +1 -15
- package/lib/save/GraphPrinter.d.ts.map +1 -1
- package/lib/save/GraphPrinter.js +4 -2
- package/lib/save/JsonPrinter.js +5 -5
- package/lib/save/ViewTreePrinter.d.ts +16 -0
- package/lib/save/ViewTreePrinter.d.ts.map +1 -0
- package/lib/save/ViewTreePrinter.js +130 -0
- package/lib/save/source/SourceBase.d.ts +2 -2
- package/lib/save/source/SourceBase.d.ts.map +1 -1
- package/lib/save/source/SourceBase.js +6 -13
- package/lib/save/source/SourceBody.d.ts.map +1 -1
- package/lib/save/source/SourceBody.js +27 -14
- package/lib/save/source/SourceClass.d.ts.map +1 -1
- package/lib/save/source/SourceClass.js +12 -8
- package/lib/save/source/SourceField.d.ts.map +1 -1
- package/lib/save/source/SourceField.js +6 -2
- package/lib/save/source/SourceMethod.d.ts.map +1 -1
- package/lib/save/source/SourceMethod.js +10 -3
- package/lib/save/source/SourceModule.d.ts.map +1 -1
- package/lib/save/source/SourceModule.js +16 -10
- 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 +1 -1
- package/lib/save/source/SourceStmt.d.ts.map +1 -1
- package/lib/save/source/SourceStmt.js +37 -25
- 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 +82 -51
- package/lib/save/source/SourceUtils.d.ts.map +1 -1
- package/lib/save/source/SourceUtils.js +12 -11
- package/lib/transformer/StaticSingleAssignmentFormer.js +3 -3
- package/lib/utils/CfgStructualAnalysis.d.ts +1 -0
- package/lib/utils/CfgStructualAnalysis.d.ts.map +1 -1
- package/lib/utils/CfgStructualAnalysis.js +103 -72
- 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/entryMethodUtils.d.ts.map +1 -1
- package/lib/utils/entryMethodUtils.js +27 -26
- 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/lib/utils/logger.js +2 -2
- package/package.json +3 -2
|
@@ -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;
|
|
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,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtB,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,C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AAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IA0C3C,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAgB7C,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAkC3C,SAAS,CAAC,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,GAAG,IAAI;IAgCpG,SAAS,CAAC,OAAO;IAiBjB,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAc9C,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAIvC,cAAc,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;CAG5C"}
|
|
@@ -14,13 +14,11 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.DataflowSolver = void 0;
|
|
18
18
|
const Expr_1 = require("../base/Expr");
|
|
19
|
-
const Ref_1 = require("../base/Ref");
|
|
20
19
|
const Stmt_1 = require("../base/Stmt");
|
|
21
20
|
const Edge_1 = require("./Edge");
|
|
22
21
|
const CallGraph_1 = require("../../callgraph/model/CallGraph");
|
|
23
|
-
const CallGraphBuilder_1 = require("../../callgraph/model/builder/CallGraphBuilder");
|
|
24
22
|
const ClassHierarchyAnalysis_1 = require("../../callgraph/algorithm/ClassHierarchyAnalysis");
|
|
25
23
|
const entryMethodUtils_1 = require("../../utils/entryMethodUtils");
|
|
26
24
|
const Util_1 = require("./Util");
|
|
@@ -44,7 +42,7 @@ class DataflowSolver {
|
|
|
44
42
|
}
|
|
45
43
|
computeResult(stmt, d) {
|
|
46
44
|
for (let pathEdge of this.pathEdgeSet) {
|
|
47
|
-
if (pathEdge.edgeEnd.node
|
|
45
|
+
if (pathEdge.edgeEnd.node === stmt && pathEdge.edgeEnd.fact === d) {
|
|
48
46
|
return true;
|
|
49
47
|
}
|
|
50
48
|
}
|
|
@@ -60,43 +58,38 @@ class DataflowSolver {
|
|
|
60
58
|
this.pathEdgeSet.add(edge);
|
|
61
59
|
// build CHA
|
|
62
60
|
let cg = new CallGraph_1.CallGraph(this.scene);
|
|
63
|
-
let cgBuilder = new CallGraphBuilder_1.CallGraphBuilder(cg, this.scene);
|
|
64
|
-
cgBuilder.buildClassHierarchyCallGraph([this.problem.getEntryMethod().getSignature()]);
|
|
65
61
|
this.CHA = new ClassHierarchyAnalysis_1.ClassHierarchyAnalysis(this.scene, cg);
|
|
66
|
-
|
|
67
|
-
this.buildStmtMap();
|
|
62
|
+
this.buildStmtMapInClass();
|
|
68
63
|
this.setCfg4AllStmt();
|
|
69
64
|
return;
|
|
70
65
|
}
|
|
71
|
-
buildStmtMapInClass(
|
|
72
|
-
|
|
66
|
+
buildStmtMapInClass() {
|
|
67
|
+
const methods = this.scene.getMethods(true);
|
|
68
|
+
methods.push(this.problem.getEntryMethod());
|
|
69
|
+
for (const method of methods) {
|
|
73
70
|
const cfg = method.getCfg();
|
|
74
71
|
const blocks = [];
|
|
75
72
|
if (cfg) {
|
|
76
73
|
blocks.push(...cfg.getBlocks());
|
|
77
74
|
}
|
|
78
75
|
for (const block of blocks) {
|
|
79
|
-
|
|
80
|
-
for (let stmtIndex = 0; stmtIndex < stmts.length; stmtIndex++) {
|
|
81
|
-
const stmt = stmts[stmtIndex];
|
|
82
|
-
if (stmtIndex != stmts.length - 1) {
|
|
83
|
-
this.stmtNexts.set(stmt, new Set([stmts[stmtIndex + 1]]));
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
const set = new Set();
|
|
87
|
-
for (const successor of block.getSuccessors()) {
|
|
88
|
-
set.add(successor.getStmts()[0]);
|
|
89
|
-
}
|
|
90
|
-
this.stmtNexts.set(stmt, set);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
76
|
+
this.buildStmtMapInBlock(block);
|
|
93
77
|
}
|
|
94
78
|
}
|
|
95
79
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
80
|
+
buildStmtMapInBlock(block) {
|
|
81
|
+
const stmts = block.getStmts();
|
|
82
|
+
for (let stmtIndex = 0; stmtIndex < stmts.length; stmtIndex++) {
|
|
83
|
+
const stmt = stmts[stmtIndex];
|
|
84
|
+
if (stmtIndex !== stmts.length - 1) {
|
|
85
|
+
this.stmtNexts.set(stmt, new Set([stmts[stmtIndex + 1]]));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const set = new Set();
|
|
89
|
+
for (const successor of block.getSuccessors()) {
|
|
90
|
+
set.add(successor.getStmts()[0]);
|
|
91
|
+
}
|
|
92
|
+
this.stmtNexts.set(stmt, set);
|
|
100
93
|
}
|
|
101
94
|
}
|
|
102
95
|
}
|
|
@@ -108,7 +101,6 @@ class DataflowSolver {
|
|
|
108
101
|
}
|
|
109
102
|
}
|
|
110
103
|
getAllCalleeMethods(callNode) {
|
|
111
|
-
// const methodSignatures = this.CHA.resolveCall(this.problem.getEntryMethod().getSignature(), callNode);
|
|
112
104
|
const callSites = this.CHA.resolveCall(this.CHA.getCallGraph().getCallGraphNodeByMethod(this.problem.getEntryMethod().getSignature()).getID(), callNode);
|
|
113
105
|
const methods = new Set();
|
|
114
106
|
for (const callSite of callSites) {
|
|
@@ -129,8 +121,9 @@ class DataflowSolver {
|
|
|
129
121
|
}
|
|
130
122
|
pathEdgeSetHasEdge(edge) {
|
|
131
123
|
for (const path of this.pathEdgeSet) {
|
|
132
|
-
|
|
133
|
-
|
|
124
|
+
this.problem.factEqual(path.edgeEnd.fact, edge.edgeEnd.fact);
|
|
125
|
+
if (path.edgeEnd.node === edge.edgeEnd.node && this.problem.factEqual(path.edgeEnd.fact, edge.edgeEnd.fact) &&
|
|
126
|
+
path.edgeStart.node === edge.edgeStart.node && this.problem.factEqual(path.edgeStart.fact, edge.edgeStart.fact)) {
|
|
134
127
|
return true;
|
|
135
128
|
}
|
|
136
129
|
}
|
|
@@ -154,15 +147,15 @@ class DataflowSolver {
|
|
|
154
147
|
let startEdgePoint = edge.edgeStart;
|
|
155
148
|
let exitEdgePoint = edge.edgeEnd;
|
|
156
149
|
const summary = this.endSummary.get(startEdgePoint);
|
|
157
|
-
if (summary
|
|
150
|
+
if (summary === undefined) {
|
|
158
151
|
this.endSummary.set(startEdgePoint, new Set([exitEdgePoint]));
|
|
159
152
|
}
|
|
160
153
|
else {
|
|
161
154
|
summary.add(exitEdgePoint);
|
|
162
155
|
}
|
|
163
156
|
const callEdgePoints = this.inComing.get(startEdgePoint);
|
|
164
|
-
if (callEdgePoints
|
|
165
|
-
if (startEdgePoint.node.getCfg().getDeclaringMethod()
|
|
157
|
+
if (callEdgePoints === undefined) {
|
|
158
|
+
if (startEdgePoint.node.getCfg().getDeclaringMethod() === this.problem.getEntryMethod()) {
|
|
166
159
|
return;
|
|
167
160
|
}
|
|
168
161
|
throw new Error('incoming does not have ' + ((_a = startEdgePoint.node.getCfg()) === null || _a === void 0 ? void 0 : _a.getDeclaringMethod().toString()));
|
|
@@ -175,7 +168,7 @@ class DataflowSolver {
|
|
|
175
168
|
let cacheEdge = new Edge_1.PathEdge(callEdgePoint, returnSitePoint);
|
|
176
169
|
let summaryEdgeHasCacheEdge = false;
|
|
177
170
|
for (const sEdge of this.summaryEdge) {
|
|
178
|
-
if (sEdge.edgeStart
|
|
171
|
+
if (sEdge.edgeStart === callEdgePoint && sEdge.edgeEnd.node === returnSite && sEdge.edgeEnd.fact === fact) {
|
|
179
172
|
summaryEdgeHasCacheEdge = true;
|
|
180
173
|
break;
|
|
181
174
|
}
|
|
@@ -184,7 +177,7 @@ class DataflowSolver {
|
|
|
184
177
|
this.summaryEdge.add(cacheEdge);
|
|
185
178
|
let startOfCaller = this.getStartOfCallerMethod(callEdgePoint.node);
|
|
186
179
|
for (let pathEdge of this.pathEdgeSet) {
|
|
187
|
-
if (pathEdge.edgeStart.node
|
|
180
|
+
if (pathEdge.edgeStart.node === startOfCaller && pathEdge.edgeEnd === callEdgePoint) {
|
|
188
181
|
this.propagate(new Edge_1.PathEdge(pathEdge.edgeStart, returnSitePoint));
|
|
189
182
|
}
|
|
190
183
|
}
|
|
@@ -212,51 +205,22 @@ class DataflowSolver {
|
|
|
212
205
|
let callEdgePoint = edge.edgeEnd;
|
|
213
206
|
const invokeStmt = callEdgePoint.node;
|
|
214
207
|
let callees;
|
|
215
|
-
if (this.scene.
|
|
208
|
+
if (this.scene.getFile(invokeStmt.getInvokeExpr().getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature())) {
|
|
216
209
|
callees = this.getAllCalleeMethods(callEdgePoint.node);
|
|
217
210
|
}
|
|
218
211
|
else {
|
|
219
212
|
callees = new Set([(0, Util_1.getRecallMethodInParam)(invokeStmt)]);
|
|
220
213
|
}
|
|
221
|
-
let callNode = edge.edgeEnd.node;
|
|
222
214
|
let returnSite = this.getReturnSiteOfCall(callEdgePoint.node);
|
|
223
215
|
for (let callee of callees) {
|
|
224
|
-
let callFlowFunc = this.problem.getCallFlowFunction(
|
|
216
|
+
let callFlowFunc = this.problem.getCallFlowFunction(invokeStmt, callee);
|
|
225
217
|
if (!callee.getCfg()) {
|
|
226
218
|
continue;
|
|
227
219
|
}
|
|
228
220
|
let firstStmt = [...callee.getCfg().getBlocks()][0].getStmts()[callee.getParameters().length];
|
|
229
221
|
let facts = callFlowFunc.getDataFacts(callEdgePoint.fact);
|
|
230
222
|
for (let fact of facts) {
|
|
231
|
-
|
|
232
|
-
let startEdgePoint = new Edge_1.PathEdgePoint(firstStmt, fact);
|
|
233
|
-
this.propagate(new Edge_1.PathEdge(startEdgePoint, startEdgePoint));
|
|
234
|
-
//add callEdgePoint in inComing.get(startEdgePoint)
|
|
235
|
-
let coming = undefined;
|
|
236
|
-
for (const incoming of this.inComing.keys()) {
|
|
237
|
-
if (incoming.fact == startEdgePoint.fact && incoming.node == startEdgePoint.node) {
|
|
238
|
-
coming = this.inComing.get(incoming);
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (coming == undefined) {
|
|
243
|
-
this.inComing.set(startEdgePoint, new Set([callEdgePoint]));
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
coming.add(callEdgePoint);
|
|
247
|
-
}
|
|
248
|
-
let exitEdgePoints = new Set();
|
|
249
|
-
for (const end of Array.from(this.endSummary.keys())) {
|
|
250
|
-
if (end.fact == fact && end.node == firstStmt) {
|
|
251
|
-
exitEdgePoints = this.endSummary.get(end);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
for (let exitEdgePoint of exitEdgePoints) {
|
|
255
|
-
let returnFlowFunc = this.problem.getExitToReturnFlowFunction(exitEdgePoint.node, returnSite, callEdgePoint.node);
|
|
256
|
-
for (let returnFact of returnFlowFunc.getDataFacts(exitEdgePoint.fact)) {
|
|
257
|
-
this.summaryEdge.add(new Edge_1.PathEdge(edge.edgeEnd, new Edge_1.PathEdgePoint(returnSite, returnFact)));
|
|
258
|
-
}
|
|
259
|
-
}
|
|
223
|
+
this.callNodeFactPropagate(edge, firstStmt, fact, returnSite);
|
|
260
224
|
}
|
|
261
225
|
}
|
|
262
226
|
let callToReturnflowFunc = this.problem.getCallToReturnFlowFunction(edge.edgeEnd.node, returnSite);
|
|
@@ -265,13 +229,45 @@ class DataflowSolver {
|
|
|
265
229
|
this.propagate(new Edge_1.PathEdge(start, new Edge_1.PathEdgePoint(returnSite, fact)));
|
|
266
230
|
}
|
|
267
231
|
for (let cacheEdge of this.summaryEdge) {
|
|
268
|
-
if (cacheEdge.edgeStart
|
|
232
|
+
if (cacheEdge.edgeStart === edge.edgeEnd && cacheEdge.edgeEnd.node === returnSite) {
|
|
269
233
|
this.propagate(new Edge_1.PathEdge(start, cacheEdge.edgeEnd));
|
|
270
234
|
}
|
|
271
235
|
}
|
|
272
236
|
}
|
|
237
|
+
callNodeFactPropagate(edge, firstStmt, fact, returnSite) {
|
|
238
|
+
let callEdgePoint = edge.edgeEnd;
|
|
239
|
+
// method start loop path edge
|
|
240
|
+
let startEdgePoint = new Edge_1.PathEdgePoint(firstStmt, fact);
|
|
241
|
+
this.propagate(new Edge_1.PathEdge(startEdgePoint, startEdgePoint));
|
|
242
|
+
//add callEdgePoint in inComing.get(startEdgePoint)
|
|
243
|
+
let coming;
|
|
244
|
+
for (const incoming of this.inComing.keys()) {
|
|
245
|
+
if (incoming.fact === startEdgePoint.fact && incoming.node === startEdgePoint.node) {
|
|
246
|
+
coming = this.inComing.get(incoming);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (coming === undefined) {
|
|
251
|
+
this.inComing.set(startEdgePoint, new Set([callEdgePoint]));
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
coming.add(callEdgePoint);
|
|
255
|
+
}
|
|
256
|
+
let exitEdgePoints = new Set();
|
|
257
|
+
for (const end of Array.from(this.endSummary.keys())) {
|
|
258
|
+
if (end.fact === fact && end.node === firstStmt) {
|
|
259
|
+
exitEdgePoints = this.endSummary.get(end);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
for (let exitEdgePoint of exitEdgePoints) {
|
|
263
|
+
let returnFlowFunc = this.problem.getExitToReturnFlowFunction(exitEdgePoint.node, returnSite, callEdgePoint.node);
|
|
264
|
+
for (let returnFact of returnFlowFunc.getDataFacts(exitEdgePoint.fact)) {
|
|
265
|
+
this.summaryEdge.add(new Edge_1.PathEdge(edge.edgeEnd, new Edge_1.PathEdgePoint(returnSite, returnFact)));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
273
269
|
doSolve() {
|
|
274
|
-
while (this.workList.length
|
|
270
|
+
while (this.workList.length !== 0) {
|
|
275
271
|
let pathEdge = this.workList.shift();
|
|
276
272
|
if (this.laterEdges.has(pathEdge)) {
|
|
277
273
|
this.laterEdges.delete(pathEdge);
|
|
@@ -291,7 +287,7 @@ class DataflowSolver {
|
|
|
291
287
|
isCallStatement(stmt) {
|
|
292
288
|
for (const expr of stmt.getExprs()) {
|
|
293
289
|
if (expr instanceof Expr_1.AbstractInvokeExpr) {
|
|
294
|
-
if (this.scene.
|
|
290
|
+
if (this.scene.getFile(expr.getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature())) {
|
|
295
291
|
return true;
|
|
296
292
|
}
|
|
297
293
|
if (stmt instanceof Stmt_1.ArkInvokeStmt && (0, Util_1.getRecallMethodInParam)(stmt)) {
|
|
@@ -309,10 +305,3 @@ class DataflowSolver {
|
|
|
309
305
|
}
|
|
310
306
|
}
|
|
311
307
|
exports.DataflowSolver = DataflowSolver;
|
|
312
|
-
function factEqual(fact1, fact2) {
|
|
313
|
-
if (fact1 instanceof Ref_1.AbstractRef && fact2 instanceof Ref_1.AbstractRef) {
|
|
314
|
-
return fact1.toString() == fact2.toString();
|
|
315
|
-
}
|
|
316
|
-
return fact1 == fact2;
|
|
317
|
-
}
|
|
318
|
-
exports.factEqual = factEqual;
|
|
@@ -30,6 +30,7 @@ export declare class TiantAnalysisChecker extends DataflowProblem<Value> {
|
|
|
30
30
|
createZeroValue(): Value;
|
|
31
31
|
getZeroValue(): Value;
|
|
32
32
|
Json2ArkMethod(path: string): ArkMethod[];
|
|
33
|
+
factEqual(d1: Value, d2: Value): boolean;
|
|
33
34
|
}
|
|
34
35
|
export declare class TiantAnalysisSolver extends DataflowSolver<Value> {
|
|
35
36
|
constructor(problem: TiantAnalysisChecker, scene: Scene);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TiantAnalysis.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/TiantAnalysis.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACl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AAE,CAAC,CAA0D;IAC7H,OAAO,EAAE,SAAS,EAAE,CAAM;IAC1B,KAAK,EAAE,SAAS,EAAE,CAAM;gBACZ,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS;IAQzC,aAAa,IAAI,IAAI;IAIrB,cAAc,IAAI,SAAS;IAI3B,OAAO,CAAC,UAAU;IAWX,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI;IAItC,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI;IAI3C,qBAAqB,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC;IAsDtE,mBAAmB,CAAC,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC;IA2DxE,2BAA2B,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,EAAE,QAAQ,EAAC,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC;IAsC3F,2BAA2B,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC;IAkB5E,eAAe,IAAI,KAAK;IAIxB,YAAY,IAAI,KAAK;IAIrB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE;IA6DzC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO;CAU3C;AAED,qBAAa,mBAAoB,SAAQ,cAAc,CAAC,KAAK,CAAC;gBAC9C,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK;CAG1D"}
|
|
@@ -46,7 +46,9 @@ 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"));
|
|
51
|
+
const Util_1 = require("./Util");
|
|
50
52
|
class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
51
53
|
constructor(stmt, method) {
|
|
52
54
|
super();
|
|
@@ -69,7 +71,7 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
69
71
|
callSource(val) {
|
|
70
72
|
if (val instanceof Expr_1.AbstractInvokeExpr) {
|
|
71
73
|
for (const source of this.sources) {
|
|
72
|
-
if (source.getSignature()
|
|
74
|
+
if (source.getSignature() === val.getMethodSignature()) {
|
|
73
75
|
return true;
|
|
74
76
|
}
|
|
75
77
|
}
|
|
@@ -87,7 +89,7 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
87
89
|
return new class {
|
|
88
90
|
getDataFacts(dataFact) {
|
|
89
91
|
let ret = new Set();
|
|
90
|
-
if (checkerInstance.getEntryPoint()
|
|
92
|
+
if (checkerInstance.getEntryPoint() === srcStmt && checkerInstance.getZeroValue() === dataFact) {
|
|
91
93
|
let entryMethod = checkerInstance.getEntryMethod();
|
|
92
94
|
const parameters = [...entryMethod.getCfg().getBlocks()][0].getStmts().slice(0, entryMethod.getParameters().length);
|
|
93
95
|
for (let i = 0; i < parameters.length; i++) {
|
|
@@ -99,7 +101,7 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
99
101
|
// 加入所有的全局变量和静态属性(may analysis)
|
|
100
102
|
const staticFields = entryMethod.getDeclaringArkClass().getStaticFields(checkerInstance.classMap);
|
|
101
103
|
for (const field of staticFields) {
|
|
102
|
-
if (field.getInitializer()
|
|
104
|
+
if (field.getInitializer() === undefined) {
|
|
103
105
|
ret.add(new Ref_1.ArkStaticFieldRef(field.getSignature()));
|
|
104
106
|
}
|
|
105
107
|
}
|
|
@@ -108,25 +110,25 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
108
110
|
}
|
|
109
111
|
return ret;
|
|
110
112
|
}
|
|
111
|
-
if (!
|
|
112
|
-
if (!(dataFact instanceof Local_1.Local && dataFact.getName()
|
|
113
|
+
if (!checkerInstance.factEqual(srcStmt.getDef(), dataFact)) {
|
|
114
|
+
if (!(dataFact instanceof Local_1.Local && dataFact.getName() === srcStmt.getDef().toString()))
|
|
113
115
|
ret.add(dataFact);
|
|
114
116
|
}
|
|
115
117
|
if (srcStmt instanceof Stmt_1.ArkAssignStmt) {
|
|
116
118
|
let stmt = srcStmt;
|
|
117
119
|
let assigned = stmt.getLeftOp();
|
|
118
120
|
let rightOp = stmt.getRightOp();
|
|
119
|
-
if (checkerInstance.getZeroValue()
|
|
121
|
+
if (checkerInstance.getZeroValue() === dataFact) {
|
|
120
122
|
if (checkerInstance.callSource(rightOp)) {
|
|
121
123
|
ret.add(assigned);
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
|
-
else if (
|
|
126
|
+
else if (checkerInstance.factEqual(rightOp, dataFact) || rightOp.getType() instanceof Type_1.UndefinedType) {
|
|
125
127
|
ret.add(assigned);
|
|
126
128
|
if (assigned instanceof Ref_1.ArkInstanceFieldRef) {
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
|
-
else if (dataFact instanceof Ref_1.ArkInstanceFieldRef && rightOp
|
|
131
|
+
else if (dataFact instanceof Ref_1.ArkInstanceFieldRef && rightOp === dataFact.getBase()) {
|
|
130
132
|
const field = new Ref_1.ArkInstanceFieldRef(srcStmt.getLeftOp(), dataFact.getFieldSignature());
|
|
131
133
|
ret.add(field);
|
|
132
134
|
}
|
|
@@ -140,11 +142,11 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
140
142
|
return new class {
|
|
141
143
|
getDataFacts(dataFact) {
|
|
142
144
|
const ret = new Set();
|
|
143
|
-
if (checkerInstance.getZeroValue()
|
|
145
|
+
if (checkerInstance.getZeroValue() === dataFact) {
|
|
144
146
|
ret.add(checkerInstance.getZeroValue());
|
|
145
147
|
// 加上调用函数能访问到的所有静态变量,如果不考虑多线程,加上所有变量,考虑则要统计之前已经处理过的变量并排除
|
|
146
148
|
for (const field of method.getDeclaringArkClass().getStaticFields(checkerInstance.classMap)) {
|
|
147
|
-
if (field.getInitializer()
|
|
149
|
+
if (field.getInitializer() === undefined) {
|
|
148
150
|
ret.add(new Ref_1.ArkStaticFieldRef(field.getSignature()));
|
|
149
151
|
}
|
|
150
152
|
}
|
|
@@ -154,19 +156,19 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
154
156
|
}
|
|
155
157
|
else {
|
|
156
158
|
const callExpr = srcStmt.getExprs()[0];
|
|
157
|
-
if (callExpr instanceof Expr_1.ArkInstanceInvokeExpr && dataFact instanceof Ref_1.ArkInstanceFieldRef && callExpr.getBase().getName()
|
|
159
|
+
if (callExpr instanceof Expr_1.ArkInstanceInvokeExpr && dataFact instanceof Ref_1.ArkInstanceFieldRef && callExpr.getBase().getName() === dataFact.getBase().getName()) {
|
|
158
160
|
// todo:base转this
|
|
159
161
|
const _this = [...srcStmt.getCfg().getBlocks()][0].getStmts()[0].getDef();
|
|
160
162
|
const thisRef = new Ref_1.ArkInstanceFieldRef(_this, dataFact.getFieldSignature());
|
|
161
163
|
ret.add(thisRef);
|
|
162
164
|
}
|
|
163
|
-
else if (callExpr instanceof Expr_1.ArkStaticInvokeExpr && dataFact instanceof Ref_1.ArkStaticFieldRef && callExpr.getMethodSignature().getDeclaringClassSignature()
|
|
165
|
+
else if (callExpr instanceof Expr_1.ArkStaticInvokeExpr && dataFact instanceof Ref_1.ArkStaticFieldRef && callExpr.getMethodSignature().getDeclaringClassSignature() === dataFact.getFieldSignature().getDeclaringSignature()) {
|
|
164
166
|
ret.add(dataFact);
|
|
165
167
|
}
|
|
166
168
|
for (const sink of checkerInstance.sinks) {
|
|
167
|
-
if (callExpr.getMethodSignature()
|
|
169
|
+
if (callExpr.getMethodSignature() === sink.getSignature()) {
|
|
168
170
|
for (const param of callExpr.getArgs()) {
|
|
169
|
-
if (
|
|
171
|
+
if (checkerInstance.factEqual(param, dataFact)) {
|
|
170
172
|
console.log("source: " + dataFact);
|
|
171
173
|
console.log("sink: " + srcStmt.getOriginPositionInfo().toString() + ", " + srcStmt.toString());
|
|
172
174
|
}
|
|
@@ -177,12 +179,12 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
177
179
|
const callStmt = srcStmt;
|
|
178
180
|
const args = callStmt.getInvokeExpr().getArgs();
|
|
179
181
|
for (let i = 0; i < args.length; i++) {
|
|
180
|
-
if (args[i]
|
|
182
|
+
if (args[i] === dataFact || checkerInstance.callSource(args[i]) && checkerInstance.getZeroValue() === dataFact) {
|
|
181
183
|
const realParameter = [...method.getCfg().getBlocks()][0].getStmts()[i].getDef();
|
|
182
184
|
if (realParameter)
|
|
183
185
|
ret.add(realParameter);
|
|
184
186
|
}
|
|
185
|
-
else if (dataFact instanceof Ref_1.ArkInstanceFieldRef && dataFact.getBase().getName()
|
|
187
|
+
else if (dataFact instanceof Ref_1.ArkInstanceFieldRef && dataFact.getBase().getName() === args[i].toString()) {
|
|
186
188
|
const realParameter = [...method.getCfg().getBlocks()][0].getStmts()[i].getDef();
|
|
187
189
|
if (realParameter) {
|
|
188
190
|
const retRef = new Ref_1.ArkInstanceFieldRef(realParameter, dataFact.getFieldSignature());
|
|
@@ -199,10 +201,10 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
199
201
|
return new class {
|
|
200
202
|
getDataFacts(dataFact) {
|
|
201
203
|
let ret = new Set();
|
|
202
|
-
if (dataFact
|
|
204
|
+
if (dataFact === checkerInstance.getZeroValue()) {
|
|
203
205
|
ret.add(checkerInstance.getZeroValue());
|
|
204
206
|
}
|
|
205
|
-
if (dataFact instanceof Ref_1.ArkInstanceFieldRef && dataFact.getBase().getName()
|
|
207
|
+
if (dataFact instanceof Ref_1.ArkInstanceFieldRef && dataFact.getBase().getName() === "this") {
|
|
206
208
|
// todo:this转base。
|
|
207
209
|
const expr = callStmt.getExprs()[0];
|
|
208
210
|
if (expr instanceof Expr_1.ArkInstanceInvokeExpr) {
|
|
@@ -217,13 +219,13 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
217
219
|
let ass = callStmt;
|
|
218
220
|
let leftOp = ass.getLeftOp();
|
|
219
221
|
let retVal = srcStmt.getOp();
|
|
220
|
-
if (dataFact
|
|
222
|
+
if (dataFact === checkerInstance.getZeroValue()) {
|
|
221
223
|
ret.add(checkerInstance.getZeroValue());
|
|
222
224
|
if (checkerInstance.callSource(retVal) || checkerInstance.callSource(ass.getRightOp())) {
|
|
223
225
|
ret.add(leftOp);
|
|
224
226
|
}
|
|
225
227
|
}
|
|
226
|
-
else if (retVal
|
|
228
|
+
else if (retVal === dataFact) {
|
|
227
229
|
ret.add(leftOp);
|
|
228
230
|
}
|
|
229
231
|
}
|
|
@@ -236,11 +238,11 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
236
238
|
return new class {
|
|
237
239
|
getDataFacts(dataFact) {
|
|
238
240
|
const ret = new Set();
|
|
239
|
-
if (checkerInstance.getZeroValue()
|
|
241
|
+
if (checkerInstance.getZeroValue() === dataFact) {
|
|
240
242
|
ret.add(checkerInstance.getZeroValue());
|
|
241
243
|
}
|
|
242
244
|
const defValue = srcStmt.getDef();
|
|
243
|
-
if (!(defValue && defValue
|
|
245
|
+
if (!(defValue && defValue === dataFact)) {
|
|
244
246
|
ret.add(dataFact);
|
|
245
247
|
}
|
|
246
248
|
return ret;
|
|
@@ -258,15 +260,15 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
258
260
|
const data = fs.readFileSync(path, 'utf-8');
|
|
259
261
|
const objects = JSON.parse(data);
|
|
260
262
|
for (const object of objects) {
|
|
261
|
-
const file = this.scene.
|
|
263
|
+
const file = this.scene.getFile(new ArkSignature_1.FileSignature(object.sdkName, object.file));
|
|
262
264
|
if (!file) {
|
|
263
265
|
console.log("no file: " + object.file);
|
|
264
266
|
continue;
|
|
265
267
|
}
|
|
266
268
|
let arkClass = null;
|
|
267
|
-
if (object.namespace
|
|
269
|
+
if (object.namespace === "_") {
|
|
268
270
|
for (const clas of file.getClasses()) {
|
|
269
|
-
if (clas.getName()
|
|
271
|
+
if (clas.getName() === object.class) {
|
|
270
272
|
arkClass = clas;
|
|
271
273
|
break;
|
|
272
274
|
}
|
|
@@ -275,14 +277,14 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
275
277
|
else {
|
|
276
278
|
let arkNamespace = null;
|
|
277
279
|
for (const ns of file.getNamespaces()) {
|
|
278
|
-
if (ns.getName()
|
|
280
|
+
if (ns.getName() === object.namespace) {
|
|
279
281
|
arkNamespace = ns;
|
|
280
282
|
break;
|
|
281
283
|
}
|
|
282
284
|
}
|
|
283
285
|
if (arkNamespace) {
|
|
284
286
|
for (const clas of arkNamespace.getClasses()) {
|
|
285
|
-
if (clas.getName()
|
|
287
|
+
if (clas.getName() === object.class) {
|
|
286
288
|
arkClass = clas;
|
|
287
289
|
break;
|
|
288
290
|
}
|
|
@@ -300,7 +302,7 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
300
302
|
else {
|
|
301
303
|
let arkMethod = null;
|
|
302
304
|
for (const method of arkClass.getMethods()) {
|
|
303
|
-
if (method.getName()
|
|
305
|
+
if (method.getName() === object.method) {
|
|
304
306
|
arkMethod = method;
|
|
305
307
|
break;
|
|
306
308
|
}
|
|
@@ -316,6 +318,18 @@ class TiantAnalysisChecker extends DataflowProblem_1.DataflowProblem {
|
|
|
316
318
|
}
|
|
317
319
|
return arkMethods;
|
|
318
320
|
}
|
|
321
|
+
factEqual(d1, d2) {
|
|
322
|
+
if (d1 instanceof Constant_1.Constant && d2 instanceof Constant_1.Constant) {
|
|
323
|
+
return d1 === d2;
|
|
324
|
+
}
|
|
325
|
+
else if (d1 instanceof Local_1.Local && d2 instanceof Local_1.Local) {
|
|
326
|
+
return (0, Util_1.LocalEqual)(d1, d2);
|
|
327
|
+
}
|
|
328
|
+
else if (d1 instanceof Ref_1.AbstractRef && d2 instanceof Ref_1.AbstractRef) {
|
|
329
|
+
return (0, Util_1.RefEqual)(d1, d2);
|
|
330
|
+
}
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
319
333
|
}
|
|
320
334
|
exports.TiantAnalysisChecker = TiantAnalysisChecker;
|
|
321
335
|
class TiantAnalysisSolver extends DataflowSolver_1.DataflowSolver {
|
|
@@ -2,12 +2,13 @@ import { Scene } from '../../Scene';
|
|
|
2
2
|
import { DataflowProblem, FlowFunction } from './DataflowProblem';
|
|
3
3
|
import { Local } from '../base/Local';
|
|
4
4
|
import { Value } from '../base/Value';
|
|
5
|
-
import { Stmt } from '../base/Stmt';
|
|
5
|
+
import { ArkAssignStmt, Stmt } from '../base/Stmt';
|
|
6
6
|
import { ArkMethod } from '../model/ArkMethod';
|
|
7
7
|
import { Constant } from '../base/Constant';
|
|
8
8
|
import { DataflowSolver } from './DataflowSolver';
|
|
9
9
|
import { FileSignature, NamespaceSignature } from '../model/ArkSignature';
|
|
10
10
|
import { ArkClass } from '../model/ArkClass';
|
|
11
|
+
import { ArkField } from '../model/ArkField';
|
|
11
12
|
export declare class UndefinedVariableChecker extends DataflowProblem<Value> {
|
|
12
13
|
zeroValue: Constant;
|
|
13
14
|
entryPoint: Stmt;
|
|
@@ -15,18 +16,31 @@ export declare class UndefinedVariableChecker extends DataflowProblem<Value> {
|
|
|
15
16
|
scene: Scene;
|
|
16
17
|
classMap: Map<FileSignature | NamespaceSignature, ArkClass[]>;
|
|
17
18
|
globalVariableMap: Map<FileSignature | NamespaceSignature, Local[]>;
|
|
19
|
+
outcomes: Outcome[];
|
|
18
20
|
constructor(stmt: Stmt, method: ArkMethod);
|
|
19
21
|
getEntryPoint(): Stmt;
|
|
20
22
|
getEntryMethod(): ArkMethod;
|
|
21
23
|
private isUndefined;
|
|
22
24
|
getNormalFlowFunction(srcStmt: Stmt, tgtStmt: Stmt): FlowFunction<Value>;
|
|
25
|
+
insideNormalFlowFunction(ret: Set<Value>, srcStmt: ArkAssignStmt, dataFact: Value): void;
|
|
23
26
|
getCallFlowFunction(srcStmt: Stmt, method: ArkMethod): FlowFunction<Value>;
|
|
27
|
+
insideCallFlowFunction(ret: Set<Value>, method: ArkMethod): void;
|
|
28
|
+
addUndefinedField(field: ArkField, method: ArkMethod, ret: Set<Value>): void;
|
|
29
|
+
addParameters(srcStmt: Stmt, dataFact: Value, method: ArkMethod, ret: Set<Value>): void;
|
|
24
30
|
getExitToReturnFlowFunction(srcStmt: Stmt, tgtStmt: Stmt, callStmt: Stmt): FlowFunction<Value>;
|
|
25
31
|
getCallToReturnFlowFunction(srcStmt: Stmt, tgtStmt: Stmt): FlowFunction<Value>;
|
|
26
32
|
createZeroValue(): Value;
|
|
27
33
|
getZeroValue(): Value;
|
|
34
|
+
factEqual(d1: Value, d2: Value): boolean;
|
|
35
|
+
getOutcomes(): Outcome[];
|
|
28
36
|
}
|
|
29
37
|
export declare class UndefinedVariableSolver extends DataflowSolver<Value> {
|
|
30
38
|
constructor(problem: UndefinedVariableChecker, scene: Scene);
|
|
31
39
|
}
|
|
40
|
+
declare class Outcome {
|
|
41
|
+
value: Value;
|
|
42
|
+
stmt: Stmt;
|
|
43
|
+
constructor(v: Value, s: Stmt);
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
32
46
|
//# sourceMappingURL=UndefinedVariable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UndefinedVariable.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/UndefinedVariable.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,KAAK,E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