[SCRIPT] Proprietary Lib Cleaner (silence logcat spammers with ease)

Search This thread

broodplank1337

Inactive Recognized Developer
Nov 24, 2011
4,992
10,155
Nijmegen
www.broodplank.net
Proprietary Lib Cleaner (PLC)
Linux shell script that allows you to silence certain lines from chatty proprietary binaries/libs which makes logcat actually readable, instead of it getting spammed by binaries such as mpdecision or thermal-engine.
Made with intention to be easily extensible for end-user. (would love to see a big database of hexxable strings)



Article featured on XDA Portal!:
http://www.xda-developers.com/android/clean-up-your-logcat-code-with-lib-cleaner/


Why I have created it.
I have made this shell script because I have experimented earlier with replacing hex strings in proprietary files, which worked out very well. I have had a lot of hassle trying to make the hex string replace work. But I found this great tool called Swiss File Knife that allows you to make hex replacements by just entering the string. Because of this it was very easy to create a template system so that users can easily add more entries to the database, rather then needing to adjust code of script every time.

plc1.png



The template system works like this:
Every binary/library is placed in the corresponding directory but in a virtual replication, in these files are the lines that need to be hexxed out of the binaries are present. nothing less nothing more.


plc2.png



Example 1:

~/ProprietaryLibCleaner/dbs/system/bin contains mpdecision which is a regular text file with the following strings inside it:

Code:
num online cores: %d reqd : %d available : %d rq_depth:%f
hotplug_avg_load_dw: %d
UP cpu:%d core_idx:%d Nw:%f Tw:%d total_time_up:%f
DOWN cpu:%d core_idx:%d Ns:%f Ts:%d total_time_down:%f
cpu%d: core_idx: %d uptime: %f downtime %f
cpu%d: core_idx: %d Nw: %f, Tw :%d, Ns: %f, Ts: %d, util_high_and:%d
cpus_up: %d cpus_down: %d thermal_mask: 0x%x

Example2:
~/ProprietaryLibCleaner/dbs/system/lib/hw contains sensors.msm8960.so which is also a regular text file since its a patch, it only has a simple reference inside (but a very annoying one)

Code:
mCompEngine is NULL

These 2 examples are listed in the shell script, when more is added it is automatically appended in the 'database'

plc3.png


Last but not least is the patching process which is done on a 'fail-safe' method, it first checks whether its actually applicable before making any changes, if not it will skip it, so it won't make your files unusable

plc4.png





Instructions for normal usage:
1. Download latest release
2. Unpack somewhere on PC
3. Run script with ./PLC
4. Install ADB + ADB USB Driver if not installed
5. Install Swiss File Knife on Phone if not installed
6. View targets & patches
7. Set target and patch
8. Profit

Downloads
Latest version: v0.7 - here or here

Github page:
https://github.com/broodplank/ProprietaryLibCleaner


Additional Credits:
stahlworks - Swiss File Knife
 

Attachments

  • 0.5.zip
    772.8 KB · Views: 80
  • 0.6.zip
    742.8 KB · Views: 38
  • 0.7.zip
    742.8 KB · Views: 237
Last edited:

broodplank1337

Inactive Recognized Developer
Nov 24, 2011
4,992
10,155
Nijmegen
www.broodplank.net
Changelog

Version 0.7 - 19/04/2014
- updated adb downloading method

Version 0.6 - 19/04/2014
- updated lines of mpdecision
- updated compatibility with quotes ( ' ' ) inside lines, was causing thermal-engine patch fail

Version 0.5 - Initial Release - 15/04/2014
 
Last edited:

broodplank1337

Inactive Recognized Developer
Nov 24, 2011
4,992
10,155
Nijmegen
www.broodplank.net
How to make a template / submit a patch

You can get readable strings from file by using 'strings' command.


When using the new beta method (auto submit by using my raspberry pi)


Enter:
1. Your XDA username
2. path to file
3. lines to be patched

If this tool gets abused it will INSTANTLY be taken offline!

http://plcsubmit.broodplank.net/



By posting it as a reply to this topic:


TEMPLATE said:
/path/to/bin/or/lib
Code:
string 1
string 2
string 3
string 4

I will merge it on github then.



By Github pull merge request

For the more advanced developer:

./dbs/system/path/to/bin/or/lib said:
string 1
string 2
string 3
string 4

But then in the git folder

Make a file (same name as target) in right folder with lines inside the file that need to be hexxed.
Then make a merge pull request on Github!
 
Last edited:
  • Like
Reactions: codelover

