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,64 @@
1
+ import { Scene } from '../../Scene';
2
+ import { Value } from '../../core/base/Value';
3
+ import { NodeID } from '../model/BaseGraph';
4
+ import { CallGraph, CallSite, FuncID } from '../model/CallGraph';
5
+ import { AbstractAnalysis } from '../algorithm/AbstractAnalysis';
6
+ import { Type } from '../../core/base/Type';
7
+ import { Stmt } from '../../core/base/Stmt';
8
+ import { Pag } from './Pag';
9
+ import { PointerAnalysisConfig } from './PointerAnalysisConfig';
10
+ export declare class PointerAnalysis extends AbstractAnalysis {
11
+ private pag;
12
+ private pagBuilder;
13
+ private ptd;
14
+ private entries;
15
+ private worklist;
16
+ private ptaStat;
17
+ private typeDiffMap;
18
+ private config;
19
+ constructor(p: Pag, cg: CallGraph, s: Scene, config: PointerAnalysisConfig);
20
+ static pointerAnalysisForWholeProject(projectScene: Scene, config?: PointerAnalysisConfig): PointerAnalysis;
21
+ protected init(): void;
22
+ start(): void;
23
+ private postProcess;
24
+ protected preProcessMethod(funcID: FuncID): CallSite[];
25
+ setEntries(fIds: FuncID[]): void;
26
+ private solveConstraint;
27
+ /**
28
+ * get newly added Address Edge, and add them to initial WorkList
29
+ */
30
+ private initWorklist;
31
+ private solveWorklist;
32
+ private processNode;
33
+ private handleCopy;
34
+ private handleLoadWrite;
35
+ private handleFieldInEdges;
36
+ private handleFieldOutEdges;
37
+ /**
38
+ * If current node is a base of a called method, pointer in this node will be transfered into `this` Local in method
39
+ */
40
+ private handleThis;
41
+ private handlePt;
42
+ private propagate;
43
+ /**
44
+ * 1. 记录被更新的节点(记录cid, nodeid)
45
+ * 2. ( PAGLocalNode记录callsite(cid, value唯一)),通过1种的nodeID查询Node,拿到Callsite
46
+ * 3. 在addDynamicCall里对传入指针过滤(已处理指针和未处理指针)
47
+ */
48
+ private onTheFlyDynamicCallSolve;
49
+ private addToReanalyze;
50
+ /**
51
+ * compare interface
52
+ */
53
+ noAlias(leftValue: Value, rightValue: Value): boolean;
54
+ mayAlias(leftValue: Value, rightValue: Value): boolean;
55
+ getRelatedNodes(value: Value): Set<Value>;
56
+ private detectTypeDiff;
57
+ getTypeDiffMap(): Map<Value, Set<Type>>;
58
+ protected resolveCall(sourceMethod: NodeID, invokeStmt: Stmt): CallSite[];
59
+ getUnhandledFuncs(): FuncID[];
60
+ getHandledFuncs(): FuncID[];
61
+ getPTAConfig(): PointerAnalysisConfig;
62
+ private dumpUnhandledFunctions;
63
+ }
64
+ //# sourceMappingURL=PointerAnalysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PointerAnalysis.d.ts","sourceRoot":"","sources":["../../../src/callgraph/pointerAnalysis/PointerAnalysis.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAiB,QAAQ,EAAe,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAa,IAAI,EAAe,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAI5C,OAAO,EAAE,GAAG,EAAgF,MAAM,OAAO,CAAC;AAE1G,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,qBAAa,eAAgB,SAAQ,gBAAgB;IACjD,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,GAAG,CAA6C;IACxD,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,QAAQ,CAAY;IAE5B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,MAAM,CAAwB;gBAE1B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,qBAAqB;IAW1E,MAAM,CAAC,8BAA8B,CAAC,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,eAAe;IAuB3G,SAAS,CAAC,IAAI;IAYP,KAAK;IAMZ,OAAO,CAAC,WAAW;IAgBnB,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE;IAK/C,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE;IAIhC,OAAO,CAAC,eAAe;IAoBvB;;OAEG;IACH,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,eAAe;IA+BvB,OAAO,CAAC,kBAAkB;IA4B1B,OAAO,CAAC,mBAAmB;IA0B3B;;OAEG;IACH,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,QAAQ;IAWhB,OAAO,CAAC,SAAS;IAoBjB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAmChC,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACI,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,GAAG,OAAO;IAkCrD,QAAQ,CAAC,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,GAAG,OAAO;IAItD,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IAqDhD,OAAO,CAAC,cAAc;IA2Cf,cAAc,IAAI,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAI9C,SAAS,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,QAAQ,EAAE;IAIlE,iBAAiB,IAAI,MAAM,EAAE;IAI7B,eAAe,IAAI,MAAM,EAAE;IAI3B,YAAY,IAAI,qBAAqB;IAI5C,OAAO,CAAC,sBAAsB;CA+BjC"}
@@ -0,0 +1,502 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.PointerAnalysis = void 0;
44
+ const path_1 = __importDefault(require("path"));
45
+ const fs = __importStar(require("fs"));
46
+ const CallGraph_1 = require("../model/CallGraph");
47
+ const AbstractAnalysis_1 = require("../algorithm/AbstractAnalysis");
48
+ const Type_1 = require("../../core/base/Type");
49
+ const CallGraphBuilder_1 = require("../model/builder/CallGraphBuilder");
50
+ const logger_1 = __importStar(require("../../utils/logger"));
51
+ const DummyMainCreater_1 = require("../../core/common/DummyMainCreater");
52
+ const Statistics_1 = require("../common/Statistics");
53
+ const Pag_1 = require("./Pag");
54
+ const PagBuilder_1 = require("./PagBuilder");
55
+ const PointerAnalysisConfig_1 = require("./PointerAnalysisConfig");
56
+ const PtsDS_1 = require("./PtsDS");
57
+ const logger = logger_1.default.getLogger(logger_1.LOG_MODULE_TYPE.ARKANALYZER, 'PTA');
58
+ class PointerAnalysis extends AbstractAnalysis_1.AbstractAnalysis {
59
+ constructor(p, cg, s, config) {
60
+ super(s);
61
+ this.pag = p;
62
+ this.cg = cg;
63
+ this.ptd = new PtsDS_1.DiffPTData(PtsDS_1.PtsSet);
64
+ this.pagBuilder = new PagBuilder_1.PagBuilder(this.pag, this.cg, s, config.kLimit);
65
+ this.cgBuilder = new CallGraphBuilder_1.CallGraphBuilder(this.cg, s);
66
+ this.ptaStat = new Statistics_1.PTAStat(this);
67
+ this.config = config;
68
+ }
69
+ static pointerAnalysisForWholeProject(projectScene, config) {
70
+ let cg = new CallGraph_1.CallGraph(projectScene);
71
+ let cgBuilder = new CallGraphBuilder_1.CallGraphBuilder(cg, projectScene);
72
+ cgBuilder.buildDirectCallGraphForScene();
73
+ let pag = new Pag_1.Pag();
74
+ if (!config) {
75
+ config = new PointerAnalysisConfig_1.PointerAnalysisConfig(1, "out/", false, false);
76
+ }
77
+ const dummyMainCreator = new DummyMainCreater_1.DummyMainCreater(projectScene);
78
+ dummyMainCreator.createDummyMain();
79
+ const dummyMainMethod = dummyMainCreator.getDummyMain();
80
+ cgBuilder.buildDirectCallGraph([dummyMainMethod]);
81
+ let dummyMainMethodID = cg.getCallGraphNodeByMethod(dummyMainMethod.getSignature()).getID();
82
+ cg.setDummyMainFuncID(dummyMainMethodID);
83
+ let pta = new PointerAnalysis(pag, cg, projectScene, config);
84
+ pta.setEntries([dummyMainMethodID]);
85
+ pta.start();
86
+ return pta;
87
+ }
88
+ init() {
89
+ logger.warn(`========== Init Pointer Analysis ==========`);
90
+ // start statistics
91
+ this.ptaStat.startStat();
92
+ // build funcPag with entries
93
+ this.pagBuilder.buildForEntries(this.entries);
94
+ if (this.config.dotDump) {
95
+ this.pag.dump(path_1.default.join(this.config.outputDirectory, 'ptaInit_pag.dot'));
96
+ this.cg.dump(path_1.default.join(this.config.outputDirectory, 'cg_init.dot'));
97
+ }
98
+ }
99
+ start() {
100
+ this.init();
101
+ this.solveConstraint();
102
+ this.postProcess();
103
+ }
104
+ postProcess() {
105
+ this.ptaStat.endStat();
106
+ this.pagBuilder.doStat();
107
+ this.cg.printStat();
108
+ this.pagBuilder.printStat();
109
+ this.ptaStat.printStat();
110
+ if (this.config.dotDump) {
111
+ this.pag.dump(path_1.default.join(this.config.outputDirectory, 'ptaEnd_pag.dot'));
112
+ this.cg.dump(path_1.default.join(this.config.outputDirectory, 'cgEnd.dot'));
113
+ }
114
+ if (this.config.unhandledFuncDump) {
115
+ this.dumpUnhandledFunctions();
116
+ }
117
+ }
118
+ preProcessMethod(funcID) {
119
+ // do nothing
120
+ return [];
121
+ }
122
+ setEntries(fIds) {
123
+ this.entries = fIds;
124
+ }
125
+ solveConstraint() {
126
+ this.worklist = [];
127
+ logger.warn(`========== Pointer Analysis Start ==========`);
128
+ this.initWorklist();
129
+ let reanalyzer = true;
130
+ while (reanalyzer) {
131
+ this.ptaStat.iterTimes++;
132
+ logger.warn(`========== Pointer Analysis Round ${this.ptaStat.iterTimes} ==========`);
133
+ // do pointer transfer
134
+ this.solveWorklist();
135
+ // process dynamic call
136
+ reanalyzer = this.onTheFlyDynamicCallSolve();
137
+ if (this.config.dotDump) {
138
+ this.pag.dump(path_1.default.join(this.config.outputDirectory, `pta_pag_itor#${this.ptaStat.iterTimes}.dot`));
139
+ }
140
+ }
141
+ }
142
+ /**
143
+ * get newly added Address Edge, and add them to initial WorkList
144
+ */
145
+ initWorklist() {
146
+ for (let e of this.pag.getAddrEdges()) {
147
+ this.ptaStat.numProcessedAddr++;
148
+ let { src, dst } = e.getEndPoints();
149
+ this.ptd.addPts(dst, src);
150
+ if (this.pag.getNode(src) instanceof Pag_1.PagGlobalThisNode) {
151
+ // readd globalThis heapObj into workList
152
+ this.ptd.addPts(src, src);
153
+ this.worklist.push(src);
154
+ }
155
+ this.worklist.push(dst);
156
+ }
157
+ this.pag.resetAddrEdges();
158
+ }
159
+ solveWorklist() {
160
+ while (this.worklist.length > 0) {
161
+ let node = this.worklist.shift();
162
+ this.processNode(node);
163
+ }
164
+ return true;
165
+ }
166
+ processNode(nodeId) {
167
+ this.handleThis(nodeId);
168
+ this.handleLoadWrite(nodeId);
169
+ this.handleCopy(nodeId);
170
+ this.handlePt(nodeId);
171
+ this.detectTypeDiff(nodeId);
172
+ return true;
173
+ }
174
+ handleCopy(nodeID) {
175
+ var _a;
176
+ let node = this.pag.getNode(nodeID);
177
+ (_a = node.getOutgoingCopyEdges()) === null || _a === void 0 ? void 0 : _a.forEach(copyEdge => {
178
+ this.propagate(copyEdge);
179
+ this.ptaStat.numProcessedCopy++;
180
+ });
181
+ return true;
182
+ }
183
+ handleLoadWrite(nodeID) {
184
+ let node = this.pag.getNode(nodeID);
185
+ let diffPts = this.ptd.getDiffPts(nodeID);
186
+ if (!diffPts || diffPts.count() == 0) {
187
+ return false;
188
+ }
189
+ // get related field node with current node's value
190
+ let instanceFieldNodeMap = this.pag.getNodesByBaseValue(node.getValue());
191
+ if (instanceFieldNodeMap === undefined) {
192
+ return true;
193
+ }
194
+ instanceFieldNodeMap.forEach((nodeIDs, cid) => {
195
+ // TODO: check cid
196
+ if (cid != node.getCid()) {
197
+ return;
198
+ }
199
+ nodeIDs.forEach((nodeID) => {
200
+ // get abstract field node
201
+ let fieldNode = this.pag.getNode(nodeID);
202
+ this.handleFieldInEdges(fieldNode, diffPts);
203
+ this.handleFieldOutEdges(fieldNode, diffPts);
204
+ });
205
+ });
206
+ return true;
207
+ }
208
+ handleFieldInEdges(fieldNode, diffPts) {
209
+ fieldNode.getIncomingEdge().forEach((edge) => {
210
+ if (edge.getKind() !== Pag_1.PagEdgeKind.Write) {
211
+ return;
212
+ //throw new Error ("field node in edge is not write edge")
213
+ }
214
+ let srcNode = edge.getSrcNode();
215
+ this.ptaStat.numProcessedWrite++;
216
+ for (let pt of diffPts) {
217
+ // filter pt
218
+ // clone the real field node with abstract field node
219
+ let dstNode;
220
+ if (fieldNode instanceof Pag_1.PagArrayNode) {
221
+ dstNode = this.pag.getOrClonePagArrayFieldNode(fieldNode, pt);
222
+ }
223
+ else {
224
+ dstNode = this.pag.getOrClonePagFieldNode(fieldNode, pt);
225
+ }
226
+ if (dstNode && this.pag.addPagEdge(srcNode, dstNode, Pag_1.PagEdgeKind.Copy)) {
227
+ this.ptaStat.numRealWrite++;
228
+ if (this.ptd.resetElem(srcNode.getID())) {
229
+ this.worklist.push(srcNode.getID());
230
+ }
231
+ }
232
+ }
233
+ });
234
+ }
235
+ handleFieldOutEdges(fieldNode, diffPts) {
236
+ fieldNode.getOutgoingEdges().forEach((edge) => {
237
+ if (edge.getKind() !== Pag_1.PagEdgeKind.Load) {
238
+ return;
239
+ }
240
+ let dstNode = edge.getDstNode();
241
+ this.ptaStat.numProcessedLoad++;
242
+ for (let pt of diffPts) {
243
+ let srcNode;
244
+ if (fieldNode instanceof Pag_1.PagArrayNode) {
245
+ srcNode = this.pag.getOrClonePagArrayFieldNode(fieldNode, pt);
246
+ }
247
+ else {
248
+ srcNode = this.pag.getOrClonePagFieldNode(fieldNode, pt);
249
+ }
250
+ if (srcNode && this.pag.addPagEdge(srcNode, dstNode, Pag_1.PagEdgeKind.Copy)) {
251
+ this.ptaStat.numRealLoad++;
252
+ // TODO: if field is used before initialzed, newSrc node has no diff pts
253
+ if (this.ptd.resetElem(srcNode.getID())) {
254
+ this.worklist.push(srcNode.getID());
255
+ }
256
+ }
257
+ }
258
+ });
259
+ }
260
+ /**
261
+ * If current node is a base of a called method, pointer in this node will be transfered into `this` Local in method
262
+ */
263
+ handleThis(nodeID) {
264
+ var _a;
265
+ let node = this.pag.getNode(nodeID);
266
+ (_a = node.getOutgoingThisEdges()) === null || _a === void 0 ? void 0 : _a.forEach(thisEdge => {
267
+ this.propagate(thisEdge);
268
+ this.ptaStat.numProcessedThis++;
269
+ });
270
+ return true;
271
+ }
272
+ handlePt(nodeID) {
273
+ let realDiff = this.ptd.calculateDiff(nodeID, nodeID);
274
+ if (realDiff.count() != 0) {
275
+ // record the updated nodes
276
+ this.pagBuilder.addUpdatedNode(nodeID, realDiff);
277
+ }
278
+ this.ptd.flush(nodeID);
279
+ this.pagBuilder.setPtForNode(nodeID, this.ptd.getPropaPts(nodeID));
280
+ }
281
+ propagate(edge) {
282
+ let changed = false;
283
+ let { src, dst } = edge.getEndPoints();
284
+ let diffPts = this.ptd.getDiffPts(src);
285
+ if (!diffPts) {
286
+ return changed;
287
+ }
288
+ let realDiffPts = this.ptd.calculateDiff(src, dst);
289
+ for (let pt of realDiffPts) {
290
+ changed = this.ptd.addPts(dst, pt) || changed;
291
+ }
292
+ if (changed) {
293
+ this.worklist.push(dst);
294
+ }
295
+ return changed;
296
+ }
297
+ /**
298
+ * 1. 记录被更新的节点(记录cid, nodeid)
299
+ * 2. ( PAGLocalNode记录callsite(cid, value唯一)),通过1种的nodeID查询Node,拿到Callsite
300
+ * 3. 在addDynamicCall里对传入指针过滤(已处理指针和未处理指针)
301
+ */
302
+ onTheFlyDynamicCallSolve() {
303
+ let changed = false;
304
+ let processedCallSites = new Set();
305
+ this.pagBuilder.getUpdatedNodes().forEach((pts, nodeID) => {
306
+ let node = this.pag.getNode(nodeID);
307
+ if (!(node instanceof Pag_1.PagLocalNode)) {
308
+ logger.warn(`node ${nodeID} is not local node, value: ${node.getValue()}`);
309
+ return;
310
+ }
311
+ let dynCallSites = node.getRelatedDynCallSites();
312
+ if (!dynCallSites) {
313
+ logger.warn(`node ${nodeID} has no related dynamic call site`);
314
+ return;
315
+ }
316
+ logger.info(`[process dynamic callsite] node ${nodeID}`);
317
+ dynCallSites.forEach((dynCallsite) => {
318
+ for (let pt of pts) {
319
+ let srcNodes = this.pagBuilder.addDynamicCallEdge(dynCallsite, pt, node.getCid());
320
+ changed = this.addToReanalyze(srcNodes) || changed;
321
+ }
322
+ processedCallSites.add(dynCallsite);
323
+ });
324
+ });
325
+ this.pagBuilder.resetUpdatedNodes();
326
+ this.pagBuilder.handleUnprocessedCallSites(processedCallSites);
327
+ changed = this.pagBuilder.handleReachable() || changed;
328
+ this.initWorklist();
329
+ return changed;
330
+ }
331
+ addToReanalyze(startNodes) {
332
+ let flag = false;
333
+ for (let node of startNodes) {
334
+ if (!this.worklist.includes(node) && this.ptd.resetElem(node)) {
335
+ this.worklist.push(node);
336
+ flag = true;
337
+ }
338
+ }
339
+ return flag;
340
+ }
341
+ /**
342
+ * compare interface
343
+ */
344
+ noAlias(leftValue, rightValue) {
345
+ var _a, _b;
346
+ let leftValueNodes = (_a = this.pag.getNodesByValue(leftValue)) === null || _a === void 0 ? void 0 : _a.values();
347
+ let rightValueNodes = (_b = this.pag.getNodesByValue(rightValue)) === null || _b === void 0 ? void 0 : _b.values();
348
+ let leftValuePts = new Set(), rightValuePts = new Set();
349
+ for (let nodeID of leftValueNodes) {
350
+ let node = this.pag.getNode(nodeID);
351
+ for (let pt of node.getPointTo()) {
352
+ leftValuePts.add(pt);
353
+ }
354
+ }
355
+ for (let nodeID of rightValueNodes) {
356
+ let node = this.pag.getNode(nodeID);
357
+ for (let pt of node.getPointTo()) {
358
+ rightValuePts.add(pt);
359
+ }
360
+ }
361
+ if (leftValuePts.size > rightValuePts.size) {
362
+ [leftValuePts, rightValuePts] = [rightValuePts, leftValuePts];
363
+ }
364
+ for (const elem of leftValuePts) {
365
+ if (rightValuePts.has(elem)) {
366
+ return false;
367
+ }
368
+ }
369
+ // no alias
370
+ return true;
371
+ }
372
+ mayAlias(leftValue, rightValue) {
373
+ return !this.noAlias(leftValue, rightValue);
374
+ }
375
+ getRelatedNodes(value) {
376
+ var _a;
377
+ let valueNodes = (_a = this.pag.getNodesByValue(value)) === null || _a === void 0 ? void 0 : _a.values();
378
+ let relatedAllNodes = new Set();
379
+ let workListNodes = [];
380
+ let processedNodes = new Set();
381
+ for (const nodeID of valueNodes) {
382
+ workListNodes.push(nodeID);
383
+ }
384
+ while (workListNodes.length !== 0) {
385
+ let valueNodeID = workListNodes.shift();
386
+ if (processedNodes.has(valueNodeID)) {
387
+ continue;
388
+ }
389
+ let valueNode = this.pag.getNode(valueNodeID);
390
+ let inCopyEdges = valueNode.getIncomingCopyEdges();
391
+ if (!inCopyEdges) {
392
+ continue;
393
+ }
394
+ inCopyEdges.forEach(edge => {
395
+ let srcID = edge.getSrcID();
396
+ if (!processedNodes.has(srcID)) {
397
+ workListNodes.push(srcID);
398
+ }
399
+ });
400
+ let outCopyEdges = valueNode.getOutgoingCopyEdges();
401
+ if (!outCopyEdges) {
402
+ continue;
403
+ }
404
+ outCopyEdges.forEach(edge => {
405
+ let dstID = edge.getDstID();
406
+ if (!processedNodes.has(dstID)) {
407
+ workListNodes.push(dstID);
408
+ }
409
+ });
410
+ processedNodes.add(valueNodeID);
411
+ }
412
+ processedNodes.forEach(nodeID => {
413
+ let valueNode = this.pag.getNode(nodeID);
414
+ relatedAllNodes.add(valueNode.getValue());
415
+ });
416
+ return relatedAllNodes;
417
+ }
418
+ detectTypeDiff(nodeId) {
419
+ var _a;
420
+ if (this.config.detectTypeDiff == false) {
421
+ return;
422
+ }
423
+ this.typeDiffMap = (_a = this.typeDiffMap) !== null && _a !== void 0 ? _a : new Map();
424
+ let node = this.pag.getNode(nodeId);
425
+ let value = node.getValue();
426
+ let origType = node.getValue().getType();
427
+ // TODO: union type
428
+ if (!(origType instanceof Type_1.ClassType || origType instanceof Type_1.UnknownType)) {
429
+ return;
430
+ }
431
+ let findSameType = false;
432
+ let pts = node.getPointTo();
433
+ if (pts.size == 0) {
434
+ return;
435
+ }
436
+ pts.forEach(pt => {
437
+ var _a;
438
+ let ptNode = this.pag.getNode(pt);
439
+ let type = ptNode.getValue().getType();
440
+ if (type.toString() != origType.toString()) {
441
+ let diffSet = (_a = this.typeDiffMap.get(value)) !== null && _a !== void 0 ? _a : new Set();
442
+ this.typeDiffMap.set(value, diffSet);
443
+ if (!diffSet.has(type)) {
444
+ diffSet.add(type);
445
+ }
446
+ }
447
+ else {
448
+ findSameType = true;
449
+ }
450
+ });
451
+ // If find pts to original type,
452
+ // need add original type back since it is a correct type
453
+ let diffSet = this.typeDiffMap.get(value);
454
+ if (diffSet && findSameType) {
455
+ diffSet.add(origType);
456
+ }
457
+ }
458
+ getTypeDiffMap() {
459
+ return this.typeDiffMap;
460
+ }
461
+ resolveCall(sourceMethod, invokeStmt) {
462
+ return [];
463
+ }
464
+ getUnhandledFuncs() {
465
+ return this.pagBuilder.getUnhandledFuncs();
466
+ }
467
+ getHandledFuncs() {
468
+ return this.pagBuilder.getHandledFuncs();
469
+ }
470
+ getPTAConfig() {
471
+ return this.config;
472
+ }
473
+ dumpUnhandledFunctions() {
474
+ const filePath = path_1.default.join(this.config.outputDirectory, 'PtaUnhandledFunctionList.txt');
475
+ fs.access(filePath, fs.constants.F_OK, (err) => {
476
+ if (!err) {
477
+ fs.truncate(filePath, 0, (err) => {
478
+ if (err) {
479
+ console.log('Error to truncate file ', err);
480
+ }
481
+ });
482
+ }
483
+ let updatedContent = '';
484
+ this.getUnhandledFuncs().forEach(funcID => {
485
+ let cgNode = this.cg.getNode(funcID);
486
+ if (cgNode.getIsSdkMethod()) {
487
+ return;
488
+ }
489
+ let f = this.cg.getArkMethodByFuncID(funcID);
490
+ if (f) {
491
+ updatedContent += f.getSignature().toString() + '\n';
492
+ }
493
+ });
494
+ fs.writeFile(filePath, updatedContent, 'utf8', (err) => {
495
+ if (err) {
496
+ console.error('Error to write file', err);
497
+ }
498
+ });
499
+ });
500
+ }
501
+ }
502
+ exports.PointerAnalysis = PointerAnalysis;
@@ -0,0 +1,9 @@
1
+ export declare class PointerAnalysisConfig {
2
+ kLimit: number;
3
+ outputDirectory: string;
4
+ detectTypeDiff: boolean;
5
+ dotDump: boolean;
6
+ unhandledFuncDump: boolean;
7
+ constructor(kLimit: number, outputDirectory: string, detectTypeDiff?: boolean, dotDump?: boolean, unhandledFuncDump?: boolean);
8
+ }
9
+ //# sourceMappingURL=PointerAnalysisConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PointerAnalysisConfig.d.ts","sourceRoot":"","sources":["../../../src/callgraph/pointerAnalysis/PointerAnalysisConfig.ts"],"names":[],"mappings":"AAiBA,qBAAa,qBAAqB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,OAAO,CAAC;gBAEtB,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,GAAE,OAAa,EAC9E,OAAO,GAAE,OAAe,EAAE,iBAAiB,GAAE,OAAe;CAcnE"}
@@ -0,0 +1,57 @@
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.PointerAnalysisConfig = void 0;
41
+ const fs = __importStar(require("fs"));
42
+ class PointerAnalysisConfig {
43
+ constructor(kLimit, outputDirectory, detectTypeDiff = false, dotDump = false, unhandledFuncDump = false) {
44
+ if (kLimit > 5) {
45
+ throw new Error("K Limit too large");
46
+ }
47
+ this.kLimit = kLimit;
48
+ this.outputDirectory = outputDirectory;
49
+ this.detectTypeDiff = detectTypeDiff;
50
+ this.dotDump = dotDump;
51
+ this.unhandledFuncDump = unhandledFuncDump;
52
+ if (!fs.existsSync(outputDirectory)) {
53
+ fs.mkdirSync(outputDirectory, { recursive: true });
54
+ }
55
+ }
56
+ }
57
+ exports.PointerAnalysisConfig = PointerAnalysisConfig;