[INF] How to enable dynamic kernel logging (debugfs) on Android/Linux builds? - Android Development on Bada

Maybe can help dev...
Need change some name to adapting with Wave Android script
To enable debugfs based dynamic kernel logging feature, please follow the steps below.
Background:
Recent kernel camera driver in Android (Froyo and after releases) adopted debugfs based kernel logging feature. By default, unlike previous releases, CDBG (camera debug message) logs can be captured dynamically by following procedure section below. You can check if your build has the feature by:
FILE: arch/arm/mach-msm/include/mach/camera.h
...
#define CDBG(fmt, args...) pr_debug(fmt, ##args)
...
Procedure:
Make sure CONFIG_DYNAMIC_DEBUG=y is set into corresponding target defconfig file.
First, please copy the following script provided at the end of this solution in between the marker <<<START OF FILE>> and <<<END OF FILE>>> and create a Windows/DOS batch file with an appropriate, such as "kernel_log.bat".
This batch file requires ADB connection from Windows/DOS to your device.
Execute the script by issuing command: kernel_log.bat enable all
After successful enabling the dynamic kernel logging after step #4, you can capture camera kernel logs like as you used to do in the normal way: ex.) adb shell cat /proc/kmsg > kernel.log
You can selectively enable only relevant logs by specifying the module provided in the script:
All (VFE, Sensor, Gemini, VPE)
kernel_log.bat <enable/disable> all
VFE (msm_io7x.c msm_io8x.c msm_io_vfe31.c msm_vfe31.c msm_vfe7x.c msm_vfe8x.c msm_vfe8x_proc.c msm_io_8x60.c)
kernel_log.bat <enable/disable> vfe
Sensor (sn12m0pz.c sn12m0pz_reg.c mt9d112.c mt9d112_reg.c mt9p012_bam.c mt9p012_fox.c mt9p012_km.c mt9p012_km_reg.c mt9p012_reg.c mt9t013.c mt9t013_reg.c s5k3e2fx.c vb6801.c vx6953.c vx6953_reg.c imx074.c imx074_reg.c)
kernel_log.bat <enable/disable> sensor
VPE (msm_vpe1.c)
kernel_log.bat <enable/disable> vpe
Gemini (msm_gemini_core.c msm_gemini_dev.c msm_gemini_hw.c msm_gemini_platform.c msm_gemini_sync.c)
kernel_log.bat <enable/disable> Gemini
Individual File (under kernel/drivers/media/video/msm with CDBG or pr_debug messages only)
kernel_log.bat <enable/disable> <file names>
FILE: kernel_log.bat
==========<<<START OF FILE>>==========
@echo off
if "%1" == "help" (
echo Usage: kernel_log.bat enable/disable modules
echo Valid modules: all vfe sensor gemini vpe file_name
goto end
)
if "%1" == "" (
echo Usage: kernel_log.bat enable/disable modules
echo Valid modules: all vfe sensor gemini vpe file_name
goto end
)
echo DYNAMIC DEBUG MSG CONF SCRIPT FOR Linux Camera
echo Define module lists for different modules
set all_module_list=flash.c msm_axi_qos.c msm_camera.c msm_gemini_core.c ov8810.c msm_gemini_dev.c msm_gemini_hw.c msm_gemini_platform.c msm_gemini_sync.c msm_io7x.c msm_io8x.c msm_io_vfe31.c msm_v4l2.c msm_vfe31.c msm_vfe7x.c msm_vfe8x.c msm_vfe8x_proc.c mt9d112.c mt9d112_reg.c mt9p012_bam.c mt9p012_fox.c mt9p012_km.c mt9p012_km_reg.c mt9p012_reg.c mt9t013.c mt9t013_reg.c s5k3e2fx.c vb6801.c vx6953.c vx6953_reg.c
set vfe_list=msm_camera.c msm_io7x.c msm_io8x.c msm_io_vfe31.c msm_vfe31.c msm_vfe7x.c msm_vfe8x.c msm_vfe8x_proc.c msm_io_8x60.c
set sensor_list=sn12m0pz.c sn12m0pz_reg.c mt9d112.c mt9d112_reg.c ov8810.cmt9p012_bam.c mt9p012_fox.c mt9p012_km.c mt9p012_km_reg.c mt9p012_reg.c mt9t013.c mt9t013_reg.c s5k3e2fx.c vb6801.c vx6953.c vx6953_reg.c imx074.c imx074_reg.c ov7692.c
set gemini_list=msm_gemini_core.c msm_gemini_dev.c msm_gemini_hw.c msm_gemini_platform.c msm_gemini_sync.c
set vpe_list=msm_camera.c msm_vpe1.c
echo Mount debufs interface
adb shell "mount -t debugfs debugfs /sys/kernel/debug"
if "%2" == "all" (
if "%1" == "enable" (
for %%a in (%all_module_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%all_module_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)
if "%2" == "vfe" (
if "%1" == "enable" (
for %%a in (%vfe_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%vfe_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)
if "%2" == "sensor" (
if "%1" == "enable" (
for %%a in (%sensor_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%sensor_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)
if "%2" == "gemini" (
if "%1" == "enable" (
for %%a in (%gemini_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%gemini_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)
if "%2" == "vpe" (
if "%1" == "enable" (
for %%a in (%vpe_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%vpe_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)
if "%1" == "disable" goto loop_disable
:loop_enable
if "%1" == "enable" adb shell "echo -n \"file %2 +p\" > /sys/kernel/debug/dynamic_debug/control"
shift /2
if not "%2" == "" goto loop_enable
goto end
:loop_disable
if "%1" == "disable" adb shell "echo -n \"file %2 -p\" > /sys/kernel/debug/dynamic_debug/control"
shift /2
if not "%2" == "" goto loop_disable
goto end
:end
echo END OF SCRIPT
==========<<<END OF FILE>>==========

Related

WARNING: Possible malicious games for ROMs with superuser

I've noticed that the latest version of two games by "Cooper Media Corp." are attempting to use su on my phone. The games are "Paradise Island" and "My country". I'm not sure what they are trying to do, the Super User logs don't seem to record the command attempted. See attached screenshot.
I replaced su with:
Code:
#!/system/bin/sh
echo "`date +%F-%T` $$ Args: [email protected]" >> /sdcard/su.log
echo -n '# '
while read line; do
echo `date +%F-%T` $$ Cmd: $line >> /sdcard/su.log
if [ "$line" = "exit" ]; then
echo `date +%F-%T` $$ Exiting >> /sdcard/su.log
exit 0
fi
echo -n '# '
done
And it logged:
2011-08-13-11:47:46 8193 Args:
2011-08-13-11:47:46 8193 Cmd: echo "Do I have root?" >/system/sd/temporary.txt
2011-08-13-11:47:47 8193 Cmd: exit
2011-08-13-11:47:47 8193 Exiting
I created that directory and file, but the game doesn't seem to use su after this point. Perhaps it's waiting for something?
It may just check if you're rooted so you can't edit/manipulate game files and stuff so you can cheat. Are the games internet based? Like FarmVille and stuff?
There's a theory. I think using su for that crosses the line a bit...

[TOOL][WIN]Take screenshots of Aroma and Recovery v1.1

This is a tool to capture screenshots while in Recovery or the Aroma Installer.
Support has ended, due to the possibility of pixel formats changing from each recovery update you receive.
But I did make a better Recovery Screenshot that handles this problem, and it can be found here or below.:cyclops:
http://forum.xda-developers.com/showthread.php?p=50029759​
It's no big secret around XDA that you can use the program FFmpeg to convert your raw framebuffer file into a normal image file. I've found the values for the Nexus 5 and made a batch script that incorporates the programs adb, and ffmpeg; to save screenshots to your computer. I don't have a Nexus 5, but thanks to an XDA user, @ikslawlok, who posted his raw framebuffer from TWRP 2.6.3.4 on another website, I was able to get it working. Also thanks to @rootSU for testing in Philz, a CWM based recovery. This should work on all versions of Windows. I have only tested in Windows 7 personally. The process, as far as using ffmpeg and adb, used here is also possible in Linux. Some versions of ffmpeg for Linux are antiquated, hence there isn't really a write one script; work for all.
Why would anyone use this or do this?
Most people, that probably includes you reading this, have actually no use for it, nor can you think of a reason too. The uses of this are limited to people that write tutorials, custom recovery themes, and the rare event that you have an anomaly in your recovery and you can't describe it.
I owe a big thanks to @Whiskey103 with his work in this thread over in the HTC One forum. :good:
You have to have the adb drivers installed before you can do anything. Go here for more information.
This rar file contains the programs adb and ffmpeg. This 32-bit version of ffmpeg is one of the newest versions available on their downloads page. You must have adb.exe, ffmpeg.exe, and the two dll files for adb in the same directory as the batch file. The easiest thing to do is just extract the rar to a new directory, then run the file named "RUNrsn511.bat" The screenshots you capture will be saved in the same folder that you unzipped everything in as 'timestamp'.png
Thank you @weihan1102 for helping me test and providing your framebuffer from the modified version of TWRP for multirom!
Download Recovery Screenshot v1.1
If you have already downloaded the original version, and wish to update with support for the modified twrp for multirom without downloading the whole new rar, then hit the button below.
The only difference is the RUNrs.bat batch script. You may wish to just download the new batch file here, it is only 1.7KB zipped. It is RUNrsn511.rar and can just be unzipped into the folder you originally unzipped the other files into. I would then delete the original batch file.
An easier way, I think, is to click show content below and click anywhere in the box. Hit Ctrl+A to select everything, hit Ctrl+C to copy it to the clipboard. Then right click on your original RUNrs.bat file, and select edit. Click in that screen anywhere, hit Ctrl+A to select everything in there, then Ctrl+V to paste the new batch script into RUNrs.bat.
Code:
@ECHO OFF
CLS
TITLE Recovery Screenshot v1.1
MODE CON:COLS=54 LINES=40
COLOR 0B
SET TS=0
SET "ffshowb=-hide_banner"
SET "ffdebug=-loglevel fatal"
IF "%~1"=="-d" (
REM @ECHO ON
SET "ffdebug=-loglevel debug"
SET "ffshowb=%"
MODE CON:COLS=140 LINES=250
COLOR 07
ECHO __________________________________________________________________
ECHO DEBUG INFO
ECHO __________________________________________________________________
)
:START
ECHO[
ECHO ______________________________________________________
ECHO This will pull a screenshot from your Nexus 5 and
ECHO save it to the directory that you ran this bat
ECHO file in. Connect USB ^& reboot into your recovery.
ECHO ______________________________________________________
ECHO Thanks to Whiskey103 for the idea!!
ECHO Written by makers_mark
ECHO ______________________________________________________
IF NOT EXIST ffmpeg.exe GOTO NOFILES
IF NOT EXIST adb.exe GOTO NOFILES
ADB kill-server -d >nul 2>&1
IF %TS%=="NOGOOD" GOTO SKIPPEDthatPause
ECHO Press 1 or 2
ECHO 1 - Save a screenshot using multirom twrp recovery
ECHO 2 - Save a screenshot using other recoveries
ECHO ______________________________________________________
CHOICE /C:12 >nul
IF ERRORLEVEL 1 SET K=1
IF ERRORLEVEL 2 SET K=2
IF %K%==1 SET "pixfmt=-pix_fmt rgb565"
IF %K%==2 SET "pixfmt=-pix_fmt rgb0"
:SKIPPEDthatPause
ECHO[
ECHO Pulling framebuffer from /dev/graphics/fb0
adb pull /dev/graphics/fb0 frmbfr >nul
IF ERRORLEVEL 1 (cls
SET TS="NOGOOD"
ECHO ______________________________________________________
ECHO Adb is not properly connected.
ECHO Try "Safely Removing" your N5 from your computer
ECHO Then unplug your usb cable, and reinsert it.
ECHO ______________________________________________________
ECHO[
ECHO[
ECHO Press any key to try again.
ECHO[
ECHO[
PAUSE >nul
CLS
GOTO START
)
SET TS=%DATE:/=%_%TIME::=_%
SET TS=%TS:.=%
SET TS=%TS: =%.png
FFMPEG %ffdebug% %ffshowb% -f rawvideo -vcodec rawvideo %pixfmt% -s 1088x1920 -i frmbfr -vf crop=1080:1920:0:0 -y %TS%
IF NOT EXIST %TS% GOTO ERRNE
DEL frmbfr >nul
ECHO ______________________________________________________
ECHO Screenshot saved as %TS%
ECHO ______________________________________________________
ECHO Press 1 or 2
ECHO 1 - Save another screenshot
ECHO 2 - Exit
ECHO ______________________________________________________
CHOICE /C:12 >nul
IF ERRORLEVEL 1 SET K=1
IF ERRORLEVEL 2 SET K=2
IF %K%==1 GOTO SKIPPEDthatPause
IF %K%==2 GOTO FINISH
:NOFILES
CLS
ECHO The directory that you are running this script in is:
ECHO %~dp0
ECHO[
ECHO You must run this script in the same directory as
ECHO adb.exe and ffmpeg.exe. Press any key to exit
PAUSE >nul
EXIT
:ERRNE
CLS
MODE CON:COLS=108 LINES=200
COLOR 07
FFMPEG -loglevel debug -f rawvideo -vcodec rawvideo %pixfmt% -s 1088x1920 -i frmbfr -vf crop=1080:1920:0:0 -y %TS%
ECHO ____________________________________________________________________________________________________________
ECHO There was a problem converting the framebuffer to a png file.
ECHO[
ECHO To capture the screen of the cmd window, hold down the alt key and press PrtSc on your keyboard. This
ECHO will save an image of the current window in memory on your clipboard. Then open paint or photoshop or
ECHO whatever program you use and hit ctrl+N to open a new file, then ctrl+V to paste an image. Save it and
ECHO please message me it or post in the XDA forum thread.
ECHO[
ECHO[
ECHO If you got to this screen and are not using a Nexus 5, congratulations for successfully pulling the
ECHO framebuffer. To figure out the resolution to use, try adding 4,8, or 16 to your native width to make it
ECHO evenly divisible by 32. Example resolution is 1080x1920..1080^/32^=33.75 ^< not right, so try 1088^/32^=34 ^< good
ECHO Only worry about width (left to right), height is stored orderly in memory.
ECHO[
ECHO To see a list of all of the pix_fmts supported by ffmpeg, run ffmpeg -pix_fmts
ECHO[
ECHO Press 1 or 2
ECHO 1 - Show available pixel formats
ECHO 2 - Exit
CHOICE /C:12
IF ERRORLEVEL 1 SET K=1
IF ERRORLEVEL 2 SET K=2
IF %K%==1 (cls
MODE CON:COLS=52 LINES=200
ffmpeg -hide_banner -pix_fmts
pause
GOTO FINISH)
IF %K%==2 GOTO FINISH
:FINISH
ADB kill-server -d
EXIT
I have more screenshots at my 2013 Nexus 7 thread.
Batch script v1.1
Code:
@ECHO OFF
CLS
TITLE Recovery Screenshot v1.1
MODE CON:COLS=54 LINES=40
COLOR 0B
SET TS=0
SET "ffshowb=-hide_banner"
SET "ffdebug=-loglevel fatal"
IF "%~1"=="-d" (
REM @ECHO ON
SET "ffdebug=-loglevel debug"
SET "ffshowb=%"
MODE CON:COLS=140 LINES=250
COLOR 07
ECHO __________________________________________________________________
ECHO DEBUG INFO
ECHO __________________________________________________________________
)
:START
ECHO[
ECHO ______________________________________________________
ECHO This will pull a screenshot from your Nexus 5 and
ECHO save it to the directory that you ran this bat
ECHO file in. Connect USB ^& reboot into your recovery.
ECHO ______________________________________________________
ECHO Thanks to Whiskey103 for the idea!!
ECHO Written by makers_mark
ECHO ______________________________________________________
IF NOT EXIST ffmpeg.exe GOTO NOFILES
IF NOT EXIST adb.exe GOTO NOFILES
ADB kill-server -d >nul 2>&1
IF %TS%=="NOGOOD" GOTO SKIPPEDthatPause
ECHO Press 1 or 2
ECHO 1 - Save a screenshot using multirom twrp recovery
ECHO 2 - Save a screenshot using other recoveries
ECHO ______________________________________________________
CHOICE /C:12 >nul
IF ERRORLEVEL 1 SET K=1
IF ERRORLEVEL 2 SET K=2
IF %K%==1 SET "pixfmt=-pix_fmt rgb565"
IF %K%==2 SET "pixfmt=-pix_fmt rgb0"
:SKIPPEDthatPause
ECHO[
ECHO Pulling framebuffer from /dev/graphics/fb0
adb pull /dev/graphics/fb0 frmbfr >nul
IF ERRORLEVEL 1 (cls
SET TS="NOGOOD"
ECHO ______________________________________________________
ECHO Adb is not properly connected.
ECHO Try "Safely Removing" your N5 from your computer
ECHO Then unplug your usb cable, and reinsert it.
ECHO ______________________________________________________
ECHO[
ECHO[
ECHO Press any key to try again.
ECHO[
ECHO[
PAUSE >nul
CLS
GOTO START
)
SET TS=%DATE:/=%_%TIME::=_%
SET TS=%TS:.=%
SET TS=%TS: =%.png
FFMPEG %ffdebug% %ffshowb% -f rawvideo -vcodec rawvideo %pixfmt% -s 1088x1920 -i frmbfr -vf crop=1080:1920:0:0 -y %TS%
IF NOT EXIST %TS% GOTO ERRNE
DEL frmbfr >nul
ECHO ______________________________________________________
ECHO Screenshot saved as %TS%
ECHO ______________________________________________________
ECHO Press 1 or 2
ECHO 1 - Save another screenshot
ECHO 2 - Exit
ECHO ______________________________________________________
CHOICE /C:12 >nul
IF ERRORLEVEL 1 SET K=1
IF ERRORLEVEL 2 SET K=2
IF %K%==1 GOTO SKIPPEDthatPause
IF %K%==2 GOTO FINISH
:NOFILES
CLS
ECHO The directory that you are running this script in is:
ECHO %~dp0
ECHO[
ECHO You must run this script in the same directory as
ECHO adb.exe and ffmpeg.exe. Press any key to exit
PAUSE >nul
EXIT
:ERRNE
CLS
MODE CON:COLS=108 LINES=200
COLOR 07
FFMPEG -loglevel debug -f rawvideo -vcodec rawvideo %pixfmt% -s 1088x1920 -i frmbfr -vf crop=1080:1920:0:0 -y %TS%
ECHO ____________________________________________________________________________________________________________
ECHO There was a problem converting the framebuffer to a png file.
ECHO[
ECHO To capture the screen of the cmd window, hold down the alt key and press PrtSc on your keyboard. This
ECHO will save an image of the current window in memory on your clipboard. Then open paint or photoshop or
ECHO whatever program you use and hit ctrl+N to open a new file, then ctrl+V to paste an image. Save it and
ECHO please message me it or post in the XDA forum thread.
ECHO[
ECHO[
ECHO If you got to this screen and are not using a Nexus 5, congratulations for successfully pulling the
ECHO framebuffer. To figure out the resolution to use, try adding 4,8, or 16 to your native width to make it
ECHO evenly divisible by 32. Example resolution is 1080x1920..1080^/32^=33.75 ^< not right, so try 1088^/32^=34 ^< good
ECHO Only worry about width (left to right), height is stored orderly in memory.
ECHO[
ECHO To see a list of all of the pix_fmts supported by ffmpeg, run ffmpeg -pix_fmts
ECHO[
ECHO Press 1 or 2
ECHO 1 - Show available pixel formats
ECHO 2 - Exit
CHOICE /C:12
IF ERRORLEVEL 1 SET K=1
IF ERRORLEVEL 2 SET K=2
IF %K%==1 (cls
MODE CON:COLS=52 LINES=200
ffmpeg -hide_banner -pix_fmts
pause
GOTO FINISH)
IF %K%==2 GOTO FINISH
:FINISH
ADB kill-server -d
EXIT
Batch script v1
Code:
@ECHO OFF
CLS
TITLE Recovery Screenshot
MODE CON:COLS=54 LINES=40
COLOR 0B
SET TS=0
SET "ffshowb=-hide_banner"
SET "ffdebug=-loglevel fatal"
IF "%~1"=="-d" (
REM @ECHO ON
SET "ffdebug=-loglevel debug"
SET "ffshowb=%"
MODE CON:COLS=140 LINES=250
COLOR 07
ECHO __________________________________________________________________
ECHO DEBUG INFO
ECHO __________________________________________________________________
)
:START
ECHO[
ECHO ______________________________________________________
ECHO This will pull a screenshot from your Nexus 5 and
ECHO save it to the directory that you ran this bat
ECHO file in. Connect USB ^& reboot into your recovery.
ECHO ______________________________________________________
ECHO Thanks to Whiskey103 for the idea!!
ECHO Written by makers_mark
ECHO ______________________________________________________
IF NOT EXIST ffmpeg.exe GOTO NOFILES
IF NOT EXIST adb.exe GOTO NOFILES
ADB kill-server -d >nul 2>&1
IF %TS%=="NOGOOD" GOTO SKIPPEDthatPause
ECHO Press any key when you are ready.
PAUSE >nul
:SKIPPEDthatPause
ECHO[
ECHO Pulling framebuffer from /dev/graphics/fb0
adb pull /dev/graphics/fb0 frmbfr >nul
IF ERRORLEVEL 1 (cls
SET TS="NOGOOD"
ECHO ______________________________________________________
ECHO Adb is not properly connected.
ECHO Try "Safely Removing" your N5 from your computer
ECHO Then unplug your usb cable, and reinsert it.
ECHO ______________________________________________________
ECHO[
ECHO[
ECHO Press any key to try again.
ECHO[
ECHO[
PAUSE >nul
CLS
GOTO START
)
SET TS=%DATE:/=%_%TIME::=_%
SET TS=%TS:.=%
SET TS=%TS: =%.png
FFMPEG %ffdebug% %ffshowb% -f rawvideo -vcodec rawvideo -pix_fmt rgb0 -s 1088x1920 -i frmbfr -vf crop=1080:1920:0:0 -y %TS%
IF NOT EXIST %TS% GOTO ERRNE
DEL frmbfr >nul
ECHO ______________________________________________________
ECHO Screenshot saved as %TS%
ECHO ______________________________________________________
ECHO Press 1 or 2
ECHO 1 - Save another screenshot
ECHO 2 - Exit
ECHO ______________________________________________________
CHOICE /C:12 >nul
IF ERRORLEVEL 1 SET K=1
IF ERRORLEVEL 2 SET K=2
IF %K%==1 GOTO SKIPPEDthatPause
IF %K%==2 GOTO FINISH
:NOFILES
CLS
ECHO The directory that you are running this script in is:
ECHO %~dp0
ECHO[
ECHO You must run this script in the same directory as
ECHO adb.exe and ffmpeg.exe. Press any key to exit
PAUSE >nul
EXIT
:ERRNE
CLS
MODE CON:COLS=108 LINES=200
COLOR 07
FFMPEG -loglevel debug -f rawvideo -vcodec rawvideo -pix_fmt rgb0 -s 1088x1920 -i frmbfr -vf crop=1080:1920:0:0 -y %TS%
ECHO ____________________________________________________________________________________________________________
ECHO There was a problem converting the framebuffer to a png file.
ECHO[
ECHO To capture the screen of the cmd window, hold down the alt key and press PrtSc on your keyboard. This
ECHO will save an image of the current window in memory on your clipboard. Then open paint or photoshop or
ECHO whatever program you use and hit ctrl+N to open a new file, then ctrl+V to paste an image. Save it and
ECHO please message me it or post in the XDA forum thread.
ECHO[
ECHO[
ECHO If you got to this screen and are not using a Nexus 5, congratulations for successfully pulling the
ECHO framebuffer. To figure out the resolution to use, try adding 4,8,16, or 32 to your native width to make
ECHO room for the extra data, ioctrls?, at the end of each pixel row. Experiment with different pixel formats
ECHO also.
ECHO[
ECHO To see a list of all of the pix_fmts supported by ffmpeg, run ffmpeg -pix_fmts
ECHO[
ECHO Press 1 or 2
ECHO 1 - Show available pixel formats
ECHO 2 - Exit
CHOICE /C:12
IF ERRORLEVEL 1 SET K=1
IF ERRORLEVEL 2 SET K=2
IF %K%==1 (cls
MODE CON:COLS=52 LINES=200
ffmpeg -hide_banner -pix_fmts
pause
GOTO FINISH)
IF %K%==2 GOTO FINISH
:FINISH
ADB kill-server -d
EXIT
Great! It worked!
I've just test it on my Nexus5.
Thanks!
Thanks! but seems like the color isn't correct and it content 4 screenshot in a single png file.
weihan1102 said:
Thanks! but seems like the color isn't correct and it content 4 screenshot in a single png file.
Click to expand...
Click to collapse
It looks like the multirom twrp uses a different kernel.
Can you do me a favor and substitute '-pix_fmt rgb0' with '-pix_fmt rgba' in the batch file?
To edit the batch file just right click it and choose edit. Find the lines, there's two of them, that start with ffmpeg..... and replace the part above. Save it and try again.
makers_mark said:
It looks like the multirom twrp uses a different kernel.
Can you do me a favor and substitute '-pix_fmt rgb0' with '-pix_fmt rgba' in the batch file?
To edit the batch file just right click it and choose edit. Find the lines, there's two of them, that start with ffmpeg..... and replace the part above. Save it and try again.
Click to expand...
Click to collapse
No, the color change but still not the correct color
weihan1102 said:
No, the color change but still not the correct color
Click to expand...
Click to collapse
Can you change the pix_fmt to bgra? I could figure it out later if you could upload your framebuffer file later, I won't be able to be around a computer for about 11 or 12 hours from now.
To save the framebuffer to your computer : shift + right click on the folder adb and other files are in, and select run cmd here. In the command window type 'adb pull /dev/graphics/fb0 rawfb0.raw'. The file rawfb0.raw will be in that same folder now.
makers_mark said:
Can you change the pix_fmt to bgra? I could figure it out later if you could upload your framebuffer file later, I won't be able to be around a computer for about 11 or 12 hours from now.
To save the framebuffer to your computer : shift + right click on the folder adb and other files are in, and select run cmd here. In the command window type 'adb pull /dev/graphics/fb0 rawfb0.raw'. The file rawfb0.raw will be in that same folder now.
Click to expand...
Click to collapse
bgra didn't work.
and the rawfb0.raw, here you are
https://drive.google.com/file/d/0B5FN-6JxBhASempFLTFUSDlkX3c/edit?usp=sharing
weihan1102 said:
bgra didn't work.
and the rawfb0.raw, here you are
https://drive.google.com/file/d/0B5FN-6JxBhASempFLTFUSDlkX3c/edit?usp=sharing
Click to expand...
Click to collapse
Thank you so much! I will fix it when I get home.

Problem of the tutorial: formatting the SD Card into Internal Storage

Hello everyone,
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
I've recently checked a tutorial about the auto-formatting the sd card into internal storage since I don't have space in my storage anymore.
https://forum.xda-developers.com/android/software/auto-formatting-sdcard-to-internal-t3583875
I did all instructions, but to the last part with the command "sm partition disk 179:194 private (or mixed 50)" it shows an error message.
You can find what I followed to the link I've put up there, and I'll ask two questions:
1. How can I do the auto-formatting with aftiss.cmd?
2. How can I fix this error message?
I hope that we'll be able to find a solution to this problem ^^
(PS: for anyone who asks "Why don't you go to the SD card and format as internal directly?" WELL, it's just that I don't have this option, I got a Huawei P8 Lite version, PRA-LX1)
May be on your phone it's not allowed the SD card to be formatted as internal memory.
Guess I have to buy another SD card then :/
But I'll wait for some other comment and see what they will say
Kaguma said:
Guess I have to buy another SD card then :/
But I'll wait for some other comment and see what they will say
Click to expand...
Click to collapse
Simply run
Code:
adb shell
sm has-adoptable
to see whether "false" or "true" is returned.
If it's "false", is there a way to put it on "true"?
Kaguma said:
If it's "false", is there a way to put it on "true"?
Click to expand...
Click to collapse
Buy a phone that supports it.
But except of having another phone, can't I put it on "true" even with my actual phone? There isn't a way at all?
@Kaguma
Here a small Windows command script that shows all the steps to be performed to transform an external SD-card into internal memory
Important: This is not tested so be aware of potential mistakes
Code:
rem (c) 2020 [email protected] Licensed under GPL v3
@echo OFF & setlocal ENABLEDELAYEDEXPANSION
echo FORMATTING EXTERNAL SD-CARD TO BE USED AS INTERNAL MEMORY ...
set "retval="
set /a device_connected=0
for /f "tokens=*" %%a in ('adb devices') do (
set "retval=%%a"
if NOT [!retva!]==[] (
echo !retval! | findstr /C:":" >nul
if !errorlevel! EQU 0 (set /a device_connected=1 )
)
)
if !device_connected! EQU 0 ( echo NO ANDROID DEVICE CONNECTED & goto :end )
set /a adoptable_sd_memory_is_supported=0
for /f "tokens=*" %%a in ('adb shell "sm has-adoptable"') do (
set "retval=%%a"
if NOT [!retval!]==[] (
echo !retval! | findstr /I /C:"true" >nul
if !errorlevel! EQU 0 ( set /a adoptable_sd_memory_is_supported=1 )
)
)
if !adoptable_sd_memory_is_supported! EQU 0 ( echo FEATURE ADOPTABLE MEMORY NOT SUPPORTED & goto :end )
set "private_sd_card_partition="
for /f "tokens=*" %%a in ('adb shell "sm list-disks adoptable"') do (
set "retval=%%a"
if NOT [!retval!]==[] (
echo !retval! | findstr /C:"disk:" >nul
if !errorlevel! EQU 0 ( set "private_sd_card_partition=!retval!" )
)
)
if [!private_sd_card_partition!]==[] ( echo NO MOUNTABLE SD-CARD PARTITION FOUND & goto :end )
rem
rem Depending on ROM instead of e.g. 179,128 obviously 179_128 must be used
rem If so, uncomment next command line
rem
rem set "private_sd_card_partition=!private_sd_card_partition:,=_!"
echo TRANSFORMING WHOLE EXTERNAL SD-CARD INTO INTERNAL MEMORY ...
echo IT TAKES TIME. BE PATIENT.
adb shell "sm set-force-adoptable true" >nul 2>nul
adb shell "sm partition !private_sd_card_partition! private" >nul 2>nul
adb shell "sm set-force-adoptable false" >nul 2>nul
echo DEVICE NOW GETS RE-BOOTED: DON'T UNPLUG SD-CARD.
adb reboot
adb wait-for-device >nul
:check_for_device_has_booted
for /f "tokens=*" %%a in ('adb shell "getprop sys.boot_completed"') do (
set "retval=%%a"
if NOT [!retval!]==[] (
echo !retval! | findstr /C:"1" >nul
if !errorlevel! EQU 0 ( goto :done_check_for_device_has_booted )
)
)
timeout /t 10 /nobreak >nul
goto :check_for_device_has_booted
:done_check_for_device_has_booted
set /a adoptable_storage_created=1
for /f "tokens=*" %%a in ('adb shell "sm list-volumes all"') do (
set "retval=%%a"
if NOT [!retval!]==[] (
echo !retval! | findstr /C:"private mounted null" >nul
if !errorlevel! EQU 0 ( set /a adoptable_storage_created=0 & goto :done_check_for_created)
)
)
:done_check_for_created
if !adoptable_storage_created! EQU 1 ( echo SUCCESS & goto :end )
echo FAILED
:end
pause >nul
echo Press any key to continue ...
endlocal & @echo on
exit
jwoegerbauer said:
@Kaguma
Here a small Windows command script that shows all the steps to be performed to transform an external SD-card into internal memory
Important: This is not tested so be aware of potential mistakes
Code:
rem (c) 2020 [email protected] Licensed under GPL v3
@echo OFF & setlocal ENABLEDELAYEDEXPANSION
echo FORMATTING EXTERNAL SD-CARD TO BE USED AS INTERNAL MEMORY ...
set "retval="
set /a device_connected=0
for /f "tokens=*" %%a in ('adb devices') do (
set "retval=%%a"
if NOT [!retva!]==[] (
echo !retval! | findstr /C:":" >nul
if !errorlevel! EQU 0 (set /a device_connected=1 )
)
)
if !device_connected! EQU 0 ( echo NO ANDROID DEVICE CONNECTED & goto :end )
set /a adoptable_sd_memory_is_supported=0
for /f "tokens=*" %%a in ('adb shell "sm has-adoptable"') do (
set "retval=%%a"
if NOT [!retval!]==[] (
echo !retval! | findstr /I /C:"true" >nul
if !errorlevel! EQU 0 ( set /a adoptable_sd_memory_is_supported=1 )
)
)
if !adoptable_sd_memory_is_supported! EQU 0 ( echo FEATURE ADOPTABLE MEMORY NOT SUPPORTED & goto :end )
set "private_sd_card_partition="
for /f "tokens=*" %%a in ('adb shell "sm list-disks adoptable"') do (
set "retval=%%a"
if NOT [!retval!]==[] (
echo !retval! | findstr /C:"disk:" >nul
if !errorlevel! EQU 0 ( set "private_sd_card_partition=!retval!" )
)
)
if [!private_sd_card_partition!]==[] ( echo NO MOUNTABLE SD-CARD PARTITION FOUND & goto :end )
rem
rem Depending on ROM instead of e.g. 179,128 obviously 179_128 must be used
rem If so, uncomment next command line
rem
rem set "private_sd_card_partition=!private_sd_card_partition:,=_!"
echo TRANSFORMING WHOLE EXTERNAL SD-CARD INTO INTERNAL MEMORY ...
echo IT TAKES TIME. BE PATIENT.
adb shell "sm set-force-adoptable true" >nul 2>nul
adb shell "sm partition !private_sd_card_partition! private" >nul 2>nul
adb shell "sm set-force-adoptable false" >nul 2>nul
echo DEVICE NOW GETS RE-BOOTED: DON'T UNPLUG SD-CARD.
adb reboot
adb wait-for-device >nul
:check_for_device_has_booted
for /f "tokens=*" %%a in ('adb shell "getprop sys.boot_completed"') do (
set "retval=%%a"
if NOT [!retval!]==[] (
echo !retval! | findstr /C:"1" >nul
if !errorlevel! EQU 0 ( goto :done_check_for_device_has_booted )
)
)
timeout /t 10 /nobreak >nul
goto :check_for_device_has_booted
:done_check_for_device_has_booted
set /a adoptable_storage_created=1
for /f "tokens=*" %%a in ('adb shell "sm list-volumes all"') do (
set "retval=%%a"
if NOT [!retval!]==[] (
echo !retval! | findstr /C:"private mounted null" >nul
if !errorlevel! EQU 0 ( set /a adoptable_storage_created=0 & goto :done_check_for_created)
)
)
:done_check_for_created
if !adoptable_storage_created! EQU 1 ( echo SUCCESS & goto :end )
echo FAILED
:end
pause >nul
echo Press any key to continue ...
endlocal & @echo on
exit
Click to expand...
Click to collapse
It's really huge, I could maybe test it, thanks
I'll just wait for other answers, but really thanks
Also, do I have to put it after I put the command "adb shell" or where?
And good morning, by the way ^^
(EDIT: What are the eventual consequences / mistakes?)
Kaguma said:
Also, do I have to put it after I put the command "adb shell" or where?
And good morning, by the way ^^
(EDIT: What are the eventual consequences / mistakes?)
Click to expand...
Click to collapse
1. IT'S A WINDOWS COMMAND SCRIPT TO AVOID TYPING
If you want to make use of it, here's the
HOW-TO:
You add /path/to/ADB to Window's PATH environment variable via Windows command prompt ( CMD ) and not via Windows Powershell ( PS )
Code:
set PATH=%PATH%;[color=red]path/to/ADB[/color]
- where /path/to/ADB for example is C:\ADB - and re-boot computer
You create a Windows .BAT file that contains the code listed above - preferredly by copy & paste - and save it under SDTRANSFORMER.BAT
You put the SD-card to be transformed into phone
You connect your running phone via USB cable with computer
You run the .BAT file previously created
As mentioned: Script may contain bugs, if so, then it's on you to fix them - I don't have SD-cards that lie around ..
2. YOU CAN USE ANDROID TERMINAL TO EXECUTE ALL THE SM * COMMANDS , TOO
Notice that this was my last post here, I no longer participate in this thread. Sorry for this.
Thanks for your help, and have a nice day even if you won't reply here
Hi Kaguma,
it doesn't work for Huawei P8 Lite...
stackoverflow.com/questions/60173545/why-i-got-this-error-please-adoptable-storage-not-available-on-device-with-nat
You can try this :
forum.xda-developers.com/p8lite/p8-lite-2017-development/rom-lineageos-17-1-huawei-p8-lite-2017-t4064121

A script to get a random file

Dear developers,
I have an issue in my script switching from Android 9 to 10 (devices from a Umidigi s3 Pro to a Umidigi F2)
I have installed Bosybox App on the first and Busybox Magisk module on the latter
Now the script does not work because the command
list=(`busybox find "$dirs" -type f -name *.$ext`)
returns an empty array
This is the complete script:
Bash:
#!/system/bin/sh
echo
if test "$1" = ""; then
echo "Randomfile script by Uranya <[email protected]> v1.4 01.01.2021"
echo "Usage:"
echo "sh randomfile.sh <sourcedir> <extension> <destdir>"
exit 1
fi
dirs=$1
ext=$2
dird=$3'/'
dest=$dird'random'
delim1=""
delim2=""
last='last.txt'
# create filename's array
IFS=$'\n'
# here we have the ISSUE
list=(`busybox find "$dirs" -type f -name *.$ext`)
# count number of files
num=${#list[@]}
# initialize random generator
RANDOM=$$
# generate random number in range 1-NUM
let "ran=(${RANDOM} % ${num})+ 1"
echo Random from $num files is $ran
sour=${list[ran]}
sourn=${sour#$dirs}
sourn=${sourn:1:${#sourn}}
date=$(date +"%Y.%m.%d %H:%M")
day=$(date +"%d")
hour=$(date +"%H")
minute=$(date +"%M")
message='---------------------------------------\n'$date' - '$num' >>> '$ran'\n'$delim1$sourn$delim2
if ([ "$day" = "01" ] && [[ "$minute" < "29" ]]) || [ ! -f $dird$last ]; then
echo >$dird$last $message
else
sed -i '1i'$message $dird$last
fi
echo $delim1$sourn$delim2
# rename the old file
cp $dest.$ext $dest'_back.'$ext
# copy the file
cat "$sour" >$dest.$ext
echo File copied as $delim1$dest.$ext$delim2
Can you please help me why this happens, and how to fix it?
Thank you very much for your attention!
Uranya said:
[...]
Click to expand...
Click to collapse
Having done some tests I have found this:
opening a root privileged terminal and executing
---
echo `find /storage/7BC3-1805/Music/MP3/Abba -type f -name *.mp3`
---
it returns two strings containing the names of files inside that folder, but putting it in my script continues to return an empty array, so the issue is not in the access to the folder, but in the syntax, I guess
try putting that *.$ext into quotes...
Dear friends, CXZa, after a couple of hours debugging the script, finally, I have found the mistake!
The line to be used is:
list=( `find "$dirs" -type f -name "*.$ext"` )
it is a very subtle difference: the space after and before the parenthesis!
(even the word busybox is useless)
Oddly in the Busybox app (I have had on my S3 Pro) the spaces are not mandatory, whilst in the Busybox Magisk module those spaces ARE mandatory!
I'm using that script for almost 8 years to have an every day different music for my wake up.
I'm using Tasker to call it just before my alarm get off, so the same file contains every day, a different song.
I have done a change also in the array index that did not began by 0...
So, here it is the right script:
Bash:
#!/system/bin/sh
echo
if test "$1" = ""; then
echo "Randomfile script by Uranya <@uranya7x> v1.5 26.03.2021"
echo "Usage:"
echo "sh randomfile.sh <sourcedir> <extension> <destdir>"
exit 1
fi
dirs=$1
ext=$2
dird=$3'/'
dest=$dird'random'
delim1=""
delim2=""
last='last.txt'
# create filename's array
IFS=$'\n'
list=( `find "$dirs" -type f -name "*.$ext"` )
# count number of files
num=${#list[@]}
# generate random number in range 1-NUM
let "ran=(${RANDOM} % ${num})+ 1"
echo Random from $num files is $ran
sour=${list[$ran-1]}
sourn=${sour#$dirs}
sourn=${sourn:1:${#sourn}}
date=$(date +"%Y.%m.%d %H:%M")
day=$(date +"%d")
hour=$(date +"%H")
minute=$(date +"%M")
message='---------------------------------------\n'$date' - '$num' >>> '$ran'\n'$delim1$sourn$delim2
if ([ "$day" = "01" ] && [[ "$minute" < "29" ]]) || [ ! -f $dird$last ]; then
echo >$dird$last $message
else
sed -i '1i'$message $dird$last
fi
echo $delim1$sourn$delim2
# rename the old file
cp $dest.$ext $dest'_back.'$ext
# copy the file
cat "$sour" >$dest.$ext
echo File copied as $delim1$dest.$ext
I hope it will be useful to someone else that loves to be waked up by music...
Peace everywhere!

How To Guide Add updated TOYBOX w/ ROOT to Windows Subsystem for Android™️

Preface​
Unfortunately Windows Subsystem for Android (WSA) is missing fully fledged Toybox ( This is a package of over 200 command-line tools, handy for advanced users - it's located in /usr/{bin,sbin} ) - though according to Microsoft WSA is meant to be used by app developers, as development platform, IIRC.
Toybox v0.8.4 ( released 2020-10-24 ) commands currently provided:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
So IMO it's time to install latest fully-fledged version ( at time of this writing it's 0.8.8 released 2022-08-12 ) of Toybox on WSA:
As you can see currently the fully-fledged Toybox command suite contains the SU command ( Toybox as provided with WSA is missing it ) what allows you to root Android, will say give you elevated rights so you get complete access to everything in the operating system, and those permissions allow you to change it all.​
Remarks​USB-Debugging is by default enabled in WSA to implicitly give up your encryption secrets to the connected computer: WSA performs per-file encryption that is software-based.
This suggested updating doesn't replace / remove the pre-installed Toybox version.
Installation into Android's data partition ( recommended )​The roadmap
Connect PC to WSA
Save SELinux context of preinstalled Toybox
Download attached Toybox binary and extract it to any location on PC, e.g. C:\
Download attached SU binary and extract it to any location on PC, e.g. C:\
Next thing to do is to transfer the attached SU binary - assumed it got stored in C:\ - to /sdcard/Download because during the updating process we sometimes need elevated rights
and give executable rights to it
and set its file-ownership-UID 2000 is the default user on WSA
Create a directory named toybox under /data/local/tmp
Transfer the downloaded toybox binary to /sdcard/Download
Disable SElinux what by default in WSA is enabled
Copy the transferred toybox binary to /data/local/tmp what sets its owner to shell:shell
and give executable permission to it. (The default permissions set for other binaries is rwxr-xr-x)
Create symlinks for the all the various tools accessible by toybox binary
Set SELinux context on all files created
Re-enable SELinux because by default in WSA it's enabled
Do some housekeeping ...
and restart WSA
The script - it's a hybrid DOS / Linux coded one
@Echo off & setlocal ENABLEDELAYEDEXPANSION
popd "%CD%"
::
title WSA Toybox Updater
color f0 & mode con: cols=54 lines=40
echo(
echo ####################################
echo # #
echo # WSA Toybox Updater #
echo # #
echo # Updates existing Toybox to #
echo # version 0.8.8 what comes with #
echo # SU-function embeddedd #
echo # #
echo # (c) 2022 [email protected] #
echo # License: BSD 2-Clause #
echo # #
echo ####################################
echo(
echo Press 1 to Continue, 0 to Abort
choice /C 10 /M "Please select"
if !errorlevel! NEQ 1 ( goto :done )
cls
::
set "adb="
set "subin="
set "tbbin="
set "adb_org=adb_r33.0.3.exe"
set "tbbin_org=toybox-x86_64"
set "subin_org=su-x86_64"
set "wsa_svc=WsaService.exe"
set "address=127.0.0.1"
::
:: Sanity checks
echo(
echo Verifying availability of required files ..
for /F "tokens=*" %%t in ('fsutil fsinfo drives') do ( set "drives=%%t" )
:: 1st check folder we are running this bat from, 2nd search all drives
set "drive=%CD:~0,2%"
for /F "tokens=*" %%t in ('where /R !drive! !adb_org! 2^>nul') do ( set "adb=%%t" )
if defined adb ( goto :done_query_adb_org )
for /F "tokens=2* delims= " %%a in ("!drives!") do (
set "drive2=%%a"
for /F "tokens=*" %%t in ('where /R !drive2! !adb_org! 2^>nul') do ( set "adb=%%t" )
if defined adb ( goto :done_query_adb_org )
)
echo FATAL: !adb_org! not found on PC & goto :failed
:done_query_adb_org
for /F "tokens=*" %%t in ('where /R !drive! !subin_org! 2^>nul') do ( set "subin=%%t" )
if defined subin ( goto :done_query_subin_org )
for /F "tokens=2* delims= " %%a in ("!drives!") do (
set "drive2=%%a"
for /F "tokens=*" %%t in ('where /R !drive2! !subin_org! 2^>nul') do ( set "subin=%%t" )
if defined subin ( goto :done_query_subin_org )
)
echo FATAL: !subin_org! not found on PC & goto :failed
:done_query_subin_org
for /F "tokens=*" %%t in ('where /R !drive! !tbbin_org! 2^>nul') do ( set "tbbin=%%t" )
if defined tbbin ( goto :done_query_tbbin_org )
for /F "tokens=2* delims= " %%a in ("!drives!") do (
set "drive2=%%a"
for /F "tokens=*" %%t in ('where /R !drive2! !tbbin_org! 2^>nul') do ( set "subin=%%t" )
if defined subin ( goto :done_query_subin_org )
)
echo FATAL: !tbbin_org! not found on PC & goto :failed
:done_query_tbbin_org
echo OK
echo(
echo Checking if WSA emulator is running ...
for /F "tokens=1 delims= " %%t in ('tasklist /FI "IMAGENAME eq !wsa_svc!" 2^>nul ^| findstr /I /C:"!wsa_svc!"') do (
set "proc=%%t"
if NOT "!proc!"==[] ( goto :done_wsa_check )
)
echo FATAL: WSA is not running & goto :failed
:done_wsa_check
echo OK
tasklist /FI "IMAGENAME eq adb*" | findstr /I /C:"adb" >nul && goto :adb_running || goto :adb_not_running
:adb_running
!adb! disconnect >nul 2>&1
:: Force a fresh start of ADB
taskkill /FI "IMAGENAME eq adb*" /IM >nul 2>&1
:adb_not_running
echo(
echo Connecting Windows to WSA emulator ...
:: Ports are odd-numbered in the range 5555 to 5585,
:: the default port is 5555
for /L %%a in (5555,2,5585) do (
set "tcpport=%%a"
!adb! connect !address!:!tcpport! >nul 2>&1
:: Verify WSA emulator is connected
for /F "tokens=*" %%t in ('!adb! get-state 2^>nul') do (
set "state=%%t"
echo !state! | findstr /C:"device" >nul
if !errorlevel! EQU 0 ( goto :done_wsa_connection )
)
)
echo FATAL: WSA emulator got not connected & goto :failed
:done_wsa_connection
echo OK
::
::
::
set "subin_fn=su"
set "tbbin_fn=toybox"
set "dldir=/sdcard/Download"
set "sucmd=!dldir!/!subin_fn!"
set "tmpdir=/data/local/tmp"
set "tbdir=!tmpdir!/!tbbin_fn!"
::
::
set "sucmd=!dldir!/!subin_fn!"
set "tbbin=!dldir!/!tbbin_fn!"
:: Check if job already was done
echo(
echo Validating Toybox update already done ...
set /A fc=0
!adb! pull !sucmd! %TEMP%\!subin_fn! >nul 2>&1
if !errorlevel! EQU 0 ( set /A fc+=1 )
!adb! pull !tbbin! %TEMP%\!tbbin_fn! >nul 2>&1
if !errorlevel! EQU 0 ( set /A fc+=1 )
if exist "%TEMP%\!subin_fn!" ( del /F /Q "%TEMP%\!subin_fn!" )
if exist "%TEMP%\!tbbin_fn!" ( del /F /Q "%TEMP%\!tbbin_fn!" )
if !fc! EQU 2 ( echo OK & goto :done_files_transferred )
echo OK
echo(
echo Transferring files ...
:: Transfer SU binary to /sdcard/Download
:: because during the updating process we sometimes need elevated rights
!adb! push !subin_org! !dldir!/
if !errorlevel! NEQ 0 (
echo Failed: Transferring SU failed
goto :failed
)
:: Transfer the downloaded toybox binary to /sdcard/Download
!adb! push !tbbin_org! !dldir!/ >nul 2>&1
if !errorlevel! NEQ 0 (
echo Failed: Transferring Toybox failed
goto :failed
)
:done_files_transferred
echo OK
::
echo(
echo Updating Toybox ...
::
:: start Android shell on the WSA emulator
::
!adb! shell
set -e
#
#
DL_DIR=/sdcard/Download;
TB_DIR=/data/local/tmp/toybox;
TB_BIN=/data/local/tmp/toybox/toybox;
SU_BIN="$DL_DIR"/su;
SU_BIN_ORG=su-x86_64;
TB_BIN_ORG=toybox-x86_64;
cat < SCRIPT > "$DL_DIR"/cat.sh & chmod +x "$DL_DIR"/cat.sh & source < "$DL_DIR"/cat.sh; \
'# Save SELinux context of pre-installed Toybox' \
TOYBOX="$(which 'toybox')"; \
EXPR=$(ls -lZ "$TOYBOX"); \
TB_SECURITY_CONTEXT=$(cut -d " " -f 4 "$EXPR"); \
'# give SU binary executable rights' \
'# Get UID GID from pre-installed toybox' \
EXPR="$(ls -ld "$TOYBOX")"; \
TB_UID=$(cut -d " " -f 3 "$EXPR"); \
TB_GID=$(cut -d " " -f 4 "$EXPR"); \
'# Set these UID GID on SU too' \
chown -f "$TB_UID":"$TB_GID" "$SU_BIN"; \
'# Create a directory named toybox under /data/local/tmp' \
if [ ! -d "$TB_DIR" ]; then ( \
$SU_BIN -c 'mkdir -p "$TB_DIR" 2>/dev/null; touch "$TB_DIR" 2>/dev/null'; \
fi; \
'# rename SU and Toybox binaries provided if not already exist' \
if [[ (! -f "$SU_BIN" || ! -f "$TB_BIN") ]]; then { \
mv -T "$DL_DIR/$SU_BIN_ORG" "$SU_BIN" 2>/dev/null; \
mv -T "$DL_DIR/$TB_BIN_ORG" "$TB_BIN" 2>/dev/null; \
} \
fi; \
'# Temporarily disable SElinux what by default in WSA is enabled' \
$SU_BIN 0 setenforce 0; \
'# Copy the transferred toybox binary to /data/local/tmp/toybox what sets its owner to shell:shell' \
cp -Tp "$TB_BIN_ORG" "$TB_DIR/$TB_BIN" >/dev/null; \
'# and give executable permission to it' \
chmod -f +x "$TB_DIR"; \
'# Create symlinks for the various Linux applets provided by toybox binary' \
for i in $($TB_DIR/$TB_BIN --long); do ln -s $TB_DIR/$TB_BIN $i; done: \
'# Set SELinux context on all files created'
$SU_BIN -c 'chcon -R "$TB_SECURITY_CONTEXT toybox" "$TB_DIR"; \
'# Re-enable SELinux because by default in WSA it's enabled' \
$SU_BIN 0 setenforce 1; \
'# Do some housekeeping ...' \
rm -f "$SU_BIN","$TB_BIN" 2>/dev/null; \
SCRIPT
#
## exit the Android shell
exit
::
::
echo OK
:: and restart
echo(
echo Restarting WSA ...
!adb! reboot
echo OK
:failed
timeout /t 10 /nobreak >nul
::
:done
echo(
echo Job done. Exiting ...
pause
pushd
taskkill /FI "IMAGENAME eq adb*" /IM >nul 2>&1
endlocal & DISABLEDELAYEDEXPANSION
exit
Screenshot
Done​Enjoy your Toybox and its applets are ready to be executed.
Validation​
( using ADB code stored in a Windows .BAT-file )
Code:
@echo off & setlocal ENABLEDELAYEDEXPANSION
pushd "%CD%"
::
::
set "adb_exe=adb_r33.0.3.exe" & set "adb="
set "ip4_address=" & set "port=58526"
set "wsa_svc=WsaService.exe"
::
::
title WSA-TOYBOX-UPDATE-VALIDATOR
color f0 & mode con: cols=50 lines=40
echo(
echo ####################################
echo # #
echo # WSA Toybox Update Validator #
echo # #
echo # Verifies Toybox got updated to #
echo # version 0.8.8 what comes with #
echo # SU-function embeddedd #
echo # #
echo # (c) 2022 [email protected] #
echo # License: BSD 2-Clause #
echo # #
echo ####################################
echo(
echo Verifying presence of ADB executable ...
:: check folder we are running this bat from
set "drive=%CD:~0,2%"
for /F "tokens=*" %%t in ('where /R !drive! !adb_exe! 2^>nul') do ( set "adb=%%t" )
if defined adb ( goto :done_query_adb )
echo FATAL: !adb_exe! not found on PC & goto :failed
:done_query_adb
echo OK & echo(
echo Checking if WSA emulator is already up ...
for /F "tokens=1 delims= " %%t in ('tasklist /FI "IMAGENAME eq !wsa_svc!" 2^>nul ^| findstr /I /C:"!wsa_svc!"') do (
set "proc=%%t"
if NOT "!proc!"==[] ( goto :done_wsa_check )
)
echo FATAL: WSA is not running & goto :failed
:done_wsa_check
echo OK & echo(
:: Force a fresh start of ADBis
tasklist /FI "IMAGENAME eq adb*" | findstr /I /C:"adb" >nul 2>nul && goto :adb_is_running || goto :adb_isnot_running
:adb_is_running
:: disconnect all
!adb! disconnect >nul 2>&1
taskkill /FI "IMAGENAME eq adb*" /IM >nul 2>&1
:adb_isnot_running
::
:: get our IP4 address
echo Obtaining local IP4 address ...
rem for /F “tokens=1,2 delims=:" %%a in ('ipconfig ^| findstr /I /C:"ipv4" ^>nul') do (
rem if !errorlevel! EQU 0 ( set "ip4_address=%%b" )
rem )
if defined ip4_address ( goto :done_query_ip4_address )
:: workaround
set "ip4_address=127.0.0.1"
:done_query_ip4_address
echo OK ^[ !ip4_address!^] & echo(
echo Connecting to emulator ...
:: start using default port
!adb! connect !ip4_address!:!port! >nul
for /F "tokens=*" %%t in ('!adb! get-state ^>nul 2^>^&1 ^| findstr /C:"device" ^>nul 2^>nul') do (
set "retval=%%t"
if "!retval!"==[] ( echo Internal error occured & timeout /t 5 /nobreak >nul & goto :oops )
)
echo OK & echo(
echo Checking for SU applet is reachable ...
!adb! shell "PATH=/data/local/tmp/toybox:$PATH; su 2>/dev/null; STATUS=$?;[ $STATUS -eq 0 ] && echo "OK" || echo "Failed"; sleep 10s;"
:oops
taskkill /FI "IMAGENAME eq adb*" /IM >nul 2>&1
:failed
echo(
pause
popd
endlocal DISABLEDELAYEDEXPANSION
exit
Screenshot:
Download​
This package got attached for your convenience
Last Note​Toybox applets are for Terminal and shell scripts - you may use ScriptRunner2 for the latter.
BTW:
Before running a script edit your default shell's configuration file via adding in an DOS coded script saved to a .BAT-file
Code:
adb shell "PATH=/data/local/tmp/toybox:$PATH"
at script's begin what would cause the shell to look into /data/local/tmp/toybox first and execute the binary, if available.
Toybox command help​is here:
Toybox 0.8.9 command help
[reserved]
Can you provide an installer script? It would make it easer for all. Thanks in advance.
Sure. But needs some time. Stay tuned.
jwoegerbauer said:
if !su_found! EQU 1 ( echo SU binary found )
else ( echo SU binary not found )
Click to expand...
Click to collapse
"Else" needs to be on the same line as the "if" in order to be read by interpreter.
Or the ")" + "else" needs to drop to the line below it.
Should be:
if !su_found! EQU 1 ( echo SU binary found ) else ( echo SU binary not found )
OR
if !su_found! EQU 1 ( echo SU binary found
) else ( echo SU binary not found )
EDIT: Also, "@ECHO on" turns on verbose command output, does no good to place at the very end (no harm either)
Thanks for that error notice: implicitely corrected it by a complete revamp of the script.
can you provide a shell script command please

Categories

Resources