mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-30 12:31:13 +08:00
Merge remote-tracking branch 'origin/GP-6710_dev747368_javaclassdecomp_fs'
This commit is contained in:
+17
-2
@@ -59,7 +59,8 @@ public class JavaClassDecompilerFileSystem implements GFileSystem {
|
|||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
|
|
||||||
this.containerFSRL = provider.getFSRL();
|
this.containerFSRL = provider.getFSRL();
|
||||||
this.className = FilenameUtils.removeExtension(containerFSRL.getName());
|
this.className =
|
||||||
|
getSafeJavaClassname(FilenameUtils.removeExtension(containerFSRL.getName()));
|
||||||
this.javaSrcFilename = className + ".java";
|
this.javaSrcFilename = className + ".java";
|
||||||
|
|
||||||
try (ByteProvider decompiledBP = getDecompiledJavaSrcFileEntry(null, monitor)) {
|
try (ByteProvider decompiledBP = getDecompiledJavaSrcFileEntry(null, monitor)) {
|
||||||
@@ -68,6 +69,14 @@ public class JavaClassDecompilerFileSystem implements GFileSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getSafeJavaClassname(String s) throws IOException {
|
||||||
|
if (s.isEmpty() || !Character.isJavaIdentifierStart(s.codePointAt(0)) ||
|
||||||
|
!s.substring(1).codePoints().allMatch(Character::isJavaIdentifierPart)) {
|
||||||
|
throw new IOException("Bad classname: " + s);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
private ByteProvider getDecompiledJavaSrcFileEntry(FSRL targetFSRL, TaskMonitor monitor)
|
private ByteProvider getDecompiledJavaSrcFileEntry(FSRL targetFSRL, TaskMonitor monitor)
|
||||||
throws CancelledException, IOException {
|
throws CancelledException, IOException {
|
||||||
return fsService.getDerivedByteProviderPush(containerFSRL, targetFSRL, javaSrcFilename, -1,
|
return fsService.getDerivedByteProviderPush(containerFSRL, targetFSRL, javaSrcFilename, -1,
|
||||||
@@ -80,13 +89,19 @@ public class JavaClassDecompilerFileSystem implements GFileSystem {
|
|||||||
try {
|
try {
|
||||||
tempDir = new File(Application.getUserTempDirectory(), "JavaClassDecompilerFileSystem");
|
tempDir = new File(Application.getUserTempDirectory(), "JavaClassDecompilerFileSystem");
|
||||||
|
|
||||||
File tempClassFile = new File(tempDir, containerFSRL.getName());
|
File tempClassFile = new File(tempDir, className + ".class");
|
||||||
|
if (!tempDir.equals(tempClassFile.getParentFile())) {
|
||||||
|
throw new IOException("Bad filename name: " + tempClassFile.getName());
|
||||||
|
}
|
||||||
FSUtilities.copyByteProviderToFile(provider, tempClassFile, monitor);
|
FSUtilities.copyByteProviderToFile(provider, tempClassFile, monitor);
|
||||||
|
|
||||||
// tempDestJavaSrcFile (ie. "javaclass.java") contents are automagically
|
// tempDestJavaSrcFile (ie. "javaclass.java") contents are automagically
|
||||||
// created by the Jad process based on the class name it finds inside
|
// created by the Jad process based on the class name it finds inside
|
||||||
// the binary "javaclass.class" file. Class, class, class.
|
// the binary "javaclass.class" file. Class, class, class.
|
||||||
File tempDestJavaSrcFile = new File(tempDir, javaSrcFilename);
|
File tempDestJavaSrcFile = new File(tempDir, javaSrcFilename);
|
||||||
|
if (!tempDir.equals(tempDestJavaSrcFile.getParentFile())) {
|
||||||
|
throw new IOException("Bad filename name: " + tempDestJavaSrcFile.getName());
|
||||||
|
}
|
||||||
|
|
||||||
JadProcessWrapper wrapper = new JadProcessWrapper(tempClassFile);
|
JadProcessWrapper wrapper = new JadProcessWrapper(tempClassFile);
|
||||||
JadProcessController controller = new JadProcessController(wrapper, className);
|
JadProcessController controller = new JadProcessController(wrapper, className);
|
||||||
|
|||||||
Reference in New Issue
Block a user