core: use flag for mark 'this' register
This commit is contained in:
@@ -26,6 +26,7 @@ public enum AFlag {
|
||||
SKIP_ARG, // skip argument in invoke call
|
||||
ANONYMOUS_CONSTRUCTOR,
|
||||
ANONYMOUS_CLASS,
|
||||
THIS,
|
||||
|
||||
ELSE_IF_CHAIN,
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ public abstract class InsnArg extends Typed {
|
||||
}
|
||||
|
||||
public boolean isThis() {
|
||||
// must be implemented in RegisterArg and MthParameterArg
|
||||
// must be implemented in RegisterArg
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.Objects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import jadx.core.dex.attributes.AFlag;
|
||||
import jadx.core.dex.instructions.InsnType;
|
||||
import jadx.core.dex.instructions.PhiInsn;
|
||||
import jadx.core.dex.nodes.DexNode;
|
||||
@@ -118,7 +119,7 @@ public class RegisterArg extends InsnArg implements Named {
|
||||
|
||||
@Override
|
||||
public boolean isThis() {
|
||||
if ("this".equals(getName())) {
|
||||
if (contains(AFlag.THIS)) {
|
||||
return true;
|
||||
}
|
||||
// maybe it was moved from 'this' register
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TypeImmutableArg extends RegisterArg {
|
||||
|
||||
private boolean isThis;
|
||||
public static final String THIS_ARG_NAME = "this";
|
||||
|
||||
public TypeImmutableArg(int rn, ArgType type) {
|
||||
super(rn, type);
|
||||
@@ -20,48 +20,20 @@ public class TypeImmutableArg extends RegisterArg {
|
||||
// not allowed
|
||||
}
|
||||
|
||||
public void markAsThis() {
|
||||
this.isThis = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isThis() {
|
||||
return isThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (isThis) {
|
||||
return "this";
|
||||
if (isThis()) {
|
||||
return THIS_ARG_NAME;
|
||||
}
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
void setSVar(@NotNull SSAVar sVar) {
|
||||
if (isThis) {
|
||||
sVar.setName("this");
|
||||
if (isThis()) {
|
||||
sVar.setName(THIS_ARG_NAME);
|
||||
}
|
||||
sVar.setTypeImmutable(type);
|
||||
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 {
|
||||
}
|
||||
}
|
||||
initArguments(argsTypes);
|
||||
return true;
|
||||
} catch (JadxRuntimeException e) {
|
||||
LOG.error("Method signature parse error: {}", this, e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void initArguments(List<ArgType> args) {
|
||||
@@ -214,7 +214,7 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode {
|
||||
thisArg = null;
|
||||
} else {
|
||||
TypeImmutableArg arg = InsnArg.typeImmutableReg(pos - 1, parentClass.getClassInfo().getType());
|
||||
arg.markAsThis();
|
||||
arg.add(AFlag.THIS);
|
||||
thisArg = arg;
|
||||
}
|
||||
if (args.isEmpty()) {
|
||||
@@ -243,6 +243,7 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode {
|
||||
return argsList.remove(0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public RegisterArg getThisArg() {
|
||||
return thisArg;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ public class SSATransform extends AbstractVisitor {
|
||||
|
||||
fixLastAssignInTry(mth);
|
||||
removeBlockerInsns(mth);
|
||||
markThisArg(mth);
|
||||
|
||||
boolean repeatFix;
|
||||
int k = 0;
|
||||
@@ -405,4 +406,11 @@ public class SSATransform extends AbstractVisitor {
|
||||
InstructionRemover.unbindInsn(mth, phi);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void markThisArg(MethodNode mth) {
|
||||
RegisterArg thisArg = mth.getThisArg();
|
||||
if (thisArg != null) {
|
||||
thisArg.getSVar().getUseList().forEach(arg -> arg.add(AFlag.THIS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user