From 78084a2d20026b8c391f87d76e74f457053a7407 Mon Sep 17 00:00:00 2001 From: James Lee Date: Mon, 9 Mar 2015 01:38:40 -0500 Subject: [PATCH] Fix stat when isHidden() is broken Works around a bug in GCJ --- .../meterpreter/stdapi/stdapi_fs_stat.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_fs_stat.java b/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_fs_stat.java index 8c47232a..72066d96 100644 --- a/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_fs_stat.java +++ b/java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi/stdapi_fs_stat.java @@ -31,10 +31,21 @@ public class stdapi_fs_stat implements Command { } public byte[] stat(File file) throws IOException { - int mode = (file.canRead() ? 0444 : 0) | (file.canWrite() ? 0222 : 0) | (canExecute(file) ? 0110 : 0) | (file.isHidden() ? 1 : 0) | (file.isDirectory() ? 040000 : 0) | (file.isFile() ? 0100000 : 0); + int mode = (file.canRead() ? 0444 : 0) + | (file.canWrite() ? 0222 : 0) + | (canExecute(file) ? 0110 : 0) + // File objects have a prefix (which is something like "C:\\" on Windows + // and always "/" on Linux) and a name. If we're talking about the root + // directory, the name will be an empty string which triggers a bug in gcj + // where isHidden() blows up when calling charAt(0) on an empty string. + // Work around it by always treating / as unhidden. + | (!file.getAbsolutePath().equals("/") && file.isHidden() ? 1 : 0) + | (file.isDirectory() ? 040000 : 0) + | (file.isFile() ? 0100000 : 0) + ; return stat(mode, file.length(), file.lastModified()); } - + private byte[] stat(int mode, long length, long lastModified) throws IOException { ByteArrayOutputStream statbuf = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(statbuf);