使用 ADB 和 SQLITE 进行转义,连接命令

发布于 2025-01-10 12:15:56 字数 2001 浏览 0 评论 0原文

我正在尝试将二进制数据插入在 Android 中运行的应用程序的数据库中。

如果我从 shell 内部运行命令,我可以完美地完成它,就像

G011A:/ # sqlite3 /data/data/com.app.test/db/data.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"

它完美地插入数据一样。但我需要从外部运行它,就像

adb shell 'sqlite3 /data/data/com.app.test/db/data.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"'

它不起作用,它给了我一个

/system/bin/sh: syntax error: '(' unexpected

我尝试了所有可能的转义和序列

adb shell "sqlite3 /data/data/com.myapp/db/test.db 'insert or replace into sessions (record, timestamp) values (X"0a81",1645815520)'"

WARNING: linker: /mnt/runtime/default/emulated/0/Download/sqlite3: unsupported flags DT_FLAGS_1=0x8000001

Error: unrecognized token: "0a81"

adb shell 'sqlite3 /data/data/com.myapp/db/test.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"'
/system/bin/sh: syntax error: '(' unexpected


adb shell 'sqlite3 /data/data/com.myapp/db/test.db "insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)"'
/system/bin/sh: syntax error: '(' unexpected


adb shell 'sqlite3 /data/data/com.myapp/db/test.db \"insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\"'
/system/bin/sh: syntax error: '(' unexpected


adb shell "sqlite3 /data/data/com.myapp/db/test.db \'insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\'"
/system/bin/sh: syntax error: '(' unexpected


adb shell "sqlite3 /data/data/com.myapp/db/test.db \'insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\'"
/system/bin/sh: syntax error: '(' unexpected

有什么想法如何做到这一点吗?

这个更简单的查询有效,因为我在查询中间没有另一个 '

adb shell "sqlite3 /data/data/com.app.test/db/data.db 'select * from sessions'"

顺便说一句:这是一个在 Windows 10 上运行的 PowerShell 终端。稍后我将此命令行嵌入到 Java 应用程序中。

I'm trying to insert binary data in database of an app running in Android.

I can do it perfectly if I run the command from inside the shell like

G011A:/ # sqlite3 /data/data/com.app.test/db/data.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"

It inserts data perfectly. But I need to run it from outside like

adb shell 'sqlite3 /data/data/com.app.test/db/data.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"'

And it does not work, it gives me a

/system/bin/sh: syntax error: '(' unexpected

I tried every possible escaping and sequence

adb shell "sqlite3 /data/data/com.myapp/db/test.db 'insert or replace into sessions (record, timestamp) values (X"0a81",1645815520)'"

WARNING: linker: /mnt/runtime/default/emulated/0/Download/sqlite3: unsupported flags DT_FLAGS_1=0x8000001

Error: unrecognized token: "0a81"

adb shell 'sqlite3 /data/data/com.myapp/db/test.db "insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)"'
/system/bin/sh: syntax error: '(' unexpected


adb shell 'sqlite3 /data/data/com.myapp/db/test.db "insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)"'
/system/bin/sh: syntax error: '(' unexpected


adb shell 'sqlite3 /data/data/com.myapp/db/test.db \"insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\"'
/system/bin/sh: syntax error: '(' unexpected


adb shell "sqlite3 /data/data/com.myapp/db/test.db \'insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\'"
/system/bin/sh: syntax error: '(' unexpected


adb shell "sqlite3 /data/data/com.myapp/db/test.db \'insert or replace into sessions (record, timestamp) values (X\'0a81\',1645815520)\'"
/system/bin/sh: syntax error: '(' unexpected

Any ideas how to do it?

This more simple query works, as I don't have another ' in the middle of the query

adb shell "sqlite3 /data/data/com.app.test/db/data.db 'select * from sessions'"

BTW: this a PowerShell terminal running on Windows 10. And I'm later embedding this command line in a Java application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏天碎花小短裙 2025-01-17 12:15:56

这应该可以

adb shell sqlite3 /data/data/com.myapp/db/test.db <<EOF
insert or replace into test (record, timestamp) values (X'0a81', 1645815520);
EOF

编辑

或者这是超级难看的

adb shell echo 'insert or replace into test \(record, timestamp\) values \(X'"\'"'0a81'"\'"', 1645815521\)\;' \| sqlite3 /data/data/com.myapp/db/test.db

编辑2

使用你最喜欢的编辑器创建一个包含SQL的文件,没有任何转义(即my.sql),

insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)

推送它

adb push my.sql /data/local/tmp

然后

adb shell sqlite3 -batch /data/data/com.app.test/db/data.db '<' /data/local/tmp/my.sql

This should work

adb shell sqlite3 /data/data/com.myapp/db/test.db <<EOF
insert or replace into test (record, timestamp) values (X'0a81', 1645815520);
EOF

edit

Or this which is super ugly

adb shell echo 'insert or replace into test \(record, timestamp\) values \(X'"\'"'0a81'"\'"', 1645815521\)\;' \| sqlite3 /data/data/com.myapp/db/test.db

edit 2

Use your favorite editor to create a file containing the SQL with nothing escaped (i.e. my.sql)

insert or replace into sessions (record, timestamp) values (X'0a81',1645815520)

push it

adb push my.sql /data/local/tmp

then

adb shell sqlite3 -batch /data/data/com.app.test/db/data.db '<' /data/local/tmp/my.sql
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文