arkanalyzer 1.0.5

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.
Files changed (322) hide show
  1. package/LICENSE +201 -0
  2. package/README.en.md +88 -0
  3. package/README.md +98 -0
  4. package/docs/HowToCreatePR.md +55 -0
  5. package/docs/HowToHandleIssues.md +155 -0
  6. package/docs/quickstart.pdf +0 -0
  7. package/lib/Config.d.ts +26 -0
  8. package/lib/Config.d.ts.map +1 -0
  9. package/lib/Config.js +128 -0
  10. package/lib/Scene.d.ts +125 -0
  11. package/lib/Scene.d.ts.map +1 -0
  12. package/lib/Scene.js +762 -0
  13. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts +28 -0
  14. package/lib/callgraph/algorithm/AbstractAnalysis.d.ts.map +1 -0
  15. package/lib/callgraph/algorithm/AbstractAnalysis.js +137 -0
  16. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts +11 -0
  17. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.d.ts.map +1 -0
  18. package/lib/callgraph/algorithm/ClassHierarchyAnalysis.js +71 -0
  19. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts +16 -0
  20. package/lib/callgraph/algorithm/RapidTypeAnalysis.d.ts.map +1 -0
  21. package/lib/callgraph/algorithm/RapidTypeAnalysis.js +147 -0
  22. package/lib/callgraph/common/Statistics.d.ts +58 -0
  23. package/lib/callgraph/common/Statistics.d.ts.map +1 -0
  24. package/lib/callgraph/common/Statistics.js +203 -0
  25. package/lib/callgraph/model/BaseGraph.d.ts +62 -0
  26. package/lib/callgraph/model/BaseGraph.d.ts.map +1 -0
  27. package/lib/callgraph/model/BaseGraph.js +158 -0
  28. package/lib/callgraph/model/CallGraph.d.ts +94 -0
  29. package/lib/callgraph/model/CallGraph.d.ts.map +1 -0
  30. package/lib/callgraph/model/CallGraph.js +339 -0
  31. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts +16 -0
  32. package/lib/callgraph/model/builder/CallGraphBuilder.d.ts.map +1 -0
  33. package/lib/callgraph/model/builder/CallGraphBuilder.js +106 -0
  34. package/lib/callgraph/pointerAnalysis/Context.d.ts +38 -0
  35. package/lib/callgraph/pointerAnalysis/Context.d.ts.map +1 -0
  36. package/lib/callgraph/pointerAnalysis/Context.js +156 -0
  37. package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts +23 -0
  38. package/lib/callgraph/pointerAnalysis/DummyCallCreator.d.ts.map +1 -0
  39. package/lib/callgraph/pointerAnalysis/DummyCallCreator.js +104 -0
  40. package/lib/callgraph/pointerAnalysis/Pag.d.ts +209 -0
  41. package/lib/callgraph/pointerAnalysis/Pag.d.ts.map +1 -0
  42. package/lib/callgraph/pointerAnalysis/Pag.js +774 -0
  43. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts +88 -0
  44. package/lib/callgraph/pointerAnalysis/PagBuilder.d.ts.map +1 -0
  45. package/lib/callgraph/pointerAnalysis/PagBuilder.js +821 -0
  46. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts +64 -0
  47. package/lib/callgraph/pointerAnalysis/PointerAnalysis.d.ts.map +1 -0
  48. package/lib/callgraph/pointerAnalysis/PointerAnalysis.js +502 -0
  49. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts +9 -0
  50. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.d.ts.map +1 -0
  51. package/lib/callgraph/pointerAnalysis/PointerAnalysisConfig.js +57 -0
  52. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts +58 -0
  53. package/lib/callgraph/pointerAnalysis/PtsDS.d.ts.map +1 -0
  54. package/lib/callgraph/pointerAnalysis/PtsDS.js +234 -0
  55. package/lib/core/base/Constant.d.ts +17 -0
  56. package/lib/core/base/Constant.d.ts.map +1 -0
  57. package/lib/core/base/Constant.js +53 -0
  58. package/lib/core/base/Decorator.d.ts +15 -0
  59. package/lib/core/base/Decorator.d.ts.map +1 -0
  60. package/lib/core/base/Decorator.js +43 -0
  61. package/lib/core/base/DefUseChain.d.ts +9 -0
  62. package/lib/core/base/DefUseChain.d.ts.map +1 -0
  63. package/lib/core/base/DefUseChain.js +25 -0
  64. package/lib/core/base/Expr.d.ts +219 -0
  65. package/lib/core/base/Expr.d.ts.map +1 -0
  66. package/lib/core/base/Expr.js +896 -0
  67. package/lib/core/base/Local.d.ts +40 -0
  68. package/lib/core/base/Local.d.ts.map +1 -0
  69. package/lib/core/base/Local.js +101 -0
  70. package/lib/core/base/Position.d.ts +39 -0
  71. package/lib/core/base/Position.d.ts.map +1 -0
  72. package/lib/core/base/Position.js +86 -0
  73. package/lib/core/base/Ref.d.ts +75 -0
  74. package/lib/core/base/Ref.d.ts.map +1 -0
  75. package/lib/core/base/Ref.js +286 -0
  76. package/lib/core/base/Stmt.d.ts +109 -0
  77. package/lib/core/base/Stmt.d.ts.map +1 -0
  78. package/lib/core/base/Stmt.js +374 -0
  79. package/lib/core/base/Type.d.ts +220 -0
  80. package/lib/core/base/Type.d.ts.map +1 -0
  81. package/lib/core/base/Type.js +477 -0
  82. package/lib/core/base/Value.d.ts +11 -0
  83. package/lib/core/base/Value.d.ts.map +1 -0
  84. package/lib/core/base/Value.js +16 -0
  85. package/lib/core/common/ArkIRTransformer.d.ts +101 -0
  86. package/lib/core/common/ArkIRTransformer.d.ts.map +1 -0
  87. package/lib/core/common/ArkIRTransformer.js +1674 -0
  88. package/lib/core/common/BodyBuilder.d.ts +10 -0
  89. package/lib/core/common/BodyBuilder.d.ts.map +1 -0
  90. package/lib/core/common/BodyBuilder.js +34 -0
  91. package/lib/core/common/Builtin.d.ts +35 -0
  92. package/lib/core/common/Builtin.d.ts.map +1 -0
  93. package/lib/core/common/Builtin.js +78 -0
  94. package/lib/core/common/CfgBuilder.d.ts +136 -0
  95. package/lib/core/common/CfgBuilder.d.ts.map +1 -0
  96. package/lib/core/common/CfgBuilder.js +1241 -0
  97. package/lib/core/common/Const.d.ts +15 -0
  98. package/lib/core/common/Const.d.ts.map +1 -0
  99. package/lib/core/common/Const.js +34 -0
  100. package/lib/core/common/DummyMainCreater.d.ts +48 -0
  101. package/lib/core/common/DummyMainCreater.d.ts.map +1 -0
  102. package/lib/core/common/DummyMainCreater.js +433 -0
  103. package/lib/core/common/EtsConst.d.ts +65 -0
  104. package/lib/core/common/EtsConst.d.ts.map +1 -0
  105. package/lib/core/common/EtsConst.js +918 -0
  106. package/lib/core/common/ExprUseReplacer.d.ts +18 -0
  107. package/lib/core/common/ExprUseReplacer.d.ts.map +1 -0
  108. package/lib/core/common/ExprUseReplacer.js +88 -0
  109. package/lib/core/common/IRUtils.d.ts +7 -0
  110. package/lib/core/common/IRUtils.d.ts.map +1 -0
  111. package/lib/core/common/IRUtils.js +39 -0
  112. package/lib/core/common/ModelUtils.d.ts +61 -0
  113. package/lib/core/common/ModelUtils.d.ts.map +1 -0
  114. package/lib/core/common/ModelUtils.js +628 -0
  115. package/lib/core/common/RefUseReplacer.d.ts +14 -0
  116. package/lib/core/common/RefUseReplacer.d.ts.map +1 -0
  117. package/lib/core/common/RefUseReplacer.js +50 -0
  118. package/lib/core/common/StmtUseReplacer.d.ts +16 -0
  119. package/lib/core/common/StmtUseReplacer.d.ts.map +1 -0
  120. package/lib/core/common/StmtUseReplacer.js +88 -0
  121. package/lib/core/common/TSConst.d.ts +11 -0
  122. package/lib/core/common/TSConst.d.ts.map +1 -0
  123. package/lib/core/common/TSConst.js +28 -0
  124. package/lib/core/common/TypeInference.d.ts +44 -0
  125. package/lib/core/common/TypeInference.d.ts.map +1 -0
  126. package/lib/core/common/TypeInference.js +519 -0
  127. package/lib/core/common/ValueUtil.d.ts +17 -0
  128. package/lib/core/common/ValueUtil.d.ts.map +1 -0
  129. package/lib/core/common/ValueUtil.js +71 -0
  130. package/lib/core/common/VisibleValue.d.ts +37 -0
  131. package/lib/core/common/VisibleValue.d.ts.map +1 -0
  132. package/lib/core/common/VisibleValue.js +212 -0
  133. package/lib/core/dataflow/DataflowProblem.d.ts +21 -0
  134. package/lib/core/dataflow/DataflowProblem.d.ts.map +1 -0
  135. package/lib/core/dataflow/DataflowProblem.js +33 -0
  136. package/lib/core/dataflow/DataflowResult.d.ts +8 -0
  137. package/lib/core/dataflow/DataflowResult.d.ts.map +1 -0
  138. package/lib/core/dataflow/DataflowResult.js +26 -0
  139. package/lib/core/dataflow/DataflowSolver.d.ts +40 -0
  140. package/lib/core/dataflow/DataflowSolver.d.ts.map +1 -0
  141. package/lib/core/dataflow/DataflowSolver.js +318 -0
  142. package/lib/core/dataflow/Edge.d.ts +16 -0
  143. package/lib/core/dataflow/Edge.d.ts.map +1 -0
  144. package/lib/core/dataflow/Edge.js +40 -0
  145. package/lib/core/dataflow/Fact.d.ts +7 -0
  146. package/lib/core/dataflow/Fact.d.ts.map +1 -0
  147. package/lib/core/dataflow/Fact.js +24 -0
  148. package/lib/core/dataflow/TiantAnalysis.d.ts +37 -0
  149. package/lib/core/dataflow/TiantAnalysis.d.ts.map +1 -0
  150. package/lib/core/dataflow/TiantAnalysis.js +326 -0
  151. package/lib/core/dataflow/UndefinedVariable.d.ts +32 -0
  152. package/lib/core/dataflow/UndefinedVariable.d.ts.map +1 -0
  153. package/lib/core/dataflow/UndefinedVariable.js +235 -0
  154. package/lib/core/dataflow/Util.d.ts +8 -0
  155. package/lib/core/dataflow/Util.d.ts.map +1 -0
  156. package/lib/core/dataflow/Util.js +137 -0
  157. package/lib/core/graph/BasicBlock.d.ts +26 -0
  158. package/lib/core/graph/BasicBlock.d.ts.map +1 -0
  159. package/lib/core/graph/BasicBlock.js +92 -0
  160. package/lib/core/graph/Cfg.d.ts +29 -0
  161. package/lib/core/graph/Cfg.d.ts.map +1 -0
  162. package/lib/core/graph/Cfg.js +154 -0
  163. package/lib/core/graph/DominanceFinder.d.ts +16 -0
  164. package/lib/core/graph/DominanceFinder.d.ts.map +1 -0
  165. package/lib/core/graph/DominanceFinder.js +121 -0
  166. package/lib/core/graph/DominanceTree.d.ts +13 -0
  167. package/lib/core/graph/DominanceTree.d.ts.map +1 -0
  168. package/lib/core/graph/DominanceTree.js +70 -0
  169. package/lib/core/graph/ViewTree.d.ts +115 -0
  170. package/lib/core/graph/ViewTree.d.ts.map +1 -0
  171. package/lib/core/graph/ViewTree.js +16 -0
  172. package/lib/core/graph/builder/ViewTreeBuilder.d.ts +204 -0
  173. package/lib/core/graph/builder/ViewTreeBuilder.d.ts.map +1 -0
  174. package/lib/core/graph/builder/ViewTreeBuilder.js +1046 -0
  175. package/lib/core/model/ArkBody.d.ts +22 -0
  176. package/lib/core/model/ArkBody.d.ts.map +1 -0
  177. package/lib/core/model/ArkBody.js +63 -0
  178. package/lib/core/model/ArkClass.d.ts +110 -0
  179. package/lib/core/model/ArkClass.d.ts.map +1 -0
  180. package/lib/core/model/ArkClass.js +315 -0
  181. package/lib/core/model/ArkExport.d.ts +70 -0
  182. package/lib/core/model/ArkExport.d.ts.map +1 -0
  183. package/lib/core/model/ArkExport.js +143 -0
  184. package/lib/core/model/ArkField.d.ts +60 -0
  185. package/lib/core/model/ArkField.d.ts.map +1 -0
  186. package/lib/core/model/ArkField.js +157 -0
  187. package/lib/core/model/ArkFile.d.ts +62 -0
  188. package/lib/core/model/ArkFile.d.ts.map +1 -0
  189. package/lib/core/model/ArkFile.js +160 -0
  190. package/lib/core/model/ArkImport.d.ts +43 -0
  191. package/lib/core/model/ArkImport.d.ts.map +1 -0
  192. package/lib/core/model/ArkImport.js +109 -0
  193. package/lib/core/model/ArkMethod.d.ts +76 -0
  194. package/lib/core/model/ArkMethod.d.ts.map +1 -0
  195. package/lib/core/model/ArkMethod.js +235 -0
  196. package/lib/core/model/ArkNamespace.d.ts +65 -0
  197. package/lib/core/model/ArkNamespace.d.ts.map +1 -0
  198. package/lib/core/model/ArkNamespace.js +182 -0
  199. package/lib/core/model/ArkSignature.d.ts +98 -0
  200. package/lib/core/model/ArkSignature.d.ts.map +1 -0
  201. package/lib/core/model/ArkSignature.js +281 -0
  202. package/lib/core/model/builder/ArkClassBuilder.d.ts +13 -0
  203. package/lib/core/model/builder/ArkClassBuilder.d.ts.map +1 -0
  204. package/lib/core/model/builder/ArkClassBuilder.js +422 -0
  205. package/lib/core/model/builder/ArkExportBuilder.d.ts +25 -0
  206. package/lib/core/model/builder/ArkExportBuilder.d.ts.map +1 -0
  207. package/lib/core/model/builder/ArkExportBuilder.js +207 -0
  208. package/lib/core/model/builder/ArkFieldBuilder.d.ts +9 -0
  209. package/lib/core/model/builder/ArkFieldBuilder.d.ts.map +1 -0
  210. package/lib/core/model/builder/ArkFieldBuilder.js +189 -0
  211. package/lib/core/model/builder/ArkFileBuilder.d.ts +10 -0
  212. package/lib/core/model/builder/ArkFileBuilder.d.ts.map +1 -0
  213. package/lib/core/model/builder/ArkFileBuilder.js +164 -0
  214. package/lib/core/model/builder/ArkImportBuilder.d.ts +4 -0
  215. package/lib/core/model/builder/ArkImportBuilder.d.ts.map +1 -0
  216. package/lib/core/model/builder/ArkImportBuilder.js +125 -0
  217. package/lib/core/model/builder/ArkMethodBuilder.d.ts +60 -0
  218. package/lib/core/model/builder/ArkMethodBuilder.d.ts.map +1 -0
  219. package/lib/core/model/builder/ArkMethodBuilder.js +419 -0
  220. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts +5 -0
  221. package/lib/core/model/builder/ArkNamespaceBuilder.d.ts.map +1 -0
  222. package/lib/core/model/builder/ArkNamespaceBuilder.js +171 -0
  223. package/lib/core/model/builder/ArkSignatureBuilder.d.ts +9 -0
  224. package/lib/core/model/builder/ArkSignatureBuilder.d.ts.map +1 -0
  225. package/lib/core/model/builder/ArkSignatureBuilder.js +40 -0
  226. package/lib/core/model/builder/builderUtils.d.ts +18 -0
  227. package/lib/core/model/builder/builderUtils.d.ts.map +1 -0
  228. package/lib/core/model/builder/builderUtils.js +449 -0
  229. package/lib/index.d.ts +77 -0
  230. package/lib/index.d.ts.map +1 -0
  231. package/lib/index.js +190 -0
  232. package/lib/save/ArkStream.d.ts +24 -0
  233. package/lib/save/ArkStream.d.ts.map +1 -0
  234. package/lib/save/ArkStream.js +83 -0
  235. package/lib/save/DotPrinter.d.ts +48 -0
  236. package/lib/save/DotPrinter.d.ts.map +1 -0
  237. package/lib/save/DotPrinter.js +229 -0
  238. package/lib/save/GraphPrinter.d.ts +17 -0
  239. package/lib/save/GraphPrinter.d.ts.map +1 -0
  240. package/lib/save/GraphPrinter.js +135 -0
  241. package/lib/save/JsonPrinter.d.ts +28 -0
  242. package/lib/save/JsonPrinter.d.ts.map +1 -0
  243. package/lib/save/JsonPrinter.js +511 -0
  244. package/lib/save/Printer.d.ts +17 -0
  245. package/lib/save/Printer.d.ts.map +1 -0
  246. package/lib/save/Printer.js +27 -0
  247. package/lib/save/PrinterBuilder.d.ts +38 -0
  248. package/lib/save/PrinterBuilder.d.ts.map +1 -0
  249. package/lib/save/PrinterBuilder.js +102 -0
  250. package/lib/save/serializeArkIR.d.ts +3 -0
  251. package/lib/save/serializeArkIR.d.ts.map +1 -0
  252. package/lib/save/serializeArkIR.js +166 -0
  253. package/lib/save/source/SourceBase.d.ts +32 -0
  254. package/lib/save/source/SourceBase.d.ts.map +1 -0
  255. package/lib/save/source/SourceBase.js +93 -0
  256. package/lib/save/source/SourceBody.d.ts +60 -0
  257. package/lib/save/source/SourceBody.d.ts.map +1 -0
  258. package/lib/save/source/SourceBody.js +292 -0
  259. package/lib/save/source/SourceClass.d.ts +27 -0
  260. package/lib/save/source/SourceClass.d.ts.map +1 -0
  261. package/lib/save/source/SourceClass.js +202 -0
  262. package/lib/save/source/SourceField.d.ts +15 -0
  263. package/lib/save/source/SourceField.d.ts.map +1 -0
  264. package/lib/save/source/SourceField.js +68 -0
  265. package/lib/save/source/SourceFilePrinter.d.ts +14 -0
  266. package/lib/save/source/SourceFilePrinter.d.ts.map +1 -0
  267. package/lib/save/source/SourceFilePrinter.js +73 -0
  268. package/lib/save/source/SourceMethod.d.ts +24 -0
  269. package/lib/save/source/SourceMethod.d.ts.map +1 -0
  270. package/lib/save/source/SourceMethod.js +170 -0
  271. package/lib/save/source/SourceModule.d.ts +18 -0
  272. package/lib/save/source/SourceModule.d.ts.map +1 -0
  273. package/lib/save/source/SourceModule.js +120 -0
  274. package/lib/save/source/SourceNamespace.d.ts +13 -0
  275. package/lib/save/source/SourceNamespace.d.ts.map +1 -0
  276. package/lib/save/source/SourceNamespace.js +80 -0
  277. package/lib/save/source/SourceStmt.d.ts +172 -0
  278. package/lib/save/source/SourceStmt.d.ts.map +1 -0
  279. package/lib/save/source/SourceStmt.js +757 -0
  280. package/lib/save/source/SourceTransformer.d.ts +37 -0
  281. package/lib/save/source/SourceTransformer.d.ts.map +1 -0
  282. package/lib/save/source/SourceTransformer.js +338 -0
  283. package/lib/save/source/SourceUtils.d.ts +25 -0
  284. package/lib/save/source/SourceUtils.d.ts.map +1 -0
  285. package/lib/save/source/SourceUtils.js +201 -0
  286. package/lib/transformer/FunctionTransformer.d.ts +3 -0
  287. package/lib/transformer/FunctionTransformer.d.ts.map +1 -0
  288. package/lib/transformer/FunctionTransformer.js +17 -0
  289. package/lib/transformer/SceneTransformer.d.ts +3 -0
  290. package/lib/transformer/SceneTransformer.d.ts.map +1 -0
  291. package/lib/transformer/SceneTransformer.js +17 -0
  292. package/lib/transformer/StaticSingleAssignmentFormer.d.ts +13 -0
  293. package/lib/transformer/StaticSingleAssignmentFormer.d.ts.map +1 -0
  294. package/lib/transformer/StaticSingleAssignmentFormer.js +259 -0
  295. package/lib/transformer/Transformer.d.ts +7 -0
  296. package/lib/transformer/Transformer.d.ts.map +1 -0
  297. package/lib/transformer/Transformer.js +22 -0
  298. package/lib/utils/CfgStructualAnalysis.d.ts +93 -0
  299. package/lib/utils/CfgStructualAnalysis.d.ts.map +1 -0
  300. package/lib/utils/CfgStructualAnalysis.js +955 -0
  301. package/lib/utils/FileUtils.d.ts +18 -0
  302. package/lib/utils/FileUtils.d.ts.map +1 -0
  303. package/lib/utils/FileUtils.js +131 -0
  304. package/lib/utils/callGraphUtils.d.ts +31 -0
  305. package/lib/utils/callGraphUtils.d.ts.map +1 -0
  306. package/lib/utils/callGraphUtils.js +208 -0
  307. package/lib/utils/entryMethodUtils.d.ts +16 -0
  308. package/lib/utils/entryMethodUtils.d.ts.map +1 -0
  309. package/lib/utils/entryMethodUtils.js +139 -0
  310. package/lib/utils/getAllFiles.d.ts +10 -0
  311. package/lib/utils/getAllFiles.d.ts.map +1 -0
  312. package/lib/utils/getAllFiles.js +91 -0
  313. package/lib/utils/json5parser.d.ts +7 -0
  314. package/lib/utils/json5parser.d.ts.map +1 -0
  315. package/lib/utils/json5parser.js +146 -0
  316. package/lib/utils/logger.d.ts +19 -0
  317. package/lib/utils/logger.d.ts.map +1 -0
  318. package/lib/utils/logger.js +90 -0
  319. package/lib/utils/pathTransfer.d.ts +2 -0
  320. package/lib/utils/pathTransfer.d.ts.map +1 -0
  321. package/lib/utils/pathTransfer.js +25 -0
  322. package/package.json +29 -0
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
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
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.Scope = exports.VisibleValue = void 0;
41
+ const logger_1 = __importStar(require("../../utils/logger"));
42
+ const Local_1 = require("../base/Local");
43
+ const Ref_1 = require("../base/Ref");
44
+ const Stmt_1 = require("../base/Stmt");
45
+ const Type_1 = require("../base/Type");
46
+ const BasicBlock_1 = require("../graph/BasicBlock");
47
+ const ArkClass_1 = require("../model/ArkClass");
48
+ const ArkFile_1 = require("../model/ArkFile");
49
+ const ArkMethod_1 = require("../model/ArkMethod");
50
+ const ArkNamespace_1 = require("../model/ArkNamespace");
51
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'VisibleValue');
52
+ class VisibleValue {
53
+ constructor() {
54
+ // TODO:填充全局变量
55
+ this.currScope = new Scope([], 0);
56
+ this.scopeChain = [this.currScope];
57
+ this.currVisibleValues = [...this.currScope.values];
58
+ }
59
+ /** get values that is visible in curr scope */
60
+ getCurrVisibleValues() {
61
+ return this.currVisibleValues;
62
+ }
63
+ getScopeChain() {
64
+ return this.scopeChain;
65
+ }
66
+ /** udpate visible values after entered a scope, only support step by step */
67
+ updateIntoScope(model) {
68
+ let name = '';
69
+ if (model instanceof BasicBlock_1.BasicBlock) {
70
+ name = 'block: ' + model.toString();
71
+ }
72
+ else {
73
+ name = model.getName();
74
+ }
75
+ logger.info('---- into scope:{', name, '}');
76
+ // get values in this scope
77
+ let values = [];
78
+ if (model instanceof ArkFile_1.ArkFile || model instanceof ArkNamespace_1.ArkNamespace) {
79
+ values = this.getVisibleValuesIntoFileOrNameSpace(model);
80
+ }
81
+ else if (model instanceof ArkClass_1.ArkClass) {
82
+ values = this.getVisibleValuesIntoClass(model);
83
+ }
84
+ else if (model instanceof ArkMethod_1.ArkMethod) {
85
+ values = this.getVisibleValuesIntoMethod(model);
86
+ }
87
+ else if (model instanceof BasicBlock_1.BasicBlock) {
88
+ values = this.getVisibleValuesIntoBasicBlock(model);
89
+ }
90
+ // handle scope chain
91
+ const targetDepth = this.getTargetDepth(model);
92
+ this.addScope(values, targetDepth, model);
93
+ }
94
+ /** udpate visible values after left a scope, only support step by step */
95
+ updateOutScope() {
96
+ const currModel = this.currScope.arkModel;
97
+ let name = '';
98
+ if (currModel instanceof BasicBlock_1.BasicBlock) {
99
+ name = 'block: ' + currModel.toString();
100
+ }
101
+ else {
102
+ name = currModel.getName();
103
+ }
104
+ logger.info('---- out scope:{', name, '}');
105
+ let targetDepth = this.currScope.depth;
106
+ if (currModel instanceof BasicBlock_1.BasicBlock) {
107
+ const successorsCnt = currModel.getSuccessors().length;
108
+ // if successorsCnt <= 0, unchange
109
+ if (successorsCnt > 1) {
110
+ targetDepth += 1; // goto inner scope
111
+ }
112
+ }
113
+ this.deleteScope(targetDepth);
114
+ }
115
+ /** clear up previous scope */
116
+ deleteScope(targetDepth) {
117
+ const prevDepth = this.currScope.depth;
118
+ if (targetDepth > prevDepth) {
119
+ return;
120
+ }
121
+ let popScopeValuesCnt = 0;
122
+ let popScopeCnt = 0;
123
+ for (let i = this.scopeChain.length - 1; i >= 0; i--) {
124
+ if (this.scopeChain[i].depth < targetDepth) {
125
+ break;
126
+ }
127
+ popScopeCnt += 1;
128
+ popScopeValuesCnt += this.scopeChain[i].values.length;
129
+ }
130
+ this.scopeChain.splice(this.scopeChain.length - popScopeCnt, popScopeCnt)[0]; // popScopeCnt >= 1
131
+ this.currScope = this.scopeChain[this.scopeChain.length - 1];
132
+ const totalValuesCnt = this.currVisibleValues.length;
133
+ this.currVisibleValues.splice(totalValuesCnt - popScopeValuesCnt, popScopeValuesCnt);
134
+ }
135
+ /** add this scope to scope chain and update visible values */
136
+ addScope(values, targetDepth, model) {
137
+ const newScope = new Scope(values, targetDepth, model);
138
+ this.currScope = newScope;
139
+ this.scopeChain.push(this.currScope);
140
+ this.currVisibleValues.push(...this.currScope.values);
141
+ }
142
+ // TODO:构造嵌套关系树
143
+ getTargetDepth(model) {
144
+ const prevDepth = this.currScope.depth;
145
+ const prevModel = this.currScope.arkModel;
146
+ let targetDepth = prevDepth + 1;
147
+ if (model instanceof BasicBlock_1.BasicBlock) {
148
+ const predecessorsCnt = model.getPredecessors().length;
149
+ if (predecessorsCnt <= 1) {
150
+ targetDepth = prevDepth + 1;
151
+ }
152
+ else {
153
+ targetDepth = prevDepth;
154
+ }
155
+ }
156
+ else if ((model instanceof ArkFile_1.ArkFile) && (prevModel instanceof ArkFile_1.ArkFile)) {
157
+ targetDepth = prevDepth;
158
+ }
159
+ else if ((model instanceof ArkNamespace_1.ArkNamespace) && (prevModel instanceof ArkNamespace_1.ArkNamespace)) {
160
+ targetDepth = prevDepth;
161
+ }
162
+ else if ((model instanceof ArkClass_1.ArkClass) && (prevModel instanceof ArkClass_1.ArkClass)) {
163
+ targetDepth = prevDepth;
164
+ }
165
+ else if ((model instanceof ArkMethod_1.ArkMethod) && (prevModel instanceof ArkMethod_1.ArkMethod)) {
166
+ targetDepth = prevDepth;
167
+ }
168
+ return targetDepth;
169
+ }
170
+ getVisibleValuesIntoFileOrNameSpace(fileOrNameSpace) {
171
+ let values = [];
172
+ return values;
173
+ }
174
+ getVisibleValuesIntoClass(cls) {
175
+ const values = [];
176
+ const fields = cls.getFields();
177
+ const classSignature = cls.getSignature();
178
+ for (const field of fields) {
179
+ if (field.getModifiers().has('StaticKeyword')) {
180
+ const staticFieldRef = new Ref_1.ArkStaticFieldRef(field.getSignature());
181
+ values.push(staticFieldRef);
182
+ }
183
+ else {
184
+ const instanceFieldRef = new Ref_1.ArkInstanceFieldRef(new Local_1.Local('this', new Type_1.ClassType(classSignature)), field.getSignature());
185
+ values.push(instanceFieldRef);
186
+ }
187
+ }
188
+ return values;
189
+ }
190
+ getVisibleValuesIntoMethod(method) {
191
+ let visibleValues = [];
192
+ return visibleValues;
193
+ }
194
+ getVisibleValuesIntoBasicBlock(basiceBlock) {
195
+ const visibleValues = [];
196
+ for (const stmt of basiceBlock.getStmts()) {
197
+ if (stmt instanceof Stmt_1.ArkAssignStmt) {
198
+ visibleValues.push(stmt.getLeftOp());
199
+ }
200
+ }
201
+ return visibleValues;
202
+ }
203
+ }
204
+ exports.VisibleValue = VisibleValue;
205
+ class Scope {
206
+ constructor(values, depth = -1, arkModel = null) {
207
+ this.values = values;
208
+ this.depth = depth;
209
+ this.arkModel = arkModel;
210
+ }
211
+ }
212
+ exports.Scope = Scope;
@@ -0,0 +1,21 @@
1
+ import { Stmt } from '../base/Stmt';
2
+ import { ArkMethod } from '../model/ArkMethod';
3
+ export declare abstract class DataflowProblem<D> {
4
+ transferEdge(srcStmt: Stmt, tgtStmt: Stmt): void;
5
+ /**
6
+ * Transfer the outFact of srcStmt to the inFact of tgtStmt
7
+ *
8
+ * Return true if keeping progagation (i.e., tgtStmt will be added to the WorkList for further analysis)
9
+ */
10
+ abstract getNormalFlowFunction(srcStmt: Stmt, tgtStmt: Stmt): FlowFunction<D>;
11
+ abstract getCallFlowFunction(srcStmt: Stmt, method: ArkMethod): FlowFunction<D>;
12
+ abstract getExitToReturnFlowFunction(srcStmt: Stmt, tgtStmt: Stmt, callStmt: Stmt): FlowFunction<D>;
13
+ abstract getCallToReturnFlowFunction(srcStmt: Stmt, tgtStmt: Stmt): FlowFunction<D>;
14
+ abstract createZeroValue(): D;
15
+ abstract getEntryPoint(): Stmt;
16
+ abstract getEntryMethod(): ArkMethod;
17
+ }
18
+ export interface FlowFunction<D> {
19
+ getDataFacts(d: D): Set<D>;
20
+ }
21
+ //# sourceMappingURL=DataflowProblem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataflowProblem.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/DataflowProblem.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,8BAAsB,eAAe,CAAC,CAAC;IAG5B,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI;IAchD;;;;OAIG;IAWH,QAAQ,CAAC,qBAAqB,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,GAAI,YAAY,CAAC,CAAC,CAAC;IAE5E,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,SAAS,GAAI,YAAY,CAAC,CAAC,CAAC;IAE9E,QAAQ,CAAC,2BAA2B,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,EAAE,QAAQ,EAAC,IAAI,GAAI,YAAY,CAAC,CAAC,CAAC;IAEjG,QAAQ,CAAC,2BAA2B,CAAC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,IAAI,GAAI,YAAY,CAAC,CAAC,CAAC;IAElF,QAAQ,CAAC,eAAe,IAAK,CAAC;IAE9B,QAAQ,CAAC,aAAa,IAAK,IAAI;IAE/B,QAAQ,CAAC,cAAc,IAAK,SAAS;CACxC;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC3B,YAAY,CAAC,CAAC,EAAC,CAAC,GAAI,GAAG,CAAC,CAAC,CAAC,CAAC;CAC9B"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.DataflowProblem = void 0;
18
+ const Edge_1 = require("./Edge");
19
+ class DataflowProblem {
20
+ transferEdge(srcStmt, tgtStmt) {
21
+ let edgeKind = Edge_1.Edge.getKind(srcStmt, tgtStmt);
22
+ if (0 == edgeKind) {
23
+ //normal
24
+ }
25
+ else if (1 == edgeKind) { //Call-Edge
26
+ }
27
+ else if (2 == edgeKind) { //Return-Edge
28
+ }
29
+ else if (3 == edgeKind) { //Call-To-Return-Edge
30
+ }
31
+ }
32
+ }
33
+ exports.DataflowProblem = DataflowProblem;
@@ -0,0 +1,8 @@
1
+ import { Stmt } from '../base/Stmt';
2
+ import { Fact } from './Fact';
3
+ export declare class DataflowResult {
4
+ stmt2InFacts: Map<Stmt, Fact>;
5
+ stmt2OutFacts: Map<Stmt, Fact>;
6
+ globalFacts: Set<Fact>;
7
+ }
8
+ //# sourceMappingURL=DataflowResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataflowResult.d.ts","sourceRoot":"","sources":["../../../src/core/dataflow/DataflowResult.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,qBAAa,cAAc;IACvB,YAAY,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAyB;IACtD,aAAa,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAyB;IAGvD,WAAW,EAAE,GAAG,CAAC,IAAI,CAAC,CAAmB;CAC5C"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.DataflowResult = void 0;
18
+ class DataflowResult {
19
+ constructor() {
20
+ this.stmt2InFacts = new Map();
21
+ this.stmt2OutFacts = new Map();
22
+ //should we specifically keep global facts or just embedding them into the two maps above
23
+ this.globalFacts = new Set();
24
+ }
25
+ }
26
+ exports.DataflowResult = DataflowResult;
@@ -0,0 +1,40 @@
1
+ import { Scene } from '../../Scene';
2
+ import { ArkInvokeStmt, Stmt } from '../base/Stmt';
3
+ import { ArkMethod } from '../model/ArkMethod';
4
+ import { DataflowProblem } from './DataflowProblem';
5
+ import { PathEdge } from './Edge';
6
+ export declare abstract class DataflowSolver<D> {
7
+ private problem;
8
+ private workList;
9
+ private pathEdgeSet;
10
+ private zeroFact;
11
+ private inComing;
12
+ private endSummary;
13
+ private summaryEdge;
14
+ private scene;
15
+ private CHA;
16
+ private stmtNexts;
17
+ private laterEdges;
18
+ constructor(problem: DataflowProblem<D>, scene: Scene);
19
+ solve(): void;
20
+ protected computeResult(stmt: Stmt, d: D): boolean;
21
+ protected getChildren(stmt: Stmt): Stmt[];
22
+ protected init(): void;
23
+ private buildStmtMapInClass;
24
+ private buildStmtMap;
25
+ private setCfg4AllStmt;
26
+ protected getAllCalleeMethods(callNode: ArkInvokeStmt): Set<ArkMethod>;
27
+ protected getReturnSiteOfCall(call: Stmt): Stmt;
28
+ protected getStartOfCallerMethod(call: Stmt): Stmt;
29
+ protected pathEdgeSetHasEdge(edge: PathEdge<D>): boolean;
30
+ protected propagate(edge: PathEdge<D>): void;
31
+ protected processExitNode(edge: PathEdge<D>): void;
32
+ protected processNormalNode(edge: PathEdge<D>): void;
33
+ protected processCallNode(edge: PathEdge<D>): void;
34
+ protected doSolve(): void;
35
+ protected isCallStatement(stmt: Stmt): boolean;
36
+ protected isExitStatement(stmt: Stmt): boolean;
37
+ getPathEdgeSet(): Set<PathEdge<D>>;
38
+ }
39
+ export declare function factEqual<D>(fact1: D, fact2: D): boolean;
40
+ //# sourceMappingURL=DataflowSolver.d.ts.map
@@ -0,0 +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;AAGpC,OAAO,EAAE,aAAa,EAAoC,IAAI,EAAE,MAAM,cAAc,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAgB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAiB,MAAM,QAAQ,CAAC;AAmBjD,8BAAsB,cAAc,CAAC,CAAC;IAElC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,QAAQ,CAAI;IACpB,OAAO,CAAC,QAAQ,CAA+C;IAC/D,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,UAAU,CAA+B;gBAErC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK;IAa9C,KAAK;IAKZ,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO;IASlD,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE;IAIzC,SAAS,CAAC,IAAI;IAiBd,OAAO,CAAC,mBAAmB;IAyB3B,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,cAAc;IAQtB,SAAS,CAAC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,GAAG,GAAG,CAAC,SAAS,CAAC;IActE,SAAS,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAI/C,SAAS,CAAC,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAMlD,SAAS,CAAC,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAU9C,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAcrC,SAAS,CAAC,eAAe,CAAC,IAAI,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;IA+D3C,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;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAKxD"}
@@ -0,0 +1,318 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.factEqual = exports.DataflowSolver = void 0;
18
+ const Expr_1 = require("../base/Expr");
19
+ const Ref_1 = require("../base/Ref");
20
+ const Stmt_1 = require("../base/Stmt");
21
+ const Edge_1 = require("./Edge");
22
+ const CallGraph_1 = require("../../callgraph/model/CallGraph");
23
+ const CallGraphBuilder_1 = require("../../callgraph/model/builder/CallGraphBuilder");
24
+ const ClassHierarchyAnalysis_1 = require("../../callgraph/algorithm/ClassHierarchyAnalysis");
25
+ const entryMethodUtils_1 = require("../../utils/entryMethodUtils");
26
+ const Util_1 = require("./Util");
27
+ class DataflowSolver {
28
+ constructor(problem, scene) {
29
+ this.laterEdges = new Set();
30
+ this.problem = problem;
31
+ this.scene = scene;
32
+ scene.inferTypes();
33
+ this.zeroFact = problem.createZeroValue();
34
+ this.workList = new Array();
35
+ this.pathEdgeSet = new Set();
36
+ this.inComing = new Map();
37
+ this.endSummary = new Map();
38
+ this.summaryEdge = new Set();
39
+ this.stmtNexts = new Map();
40
+ }
41
+ solve() {
42
+ this.init();
43
+ this.doSolve();
44
+ }
45
+ computeResult(stmt, d) {
46
+ for (let pathEdge of this.pathEdgeSet) {
47
+ if (pathEdge.edgeEnd.node == stmt && pathEdge.edgeEnd.fact == d) {
48
+ return true;
49
+ }
50
+ }
51
+ return false;
52
+ }
53
+ getChildren(stmt) {
54
+ return Array.from(this.stmtNexts.get(stmt) || []);
55
+ }
56
+ init() {
57
+ let edgePoint = new Edge_1.PathEdgePoint(this.problem.getEntryPoint(), this.zeroFact);
58
+ let edge = new Edge_1.PathEdge(edgePoint, edgePoint);
59
+ this.workList.push(edge);
60
+ this.pathEdgeSet.add(edge);
61
+ // build CHA
62
+ 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
+ this.CHA = new ClassHierarchyAnalysis_1.ClassHierarchyAnalysis(this.scene, cg);
66
+ // this.CHA = this.scene.makeCallGraphCHA([this.problem.getEntryMethod().getSignature()]) as ClassHierarchyAnalysisAlgorithm;
67
+ this.buildStmtMap();
68
+ this.setCfg4AllStmt();
69
+ return;
70
+ }
71
+ buildStmtMapInClass(clas) {
72
+ for (const method of clas.getMethods(true)) {
73
+ const cfg = method.getCfg();
74
+ const blocks = [];
75
+ if (cfg) {
76
+ blocks.push(...cfg.getBlocks());
77
+ }
78
+ for (const block of blocks) {
79
+ const stmts = block.getStmts();
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
+ }
93
+ }
94
+ }
95
+ }
96
+ buildStmtMap() {
97
+ for (const classes of this.scene.getClassMap()) {
98
+ for (const cls of classes[1]) {
99
+ this.buildStmtMapInClass(cls);
100
+ }
101
+ }
102
+ }
103
+ setCfg4AllStmt() {
104
+ for (const cls of this.scene.getClasses()) {
105
+ for (const mtd of cls.getMethods(true)) {
106
+ (0, entryMethodUtils_1.addCfg2Stmt)(mtd);
107
+ }
108
+ }
109
+ }
110
+ getAllCalleeMethods(callNode) {
111
+ // const methodSignatures = this.CHA.resolveCall(this.problem.getEntryMethod().getSignature(), callNode);
112
+ const callSites = this.CHA.resolveCall(this.CHA.getCallGraph().getCallGraphNodeByMethod(this.problem.getEntryMethod().getSignature()).getID(), callNode);
113
+ const methods = new Set();
114
+ for (const callSite of callSites) {
115
+ const method = this.scene.getMethod(this.CHA.getCallGraph().getMethodByFuncID(callSite.calleeFuncID));
116
+ if (method) {
117
+ methods.add(method);
118
+ }
119
+ }
120
+ return methods;
121
+ }
122
+ getReturnSiteOfCall(call) {
123
+ return [...this.stmtNexts.get(call)][0];
124
+ }
125
+ getStartOfCallerMethod(call) {
126
+ const cfg = call.getCfg();
127
+ const paraNum = cfg.getDeclaringMethod().getParameters().length;
128
+ return [...cfg.getBlocks()][0].getStmts()[paraNum];
129
+ }
130
+ pathEdgeSetHasEdge(edge) {
131
+ for (const path of this.pathEdgeSet) {
132
+ if (path.edgeEnd.node == edge.edgeEnd.node && factEqual(path.edgeEnd.fact, edge.edgeEnd.fact) &&
133
+ path.edgeStart.node == edge.edgeStart.node && factEqual(path.edgeStart.fact, edge.edgeStart.fact)) {
134
+ return true;
135
+ }
136
+ }
137
+ return false;
138
+ }
139
+ propagate(edge) {
140
+ if (!this.pathEdgeSetHasEdge(edge)) {
141
+ let index = this.workList.length;
142
+ for (let i = 0; i < this.workList.length; i++) {
143
+ if (this.laterEdges.has(this.workList[i])) {
144
+ index = i;
145
+ break;
146
+ }
147
+ }
148
+ this.workList.splice(index, 0, edge);
149
+ this.pathEdgeSet.add(edge);
150
+ }
151
+ }
152
+ processExitNode(edge) {
153
+ var _a;
154
+ let startEdgePoint = edge.edgeStart;
155
+ let exitEdgePoint = edge.edgeEnd;
156
+ const summary = this.endSummary.get(startEdgePoint);
157
+ if (summary == undefined) {
158
+ this.endSummary.set(startEdgePoint, new Set([exitEdgePoint]));
159
+ }
160
+ else {
161
+ summary.add(exitEdgePoint);
162
+ }
163
+ const callEdgePoints = this.inComing.get(startEdgePoint);
164
+ if (callEdgePoints == undefined) {
165
+ if (startEdgePoint.node.getCfg().getDeclaringMethod() == this.problem.getEntryMethod()) {
166
+ return;
167
+ }
168
+ throw new Error('incoming does not have ' + ((_a = startEdgePoint.node.getCfg()) === null || _a === void 0 ? void 0 : _a.getDeclaringMethod().toString()));
169
+ }
170
+ for (let callEdgePoint of callEdgePoints) {
171
+ let returnSite = this.getReturnSiteOfCall(callEdgePoint.node);
172
+ let returnFlowFunc = this.problem.getExitToReturnFlowFunction(exitEdgePoint.node, returnSite, callEdgePoint.node);
173
+ for (let fact of returnFlowFunc.getDataFacts(exitEdgePoint.fact)) {
174
+ let returnSitePoint = new Edge_1.PathEdgePoint(returnSite, fact);
175
+ let cacheEdge = new Edge_1.PathEdge(callEdgePoint, returnSitePoint);
176
+ let summaryEdgeHasCacheEdge = false;
177
+ for (const sEdge of this.summaryEdge) {
178
+ if (sEdge.edgeStart == callEdgePoint && sEdge.edgeEnd.node == returnSite && sEdge.edgeEnd.fact == fact) {
179
+ summaryEdgeHasCacheEdge = true;
180
+ break;
181
+ }
182
+ }
183
+ if (!summaryEdgeHasCacheEdge) {
184
+ this.summaryEdge.add(cacheEdge);
185
+ let startOfCaller = this.getStartOfCallerMethod(callEdgePoint.node);
186
+ for (let pathEdge of this.pathEdgeSet) {
187
+ if (pathEdge.edgeStart.node == startOfCaller && pathEdge.edgeEnd == callEdgePoint) {
188
+ this.propagate(new Edge_1.PathEdge(pathEdge.edgeStart, returnSitePoint));
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ processNormalNode(edge) {
196
+ let start = edge.edgeStart;
197
+ let end = edge.edgeEnd;
198
+ let stmts = [...this.getChildren(end.node)].reverse();
199
+ for (let stmt of stmts) {
200
+ let flowFunction = this.problem.getNormalFlowFunction(end.node, stmt);
201
+ let set = flowFunction.getDataFacts(end.fact);
202
+ for (let fact of set) {
203
+ let edgePoint = new Edge_1.PathEdgePoint(stmt, fact);
204
+ const edge = new Edge_1.PathEdge(start, edgePoint);
205
+ this.propagate(edge);
206
+ this.laterEdges.add(edge);
207
+ }
208
+ }
209
+ }
210
+ processCallNode(edge) {
211
+ let start = edge.edgeStart;
212
+ let callEdgePoint = edge.edgeEnd;
213
+ const invokeStmt = callEdgePoint.node;
214
+ let callees;
215
+ if (this.scene.getFilesMap().get(invokeStmt.getInvokeExpr().getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature().toString())) {
216
+ callees = this.getAllCalleeMethods(callEdgePoint.node);
217
+ }
218
+ else {
219
+ callees = new Set([(0, Util_1.getRecallMethodInParam)(invokeStmt)]);
220
+ }
221
+ let callNode = edge.edgeEnd.node;
222
+ let returnSite = this.getReturnSiteOfCall(callEdgePoint.node);
223
+ for (let callee of callees) {
224
+ let callFlowFunc = this.problem.getCallFlowFunction(callNode, callee);
225
+ if (!callee.getCfg()) {
226
+ continue;
227
+ }
228
+ let firstStmt = [...callee.getCfg().getBlocks()][0].getStmts()[callee.getParameters().length];
229
+ let facts = callFlowFunc.getDataFacts(callEdgePoint.fact);
230
+ for (let fact of facts) {
231
+ // method start loop path edge
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
+ }
260
+ }
261
+ }
262
+ let callToReturnflowFunc = this.problem.getCallToReturnFlowFunction(edge.edgeEnd.node, returnSite);
263
+ let set = callToReturnflowFunc.getDataFacts(callEdgePoint.fact);
264
+ for (let fact of set) {
265
+ this.propagate(new Edge_1.PathEdge(start, new Edge_1.PathEdgePoint(returnSite, fact)));
266
+ }
267
+ for (let cacheEdge of this.summaryEdge) {
268
+ if (cacheEdge.edgeStart == edge.edgeEnd && cacheEdge.edgeEnd.node == returnSite) {
269
+ this.propagate(new Edge_1.PathEdge(start, cacheEdge.edgeEnd));
270
+ }
271
+ }
272
+ }
273
+ doSolve() {
274
+ while (this.workList.length != 0) {
275
+ let pathEdge = this.workList.shift();
276
+ if (this.laterEdges.has(pathEdge)) {
277
+ this.laterEdges.delete(pathEdge);
278
+ }
279
+ let targetStmt = pathEdge.edgeEnd.node;
280
+ if (this.isCallStatement(targetStmt)) {
281
+ this.processCallNode(pathEdge);
282
+ }
283
+ else if (this.isExitStatement(targetStmt)) {
284
+ this.processExitNode(pathEdge);
285
+ }
286
+ else {
287
+ this.processNormalNode(pathEdge);
288
+ }
289
+ }
290
+ }
291
+ isCallStatement(stmt) {
292
+ for (const expr of stmt.getExprs()) {
293
+ if (expr instanceof Expr_1.AbstractInvokeExpr) {
294
+ if (this.scene.getFilesMap().get(expr.getMethodSignature().getDeclaringClassSignature().getDeclaringFileSignature().toString())) {
295
+ return true;
296
+ }
297
+ if (stmt instanceof Stmt_1.ArkInvokeStmt && (0, Util_1.getRecallMethodInParam)(stmt)) {
298
+ return true;
299
+ }
300
+ }
301
+ }
302
+ return false;
303
+ }
304
+ isExitStatement(stmt) {
305
+ return stmt instanceof Stmt_1.ArkReturnStmt || stmt instanceof Stmt_1.ArkReturnVoidStmt;
306
+ }
307
+ getPathEdgeSet() {
308
+ return this.pathEdgeSet;
309
+ }
310
+ }
311
+ 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;