Hero and Contact Types - please help - Hero, G2 Touch Android Development

Hi!
I'm developing an Android app that works with contacts in some way.
I personally own a G1 Dream.
Hero users are requesting support for Contact Types, but I have no clue what those Types are about - my Dream doesn't seem to have those.
I've searched through the Android API and couldn't find any Contact Types, just Contact Groups!
Could someone here please shed a light on what Hero Contact Types are, are they part of Android API or something HTC proprietary? If it's something proprietary - where do I find the API to work with them?
Thanks

PLEASE,
Could someone with a rooted HTC Hero PLEASE run this under root and post the result here?
# sqlite3 /data/data/com.android.providers.contacts/databases/contacts.db "select * from groups"

OK
With a little help from my friends I found out that Hero Contact Types are no more than another representation of Contact Groups.
On a plain Hero there are four Groups: exchange, pc, starred in android, system group.

Apparently the groups that I listed do not correlate with contact types on Hero.
I wonder if anyone here possesses a rooted Hero?

Code:
c:\Android\tools>adb shell
# su
su
# sqlite3 /data/data/com.android.providers.contacts/databases/contacts.db
sqlite3 /data/data/com.android.providers.contacts/databases/contacts.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite>
Thats all i got

burgess_boy said:
Thats all i got
Click to expand...
Click to collapse
You've forgotten the "select * from groups" part

yes sorry I know, only just started looking at sqlite: here is the post:
Code:
1||1||||0|1|Exchange||0|Exchange|
2||2||||0|1|PC||0|PC|
3|*******@googlemail.com|6||||0|1|System Group: My Contacts|System Group: My Contacts|0|Contacts|
4|*******@googlemail.com|3f4d84c489473658|1255041281243000|1255041281243000||0|1|Starred in Android|Starred in Android|0||
5|*******@googlemail.com|6f12be4e8fbc53f2|1252749793434000|1252749793434000||0|1|Starred in Android|Starred in Android|0||
6|*******@googlemail.com|ec24fd30a949a10|1254919459679000|1254919459679000||0|1|Starred in Android|Starred in Android|0||

Thanks burgess,
Hero has the same groups functionality as Dream.
My friend with Hero sent me its People table schema:
Code:
CREATE TABLE people (_id INTEGER PRIMARY KEY AUTOINCREMENT,_sync_account TEXT,_s
ync_id TEXT,_sync_time TEXT,_sync_version TEXT,_sync_local_id INTEGER,_sync_dirt
y INTEGER NOT NULL DEFAULT 0,_sync_mark INTEGER,name TEXT COLLATE LOCALIZED,firs
tName TEXT, lastName TEXT, numIndicator TEXT, picasaUrl TEXT, notes TEXT COLLATE
LOCALIZED,times_contacted INTEGER NOT NULL DEFAULT 0,last_time_contacted INTEGE
R,starred INTEGER NOT NULL DEFAULT 0,primary_phone INTEGER REFERENCES phones(_id
),primary_organization INTEGER REFERENCES organizations(_id),primary_email INTEG
ER REFERENCES contact_methods(_id),photo_version TEXT,custom_ringtone TEXT,send_
to_voicemail INTEGER,phonetic_name TEXT COLLATE LOCALIZED, extra_group INTEGER D
EFAULT 0,default_action TEXT, photo TEXT, duplicate_id INTEGER NOT NULL DEFAULT
0, cn_name_pattern TEXT, tw_name_pattern TEXT, last_update_time TEXT);
It differs from what I have on my Dream. There is no extra_group field in People table on Dream. That's probably the 'type', will investigate more

Hey bornmw, am I a bit late?
The extra_group field changes on the Hero if you create a new contact within the People > Add Contact screen of three types: google, phone, sim. 0 google, 2 for phone, dunno about sim.

The problem is that there is no way you can change this column through the Android API http://developer.android.com/reference/android/provider/Contacts.People.html
So it's not possible to create an app that would get access to that field....... or I'm missing smth

why dun you get a copy of the contacts.db and work from there?

Leechoonhwee said:
why dun you get a copy of the contacts.db and work from there?
Click to expand...
Click to collapse
Not sure I understand what you're suggesting.
There is no way I can get contacts.db from within Android application.

Related

Another volunteer project: IIWPO (theft protection)

I need (or in fact, we all need...) someone that can read and write to the registry and send SMS messages in C++. (A code example for sending SMS is here)
The objective here is to create a program which we can include in the ROMkitchen and which will allow for theft-protection of the device. Basically when you select this option, you enter the GSM number of a friend and your name at the time you create the ROM. The device regularly checks whether your name still appears in the Owner Information. If not, it sends an SMS to your friend, including the new owner info, and then it is silent until the Owner Information changes again.
More formally:
Code:
Loop forever
SLEEP 1 hour
IF reg-key '\HKEY_CURRENT_USER\ControlPanel\Owner'
value 'Owner' != reg-key '\HKEY_CURRENT_USER\
Software\XDA-developers\IIWPO' value 'LastOwner'
THEN
COPY 'Owner' to 'LastOwner' (See above)
IF value 'Owner' doesn't contain the string
held in '\HKEY_CURRENT_USER\Software\
XDA-developers\IIWPO' value 'Name' THEN
Send data from Owner field above
via SMS to number held in '[...]IIWPO'
value 'Number' (REG_SZ)
Only slightly complicating factor is that the 'Owner' field is a binary field holding unicode, and that I'd like the 'Name' field in our own entry to be REG_SZ because ROMkitchen does that without hassle. But otherwise this is all pretty straightforward.
Because our IIWPO (which, by the way, stands for 'Interesting Interaction With Previous Owner') program is meant to be in 'Startup', it would be nice if memory footprint was as small as possible. Since it's going to sleep most of the time, performance should be unaffected no matter what.
The sleep is at the beginning so that you have one hour after a cold boot to set your name before it starts sending the SMS.
Ofcourse everyone that has read this could change the registry. We're assuming for a moment that it's much more likely that your phone will be stolen by someone that didn't read this. A little Security By Obscurity never hurt anyone.
I just wonder
very interesting concept, very...
I can code this feature easy, but I just wonder: what to say, if your stoles device will stay hundreds kilometers away from you a few days later? ask the new owner to mail it to you?
hmmm? maybe it is worth?
improve the concept
I have an idea to improve the above concept:
1. we can save the original owner and "sms to send" number in the random generated register key, encrypted binary - it will be hard to find and delete for most of users
2. we provide a shortcut to the application allows the oroginal user to run it and type the name and the above number and save
3. after the above point 2 happen once, the shortcut and even the application are deleting completely, so nobody can do that again
the quextion is:
the execute part of the application: to check the current name and eventually send the sms, have to be placed in the Startup folder to run after the reset. How to hide this shortcut?
Re: improve the concept
JGUI said:
1. we can save the original owner and "sms to send" number in the random generated register key, encrypted binary - it will be hard to find and delete for most of users
Click to expand...
Click to collapse
Nice idea: but any thief that knows about this danger will just cook themselves a new ROM and install it.
2. we provide a shortcut to the application allows the original user to run it and type the name and the above number and save
Click to expand...
Click to collapse
Why not just do it in the ROMkitchen?
And besides, it already done: a kind gentleman by the name of Charles Warner has written the app, and it'll be in the ROMkitchen later today, hopefully...

