mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-01 14:44:26 +02:00
cleanup formatting in smali-res-tagger
- experiment rewriting resIds in smali to remove need of public.xml
This commit is contained in:
parent
dc2db53dec
commit
1d485d21e9
@ -47,15 +47,8 @@ public class ResSmaliUpdater {
|
|||||||
for (String fileName : dir.getFiles(true)) {
|
for (String fileName : dir.getFiles(true)) {
|
||||||
try {
|
try {
|
||||||
tagResIdsForFile(resTable, dir, fileName);
|
tagResIdsForFile(resTable, dir, fileName);
|
||||||
} catch (IOException ex) {
|
} catch (IOException | DirectoryException | AndrolibException ex) {
|
||||||
throw new AndrolibException("Could not tag resIDs for file: "
|
throw new AndrolibException("Could not tag resIDs for file: " + fileName, ex);
|
||||||
+ fileName, ex);
|
|
||||||
} catch (DirectoryException ex) {
|
|
||||||
throw new AndrolibException("Could not tag resIDs for file: "
|
|
||||||
+ fileName, ex);
|
|
||||||
} catch (AndrolibException ex) {
|
|
||||||
throw new AndrolibException("Could not tag resIDs for file: "
|
|
||||||
+ fileName, ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,47 +58,36 @@ public class ResSmaliUpdater {
|
|||||||
try {
|
try {
|
||||||
Directory dir = new FileDirectory(smaliDir);
|
Directory dir = new FileDirectory(smaliDir);
|
||||||
for (String fileName : dir.getFiles(true)) {
|
for (String fileName : dir.getFiles(true)) {
|
||||||
Iterator<String> it = IOUtils.readLines(
|
Iterator<String> it = IOUtils.readLines(dir.getFileInput(fileName)).iterator();
|
||||||
dir.getFileInput(fileName)).iterator();
|
|
||||||
PrintWriter out = new PrintWriter(dir.getFileOutput(fileName));
|
PrintWriter out = new PrintWriter(dir.getFileOutput(fileName));
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
String line = it.next();
|
String line = it.next();
|
||||||
out.println(line);
|
out.println(line);
|
||||||
Matcher m1 = RES_NAME_PATTERN.matcher(line);
|
Matcher m1 = RES_NAME_PATTERN.matcher(line);
|
||||||
if (!m1.matches()) {
|
if (! m1.matches()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Matcher m2 = RES_ID_PATTERN.matcher(it.next());
|
Matcher m2 = RES_ID_PATTERN.matcher(it.next());
|
||||||
if (!m2.matches()) {
|
if (! m2.matches()) {
|
||||||
throw new AndrolibException();
|
throw new AndrolibException();
|
||||||
}
|
}
|
||||||
int resID = resTable.getPackage(m1.group(1))
|
int resID = resTable.getPackage(m1.group(1)).getType(m1.group(2)).getResSpec(m1.group(3)).getId().id;
|
||||||
.getType(m1.group(2)).getResSpec(m1.group(3))
|
|
||||||
.getId().id;
|
|
||||||
if (m2.group(1) != null) {
|
if (m2.group(1) != null) {
|
||||||
out.println(String.format(RES_ID_FORMAT_FIELD,
|
out.println(String.format(RES_ID_FORMAT_FIELD, m2.group(1), resID));
|
||||||
m2.group(1), resID));
|
|
||||||
} else {
|
} else {
|
||||||
out.println(String.format(RES_ID_FORMAT_CONST,
|
out.println(String.format(RES_ID_FORMAT_CONST, m2.group(2), resID));
|
||||||
m2.group(2), resID));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException | DirectoryException ex) {
|
||||||
throw new AndrolibException("Could not tag res IDs for: "
|
throw new AndrolibException("Could not tag res IDs for: " + smaliDir.getAbsolutePath(), ex);
|
||||||
+ smaliDir.getAbsolutePath(), ex);
|
|
||||||
} catch (DirectoryException ex) {
|
|
||||||
throw new AndrolibException("Could not tag res IDs for: "
|
|
||||||
+ smaliDir.getAbsolutePath(), ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tagResIdsForFile(ResTable resTable, Directory dir,
|
private void tagResIdsForFile(ResTable resTable, Directory dir, String fileName)
|
||||||
String fileName) throws IOException, DirectoryException,
|
throws IOException, DirectoryException, AndrolibException {
|
||||||
AndrolibException {
|
Iterator<String> it = IOUtils.readLines(dir.getFileInput(fileName)).iterator();
|
||||||
Iterator<String> it = IOUtils.readLines(dir.getFileInput(fileName))
|
|
||||||
.iterator();
|
|
||||||
PrintWriter out = new PrintWriter(dir.getFileOutput(fileName));
|
PrintWriter out = new PrintWriter(dir.getFileOutput(fileName));
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
String line = it.next();
|
String line = it.next();
|
||||||
@ -120,13 +102,10 @@ public class ResSmaliUpdater {
|
|||||||
if (resID != -1) {
|
if (resID != -1) {
|
||||||
try {
|
try {
|
||||||
ResResSpec spec = resTable.getResSpec(resID);
|
ResResSpec spec = resTable.getResSpec(resID);
|
||||||
out.println(String.format(RES_NAME_FORMAT,
|
out.println(String.format(RES_NAME_FORMAT, spec.getFullName()));
|
||||||
spec.getFullName()));
|
|
||||||
} catch (UndefinedResObject ex) {
|
} catch (UndefinedResObject ex) {
|
||||||
if (!R_FILE_PATTERN.matcher(fileName).matches()) {
|
if (!R_FILE_PATTERN.matcher(fileName).matches()) {
|
||||||
LOGGER.warning(String.format(
|
LOGGER.warning(String.format("Undefined resource spec in %s: 0x%08x", fileName, resID));
|
||||||
"Undefined resource spec in %s: 0x%08x",
|
|
||||||
fileName, resID));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,8 +128,10 @@ public class ResSmaliUpdater {
|
|||||||
|
|
||||||
private final static String RES_ID_FORMAT_FIELD = ".field %s:I = 0x%08x";
|
private final static String RES_ID_FORMAT_FIELD = ".field %s:I = 0x%08x";
|
||||||
private final static String RES_ID_FORMAT_CONST = " const %s, 0x%08x";
|
private final static String RES_ID_FORMAT_CONST = " const %s, 0x%08x";
|
||||||
|
|
||||||
private final static Pattern RES_ID_PATTERN = Pattern
|
private final static Pattern RES_ID_PATTERN = Pattern
|
||||||
.compile("^(?:\\.field (.+?):I =| const(?:|/(?:|high)16) ([pv]\\d+?),) 0x(7[a-f]0[1-9a-f](?:|[0-9a-f]{4}))$");
|
.compile("^(?:\\.field (.+?):I =| const(?:|/(?:|high)16) ([pv]\\d+?),) 0x(7[a-f]0[1-9a-f](?:|[0-9a-f]{4}))$");
|
||||||
|
|
||||||
private final static String RES_NAME_FORMAT = "# APKTOOL/RES_NAME: %s";
|
private final static String RES_NAME_FORMAT = "# APKTOOL/RES_NAME: %s";
|
||||||
private final static Pattern RES_NAME_PATTERN = Pattern
|
private final static Pattern RES_NAME_PATTERN = Pattern
|
||||||
.compile("^# APKTOOL/RES_NAME: ([a-zA-Z0-9.]+):([a-z]+)/([a-zA-Z0-9._]+)$");
|
.compile("^# APKTOOL/RES_NAME: ([a-zA-Z0-9.]+):([a-z]+)/([a-zA-Z0-9._]+)$");
|
||||||
@ -158,6 +139,5 @@ public class ResSmaliUpdater {
|
|||||||
private final static Pattern R_FILE_PATTERN = Pattern
|
private final static Pattern R_FILE_PATTERN = Pattern
|
||||||
.compile(".*R\\$[a-z]+\\.smali$");
|
.compile(".*R\\$[a-z]+\\.smali$");
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger.getLogger(ResSmaliUpdater.class
|
private final static Logger LOGGER = Logger.getLogger(ResSmaliUpdater.class.getName());
|
||||||
.getName());
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user