Commit 6cb14a1c authored by Skylot's avatar Skylot

core: use flag for mark 'this' register

parent ea9f933f
...@@ -26,6 +26,7 @@ public enum AFlag { ...@@ -26,6 +26,7 @@ public enum AFlag {
SKIP_ARG, // skip argument in invoke call SKIP_ARG, // skip argument in invoke call
ANONYMOUS_CONSTRUCTOR, ANONYMOUS_CONSTRUCTOR,
ANONYMOUS_CLASS, ANONYMOUS_CLASS,
THIS,
ELSE_IF_CHAIN, ELSE_IF_CHAIN,
......
...@@ -140,7 +140,7 @@ public abstract class InsnArg extends Typed { ...@@ -140,7 +140,7 @@ public abstract class InsnArg extends Typed {
} }
public boolean isThis() { public boolean isThis() {
// must be implemented in RegisterArg and MthParameterArg // must be implemented in RegisterArg
return false; return false;
} }
} }
...@@ -4,6 +4,7 @@ import java.util.Objects; ...@@ -4,6 +4,7 @@ import java.util.Objects;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.instructions.InsnType; import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.instructions.PhiInsn; import jadx.core.dex.instructions.PhiInsn;
import jadx.core.dex.nodes.DexNode; import jadx.core.dex.nodes.DexNode;
...@@ -118,7 +119,7 @@ public class RegisterArg extends InsnArg implements Named { ...@@ -118,7 +119,7 @@ public class RegisterArg extends InsnArg implements Named {
@Override @Override
public boolean isThis() { public boolean isThis() {
if ("this".equals(getName())) { if (contains(AFlag.THIS)) {
return true; return true;
} }
// maybe it was moved from 'this' register // maybe it was moved from 'this' register
......
...@@ -4,7 +4,7 @@ import org.jetbrains.annotations.NotNull; ...@@ -4,7 +4,7 @@ import org.jetbrains.annotations.NotNull;
public class TypeImmutableArg extends RegisterArg { public class TypeImmutableArg extends RegisterArg {
private boolean isThis; public static final String THIS_ARG_NAME = "this";
public TypeImmutableArg(int rn, ArgType type) { public TypeImmutableArg(int rn, ArgType type) {
super(rn, type); super(rn, type);
...@@ -20,48 +20,20 @@ public class TypeImmutableArg extends RegisterArg { ...@@ -20,48 +20,20 @@ public class TypeImmutableArg extends RegisterArg {
// not allowed // not allowed
} }
public void markAsThis() {
this.isThis = true;
}
@Override
public boolean isThis() {
return isThis;
}
@Override @Override
public String getName() { public String getName() {
if (isThis) { if (isThis()) {
return "this"; return THIS_ARG_NAME;
} }
return super.getName(); return super.getName();
} }
@Override @Override
void setSVar(@NotNull SSAVar sVar) { void setSVar(@NotNull SSAVar sVar) {
if (isThis) { if (isThis()) {
sVar.setName("this"); sVar.setName(THIS_ARG_NAME);
} }
sVar.setTypeImmutable(type); sVar.setTypeImmutable(type);
super.setSVar(sVar); super.setSVar(sVar);
} }
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof TypeImmutableArg)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
return isThis == ((TypeImmutableArg) obj).isThis;
}
@Override
public int hashCode() {
return 31 * super.hashCode() + (isThis ? 1 : 0);
}
} }
...@@ -193,11 +193,11 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode { ...@@ -193,11 +193,11 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode {
} }
} }
initArguments(argsTypes); initArguments(argsTypes);
return true;
} catch (JadxRuntimeException e) { } catch (JadxRuntimeException e) {
LOG.error("Method signature parse error: {}", this, e); LOG.error("Method signature parse error: {}", this, e);
return false; return false;
} }
return true;
} }
private void initArguments(List<ArgType> args) { private void initArguments(List<ArgType> args) {
...@@ -214,7 +214,7 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode { ...@@ -214,7 +214,7 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode {
thisArg = null; thisArg = null;
} else { } else {
TypeImmutableArg arg = InsnArg.typeImmutableReg(pos - 1, parentClass.getClassInfo().getType()); TypeImmutableArg arg = InsnArg.typeImmutableReg(pos - 1, parentClass.getClassInfo().getType());
arg.markAsThis(); arg.add(AFlag.THIS);
thisArg = arg; thisArg = arg;
} }
if (args.isEmpty()) { if (args.isEmpty()) {
...@@ -243,6 +243,7 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode { ...@@ -243,6 +243,7 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode {
return argsList.remove(0); return argsList.remove(0);
} }
@Nullable
public RegisterArg getThisArg() { public RegisterArg getThisArg() {
return thisArg; return thisArg;
} }
......
...@@ -53,6 +53,7 @@ public class SSATransform extends AbstractVisitor { ...@@ -53,6 +53,7 @@ public class SSATransform extends AbstractVisitor {
fixLastAssignInTry(mth); fixLastAssignInTry(mth);
removeBlockerInsns(mth); removeBlockerInsns(mth);
markThisArg(mth);
boolean repeatFix; boolean repeatFix;
int k = 0; int k = 0;
...@@ -405,4 +406,11 @@ public class SSATransform extends AbstractVisitor { ...@@ -405,4 +406,11 @@ public class SSATransform extends AbstractVisitor {
InstructionRemover.unbindInsn(mth, phi); InstructionRemover.unbindInsn(mth, phi);
return true; return true;
} }
private static void markThisArg(MethodNode mth) {
RegisterArg thisArg = mth.getThisArg();
if (thisArg != null) {
thisArg.getSVar().getUseList().forEach(arg -> arg.add(AFlag.THIS));
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment