Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tonka exec output decoding with specified charset #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions beanshooter/src/de/qtc/beanshooter/mbean/tonkabean/Dispatcher.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package de.qtc.beanshooter.mbean.tonkabean;

import java.io.Console;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.Proxy;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
Expand Down Expand Up @@ -152,7 +149,25 @@ else if( TonkaBeanOption.EXEC_FILE.notNull() )
else
{
Logger.printlnYellow("Server response:");
System.out.write(result);

if (TonkaBeanOption.EXEC_CHARSET.notNull()){
String charset = TonkaBeanOption.EXEC_CHARSET.<String>getValue();

InputStream is = new ByteArrayInputStream(result);
Reader reader = new InputStreamReader(is, charset);
BufferedReader br = new BufferedReader(reader);

String s;
while((s=br.readLine()) != null) {
System.out.println(s);
}

br.close();
}

else{
System.out.write(result);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public enum TonkaBeanOperation implements Operation
TonkaBeanOption.EXEC_FILE,
TonkaBeanOption.EXEC_HEX,
TonkaBeanOption.EXEC_RAW,
TonkaBeanOption.EXEC_CHARSET,
TonkaBeanOption.EXEC_BACK,
TonkaBeanOption.SHELL_CMD,
}),
Expand Down Expand Up @@ -99,6 +100,7 @@ public enum TonkaBeanOperation implements Operation
TonkaBeanOption.EXEC_FILE,
TonkaBeanOption.EXEC_HEX,
TonkaBeanOption.EXEC_RAW,
TonkaBeanOption.EXEC_CHARSET,
TonkaBeanOption.EXEC_BACK,
}),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public enum TonkaBeanOption implements Option
ArgType.BOOL
),

EXEC_CHARSET("--charset",
"decode the output of the command with specific charset",
Arguments.store(),
OptionGroup.ACTION,
ArgType.STRING
),

UPLOAD_SOURCE("local",
"local file to upload onto the server",
Arguments.store(),
Expand Down