bcv-vf/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportResource.java

111 lines
3.5 KiB
Java
Raw Normal View History

2021-06-26 12:59:51 +00:00
package the.bytecode.club.bytecodeviewer.util.resources;
import org.apache.commons.io.FileUtils;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
2021-06-22 18:05:25 +00:00
import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListPane;
import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI;
2021-06-26 12:59:51 +00:00
import the.bytecode.club.bytecodeviewer.util.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* @author Konloch
*/
2021-06-26 12:59:51 +00:00
public class ImportResource implements Runnable
{
private boolean update = true;
private final File[] files;
2021-06-26 12:59:51 +00:00
public ImportResource(File[] files) {this.files = files;}
@Override
public void run()
{
2021-06-26 12:59:51 +00:00
try
{
2021-06-26 14:11:23 +00:00
for (final File file : files)
2021-06-26 12:59:51 +00:00
{
2021-06-26 14:11:23 +00:00
final String fn = file.getName();
if (!file.exists())
{
update = false;
2021-06-26 14:11:23 +00:00
BytecodeViewer.showMessage("The file " + file.getAbsolutePath() + " could not be found.");
}
else
{
if (file.isDirectory())
{
ImportType.DIRECTORY.getImporter().open(file);
}
else
{
if (fn.endsWith(".jar") || fn.endsWith(".zip") || fn.endsWith(".war"))
{
if(!ImportType.ZIP.getImporter().open(file))
update = false;
2021-06-26 14:11:23 +00:00
}
else if (fn.endsWith(".class"))
{
if(!ImportType.CLASS.getImporter().open(file))
update = false;
2021-06-26 14:11:23 +00:00
}
else if (fn.endsWith(".apk"))
{
ImportType.APK.getImporter().open(file);
return;
2021-06-26 14:11:23 +00:00
}
else if (fn.endsWith(".dex"))
{
ImportType.DEX.getImporter().open(file);
return;
2021-06-26 14:11:23 +00:00
}
else
{
ImportType.FILE.getImporter().open(file);
}
}
}
}
} catch (final Exception e) {
new ExceptionUI(e);
} finally {
2021-06-21 23:37:55 +00:00
BytecodeViewer.viewer.updateBusyStatus(false);
if (update)
try {
2021-06-21 22:45:00 +00:00
Objects.requireNonNull(MainViewerGUI.getComponent(ResourceListPane.class)).updateTree();
2021-06-26 14:11:23 +00:00
} catch (NullPointerException ignored) { }
}
}
}