Skip to content

Commit

Permalink
[backend] handle multilines with cmd (#2000)
Browse files Browse the repository at this point in the history
Signed-off-by: Marine LM <[email protected]>
  • Loading branch information
MarineLeM authored Jan 2, 2025
1 parent 7b58130 commit 100a439
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,32 @@ public static String replaceCmdVariables(String cmd) {
return result.toString();
}

private static String formatMultilineCommand(String command) {
String[] lines = command.split("\n");
StringBuilder formattedCommand = new StringBuilder();

for (int i = 0; i < lines.length; i++) {
String line = lines[i];
String trimmedLine = line.trim();
if (trimmedLine.isEmpty()) {
continue;
}
formattedCommand.append(trimmedLine);

boolean isLastLine = (i == lines.length - 1);
boolean isAfterParentheses = trimmedLine.endsWith("(");
boolean isBeforeParentheses = !isLastLine && lines[i + 1].trim().startsWith(")");

if (!isAfterParentheses && !isBeforeParentheses && !isLastLine) {
formattedCommand.append(" & ");
} else {
formattedCommand.append(" ");
}
}

return formattedCommand.toString();
}

private String processAndEncodeCommand(
String command,
String executor,
Expand All @@ -87,7 +113,7 @@ private String processAndEncodeCommand(

if (executor.equals("cmd")) {
computedCommand = replaceCmdVariables(computedCommand);
computedCommand = computedCommand.trim().replace("\n", " & ");
computedCommand = formatMultilineCommand(computedCommand);
}

computedCommand = obfuscationMap.executeObfuscation(obfuscator, computedCommand, executor);
Expand Down

0 comments on commit 100a439

Please sign in to comment.