From 272ec443e4f5b9f16a249b37cdd663c2a63829f7 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Mon, 21 Dec 2020 04:49:10 +0100 Subject: [PATCH] add CustomSection: NameSection + small changes --- .../disassembly/modules/sections/Section.java | 12 ++- .../modules/sections/code/CodeSection.java | 6 +- .../sections/custom/CustomSection.java | 2 +- .../sections/custom/CustomSectionFactory.java | 5 +- .../custom/UnImplementedCustomSection.java | 1 + .../custom/namesection/NameSection.java | 74 +++++++++++++++++++ .../subsections/FunctionNamesSubSection.java | 40 ++++++++++ .../subsections/LocalNamesSubSection.java | 42 +++++++++++ .../subsections/ModuleNameSubSection.java | 39 ++++++++++ .../namesection/subsections/SubSection.java | 44 +++++++++++ .../namemaps/IndirectNameAssoc.java | 48 ++++++++++++ .../subsections/namemaps/IndirectNameMap.java | 38 ++++++++++ .../subsections/namemaps/NameAssoc.java | 49 ++++++++++++ .../subsections/namemaps/NameMap.java | 38 ++++++++++ .../modules/sections/data/DataSection.java | 6 +- .../sections/element/ElementSection.java | 6 +- .../sections/export/ExportSection.java | 6 +- .../sections/function/FunctionSection.java | 6 +- .../sections/global/GlobalSection.java | 6 +- .../modules/sections/imprt/ImportSection.java | 6 +- .../sections/memory/MemorySection.java | 6 +- .../modules/sections/start/StartSection.java | 6 +- .../modules/sections/table/TableSection.java | 6 +- .../modules/sections/type/TypeSection.java | 6 +- 24 files changed, 459 insertions(+), 39 deletions(-) create mode 100644 src/main/java/wasm/disassembly/modules/sections/custom/namesection/NameSection.java create mode 100644 src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/FunctionNamesSubSection.java create mode 100644 src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/LocalNamesSubSection.java create mode 100644 src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/ModuleNameSubSection.java create mode 100644 src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/SubSection.java create mode 100644 src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/IndirectNameAssoc.java create mode 100644 src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/IndirectNameMap.java create mode 100644 src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/NameAssoc.java create mode 100644 src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/NameMap.java diff --git a/src/main/java/wasm/disassembly/modules/sections/Section.java b/src/main/java/wasm/disassembly/modules/sections/Section.java index 6e014fd..8eab590 100644 --- a/src/main/java/wasm/disassembly/modules/sections/Section.java +++ b/src/main/java/wasm/disassembly/modules/sections/Section.java @@ -2,6 +2,7 @@ package wasm.disassembly.modules.sections; import wasm.disassembly.InvalidOpCodeException; import wasm.disassembly.WASMOpCode; +import wasm.disassembly.modules.Module; import wasm.disassembly.values.WUnsignedInt; import java.io.BufferedInputStream; @@ -13,19 +14,22 @@ public abstract class Section extends WASMOpCode { private int sectionId; private long size; + protected Module module; - public Section(BufferedInputStream in, int sectionId) throws IOException, InvalidOpCodeException { + public Section(BufferedInputStream in, Module module, int sectionId) throws IOException, InvalidOpCodeException { + this.module = module; this.sectionId = sectionId; size = WUnsignedInt.read(in, 32); } - public Section(int sectionId, long size) { + public Section(Module module, int sectionId, long size) { + this.module = module; this.sectionId = sectionId; this.size = size; } - public Section(int sectionId) { - this(sectionId, -1); + public Section(Module module, int sectionId) { + this(module, sectionId, -1); } @Override diff --git a/src/main/java/wasm/disassembly/modules/sections/code/CodeSection.java b/src/main/java/wasm/disassembly/modules/sections/code/CodeSection.java index f01aa70..fec2326 100644 --- a/src/main/java/wasm/disassembly/modules/sections/code/CodeSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/code/CodeSection.java @@ -18,12 +18,12 @@ public class CodeSection extends Section { private Vector codesEntries; public CodeSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, CODE_SECTION_ID); + super(in, module, CODE_SECTION_ID); codesEntries = new Vector<>(in, Code::new, module); } - public CodeSection(List codesEntries) { - super(CODE_SECTION_ID); + public CodeSection(Module module, List codesEntries) { + super(module, CODE_SECTION_ID); this.codesEntries = new Vector<>(codesEntries); } diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/CustomSection.java b/src/main/java/wasm/disassembly/modules/sections/custom/CustomSection.java index 06e5f53..3002bf4 100644 --- a/src/main/java/wasm/disassembly/modules/sections/custom/CustomSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/custom/CustomSection.java @@ -16,7 +16,7 @@ public abstract class CustomSection extends Section { private String name; public CustomSection(Module module, long size, String name) throws IOException, InvalidOpCodeException { - super(CUSTOM_SECTION_ID, size); + super(module, CUSTOM_SECTION_ID, size); this.name = name; } diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/CustomSectionFactory.java b/src/main/java/wasm/disassembly/modules/sections/custom/CustomSectionFactory.java index cee0fdc..9126484 100644 --- a/src/main/java/wasm/disassembly/modules/sections/custom/CustomSectionFactory.java +++ b/src/main/java/wasm/disassembly/modules/sections/custom/CustomSectionFactory.java @@ -2,6 +2,7 @@ package wasm.disassembly.modules.sections.custom; import wasm.disassembly.InvalidOpCodeException; import wasm.disassembly.modules.Module; +import wasm.disassembly.modules.sections.custom.namesection.NameSection; import wasm.disassembly.values.WName; import wasm.disassembly.values.WUnsignedInt; @@ -14,7 +15,9 @@ public class CustomSectionFactory { long size = WUnsignedInt.read(in, 32); String name = WName.read(in); - // select implementation + if (name.equals("name")) { + return new NameSection(in, module, size); + } return new UnImplementedCustomSection(in, module, size, name); } diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/UnImplementedCustomSection.java b/src/main/java/wasm/disassembly/modules/sections/custom/UnImplementedCustomSection.java index d9cb1d0..32ac0ab 100644 --- a/src/main/java/wasm/disassembly/modules/sections/custom/UnImplementedCustomSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/custom/UnImplementedCustomSection.java @@ -2,6 +2,7 @@ package wasm.disassembly.modules.sections.custom; import wasm.disassembly.InvalidOpCodeException; import wasm.disassembly.modules.Module; +import wasm.disassembly.modules.sections.custom.CustomSection; import wasm.disassembly.values.WName; import java.io.BufferedInputStream; diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/namesection/NameSection.java b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/NameSection.java new file mode 100644 index 0000000..c35ed71 --- /dev/null +++ b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/NameSection.java @@ -0,0 +1,74 @@ +package wasm.disassembly.modules.sections.custom.namesection; + +import wasm.disassembly.InvalidOpCodeException; +import wasm.disassembly.modules.Module; +import wasm.disassembly.modules.sections.custom.CustomSection; +import wasm.disassembly.modules.sections.custom.namesection.subsections.FunctionNamesSubSection; +import wasm.disassembly.modules.sections.custom.namesection.subsections.LocalNamesSubSection; +import wasm.disassembly.modules.sections.custom.namesection.subsections.ModuleNameSubSection; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; + +public class NameSection extends CustomSection { + + private ModuleNameSubSection moduleName; + private FunctionNamesSubSection functionNames; + private LocalNamesSubSection localNames; + + public NameSection(BufferedInputStream in, Module module, long size) throws IOException, InvalidOpCodeException { + super(module, size, "name"); + + moduleName = isNextSection(in, 0) ? new ModuleNameSubSection(in, module) : null; + functionNames = isNextSection(in, 1) ? new FunctionNamesSubSection(in, module) : null; + localNames = isNextSection(in, 2) ? new LocalNamesSubSection(in, module) : null; + } + + public NameSection(Module module, long size, String name, ModuleNameSubSection moduleName, FunctionNamesSubSection functionNames, LocalNamesSubSection localNames) throws IOException, InvalidOpCodeException { + super(module, size, name); + this.moduleName = moduleName; + this.functionNames = functionNames; + this.localNames = localNames; + } + + public ModuleNameSubSection getModuleName() { + return moduleName; + } + + public void setModuleName(ModuleNameSubSection moduleName) { + this.moduleName = moduleName; + } + + public FunctionNamesSubSection getFunctionNames() { + return functionNames; + } + + public void setFunctionNames(FunctionNamesSubSection functionNames) { + this.functionNames = functionNames; + } + + public LocalNamesSubSection getLocalNames() { + return localNames; + } + + public void setLocalNames(LocalNamesSubSection localNames) { + this.localNames = localNames; + } + + @Override + protected void assemble3(OutputStream out) throws IOException, InvalidOpCodeException { + if (moduleName != null) moduleName.assemble(out); + if (functionNames != null) functionNames.assemble(out); + if (localNames != null) localNames.assemble(out); + } + + private boolean isNextSection(BufferedInputStream in, int id) throws IOException { + in.mark(1); + if (in.read() == id) { + return true; + } + in.reset(); + return false; + } +} diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/FunctionNamesSubSection.java b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/FunctionNamesSubSection.java new file mode 100644 index 0000000..0c89de6 --- /dev/null +++ b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/FunctionNamesSubSection.java @@ -0,0 +1,40 @@ +package wasm.disassembly.modules.sections.custom.namesection.subsections; + +import wasm.disassembly.InvalidOpCodeException; +import wasm.disassembly.conventions.Creator; +import wasm.disassembly.modules.Module; +import wasm.disassembly.modules.indices.FuncIdx; +import wasm.disassembly.modules.sections.custom.namesection.subsections.namemaps.NameMap; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; + +public class FunctionNamesSubSection extends SubSection { + + public static final int FUNCTION_NAMES_SUBSECTION_ID = 1; + private NameMap nameMap; + + public FunctionNamesSubSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { + super(in, FUNCTION_NAMES_SUBSECTION_ID); + nameMap = new NameMap<>(in, module, FuncIdx::new); + } + + public FunctionNamesSubSection(NameMap nameMap) { + super(FUNCTION_NAMES_SUBSECTION_ID); + this.nameMap = nameMap; + } + + public NameMap getNameMap() { + return nameMap; + } + + public void setNameMap(NameMap nameMap) { + this.nameMap = nameMap; + } + + @Override + protected void assemble2(OutputStream out) throws IOException, InvalidOpCodeException { + nameMap.assemble(out); + } +} diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/LocalNamesSubSection.java b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/LocalNamesSubSection.java new file mode 100644 index 0000000..fdbee7c --- /dev/null +++ b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/LocalNamesSubSection.java @@ -0,0 +1,42 @@ +package wasm.disassembly.modules.sections.custom.namesection.subsections; + +import wasm.disassembly.InvalidOpCodeException; +import wasm.disassembly.conventions.Creator; +import wasm.disassembly.modules.Module; +import wasm.disassembly.modules.indices.FuncIdx; +import wasm.disassembly.modules.indices.LocalIdx; +import wasm.disassembly.modules.sections.custom.namesection.subsections.namemaps.IndirectNameMap; +import wasm.disassembly.modules.sections.custom.namesection.subsections.namemaps.NameMap; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; + +public class LocalNamesSubSection extends SubSection { + + public static final int LOCAL_NAMES_SUBSECTION_ID = 2; + private IndirectNameMap indirectNameMap; + + public LocalNamesSubSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { + super(in, LOCAL_NAMES_SUBSECTION_ID); + indirectNameMap = new IndirectNameMap<>(in, module, FuncIdx::new, LocalIdx::new); + } + + public LocalNamesSubSection(IndirectNameMap indirectNameMap) { + super(LOCAL_NAMES_SUBSECTION_ID); + this.indirectNameMap = indirectNameMap; + } + + public IndirectNameMap getIndirectNameMap() { + return indirectNameMap; + } + + public void setIndirectNameMap(IndirectNameMap indirectNameMap) { + this.indirectNameMap = indirectNameMap; + } + + @Override + protected void assemble2(OutputStream out) throws IOException, InvalidOpCodeException { + indirectNameMap.assemble(out); + } +} diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/ModuleNameSubSection.java b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/ModuleNameSubSection.java new file mode 100644 index 0000000..f7ccc12 --- /dev/null +++ b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/ModuleNameSubSection.java @@ -0,0 +1,39 @@ +package wasm.disassembly.modules.sections.custom.namesection.subsections; + +import wasm.disassembly.InvalidOpCodeException; +import wasm.disassembly.modules.Module; +import wasm.disassembly.values.WName; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; + +public class ModuleNameSubSection extends SubSection { + + public static final int MODULE_NAME_SUBSECTION_ID = 0; + + private String name; + + public ModuleNameSubSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { + super(in, MODULE_NAME_SUBSECTION_ID); + name = WName.read(in); + } + + public ModuleNameSubSection(String name) { + super(MODULE_NAME_SUBSECTION_ID); + this.name = name; + } + + @Override + protected void assemble2(OutputStream out) throws IOException, InvalidOpCodeException { + WName.write(name, out); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/SubSection.java b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/SubSection.java new file mode 100644 index 0000000..30a576f --- /dev/null +++ b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/SubSection.java @@ -0,0 +1,44 @@ +package wasm.disassembly.modules.sections.custom.namesection.subsections; + +import wasm.disassembly.InvalidOpCodeException; +import wasm.disassembly.WASMOpCode; +import wasm.disassembly.values.WName; +import wasm.disassembly.values.WUnsignedInt; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +public abstract class SubSection extends WASMOpCode { + + private long size; + private int subSectionId; + + public SubSection(BufferedInputStream in, int subSectionId) throws IOException, InvalidOpCodeException { + this.subSectionId = subSectionId; + size = WUnsignedInt.read(in, 32); + } + + public SubSection(int subSectionId) { + this.subSectionId = subSectionId; + size = -1; + } + + @Override + public void assemble(OutputStream out) throws IOException, InvalidOpCodeException { + out.write(subSectionId); + + ByteArrayOutputStream fakeOutputStream = new ByteArrayOutputStream(); + assemble2(fakeOutputStream); + byte[] asbytes = fakeOutputStream.toByteArray(); + WUnsignedInt.write(asbytes.length, out, 32); + out.write(asbytes); + } + + protected abstract void assemble2(OutputStream out) throws IOException, InvalidOpCodeException; + + public int getSubSectionId() { + return subSectionId; + } +} diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/IndirectNameAssoc.java b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/IndirectNameAssoc.java new file mode 100644 index 0000000..f8a1510 --- /dev/null +++ b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/IndirectNameAssoc.java @@ -0,0 +1,48 @@ +package wasm.disassembly.modules.sections.custom.namesection.subsections.namemaps; + +import wasm.disassembly.InvalidOpCodeException; +import wasm.disassembly.WASMOpCode; +import wasm.disassembly.conventions.Creator; +import wasm.disassembly.modules.Module; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; + +public class IndirectNameAssoc extends WASMOpCode { + + private Idx idx; + private NameMap nameMap; + + public IndirectNameAssoc(BufferedInputStream in, Module module, Creator creator, Creator innerCreator) throws IOException, InvalidOpCodeException { + idx = creator.create(in, module); + nameMap = new NameMap<>(in, module, innerCreator); + } + + public IndirectNameAssoc(Idx idx, NameMap nameMap) { + this.idx = idx; + this.nameMap = nameMap; + } + + public Idx getIdx() { + return idx; + } + + public void setIdx(Idx idx) { + this.idx = idx; + } + + public NameMap getNameMap() { + return nameMap; + } + + public void setNameMap(NameMap nameMap) { + this.nameMap = nameMap; + } + + @Override + public void assemble(OutputStream out) throws IOException, InvalidOpCodeException { + idx.assemble(out); + nameMap.assemble(out); + } +} diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/IndirectNameMap.java b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/IndirectNameMap.java new file mode 100644 index 0000000..104e0fe --- /dev/null +++ b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/IndirectNameMap.java @@ -0,0 +1,38 @@ +package wasm.disassembly.modules.sections.custom.namesection.subsections.namemaps; + +import wasm.disassembly.InvalidOpCodeException; +import wasm.disassembly.WASMOpCode; +import wasm.disassembly.conventions.Creator; +import wasm.disassembly.conventions.Vector; +import wasm.disassembly.modules.Module; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; + +public class IndirectNameMap extends WASMOpCode { + + private Vector> idxAndMaps; + + public IndirectNameMap(BufferedInputStream in, Module module, Creator creator, Creator innerCreator) throws IOException, InvalidOpCodeException { + idxAndMaps = new Vector<>(in, (in1, m) -> new IndirectNameAssoc<>(in1, m, creator, innerCreator), module); + } + + public IndirectNameMap(Vector> idxAndMaps) { + this.idxAndMaps = idxAndMaps; + } + + public List> getIdxAndMaps() { + return idxAndMaps.getElements(); + } + + public void setIdxAndMaps(List> idxAndMaps) { + this.idxAndMaps = new Vector<>(idxAndMaps); + } + + @Override + public void assemble(OutputStream out) throws IOException, InvalidOpCodeException { + idxAndMaps.assemble(out); + } +} diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/NameAssoc.java b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/NameAssoc.java new file mode 100644 index 0000000..04e3c00 --- /dev/null +++ b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/NameAssoc.java @@ -0,0 +1,49 @@ +package wasm.disassembly.modules.sections.custom.namesection.subsections.namemaps; + +import wasm.disassembly.InvalidOpCodeException; +import wasm.disassembly.WASMOpCode; +import wasm.disassembly.conventions.Creator; +import wasm.disassembly.modules.Module; +import wasm.disassembly.values.WName; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; + +public class NameAssoc extends WASMOpCode { + + private Idx idx; + private String name; + + public NameAssoc(BufferedInputStream in, Module module, Creator creator) throws IOException, InvalidOpCodeException { + idx = creator.create(in, module); + name = WName.read(in); + } + + public NameAssoc(Idx idx, String name) { + this.idx = idx; + this.name = name; + } + + public Idx getIdx() { + return idx; + } + + public void setIdx(Idx idx) { + this.idx = idx; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public void assemble(OutputStream out) throws IOException, InvalidOpCodeException { + idx.assemble(out); + WName.write(name, out); + } +} diff --git a/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/NameMap.java b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/NameMap.java new file mode 100644 index 0000000..6ae2b21 --- /dev/null +++ b/src/main/java/wasm/disassembly/modules/sections/custom/namesection/subsections/namemaps/NameMap.java @@ -0,0 +1,38 @@ +package wasm.disassembly.modules.sections.custom.namesection.subsections.namemaps; + +import wasm.disassembly.InvalidOpCodeException; +import wasm.disassembly.WASMOpCode; +import wasm.disassembly.conventions.Creator; +import wasm.disassembly.conventions.Vector; +import wasm.disassembly.modules.Module; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; + +public class NameMap extends WASMOpCode { + + private Vector> idxAndNames; + + public NameMap(BufferedInputStream in, Module module, Creator creator) throws IOException, InvalidOpCodeException { + idxAndNames = new Vector<>(in, (in1, m) -> new NameAssoc<>(in1, m, creator), module); + } + + public NameMap(Vector> idxAndNames) { + this.idxAndNames = idxAndNames; + } + + public List> getIdxAndNames() { + return idxAndNames.getElements(); + } + + public void setIdxAndNames(List> idxAndNames) { + this.idxAndNames = new Vector<>(idxAndNames); + } + + @Override + public void assemble(OutputStream out) throws IOException, InvalidOpCodeException { + idxAndNames.assemble(out); + } +} diff --git a/src/main/java/wasm/disassembly/modules/sections/data/DataSection.java b/src/main/java/wasm/disassembly/modules/sections/data/DataSection.java index 0943844..2475a89 100644 --- a/src/main/java/wasm/disassembly/modules/sections/data/DataSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/data/DataSection.java @@ -18,12 +18,12 @@ public class DataSection extends Section { private Vector dataSegments; public DataSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, DATA_SECTION_ID); + super(in, module, DATA_SECTION_ID); dataSegments = new Vector<>(in, Data::new, module); } - public DataSection(List dataSegments) { - super(DATA_SECTION_ID); + public DataSection(Module module, List dataSegments) { + super(module, DATA_SECTION_ID); this.dataSegments = new Vector<>(dataSegments); } diff --git a/src/main/java/wasm/disassembly/modules/sections/element/ElementSection.java b/src/main/java/wasm/disassembly/modules/sections/element/ElementSection.java index b9e032a..3588817 100644 --- a/src/main/java/wasm/disassembly/modules/sections/element/ElementSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/element/ElementSection.java @@ -17,12 +17,12 @@ public class ElementSection extends Section { private Vector elementSegments; public ElementSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, ELEMENT_SECTION_ID); + super(in, module, ELEMENT_SECTION_ID); elementSegments = new Vector<>(in, Elem::new, module); } - public ElementSection(List elementSegments) { - super(ELEMENT_SECTION_ID); + public ElementSection(Module module, List elementSegments) { + super(module, ELEMENT_SECTION_ID); this.elementSegments = new Vector<>(elementSegments); } diff --git a/src/main/java/wasm/disassembly/modules/sections/export/ExportSection.java b/src/main/java/wasm/disassembly/modules/sections/export/ExportSection.java index ccb1183..f9b75e6 100644 --- a/src/main/java/wasm/disassembly/modules/sections/export/ExportSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/export/ExportSection.java @@ -17,12 +17,12 @@ public class ExportSection extends Section { private Vector exports; public ExportSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, EXPORT_SECTION_ID); + super(in, module, EXPORT_SECTION_ID); exports = new Vector<>(in, Export::new, module); } - public ExportSection(List exports) { - super(EXPORT_SECTION_ID); + public ExportSection(Module module, List exports) { + super(module, EXPORT_SECTION_ID); this.exports = new Vector<>(exports); } diff --git a/src/main/java/wasm/disassembly/modules/sections/function/FunctionSection.java b/src/main/java/wasm/disassembly/modules/sections/function/FunctionSection.java index 300e09c..f2107b4 100644 --- a/src/main/java/wasm/disassembly/modules/sections/function/FunctionSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/function/FunctionSection.java @@ -19,12 +19,12 @@ public class FunctionSection extends Section { public FunctionSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, FUNCTION_SECTION_ID); + super(in, module, FUNCTION_SECTION_ID); typeIdxVector = new Vector<>(in, TypeIdx::new, module); } - public FunctionSection(List typeIdxList) { - super(FUNCTION_SECTION_ID); + public FunctionSection(Module module, List typeIdxList) { + super(module, FUNCTION_SECTION_ID); this.typeIdxVector = new Vector<>(typeIdxList); } diff --git a/src/main/java/wasm/disassembly/modules/sections/global/GlobalSection.java b/src/main/java/wasm/disassembly/modules/sections/global/GlobalSection.java index 5dc760e..486e55b 100644 --- a/src/main/java/wasm/disassembly/modules/sections/global/GlobalSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/global/GlobalSection.java @@ -18,12 +18,12 @@ public class GlobalSection extends Section { public GlobalSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, GLOBAL_SECTION_ID); + super(in, module, GLOBAL_SECTION_ID); globals = new Vector<>(in, Global::new, module); } - public GlobalSection(List globals) { - super(GLOBAL_SECTION_ID); + public GlobalSection(Module module, List globals) { + super(module, GLOBAL_SECTION_ID); this.globals = new Vector<>(globals); } diff --git a/src/main/java/wasm/disassembly/modules/sections/imprt/ImportSection.java b/src/main/java/wasm/disassembly/modules/sections/imprt/ImportSection.java index 1d5c1c1..499b642 100644 --- a/src/main/java/wasm/disassembly/modules/sections/imprt/ImportSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/imprt/ImportSection.java @@ -24,7 +24,7 @@ public class ImportSection extends Section { public ImportSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, IMPORT_SECTION_ID); + super(in, module, IMPORT_SECTION_ID); this.module = module; imports = new Vector<>(in, Import::new, module); @@ -36,8 +36,8 @@ public class ImportSection extends Section { } } - public ImportSection(List imports) { - super(IMPORT_SECTION_ID); + public ImportSection(Module module, List imports) { + super(module, IMPORT_SECTION_ID); this.imports = new Vector<>(imports); } diff --git a/src/main/java/wasm/disassembly/modules/sections/memory/MemorySection.java b/src/main/java/wasm/disassembly/modules/sections/memory/MemorySection.java index 2067fd3..d1bf5b5 100644 --- a/src/main/java/wasm/disassembly/modules/sections/memory/MemorySection.java +++ b/src/main/java/wasm/disassembly/modules/sections/memory/MemorySection.java @@ -18,12 +18,12 @@ public class MemorySection extends Section { public MemorySection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, MEMORY_SECTION_ID); + super(in, module, MEMORY_SECTION_ID); memories = new Vector<>(in, Mem::new, module); } - public MemorySection(List memories) { - super(MEMORY_SECTION_ID); + public MemorySection(Module module, List memories) { + super(module, MEMORY_SECTION_ID); this.memories = new Vector<>(memories); } diff --git a/src/main/java/wasm/disassembly/modules/sections/start/StartSection.java b/src/main/java/wasm/disassembly/modules/sections/start/StartSection.java index 46f440a..5927a31 100644 --- a/src/main/java/wasm/disassembly/modules/sections/start/StartSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/start/StartSection.java @@ -15,12 +15,12 @@ public class StartSection extends Section { private Start start; public StartSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, START_SECTION_ID); + super(in, module, START_SECTION_ID); start = new Start(in, module); } - public StartSection(Start start) { - super(START_SECTION_ID); + public StartSection(Module module, Start start) { + super(module, START_SECTION_ID); this.start = start; } diff --git a/src/main/java/wasm/disassembly/modules/sections/table/TableSection.java b/src/main/java/wasm/disassembly/modules/sections/table/TableSection.java index e8f5438..b0a4937 100644 --- a/src/main/java/wasm/disassembly/modules/sections/table/TableSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/table/TableSection.java @@ -18,12 +18,12 @@ public class TableSection extends Section { public TableSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, TABLE_SECTION_ID); + super(in, module, TABLE_SECTION_ID); tables = new Vector<>(in, Table::new, module); } - public TableSection(List tables) { - super(TABLE_SECTION_ID); + public TableSection(Module module, List
tables) { + super(module, TABLE_SECTION_ID); this.tables = new Vector<>(tables); } diff --git a/src/main/java/wasm/disassembly/modules/sections/type/TypeSection.java b/src/main/java/wasm/disassembly/modules/sections/type/TypeSection.java index 2f33a76..be70835 100644 --- a/src/main/java/wasm/disassembly/modules/sections/type/TypeSection.java +++ b/src/main/java/wasm/disassembly/modules/sections/type/TypeSection.java @@ -20,12 +20,12 @@ public class TypeSection extends Section { public TypeSection(BufferedInputStream in, Module module) throws IOException, InvalidOpCodeException { - super(in, TYPE_SECTION_ID); + super(in, module, TYPE_SECTION_ID); functionTypes = new Vector<>(in, FuncType::new, module); } - public TypeSection(List functionTypes) { - super(TYPE_SECTION_ID); + public TypeSection(Module module, List functionTypes) { + super(module, TYPE_SECTION_ID); this.functionTypes = new Vector<>(functionTypes); }