Hack to change default browser - Windows Phone 7 Development and Hacking

Hello,
I recently bought and installed surfcube (which is pretty cool) but whenever i click on any link outside the browser (ex: twitter/ facebook), it automatically opens an IE window. Any hack out there to get that to go to a different browser, such as surfcube?

This may be based on the default handler for the http: URI format. If anybody finds a way to change this (either the URI handlers, file extension handlers, or just default browser) we would all love to know. I don't think anybody has pulled this off yet, though.

GoodDayToDie said:
This may be based on the default handler for the http: URI format. If anybody finds a way to change this (either the URI handlers, file extension handlers, or just default browser) we would all love to know. I don't think anybody has pulled this off yet, though.
Click to expand...
Click to collapse
And almost more importantly, SurfCube doesn't have the code to read a URL from a command line (or whatever method is used), so the best it would do is just open the app without the specified URL.

davux said:
And almost more importantly, SurfCube doesn't have the code to read a URL from a command line (or whatever method is used), so the best it would do is just open the app without the specified URL.
Click to expand...
Click to collapse
Hi,
I am the developer of SurfCube - if somebody can figure out how to open it as the default browser, we will work hard on making it actually open the URL if it gets passed to us.

That would be pretty cool. I would suspect that there is a registry key for the default handling of URL's. Passing that URL to the third party browserr would most likely need command line and lower file system access.
Sent from my Samsung Focus

HKEY_CLASSES_ROOT is present on WP7, although it works a little differently than on desktop Windows. One thing worth noting is that built-in software, such as IE, is invoked differently from installable apps. Built-in software is compiled to actual EXEs, which of course have a standard way to be passed parameters. WP7 apps are DLLs, invoked by a hosting EXE. Also, the way apps are specified is a bit weird; it's by GUID instead of by path.
There is one installable app which is registered as the handler for a file extension (Adobe Reader for PDF). By picking apart its registry entries, I have at least a partial view of how it works.
HKCR\.pdf:
Default = PDFFile
Content Type = application/pdf
HKCR\PDFFile
AppID = "BC4F319A-9A9A-DF11-A490-00237DE2DB9E"
Application Task = "app://BC4F319A-9A9A-DF11-A490-00237DE2DB9E/_default?"
EditFlags = d:0x00010000
HKCR\PDFFile\shell\open\command
Default = "app://5B04B775-356B-4AA0-AAF8-6491FFEA5665/_default?type=PDFFile&file=%s"
There are some interesting hings here. First of all, the BC4F GUID is the one for the Adobe Reader app. Therefore, AppID is the GUID for an installed app that handles a file or protocol association.
Second of all, the shell\open\command\Default value is present for every openable type, but the GUIDs it contains are *not* in the Applications list (note the difference between it and the AppID value). This appears to be how the OS specifies native applications.
Third, it *is* possible to pass parameters to installable apps. See the %s on the end of the value? That gets replaced by the filename, I suspect. Anybody want do pull apart the Adobe Reader or YouTube apps (the only ones with AppID values) and see how they do it?
Fourth, I'm pretty sure we can use this to add our own associations even if we can't get it to open files in them. I'm not sure how easy it will be, but it should be possible.
For those interested in browsers:
HKCR\http
Default = "HyperText Transfer Protocol"
Source Filter = "{97e7c245-4d6f-483b-a772-de22b15fa999}"
URL Protocol = ""
HKCR\http\Extensions
.3g2 = "{97e7c245-4d6f-483b-a772-de22b15fa999}"
.3gp = "{97e7c245-4d6f-483b-a772-de22b15fa999}"
.aif = "{e436ebb6-524f-11ce-9f53-0020af0ba770}"
... and 20-odd more like this
HKCR\http\Shell\Open\Command
Default = "app://5B04B775-356B-4AA0-AAF8-6491FFEA5665/_default?StartURL=%s"
HKCR\PROTOCOLS\Handler\about
CLSID = "{3050F406-98B5-11CF-BB82-00AA00BDCE0B}"
HKCR\PROTOCOLS\Handler\javascript
CLSID = "{3050F3B2-98B5-11CF-BB82-00AA00BDCE0B}"
HKCR\PROTOCOLS\Handler\mailto
CLSID = "{3050f3DA-98B5-11CF-BB82-00AA00BDCE0B}"
HKCR\PROTOCOLS\Handler\res
CLSID = "{3050F3BC-98B5-11CF-BB82-00AA00BDCE0B}"
... note that these GUIDs are very similar but not the same.
HKCR\.html
Default = "htmlfile"
Content Type = "text/html"
HKCR\htmlfile
Default = "HTML Document"
EditFlags = d:0x00010000
HKCR\htmlfile\CLSID
Default = "{25336920-03F9-11cF-8FD0-00AA00686F13}"
HKCR\htmlfile\Shell\Open\Command
Default = "app://FB04B775-356B-4AA0-AAF8-6491FFEA5660/_default?StartURL=file://%s
HKCR\MIME\Database\Content Type\text/html
CLSID = "{25336920-03F9-11cf-8FD0-00AA00686F13}"
Encoding = 08-00-00-00 (binary)
Extension = ".htm"
I'm omitting a few fairly irrelevant keys, like DefaultIcon. This FB04B775 app is interesting - it seems to serve as a launcher, although that's just a guess for now. In any case, it accepts parameters like StartURL, Type, and File (with the last two coming together) and file substitution (the %s that stands in for the URL or file).
Anybody want to have a go at detangling this?

Also, Good News Everyone: it *is* possible to add associations between unknown extensions and known files, at least. I just added HKCR\.log as a clone of HKCR\.txt (Default = "txtfile"; Content Type = "text/plain") and opening a .LOG file in Outlook now opens the file in Work (it used to trigger a MessageBox saying file type was not known). So cool!

Looks like you can override OnNavigatedTo (from PhoneApplicationBase class) and use NavigationContext.QueryString() to get the required information.
If you use something like
Default = "app://5B04B775-356B-4AA0-AAF8-6491FFEA5665/_default?type=PDFFile&file=%s"
you could use
var params = NavigationContext().QueryString();
if (params.ContainsKey("file"))
{
// code here
}
so any param of the caller url will be part of the query string dictionary.
Hope this helps.
P.S.: Office does it in a more elegant way , They use only one param "CmdLine" and can use the normal cmd line argument parsing on this param, e.g. ...........?CmdLine=-opendoc %s

kuerbis2 said:
Looks like you can override OnNavigatedTo (from PhoneApplicationBase class) and use NavigationContext.QueryString() to get the required information.
...
P.S.: Office does it in a more elegant way , They use only one param "CmdLine" and can use the normal cmd line argument parsing on this param, e.g. ...........?CmdLine=-opendoc %s
Click to expand...
Click to collapse
Yes, this is pretty much what I wanted to go with. The question now is how to get SurfCube to open if you click on a link in en email or twitter or the poeple hub.

I can only imagine one solution (but my imagination is limited <g>): Create two apps.
1.) SurfCube prepared for parameter passing
2.) HomeBrew App which replaces HKCR\http\Shell\Open\Command
-t

kuerbis2 said:
I can only imagine one solution (but my imagination is limited <g>): Create two apps.
1.) SurfCube prepared for parameter passing
2.) HomeBrew App which replaces HKCR\http\Shell\Open\Command
-t
Click to expand...
Click to collapse
Yes, this is exactly what I am thinking about. But I need help with the second one from this group. Also, is there any way to do the registry edits on the emulator? I would prefer to play with that until things get fairly stable.

After digging a bit deeper, it looks like you are out of luck. I don't know why but the AppID of MobileIE is hardcoded in the WebBrowserTask (reference assemblies and Samsung Omnia 7 GAC assembly):
ChooserHelper.LaunchSession("app://5B04B775-356B-4AA0-AAF8-6491FFEA5660/_default?StartURL=" + this.URL);
So, even if you manage to change the html handler, you won't get the calls from the correspondig task.
Long time since I've seen something hardcoded like this on a windows platform...

I can't confirm this now, but I think 5b04b is actually the application host process. In other words, it's the thing that makes the navigation buttons work, and which runs the installable app DLLs. The StartURL parameter may just mean "look up things defined as a URL Protocol (HTTP is one such thing) and launch the corresponding app." The Filter value may be relevant here, perhaps even as the actual app id for IE. In any case, I get the feeling that the reason it's hard-coded is because it's the launcher app, and StartUrl is just how you tell it to invoke the web browser.

However, the hardcoded GUID and the ones in htmlfile, http and related keys is different from for example the one used in PDFFile.

Crap, you're right. I wasn't paying enough attention to the last couple digits. It doesn't help that searching registry data (as opposed to keys and value names) doesn't seem to work. I'm tempted to say that some experimentation is in order, although I'd prefer to know what I'm messing with.

Related

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.

[Q] [Resolved] [.Net CF 3.5] How do i create a treeview based file browser

I have a problem with a project i'm working on and that is:
How do i create a TreeView based file browser that can export a selected path and filename to a textbox and a Process.Start call at the same time. That's it in a nut shell. The main part if the tree view bit but i haven't figured out how to do variables yet and i'm gonna need one for the second part. I have spent hours googling and i have this question posted on a dedicated VB forum.
I'm using Visual Basic 2008 as the IDE and .Net CF 3.5 as the language (obviously)
If anyone has any ideas on this i'll gladly hear them coz i am really stuck. I found writting code to soft reset a device was easier
TreeNodeCollection tr=treeView1.Nodes;
TreeNode tn;
foreach (string dirs in System.IO.Directory.GetDirectories(System.IO.Directory.GetDirectoryRoot(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName)))
{
tn = new TreeNode(dirs);
//tr = new TreeNodeCollection();
tr.Add(tn);
}
ergintiravoglu said:
TreeNodeCollection tr=treeView1.Nodes;
TreeNode tn;
foreach (string dirs in System.IO.Directory.GetDirectories(System.IO.Directory.GetDirectoryRoot(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName)))
{
tn = new TreeNode(dirs);
//tr = new TreeNodeCollection();
tr.Add(tn);
}
Click to expand...
Click to collapse
Is that C# code or VB?
M3PH said:
Is that C# code or VB?
Click to expand...
Click to collapse
C#....VB don't have the curly brackets
So i've come back to this question after a few months avoiding VB. I'm now working on a new product and the lack of an folderbrowserdialog object in .Net CF is killing me.
What i need is this (oh and thanks to everyone that posted above but i can't make that solution work). A way to list all the folders on a device and then select one that can be passed to a variable so it's path can be used elsewhere. Maybe also pass the path to a textbox just so it's clear what you have selected. I've spent 2 days googling this and i did find a few things. Most don't work and the rest are in c# which is not much good. So if anyone wants to help me out i would really appreciate it.
Get your head round this.........
O.K. Here's how it's done, with a crash course in one of the most powerful of programming techniques - Recursion. It can confuse the hell out of rookie programmers, as they just can't get their heads round what's going on. It is dependant on a function's local variables and fortunately, .NET's stack based architecture allows us to use it to the full.
You will need, 1.) a TreeView object - named "treeView1" and 2.), a label named "label1" placed underneath it. The label is only there to prove the point that we can get at the full pathname of the selected directory in the Treeview. In reality it can be dropped, just put your processing code directly in the TreeView's AfterSelect() event.
The Form_Load() event gets the directories in the root directory, by calling GetDirList with an initial directory of "\".
GetDirList() adds the directories to the TreeView then calls GetDirList again on each directory to get any subdirectories, and again on each subdirectory, ad nauseum. Keep going until there are no more directories returned.
When completed TreeView contains a list of every directory/subdirectory on the device.
When you select an item from the TreeView the full pathname is displayed in the label. The image at the bottom shows it running under debug on the WinMo 5.0 emulator. There are several directories you would not normally see on your device.
Good Luck, stephj.
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Me.GetDirList("\")
End Sub
Private Sub GetDirList(ByVal PathName As String)
Dim dirs As String
For Each dirs In Directory.GetDirectories(PathName)
Dim tn As New TreeNode(dirs)
Me.treeView1.Nodes.Add(tn)
Me.GetDirList(tn.FullPath)
Next
End Sub
Private Sub treeView1_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs)
Me.label1.Text = e.Node.FullPath
End Sub
P.S.
You will need the VB equivalent of using System.IO adding to your project.
This stuff has been around since .NET CF 1.1
The original project was written in C#, I used .NET Reflector to translate it into VB from the original. The original C# is included here:-
Code:
using System;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
GetDirList("\\");
}
private void GetDirList(string PathName)
{
foreach (string dirs in System.IO.Directory.GetDirectories(PathName))
{
TreeNode tn = new TreeNode(dirs);
treeView1.Nodes.Add(tn);
GetDirList(tn.FullPath);
}
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
label1.Text = e.Node.FullPath;
}
}
}
cool thanks. I'll have a look at coding this tomorrow (i having some fun time right now).
I did have a look at doing this with a list box yesterday but i was getting errors left, right and centre so i really do appreciate the help.
Just an FYI the VB equivelent of "using" is "imports" otherwise most of the objects are the same but i don't nee to worry about adding it as the program is already interacting with the file system.
Again thanks very much. I really appreciate you taking the time to help me out.
I've just had a look at implementing this but i'm having trouble getting the treeview to populate with the folder list. What am i doing wrong? the object names all match up and i can't see why it's not working. Am i just being plain dense?
What i have Is pretty much what you posted except for a few changes to allow for the fact that the treeview object is in a tabcontrol and i already have a bunch of labels knocking around so the label is called label28 and not label1.
I'm sorry if it appears like i'm not trying or i'm asking you to do all the work but i am genuinely really stuck. I get the recursion principal, That's not an issue but i'm trying to create something from scratch that should really have been included in .net CF and i'm just not that good a programmer yet
Should work..... but without seeing the actual code it's rather hard to remotely debug it.
To prove the point, here's the complete VS2008 VB .NET CF 3.5 project.
In the \bin\release directory is the actual executable. If you have .NET CF 3.5 on your device, drop DirList.exe onto it and run it.
I had a look at the project you posted and just copied the coded over. I did make some tweaks so it only loaded the folder list when the tab the treeview was on was clicked but that didn't work so i repated the code in as is and voila! it works. Now all i need is to create a variable to store the selected path in but i think i can manage that.
Again a huge thanks.
Hierarchical view......
Here's the project to indent, compress, and expand the directory tree structure.
I was just playing around with this and i noticed that when you click on a directory below "\" the path becomes "\\this\path". This is obviously not a valid windows mobile path and it is causing an IOexception and I have no idea how to fix it. Google suggests lots of c# pages that say to use a regular expression to strip out the illegal characters but the example i found was for the entire path and it seemed to check each character against a variable of illegal values. I'm sure if that would work for me. Heres the link.
Let me know what you think.
I have no idea where the \\this is coming from, I can't replicate it.
To filter out the extra leading slash use this:-
Code:
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
If TreeView1.SelectedNode.FullPath.Length() = 1 Then
Label1.Text = TreeView1.SelectedNode.FullPath
Else
Label1.Text = TreeView1.SelectedNode.FullPath.Substring(1)
End If
Interesting new problem has cropped up with this code. It doesn't seem to work on rhodiums. It works fine in the emulator, my HD2 and all of CajunFlavouredBob's devices but i have a user that has a rhodium that get the error posted here. I can't replicte it and i don't have a rhodium to test it with. Any ideas?
Hmmmmm another tricky one. Without seeing the device actually throw the error, it can be a bit difficult.
Does this machine actually report the storage card as "\Storage Card"? Some machines don't. In which case you may have to use some storage card enumeration trick to get hold of the real name it uses. This may not apply in this case.
Also, to make things trickier still, the stack dump shows 'GetInternalDirectoryNames()' as the function throwing the error first. This is a level below your call of GetDirectories(), and is being used by the OS to actually go get the info. You may have to create a test version of EXCT2 full of Try...Catch programming blocks, to try to get to the real point where the error is being thrown.
well this turned out to be a memory related issue. So instead of using the folder browser we now use the stock winmo savedialog. because it uses less memory and allows us access to the locations we need.
Thanks for helping though steph.

[eVC++] How to rename/delete/copy/move a file from specified location?

Hello.
Just a quick question,I didn't found answer for,not so difficult for skilled programmers.
I have a file "\Somewhere\abc.xyz",which I want to rename to something else,delete,copy or move to different location.
How can I do this in classic Embedded Visual C++ 4.0SP3?
Can anyone post here some source code,how to use some functions please?
Thank you for the tips in advance.
Use the functions DeleteFile(), MoveFile(), DeleteAndRenameFile() and CopyFile(), all functions are already in coredll.dll, and are declared in winbase.h, should be part of a standard app.
Parameters change from one function to the next, you'll have to look in the online help for the full definitions, but most of them use long pointers to one or more wide character strings. Be aware of the fact that '\' in C++ is an escape character itself, so a backslash in a pathname must be specified as a double backslash, if used in a quoted string. A hard coded example of the above is :
Code:
DeleteFile(TEXT("\\Somewhere\\abc.xyz"));
The compiler macro TEXT converts the string to a wide character TCHAR string, as required by the function.
Variable strings passed to the function should be TCHAR arrays. Use the predefined value MAX_PATH for the length. To put values in them at run time by the program use wsprintf();
for example :-
Code:
TCHAR szFile[MAX_PATH];
SYSTEMTIME stime;
GetLocalTime(&stime);
wsprintf(szFile,"\\Storage Card\\%04d%02d%02d.TXT",stime.wYear,stime.wMonth,stime.wDay);
DeleteFile(szFile);
deletes the file on the storage card with today's date as YYYYMMDD.TXT, if it exists, e.g. \Storage Card\20101121.TXT

Little "non-useful" tips/hacks

