[PoC][Work in progress] Trim Area Proof Of Concept

Search This thread

RaXelliX

Senior Member
Apr 12, 2012
138
49
Tallinn
If you have bootloader unlocked, maybe flash recovery using fastboot and leave kernel without recovery integrated?
As said above why not just flash recovery to fotakernel (fastboot flash recovery twrp.img) and leave it out from kernel? To get into TWRP press power+vol untill phone turns on. That will work fine and you won't have to rely on kernel and recovery image is compatible every time there is an update to either one. Just exclude fotakernel in flashtool when updating and recovery won't be overwritten, or you will have to fastboot flash recovery again.

As another example you don't even need to flash recovery, it can also be booted with 'fastboot boot twrp.img' by now getting into recovery and get root should be the least of your problem. :)

Sorry for sidetracking the thread.
Nope no luck. I tried many combinations to get things working including all suggested. I even flashed both the working recovery and working (older kernel by androplus). Then went into recovery and flashed the PoC created stock kernel from there. Upon reboot recovery stopped working. No led during boot, no reaction to pressing vol key but phone itself booted to system.

So whatever makes this revovery work is some special sauce androplus has baked into his kernel and obviously the PoC version is missing this. Just dunno what that something is. Here's the thread: https://xdaforums.com/x-compact/development/advanced-stock-kernel-twrp-xperia-x-t3464685
And notes:
Advanced stock kernel
-For 34.1.A.1.198
-ric, dm-verity disabled
-DRM patch from tobias.waldvogel
-SELinux Permissive
-Load recovery from recovery (FOTAKernel) partition
So i assume PoC is doing almost the same exept DRM fix wich is unnessesary and SELinux Permissive wich would only work for Marshmallow if i read munjeni's answer correctly. I assume PoC also loads recovery from FOTAKernel if i choose to include it?
 

realtuxen

Senior Member
Jun 17, 2014
209
90
No poc does not load from fotakernel if you include it. I think you misunderstand. Fotakernel location and poc boot.img have nothing to do with each other. The point was to leave recovery out from poc and use fotakernel to load recovery instead. You do not wait for led to come to enter recovery in fotakernel.

fastboot flash boot pocboot.img
fastboot flash recovery androplustwrp.img

Again leave recovery out from pocboot.img and when you need to enter recovery hold volume down key and power button until recovery appears.

Is this what you did?
 
Last edited:
  • Like
Reactions: munjeni

shoey63

Recognized Contributor
Added support for latest devices e.g. XZS so Z5 will work too
Getting this on Z5 mm
Code:
-------------------------------------------------------
             Xperia Command Line Flasher               
                                                       
                 by Munjeni @ 2014-2017                     
-------------------------------------------------------
Device path: \\?\usb#vid_0fce&pid_adde#5&3879604a&0&5#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
Class Description: Universal Serial Bus controllers
Device Instance Id: USB\VID_0FCE&PID_ADDE\5&3879604A&0&5

Timeout happened!
Edit: Haven't tried on N, don't want N on this device. I have z, z3, z5 and X:silly:
 
Last edited:
  • Like
Reactions: munjeni

RaXelliX

Senior Member
Apr 12, 2012
138
49
Tallinn
No poc does not load from fotakernel if you include it. I think you misunderstand. Fotakernel location and poc boot.img have nothing to do with each other. The point was to leave recovery out from poc and use fotakernel to load recovery instead. You do not wait for led to come to enter recovery in fotakernel.

fastboot flash boot pocboot.img
fastboot flash recovery androplustwrp.img

Again leave recovery out from pocboot.img and when you need to enter recovery hold volume down key and power button until recovery appears.

Is this what you did?
I held down vol down. I did'nt try vol down+power. Aside from that that was one of the ways i flashed yes.
 

realtuxen

Senior Member
Jun 17, 2014
209
90
I held down vol down. I did'nt try vol down+power. Aside from that that was one of the ways i flashed yes.
Well that's it then. You need to turn on the phone by holding power and vol - untill recovery you flashed to fotakernel with 'fastboot flash recovery twrp.img' appears. You do not wait for any led to turn on in any color. That is for recovery in poc boot.img that you should just leave out because of compability.
 
Last edited:
  • Like
Reactions: munjeni

