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

Fix Base64 output from /exec on webOS 1 #178

Merged
merged 1 commit into from
Mar 16, 2024

Conversation

throwaway96
Copy link
Member

While #172 fixed the basic functionality of /exec on webOS 1, the Base64 fields of the response (stdoutBytes and stderrBytes) were not working as intended.

On Node.js v0.10.x, child_process.exec() doesn't appear to support passing stdout and stderr as Buffer objects to the callback. However, the binary encoding (an alias for latin1) can be used to get strings containing the raw program output. After creating Buffers from the strings, the data can be handled the same as on newer webOS/Node.js versions.

Testing

I verified that responses containing UTF-8 encoded data were handled identically between webOS 1 and 8.

webOS 8.1.0:

# luna-send -n 1 'luna://org.webosbrew.hbchannel.service/exec' '{"command":"/home/root/utf8.sh"}' | tee /dev/tty | sha256sum
{"returnValue":true,"stdoutString":"һȅḽḻ𝖔 𝙛гổḿ ꞩƭᑯ𝞼ʋ𝙩\n","stdoutBytes":"0rvIheG4veG4u/CdlpQg8J2Zm9Cz4buV4bi/IOqeqcat4ZGv8J2evMqL8J2ZqQo=","stderrString":"ȟęḽƚⲟ ᵮ𝓻őṁ ꜱ𝖙ḓ𝒆𝖗𝗋\n","stderrBytes":"yJ/EmeG4vcaa4rKfIOG1rvCdk7vFkeG5gSDqnLHwnZaZ4biT8J2ShvCdlpfwnZeLCg=="}
f4001c0d30d4a0553ef3581f97ef6c12426374aa96f4be32d4f183109a27d1dc  -

webOS 1.4.0:

# luna-send -n 1 'luna://org.webosbrew.hbchannel.service/exec' '{"command":"/home/root/utf8.sh"}' | tee /dev/tty | sha256sum
{"returnValue":true,"stdoutString":"һȅḽḻ𝖔 𝙛гổḿ ꞩƭᑯ𝞼ʋ𝙩\n","stdoutBytes":"0rvIheG4veG4u/CdlpQg8J2Zm9Cz4buV4bi/IOqeqcat4ZGv8J2evMqL8J2ZqQo=","stderrString":"ȟęḽƚⲟ ᵮ𝓻őṁ ꜱ𝖙ḓ𝒆𝖗𝗋\n","stderrBytes":"yJ/EmeG4vcaa4rKfIOG1rvCdk7vFkeG5gSDqnLHwnZaZ4biT8J2ShvCdlpfwnZeLCg=="}
f4001c0d30d4a0553ef3581f97ef6c12426374aa96f4be32d4f183109a27d1dc  -

/home/root/utf8.sh just outputs UTF-8 encoded text on stdout and stderr. The original files in Base64 form are 0rvIheG4veG4u/CdlpQg8J2Zm9Cz4buV4bi/IOqeqcat4ZGv8J2evMqL8J2ZqQo= (stdout) and yJ/EmeG4vcaa4rKfIOG1rvCdk7vFkeG5gSDqnLHwnZaZ4biT8J2ShvCdlpfwnZeLCg== (stderr). They were received unmodified on both webOS 1 and 8.

I also checked that a chunk of data from /dev/urandom made it through unchanged on webOS 1.

Limitations

/exec still doesn't behave exactly the same on all webOS versions. I have noticed that errorText is different, as can be seen with the false command.

webOS 8.1.0:

# luna-send -n 1 'luna://org.webosbrew.hbchannel.service/exec' '{"command":"false"}'
{"returnValue":false,"errorText":"Command failed: false\n","stdoutString":"","stdoutBytes":"","stderrString":"","stderrBytes":""}

webOS 1.4.0:

# luna-send -n 1 'luna://org.webosbrew.hbchannel.service/exec' '{"command":"false"}'
{"returnValue":false,"errorText":"Command failed: ","stdoutString":"","stdoutBytes":"","stderrString":"","stderrBytes":""}

In seems later versions generally include the failed command itself, while webOS 1 does not. This is not something we can easily change, though, and it is probably not that important.

Copy link
Member

@kitsuned kitsuned left a comment

Choose a reason for hiding this comment

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

I don’t have the ability to test it on a real device, looks nice tho!

@throwaway96 throwaway96 merged commit 3c0b043 into webosbrew:main Mar 16, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants