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 encoded mode #508

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 27 additions & 4 deletions inject/inject.vala
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,14 @@ namespace Frida.Inject {

buf[n] = 0;

script_runner.on_stdin ((string) buf);
if (script_runner.terminal_mode == TerminalMode.ENCODED)
/*
* If we are in encoded mode, then send our data to
* the target in base64 encoded form.
*/
script_runner.on_stdin (Base64.encode (buf[:n]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to encode it, post() has a data argument which supports binary data. It's passed to the message handler in the second argument. But we should improve the RPC API (built on top of send() + recv()) so it supports binary data in parameters and not only in the return value. The GumJS implementation can be found here. We could basically use a special marker, like ['frida:oob', offset, size], which specifies the offset into the data argument, and the size of the region.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I had the same problem on output. Sending ansi control codes to the stdout. Is it possible for frida core to work as a dumb byte pump rather than dealing with strings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's only a matter of returning an ArrayBuffer instead of a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can binary data only be sent/received by post and it's return value? Is there an ability to make an RPC to send bytes during the handling of the post? Or so they all have to be collated and sent by return?

else
script_runner.on_stdin ((string) buf);

return true;
}
Expand Down Expand Up @@ -599,10 +606,18 @@ namespace Frida.Inject {
if (mode_value.get_value_type () != typeof (string))
return COOKED;

return (mode_value.get_string () == "raw") ? TerminalMode.RAW : TerminalMode.COOKED;
switch (mode_value.get_string ()) {
case "raw":
return TerminalMode.RAW;
case "encoded":
return TerminalMode.ENCODED;
default:
return TerminalMode.COOKED;
}
}

private void apply_terminal_mode (TerminalMode mode) throws Error {
/* Disable processing by the TTY in RAW and ENCODED modes */
if (mode == COOKED || original_term == null)
return;

Expand Down Expand Up @@ -751,7 +766,14 @@ namespace Frida.Inject {

switch (type) {
case "frida:stdout":
stdout.write (str.data);
/*
* If we are in encoded mode, expect our input from our
* target to be base64 encoded.
*/
if (this.terminal_mode == TerminalMode.ENCODED)
stdout.write (Base64.decode (str));
else
stdout.write (str.data);
stdout.flush ();
return true;
case "frida:stderr":
Expand All @@ -769,6 +791,7 @@ namespace Frida.Inject {

private enum TerminalMode {
COOKED,
RAW
RAW,
ENCODED
}
}
Loading