Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
GoodDayToDie
Old
#1  
Recognized Developer - OP
Thanks Meter 1365
Posts: 3,563
Join Date: Jan 2011
Location: Seattle
Exclamation [Source][Dll][XAP] The HtcRoot project - Testers needed

The result of probably more than 100 hours of solo hackery: a working COM DLL for allowing any application to elevate itself to SYSTEM (root) permissions.

What you need:
An interop-unlocked HTC phone. Sorry second-gen and Arrive users.
A working HtcUtility driver. It's possible some HTC update at some point crippled this. It works for me; if it doesn't work for you let me know what updates you have.

What it does:
Allows changing the security token of any application to give that app unrestricted permissions. At this point, you can call any user-mode API, perform any operation, with full access.
It also allows you to read or write any value from memory, even kernel memory (this is how it modifes the security token).

What it can be used for:
Darn near anything. If it can be done while the phone is booted, you can do it.

What it can't be used for:
Modifying the ROM - the R and O stand for "read only" and they mean it.
Interop-unlocking a phone - it requires interop-unlock to get root in the first place.

How to use it:
In your app, include the HtcRoot.dll library.
Include the code from DriverAccessTest.cs in the test app (defines the COM API and enables using it).
Call the OpenHtcUtility function (will throw an exception if your device is incompatible).
Call the MakeMeRoot function (can also throw exceptions).
(OPTIONAL) Call the ReturnZeroIfRoot function to make sure your app is elevated (does not throw exceptions, will return an error code if you get one).
Do stuff with SYSTEM permissions (probably using another COM DLL, such as for registry or filesystem access).
Call the RestoreToken function (failure to do this *might* cause a kernel memory leak).
Call the CloseHtcUtility function (OS will probably handle this if program just exits).

What you can do right now:
Try the test app. It should pop up a series of messge boxes. Hopefully none of them say anything like "FAILURE".
Report any bugs or failures you discover.
Build things with this library, and publish them!

Breakdown of the download:
There are two folders in the ZIP, one for the Visual Studio 2010 C#/Silverlight XAP project, and one for the Visual Studio 2008 C++/COM DLL project.
The test XAP is in the HtcUtilityTest\bin\Debug folder.
The native (COM) DLL is also available in that folder, or under its own project.
If you want to mess with this, I'm going to assume you are already familiar with hybrid native/managed development for WP7. If not, Heathcliff74 has posted an excellent tutorial on this forum.

Special thanks to:
Heathcliff74 for the hybrid app tutorial and interop unlock info.
Paul_Hammons for the links and info about HtcUtility, the driver that makes this possible. Thread: http://forum.xda-developers.com/show....php?t=1434793
Attached Files
File Type: zip HtcRootTest1.zip - [Click for QR Code] (622.1 KB, 1243 views)
The Following 15 Users Say Thank You to GoodDayToDie For This Useful Post: [ Click to Expand ]
 
GoodDayToDie
Old
(Last edited by GoodDayToDie; 22nd January 2012 at 02:18 AM.)
#2  
Recognized Developer - OP
Thanks Meter 1365
Posts: 3,563
Join Date: Jan 2011
Location: Seattle
Supported devices / firmware versions / ROMs

All HTC devices (if interop-unlocked and with the right firmware numbers) should be compatible.
Some custom ROMs work, some do not. This will depend on the version of the firmware that the ROM's HtcUtility driver is taken from.
I believe I compiled the test app as Mango-only, but the native library doesn't care at all.

Compatible:
Stock ROMs with compatible firmware for HD7, Trophy, Mozart
HD2 (BttF [XBmod-Yuki] v2 SP1)

Not compatible:
Firmware version 2250.21.51004.401 or newer
Verizon Trophy firmware version 2305.13.20104.605 or newer
DFT ROM with build 8107, Firmware 5.10.401
Arrive (except on pre-Mango), Titan, Radar, Titan 2 (no interop-unlock)

Others are untested or results are incomplete.


Goals and future work:
Support more devices:
* Try and add support for newer firmware.
* Help ROM cookers ensure the library is supported.
* Look for similar openings in other OEM libraries.

Future-proofing:
* Allow installation of a mod to support this capability after known updates.
* Resilience against possible future updates.
* Allow users with incompatible devices to downgrade (possibly to NoDo), install the mod, and be able to use the phone after upgrading.

