tolerate missing classes in interceptFileOperations

If we fail to resolve a given class (e.g. due to ProGuard obfuscating
or eliminating it), just move on to the next one rather than return
immediately.  Otherwise, we may miss intercepting methods of classes
we can resolve.
This commit is contained in:
Joel Dice 2011-04-10 17:01:38 -06:00
parent 4d1711cd04
commit 0987255552

View File

@ -1691,156 +1691,174 @@ interceptFileOperations(Thread* t)
MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath); MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath);
{ object fileClass = resolveClass { object fileClass = resolveClass
(t, root(t, Machine::BootLoader), "java/io/File"); (t, root(t, Machine::BootLoader), "java/io/File", false);
if (fileClass == 0) return;
object filePathField = findFieldInClass2 if (fileClass) {
(t, fileClass, "path", "Ljava/lang/String;"); object filePathField = findFieldInClass2
if (filePathField == 0) return; (t, fileClass, "path", "Ljava/lang/String;");
cp->filePathField = fieldOffset(t, filePathField); if (filePathField) {
cp->filePathField = fieldOffset(t, filePathField);
}
}
} }
{ object fileDescriptorClass = resolveClass { object fileDescriptorClass = resolveClass
(t, root(t, Machine::BootLoader), "java/io/FileDescriptor"); (t, root(t, Machine::BootLoader), "java/io/FileDescriptor", false);
if (fileDescriptorClass == 0) return;
object fileDescriptorFdField = findFieldInClass2 if (fileDescriptorClass) {
(t, fileDescriptorClass, "fd", "I"); object fileDescriptorFdField = findFieldInClass2
if (fileDescriptorFdField == 0) return; (t, fileDescriptorClass, "fd", "I");
cp->fileDescriptorFdField = fieldOffset(t, fileDescriptorFdField); if (fileDescriptorFdField) {
cp->fileDescriptorFdField = fieldOffset(t, fileDescriptorFdField);
}
}
} }
{ object fileInputStreamClass = resolveClass { object fileInputStreamClass = resolveClass
(t, root(t, Machine::BootLoader), "java/io/FileInputStream"); (t, root(t, Machine::BootLoader), "java/io/FileInputStream", false);
if (fileInputStreamClass == 0) return;
PROTECT(t, fileInputStreamClass); if (fileInputStreamClass) {
PROTECT(t, fileInputStreamClass);
object fileInputStreamFdField = findFieldInClass2 object fileInputStreamFdField = findFieldInClass2
(t, fileInputStreamClass, "fd", "Ljava/io/FileDescriptor;"); (t, fileInputStreamClass, "fd", "Ljava/io/FileDescriptor;");
if (fileInputStreamFdField == 0) return;
cp->fileInputStreamFdField = fieldOffset(t, fileInputStreamFdField); if (fileInputStreamFdField) {
cp->fileInputStreamFdField = fieldOffset(t, fileInputStreamFdField);
intercept(t, fileInputStreamClass, "open", "(Ljava/lang/String;)V", intercept(t, fileInputStreamClass, "open", "(Ljava/lang/String;)V",
voidPointer(openFile)); voidPointer(openFile));
intercept(t, fileInputStreamClass, "read", "()I", intercept(t, fileInputStreamClass, "read", "()I",
voidPointer(readByteFromFile)); voidPointer(readByteFromFile));
intercept(t, fileInputStreamClass, "readBytes", "([BII)I", intercept(t, fileInputStreamClass, "readBytes", "([BII)I",
voidPointer(readBytesFromFile)); voidPointer(readBytesFromFile));
intercept(t, fileInputStreamClass, "skip", "(J)J", intercept(t, fileInputStreamClass, "skip", "(J)J",
voidPointer(skipBytesInFile)); voidPointer(skipBytesInFile));
intercept(t, fileInputStreamClass, "available", "()I", intercept(t, fileInputStreamClass, "available", "()I",
voidPointer(availableBytesInFile)); voidPointer(availableBytesInFile));
intercept(t, fileInputStreamClass, "close0", "()V", intercept(t, fileInputStreamClass, "close0", "()V",
voidPointer(closeFile)); voidPointer(closeFile));
}
}
} }
{ object zipEntryClass = resolveClass { object zipEntryClass = resolveClass
(t, root(t, Machine::BootLoader), "java/util/zip/ZipEntry"); (t, root(t, Machine::BootLoader), "java/util/zip/ZipEntry", false);
if (zipEntryClass == 0) return;
PROTECT(t, zipEntryClass); if (zipEntryClass) {
PROTECT(t, zipEntryClass);
object zipEntryNameField = findFieldInClass2 object zipEntryNameField = findFieldInClass2
(t, zipEntryClass, "name", "Ljava/lang/String;"); (t, zipEntryClass, "name", "Ljava/lang/String;");
if (zipEntryNameField == 0) return;
cp->zipEntryNameField = fieldOffset(t, zipEntryNameField); if (zipEntryNameField) {
cp->zipEntryNameField = fieldOffset(t, zipEntryNameField);
object zipEntryTimeField = findFieldInClass2 object zipEntryTimeField = findFieldInClass2
(t, zipEntryClass, "time", "J"); (t, zipEntryClass, "time", "J");
if (zipEntryTimeField == 0) return;
cp->zipEntryTimeField = fieldOffset(t, zipEntryTimeField); if (zipEntryTimeField) {
cp->zipEntryTimeField = fieldOffset(t, zipEntryTimeField);
object zipEntryCrcField = findFieldInClass2 object zipEntryCrcField = findFieldInClass2
(t, zipEntryClass, "crc", "J"); (t, zipEntryClass, "crc", "J");
if (zipEntryCrcField == 0) return;
cp->zipEntryCrcField = fieldOffset(t, zipEntryCrcField); if (zipEntryCrcField) {
cp->zipEntryCrcField = fieldOffset(t, zipEntryCrcField);
object zipEntrySizeField = findFieldInClass2 object zipEntrySizeField = findFieldInClass2
(t, zipEntryClass, "size", "J"); (t, zipEntryClass, "size", "J");
if (zipEntrySizeField == 0) return;
cp->zipEntrySizeField = fieldOffset(t, zipEntrySizeField); if (zipEntrySizeField) {
cp->zipEntrySizeField = fieldOffset(t, zipEntrySizeField);
object zipEntryCsizeField = findFieldInClass2 object zipEntryCsizeField = findFieldInClass2
(t, zipEntryClass, "csize", "J"); (t, zipEntryClass, "csize", "J");
if (zipEntryCsizeField == 0) return;
if (zipEntryCsizeField) {
cp->zipEntryCsizeField = fieldOffset(t, zipEntryCsizeField);
cp->zipEntryCsizeField = fieldOffset(t, zipEntryCsizeField); object zipEntryMethodField = findFieldInClass2
(t, zipEntryClass, "method", "I");
object zipEntryMethodField = findFieldInClass2 if (zipEntryMethodField) {
(t, zipEntryClass, "method", "I"); cp->zipEntryMethodField = fieldOffset
if (zipEntryMethodField == 0) return; (t, zipEntryMethodField);
cp->zipEntryMethodField = fieldOffset(t, zipEntryMethodField); intercept(t, zipEntryClass, "initFields", "(J)V",
voidPointer(initializeZipEntryFields));
intercept(t, zipEntryClass, "initFields", "(J)V", }
voidPointer(initializeZipEntryFields)); }
}
}
}
}
}
} }
{ object zipFileClass = resolveClass { object zipFileClass = resolveClass
(t, root(t, Machine::BootLoader), "java/util/zip/ZipFile"); (t, root(t, Machine::BootLoader), "java/util/zip/ZipFile", false);
if (zipFileClass == 0) return;
PROTECT(t, zipFileClass); if (zipFileClass) {
PROTECT(t, zipFileClass);
object zipFileJzfileField = findFieldInClass2 object zipFileJzfileField = findFieldInClass2
(t, zipFileClass, "jzfile", "J"); (t, zipFileClass, "jzfile", "J");
if (zipFileJzfileField == 0) return;
cp->zipFileJzfileField = fieldOffset(t, zipFileJzfileField); if (zipFileJzfileField) {
cp->zipFileJzfileField = fieldOffset(t, zipFileJzfileField);
intercept(t, zipFileClass, "open", "(Ljava/lang/String;IJ)J", intercept(t, zipFileClass, "open", "(Ljava/lang/String;IJ)J",
voidPointer(openZipFile)); voidPointer(openZipFile));
intercept(t, zipFileClass, "getTotal", "(J)I", intercept(t, zipFileClass, "getTotal", "(J)I",
voidPointer(getZipFileEntryCount)); voidPointer(getZipFileEntryCount));
intercept(t, zipFileClass, "getEntry", "(JLjava/lang/String;Z)J", intercept(t, zipFileClass, "getEntry", "(JLjava/lang/String;Z)J",
voidPointer(getZipFileEntry)); voidPointer(getZipFileEntry));
intercept(t, zipFileClass, "getNextEntry", "(JI)J", intercept(t, zipFileClass, "getNextEntry", "(JI)J",
voidPointer(getNextZipFileEntry)); voidPointer(getNextZipFileEntry));
intercept(t, zipFileClass, "getMethod", "(J)I", intercept(t, zipFileClass, "getMethod", "(J)I",
voidPointer(getZipFileEntryMethod)); voidPointer(getZipFileEntryMethod));
intercept(t, zipFileClass, "freeEntry", "(JJ)V", intercept(t, zipFileClass, "freeEntry", "(JJ)V",
voidPointer(freeZipFileEntry)); voidPointer(freeZipFileEntry));
intercept(t, zipFileClass, "read", "(JJJ[BII)I", intercept(t, zipFileClass, "read", "(JJJ[BII)I",
voidPointer(readZipFileEntry)); voidPointer(readZipFileEntry));
intercept(t, zipFileClass, "getCSize", "(J)J", intercept(t, zipFileClass, "getCSize", "(J)J",
voidPointer(getZipFileEntryCompressedSize)); voidPointer(getZipFileEntryCompressedSize));
intercept(t, zipFileClass, "getSize", "(J)J", intercept(t, zipFileClass, "getSize", "(J)J",
voidPointer(getZipFileEntryUncompressedSize)); voidPointer(getZipFileEntryUncompressedSize));
intercept(t, zipFileClass, "getZipMessage", "(J)Ljava/lang/String;", intercept(t, zipFileClass, "getZipMessage", "(J)Ljava/lang/String;",
voidPointer(getZipMessage)); voidPointer(getZipMessage));
intercept(t, zipFileClass, "close", "(J)V", intercept(t, zipFileClass, "close", "(J)V",
voidPointer(closeZipFile)); voidPointer(closeZipFile));
}
}
} }
{ object jarFileClass = resolveClass { object jarFileClass = resolveClass
(t, root(t, Machine::BootLoader), "java/util/jar/JarFile"); (t, root(t, Machine::BootLoader), "java/util/jar/JarFile", false);
if (jarFileClass == 0) return;
intercept(t, jarFileClass, "getMetaInfEntryNames", "()[Ljava/lang/String;", if (jarFileClass) {
voidPointer(getJarFileMetaInfEntryNames)); intercept(t, jarFileClass, "getMetaInfEntryNames",
"()[Ljava/lang/String;",
voidPointer(getJarFileMetaInfEntryNames));
}
} }
{ {
@ -1854,18 +1872,19 @@ interceptFileOperations(Thread* t)
object fsClass = resolveClass object fsClass = resolveClass
(t, root(t, Machine::BootLoader), fsClassName, false); (t, root(t, Machine::BootLoader), fsClassName, false);
if (fsClass == 0) return;
PROTECT(t, fsClass); if (fsClass) {
PROTECT(t, fsClass);
intercept(t, fsClass, gbaMethodName, "(Ljava/io/File;)I", intercept(t, fsClass, gbaMethodName, "(Ljava/io/File;)I",
voidPointer(getFileAttributes)); voidPointer(getFileAttributes));
intercept(t, fsClass, "checkAccess", "(Ljava/io/File;I)Z", intercept(t, fsClass, "checkAccess", "(Ljava/io/File;I)Z",
voidPointer(checkFileAccess)); voidPointer(checkFileAccess));
intercept(t, fsClass, "getLength", "(Ljava/io/File;)J", intercept(t, fsClass, "getLength", "(Ljava/io/File;)J",
voidPointer(getFileLength)); voidPointer(getFileLength));
}
} }
intercept(t, type(t, Machine::ClassLoaderType), "loadLibrary", intercept(t, type(t, Machine::ClassLoaderType), "loadLibrary",