Fix getUniqueName

This commit is contained in:
Konloch 2024-10-02 10:58:27 -06:00
parent 32b6f4ee8a
commit 8301a58db8

AI 샘플 코드 생성 중입니다

Loading...
4 changed files with 33 additions and 3 deletions

View File

@ -72,7 +72,7 @@ public class FernFlowerDecompiler extends AbstractDecompiler
@Override @Override
public String decompileClassNode(ClassNode cn, byte[] bytes) public String decompileClassNode(ClassNode cn, byte[] bytes)
{ {
String start = TEMP_DIRECTORY + FS + MiscUtils.getUniqueName("", ".class"); String start = TEMP_DIRECTORY + FS + MiscUtils.getUniqueNameBroken("", ".class");
final File tempClass = new File(start + ".class"); final File tempClass = new File(start + ".class");

View File

@ -52,7 +52,7 @@ public class JADXDecompiler extends AbstractDecompiler
String fileStart = TEMP_DIRECTORY + FS; String fileStart = TEMP_DIRECTORY + FS;
String exception = ""; String exception = "";
final File tempClass = new File(MiscUtils.getUniqueName(fileStart, ".class") + ".class"); final File tempClass = new File(MiscUtils.getUniqueNameBroken(fileStart, ".class") + ".class");
try (FileOutputStream fos = new FileOutputStream(tempClass)) try (FileOutputStream fos = new FileOutputStream(tempClass))
{ {

View File

@ -52,7 +52,7 @@ public class SmaliDisassembler extends AbstractDecompiler
public String decompileClassNode(ClassNode cn, byte[] bytes) public String decompileClassNode(ClassNode cn, byte[] bytes)
{ {
final String fileStart = TEMP_DIRECTORY + FS + "temp"; final String fileStart = TEMP_DIRECTORY + FS + "temp";
final String start = MiscUtils.getUniqueName(fileStart, ".class"); final String start = MiscUtils.getUniqueNameBroken(fileStart, ".class");
final File tempClass = new File(start + ".class"); final File tempClass = new File(start + ".class");
final File tempDex = new File(start + ".dex"); final File tempDex = new File(start + ".dex");
final File tempDexOut = new File(start + "-out"); final File tempDexOut = new File(start + "-out");

View File

@ -144,6 +144,36 @@ public class MiscUtils
File tempFile; File tempFile;
String randomString; String randomString;
while (searching)
{
randomString = MiscUtils.randomString(32);
uniqueName = stringStart + randomString + fileExtension;
tempFile = new File(stringStart + randomString + fileExtension);
if (!tempFile.exists())
searching = false;
}
return uniqueName;
}
/**
* Checks the file system to ensure it's a unique name
*
* @param stringStart directory it'll be in
* @param fileExtension the file extension it'll use
* @return the unique name
*/
//TODO anything using this should be updated:
// The + ".class" needs to be removed
@Deprecated
public static String getUniqueNameBroken(String stringStart, String fileExtension)
{
String uniqueName = null;
boolean searching = true;
File tempFile;
String randomString;
while (searching) while (searching)
{ {
randomString = MiscUtils.randomString(32); randomString = MiscUtils.randomString(32);