Hi all.
This is a little collection of things that i have been noticing while testing hacking issues on the phone.
Remember that those are "non-useful" (not to jailbreak) the phone, and just curiousity as topic.
Easy Hidden Menu Call
Do you need a search on the net to remember the hidden menu code? No more!. Test this phone-number string instead:
(Edited now): ##PROGRAMNITT
Max size for an app name/web favorite
Seems to be no max per se, but after doing some test, where i created title as: "chunk1chunk2chunk......chunkN" i was able to load a 1691124 characters title. Further than that, the browser seems to crash.
That's about a 3MB text string, just for the title. Would work well, when testing if several of them pinned reduce our 8gb storage(use storage) or doesn't (uses other).
Btw, you can pip up to 67 apps, (51 new) so... that's a max anyway,
Application Menu "About:blank" hack
Test this in the browser bar as direction: "about:blank". Kin IE will yell that it's not a supported protocol. Yeah, that's right. Let's dev a page on a local webserver with:
PHP:
<html>
<head>
<title>Mad redirection!</title>
</head>
<body>
<h3>Mad redirection tool!</h3>
<p> Testing: <div id="testTab"></div></p>
<p> Errors:
<div id="errorsTab"></div>
</p>
<script type="text/javascript">
var urlToTest = "about:blank";
try {
var test = document.getElementById("testTab");
test.innerHTML = urlToTest;
window.location=urlToTest;
}
catch (error) {
var err = document.getElementById("errorsTab");
err.innerHTML = "Error going to " +urlToTest+"<br/>"+error.message;
}
</script>
</body>
</html>
Browse it with the kin and you will land in the about:blank page, with the ability to be pinned on the application menu. Of course it will work, having the App link on the App menu, with a non working link (Kin still yells if you use it from menu).
Useless, but weird...
I do know that this is pure thread necromancy and that those are old news but:
a) if you are able to do the trick (using the sample html i posted) you can see that indeed it comes to about:blank and is shown as that on the title: "ABOUT:BLANK".
b) if you are so smart to change it to "about:lame" it goes there but shows a "Action canceled" webpage, where it suggest you to press the "refresh" button or use menu opcion "File -> work offline".
Like if you could.. rofl.
That means:
1) "about:" protocol is supported (at least about:blank) to be navigated BUT is nerfed from the direction bar. So other protocols could work. For example, smtp and ftp does trigger a popup from the IE, but res:// file:// and rtsp:// do not (even if they crash later, and rtsp opening zune for streaming).
2) This is a pure IE (with file menu,hopefully )
3) some other things can be tested, and every person can!
I upgraded the posted code, so it outputs an error when the redirection doesnt work (almost allways).
If you try it, remember not to end your url with \ (backslash) as it interferes with the doublequotes.
I've just completed testing a couple of things.
First, I successfully tested the "about:blank".
I also tried "about:", "about:about", "about:cache", and "about:home". These each resulted in the action canceled page described above.
I also tried the "file://" protocol, with the address "file://localhost/c:/" and received the following:
Errors:
Error going to file://localhost/c:/
Could not complete the operation due to error 80070005.
[edit] It seems that error 80070005 is given when you do not permission. The solution? Log on with administrator privileges... (see link)
Upon further testing:
about:desktopitemnavigationfailure works and displays "navigation cancelled" page.
about:navigationcanceled works and displays "navigation cancelled" page.
about:navigationfailure works and displays "navigation cancelled" page.
about:noadd-ons displays "navigation cancelled" page.
about: offlineinformation works and informs the user that the current page can not be viewed off line.
about: postnotcached works and informs the user that to refresh the current page, information entered in a form will have to be re-posted.
about:securityrisk displays "navigation cancelled" page.
about:tabs (unsuprisingly) displays "navigation cancelled" page.
I read that about:mozilla works in older versions of IE. However, it displayed the "navigation cancelled" page. You can also supposedly access the about:mozilla page using the following URL: res://mshtml.dll/about.moz
However, while this "res" protocol appears to be supported, I received the same permissions error as referenced in the above post.
I tested the mms protocol on a couple of working mms streams, but received the notification that the protocol is not supported.
I tried view-source://(random web address) and unsuprisingly was told that the protocol isn't supported. While this protocol works with some browsers, it doesn't seem to work on internet explorer even on a regular computer.
I tried the javascript protocol and it seems to work, but is different than about:, http:, etc. Mainly, it processes the javascript without leaving the script "address" in the address bar like we see with about: and http:
I was a little disappointed in this one, hoping to bookmark a javascript to test the videohamster flash video viewer for ipods, or itransmogrify for other flash files.
very nice work here. I like what you have done with this.
I'm glad that other than about:blank works (apart of the "action cancelled").
I took my time to install a wm6.5 emulator and test where do this "Action cancelled" come from in the pocket IE url bar.
They are from " res://.....navcancl.dll ".
Maybe there's a way to bypass the restrictions (the permission error) by calling some parameter in the "about:XXXX", but i can't bet on it.
Edit:
about:version seems to work (it auto-says "cannot find server", although my python custom-made-for-exploits server says that it delivered my html). But it keeps loading after the javascript redirection happens.... lol, so random .
One thought I had, that I have not had time to experiment with yet, is how deep the permissions restrictions go. For example, at times I have been logged on to a windows-based computer and have access to certain user-specific files but not to system files or to files or folders closer to the root. So for instance, we may be able to access the WinCE equivalent of "C:\Documents and Settings\<UserName>" using the file:// or res:// protocols even though we don't have permission to access "C:\".
Here's another potential avenue for information related to the "res" protocol. Apparently, it can be used to enumerate the software on a machine by identifying certain executables or dlls. (see here).
Unfortunately, the example cited in the article is not available so I can't view the code on how it was done. However, the results can be viewed here, where incidentally you can see the software installed on the computer that crawled this webpage.
Luckily, a manual or how-to paper is available here. I will try to check it out and see if I can figure out something useful.
i checked, it doesnt yell at you if you use a res:// but either if using ftp:// so the big problem is that you must pre-know the res:// uri before testing.
And in the best case, you will just get an image shown, ad js cannot give you the binary data.
anyway, i'm interested in this things....
Here's a couple other likely non-useful tidbits.
The browser will attempt to open the following filetypes with the Zune player:
.avi
.3gp
.mov
.fli
.mp4
.wmv
.wmx
When you open a VBScript in the browser, the script isn't executed, but it is displayed.
The mailto: protocol works from the browser and opens up the email dialog.
The following script causes the browser to hang (and deleting temporary files does not resolve the problem--but restarting the Kin does):
HTML:
<html><body onLoad=Demo()><script>
// MoBB Demonstration
function Demo() {
var a = new ActiveXObject("Internet.HHCtrl.1");
var b = unescape("XXXX");
while (b.length < 256) b += b;
for (var i=0; i<4096; i++) {
a['Image'] = b + "";
}
}
</script>
</body></html>
I haven't played around with the logs at all, but would this provide an error that gives some useful log output?
After some further testing, I discovered the Kin does not yell about the following protocols as being unsupported (in other words, they seem to be supported):
gopher://
nntp://
telnet://
news://
snews://
windowsmail.url.mailto://
windowsmail.url.news://
windowsmail.url.nntp://
windowsmail.url.snews://
johnkussack said:
Maybe there's a way to bypass the restrictions (the permission error) by calling some parameter in the "about:XXXX", but i can't bet on it.
Click to expand...
Click to collapse
I tried playing around with about:____, such as with the following types of addresses:
about:<input%20type=file>
about:<a%20href=C:\windows\>Click-Here</a>
but without luck.
I also tried the shell handler "Shell:" which seems to be another supported protocol, but again without luck. I tried the following Shell commands:
Shellrofile
ShellrogramFiles
Shell:System
Shell:ControlPanelFolder
Shell:Windows
Shell:::{21EC2020 shell:::{21EC2020-3AEA 3AEA-1069 1069-A2DD A2DD-08002B30309D}
Here are a couple more that I found other people sometimes try that I haven't tried (at least not yet):
shell:ControlPanelFolder
shell:::{35786D3C-B075-49b9-88DD-029876E11C01}
shell:::{208D2C60-3AEA-1069-A2D7-08002B30309D}
shell:::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
shell:::{450D8FBA-AD25-11D0-98A8-0800361B1103}
shell:::{E17D4FC0-5564-11D1-83F2-00A0C90DC849}
Ok, so this will be my last post in this thread tonight . For some unknown reason, you can access your emotes when in camera mode.... It doesn't do anything if you try to use one though.
great to hear about the shell::XXXX thing.
Does it trigger something? like about:blank or the other trigger a blank or a "cannot go" page.
btw, a real path on the phone (granted by the logs) is:
\Windows\eri.bin
That's assured , with the start backslash ("\\" if used on js code)
these hacks arent nonuseful
you should have called these hacks something other than non useful because we can use these little tips and tricks in combination with others to actually create an in browser jailbreak using the unrestricted protocols.
shell commands
try the net user admin <username> <password> console command in the shell protocol and see if you an bypass restrictions. theres no reason why console commands shouldnt work even though i havent tried this myself.
X-15D9W8491 said:
try the net user admin <username> <password> console command in the shell protocol and see if you an bypass restrictions. theres no reason why console commands shouldnt work even though i havent tried this myself.
Click to expand...
Click to collapse
Sorry, I'm not sure where you mean to do this. Unless I completely missed the revelation, so far, nobody has been able to get any type of shell/console access (as it doesn't really exist on a Windows Mobile OS anyway).
i called them as is, cause in first place, they were non useful, lol.
Although now, it could be a good try to get some "jailbreak" procedure.
as we dunno what windows mobile i6 can do, i guess we should/must try into a real mobile device (maybe my old pda too), or a win mobile 6.5 emulator, to test procedures (less restrictions), and then repeat on the kin (restricted).
I always though that the browser was the weakest part anyway
if you do tel: in the browser, and write anything after that it opens it up in a bubble....it lets you call letters, although it gives an error in the phone app
When using the TRACERT (Trace Route) in the programnitt menu I found a quirk.
Using 127.0.0.1 to Trace replies: WindowsCE
...that's obvious but interesting.
Using 127.0.0.0 to Trace replies: * 87 (30 times, hits limit and stops)
I have no idea why it would reply with the voicemail number....

