[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Fix 66047 executable icon missing when connected to remote host
From: |
vladimir . mezentsev |
Subject: |
[PATCH] Fix 66047 executable icon missing when connected to remote host |
Date: |
Mon, 18 Nov 2024 20:12:31 -0800 |
From: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
gprofng-display-text does not report whether a file is executable.
I use /usr/bin/ls on the remote host to get information about files.
Removed unused code.
ChangeLog
2024-11-18 Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
PR 66047
* org/gprofng/mpmt/AnChooser.java (getIcon): Return elf_icon if the file
is executable.
* org/gprofng/mpmt/AnFile.java: New methodc canExecute.
* org/gprofng/mpmt/AnFileSystemView.java: Use /usr/bin/ls on the remote
host to get information about files. Clean up code.
* org/gprofng/mpmt/Analyzer.java: Set remoteConnectCommand.
* org/gprofng/mpmt/util/gui/AnUtility.java: New method getRemoteOutput.
---
org/gprofng/mpmt/AnChooser.java | 12 +-
org/gprofng/mpmt/AnFile.java | 51 ++--
org/gprofng/mpmt/AnFileSystemView.java | 366 +++--------------------
org/gprofng/mpmt/Analyzer.java | 11 +-
org/gprofng/mpmt/util/gui/AnUtility.java | 80 +++--
5 files changed, 146 insertions(+), 374 deletions(-)
diff --git a/org/gprofng/mpmt/AnChooser.java b/org/gprofng/mpmt/AnChooser.java
index ed2f056..b416304 100644
--- a/org/gprofng/mpmt/AnChooser.java
+++ b/org/gprofng/mpmt/AnChooser.java
@@ -836,22 +836,20 @@ public class AnChooser extends JFileChooser implements
PropertyChangeListener {
@Override
public Icon getIcon(final File file) {
if (chooser_type == TARGET_CHOOSER) {
- if (!file.isFile()) {
- return getExperimentIcon(file);
- }
switch (AnUtility.getMimeFormat(file)) {
+ case AnUtility.MIME_DIRECTORY:
+ return getExperimentIcon(file);
case AnUtility.MIME_ELF_EXECUTABLE:
+ case AnUtility.MIME_EXECUTABLE:
return AnUtility.elf_icon;
case AnUtility.MIME_JAVA_CLASS_FILE:
return AnUtility.cls_icon;
case AnUtility.MIME_JAR_FILE:
return AnUtility.jar_icon;
- default:
- return getExperimentIcon(file);
}
- } else {
- return getExperimentIcon(file);
+ return null;
}
+ return getExperimentIcon(file);
}
private Icon getExperimentIcon(final File file) {
diff --git a/org/gprofng/mpmt/AnFile.java b/org/gprofng/mpmt/AnFile.java
index ed5c3cf..d72fc67 100644
--- a/org/gprofng/mpmt/AnFile.java
+++ b/org/gprofng/mpmt/AnFile.java
@@ -23,7 +23,8 @@ import java.io.IOException;
public class AnFile extends File {
public static final char separatorChar = '/';
boolean attributesReady = false;
- boolean isDirectoryFlag = true;
+ boolean isDirectoryFlag = false;
+ boolean executableFlag = false;
boolean existsFlag = true;
private String directory = null;
private String fullpath = null;
@@ -39,13 +40,10 @@ public class AnFile extends File {
super(pathname);
if (Analyzer.getInstance().remoteConnection == null) {
File f = new File(pathname);
- if (f.exists()) {
- if (!f.isDirectory()) {
- isDirectoryFlag = false;
- }
- } else {
- existsFlag = false;
- isDirectoryFlag = false;
+ existsFlag = f.exists();
+ if (existsFlag) {
+ isDirectoryFlag = f.isDirectory();
+ executableFlag = f.canExecute();
}
fullpath = f.getAbsolutePath();
directory = f.getParent();
@@ -54,9 +52,11 @@ public class AnFile extends File {
}
pathname = AnFileSystemView.slashifyPath(pathname);
if (pathname.equals(SLASH)) {
+ isDirectoryFlag = true;
+ attributesReady = true;
fullpath = SLASH;
- directory = SLASH; // NM TEMPORARY
- return; // Special case: leave directory = null
+ directory = SLASH;
+ return;
}
if (pathname.startsWith(SLASH)) {
fullpath = pathname;
@@ -67,17 +67,13 @@ public class AnFile extends File {
directory = SLASH;
}
} else {
- if (Analyzer.getInstance().remoteConnection != null) {
- AnWindow aw = AnWindow.getInstance();
- directory = aw.getCurrentRemoteDirectory();
- if (directory == null) {
- directory = DOT; // NM TEMPORARY
- }
- if (!directory.endsWith(SLASH)) {
- directory += SLASH;
- }
- } else {
- directory = SLASH; // ? BUG!
+ AnWindow aw = AnWindow.getInstance();
+ directory = aw.getCurrentRemoteDirectory();
+ if (directory == null) {
+ directory = SLASH;
+ }
+ if (!directory.endsWith(SLASH)) {
+ directory += SLASH;
}
fullpath = directory + pathname;
}
@@ -151,6 +147,19 @@ public class AnFile extends File {
return ret;
}
+ /**
+ * Checks if remote file is executable.
+ *
+ * @return
+ */
+ @Override
+ public boolean canExecute() {
+ if (!attributesReady) {
+ updateAttributes();
+ }
+ return executableFlag;
+ }
+
/**
* Checks if remote file exists.
*
diff --git a/org/gprofng/mpmt/AnFileSystemView.java
b/org/gprofng/mpmt/AnFileSystemView.java
index 61cb339..1bbb355 100644
--- a/org/gprofng/mpmt/AnFileSystemView.java
+++ b/org/gprofng/mpmt/AnFileSystemView.java
@@ -26,20 +26,17 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Vector;
+import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.filechooser.FileSystemView;
+import org.gprofng.analyzer.AnLog;
+import org.gprofng.mpmt.util.gui.AnUtility;
/** AnFileSystemView - File System View for remote experiments */
public class AnFileSystemView extends FileSystemView {
private AnWindow anWindow = null;
private AnChooser anChooser = null;
- // private int TIMEOUT = 2000; // default timeout 2 seconds
- // private int SLEEPTIME = 10; // default sleep time 10 milliseconds
- private String lastRequest = null;
- private String lastResponse = null;
- private boolean firstEntry = false; // true;
private static final String SLASH = "/";
private static final String DOUBLE_SLASH = "//";
private static final char SLASH_CHAR = '/';
@@ -52,7 +49,7 @@ public class AnFileSystemView extends FileSystemView {
static AnFileSystemView remoteFileSystemView = null;
static boolean useSystemExtensionsHiding = false;
- private boolean DONT_USE_LS = true; // false;
+ private boolean DONT_USE_LS = false;
public static AnFileSystemView getFileSystemView() {
useSystemExtensionsHiding =
@@ -105,202 +102,57 @@ public class AnFileSystemView extends FileSystemView {
return false;
}
- private File[] filterHiddenFiles(File[] files, boolean isFileHidingEnabled) {
- File[] filesOut = files;
- if (isFileHidingEnabled) {
- List list = new ArrayList();
- for (File file : files) {
- if (!file.getName().startsWith(".")) {
- list.add(file);
- }
- }
- filesOut = (File[]) list.toArray(new File[list.size()]);
- }
- return filesOut;
- }
-
/**
- * Gets the list of shown (i.e. not hidden) files. Use '/bin/ls' or
- * 'gp-display-text' to get the list of remote files
+ * Gets the list of shown (i.e. not hidden) files.
+ * Use IPC_getFiles to get the list of remote files
*/
@Override
public synchronized File[] getFiles(File directory, boolean
isFileHidingEnabled) {
- long start, end;
- start = System.currentTimeMillis();
// Temporary fix for Windows
String path = slashifyPath(directory.getPath());
AnFile dir = new AnFile(path);
+ dir.isDirectoryFlag = true;
+ dir.attributesReady = true;
ThreadID++;
- // System.err.println("AnFileSystemView.getFiles: Thread ID="+ThreadID);
- if (firstEntry) { // First time run some useless command
- String s = getRemoteHostInfo();
- end = System.currentTimeMillis();
- // System.out.println("getRemoteHostInfo() [Duration: " + (end - start)
+ " ms.] returned: " +
- // s);
- firstEntry = false;
- }
- File[] files = new AnFile[0];
+ ArrayList<AnFile> anFiles = new ArrayList<AnFile>();
+ String dirname = dir.getAbsolutePath(); // dir.getCanonicalPath();
try {
- String cmd = "/bin/ls -a";
- String dirname = dir.getAbsolutePath(); // dir.getCanonicalPath();
- // Try to get directory contents
- if (firstEntry) { // First time try to use /bin/ls
- // firstEntry = false;
- } else { // Try to get directory contents from gp-display-text
- try {
- String filenames = lastResponse; // Debug optimization
- // Debug optimization
- if ((null == lastRequest) || (!lastRequest.equals(dirname))) {
- // filenames = anWindow.getFiles(dirname, cmd);
- // System.err.println("AnFileSystemView.getFiles: call
IPC_getFiles() Thread
- // ID="+ThreadID+" File:"+dirname);
- filenames = IPC_getFiles(dirname, cmd);
- }
- Vector<AnFile> v = new Vector();
- if (null != filenames) {
- String fn = filenames;
- while (fn.length() > 0) {
- int j = fn.indexOf("\n");
- if (j <= 0) {
- break;
- }
- String fname = fn.substring(0, j);
- fn = fn.substring(j + 1);
- AnFile af = new AnFile(dirname, fname);
- v.add(af);
- }
- if (v.size() > 0) {
- files = new AnFile[v.size()];
- for (int i = 0; i < v.size(); i++) {
- AnFile af = v.elementAt(i);
- // updateFileAttributes(dir, af); // too slow
- files[i] = af;
- }
- updateFileAttributes(dir, (AnFile[]) files);
- lastRequest = dirname; // Debug optimization
- lastResponse = filenames; // Debug optimization
- end = System.currentTimeMillis();
- return filterHiddenFiles(files, isFileHidingEnabled);
- }
- }
- } catch (AnIPCException e) {
- // e.printStackTrace();
- // System.err.println("AnFileSystemView.getFiles: AnIPCException CR
7199013 Thread
- // ID="+ThreadID);
- IPCLogger.logTrace(
- "\nAnFileSystemView.getFiles: AnIPCException CR 7199013 Thread
ID=" + ThreadID);
- } catch (Exception e) {
- e.printStackTrace();
- // continue using /bin/ls
- }
- }
+ String filenames;
if (DONT_USE_LS) {
- return filterHiddenFiles(files, isFileHidingEnabled);
- }
- // Try to get directory contents from /bin/ls
- AnShellCommand sc = new AnShellCommand();
- sc.setRemoteConnection(anWindow.getAnalyzer().remoteConnection);
- try {
- sc.run(dirname, cmd);
- Vector<AnFile> v = new Vector();
- String fn;
- while (sc.isRunning()) {
- // Parse /bin/ls output
- try {
- fn = sc.readOutput(true);
- if (fn == null) {
- break;
- }
- if (fn.length() <= 0) {
- continue;
- }
- int j = fn.indexOf("\n");
- if (j > 0) {
- fn = fn.substring(0, j);
- }
- AnFile af = new AnFile(dirname, fn);
- v.add(af);
- } catch (Exception e) {
- // done?
- }
+ filenames = IPC_getFiles(dirname, "/bin/ls -aF");
+ } else {
+ String cmd = "/usr/bin/ls -";
+ if (isFileHidingEnabled) {
+ cmd += "a";
}
- fn = sc.readOutput(false);
- while (fn != null) {
- // Parse /bin/ls output
- if (fn.length() <= 0) {
- fn = sc.readOutput(false);
- continue;
- }
- int j = fn.indexOf("\n");
- if (j > 0) {
- fn = fn.substring(0, j);
- }
- AnFile af = new AnFile(dirname, fn);
- v.add(af);
- fn = sc.readOutput(false);
+ filenames = AnUtility.getRemoteOutput(cmd + "F1 " + dirname);
+ }
+ AnLog.log(String.format("getFiles: %d %s\n%s", ThreadID, path,
filenames));
+ while (filenames.length() > 0) {
+ int j = filenames.indexOf("\n");
+ if (j <= 0) {
+ break;
}
- if (v.size() < 1) {
- return filterHiddenFiles(files, isFileHidingEnabled);
+ String fn = filenames.substring(0, j);
+ filenames = filenames.substring(j + 1);
+ char sym = fn.charAt(j - 1);
+ if (sym == '/' || sym == '*' || sym == '@') {
+ fn = fn.substring(0, j - 1);
}
- files = new AnFile[v.size()];
- for (int i = 0; i < v.size(); i++) {
- AnFile af = v.elementAt(i);
- // updateFileAttributes(dir, af); // too slow
- files[i] = af;
+ if (fn.equals(".") || fn.equals("..") ||
+ (!isFileHidingEnabled && fn.startsWith("."))) {
+ continue;
}
- updateFileAttributes(dir, (AnFile[]) files);
- end = System.currentTimeMillis();
- // System.out.println("getFiles(" + dirname + ") using /bin/ls: " +
(end - start) + " ms.");
- } catch (Exception e) {
- return filterHiddenFiles(files, isFileHidingEnabled);
+ AnFile f = new AnFile(fn);
+ anFiles.add(f);
+ f.executableFlag = sym == '*';
+ f.setAttributes(path, sym == '/', true);
}
+ } catch (AnIPCException e) {
+ AnLog.log("AnFileSystemView.getFiles: Thread ID=" + ThreadID + " " + e);
} catch (Exception e) {
- return filterHiddenFiles(files, isFileHidingEnabled);
- }
- /*
- // add all files in dir
- if (!(dir instanceof ShellFolder)) {
- try {
- dir = getShellFolder(dir);
- } catch (FileNotFoundException e) {
- return new File[0];
- }
}
-
- File[] names = ((ShellFolder) dir).listFiles(!useFileHiding);
-
- if (names == null) {
- return new File[0];
- }
-
- for (File f : names) {
- if (Thread.currentThread().isInterrupted()) {
- break;
- }
-
- if (!(f instanceof ShellFolder)) {
- if (isFileSystemRoot(f)) {
- f = createFileSystemRoot(f);
- }
- try {
- f = ShellFolder.getShellFolder(f);
- } catch (FileNotFoundException e) {
- // Not a valid file (wouldn't show in native file chooser)
- // Example: C:\pagefile.sys
- continue;
- } catch (InternalError e) {
- // Not a valid file (wouldn't show in native file chooser)
- // Example C:\Winnt\Profiles\joe\history\History.IE5
- continue;
- }
- }
- if (!useFileHiding || !isHiddenFile(f)) {
- files.add(f);
- }
- }
- */
- // firstEntry = false;
- return filterHiddenFiles(files, isFileHidingEnabled);
+ return (File[]) anFiles.toArray(new File[anFiles.size()]);
}
/**
@@ -319,17 +171,11 @@ public class AnFileSystemView extends FileSystemView {
fattr = fattr.substring(0, j);
}
if (fattr.endsWith(filename)) {
- boolean isDir = false;
- boolean exists = false;
if (fattr.startsWith("d")) {
- isDir = true;
- exists = true;
- file.setAttributes(dir, isDir, exists);
+ file.setAttributes(dir, true, true);
}
if (fattr.startsWith("-")) {
- isDir = false;
- exists = true;
- file.setAttributes(dir, isDir, exists);
+ file.setAttributes(dir, false, true);
}
file.attributesReady = true;
return true;
@@ -379,7 +225,6 @@ public class AnFileSystemView extends FileSystemView {
fullfilename = SLASH + filename; // BUG!
}
}
- // String fattr = anWindow.getFileAttributes(fullfilename, LS_CMD);
String fattr = IPC_getFileAttributes(fullfilename, LS_CMD);
if (null != fattr) {
if (fattr.length() > 0) {
@@ -394,40 +239,6 @@ public class AnFileSystemView extends FileSystemView {
file.isDirectoryFlag = false;
file.attributesReady = true;
}
- if (DONT_USE_LS) { // TEMPORARY: don't use /bin/ls
- return false;
- }
- AnShellCommand sc = new AnShellCommand();
- sc.setRemoteConnection(anWindow.getAnalyzer().remoteConnection);
- String cmd = LS_CMD + filename;
- sc.run(dirname, cmd);
- while (sc.isRunning()) {
- try {
- fattr = sc.readOutput(true);
- if (fattr == null) {
- break;
- }
- if (fattr.length() > 0) {
- // Parse /bin/ls output
- if (processFileAttributes(/*dir*/ dirname, file, filename, fattr))
{
- return true;
- }
- }
- } catch (Exception e) {
- // done?
- break;
- }
- }
- fattr = sc.readOutput(false);
- while (fattr != null) {
- if (fattr.length() > 0) {
- // Parse /bin/ls output
- if (processFileAttributes(/*dir*/ dirname, file, filename, fattr)) {
- return true;
- }
- }
- fattr = sc.readOutput(false);
- }
} catch (Exception e) {
// e.printStackTrace();
}
@@ -487,7 +298,8 @@ public class AnFileSystemView extends FileSystemView {
* @param filenames
* @return
*/
- private boolean processFileAttributes(/*AnFile*/ String dir, AnFile[] files,
String filenames) {
+ private boolean processFileAttributes(String dir, AnFile[] files,
+ String filenames) {
int index = 0;
String fn = filenames;
while (filenames.length() > 0) {
@@ -524,8 +336,8 @@ public class AnFileSystemView extends FileSystemView {
/**
* Update file attributes for the whole directory
*
- * @param File dir
- * @param AnFile[] files
+ * @param dir
+ * @param files
* @return
*/
public boolean updateFileAttributes(AnFile dir, AnFile[] files) {
@@ -541,55 +353,12 @@ public class AnFileSystemView extends FileSystemView {
dirname = dir.getAbsolutePath();
// Temporary fix for Windows
dirname = slashifyPath(dirname);
- String cmd = "/bin/ls -aF";
- // Try to get this info from gp-display-text
- // filenames = anWindow.getFiles(dirname, cmd);
- filenames = IPC_getFiles(dirname, cmd);
+ filenames = IPC_getFiles(dirname, "/bin/ls -aF");
if (filenames.length() > 0) {
- return (processFileAttributes(dirname, files, filenames));
- }
- if (DONT_USE_LS) {
- return false; // NM don't use /bin/ls
- }
- // Try to get this info from /bin/ls
- AnShellCommand sc = new AnShellCommand();
- sc.setRemoteConnection(anWindow.getAnalyzer().remoteConnection);
- sc.run(dirname, cmd);
- String fattr = null;
- while (sc.isRunning()) {
- // Read output
- try {
- fattr = sc.readOutput(true);
- if (fattr == null) {
- break;
- }
- if (fattr.length() <= 0) {
- continue;
- }
- filenames += fattr;
- } catch (Exception e) {
- // done?
- }
- }
- fattr = sc.readOutput(false);
- while (fattr != null) {
- // Read output
- if (fattr.length() <= 0) {
- fattr = sc.readOutput(false);
- continue;
- }
- filenames += fattr;
- fattr = sc.readOutput(false);
+ return processFileAttributes(dirname, files, filenames);
}
} catch (Exception e) {
}
- if (filenames.indexOf("\n") > 0) {
- if (null != dirname) {
- return (processFileAttributes(dirname, files, filenames));
- } else {
- return false; // for debug
- }
- }
return false;
}
@@ -650,49 +419,6 @@ public class AnFileSystemView extends FileSystemView {
anChooser = c;
}
- /**
- * Run "/bin/uname -a" command
- *
- * @return output
- */
- String getRemoteHostInfo() {
- String hostInfo = "";
- AnShellCommand sc = new AnShellCommand();
- sc.setRemoteConnection(anWindow.getAnalyzer().remoteConnection);
- String cmd = "/bin/uname -a";
- try {
- sc.run(cmd);
- String str = null;
- while (sc.isRunning()) {
- // Read output
- try {
- str = sc.readOutput(true);
- if (str == null) {
- break;
- }
- if (str.length() <= 0) {
- continue;
- }
- hostInfo += str;
- } catch (Exception e) {
- break;
- }
- }
- str = sc.readOutput(false);
- while (str != null) {
- // Read output
- if (str.length() <= 0) {
- str = sc.readOutput(false);
- continue;
- }
- hostInfo += str;
- str = sc.readOutput(false);
- }
- } catch (Exception e) {
- }
- return hostInfo;
- }
-
/**
* Get File Attributes via IPC call
*
diff --git a/org/gprofng/mpmt/Analyzer.java b/org/gprofng/mpmt/Analyzer.java
index dcc7ab4..0e5797e 100644
--- a/org/gprofng/mpmt/Analyzer.java
+++ b/org/gprofng/mpmt/Analyzer.java
@@ -422,6 +422,7 @@ public final class Analyzer {
* @param p
* @param connectCommand
* @param path
+ * @return
*/
public String createNewIPC(
ConnectionDialog cc,
@@ -496,15 +497,7 @@ public final class Analyzer {
rh = name + "@" + rh;
}
}
- String rs = AnUtility.getenv("SP_ANALYZER_REMOTE_SHELL");
- if (rs != null) { // Special way to login
- remoteConnectCommand = rs;
- } else if (null != connectCommand) {
- remoteConnectCommand = connectCommand;
- } else {
- remoteConnectCommand = remoteShell;
- }
- remoteConnectCommand += " " + rh;
+ remoteConnectCommand = connectCommand + " " + rh;
er_printCmd = remoteConnectCommand + " " + er_printCmd;
}
rc = er_printCmd;
diff --git a/org/gprofng/mpmt/util/gui/AnUtility.java
b/org/gprofng/mpmt/util/gui/AnUtility.java
index e66e456..4fbf9a7 100644
--- a/org/gprofng/mpmt/util/gui/AnUtility.java
+++ b/org/gprofng/mpmt/util/gui/AnUtility.java
@@ -48,10 +48,12 @@ import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -89,6 +91,8 @@ public final class AnUtility {
public static final int MIME_JAVA_CLASS_FILE = 0xcafebabe;
public static final int MIME_JAR_FILE = 0x504b0304;
private static final int MIME_UNKNOWN_FILE_TYPE = 0x00000000;
+ public static final int MIME_DIRECTORY = 1;
+ public static final int MIME_EXECUTABLE = 2;
public static final int MIME_CANNOT_READ_FILE = 0xFFFFFFFF;
public static final Cursor norm_cursor =
Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
public static final Cursor wait_cursor =
Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
@@ -213,26 +217,38 @@ public final class AnUtility {
private static AnThreadGroup threadGroup = new AnThreadGroup();
public static int getMimeFormat(final File file) {
- try {
- if (!file.isFile()) {
- return MIME_UNKNOWN_FILE_TYPE;
- }
- final DataInputStream dis =
- new DataInputStream(new BufferedInputStream(new
FileInputStream(file)));
- int iMagicNumber = dis.readInt();
- if (iMagicNumber == MIME_ELF_EXECUTABLE) { // reading elf header
- dis.skipBytes(12);
- final int elf_type = dis.readShort(); // check for elf executable
- if (elf_type != 0x0002 && elf_type != 0x0200) // Not MSB or LSB elf
executable
- {
- iMagicNumber = MIME_UNKNOWN_FILE_TYPE;
+ if (file.isDirectory()) {
+ return MIME_DIRECTORY;
+ }
+ if (file.canExecute()) {
+ if (Analyzer.getInstance().remoteConnection == null) {
+ try {
+ final DataInputStream dis = new DataInputStream(
+ new BufferedInputStream(new FileInputStream(file)));
+ int elf_type = 0;
+ int iMagicNumber = dis.readInt();
+ if (iMagicNumber == MIME_ELF_EXECUTABLE) { // reading elf header
+ dis.skipBytes(12);
+ elf_type = dis.readShort(); // check for elf executable
+ }
+ dis.close();
+ if (elf_type == 0x0002 || elf_type != 0x0200) { // MSB or LSB elf
+ return MIME_ELF_EXECUTABLE;
+ }
+ } catch (IOException e) {
+ return MIME_CANNOT_READ_FILE;
}
}
- dis.close();
- return iMagicNumber;
- } catch (IOException e) {
- return MIME_CANNOT_READ_FILE;
+ return MIME_EXECUTABLE;
+ }
+ String nm = file.getName();
+ if (nm.endsWith(".class'")) {
+ return MIME_JAVA_CLASS_FILE;
}
+ if (nm.endsWith(".jar'")) {
+ return MIME_JAR_FILE;
+ }
+ return MIME_UNKNOWN_FILE_TYPE;
}
public static boolean isTarget(final File file) {
@@ -240,6 +256,36 @@ public final class AnUtility {
return (type == MIME_ELF_EXECUTABLE || type == MIME_JAVA_CLASS_FILE ||
type == MIME_JAR_FILE);
}
+ public static String getRemoteOutput(String cmd) {
+ String rc = Analyzer.getInstance().remoteConnectCommand;
+ AnLog.log(String.format("getRemoteOutput: %s %s", rc, cmd));
+ ArrayList<String> args = new ArrayList<String>(
+ Arrays.asList(rc.split("\\s+")));
+ args.add(cmd);
+
+ ProcessBuilder processBuilder = new ProcessBuilder(args);
+ String lines = "";
+ try {
+ Process process = processBuilder.start();
+
+ // Read standard output
+ BufferedReader stdoutReader = new BufferedReader(
+ new InputStreamReader(process.getInputStream()));
+ for (;;) {
+ String line;
+ line = stdoutReader.readLine();
+ if (line == null) {
+ break;
+ }
+ lines += line + "\n";
+ }
+ process.waitFor();
+ } catch (IOException | InterruptedException ex) {
+ AnLog.log("getRemoteOutput: " + ex + " " + cmd);
+ }
+ return lines;
+ }
+
// General check box
public static final class AnCheckBox extends JCheckBox {
--
2.43.5
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Fix 66047 executable icon missing when connected to remote host,
vladimir . mezentsev <=