Skip to content

Commit

Permalink
Fix bug: array types are not rewritten when renaming classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanchon committed Nov 27, 2019
1 parent 8dfc94d commit c69cd60
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lanchon.dexpatcher.core.PatcherAnnotation;
import lanchon.dexpatcher.core.model.BasicClassDef;
import lanchon.dexpatcher.core.util.DexUtils;
import lanchon.dexpatcher.core.util.ElementalTypeRewriter;
import lanchon.dexpatcher.core.util.Id;
import lanchon.dexpatcher.core.util.Label;
import lanchon.dexpatcher.core.util.TypeName;
Expand Down Expand Up @@ -215,10 +216,10 @@ private static ClassDef renameClass(ClassDef classDef, final String to) {
DexRewriter rewriter = new DexRewriter(new RewriterModule() {
@Override
public Rewriter<String> getTypeRewriter(Rewriters rewriters) {
return new Rewriter<String>() {
return new ElementalTypeRewriter() {

@Override
public String rewrite(String value) {
public String rewriteElementalType(String elementalType) {
return from.equals(value) ? to : value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* DexPatcher - Copyright 2015-2019 Rodrigo Balerdi
* (GNU General Public License version 3 or later)
*
* DexPatcher is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*/

package lanchon.dexpatcher.core.util;

import org.jf.dexlib2.rewriter.TypeRewriter;

public abstract class ElementalTypeRewriter extends TypeRewriter {

@Override
public String rewrite(String value) {
int length = value.length();
if (length == 0 || value.charAt(0) != '[') return rewriteElementalType(value);
int start = 1;
while (start < length && value.charAt(start) == '[') start++;
String elementalType = value.substring(start);
String rewrittenElementalType = rewriteElementalType(elementalType);
if (rewrittenElementalType.equals(elementalType)) return value;
StringBuilder sb = new StringBuilder(start + rewrittenElementalType.length());
sb.append(value, 0, start).append(rewrittenElementalType);
return sb.toString();
}

public abstract String rewriteElementalType(String elementalType);

}

0 comments on commit c69cd60

Please # to comment.