displayer.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. function HashTable() {
  2. let size = 0;
  3. let entry = new Object();
  4. this.add = function (key, value) {
  5. if (!this.containsKey(key)) {
  6. size++;
  7. }
  8. entry[key] = value;
  9. };
  10. this.getValue = function (key) {
  11. return this.containsKey(key) ? entry[key] : null;
  12. };
  13. this.remove = function (key) {
  14. if (this.containsKey(key) && (delete entry[key])) {
  15. size--;
  16. }
  17. };
  18. this.containsKey = function (key) {
  19. return (key in entry);
  20. };
  21. this.containsValue = function (value) {
  22. for (var prop in entry) {
  23. if (entry[prop] == value) {
  24. return true;
  25. }
  26. }
  27. return false;
  28. };
  29. this.getValues = function () {
  30. var values = new Array();
  31. for (var prop in entry) {
  32. values.push(entry[prop]);
  33. }
  34. return values;
  35. };
  36. this.getKeys = function () {
  37. var keys = new Array();
  38. for (var prop in entry) {
  39. keys.push(prop);
  40. }
  41. return keys;
  42. };
  43. this.getSize = function () {
  44. return size;
  45. };
  46. this.clear = function () {
  47. size = 0;
  48. entry = new Object();
  49. }
  50. }
  51. let myuser;
  52. let lines;
  53. let routineTab = new HashTable();
  54. let vulTypeCount = new HashTable();
  55. let fileCount = new HashTable();
  56. $(document).ready(function () {
  57. let outhtml;
  58. try {
  59. outhtml = $(window.frames["opencc_vul"].document).html();
  60. }catch (e) {
  61. outhtml = $(window.frames["opencc_vul"].document)[0].body.innerHTML
  62. }
  63. if(outhtml === "" || outhtml == undefined || outhtml == null || outhtml.length == 0){
  64. $.ajax({url: "opencc_vul.txt"}).done(display_content);
  65. } else {
  66. display_content(outhtml);
  67. }
  68. });
  69. function display_content(s){
  70. let answer = s;
  71. let i = 0;
  72. let count = 0;
  73. let one_obj = {};
  74. let obj_list = [];
  75. let all_lines = "";
  76. lines = answer.split("\n");
  77. for(i = 0; i < lines.length ; i++){
  78. let n = lines[i].match(/[a-zA-Z\._:0-9]+/g);
  79. if(n != null) {
  80. let res = {}; // One line of result
  81. res.filename = n[0];
  82. res.vultype = n[4];
  83. res.variate = n[8];
  84. res.subroutine = n[9];
  85. res.lineno = n[1];
  86. if(!routineTab.containsKey
  87. (res.subroutine+"+"+res.variate+"+"+res.filename))
  88. {
  89. // Repetition Check Passes
  90. routineTab.add(res.subroutine+"+"+res.variate+"+"+res.filename, res.vultype);
  91. obj_list.push(res);
  92. all_lines += "L" + res.lineno + " - <span> " + res.filename + "</span> <br>";
  93. count ++;
  94. if(vulTypeCount.containsKey(res.vultype)){
  95. let vul_list = vulTypeCount.getValue(res.vultype);
  96. vul_list.push(res);
  97. }else{
  98. let vul_list = new Array();
  99. vul_list.push(res);
  100. vulTypeCount.add(res.vultype, vul_list);
  101. }
  102. if(fileCount.containsKey(res.filename)){
  103. let vul_list = fileCount.getValue(res.filename);
  104. vul_list.push(res);
  105. }else{
  106. let vul_list = new Array();
  107. vul_list.push(res);
  108. fileCount.add(res.filename, vul_list);
  109. }
  110. }
  111. }
  112. }
  113. }