Skip to content

Commit

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

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

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

if (trimmedLine.endsWith("(")) {
insideBlock = true;
}

if (trimmedLine.endsWith(")")) {
insideBlock = false;
}

boolean isLastLine = (i == lines.length - 1);
if (!insideBlock && !isLastLine) {
formattedCommand.append(" & ");
} else {
formattedCommand.append(" ");
}
}

return formattedCommand.toString();
}

private String processAndEncodeCommand(
String command,
String executor,
Expand All @@ -83,7 +115,7 @@ private String processAndEncodeCommand(

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

if (obfuscator.equals("base64")) {
Expand Down

0 comments on commit b9bf3dd

Please sign in to comment.