use of java.util.jar.JarFile in project android_frameworks_base by ParanoidAndroid.
the class PackageParser method collectCertificates.
public boolean collectCertificates(Package pkg, int flags) {
pkg.mSignatures = null;
WeakReference<byte[]> readBufferRef;
byte[] readBuffer = null;
synchronized (mSync) {
readBufferRef = mReadBuffer;
if (readBufferRef != null) {
mReadBuffer = null;
readBuffer = readBufferRef.get();
}
if (readBuffer == null) {
readBuffer = new byte[8192];
readBufferRef = new WeakReference<byte[]>(readBuffer);
}
}
try {
JarFile jarFile = new JarFile(mArchiveSourcePath);
Certificate[] certs = null;
if ((flags & PARSE_IS_SYSTEM) != 0) {
// If this package comes from the system image, then we
// can trust it... we'll just use the AndroidManifest.xml
// to retrieve its signatures, not validating all of the
// files.
JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
certs = loadCertificates(jarFile, jarEntry, readBuffer);
if (certs == null) {
Slog.e(TAG, "Package " + pkg.packageName + " has no certificates at entry " + jarEntry.getName() + "; ignoring!");
jarFile.close();
mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
return false;
}
if (DEBUG_JAR) {
Slog.i(TAG, "File " + mArchiveSourcePath + ": entry=" + jarEntry + " certs=" + (certs != null ? certs.length : 0));
if (certs != null) {
final int N = certs.length;
for (int i = 0; i < N; i++) {
Slog.i(TAG, " Public key: " + certs[i].getPublicKey().getEncoded() + " " + certs[i].getPublicKey());
}
}
}
} else {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
final JarEntry je = entries.nextElement();
if (je.isDirectory())
continue;
final String name = je.getName();
if (name.startsWith("META-INF/"))
continue;
if (ANDROID_MANIFEST_FILENAME.equals(name)) {
pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
}
final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
if (DEBUG_JAR) {
Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName() + ": certs=" + certs + " (" + (certs != null ? certs.length : 0) + ")");
}
if (localCerts == null) {
Slog.e(TAG, "Package " + pkg.packageName + " has no certificates at entry " + je.getName() + "; ignoring!");
jarFile.close();
mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
return false;
} else if (certs == null) {
certs = localCerts;
} else {
// Ensure all certificates match.
for (int i = 0; i < certs.length; i++) {
boolean found = false;
for (int j = 0; j < localCerts.length; j++) {
if (certs[i] != null && certs[i].equals(localCerts[j])) {
found = true;
break;
}
}
if (!found || certs.length != localCerts.length) {
Slog.e(TAG, "Package " + pkg.packageName + " has mismatched certificates at entry " + je.getName() + "; ignoring!");
jarFile.close();
mParseError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
return false;
}
}
}
}
}
jarFile.close();
synchronized (mSync) {
mReadBuffer = readBufferRef;
}
if (certs != null && certs.length > 0) {
final int N = certs.length;
pkg.mSignatures = new Signature[certs.length];
for (int i = 0; i < N; i++) {
pkg.mSignatures[i] = new Signature(certs[i].getEncoded());
}
} else {
Slog.e(TAG, "Package " + pkg.packageName + " has no certificates; ignoring!");
mParseError = PackageManager.INSTALL_PARSE_FAILED_NO_CERTIFICATES;
return false;
}
} catch (CertificateEncodingException e) {
Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
return false;
} catch (IOException e) {
Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
return false;
} catch (RuntimeException e) {
Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
return false;
}
return true;
}
use of java.util.jar.JarFile in project pinpoint by naver.
the class PinpointBootStrap method appendToBootstrapClassLoader.
private static void appendToBootstrapClassLoader(Instrumentation instrumentation, BootstrapJarFile agentJarFile) {
List<JarFile> jarFileList = agentJarFile.getJarFileList();
for (JarFile jarFile : jarFileList) {
logger.info("appendToBootstrapClassLoader:" + jarFile.getName());
instrumentation.appendToBootstrapClassLoaderSearch(jarFile);
}
}
use of java.util.jar.JarFile in project pinpoint by naver.
the class ProfilerPluginLoader method load.
public List<SetupResult> load(URL[] pluginJars) {
List<SetupResult> pluginContexts = new ArrayList<SetupResult>(pluginJars.length);
for (URL pluginJar : pluginJars) {
final JarFile pluginJarFile = createJarFile(pluginJar);
final List<String> pluginPackageList = getPluginPackage(pluginJarFile);
final ClassNameFilter pluginFilterChain = createPluginFilterChain(pluginPackageList);
final List<ProfilerPlugin> original = PluginLoader.load(ProfilerPlugin.class, new URL[] { pluginJar });
List<ProfilerPlugin> plugins = filterDisablePlugin(original);
for (ProfilerPlugin plugin : plugins) {
if (logger.isInfoEnabled()) {
logger.info("{} Plugin {}:{}", plugin.getClass(), PluginConfig.PINPOINT_PLUGIN_PACKAGE, pluginPackageList);
}
logger.info("Loading plugin:{} pluginPackage:{}", plugin.getClass().getName(), plugin);
PluginConfig pluginConfig = new PluginConfig(pluginJar, pluginFilterChain);
final ClassInjector classInjector = new JarProfilerPluginClassInjector(pluginConfig, instrumentEngine);
final SetupResult result = pluginSetup.setupPlugin(plugin, classInjector);
pluginContexts.add(result);
}
}
return pluginContexts;
}
use of java.util.jar.JarFile in project RocooFix by dodola.
the class PatchRefScan method addClasstoPatch.
public static void addClasstoPatch(JarEntry jarEntry, String className, JarFile alljar, File patchDir) throws Exception {
System.out.println("============addClasstoPatch======" + className);
File entryFile = new File(patchDir, className);
if (!entryFile.exists()) {
InputStream inputStreamX = alljar.getInputStream(jarEntry);
byte[] bytes = NuwaProcessor.referHackWhenInit(inputStreamX);
FileUtils.writeByteArrayToFile(entryFile, bytes);
}
}
use of java.util.jar.JarFile in project RocooFix by dodola.
the class ClassReferenceListBuilder method addRoots.
public void addRoots(String path) throws IOException {
this.path = new Path(path);
this.jarOfRoots = new JarFile(path);
}
Aggregations