bdsm - For utter dominance over Android's Binder RPC
Android's Binder is indubitably one of its least documented, (unnecessarily?) complex, yet crucial mechanisms, as it underpins nearly all IPC/RPC in the system. I've taken to the painful task of explicating every last bit of it in Volume II (Chapter 8, the longest in the book..), and throughout it have been using a tool of my own devising. This tool takes another tool of mine, bindump(j)
, and combines its functionality with AOSP's service
and dumpsys
.
Bindump, Dumpsys, Service & More
bindump
bindump
My bindump
is a 100% original tool I had originally derived from service
. Android 8.0 broke my implementation, forcing me to rewrite it from scratch, with my own low-level Binder interface, rather than libbinder
. The tool has its own detailed page, detailing how to use it to list the owners and users of [vnd]Binder users. As of today, it is effectively deprecated in favor of bdsm
, which supports all of its functions.
The main use here is bdsm users
(or owner
), which will find who uses a particular Binder service (or is its owner), like so (su -c
is actually not required for
This is wicked useful. In the example above, users of SurfaceFlinger
mean anyone who has registered a surface
(i.e. has a view
) - and I will explain that in Volume IV someday. Similar interesting services are power
(wakelocks) activity
(app components), etc. The "owner" is useful for pinpointing services hosted by their own binaries - especially if in the vendor space:
And this also works now to list HAL interfaces:
dumpsys
Most users are probably familiar with dumpsys
(or dumpstate
, which uses it). This tool is really a fairly simple client which consists of :
- Look up service node through
servicemanager
- Spin a thread to send a
DUMP_TRANSACTION
to looked up service, along with a pipe (as a Binderize FD) - Let remote to dump output to pipe, read in main thread till EOF and repeat to stdout.
So now that, too, is integrated into bdsm
*. The only difference is I stick to a single thread and (at least for now) directly give out the stdout
handle (i.e. direct to working terminal or '>' redirection. But it still works similarly.
service
AOSP's service
is a generic Binder client, and absolutely one of its most useful CLI utilities. Although it steadily improves (float
s and fd
s at last!), it still falls very short of its true promise. Most of what bdsm
does is first match service
's capabilities, then address this utility's shortcomings.
- Use "list" just like
service list
to get a list of all registered Binder endpoints - But use "vnd" or "hw" to perform the same on thevndbinder
orhwbinder
. The former (requiringroot
sinceshell
can'topen(2)
/dev/vndbinder ) is likevndservice
that you can sometimes find in/vendor/bin . The latter is likelshal
(and uses an entirely different protocol.. - Use "check" to check if a service exists.
- Use "call" the same old fashioned way, groping in the dark for the right method number, hoping you get it right :-)
More**
This is where things get interesting: I've compiled bdsm
with my own AIDL parsing library, which I call aidlwise
. This is really a simple AIDL parser, but opens up wonderful possibilities - once you install the AIDLs. By default, put them all (from AOSP) into bdsm
does the rest:
- First, using
methods
will tell you if the AIDL has been parsed successfully, *and* number the methods for you. Pretty basic, but saves you SO MUCH TIME over doing it manually!grep
is your friend here, to find methods by partial name - Bug fix: service won't call any process refusing INTERFACE_TRANSACTION (_NTF), erroneously claiming it wasn't found.
- You can now call the default methods (_PNG, _PID, etc) by name, instead of figuring out the hard coded number.
- If you have AIDLs installed you can call a method by name (case insensitive), without painful argument types (i.e. no more
i32
,s16
), since I can pick up the argument definitions from the AIDL. Note at this point only primitive types are supported, but that still is useful.
jtrace(j)
(which I've also compiled with AIDLwise) will automatically load them when parsing Binder calls, and tell you the method names and arguments!Questions/comments/etc
always welcome.
This tool (like all my tools) contains no code from AOSP, and is entirely 100% proprietary, original code
Get it
right here. Or HERE (for the nightly build).
Upload to your and then (from root) tar xvf /data/local/tmp/bdsm.tgz
, which will also expand all the AIDL files to /data/local/tmp/aidl
. An experimental ARMv7 version (runs on my 64-bit device but might need fixing for legacy 32-bit devices, which I no longer have) is here. Let me know if it needs any fixes (though note Android deprecates 32-bit as of 8.0 and eliminates it entirely in 13.0).
** - without 'M'ore I'd have ended up with "bds", which would piss off my Israeli readers. Also, considering OpenBinder's origins (and the excruciating suffering inflicted upon me over the years as I tried to figure out how Binder works), I think I ended up with the most apt name possible (with love to @hackbod).