不好意思,现在才有时间回复, Java伪加密和安卓上的java伪加密有不同,但也有类似之处,都可以使用zip使其看起来好像被压缩加密了,现把看雪的代码粘帖上来:
package com.rover12421.apkutil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.zip.ZipError;
import static com.rover12421.apkutil.ZipConstants.*;
public class ApkUtilTool {
private FileChannel ch; // channel to the zipfile
private FileChannel fc;
/**
* 修复zip伪加密状态的Entry
* @param inZip
* @param storeZip
* @throws IOException
*/
public void FixEncryptedEntry(File inZip, File fixZip) throws IOException {
changEntry(inZip, fixZip, true);
}
/**
* 修复zip伪加密状态的Entry
* @param inZip
* @param storeZip
* @throws IOException
*/
public void FixEncryptedEntry(String inZip, String fixZip) throws IOException {
FixEncryptedEntry(new File(inZip), new File(fixZip));
}
/**
* 修改zip的Entry为伪加密状态
* @param inZip
* @param storeZip
* @throws IOException
*/
public void ChangToEncryptedEntry(File inZip, File storeZip) throws IOException {
changEntry(inZip, storeZip, false);
}
/**
* 修改zip的Entry为伪加密状态
* @param inZip
* @param storeZip
* @throws IOException
*/
public void ChangToEncryptedEntry(String inZip, String storeZip) throws IOException {
ChangToEncryptedEntry(new File(inZip), new File(storeZip));
}
/**
* 更改zip的Entry为伪加密状态
* @param inZip
* @param storeZip
* @param fix ture:修复伪加密 false:更改到伪加密
* @throws IOException
*/
private void changEntry(File inZip, File storeZip, boolean fix) throws IOException {
FileInputStream fis = new FileInputStream(inZip);
FileOutputStream fos = new FileOutputStream(storeZip);
byte[] buf = new byte[10240];
int len;
while ((len = fis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
ch = fis.getChannel();
fc = fos.getChannel();
changEntry(fix);
ch.close();
fc.close();
fis.close();
fos.close();
}
// Reads zip file central directory. Returns the file position of first
// CEN header, otherwise returns -1 if an error occured. If zip->msg != NULL
// then the error was a zip format error and zip->msg has the error text.
// Always pass in -1 for knownTotal; it's used for a recursive call.
private void changEntry(boolean fix) throws IOException {
END end = findEND();
if (end.cenlen > end.endpos)
zerror("invalid END header (bad central directory size)");
long cenpos = end.endpos - end.cenlen; // position of CEN table
// Get position of first local file (LOC) header, taking into
// account that there may be a stub prefixed to the zip file.
long locpos = cenpos - end.cenoff;
if (locpos < 0)
zerror("invalid END header (bad central directory offset)");
// read in the CEN and END
byte[] cen = new byte[(int)(end.cenlen + ENDHDR)];
if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen + ENDHDR) {
zerror("read CEN tables failed");
}
int pos = 0;
int limit = cen.length - ENDHDR;
while (pos < limit) {
if (CENSIG(cen, pos) != CENSIG)
zerror("invalid CEN header (bad signature)");
int method = CENHOW(cen, pos);
int nlen = CENNAM(cen, pos);
int elen = CENEXT(cen, pos);
int clen = CENCOM(cen, pos);
if (fix) {
if ((CEN***(cen, pos) & 1) != 0) {
byte[] name = Arrays.copyOfRange(cen, pos + CENHDR, pos + CENHDR + nlen);
System.out.println("Found the encrypted entry : " + new String(name) + ", fix...");
//b[n] & 0xff) | ((b[n + 1] & 0xff) << 8
cen[pos+8] &= 0xFE;
// |