forked from skylot/jadx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: fix incorrect package for R class (skylot#99)
- Loading branch information
Showing
7 changed files
with
85 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
jadx-core/src/main/java/jadx/core/utils/android/AndroidResourcesUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package jadx.core.utils.android; | ||
|
||
import jadx.core.codegen.ClassGen; | ||
import jadx.core.codegen.CodeWriter; | ||
import jadx.core.dex.info.ClassInfo; | ||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.core.dex.nodes.DexNode; | ||
import jadx.core.dex.nodes.RootNode; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Android resources specific handlers | ||
*/ | ||
public class AndroidResourcesUtils { | ||
private static final Logger LOG = LoggerFactory.getLogger(AndroidResourcesUtils.class); | ||
|
||
public static ClassNode searchAppResClass(RootNode root) { | ||
String appPackage = root.getAppPackage(); | ||
String fullName = appPackage != null ? appPackage + ".R" : "R"; | ||
ClassNode resCls = root.searchClassByName(fullName); | ||
if (resCls != null) { | ||
return resCls; | ||
} | ||
List<ClassNode> candidates = root.searchClassByShortName("R"); | ||
if (candidates.size() == 1) { | ||
return candidates.get(0); | ||
} | ||
if (!candidates.isEmpty()) { | ||
LOG.info("Found several 'R' class candidates: {}", candidates); | ||
} | ||
LOG.warn("Unknown 'R' class, create references to '{}'", fullName); | ||
return makeClass(root, fullName); | ||
} | ||
|
||
public static boolean handleAppResField(CodeWriter code, ClassGen clsGen, ClassInfo declClass) { | ||
ClassInfo parentClass = declClass.getParentClass(); | ||
if (parentClass != null && parentClass.getShortName().equals("R")) { | ||
clsGen.useClass(code, parentClass); | ||
code.add('.'); | ||
code.add(declClass.getAlias().getShortName()); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private static ClassNode makeClass(RootNode root, String clsName) { | ||
DexNode firstDex = root.getDexNodes().get(0); | ||
ClassInfo r = ClassInfo.fromName(firstDex, clsName); | ||
return new ClassNode(firstDex, r); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters