Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0 revised SystemUtilities.getUserName() to eliminate Domain Name

ghidra1f64c38ef7fe8
diff --git a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ClientUtil.java b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ClientUtil.java
index a196b96305..c9dc6d8976 100644
--- a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ClientUtil.java
+++ b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ClientUtil.java
@@ -171,13 +171,7 @@ public class ClientUtil {
* @return default user name
*/
public static String getUserName() {
- String name = SystemUtilities.getUserName();
- // exclude domain prefix which may be included
- int slashIndex = name.lastIndexOf('\\');
- if (slashIndex >= 0) {
- name = name.substring(slashIndex + 1);
- }
- return name;
+ return SystemUtilities.getUserName();
}
/**
@@ -446,8 +440,8 @@ public class ClientUtil {
static void processSignatureCallback(String serverName, SignatureCallback sigCb)
throws IOException {
try {
- SignedToken signedToken = ApplicationKeyManagerUtils.getSignedToken(
- sigCb.getRecognizedAuthorities(), sigCb.getToken());
+ SignedToken signedToken = ApplicationKeyManagerUtils
+ .getSignedToken(sigCb.getRecognizedAuthorities(), sigCb.getToken());
sigCb.sign(signedToken.certChain, signedToken.signature);
Msg.info(ClientUtil.class, "PKI Authenticating to " + serverName + " as user '" +
signedToken.certChain[0].getSubjectX500Principal() + "'");
diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/util/SystemUtilities.java b/Ghidra/Framework/Utility/src/main/java/ghidra/util/SystemUtilities.java
index 6480638e10..e6d084f185 100644
--- a/Ghidra/Framework/Utility/src/main/java/ghidra/util/SystemUtilities.java
+++ b/Ghidra/Framework/Utility/src/main/java/ghidra/util/SystemUtilities.java
@@ -91,7 +91,7 @@ public class SystemUtilities {
if (url.getPath().contains("/build/libs")) {
return true; // Source repository Gradle JavaExec task mode
}
- return switch(url.getProtocol()) {
+ return switch (url.getProtocol()) {
case "file" -> true; // Eclipse run config mode (class files)
case "jar" -> false; // Release mode (jar files)
case "bundleresource" -> false; // GhidraDev Utility.jar access mode
@@ -100,25 +100,33 @@ public class SystemUtilities {
}
/**
- * Get the user that is running the ghidra application
+ * Get the user that is running the ghidra application. This name may be modified to
+ * eliminate any spaces or leading domain name which may be present in Java's
+ * {@code user.name} system property.
* @return the user name
*/
public static String getUserName() {
if (userName == null) {
String uname = System.getProperty("user.name");
- // remove the spaces since some operating systems allow
+ // Remove the spaces since some operating systems allow
// spaces and some do not, Java's File class doesn't
+ StringBuilder nameBuf = new StringBuilder();
if (uname.indexOf(" ") >= 0) {
- userName = "";
StringTokenizer tokens = new StringTokenizer(uname, " ", false);
while (tokens.hasMoreTokens()) {
- userName += tokens.nextToken();
+ nameBuf.append(tokens.nextToken());
}
+ uname = nameBuf.toString();
}
- else {
- userName = uname;
+
+ // Remove leading Domain Name if present
+ int slashIndex = uname.lastIndexOf('\\');
+ if (slashIndex >= 0) {
+ uname = uname.substring(slashIndex + 1);
}
+
+ userName = uname;
}
return userName;
}