Improve the library:
* Fix some memory leaks.
* Clean up the code - remove dead code and improve comments.
* Allow reading/writing more than 4 bytes at a time from managed code.
* Add APIs to elevate other processes (by name or ID) to SYSTEM.

Develop homebrew around the library:
* Support accessing common APIs (filesystem, etc.).
* Resurrect the Advanced Explorer app, perhaps (registry and filesystem).
* Support native app launching on stock ROMs.
The Following User Says Thank You to GoodDayToDie For This Useful Post: [ Click to Expand ]
 
GoodDayToDie
Old
#3  
Recognized Developer - OP
Thanks Meter 1365
Posts: 3,563
Join Date: Jan 2011
Location: Seattle
Default Also reserved

Reserved for OP #2
The Following User Says Thank You to GoodDayToDie For This Useful Post: [ Click to Expand ]
 
bleh815
Old
(Last edited by bleh815; 19th January 2012 at 11:20 AM.) Reason: Added explicit error message
#4  
Member
Thanks Meter 16
Posts: 71
Join Date: May 2010
It does not work on HTC 7 Mozart (HTC Europe):

Quote:
Error to Write the value 1337 to test address - System.Runtime.InteropServices.COMException (0x8007001F): A device attached to the system is not functioning
OS: 7.10.7740.16
Firmware: 2250.21.51101.401
Radio: 5.71.09.02a_22.51.50.21U
Boot: 5.11.2250.1(133487)
The Following User Says Thank You to bleh815 For This Useful Post: [ Click to Expand ]
 
GoodDayToDie
Old
#5  
Recognized Developer - OP
Thanks Meter 1365
Posts: 3,563
Join Date: Jan 2011
Location: Seattle
Please include the full error message or a description of what went wrong.

Failure on fully updated devices is unfortunately possible - my phone is (intentionally) a few updates behind. I'm looking into ways to make it work anyhow (either sending an older CAB update to roll back, or using the root acess to create an unlocker/root-enabler that survives subsequent updates). I'm going to look into how the full-unlock ROMs differ from standard ROMs, and see if I can do the same thing in running software.
The Following User Says Thank You to GoodDayToDie For This Useful Post: [ Click to Expand ]
 
Ttblondey
Old
#6  
Ttblondey's Avatar
Senior Member
Thanks Meter 104
Posts: 1,677
Join Date: Jan 2008
Does it works with custom roms?
 
GoodDayToDie
Old
#7  
Recognized Developer - OP
Thanks Meter 1365
Posts: 3,563
Join Date: Jan 2011
Location: Seattle
If the custom ROM has a working HtcUtility driver, then yes. My goal is to unlock the kind of capabilities normally restricted to custom ROMs on stock firmware, though.

@bleh815: Thanks for the report. That's frustrating; it looks like it is capable of doing read but not write. Write might just be restricted in what addresses is allowed, or it might be disabled entirely (the driver gives the same error code for every problem that I've encountered so far). Time to figure out
A) what update causes the problem (I'm on 2250.21.30102.531, HD7, stock ROM)
B) what restrictions that update introduces
C) how to work around those resrtictions (possibly by downgrading and then using root access to add something that will still work after upgrade).
The Following User Says Thank You to GoodDayToDie For This Useful Post: [ Click to Expand ]
 
bleh815
Old
#8  
Member
Thanks Meter 16
Posts: 71
Join Date: May 2010
Quote:
Originally Posted by GoodDayToDie View Post
A) what update causes the problem (I'm on 2250.21.30102.531, HD7, stock ROM)
I've just downgraded a mozart of mine back to stock NoDo (TMOB-DE) to find out which OEM update breaks (actually fixes) it.
 
GoodDayToDie
Old
#9  
Recognized Developer - OP
Thanks Meter 1365
Posts: 3,563
Join Date: Jan 2011
Location: Seattle
Cool, thanks! It's one of the post-Mango HTC updates; a Microsoft update wouldn't have modified an HTC driver, and my phone has all the pre-Mango HTC updates but it still works.
 
KlausWidraw
Old
#10  
KlausWidraw's Avatar
Senior Member
Thanks Meter 78
Posts: 142
Join Date: Jul 2011
Location: Berlin

 
DONATE TO ME
.








..........

Windows Phone App: Zero to Hero

 
Post Reply+
Tags
dll, htc, root, source, xap
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...