Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
add Main
Browse files Browse the repository at this point in the history
  • Loading branch information
Dong Liu committed Apr 25, 2015
1 parent 6b40c09 commit 214618b
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 59 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.idea/
*.iml
target/
TestMain.java
18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<developers>
<developer>
<id>xiaxiaocao</id>
<name>Dong Liu</name>
<email>[email protected]</email>
<name>Liu Dong</name>
<email>[email protected]</email>
</developer>
</developers>

Expand Down Expand Up @@ -100,8 +100,20 @@
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>net.dongliu.apk.parser.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>

</build>

<profiles>
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/net/dongliu/apk/parser/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.dongliu.apk.parser;

import net.dongliu.apk.parser.bean.CertificateMeta;

import java.io.IOException;
import java.security.cert.CertificateException;
import java.util.List;
import java.util.Locale;

/**
* Main method for parser apk
*
* @author Liu Dong {@literal <[email protected]>}
*/
public class Main {
public static void main(String[] args) throws IOException, CertificateException {
String apkFile = args[0];
try (ApkParser parser = new ApkParser(apkFile)) {
parser.setPreferredLocale(Locale.SIMPLIFIED_CHINESE);
System.out.println(parser.getApkMeta());
List<CertificateMeta> certList = parser.getCertificateMetaList();
for (CertificateMeta certificateMeta : certList) {
System.out.println(certificateMeta);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* attribute value constant
*
* @author Dong Liu
* @author Liu Dong
*/
public class AttributeValues {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Date;

/**
* basic certificate infos.
* basic certificate info.
*
* @author dongliu
*/
Expand Down Expand Up @@ -108,9 +108,8 @@ public void setSignAlgorithmOID(String signAlgorithmOID) {

@Override
public String toString() {
return "sign algorithm:\t" + signAlgorithm + "\n" +
"startDate:\t" + startDate + "\n" +
"endDate:\t" + endDate + "\n" +
return "signAlgorithm:\t" + signAlgorithm + '\n' +
"certBase64Md5:\t" + certBase64Md5 + '\n' +
"certMd5:\t" + certMd5;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/dongliu/apk/parser/bean/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* The apk icon file path, and data
*
* @author Dong Liu
* @author Liu Dong
*/
public class Icon {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/dongliu/apk/parser/bean/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* permission provided by the app
*
* @author Dong Liu
* @author Liu Dong
*/
public class Permission {
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* trans binary xml to text
*
* @author Dong Liu [email protected]
* @author Liu Dong [email protected]
*/
public class ApkMetaTranslator implements XmlStreamer {
private String[] tagStack = new String[100];
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/dongliu/apk/parser/utils/Buffers.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* utils method for byte buffer
*
* @author Dong Liu [email protected]
* @author Liu Dong [email protected]
*/
public class Buffers {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* fetch dependency resource file from android source
*
* @author Dong Liu [email protected]
* @author Liu Dong [email protected]
*/
public class ResourceFetcher {

Expand Down
46 changes: 1 addition & 45 deletions src/main/java/net/dongliu/apk/parser/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,18 @@ public class Utils {
public static byte[] toByteArray(InputStream in) throws IOException {
try {
byte[] buf = new byte[1024];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
int len;
while ((len = in.read(buf)) != -1) {
bos.write(buf, 0, len);
}
return bos.toByteArray();
} finally {
bos.close();
}
} finally {
in.close();
}
}

public static String toString(InputStream in) throws IOException {
return new String(toByteArray(in), "UTF-8");
}

public static String toString(InputStream in, String encoding) throws IOException {
return new String(toByteArray(in), encoding);
}

public static long toLong(String value) {
try {
return Long.valueOf(value);
} catch (Exception e) {
return 0;
}
}

public static int toInt(String value) {
try {
return Integer.valueOf(value);
} catch (Exception e) {
return 0;
}
}

public static String between(String text, String begin, String end) {
if (text == null) {
return null;
}
int idx = text.indexOf(begin);
if (idx < 0) {
idx = 0;
} else {
idx = idx + begin.length();
}
int eidx = text.indexOf(end, idx);
if (eidx < 0) {
eidx = 0;
}
return text.substring(idx, eidx);
}

public static ZipArchiveEntry getEntry(ZipFile zf, String path) {
Enumeration<ZipArchiveEntry> enu = zf.getEntries();
while (enu.hasMoreElements()) {
Expand Down

0 comments on commit 214618b

Please sign in to comment.