This repository has been archived by the owner on Sep 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dongliu
committed
Jun 12, 2018
1 parent
9ef1070
commit 666cc64
Showing
10 changed files
with
259 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
package net.dongliu.apk.parser; | ||
|
||
import net.dongliu.apk.parser.bean.IconFace; | ||
|
||
import java.io.IOException; | ||
import java.security.cert.CertificateException; | ||
import java.util.List; | ||
|
||
/** | ||
* Main method for parser apk | ||
* | ||
* @author Liu Dong {@literal <[email protected]>} | ||
*/ | ||
public class Main { | ||
public static void main(String[] args) throws IOException, CertificateException { | ||
public static void main(String[] args) throws IOException { | ||
try (ApkFile apkFile = new ApkFile(args[0])) { | ||
System.out.println(apkFile.getApkSingers().get(0).getCertificateMetas()); | ||
List<IconFace> allIcons = apkFile.getAllIcons(); | ||
System.out.println(allIcons); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/net/dongliu/apk/parser/bean/AdaptiveIcon.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 net.dongliu.apk.parser.bean; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Android adaptive icon, from android 8.0 | ||
*/ | ||
public class AdaptiveIcon implements IconFace, Serializable { | ||
private static final long serialVersionUID = 4185750290211529320L; | ||
private final Icon foreground; | ||
private final Icon background; | ||
|
||
public AdaptiveIcon(Icon foreground, Icon background) { | ||
this.foreground = foreground; | ||
this.background = background; | ||
} | ||
|
||
|
||
/** | ||
* The foreground icon | ||
*/ | ||
public Icon getForeground() { | ||
return foreground; | ||
} | ||
|
||
/** | ||
* The background icon | ||
*/ | ||
public Icon getBackground() { | ||
return background; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AdaptiveIcon{" + | ||
"foreground=" + foreground + | ||
", background=" + background + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean isFile() { | ||
return foreground.isFile(); | ||
} | ||
|
||
@Override | ||
public byte[] getData() { | ||
return foreground.getData(); | ||
} | ||
|
||
@Override | ||
public String getPath() { | ||
return foreground.getPath(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.dongliu.apk.parser.bean; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* The plain icon, using color drawable resource. | ||
*/ | ||
//to be implemented | ||
public class ColorIcon implements IconFace, Serializable { | ||
private static final long serialVersionUID = -7913024425268466186L; | ||
|
||
@Override | ||
public boolean isFile() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public byte[] getData() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public String getPath() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.dongliu.apk.parser.bean; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* The icon interface | ||
*/ | ||
public interface IconFace extends Serializable { | ||
|
||
/** | ||
* If icon is file resource | ||
*/ | ||
boolean isFile(); | ||
|
||
/** | ||
* Return the icon file as bytes. This method is valid only when {@link #isFile()} return true. | ||
* Otherwise, {@link UnsupportedOperationException} should be thrown. | ||
*/ | ||
byte[] getData(); | ||
|
||
|
||
/** | ||
* Return the icon file path in apk file. This method is valid only when {@link #isFile()} return true. | ||
* Otherwise, {@link UnsupportedOperationException} should be thrown. | ||
*/ | ||
String getPath(); | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/net/dongliu/apk/parser/parser/AdaptiveIconParser.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,61 @@ | ||
package net.dongliu.apk.parser.parser; | ||
|
||
import net.dongliu.apk.parser.struct.xml.*; | ||
|
||
/** | ||
* Parse adaptive icon xml file. | ||
* | ||
* @author Liu Dong [email protected] | ||
*/ | ||
public class AdaptiveIconParser implements XmlStreamer { | ||
|
||
private String foreground; | ||
private String background; | ||
|
||
public String getForeground() { | ||
return foreground; | ||
} | ||
|
||
public String getBackground() { | ||
return background; | ||
} | ||
|
||
@Override | ||
public void onStartTag(XmlNodeStartTag xmlNodeStartTag) { | ||
if (xmlNodeStartTag.getName().equals("background")) { | ||
background = getDrawable(xmlNodeStartTag); | ||
} else if (xmlNodeStartTag.getName().equals("foreground")) { | ||
foreground = getDrawable(xmlNodeStartTag); | ||
} | ||
} | ||
|
||
private String getDrawable(XmlNodeStartTag xmlNodeStartTag) { | ||
Attributes attributes = xmlNodeStartTag.getAttributes(); | ||
for (Attribute attribute : attributes.values()) { | ||
if (attribute.getName().equals("drawable")) { | ||
return attribute.getValue(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void onEndTag(XmlNodeEndTag xmlNodeEndTag) { | ||
|
||
} | ||
|
||
@Override | ||
public void onCData(XmlCData xmlCData) { | ||
|
||
} | ||
|
||
@Override | ||
public void onNamespaceStart(XmlNamespaceStartTag tag) { | ||
|
||
} | ||
|
||
@Override | ||
public void onNamespaceEnd(XmlNamespaceEndTag tag) { | ||
|
||
} | ||
} |