From 52a8a00698baf463a9b421a294a403feec6fa483 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 8 Mar 2020 19:39:35 +0000 Subject: [PATCH] Add OriginalPcTable attribute decoder --- .../struct/attr/StructGeneralAttribute.java | 4 +++ .../attr/StructOriginalPcTableAttribute.java | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/org/jetbrains/java/decompiler/struct/attr/StructOriginalPcTableAttribute.java diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java index f421671..02ddbec 100644 --- a/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructGeneralAttribute.java @@ -34,6 +34,7 @@ public class StructGeneralAttribute { public static final Key ATTRIBUTE_DEPRECATED = new Key<>("Deprecated"); public static final Key ATTRIBUTE_LINE_NUMBER_TABLE = new Key<>("LineNumberTable"); public static final Key ATTRIBUTE_METHOD_PARAMETERS = new Key<>("MethodParameters"); + public static final Key ATTRIBUTE_ORIGINAL_PC_TABLE = new Key<>("OriginalPcTable"); public static class Key { private final String name; @@ -97,6 +98,9 @@ public class StructGeneralAttribute { else if (ATTRIBUTE_METHOD_PARAMETERS.getName().equals(name)) { attr = new StructMethodParametersAttribute(); } + else if (ATTRIBUTE_ORIGINAL_PC_TABLE.getName().equals(name)) { + attr = new StructOriginalPcTableAttribute(); + } else { // unsupported attribute return null; diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructOriginalPcTableAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructOriginalPcTableAttribute.java new file mode 100644 index 0000000..1c27ef2 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructOriginalPcTableAttribute.java @@ -0,0 +1,31 @@ +package org.jetbrains.java.decompiler.struct.attr; + +import org.jetbrains.java.decompiler.struct.consts.ConstantPool; +import org.jetbrains.java.decompiler.util.DataInputFullStream; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public final class StructOriginalPcTableAttribute extends StructGeneralAttribute { + private final Map pcs = new HashMap<>(); + + @Override + public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException { + int len = data.readUnsignedShort(); + + for (int i = 0; i < len; i++) { + int pc = data.readUnsignedShort(); + int originalPc = data.readUnsignedShort(); + pcs.put(pc, originalPc); + } + } + + public boolean hasOriginalPc(int pc) { + return pcs.containsKey(pc); + } + + public int getOriginalPc(int pc) { + return pcs.get(pc); + } +}