Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

remove.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { traverse, getSectionMetadatas, shiftSection } from "@webassemblyjs/ast";
  2. import { overrideBytesInBuffer } from "@webassemblyjs/helper-buffer";
  3. export function removeSections(ast, uint8Buffer, section) {
  4. var sectionMetadatas = getSectionMetadatas(ast, section);
  5. if (sectionMetadatas.length === 0) {
  6. throw new Error("Section metadata not found");
  7. }
  8. return sectionMetadatas.reverse().reduce(function (uint8Buffer, sectionMetadata) {
  9. var startsIncludingId = sectionMetadata.startOffset - 1;
  10. var ends = section === "start" ? sectionMetadata.size.loc.end.column + 1 : sectionMetadata.startOffset + sectionMetadata.size.value + 1;
  11. var delta = -(ends - startsIncludingId);
  12. /**
  13. * update AST
  14. */
  15. // Once we hit our section every that is after needs to be shifted by the delta
  16. var encounteredSection = false;
  17. traverse(ast, {
  18. SectionMetadata: function SectionMetadata(path) {
  19. if (path.node.section === section) {
  20. encounteredSection = true;
  21. return path.remove();
  22. }
  23. if (encounteredSection === true) {
  24. shiftSection(ast, path.node, delta);
  25. }
  26. }
  27. }); // replacement is nothing
  28. var replacement = [];
  29. return overrideBytesInBuffer(uint8Buffer, startsIncludingId, ends, replacement);
  30. }, uint8Buffer);
  31. }