broodplank1337

Inactive Recognized Developer
Nov 24, 2011
4,992
10,155
Nijmegen
www.broodplank.net
The Sensors get knocked out when you silence sensors.msm8960.so

I have had this once, it was the cause of a invalid hex replacement. but I have been using the hexxed sensors.msm8960.so for a while now and in the app sensorbox everything is showing, compared to nothing showing when a failed hexx is done. please show me the results of sensorbox.

it should work just fine.
 

Chahk

Senior Member
Apr 11, 2009
1,373
234
New York
Samsung Galaxy Z Fold 5
Is it possible to run the patches directly on the phone via terminal emulator or adb shell (assuming all prerequisites like adb, drivers, and sfk are installed)?
 
Last edited:

bsimpson1

Senior Member
Jun 16, 2013
284
88
First of all, thanks a lot for these scripts, and for the tutorial you provided in your other thread on how to patch them manually. The script seemed to work just fine but for some reason the resulting binaries would be a few bytes smaller than the original file and so I'd get an error that would say something about ELF header magic ( can't remember the exact error message) and they could not be executed. I decided to try to create my own script and finally managed to get something working. My original script is run from the phone itself, but I tried to port it to yours as a dbs/patcher script replacement, keeping as much of the original functionality as I could. It seems to work, but could maybe use some polishing. I thought you might be interested in it, as it does not require any installation of extra binaries (it uses grep and dd to perform the functions of sfk). Feel free to use any of it how and where you might see fit. To use it just put it into dbs in place of the original patcher script.

Update: The patcher in patcherv2.zip now correctly restores the file permissions.


As an interesting side note I noticed that with unmodified files, my CPU usage while the phone is otherwise idle and only a single core is active, is reported as 3% with periodic spikes every few seconds of up to 10%. Once the strings are cleaned from the files, the CPU consistently reports usage of 0% or 1%, and the spikes are completely nonexistent.
 

Attachments

  • patcher.zip
    1.4 KB · Views: 25
  • patcherv2.zip
    1.6 KB · Views: 50
Last edited:

broodplank1337

Inactive Recognized Developer
Nov 24, 2011
4,992
10,155
Nijmegen
www.broodplank.net
Is it possible to run the patches directly on the phone via terminal emulator or adb shell (assuming all prerequisites like adb, drivers, and sfk are installed)?

yes with some modification to the code it can do that. but you will have to convert it to real sh script instead of bash. it's somewhat different.

First of all, thanks a lot for these scripts, and for the tutorial you provided in your other thread on how to patch them manually. The script seemed to work just fine but for some reason the resulting binaries would be a few bytes smaller than the original file and so I'd get an error that would say something about ELF header magic ( can't remember the exact error message) and they could not be executed. I decided to try to create my own script and finally managed to get something working. My original script is run from the phone itself, but I tried to port it to yours as a dbs/patcher script replacement, keeping as much of the original functionality as I could. It seems to work, but could maybe use some polishing. I thought you might be interested in it, as it does not require any installation of extra binaries (it uses grep and dd to perform the functions of sfk). Feel free to use any of it how and where you might see fit. To use it just put it into dbs in place of the original patcher script.

Update: The patcher in patcherv2.zip now correctly restores the file permissions.


As an interesting side note I noticed that with unmodified files, my CPU usage while the phone is otherwise idle and only a single core is active, is reported as 3% with periodic spikes every few seconds of up to 10%. Once the strings are cleaned from the files, the CPU consistently reports usage of 0% or 1%, and the spikes are completely nonexistent.

You're welcome. This may be caused because the strings are replaced with "nothing", It might be a good idea for me to count the numbers (in hex) of the string and then replace it all with zero's instead. I think this creates more compatibility, but I'm not 100% sure of that.
Some files indeed get corrupted by hexxing them, (at least when removing strings), maybe putting zero's there would fix it. as I am not advanced in hex at all I honestly don't know before I have tested it.. anyways, the binary templates that are included should not corrupt the files.

I really appreciate you have put this effort in updating the patcher. It really looks awesome, I have not tested it yet, but if it really can replace sfk consistently It will be great. I will take a look at the script and I am certainly interested in it! The script looks pretty advanced to me actually, for example that regex is just badass!
I think I will integrate your patcher and generate an option that lets you choose between your method (local patching, on PC) and my method (remote patching, on phone), that way users could choose what they prefer. Of course I will add your credits to the top because you made it. not me :p

I will look into this very soon, for the meanwhile you could create merge pull requests on the git if you'd like.