CycloneApps[By Request][ContactRetriever 3.0][CMessageSuite V1.0][CBRunner V1.0]

Hello Everyone,
I am a avid, aspiring developer, and as such I felt it would be mutually beneficial to start this thread. The Point of this this is for you [the users] to post up ideas for programs, and some sketch-ups of designs, and in return, I will try to make, and maintain, these applications.
In doing this, I will get the experience I need, and you [the users] will get the results that you [hopefully] want.
Below is [or will be soon enough] a list of programs that are developed or in the process of consideration.
Project List:
AutoSend - Scheduled SMS Sender [V3.5][NO LONGER BEING UPDATED]
CMail - A Replacement tmail for Devs and Advanced Users[V1.0]
Export-Studio - A FREE alternative app to export Contacts and SMS[V4.0 + Command Line Version]
Appointmentor - A command-line based app for creating appointments quickly and easily [V1.5]
ContactRetriever - A command-line based app for getting info on a specific contact! [V3.5]
CDL - A Command-Line based File downloader (designed with MortScripter's in mind) [Release Delayed]
CSort - A Command-Line based List Sorter (designed with MortScripters in mind) [V2.0]
ImgResize - A Command-Line based Image Resizer (Resize + Crop) [V2.0]
All2Reg - Based off of Msg2Reg, this will export MANY things to registry [Coming Soon]
TornadoClean - A utility for deleting old files/SMS/MMS/EMAILS with certain 'traits' specified by the user [Conceptual - PsuedoCode Stage]
CBRunner - [Idea courtesy of HowdyKeith] Runs EXE's (and possibly other file types like MP3, etc.) In the background so MortScripters can do their stuff! [V1.0]
CMessageSuite - A Re-Make of AutoSend with more features! [V1.0]
*As you can see, the list is sort of pathetic now, but with your help, I can bulk it up*
UPDATE:
A command-line version of Export Studio is now posted for all you Scripters!
Appointmentor[V1.5]
This program allows scripters and devs to quickly and easily make appointments. This program features the ability to set every parameter that a user could set thru the calendar itself (I believe...)
This Program Includes:
A documentation explaining all parameters
A small cmd-line app for creating appointments.
To Install:
Just download and extract the ZIP file to anywhere on your phone, and you are done!
To use:
Follow the parameters in the documentation, but as for running it, run it like any other command-line based program.
Tips:
Not all parameters must be set, as I have preset defaults (shown in documentation).
EDIT: DOWNLOADS REUPLOADED
V1.5 Update:
In this update, you can DELETE scheduled appointments. This feature has not been thoroughly tested, so errors may occur. Will test in near future. (If users could post back successes/failures it would help).
Please test it out!
*While I coded this on my own, credit must be given to google and this forum for its constant help in everything I do. Please don't forget that while these apps are free, donations are appreciated!*
Update:
I fixed up a major issue in Appointmentor and re-uploaded it. Now it should work. All documentation is provided in the ZIP file. Please test and post results and ideas!!!!
Image Resizer [V2.0](Command-Line Utility)
This application is a command-line based app for resizing images.
All instructions are provided in the Documentation.txt
Enjoy!
V1.5 Update:
In this version of the program, Cropping is now available. Look at the docs to find out how to use it. I also fixed an issue with Naming, so now the outputted file has the ACTUAL size of the image (not what is inputted in some cases). Also, you can use PERCENTAGE to resize/crop. Lastly, you can now simply convert your file from one extension to another.
V2.0 Update:
In this version, BatchCropping and BatchResizing is now available. Look at the docs to find out how to use it. This comes in handy when dealing with many pics in a folder. Please report back any bugs that are found
DISCLAIMER::::::
I did not code this program fully by myself. For the original Image Resizing project visit:
http://blogs.msdn.com/acoat/archive/2007/05/09/resize-images-a-thumbnail-maker.aspx
All Credit for the actual Image Resizing functions of this app go to the original author:
Username on msdn blogs is : acoat
Name (?) : Andrew Coates
ContactRetriever V3.5
This application allows a scripter or dev to export a specific contact's data for easy use!
This program includes:
A simple, easy to follow documentation and functionality
A light-weight solution for getting contact info.
A SUPER EASY GUI (contacts menu) when not wanting to start it in CommandLine mode.
The ability to export specific contacts (or many) as VCF files
To Install/Use
Just unzip the ZIP file and read the documentation!
(To use the GUI, just run the app WITHOUT parameters, to use the CMD run it WITH paramteres)
Bugs:
None so far!
V3.5 Update:
In this version, you can find contacts by partial (or full) phone numbers! Read the docs for more info.
Please remember that while I did the coding on my own, help came from XDA and Google and the millions of resources on the net. Please remember that while this application is free, Donations are greatly appreciated!
Enjoy!
UPDATE:::
Export-Studio 2.5 Is now out.
2.5 Has the ability to set the NUMBER of Contacts/SMS to be exported (with a safeguard that if the number is too high or is 0, it will set it to the maximum).
Expect an upgrade to Export-Studio 3.0 Soon (ability to export to VCF, and maybe MMS implementations).
Expect a new CMail to come out (ability to send E-Mail's via commandline and maybe MMS implementations).
Contact related app...
I've been searching for an app that allows to browse the contact list (with a scrollable list of names for a GUI... similar to Outlook or any other contact manager) and retrieves a selected contact full name as a reg key (my point would be using it in conjunction with MortScript and go2contact to add a dynamic contact launcher feature to my HS++ skin... guess it would be usefull for other skinning engines too).
Would you be willing to do such an app?
frmariam said:
I've been searching for an app that allows to browse the contact list (with a scrollable list of names for a GUI... similar to Outlook or any other contact manager) and retrieves a selected contact full name as a reg key (my point would be using it in conjunction with MortScript and go2contact to add a dynamic contact launcher feature to my HS++ skin... guess it would be usefull for other skinning engines too).
Would you be willing to do such an app?
Click to expand...
Click to collapse
Sure would be! I will just implement a GUI into ContactRetriever! Expect a release in 10 minutes TOPS.
UPDATE::
Export-Studio 3.0 Now released - Can export Contacts as vCard (VCF) format!
UPDATE::
ContactRetriever 1.5 NOW released - Has a really simple GUI (same functions)!!
UPDATE::
ContactRetriever 2.0 NOW released - Ability to export as VCF, control # of contacts, and WILDCARD'ing
Thank you so much! Just tried it and this was what I was looking for.
There seems to be an issue though... I can only get stuff from the first contact in the list... Also the name will be in all caps and have an underscore before it... I can't get any other contatcs info in the reg...
how about Cdown.exe -url "http:.../file.zip" -outp ".../file-Downd.zip"
as smartphones cant do that w/mort atm...
howdykeith said:
how about Cdown.exe -url "http:.../file.zip" -outp ".../file-Downd.zip"
as smartphones cant do that w/mort atm...
Click to expand...
Click to collapse
Added to project list....WOrking on it
Thank you so much for fixing ContactRetriever
While the paint is still fresh... Any chance on creating a value for the selected contact named "LastSelectedContact" (or something else) where the contact name is the data (without the preceding underscore and case sensitive like Outlook). Would really make it a lot easier to MortScript (I really have no idea how to get just the desired part of the key and remove the underscore).
Hope I'm not abusing of your good will...
Hey, so I can't really make a key that is for "lastcontact" because the command-line users may export a whole bunch of them (as you can see, I implemented the ability to export based on Wildcards)....
As for removing the underscore and such, I put that there as a standard for users so that they know what WAS created by my program, or what was created by something else that may have used the same area (rare, but possible).
Anyways, if you want to format it, do a substring on the Key name using the indexOf the _ as the ending for the first and that + 1 for the start of the second, then bring it all to lowercase then make the first uppercase (through substringing?) I don't know the mort-commands, but I am sure you can figure it out by asking HowdyKeith or posting on the MortScript thread or reading the Manual on Mort's website.
Good Luck
Thanks for the info. I've been reading the txt manual of Mortscript and it's kind of incomplete compared to the pdf... I'll read it tomorrow (must sleep) but until now I didn't find a function that returns the reg key (because it'll be random). I'm sure the substring bit will help.
Just found my contact list got sort of messed up by some app I used (guess it's too late to find out which one...) All the names (first and last) are now stored in the first name box... I didn't notice it before so I didn't get why was there a _ before the name even when I had a last name too.
Ok.
How about CSort.exe -inp "/path/Unsorted.txt" -outp "/path/sorted.txt"
maybe the option to dump the output into a regkey:
Sorted1=Alimoney
Sorted2=Bingo
...
If we r dumping to a reg folder, why not import from a registry folder too?
So i know u got the picture taking exe.
what about calling the Camera get picture class? Like your contact retriever calls the GUI.
I have to think about it to see if that makes sense.
howdykeith said:
So i know u got the picture taking exe.
what about calling the Camera get picture class? Like your contact retriever calls the GUI.
I have to think about it to see if that makes sense.
Click to expand...
Click to collapse
I am using Managed C# code, and the most 'power' that I get in terms of taking photos is just to start up the 'dialog' with certain paramters....so in MortScript, a script can just call it, then send the "ENTER" button to start and "ENTER" to stop (if it is a video) or save (if it is a photo)....
*FYI: The Camera App I am developing is currently in Private Beta, release soon enough*
So as far as contacts posted to the reg from contact retriever.
It probly should always delete the prior searches unless you give it a command -keep
For the advanced hacker: SQL database access and posting.
Do u have a Microsoft Bluetooth stack? There is no toggler for Widcomm Bluetooth. PhoneAlarm controls the bt just fine, so it's not impossible.
Can you turn on and off the flash? Other apps do it, so that's a low priority. But if you could and u added that function to an all in one tool, that would be cool.
Make a contact from a command line.
Can u change the power profiles? Normal/Headset/Auto...
Can u get the accelerometer info? i dont have one. Detect stylus removed from a command line?
I really hope u can get the sorter to the registry, so i am holding my breath til then.
Thanks Dude.

Truetype fonts in evC++

Hi gents.
I want to ask you,how can I use external font loaded from ttf file in my app,developed under Embedded Visual C++?
I need to easily change color and size of the font and using the DrawText() function make an output into current DC.
Can someone make an example for me please?
Thank you.
Here's the bare bones of it ,you'll have to flesh it out to suit. It might not be perfect but it works.
Global Variable
Code:
HFONT g_hfont;
Forward declaration of EnumFontProc()
Code:
int CALLBACK EnumFontsProc(LOGFONT *lplf, TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData);
In WM_PAINT print it out. I'll use Wingdings. The name in the EnumFonts must match the actual name of the font as declared in the TTF file.
Code:
case WM_PAINT:
RECT rt;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
EnumFonts(hdc,TEXT("Wingdings"),(FONTENUMPROC) EnumFontsProc,NULL);
SelectObject(hdc,g_hfont);
DrawText(hdc,TEXT("12345"),5, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
DeleteObject(g_hfont);
EndPaint(hWnd, &ps);
break;
In EnumFontsProc set the font to the first font given. Returning 0, ends the enumeration, non zero, give me the next.
To change the size do it here by changing lplf->lfHeight and lplf->lfWidth
Code:
int CALLBACK EnumFontsProc(LOGFONT *lplf, TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
g_hfont = CreateFontIndirect(lplf);
return 0;
}
To load and release your font add the code below to the message handling sections.
Code:
WM_CREATE:
AddFontResource(TEXT("\\Storage Card\\myfont.TTF"));
WM_DESTROY:
RemoveFontResource(TEXT("\\Storage Card\\myfont.TTF"));
Here's the proof it works, (with Wingdings anyway!)
Thanks man,I will try it ASAP.
Well,is it possible to read the ttf file directly from exe resource also?
I am still learning C++,so some things are a bit unclear for me. Can you please post this source?
This stuff is explained fully at:
http://msdn.microsoft.com/en-us/library/aa911455.aspx
I've just taken a few shortcuts with it.
The zip file contains the main .cpp file of the above project. It does not include the AddFontResource or RemoveFontResource statements.
Create a shell WinMo application and replace the main program .cpp file with it.
AddFontResource can only accept the path to a True Type font TTF file as an argument.
The thing you have got to get your head around are CALLBACK routines, they are used during most enumeration routines, and are widely used in Win32 for all sorts of things. A Win32 app's WndProc it itself a callback routine. In the case of EnumFonts, you pass the address of the callback routine to the enumerating function, which will call your function once for every instance it finds that matches your request. You terminate the sequence by returning 0 or it will carry on until there are no instances left. You have to decide what to do with the results. In my case I take the first Wingding font I'm offered, then quit.
Be aware that there is little, or no error handling in this code. I cobbled it together pretty quickly to prove the point.
I remember reading somewhere that if you drop the .TTF file in the Windows directory, and do a soft reset, then Windows will pick it up as a resident font, so the AddFontResource and RemoveFontResource functions are not required. EnumFonts() should know about it, and present it accordingly.
Well,thank you very much for that,but can you please provide me full project source,including all the files? With working project,I can better understand the font loading principle.
Unfortunately,I am too busy nowadays to discover something,that I don't understand well,so every time save is a big plus for me. Thank you very much again.
Attached,
But, it is a VS 2008 Smart Device project. EVC won't read it.
You will have to create a shell hello world project in EVC and copy the modified code in the panels above from TestFont.CPP.
Hello.
Actually i've got it working,but I still cannot discover,how to resize the font.
Where should I exactly put the lfWidth and lfHeight?
I am now a bit confused of that.
This is my code:
Functions and declarations of HFONT,CALLBACK,WM_CREATE,WM_DESTROY are present as you described.
void ShowNumber(HDC hdc, int Value,int xrect,int yrect,int wrect,int hrect,HBITMAP source)
{
EnumFonts(hdc,TEXT("Sam's Town"),(FONTENUMPROC) EnumFontsProc,NULL);
SelectObject(hdc,g_hfont);
TCHAR szText[MAX_LOADSTRING];
int width,height;
rtText.right=wrect;rtText.bottom=hrect;width=wrect-xrect;height=hrect-yrect;
TransparentImage(hdc,xrect,yrect,width,height,source,xrect,yrect,width,height,RGB(255,0,255));
SetBkMode(hdc,TRANSPARENT);
if(Value<10) wsprintf (szText, TEXT ("0%d"),Value);else wsprintf (szText, TEXT ("%d"),Value);
rtText.left=xrect ;rtText.top=yrect ;SetTextColor(hdc,RGB(0,0,0)); DrawText(hdc,szText,2,&rtText,DT_SINGLELINE | DT_LEFT | DT_TOP);
DeleteObject(g_hfont);
}
int CALLBACK EnumFontsProc(LOGFONT *lplf, TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
g_hfont = CreateFontIndirect(lplf);
return 0;
}
Click to expand...
Click to collapse
This doesn't work:
lplf.lfWidth=0;
g_hfont = CreateFontIndirect(lplf);
Click to expand...
Click to collapse
Actually I want to put one more parameter into ShowNumber() function,which will tell the function the size of the font.
You are nearly there...........
The code to set the font size will have to go in here.......
Code:
int CALLBACK EnumFontsProc(LOGFONT *lplf, TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
lplf->lfHeight=14;
lplf->lfWidth=8;
g_hfont = CreateFontIndirect(lplf);
return 0;
}
Or whatever your values are, I just picked 8 and 14 as examples. If these values are passed as variables to another function above, store them as global variables, and use them here.
As lplf is passed to this function as a pointer to a LOGFONT structure, you have to use the -> operator to access its members. lplf.lfHeight won't work as you mentioned, that is for predeclared or static structures.
These values have to be changed here in the EnumFontsProc() routine before the font is created, as we are passing that pointer to create the font.
Good Luck!!
P.S. While we are here, let's tidy it up a bit.
Replace:
Code:
if(Value<10) wsprintf(szText,TEXT ("0%d"),Value);else wsprintf (szText,TEXT("%d"),Value);
with
Code:
wsprintf(szText, TEXT ("02%d"),Value);
A very big thanks for that.
I am still beginner in C++,so something can look very comic for others.
My beloved programming language is Pascal.
I really didn't think,that -> is an operator,I've just mentioned,you wrote it as something else(something like "to")
You are more than welcome.
Some features in C/C++ are not immediately obvious, but the real battle is fighting your way through the Win32 programming model, trying to get it to do what you want. Sometimes the simplest of things become maddeningly complicated, but the effort to do it properly is usually worth the effort.
Glad you got it working, best wishes, stephj.
Hello a bit later.
First of all,thank your for your explanation and now I am using this method successfuly.
I want to ask you now,if there is a way to get fixed pitch of the font,that is truetype. With standart font I can achieve with this...
lf.lfPitchAndFamily = (tm.tmPitchAndFamily & 0xf0) | TMPF_FIXED_PITCH;
I am using font,that displays numbers in "digital" mode(7-segment display) and I get the number "1" very narrow in comparison with others(actually it is narrow on any kind display,but is displayed on right segments,so "01" has adequate spacing on hard display). Now I get "0l_" instead of "0_l",that's not preferable.
Thanks in advance for reactions.
I don't think there the above method will work as each character has it own width associated with it.
A simpler approach, a bit of a pain, but which should work, is to draw/print the numeric value out one character at a time using DrawText(). Set a RECT structure up to hold the coordinates of the top left and bottom right of the area for each character.
Setting uFormat to DT_RIGHT will force the character to right align in the RECT area, so the '1' should appear correctly. Move the left and right values along a fixed amount for each character. A bit of trial and error will be involved first until you get the values just right.
Good luck, stephj.

CheckBox state presrving/restoring

Hi there,
Does anyone out there how to preserve/restore the transient state of a CheckBox and/or Radio button?
So far, I'm using the following code, working for textbox
Code:
Public Sub PreserveState_TextBox(ByVal TB As TextBox)
Dim buffer As String = String.Empty
If True = PhoneApplicationService.Current.State.ContainsKey(TB.Name) Then
buffer = TryCast(PhoneApplicationService.Current.State(TB.Name), String)
If Not String.IsNullOrEmpty(buffer) Then
TB.Text = buffer
End If
End If
End Sub
Public Sub RestoreState_TextBox(ByVal TB As TextBox)
If True = PhoneApplicationService.Current.State.ContainsKey(TB.Name) Then
PhoneApplicationService.Current.State.Remove(TB.Name)
End If
PhoneApplicationService.Current.State.Add(TB.Name, TB.Text)
End Sub
it possible to modify the above code to work for Checkbox and/or Radiobutton?
If not, any ideas?
So far, I've been trying the sample "Tombstoning" sample code from Microsoft without any luck...
Thanks in advance!
Hi,
I'm not a VB developer, but storing the state of a checkbox is not much different from storing any other primitive type. What you could do is have a bool variable "isCbChecked" and store that bool state in your PhoneApplicationService.State.
Code:
PhoneApplicationService.Current.State.Add("isCbChecked", myCheckbox.IsChecked)
Then, when you're restoring your app, simply do
Code:
myCheckbox.IsChecked = (bool)PhoneApplicationService.Current.State.ContainsKey("isCbChecked");
keyboardP said:
Hi,
I'm not a VB developer, but storing the state of a checkbox is not much different from storing any other primitive type. What you could do is have a bool variable "isCbChecked" and store that bool state in your PhoneApplicationService.State.
Code:
PhoneApplicationService.Current.State.Add("isCbChecked", myCheckbox.IsChecked)
Then, when you're restoring your app, simply do
Code:
myCheckbox.IsChecked = (bool)PhoneApplicationService.Current.State.ContainsKey("isCbChecked");
Click to expand...
Click to collapse
Thanks a lot for your fast reply.
Can I ask for additional help on how to make your statements into generic procedures, at least to take them to something similar to what I posted?
Don't care if it's in C#
Thanks in advance!
GFR_2009 said:
Thanks a lot for your fast reply.
Can I ask for additional help on how to make your statements into generic procedures, at least to take them to something similar to what I posted?
Don't care if it's in C#
Thanks in advance!
Click to expand...
Click to collapse
Off the top of my head, something like this should work (C# code).
Code:
public static T RestoreState<T>(string key)
{
if (PhoneApplicationService.Current.State.ContainsKey(key))
{
return (T)PhoneApplicationService.Current.State[key];
}
return null;
}
'T' is the type that will be used. In C# 'T' is a special character denoting the generic type, not something I just used
So in the code above, the return type is 'T' and when using RestoreState, it will be 'RestoreState<Textbox>("TB.Name");'. The value of 'TB.Name' will be searched within the dictionary and, if it's found, it will cast that object as 'T' (Textbox) and return it, otherwise it will return null.
Hi,
So far, I did the following and while no error is raised, nothing happens...
Code:
Public Function Backup(ByVal token As String, ByVal value As Object) As Boolean
If Nothing Is value Then
Return False
End If
Dim store = PhoneApplicationService.Current.State
If store.ContainsKey(token) Then
store(token) = value
Else
store.Add(token, value)
End If
Return True
End Function
Public Function Restore(Of T)(ByVal token As String) As T
Dim store = PhoneApplicationService.Current.State
If Not store.ContainsKey(token) Then
Return Nothing
End If
Return CType(store(token), T)
End Function
I call them as follows
Code:
Backup(Me.CheckBox_1.Name, Me.CheckBox_1)
Restore(Of CheckBox)(Me.CheckBox_1.Name)
Don't where is the error, maybe you could take a look and help me out.
Any help is much appreciated!
Where are you calling the Backup and Restore functions? Since your doing page specific things, you could do it in the OnNavigatedFrom and OnNavigatedTo methods, respectively.
keyboardP said:
Where are you calling the Backup and Restore functions? Since your doing page specific things, you could do it in the OnNavigatedFrom and OnNavigatedTo methods, respectively.
Click to expand...
Click to collapse
Hi,
I'm calling them in the OnNavigatedTo and OnNavigatedFrom methods, as you pointed out
Unfortunately, nothing happens at all!
Thanks!
Hi,
As far as I can tell, there's nothing wrong with your saving/loading code. When you call
"Restore(Of CheckBox)(Me.CheckBox_1.Name)", is that returning a bool? You need to assign that bool to the checkbox:
Code:
myCheckbox.IsChecked = Restore(Of CheckBox)(Me.CheckBox_1.Name);
Also, all variables are reset when the page loads, so make sure you have set "myCheckbox.IsChecked" anywhere else on the page that could be called when the page loads.
Please, check the converted code of the above functions, to C#
Code:
public bool Backup(string token, object value)
{
if (null == value)
{
return false;
}
var store = PhoneApplicationService.Current.State;
if (store.ContainsKey(token))
{
store(token) = value;
}
else
{
store.Add(token, value);
}
return true;
}
public T Restore<T>(string token)
{
var store = PhoneApplicationService.Current.State;
if (! (store.ContainsKey(token)))
{
return default(T);
}
return (T)(store(token));
}
Do you think they are OK?
How should I call them ?
Clearly, the restore does not returns a boolean...
Honestly, I'm lost now!
Hope this helps to find the culprit.
It seems okay to me. You'll have to do some debugging. Set a breakpoint inside the Backup and Restore methods. Step through each line and make sure it's going to the line you expect it to and that the value being set is the correct one.
I haven't seen the tombstoning sample from MSDN, but can you get that to work? If so, is the generic method causing the problem? Or can you not get it to work at all?
Hi,
Sorry for the delay in getting back, but I was trying different codes and at least I found the cause.
Code:
Me.NavigationService.Navigate(New Uri("/PivotPage1.xaml?Name=" & "John", UriKind.Relative))
[B]Me.NavigationService.GoBack[/B]()
Me.NavigationService.Navigate(New Uri("/PivotPage1.xaml", UriKind.Relative))
Everything works fine, and the Checkbox state is saved/restored (in the Pivot Page) if I GO BACK using the GoBack hardware button or Me.NavigationService.GoBack
But, the state's dictionary entry is lost or ignored if I go back with the Navigate service (lines 1 and 3)...
Problem is that I need to get back with the query string...
The query string contains a value taken in the SelectedItem event of PAGE2's ListBox, and automatically once retrieved must go back.
I didn't know until know, that NavigationService.Navigate creates a new page instance or something like that in the backstack...
Any sugestions are welcomed!
Hi,
There are various methods you can use depending on the app's architecture. For example, you could have a 'shared' class that contains a shared field that holds the SelectedItem value. When the user selects the item, set the shared field's value and then when you go back, you can get the value from the shared field.
keyboardP said:
Hi,
There are various methods you can use depending on the app's architecture. For example, you could have a 'shared' class that contains a shared field that holds the SelectedItem value. When the user selects the item, set the shared field's value and then when you go back, you can get the value from the shared field.
Click to expand...
Click to collapse
So, no other way to cope with the navigation service?
It's a strange behaviour for sure...
Will try your ideas.
Thanks a lot for your reply!
GFR_2009 said:
So, no other way to cope with the navigation service?
It's a strange behaviour for sure...
Will try your ideas.
Thanks a lot for your reply!
Click to expand...
Click to collapse
There are other ways. For example, instead of using the PhoneApplicationService to store the tombstoning information, you could put it in a querystring for page 2. Then, in page 2, you could add the information from the previous page to a querystring AND the information of the selected item to the querystring. Navigate to page 1, with the querystring that contains information on what was there before and what the user selected. Tombstoning is there for when the user presses the hardware search button, home button, a phone call arrives etc.. It's not there for the navigation of the app. That's where querystrings, shared variables, binary serialization etc... come into play.
The concept of the navigation service is similar to a website. For example, when you submit something and then go back, it might still be there in the page state. However, if you submit something and then reload the previous page by typing it in the address bar, it becomes a completely new page as no state is stored.
keyboardP said:
There are other ways. For example, instead of using the PhoneApplicationService to store the tombstoning information, you could put it in a querystring for page 2. Then, in page 2, you could add the information from the previous page to a querystring AND the information of the selected item to the querystring. Navigate to page 1, with the querystring that contains information on what was there before and what the user selected. Tombstoning is there for when the user presses the hardware search button, home button, a phone call arrives etc.. It's not there for the navigation of the app. That's where querystrings, shared variables, binary serialization etc... come into play.
The concept of the navigation service is similar to a website. For example, when you submit something and then go back, it might still be there in the page state. However, if you submit something and then reload the previous page by typing it in the address bar, it becomes a completely new page as no state is stored.
Click to expand...
Click to collapse
Hi,
Will try your suggested approach, and thanks a lot for the last explanation on how the darn thing works.
Thanks again!
GFR_2009 said:
Hi,
Will try your suggested approach, and thanks a lot for the last explanation on how the darn thing works.
Thanks again!
Click to expand...
Click to collapse
You're welcome . It's one of those things that take a bit of time to understand, but starts to make sense. You might be interested in a free WP7 development ebook by Charles Petzold.
keyboardP said:
You're welcome . It's one of those things that take a bit of time to understand, but starts to make sense. You might be interested in a free WP7 development ebook by Charles Petzold.
Click to expand...
Click to collapse
I already have the book, but will need a deeper reading
So far, I've been testing your idea of using global classes and works ok.
Thanks a lot for being so cooperative, it's much appreciated!
GFR_2009 said:
I already have the book, but will need a deeper reading
So far, I've been testing your idea of using global classes and works ok.
Thanks a lot for being so cooperative, it's much appreciated!
Click to expand...
Click to collapse
No worries! If programming was super easy everyone would be doing it
keyboardP said:
No worries! If programming was super easy everyone would be doing it
Click to expand...
Click to collapse
Never said better!

Hacking the policy database

OK, time to give this subject its own thread. You can read about previous efforts here: http://forum.xda-developers.com/showthread.php?t=1113066. In particular, http://forum.xda-developers.com/showthread.php?t=1113066&page=11 is where I started.
Background: the policy database is essentially the Access Control List (ACL) store for WP7. ACLs are typically attached to objects (files/folders, registry keys/values, drivers/services, possibly even APIs). When a process tries to do something, the OS uses the process's security identifier (called a "Token", it identifies the account running the process and therefore the permissions that process has) and looks up the ACL specific to that operation. If the ACL authorizes that account to perform the operation, the kernel permits it. If not, it blocks the operation and indicates an error (most famously on WP7, 1260 or 0x4EC, meaning blocked by policy). For some OSes, like NT, that attachment is in the metadata which describes the object (for example, NTFS stores ACLs for each file and folder). Apparently, WP7 uses a centralized database of ACLs, stored as "policies", instead.
Why I'm doing this: the policy database is the key to fully unlocking the phone. I mean that literally; "full unlock" ROMs achieve that state by basically turning off policy enforcement. I don't necessarily want to do that - at least not phone-wide and constantly - but I want to be able to set my own policies, and possibly modify existing ones.
What can be done with it: well, one example is the subject of the thread I linked above: homebrew native EXEs require first being able to add policies for them. There are some other cool possibilities, like turning off ID_CAP_INTEROPSERVICES enforcement or allowing apps to write to the MaxUnsignedApp registry value directly. That gets around the risk of phones being re-locked and unable to interop-unlock again. Basically, it allows an app to do anything short of modify the ROM.
Purpose of this thread:
* Provide a central location of information about the policy system, policy database, and creation of custom policies.
* Collaborate on the project of understanding and modifying the policy database and policy system overall.
* Share interesting policies we've found in the database, or post custom policies that can be added to enable a cool hack.
* Discuss and share ways to preserve, going forward, our control over the policy system.
There has been concern raised that this work should not be mde public, because Microsoft will look at what we are doing and use that knowledge against us. There is some validity to that argument; if the work is done in secret, and any files posted that use the fruits of that work are heavily obfuscated, it would probably take Microsoft a little longer to block it if they decided to do so. Not terribly *much* longer though, I suspect - they have many tools at their disposal, full source code and documentation, and full understanding of the system in their engineer's minds. Any hack we find, they can reverse engineer or simply block access to whether or not they can read a thread about it here on XDA-Devs.
There's also the risk of malware. Malicious homebrew apps could abuse this knowledge to do serious damage to your phone, to steal info, and possibly even for direct financial effect (send premium SMS, for example). However, I see no real way around that problem; it's an inherent risk of unlocking a device. The simplest and best step to combat it is to not install untrasted apps, and the best way to be sure an app is trusted is to be able to analyze it. (This is one of the reasons I include the source for my apps, and encourage others to do the same.) Besides, it's already possible to do plenty of damage with existing homebrew hacks, yet somehow that problem hasn't materialized.
So, instead of secrecy, I propose openness. The best option we have to offset Microsoft's tools, knowledge, and source code is to collaborate, pooling the knowledge and effort of many hackers. If people want to keep certain things secret, by all means use email or PMs. In general, though, I think the failure to spread knowledge does more harm than good.
OK, that turned into a long enough intro that I'm going to post my first actual findings in a reply.
Policy-related files
There are actually two databases: one is for policies, and one is for accounts. They are located in \Windows\Security\ and are called policydb.vol and accountdb.vol. These files are locked (opened without sharing permitted) while the OS is running. There are two additional files in this folder: PolicyMeta.xml and PolicyCommit.xml. These files can be accessed using provxml, TouchXplorer, WP7 Root Tools, or HtcRoot Webserver.
The PolicyMeta XML file contains macros describing accounts, and metadata about the policies in the database. In particular, it contains a large number of bit masks that indicate different permissions. By itself, this file doesn't tell us much of use, but it will be a big help for understanding binary data in the the database. It's small and not commented, but easy to read.
The PolicyCommit.xml file contains the merged result of combining all the policy files on the phone. I don't know if anything actually reads this fine, but it's a nice human-readable (and searchable) view of the data that goes into the policy database. It contains a number of comments, but most are just where the various policies were merged from. It is the largest file.
The policy database file ("Volume" to use the term of the CEDB APIs) itself is large-ish (mine approaches a megabyte) and contains three CEDB databases. The first is a small single-record "database" (in SQL you'd call it a table) that appears to be used for transaction locking. The second is a single large record (several KB) that appears to be a bloom filter (Wikipedia has a pretty good article, the short version is that it is a quick and compact data structure for checking whether a given item is in a collection). The third database (named "PatternDBmultimap") is the real deal, containing thousands of policy records.
I haven't looked at the Accounts database much yet. It's smaller than the Policy database volume, but still a few hundred KB. A substantial portion of that is probably custom accounts created for each app that is installed (since each app has different permissions - specifically, each app has read and write access to a different set of folders - there must be a unique account for each).
The policies appear to come from a few sources. One of them is the many *.policy.xml files (the first part is usually a GUID) in the Windows folder. These files are locked in ROM, and define the core system policies (system accounts, permissions for system objects, etc.). The \Windows\Security\PolicyCommit.xml file (which is not in ROM, or even marked read-only) appears to be simply the result of merging all these files.
Another source of policies must be the application installer. Application-specific polices are not present in the PolicyCommit.xml merged file, but are in the database itself. It is reasonable to expect that they are created and removed by the package manager. This is a good sign for being able to modify policies ourselves.
The initial creation of the policy files appears to be up to a program, \Windows\PolicyLoader.exe. This program takes policy.xml files, merges them, and produces the merged result file and the policy database(s?). It's even possible to run it, given sufficient permissions. Unfortunately, it seems unable to modify the policies on a running device, and is believed to only run at first boot (or after a hard reset) or when an update CAB installs new policy XML files.
EDIT: Attaching the \Windows\Security\*.xml files from my phone, along with the decompiled source for PolicyLoader that was posted on the other thread.
The LG MFG app has a section for editing certain security policies. I can post the info from there, if it'd be of any help. By the way, it specifically says "Edit security policy through registry" so it might not be the same policies that you're talking about, I don't know.
EDIT: Actually, looks like those policies are a subset of the ones listed here: http://msdn.microsoft.com/en-us/library/bb416355.aspx
Analysis of the policy database
I wrote a function to dump the policy database to a text file (with inevitably some embedded binary). Each record in the database has four fields. I'll do my best to describe them below.
1) The first is a DATETIME struct (two 32-bit integers). This is the only 64-bit numerical type available except for a DOUBLE, so it might be selected just as a convenient way to store that many bits rather than because it's actually a date and time. In particular, when I converted them to actual dates and times, the years ranged from the 1970s well into future centuries... this seems an unlikely candidate for an actual set of dates.
What I think it actually is, is some kind of hash of the second field. It might be the index bits for the bloom filter, for example. The reason I think so is that, when there are multiple records with the same value in the second field, they also have the same value in this field, but even a slight difference in the value of the second field results in a very different first field.
This field is not unique, but it does appear to be the default sort order for the database. I don't know if that's ust because it's the first field, but it would make sense to have it be indexed using this field for fast lookup (binary search) after the bloom filter finds that the item is (probably) present.
2) This field is a binary BLOB struct (a size and a pointer). This field contains Unicode strings, sometimes with a bit of binary data (small, typically less than 20 bytes) tacked on the end. Strings plural; each one is NULL-character terminated.
This field appears to be the paths that indicate the object (or objects, since it can contain wildcards) that the policy applies to. If there is a policy in the XML for ResourceIri="/REGISTRY/HKLM/SOFTWARE/MICROSOFT/CAMERA/READWRITESETTINGS" then there will be a record in the database with the second field that would be written like this in C source code: L"REGISTRY\0HKLM\0SOFTWARE\0MICROSOFT\0CAMERA\0READWRITESETTINGS\0". I'm not sure what the occasional binary afterwards means, although there appears to be a specific value for a wildcard (represented in the source XML as ResourceIri=/PATH/WILDCARD/BASE/(*)", but the last part doesn't translate to Unicade the way you'd expect).
As mentioned above, I'm pretty sure that the first field is related to this one. Since the value of a bloom filter on this database would be to quickly establish "Is there a policy for this object?" it makes sense that the path (second field) is the data that gets hashed to produce the bits of the key. It's not really required to then store the key bits, but they make a reasoanble value to sort on.
3) The third field is also a binary BLOB, but the value of it is much more opaque. Typically in the range of 50-300 bytes in length, there are certain patterns that I've noticed within it (0x01 00 01/02 00 65 is a common prefix, and they typically end with 0x00 3X) but I have not yet determined what they actually represent.
Some logical possibilities are an account identifier (though that seems needlessly long for such a purpose) or possibly the permissions data directly. When the second field has a path to related objects (for example, the isolated storage of an application), the third field is often similar as well.
4) The fourth field is another DATETIME struct, but in this case is obviously not an actual date value. The high four bytes are (almost?) always 0xFFFFFFFC, and the low four bytes are typically 0x0000XXXX where the Xs can be anything. This value is not unique - there are numerous instances of 0xFFFFFFFC00000001, for example - but I'm not yet sure what it is.
The same guesses I offered for field 3 apply as well, with the caveat that it's probably not just a different representation of field 3 because two records can have the same value on field 4, and their field three values may not only differ, but be different sizes. I need to look at the XML files and see if there's a pattern between policies with the same field 4 and an equivalent data item in the XML.
I'm attaching the dump file I created of the policy database. It's best opened in a hex editor (Visual Studio does well enough) although you can also use Wordpad (Notepad won't respect the line endings). Wordpad can't show you the binary, of course, but it's a readable layout of the data.
The format is as follows:
ASCII string: "Index "
ASCII representation of an Integer for the index.
ASCII string: ": Prop0 (FILETIME): 0x"
ASCII representation of the DateTime, with a space between the high and low DWORDs.
ASCII string: " | Prop1 (BLOB, "
ASCII representation of the blob's integer size.
ASCII string: " bytes): "
Direct dump of the second field's BLOB buffer (multiple UNICODE strings).
ASCII string: " | Prop2 (BLOB, "
... and so on. I intentionally used ASCII to make the direct memory dumps, which are in UNICODE for the second field at least, stand out.
@Arktronic: Interesting. Those policies (in the registry) are a legacy holdover from WinMo, and at least some of them have been superceded by the new policy system, but the fact that LG gave them specific mention in their app suggests that they still have some relevance.
However, you're correct that those aren't the policies I was speaking of elsewhere in the thread. It may be a good idea to explore them both in parallel, though. Which ones does the LG app list?
Arktronic said:
The LG MFG app has a section for editing certain security policies. I can post the info from there, if it'd be of any help. By the way, it specifically says "Edit security policy through registry" so it might not be the same policies that you're talking about, I don't know.
EDIT: Actually, looks like those policies are a subset of the ones listed here: http://msdn.microsoft.com/en-us/library/bb416355.aspx
Click to expand...
Click to collapse
We already did some testing with those policy settings, but the ones granting more access were not available and the others could not get the app itself into an "unsafe" mode. But then again, I'm far from a professional when it comes down to these things, I just crossreferenced them all against the MSDN DB and looked for the ones that would make fileops possible, no luck.
I'm not sure if they added policies to the LG MFG app in the meanwhile (unlikely) but it might be worth it to investigate how the MFG app modifies those select policies.
GoodDayToDie said:
@Arktronic: Interesting. Those policies (in the registry) are a legacy holdover from WinMo, and at least some of them have been superceded by the new policy system, but the fact that LG gave them specific mention in their app suggests that they still have some relevance.
However, you're correct that those aren't the policies I was speaking of elsewhere in the thread. It may be a good idea to explore them both in parallel, though. Which ones does the LG app list?
Click to expand...
Click to collapse
The latest ROM's MFG app has the following policy IDs: 4104, 4105, 4108, 4109, 4110, 4111, 4113, 4119, 4120, 4121, 4124, 4131, 4132, 4141, 4142, 4143, and 4149.
The last one isn't in the MSDN doc; it calls itself "FIPS Self Test Policy" or SECPOLICY_FIPS_SELF_TESTS.
There are potentially useful things like SECPOLICY_OTAPROVISIONING (4111), which has the value of 3732 - no idea which flag(s) that represents - but if there's a way to send provisioning messages to WP7, that might open up quite a few possibilities.
I believe there's at least a chance for OTA provisioning. Sending custom SMS appears to be possible (click around from the link):
http://msdn.microsoft.com/en-us/library/ee498239.aspx
That said, it's almsot certainly either secured or disabled by default.
Hmm... does anybody want to take a shot at getting a decent decompile of lvmod.dll? I don't have the tools, though I probably should. Reading the disassembly is slow and painful.
I've found a few new things:
It's possible for two records to differ *only* on the third field, and even then the binary was more alike than not. Look at indexes 12 and 13 in the dump - they're really similar. They are built from the following policy rules (no promises on order):
Code:
<Rule PriorityCategoryId="PRIORITY_HIGH" ResourceIri="/REGISTRY/(*)" SpeakerAccountId="S-1-5-112-0-0-1" Description="TCB can do anything to all registry keys">
<Authorize>
<Match AccountId="S-1-5-112-0-0X02" AuthorizationIds="KEY_ALL_ACCESS, KEY_READ, KEY_WRITE, KEY_EXECUTE, GENERIC_READ, GENERIC_WRITE, GENERIC_EXECUTE, GENERIC_ALL, DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, SYNCHRONIZE, STANDARD_RIGHTS_REQUIRED, SPECIFIC_RIGHTS_ALL, ALL_ACCESS" />
</Authorize>
</Rule>
Code:
<Rule PriorityCategoryId="PRIORITY_LOW" ResourceIri="/REGISTRY/(*)" SpeakerAccountId="S-1-5-112-0-0-1" Description="Catch all rule to allow Normal and above apps to read/write to all unnamed keys">
<Authorize>
<Match AccountId="S-1-5-112-0-0X23" AuthorizationIds="KEY_ALL_ACCESS, KEY_READ, KEY_WRITE, KEY_EXECUTE" />
</Authorize>
</Rule>
I would have thought that either the different permissions being granted, or the different accounts they were granted to, would result in a different fourth field... but no such luck. Time to look into this further.
The accountdb.vol file has two databases in it, GroupMemberships (1105 records on my phone) and Accounts (291 records). The latter is actually much bigger in terms of data size, though - 70KB vs 31KB for GroupMemberships. The records in GM must be very small, probably just pair mappings.
Hey GoodDayToDie,
Awesome job on sharing all this low level findings from underneat the hood of my favourite mobile OS. While i'm not capable of researching this myself due to lack of knowledge I love to read about how you (and other well known WP7 hackers as well of course!!) tackle the security and are willing to share this with the community to combine power. I think threads such as these are really necessary to get to the finish. Keep up the good work, i've got a strong feeling we will get there eventually .
THANKS
Looks to me like this is the policy database.
Here is an example set of policies that enable/disable tethering on the Arrive.
Is shows the values needed to create/add a policy to the policy database. HTClv.dll shoudl be able do set/modify these values using "LVModProvisionSecurityForApplication"
You may already know this, but figured I would share.
Also, HTC has regedit.exe and HTC uses it to provision/make registry changes.
I will attach the regedit4 file HTC uses to configure the radios.
This also defines where the key UserProcGroup defines the TCB chamber a driver runs under. see... "UserProcGroup"=dword:5 ; TCB chamber
Seems with using the registry editor, we could elevate any driver to the Kernel chamber.
See attached....
Thanks for the info Paul!
I've heard of the "LVModProvisionSecurityForApplication" API before, yes, and it might be possible to use it here (*really* depends on how it works; if it just reads the app's manifest file like the normal XAP installer does, that's not very useful). LVModAuthenticateFile, LVModRouting, and LVModAuthorize may be extremely useful, though. It also might be helpful to try reverse-engineering how it interacts with the policy database.
The weird thing is, I don't have any htclv.dll or htcpl.dll on my phone, at least not in the \Windows folder. Perhaps they were removed in an older firmware update? It certainly sounds like they would provide the APIs I need - only for HTC phones, true, but they would provide.
The policy.xml file is the standard format read by PolicyLoader.exe, but that doesn't really help unless I can convince PolicyLoader to modify the ploicy database on a running phone.
Elevating an (already installed) driver to TCB might be useful (although I'm not certain that LVMod route-to-chamber rules wouldn't interfere) but all the useful HTC drivers are already in TCB, and installing any more drivers... well, I haven't been able to make that work yet, even old versions of official drivers with the necessary changes to the DllName in the registry.
It's really too bad you can't join in on hacking this stuff though, you've got the right ideas. Do you by any chance have a NoDo restore point you could downgrade to in order to try out some stuff on the old firmware?
Dumped the account database
Turns out the account info is quite straightforward. There are four fields per record.
0) String - the SID ("S-1-5-112-0-0X10-0X00000024").
1) Int32 - 0 for accounts, 1 for groups.
2) Int32 - always 0 on my phone.
3) String - account or group name ("TCB" or "ID_CAP_FILEVIEWER:Capability for hybrid file view app such as PDF reader etc." or "Settings3.exe Chamber" or "9BFACECD-C655-4E5B-B024-1E6C2A7456AC").
Not sure why the third field is there if it's always 0, but OK. The first and last were obvious, and the second was easy to infer. The last record has no fields, and the three immediately before it are without a fourth field; not sure why. All three are groups, and their SIDs are:
S-1-5-112-700-4160
S-1-5-112-700-5132A485-ADEE-5842-9490-856FFFFF2D6D
S-1-5-112-700-A22CF327-25C3-DB2A-A8DF-7BE586F11FBD
This database contained no binary blobs, so the dump file is plain ASCII text (the strings were originally Unicode but converted to ASCII gracefully). In the interest of making it easier to analyze, I ran a quick pass over the dump with sed and produced a CSV, which is attached.
Then, there's the GroupMemberships database. I think this one is probably less important for our concerns, but I wanted to take a look anyhow. It's the simplest so far, though that's not necessarily good. Each record has two fields, and both are just 32-bit ints.
0) Ranges from 0x30000006 to 0x3F0004A6, though the the third through fifth hex digits are always 0. Includes duplicates.
1) Ranges from 0x31000008 to 0x3100007A, then from 0x32000380 to 0x3200038C. Includes duplicates.
The mappings appear to be many-to-many (each account in multiple groups, each group holding multiple accounts) as expected. I'm guessing the first column is accounts and groups, and the second is the groups that the account or group belongs to. Given that some values appear in both columns (through in different records), I'm guessing nesting of groups is allowed.
I dumped and CSV-d this database, and it is attached as well. Ideas as to what's up with it are welcome too.

Categories

Resources