munjeni

Senior Member
Jun 2, 2011
9,720
22,375
Getting this on Z5 mm
Code:
-------------------------------------------------------
             Xperia Command Line Flasher               
                                                       
                 by Munjeni @ 2014-2017                     
-------------------------------------------------------
Device path: \\?\usb#vid_0fce&pid_adde#5&3879604a&0&5#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
Class Description: Universal Serial Bus controllers
Device Instance Id: USB\VID_0FCE&PID_ADDE\5&3879604A&0&5

Timeout happened!
Edit: Haven't tried on N, don't want N on this device. I have z, z3, z5 and X:silly:

Thanks! Can we move to xflasher thread? Did your device loader.sin capable and which configuration you use, loader.sin or noloader? Can you post xflasher.bat which you used?
 

Andrzej_Andrzej

Senior Member
Apr 1, 2017
94
4
constant bootloop

Hi munjeni,
Ja have learnt a bit about android and adb. I have done ta_poc with a few kernels, boot.img(s).
So far no success. New_boot.img creation always went properly. When I flash it with fastboot I always got a bootloop. This is constant bootloop on sony logo. I assume that in order to take proper last_kmsg I need to connect to pc with adb, but when phone is in bootloop the only mode available is fastboot mode. So I tried (I don't know if it is correct) reboot to recovery and take this last_kmsg from recovery. But when I did that I received an error: fastboot boot recovery.img
downloading 'boot.img'...
OKAY [ 0.502s]
booting...
FAILED (remote: oem unlock is false)
finished. total time: 0.515s

I read a guide about bootloop in here: https://xdaforums.com/showthread.php?t=2426426 and it says: " Using ADB BY Samantha
DB can be used to access the phone while booting, be aware that some bootloops make it unable to use ADB since they do not go further then the manufacturer logo. (In new CWM versions it’s possible to use adb)
The only tricky part about using ADB with bootloops is that you have to do it on the right time, this is different from every device, but normally it’s after the manufacturer logo that the partitions get mounted. The easiest way to enter your phone in this part is using a batch script that monitors the state of your device and connects directly when possible.
I use this script for example, called ondemand.bat (requires adb.exe and the 2 dlls)"

But this script is helpful when CWM is installed, but I have TWRP.

So I do not give up trying and learning but if you could advise me what to do and how to take that last_kmsg in spite of these obstacles described above.

regards,
 

levone1

Senior Member
Dec 28, 2014
3,827
1,478
Hi munjeni,
Ja have learnt a bit about android and adb. I have done ta_poc with a few kernels, boot.img(s).
So far no success. New_boot.img creation always went properly. When I flash it with fastboot I always got a bootloop. This is constant bootloop on sony logo. I assume that in order to take proper last_kmsg I need to connect to pc with adb, but when phone is in bootloop the only mode available is fastboot mode. So I tried (I don't know if it is correct) reboot to recovery and take this last_kmsg from recovery. But when I did that I received an error: fastboot boot recovery.img
downloading 'boot.img'...
OKAY [ 0.502s]
booting...
FAILED (remote: oem unlock is false)
finished. total time: 0.515s

I read a guide about bootloop in here: https://xdaforums.com/showthread.php?t=2426426 and it says: " Using ADB BY Samantha
DB can be used to access the phone while booting, be aware that some bootloops make it unable to use ADB since they do not go further then the manufacturer logo. (In new CWM versions it’s possible to use adb)
The only tricky part about using ADB with bootloops is that you have to do it on the right time, this is different from every device, but normally it’s after the manufacturer logo that the partitions get mounted. The easiest way to enter your phone in this part is using a batch script that monitors the state of your device and connects directly when possible.
I use this script for example, called ondemand.bat (requires adb.exe and the 2 dlls)"

But this script is helpful when CWM is installed, but I have TWRP.

So I do not give up trying and learning but if you could advise me what to do and how to take that last_kmsg in spite of these obstacles described above.

regards,

Unlock bootloader
 

oSandmaNo

Senior Member
Mar 16, 2011
1,369
504
31
Bangalore
Samsung Galaxy S23 Ultra
Hello, how does this work exactly? I created new boot image with my TA backup. Flashed it after flashing Stock 291 Mm on my z3. Camera is still showing lot of noise. But x reality and clear audio is present.

I have attached screenshot of the security test menu. Do I have to lock the bootloader?
 

Attachments

  • Screenshot_20170513-210305.png
    Screenshot_20170513-210305.png
    96.5 KB · Views: 150

x_one

Senior Member
Feb 21, 2011
316
147
Wroclaw
Hello, how does this work exactly? I created new boot image with my TA backup. Flashed it after flashing Stock 291 Mm on my z3. Camera is still showing lot of noise. But x reality and clear audio is present.

I have attached screenshot of the security test menu. Do I have to lock the bootloader?
Flash kernel without tapoc and you will see the difference.
With tapoc you have drm key as with locked broader.
 
  • Like
Reactions: munjeni

fluffi444

Senior Member
Nov 19, 2012
1,600
932
Amazon Fire TV
Samsung Galaxy S9+
Hello, how does this work exactly? I created new boot image with my TA backup. Flashed it after flashing Stock 291 Mm on my z3. Camera is still showing lot of noise. But x reality and clear audio is present.

I have attached screenshot of the security test menu. Do I have to lock the bootloader?


Delete
/data/credmgr
/data/DRM
/data/mediadrm
And reboot

EDIT
And don't be afraid to do so.
Those data will be re-created after reboot but now with new DRM data from your original TA.img.

Try this.

Otherwise your TA.img is not ok or already not original anymore.
 

x_one

Senior Member
Feb 21, 2011
316
147
Wroclaw
Yes, I was on unlocked bootloader, but camera is same after tapoc. That's what I'm asking. Is there anything left for me to do?
I see coupe errors on your screenshot. I think you need clear drm cert db and reboot. You should have all keys ok.
Delete
/data/credmgr
/data/DRM
/data/mediadrm
And reboot

EDIT
And don't be afraid to do so.
Those data will be re-created after reboot but now with new DRM data from your original TA.img.
 

oSandmaNo

Senior Member
Mar 16, 2011
1,369
504
31
Bangalore
Samsung Galaxy S23 Ultra
Thanks both of you. Unfortunately I'm already in bed now . Have two exams tomorrow :(
I will give this a try tomorrow


Cheers


EDIT: woke up early to try this out. Seems as though it's working as ISO goes up to 12800 now. But the security test still shows as unknown error like in my previous screenshot. :/

EDIT2: ISO does reach 12800 but noise reduction is terrible. It doesn't exist even. I think my TA backup is screwed :(
 
Last edited:

munjeni

Senior Member
Jun 2, 2011
9,720
22,375
Thanks both of you. Unfortunately I'm already in bed now . Have two exams tomorrow :(
I will give this a try tomorrow


Cheers


EDIT: woke up early to try this out. Seems as though it's working as ISO goes up to 12800 now. But the security test still shows as unknown error like in my previous screenshot. :/

EDIT2: ISO does reach 12800 but noise reduction is terrible. It doesn't exist even. I think my TA backup is screwed :(

Your picture confirms that poc sucesfully mounted ta but your ta is definitelly from unlocked bootloader, you can also see that in poc log.
 
  • Like
Reactions: oSandmaNo

Top Liked Posts

  • There are no posts matching your filters.
  • 182
    Disclaimer:

    PoC was made for testing and educational purposes, ME is not responsible for what you do on/with your device using PoC, you must agree that you using PoC on your own risk, I am not responsible if you brick your device, you lost your personal data or anything else!

    Hello!
    First of all this tool fully replaces DRM fix! So do not use our tool with DRM fix!!! I'm going to explain what is this, how it working. Everybody know what drm fix doing and everybody know whats happening when bootloader is unlocked. Ok. This PoC is designed for unlocked devices and makes things identic to having bootloader never unlocked! Which mean this is for peoples who have backup of the trim area BEFORE unlocking bootloader! This PoC mounts your trim area backup (TA.img) to the kernel loop5 device which makes your trim area like real trim area partition (in our case it mounts your backup TA.img and uses it instead of unlocked trim area partition) so everything after android boot up is like having locked bootloader which mean all drm keys, widevine keys and etc is fully functional! And most better thing, we can use PoC with AOSP, CM or whatever for having trim area fully functional!!!
    Do in mind this is for stock roms only! Only nougat and marchmallow by now, some of before marchmalow too.

    Supported kernel images:

    - SIN (kernel.sin)
    - ELF (kernel.elf)
    - IMG (boot.img)
    So you no need to extract elf from kernel since our tool extract any sony format, sin,img,elf autodetection.

    Credits:

    - I must give big creadits to @steom since he tested things very deeply on his xperia x compact, he tested things more than 7 days, he tested it very frequently and I must say... big respect to him! Thanks man!
    - Also respect to @tobias.waldvogel ! His mkinitfs source code (idea about #perm appended to file names) helped me a lot making our tool for windows. His scripts helped me a lot figuring out all things! Thanks man! Original forum thread for tobias.waldvogel great work -> https://xdaforums.com/xperia-z5/development/root-automatic-repack-stock-kernel-dm-t3301605
    - Uhh sorry, forgot to give credit to @osm0sis for great extended version of the boot image tools https://github.com/osm0sis/mkbootimg
    - @serajr mate sorry, forgot your great scripts!
    - @the_laser for figuring out that poc is working by directly using TA.img, no need to mount to loop, thanks man!
    - @mbc07 for this post https://xdaforums.com/showpost.php?p=73232574&postcount=1547
    40
    How to extend our tool:

    I have reserved some spaces for everybody who need to extend our tool (tool looks for user script.sh or script.bat), so if tool found user script tool will execute that scipt which mean everybody can make own scipt to extend ramdisk patching mechanism (e.g. to add su... etc). If tool didn't find user script, tool pause so you have enough time to modify everything you need manualy and continue tool by pressing any key on your keyboard. Tool didn't delete output folder so you can use for example something from unmodified boot.img-ramdisk.gz if you need. Also sepolicy binary file have a backup (backupsepolicy) so you can use it too if you need.

    How to fix byself denials from dmesg:

    This explains how: https://xdaforums.com/showpost.php?p=70955889&postcount=47
    And finaly this is a tool: https://xdaforums.com/showpost.php?p=70973513&postcount=120
    27
    Everybody and every device is involved! You need at least good knownledge in getting logcat and dmesg if you want to help here! You can suggest, speak whatewer you want in this thread since this thread is for everybody! Need your words about tool and suggestions! Please if you want to post logcat or dmesg please use http://www.pastebin.com for it! If you need tool working for your device please get involved here!
    19
    New version is out, hope this -> https://xdaforums.com/showpost.php?p=73232574&postcount=1547 isue solved. I am back and just to tell you about reason for post removal... done that because all executables was UPX packed by me but every UPX version curently which I found on internet is reported as a malware on virustotal! I have no idea why virustotal reports upx as a malware but if you not believe me just download any version of the upx, submit it to the virustotal you will notice the same malware, I realy don't know if that malware is false or true but better idea is omiting upx packer, curently I going to recompile all my tools and not use upx anymore. Enjoy!
    19
    scripts - v2

    First of all thanks @munjeni again for the PoA (Art) :highfive:

    I've made some scripts to disable dm-verity, Sony RIC and force-encrypt. I put the scripts as separated files into \scripts folder (maybe this will be usefull for new scripts).
    Download attached zip and unpack it into \ta_poc folder (replacing script.bat file). Also make sure you have the latest version of PoC that comes with busybox.exe.
    Not tested on linux. Windows only (see log blue lines):

    Code:
    E:\Android\ta_poc>nougat_ta_poc n_39.2.A.0.417_kernel.elf TA.img ramdisk
    ------------------------------------------------------------------------
               Trim Area PoC kernel image patcher by Munjeni @ 2017
    ------------------------------------------------------------------------
    
    hash:0x4A2463D0 calc_hash:0x4A2463D0
    hash:0x1847E017 calc_hash:0x1847E017
    hash:0x7E6F8C67 calc_hash:0x7E6F8C67
    hash:0x8BFE56C7 calc_hash:0x8BFE56C7
    device: F8131
    serial number: CB512AD0TJ
    drm key: 0001046B 0010 B8 1F 52 03 D0 39 6C 60 85 C0 A9 9D FE 4F D1 B8
    Trim area dump is a valid.
    Locked bootloader.
    Deleting old folder ramdisk if exist...
    if exist ramdisk (rd ramdisk /s/q)
    returned: 0.
    New directory ramdisk created.
    Using folder "out"
    opening n_39.2.A.0.417_kernel.elf
    Extracting file n_39.2.A.0.417_kernel.elf
    ELF magic found
    Entry point          : 0x80080000
    Class                : 64-bit objects
    Program Header start : 0x40
    Program Header size  : 0x38
    Program Header count : 3
       PH[0], type=1, offset=0x000000E8, virtual=0x80080000, phy=0x80080000, size=0x01BC9C00
       PH[1], type=1, offset=0x01BC9CE8, virtual=0x82200000, phy=0x82200000, size=0x0059FDA8
       PH[2], type=1, offset=0x02169A90, virtual=0x82000000, phy=0x82000000, size=0x001AFB54
    0. Dumping out/boot.img-zImage
    1. Dumping out/boot.img-ramdisk.gz
    2. Dumping out/boot.img-dt
       Seeking to cmdline address = 0x023195EC
    3. Dumping cmdline to out/boot.img-cmdline
    Done.
    No file exist out/n_39.2.A.0.417_kernel.elf.elf .
    Gunziping...
    setting up infflate...
    infflating...
    infflate returned: 0
    gzpipe: ok.
    unziped: ok.
    Extracting ramdisk.cpio...
    Searching for file_contexts...
    ramdisk/file_contexts.bin@0644 file is binary.
    Converting ramdisk/file_contexts.bin@0644 to plaintext...
    Converted.
    Patching file "ramdisk/init.sony-platform.rc@0750"
    Patching file "ramdisk/ueventd.rc@0644"
    Patching file "ramdisk/init.rc@0750"
    Patching file "ramdisk/file_contexts@0644"
    Converting plaintext file_contexts to binary...
    ---- Now you have some chance to modify plaintext file_contexts
    ---- before it is converted to the binary.
    Pressione qualquer tecla para continuar. . .
    Converted.
    Create ta scipt.
    Create busybox.
    TA.img (TA.img) installed.
    Making sepolicy backup: ramdisk/backupsepolicy@0644
    Patching sepolicy...
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18233 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18233 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18234 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18235 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18236 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18236 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18237 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18238 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18238 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18239 rules, 0 cond rules
    Success
    libsepol.policydb_index_others: security:  1 users, 2 roles, 1387 types, 0 bools
    libsepol.policydb_index_others: security: 1 sens, 1024 cats
    libsepol.policydb_index_others: security:  63 classes, 18240 rules, 0 cond rules
    Success
    [COLOR="Blue"]Runing user script...
    
    dm-verity:
    - dm-verity is enabled. Disable? (Say yes if you modify /system) [Y/n] Y
      Disabling dm-verity...
    
    Sony RIC:
    - Sony RIC is enabled. Disable? (Say yes if you mount /system) [Y/n] Y
      Disabling Sony RIC...
      Patching sepolicy...
      Success
    
    force-encrypt:
    - force-encrypt is enabled. Disable? (Say yes if you wipe and decrypt /data) [Y/n] Y
      Disabling force-encrypt...
    
    Pressione qualquer tecla para continuar. . .[/COLOR]
    script.bat ramdisk nougat_ta_poc
    returned: 0.
    Repacking ramdisk...
    ramdisk.cpio done.
    Making ramdisk.gz
    defflating...
    defflate returned: 0
    setting up infflate...
    infflating...
    infflate returned: 0
    gzpipe: ok.
    gzip: ok.
    ramdisk.gz done.
    Found kernel dt.
    No QCDT magic string.
    Packing new_boot.img
    cmdline="androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff coherent_pool=2M"
    base="0x00000000"
    pagesize="4096"
    ramdiskoff="0x82200000"
    defflating...
    defflate returned: 0
    setting up infflate...
    infflating...
    infflate returned: 0
    gzpipe: ok.
    gzip: ok.
    zImage-dtb , dt appended.
    making new_boot.img
    new_boot.img created.
    Done.
    
    Pressione qualquer tecla para continuar. . .
    
    E:\Android\ta_poc>

    Changelog:
    v1 - Initial release
    v2 - Updated scripts (script.bat and *.sh) with PoC's parameters and errors handling ( thanks @munjeni )