And btw I am really glad to hear that removing the strings actually lowered the cpu usage :), that's a great thing! and is absolutely the goal of the script next to making it more readable ^^

Thanks a lot for your wisdom and effort on this patcher :D
 
Last edited:
  • Like
Reactions: Chahk

bsimpson1

Senior Member
Jun 16, 2013
284
88
yes with some modification to the code it can do that. but you will have to convert it to real sh script instead of bash. it's somewhat different.



You're welcome. This may be caused because the strings are replaced with "nothing", It might be a good idea for me to count the numbers (in hex) of the string and then replace it all with zero's instead. I think this creates more compatibility, but I'm not 100% sure of that.
Some files indeed get corrupted by hexxing them, (at least when removing strings), maybe putting zero's there would fix it. as I am not advanced in hex at all I honestly don't know before I have tested it.. anyways, the binary templates that are included should not corrupt the files.

I really appreciate you have put this effort in updating the patcher. It really looks awesome, I have not tested it yet, but if it really can replace sfk consistently It will be great. I will take a look at the script and I am certainly interested in it! The script looks pretty advanced to me actually, for example that regex is just badass!
I think I will integrate your patcher and generate an option that lets you choose between your method (local patching, on PC) and my method (remote patching, on phone), that way users could choose what they prefer. Of course I will add your credits to the top because you made it. not me :p

I will look into this very soon, for the meanwhile you could create merge pull requests on the git if you'd like.

And btw I am really glad to hear that removing the strings actually lowered the cpu usage :), that's a great thing! and is absolutely the goal of the script next to making it more readable ^^

Thanks a lot for your wisdom and effort on this patcher :D

I'm glad to help! I'm not very familiar with binary files myself. I recently noticed that it's possible to simply pass the flag '-o' to the 'strings' command to print the byte offset along with each string! I think that would be a lot more reliable than using grep, not to mention faster. Since that's also how other users will be getting the strings to use for the templates it seems like a very good option also. I'll see if I can come up with a revised version

