📄 aejarsigner2.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: AEJarSigner2.java
package org.gudy.azureus2.core3.util.jar;
import java.io.*;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.logging.LogAlert;
import org.gudy.azureus2.core3.logging.Logger;
import org.gudy.azureus2.core3.util.*;
public class AEJarSigner2
{
protected static Class JarSigner_class;
protected String keystore_name;
protected String keystore_password;
protected String alias;
public AEJarSigner2(String _alias, String _keystore_name, String _keystore_password)
{
alias = _alias;
keystore_name = _keystore_name;
keystore_password = _keystore_password;
}
protected void loadJarSigner()
throws IOException
{
String manual_tools_dir = COConfigurationManager.getStringParameter("Security.JAR.tools.dir");
File tools_dir;
if (manual_tools_dir.length() == 0)
{
String java_home = System.getProperty("java.home");
File jh = new File(java_home);
if (jh.getName().equalsIgnoreCase("jre"))
{
jh = jh.getParentFile();
} else
{
String dir_name = jh.getName();
if (dir_name.startsWith("jre"))
{
dir_name = (new StringBuilder()).append("jdk").append(dir_name.substring(3)).toString();
jh = new File(jh.getParentFile(), dir_name);
}
}
tools_dir = new File(jh, "lib");
} else
{
tools_dir = new File(manual_tools_dir);
}
File tools_jar = new File(tools_dir, "tools.jar");
if (tools_jar.exists())
{
try
{
ClassLoader cl = new URLClassLoader(new URL[] {
tools_jar.toURL()
}, org/gudy/azureus2/core3/util/jar/AEJarSigner2.getClassLoader());
JarSigner_class = cl.loadClass("sun.security.tools.JarSigner");
}
catch (Throwable e)
{
Logger.logTextResource(new LogAlert(false, 3, "Security.jar.signfail"), new String[] {
e.getMessage()
});
Debug.printStackTrace(e);
throw new IOException((new StringBuilder()).append("JAR signing fails: ").append(e.getMessage()).toString());
}
} else
{
Logger.logTextResource(new LogAlert(false, 3, "Security.jar.tools_not_found"), new String[] {
tools_dir.toString()
});
throw new IOException("JAR signing fails: tools.jar not found");
}
}
protected void signJarFile(File input_file)
throws IOException
{
PrintStream old_err;
PrintStream old_out;
String failure_msg;
if (JarSigner_class == null)
loadJarSigner();
old_err = null;
old_out = null;
failure_msg = null;
Object jar_signer = JarSigner_class.newInstance();
String args[] = {
"-keystore", keystore_name, "-storepass", keystore_password, input_file.toString(), alias
};
old_err = System.err;
old_out = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
System.setErr(ps);
System.setOut(ps);
try
{
JarSigner_class.getMethod("run", new Class[] {
[Ljava/lang/String;
}).invoke(jar_signer, new Object[] {
args
});
}
catch (Throwable e)
{
ps.close();
String err_msg = baos.toString();
if (err_msg.length() > 0)
{
failure_msg = err_msg;
} else
{
Debug.printStackTrace(e);
failure_msg = e.getMessage();
}
}
if (old_err != null)
{
System.setErr(old_err);
System.setOut(old_out);
}
break MISSING_BLOCK_LABEL_246;
Throwable e;
e;
Debug.printStackTrace(e);
failure_msg = e.getMessage();
if (old_err != null)
{
System.setErr(old_err);
System.setOut(old_out);
}
break MISSING_BLOCK_LABEL_246;
Exception exception;
exception;
if (old_err != null)
{
System.setErr(old_err);
System.setOut(old_out);
}
throw exception;
if (failure_msg != null)
{
Debug.out((new StringBuilder()).append("JAR signing fails '").append(failure_msg).append("'").toString());
Logger.logTextResource(new LogAlert(false, 3, "Security.jar.signfail"), new String[] {
failure_msg
});
throw new IOException((new StringBuilder()).append("JAR signing fails: ").append(failure_msg).toString());
} else
{
return;
}
}
public void signJarFile(File file, OutputStream os)
throws IOException
{
FileInputStream fis;
signJarFile(file);
fis = null;
fis = new FileInputStream(file);
FileUtil.copyFile(file, os, false);
try
{
if (fis != null)
fis.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
break MISSING_BLOCK_LABEL_67;
Exception exception;
exception;
try
{
if (fis != null)
fis.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
throw exception;
}
public void signJarStream(InputStream is, OutputStream os)
throws IOException
{
File temp_file;
FileOutputStream fos;
temp_file = AETemporaryFileHandler.createTempFile();
fos = null;
byte buffer[] = new byte[8192];
fos = new FileOutputStream(temp_file);
do
{
int len = is.read(buffer);
if (len <= 0)
break;
fos.write(buffer, 0, len);
} while (true);
fos.close();
fos = null;
signJarFile(temp_file, os);
try
{
is.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
if (fos != null)
try
{
fos.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
temp_file.delete();
break MISSING_BLOCK_LABEL_153;
Exception exception;
exception;
try
{
is.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
if (fos != null)
try
{
fos.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
temp_file.delete();
throw exception;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -