fix: handle incorrect args count in signature (#763)
This commit is contained in:
@@ -199,28 +199,39 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode {
|
||||
if (argsTypes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (!mthInfo.isConstructor()) {
|
||||
LOG.warn("Wrong signature parse result: {} -> {}, not generic version: {}", sp, argsTypes, mthArgs);
|
||||
return null;
|
||||
} else if (getParentClass().getAccessFlags().isEnum()) {
|
||||
// TODO:
|
||||
argsTypes.add(0, mthArgs.get(0));
|
||||
argsTypes.add(1, mthArgs.get(1));
|
||||
} else {
|
||||
// add synthetic arg for outer class
|
||||
argsTypes.add(0, mthArgs.get(0));
|
||||
}
|
||||
if (argsTypes.size() != mthArgs.size()) {
|
||||
if (!tryFixArgsCounts(argsTypes, mthArgs)) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Incorrect method signature, types: ({}), method: {}", Utils.listToString(argsTypes), this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return argsTypes;
|
||||
} catch (JadxRuntimeException e) {
|
||||
LOG.error("Method signature parse error: {}", this, e);
|
||||
} catch (Exception e) {
|
||||
addWarningComment("Failed to parse method signature: " + sp.getSignature(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean tryFixArgsCounts(List<ArgType> argsTypes, List<ArgType> mthArgs) {
|
||||
if (!mthInfo.isConstructor()) {
|
||||
return false;
|
||||
}
|
||||
if (getParentClass().getAccessFlags().isEnum()) {
|
||||
if (mthArgs.size() >= 2) {
|
||||
// TODO:
|
||||
argsTypes.add(0, mthArgs.get(0));
|
||||
argsTypes.add(1, mthArgs.get(1));
|
||||
}
|
||||
} else {
|
||||
if (!mthArgs.isEmpty()) {
|
||||
// add synthetic arg for outer class
|
||||
argsTypes.add(0, mthArgs.get(0));
|
||||
}
|
||||
}
|
||||
return argsTypes.size() == mthArgs.size();
|
||||
}
|
||||
|
||||
private void initArguments(List<ArgType> args) {
|
||||
int pos;
|
||||
if (noCode) {
|
||||
@@ -687,6 +698,20 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode {
|
||||
ErrorsCounter.methodWarn(this, warnStr);
|
||||
}
|
||||
|
||||
public void addWarningComment(String warn) {
|
||||
addWarningComment(warn, null);
|
||||
}
|
||||
|
||||
public void addWarningComment(String warn, @Nullable Throwable exc) {
|
||||
String commentStr = "JADX WARN: " + warn;
|
||||
addAttr(AType.COMMENTS, commentStr);
|
||||
if (exc != null) {
|
||||
LOG.warn("{} in {}", warn, this, exc);
|
||||
} else {
|
||||
LOG.warn("{} in {}", warn, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void addComment(String commentStr) {
|
||||
addAttr(AType.COMMENTS, commentStr);
|
||||
LOG.info("{} in {}", commentStr, this);
|
||||
|
||||
@@ -292,6 +292,10 @@ public class SignatureParser {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
private String debugString() {
|
||||
if (pos >= sign.length()) {
|
||||
return sign;
|
||||
|
||||
Reference in New Issue
Block a user