Skip to content

Commit

Permalink
pull parser style xml values decoder #18
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed May 1, 2023
1 parent fea0583 commit c7c6863
Show file tree
Hide file tree
Showing 33 changed files with 1,491 additions and 615 deletions.
110 changes: 110 additions & 0 deletions src/main/java/com/reandroid/apk/ApkDecoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reandroid.apk;

import com.reandroid.archive.InputSource;
import com.reandroid.archive2.block.ApkSignatureBlock;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public abstract class ApkDecoder {
private final Set<String> mDecodedPaths;
private APKLogger apkLogger;
private boolean mLogErrors;

public ApkDecoder(){
mDecodedPaths = new HashSet<>();
}
public final void decodeTo(File outDir) throws IOException{
reset();
onDecodeTo(outDir);
}
abstract void onDecodeTo(File outDir) throws IOException;

boolean containsDecodedPath(String path){
return mDecodedPaths.contains(path);
}
void addDecodedPath(String path){
mDecodedPaths.add(path);
}
void writePathMap(File dir, Collection<? extends InputSource> sourceList) throws IOException {
PathMap pathMap = new PathMap();
pathMap.add(sourceList);
File file = new File(dir, PathMap.JSON_FILE);
pathMap.toJson().write(file);
}
void dumpSignatures(File outDir, ApkSignatureBlock signatureBlock) throws IOException {
if(signatureBlock == null){
return;
}
logMessage("Dumping signatures ...");
File dir = new File(outDir, ApkUtil.SIGNATURE_DIR_NAME);
signatureBlock.writeSplitRawToDirectory(dir);
}
void logOrThrow(String message, IOException exception) throws IOException{
if(isLogErrors()){
logError(message, exception);
return;
}
if(message == null && exception == null){
return;
}
if(exception == null){
exception = new IOException(message);
}
throw exception;
}
private void reset(){
mDecodedPaths.clear();
}

public boolean isLogErrors() {
return mLogErrors;
}
public void setLogErrors(boolean logErrors) {
this.mLogErrors = logErrors;
}

public void setApkLogger(APKLogger apkLogger) {
this.apkLogger = apkLogger;
}
APKLogger getApkLogger() {
return apkLogger;
}
void logMessage(String msg) {
APKLogger apkLogger = this.apkLogger;
if(apkLogger!=null){
apkLogger.logMessage(msg);
}
}
void logError(String msg, Throwable tr) {
APKLogger apkLogger = this.apkLogger;
if(apkLogger == null || (msg == null && tr == null)){
return;
}
apkLogger.logError(msg, tr);
}
void logVerbose(String msg) {
APKLogger apkLogger = this.apkLogger;
if(apkLogger!=null){
apkLogger.logVerbose(msg);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/reandroid/apk/ApkJsonDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ApkJsonDecoder(ApkModule apkModule){
this(apkModule, false);
}
public void sanitizeFilePaths(){
PathSanitizer sanitizer = new PathSanitizer(apkModule);
PathSanitizer sanitizer = PathSanitizer.create(apkModule);
sanitizer.sanitize();
}
public File writeToDirectory(File dir) throws IOException {
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/com/reandroid/apk/ApkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,7 @@ public String getSplit(){
}
return getAndroidManifestBlock().getSplit();
}
public FrameworkApk initializeAndroidFramework() throws IOException {
if(!hasTableBlock()){
return null;
}
Integer version = getAndroidFrameworkVersion();
return initializeAndroidFramework(getTableBlock(false), version);
}
private FrameworkApk initializeAndroidFramework(TableBlock tableBlock, Integer version) throws IOException {
public FrameworkApk initializeAndroidFramework(TableBlock tableBlock, Integer version) throws IOException {
if(tableBlock == null || isAndroid(tableBlock)){
return null;
}
Expand Down
Loading

0 comments on commit c7c6863

Please sign in to comment.