Include local JavaScript within PhoneGap on Windows Phone 7

I have a PhoneGap application designed to work on multiple mobile platforms. I'm loading a dynamic HTML content from an external page on the Internet using jQuery Mobile. The problematic system is Windows Phone 7.
This is what I get from the external page, with the URL of the script tag already replaced to load from the phone instead of from the net to save bandwidth:
HTML:
<script type="text/javascript" charset="utf-8" src="x-wmapp1:/app/www/test.js"></script>
This works fine on Android, iPhone and even BlackBerry when I replaced the x-wmapp1: part by a respective counterpart (e.g. file:///android_asset/www/ on Android). However, on Windows Phone 7 it doesn't seem to work at all.
When I try to load the same URL via $.getScript function, it always returns a 404 eror, even if I try and load it with a relative path only.
Any suggestions?
First of all, this type of question may be better suited to the Software Development or Apps and Games sub-forums, as a lot of the people who hang out here are more familiar with homebrew hacks. I'll give it a shot, though.
First of all, what kind of path are you trying to use? I haven't tried loading scripts or images in HTML or JS, but to dynamically load content within the app itself typically requires some care with regard to the path. For example, is the JS file being built into the assembly (as a resource) or included alongside it (as content)? How about the HTML page?
This is a kind of lame approach, but one option that's sure to work is just inlining the scripts in the page, directly. That won't increase the total app size or load time at all, although it might make maintaining the app take a little bit more effort.
Thanks for the reply, I will try to post this into the more appropriate forum.
With regards to paths - you can see the path in the HTML snippet I provided in the original question. It's all a bit specific and we cannot afford to load JS directly from page, since that does increase the size of the resulting HTML, sent from an external PHP page, thus increasing bandwidth. This is the first reason why we chose to have all JS and CSS files directly bundled with the application and load them internally rather than from Internet.
Also, all of JS files are included alongside the application as content. I'm using the same approach for all images, since if they were included as a resource, they would not show in the application.
GoodDayToDie said:
First of all, this type of question may be better suited to the Software Development or Apps and Games sub-forums, as a lot of the people who hang out here are more familiar with homebrew hacks. I'll give it a shot, though.
First of all, what kind of path are you trying to use? I haven't tried loading scripts or images in HTML or JS, but to dynamically load content within the app itself typically requires some care with regard to the path. For example, is the JS file being built into the assembly (as a resource) or included alongside it (as content)? How about the HTML page?
This is a kind of lame approach, but one option that's sure to work is just inlining the scripts in the page, directly. That won't increase the total app size or load time at all, although it might make maintaining the app take a little bit more effort.
Click to expand...
Click to collapse
First question: have you set the IsScriptEnabled proerty on the control to True? It defaults to False, preventing scripting within the control. Also, changing it only takes effect
on navigation, so if you already loaded the page and then set this property, it still won't work.
Anyhow, I missed that your HTML was coming externally, and only the scripts and stylesheets were local. That's... interesting, and seems reasonable enough, and I can't find any info online that exactly matches your use case. The way you're structuring the script src URI looks weird to me, but I haven't messed with the WebBrowserControl very much at all.
One solution, though a bit hacky:
Use the WebBrowserControl's InvokeScript function to dynamically load scripts into your pages. To do this, you would first need to load the script file content into a .NET String object. The GetResourceStream function is probably your best friend here, combined with ReadToEnd(). Then, just invoke the eval() JS function, which should be built-in, and pass it the JS file content. That will load the JS into the web page, creating objects (including functions) and executing instructions as the files are eval()ed.
Of course, you'd need to do this on every page navigation, but you can actually automate it such that the page itself requests that the app load those scripts. In your app, bind the script-loading function to the ScriptNotify event handler, probably with some parameter such as the name of the script to load. Then, on each page served from your server to the app, instead of including standard <script src=...> tags, use <script>window.external.notify('load localscript1.js')</script> and so on; this will trigger the app's ScriptNotify function for you.
I hope that helps. I can see your use case, but somewhat surprisingly, I couldn't find anybody else online who had either run into your problem or written a tutorial on doing it your way.
Thank you for your reply, it was very informative. One question though - why do you think the way I'm structuring the SCRIPT URI is wierd? I tried to mess around with relative URIs and the such, however those would load the JavaScript file from Internet rather than from the application itself.
The problem I'm running into with your proposed solutions, however is that:
1. the project is a PhoneGap/Cordova application, using its own components, so I have no idea where I would look for IsScriptEnabled here (although this all worked on an older PhoneGap release, so I'm guessing they have it set up correctly)
2. injecting a script programmatically on each navigation would require me to rewrite much of the code we already use for other platforms, not to mention those custom Cordova components, which I don't even know if they can handle such thing
As for my user case - I was surprised to be the only guy on the internet with this methodology in place as well. So it either works for everyone else or nobody really thought of doing it my way, since it's basically an Internet application (maybe the don't want to disclose their sources, who knows).
CyberGhost636 said:
1. the project is a PhoneGap/Cordova application, using its own components, so I have no idea where I would look for IsScriptEnabled here (although this all worked on an older PhoneGap release, so I'm guessing they have it set up correctly)
Click to expand...
Click to collapse
In the WebBrowser properties.
CyberGhost636 said:
As for my user case - I was surprised to be the only guy on the internet with this methodology in place as well.
Click to expand...
Click to collapse
Of course you not "the only guy". I've tried to port/run a few HTML java-script based games on WP7 (Digger and couple more) more then year ago; they runs well with one HUGE exception - touch screen events are freezing scripts execution and make games not playable.
The "x-wmapp1:" URI scheme was what I was referring to. Not sure where that comes from, but I haven't done anything really with the WebBrowser control.
I have no knowledge of PhoneGap or Cordova; I assume they're "we write your app for you" frameworks? One would assume that such tools would know to set IsScriptEnabled, but you may have to do so manually. A bit of web searching on that direction may be fruitful - maybe earlier versions enabled scripting by default, and now it's disabled by default so you have to specify an option somewhere?
Injecting the script on navigation really doesn't require any major change to the server-side code. I mean, is sending
<script>window.external.notify('load localscript1.js')</script>
really much different from sending
<script type="text/javascript" charset="utf-8" src="x-wmapp1:/app/www/test.js"></script>
? If that's too different, you could instead send
<script src="http://yourserver.com/LoadLocalScripts.js"></script>
and put "LoadLocalScripts.js" on your server with the following code:
window.external.notify('load localscript1.js');
This has only a trivial increase in server traffic and load time, but lets you continue using external scripts instead of inline ones. Very little server-side change needed at all.
Now, the additional client-side code to support the window.external.notify and call InvokeScript... normally I'd say that's dead easy, because it is if you have any experience with the .NET framework, but in your case I get the feeling that this isn't so? I code to the framework, or to the underlying native code, and I tend to code "raw" (very little auto-generated code), so I'm not going to be able to help you solve the problems with a "make me an app" wizard unless I can see the code it generates for you.
For what it's worth, here's the approximate raw code that I'd use (it's over-simplified, but close enough):
void HandleNotify (String param) {
String[] parts = param.split(" ");
if (parts[0] == "load") LoadScript(parts[1]);
}
void LoadScript (String script) {
String content = Application.GetResourceStream(new Uri(script, UriType.Absolute)).ReadToEnd();
theBrowserControl.InvokeScript("eval", content);
}
void theBrowserControl_Loaded (...event handler args here...) {
theBrowserControl.IsScriptEnabled = true;
theBrowserControl.ScriptNotify += HandleNotify;
theBrowserControl.Navigate("http://yoursite.com");
}
the URI comes from Windows Phone itself, with this code, you can see for yourself:
var a = document.createElement('a');
a.setAttribute('href', '.');
alert(a.href);
also, I've been informed that this works in Cordova 2.0, so it might be a 1.8.1 bug... will try and see how it goes
thanks for your help so far!
Looks like it was a problem with PhoneGap 1.8.1 - after upgading to Cordova 2.0 (PhoneGap got renamed) it all works now... thanks for all the help!

Categories

Resources