From 2bf9bb4e9b855eedef893b7ae7b02adbac08f17b Mon Sep 17 00:00:00 2001 From: Graham Date: Fri, 3 Jul 2020 20:30:41 +0100 Subject: [PATCH] Use mapped local variable names from the OriginalPcTable --- .../modules/decompiler/exps/VarExprent.java | 5 ++++ .../attr/StructOriginalPcTableAttribute.java | 28 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java index 665b5d1..1c86bb4 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java @@ -123,6 +123,11 @@ public class VarExprent extends Exprent { buffer.append('('); buffer.append(Integer.toString(pc)); buffer.append(") "); + + if (originalPcTable.hasName(pc) && processor != null) { + name = originalPcTable.getName(pc); + processor.setVarName(varVersion, name); + } } } diff --git a/src/org/jetbrains/java/decompiler/struct/attr/StructOriginalPcTableAttribute.java b/src/org/jetbrains/java/decompiler/struct/attr/StructOriginalPcTableAttribute.java index 1c27ef2..ef23cf8 100644 --- a/src/org/jetbrains/java/decompiler/struct/attr/StructOriginalPcTableAttribute.java +++ b/src/org/jetbrains/java/decompiler/struct/attr/StructOriginalPcTableAttribute.java @@ -1,6 +1,7 @@ package org.jetbrains.java.decompiler.struct.attr; import org.jetbrains.java.decompiler.struct.consts.ConstantPool; +import org.jetbrains.java.decompiler.struct.consts.PrimitiveConstant; import org.jetbrains.java.decompiler.util.DataInputFullStream; import java.io.IOException; @@ -9,16 +10,31 @@ import java.util.Map; public final class StructOriginalPcTableAttribute extends StructGeneralAttribute { private final Map pcs = new HashMap<>(); + private final Map names = new HashMap<>(); @Override public void initContent(DataInputFullStream data, ConstantPool pool) throws IOException { - int len = data.readUnsignedShort(); + int pcsLen = data.readUnsignedShort(); - for (int i = 0; i < len; i++) { + for (int i = 0; i < pcsLen; i++) { int pc = data.readUnsignedShort(); int originalPc = data.readUnsignedShort(); pcs.put(pc, originalPc); } + + int namesLen = data.readUnsignedShort(); + + for (int i = 0; i < namesLen; i++) { + int originalPc = data.readUnsignedShort(); + + PrimitiveConstant constant = pool.getPrimitiveConstant(data.readUnsignedShort()); + if (constant.type != PrimitiveConstant.CONSTANT_Utf8) { + throw new IllegalArgumentException(); + } + + String name = (String) constant.value; + names.put(originalPc, name); + } } public boolean hasOriginalPc(int pc) { @@ -28,4 +44,12 @@ public final class StructOriginalPcTableAttribute extends StructGeneralAttribute public int getOriginalPc(int pc) { return pcs.get(pc); } + + public boolean hasName(int originalPc) { + return names.containsKey(originalPc); + } + + public String getName(int originalPc) { + return names.get(originalPc); + } }