Unfortunately, the version of strings that's provided by busybox on my phone doesn't have the -o option, but i managed to find a version of the real strings binary with -o support that runs on android, so it could be very possible to eventually make a flashable zip or version that runs on the phone: View attachment strings-armeabi.zip (can't seem to remember where i found this)
 
  • Like
Reactions: broodplank1337

broodplank1337

Inactive Recognized Developer
Nov 24, 2011
4,992
10,155
Nijmegen
www.broodplank.net
I'm glad to help! I'm not very familiar with binary files myself. I recently noticed that it's possible to simply pass the flag '-o' to the 'strings' command to print the byte offset along with each string! I think that would be a lot more reliable than using grep, not to mention faster. Since that's also how other users will be getting the strings to use for the templates it seems like a very good option also. I'll see if I can come up with a revised version

Unfortunately, the version of strings that's provided by busybox on my phone doesn't have the -o option, but i managed to find a version of the real strings binary with -o support that runs on android, so it could be very possible to eventually make a flashable zip or version that runs on the phone: View attachment 2810739 (can't seem to remember where i found this)

Me neither hehe, I just tested the -o flag and you're right :), it works, it returns idd the byte offset. that is nice. and it would be faster for sure, dd'ing some bytes to a certain area has to be faster then grep/replace. But my concern is that maybe the byte offsets are not the same on files, which could easily corrupt the binary if it doesn't match the template. And how do you calculate how many bytes should be flashed to the byte offset? or you just want to jump to the offset and then replace hex? i am not sure which is better honestly. Anyways, I appreciate it that you want to come up with a revised version maybe :p

Oh it didn't? Do you perhaps have an old version of busybox? I have "BusyBox v1.21.1-kk bionic" and for me it works in android (adb shell, with for example "busybox strings -o /system/bin/mpdecision"), so there wouldn't be need for a seperate binary, just an updated busybox.

Anyways, before we could seriously replace the method we need to do a lot of testing ;p
 

Top Liked Posts

  • There are no posts matching your filters.
  • 12
    Proprietary Lib Cleaner (PLC)
    Linux shell script that allows you to silence certain lines from chatty proprietary binaries/libs which makes logcat actually readable, instead of it getting spammed by binaries such as mpdecision or thermal-engine.
    Made with intention to be easily extensible for end-user. (would love to see a big database of hexxable strings)



    Article featured on XDA Portal!:
    http://www.xda-developers.com/android/clean-up-your-logcat-code-with-lib-cleaner/


    Why I have created it.
    I have made this shell script because I have experimented earlier with replacing hex strings in proprietary files, which worked out very well. I have had a lot of hassle trying to make the hex string replace work. But I found this great tool called Swiss File Knife that allows you to make hex replacements by just entering the string. Because of this it was very easy to create a template system so that users can easily add more entries to the database, rather then needing to adjust code of script every time.

    plc1.png



    The template system works like this:
    Every binary/library is placed in the corresponding directory but in a virtual replication, in these files are the lines that need to be hexxed out of the binaries are present. nothing less nothing more.


    plc2.png



    Example 1:

    ~/ProprietaryLibCleaner/dbs/system/bin contains mpdecision which is a regular text file with the following strings inside it:

    Code:
    num online cores: %d reqd : %d available : %d rq_depth:%f
    hotplug_avg_load_dw: %d
    UP cpu:%d core_idx:%d Nw:%f Tw:%d total_time_up:%f
    DOWN cpu:%d core_idx:%d Ns:%f Ts:%d total_time_down:%f
    cpu%d: core_idx: %d uptime: %f downtime %f
    cpu%d: core_idx: %d Nw: %f, Tw :%d, Ns: %f, Ts: %d, util_high_and:%d
    cpus_up: %d cpus_down: %d thermal_mask: 0x%x

    Example2:
    ~/ProprietaryLibCleaner/dbs/system/lib/hw contains sensors.msm8960.so which is also a regular text file since its a patch, it only has a simple reference inside (but a very annoying one)

    Code:
    mCompEngine is NULL

    These 2 examples are listed in the shell script, when more is added it is automatically appended in the 'database'

    plc3.png


    Last but not least is the patching process which is done on a 'fail-safe' method, it first checks whether its actually applicable before making any changes, if not it will skip it, so it won't make your files unusable

    plc4.png





    Instructions for normal usage:
    1. Download latest release
    2. Unpack somewhere on PC
    3. Run script with ./PLC
    4. Install ADB + ADB USB Driver if not installed
    5. Install Swiss File Knife on Phone if not installed
    6. View targets & patches
    7. Set target and patch
    8. Profit

    Downloads
    Latest version: v0.7 - here or here

    Github page:
    https://github.com/broodplank/ProprietaryLibCleaner


    Additional Credits:
    stahlworks - Swiss File Knife
    3
    First of all, thanks a lot for these scripts, and for the tutorial you provided in your other thread on how to patch them manually. The script seemed to work just fine but for some reason the resulting binaries would be a few bytes smaller than the original file and so I'd get an error that would say something about ELF header magic ( can't remember the exact error message) and they could not be executed. I decided to try to create my own script and finally managed to get something working. My original script is run from the phone itself, but I tried to port it to yours as a dbs/patcher script replacement, keeping as much of the original functionality as I could. It seems to work, but could maybe use some polishing. I thought you might be interested in it, as it does not require any installation of extra binaries (it uses grep and dd to perform the functions of sfk). Feel free to use any of it how and where you might see fit. To use it just put it into dbs in place of the original patcher script.

    Update: The patcher in patcherv2.zip now correctly restores the file permissions.


    As an interesting side note I noticed that with unmodified files, my CPU usage while the phone is otherwise idle and only a single core is active, is reported as 3% with periodic spikes every few seconds of up to 10%. Once the strings are cleaned from the files, the CPU consistently reports usage of 0% or 1%, and the spikes are completely nonexistent.
    2
    Wow this looks promising .

    I've been doing some little hex edits on some system binarys, will try this out .

    Regards

    Thank you :), I hope it becomes useful for you
    1
    How to make a template / submit a patch

    You can get readable strings from file by using 'strings' command.


    When using the new beta method (auto submit by using my raspberry pi)


    Enter:
    1. Your XDA username
    2. path to file
    3. lines to be patched

    If this tool gets abused it will INSTANTLY be taken offline!

    http://plcsubmit.broodplank.net/



    By posting it as a reply to this topic:


    TEMPLATE said:
    /path/to/bin/or/lib
    Code:
    string 1
    string 2
    string 3
    string 4

    I will merge it on github then.



    By Github pull merge request

    For the more advanced developer:

    ./dbs/system/path/to/bin/or/lib said:
    string 1
    string 2
    string 3
    string 4

    But then in the git folder

    Make a file (same name as target) in right folder with lines inside the file that need to be hexxed.
    Then make a merge pull request on Github!
    1
    Wow I just noticed the topic was horribly formated! tip to everyone DO NOT USE THE WYSIWYG Editor!