Skip to content

Commit

Permalink
fix: handle incorrect args count in signature (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 17, 2019
1 parent d3ecc1f commit 00f5e83
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
53 changes: 39 additions & 14 deletions jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,28 +199,39 @@ private List<ArgType> parseSignature() {
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) {
Expand Down Expand Up @@ -687,6 +698,20 @@ public void addWarn(String warnStr) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ private static String mergeSignature(List<String> list) {
return sb.toString();
}

public String getSignature() {
return sign;
}

private String debugString() {
if (pos >= sign.length()) {
return sign;
Expand Down

0 comments on commit 00f5e83

Please sign in to comment.