The DllImport Project (+/also C++ Wrapper) [Mango Support]

Search This thread

Flow WP7

Member
Mar 23, 2011
29
3
He was talking about the dev of touchexperience, he does not want to share code to help others out. And not about fiinix...

The hate comes from making promises, not delivering and not helping out others...

However fiinix on the other hand helps the community, shares his code and is developing something usefull which everybody will benefit from. He deserves all credit and respect. He is not promising he just delivers instead.

Sorry my mistake, must have over read that.
 

fiinix

Retired Recognized Developer
Oct 9, 2010
570
224
31
Stockholm
:D This is not the way to earn money. People does it at the free time.

fiinix, i see you are using the GDI methods in the CaptureScreen. Are these calls didn't block by policy? Or this code is unworking (it's commented)?
No block at all, it even returns a valid GDI capture handle. I commented it out due i had COM-Interop problems so i commented all methods and started clean by un-commenting only a few.

The CaptureScreen works but the problem is to convert the IntPtr (handle) to Silverlight Image (how..)
 

KooKiz

Member
Nov 20, 2008
39
4
No block at all, it even returns a valid GDI capture handle. I commented it out due i had COM-Interop problems so i commented all methods and started clean by un-commenting only a few.

The CaptureScreen works but the problem is to convert the IntPtr (handle) to Silverlight Image (how..)

Maybe the hard way? Read the binary content of the picture in C++, then return a byte array to the Silverlight code.
 

fiinix

Retired Recognized Developer
Oct 9, 2010
570
224
31
Stockholm
as KooKiz already said IntPtr is for sure a System.Drawing.Bitmap. You need to get its content into a MemoryStream an load it as BitmapSource, even in Wpf there is no other way.

http://www.generoso.info/blog/wpf-system.drawing.bitmap-to-bitmapsource-and-viceversa.html
The "CreateBitmapSourceFromHBitmap" is not available. But when i "Net Reflector" on type "Imaging" its nested internal under "Microsoft.Xna.Framework.Graphics.UnsafeNativeMethods+Imaging", easy to crack, just do

Type.GetType("Microsoft.Xna.Framework.Graphics.UnsafeNativeMethods+Imaging" ... ).GetMethod("DecodeStreamToBuffer").Invoke( ... );

> "DecodeStreamToBuffer(uint handle, ref int width, ref int height, XnaImageOperation operation, ref byte[] buffer);"

Microsoft.Xna.Framework.Graphics.UnsafeNativeMethods (internal)
> .Imaging (public static) (nested)
 

Jaxbot

Inactive Recognized Developer
Mar 14, 2009
1,224
548
windowsphonehacker.com
Question.. how are Silverlight applications displayed under the task list? Are they run through a virtual host application or do they just show up as their app ID or what?

Nice work, by the way! If you can get application resuming done and add it with the dehydration hack, we basically have a fast app switcher ;)
 

fiinix

Retired Recognized Developer
Oct 9, 2010
570
224
31
Stockholm
Question.. how are Silverlight applications displayed under the task list? Are they run through a virtual host application or do they just show up as their app ID or what?

Nice work, by the way! If you can get application resuming done and add it with the dehydration hack, we basically have a fast app switcher ;)
All the managed silverlight's and XNA go under the process name "TaskHost.exe". Next step is to see what arguments/command that goes with it and maybe im able to start an app from phone sided code.
 

KooKiz

Member
Nov 20, 2008
39
4
Have you tried a StartProcess directly on the xap file? That's still a Windows CE under the hood, there may be a file association set.
 

Jaxbot

Inactive Recognized Developer
Mar 14, 2009
1,224
548
windowsphonehacker.com
Have you tried a StartProcess directly on the xap file? That's still a Windows CE under the hood, there may be a file association set.

The HKEY_CLASSES_ROOT shows all the different file associations and what commands they run. Interesting stuff, but not really modifiable/useful.

All the managed silverlight's and XNA go under the process name "TaskHost.exe". Next step is to see what arguments/command that goes with it and maybe im able to start an app from phone sided code.

Ah, that's what TaskHost is for. Yeah, it's probably TaskHost <appID> but it could also have other flags associated with it. I can run EXE commands from the PC, would be nice if I can do this phone-wise ;)
 

Marvin_S

Retired Recognized Developer
Dec 8, 2010
883
239
All the managed silverlight's and XNA go under the process name "TaskHost.exe". Next step is to see what arguments/command that goes with it and maybe im able to start an app from phone sided code.

Cool :) how many of those keep running? Is it indeed 4 like the quantum number? Ans you are able to kill those tasks as well? What if you kill it and press the back button? Does it skip the task or does it launch the previous app from scratch?
Interesting stuff good job, did you found a way to identify the xaps yet?
 

fiinix

Retired Recognized Developer
Oct 9, 2010
570
224
31
Stockholm
Cool :) how many of those keep running? Is it indeed 4 like the quantum number? Ans you are able to kill those tasks as well? What if you kill it and press the back button? Does it skip the task or does it launch the previous app from scratch?
Interesting stuff good job, did you found a way to identify the xaps yet?
I can kill any task i want :), i can even do a

foreach(WP7Process proc in Phone.TaskManager.AllProcesses())
{
proc.Kill(0 /*exit code*/ );
}

Well im currently on the process handling system, cant identify xap yet, need a way to get raw commandline arguments of current taskhost. The arguments passed to silverlight are way not the same as the raw commandline.

"or does it launch the previous app from scratch?", it just loads for a second and returns to home without showing an error.
 
  • Like
Reactions: Marvin_S

Marvin_S

Retired Recognized Developer
Dec 8, 2010
883
239
I can kill any task i want :), i can even do a

foreach(WP7Process proc in Phone.TaskManager.AllProcesses())
{
proc.Kill(0 /*exit code*/ );
}

Well im currently on the process handling system, cant identify xap yet, need a way to get raw commandline arguments of current taskhost. The arguments passed to silverlight are way not the same as the raw commandline.

"or does it launch the previous app from scratch?", it just loads for a second and returns to home without showing an error.


Instead of the app id which needs to be translated back to the appname is it not possible to make a screenshot of each app like joe belfiores app did and link them to these processes? Its not nescessary to list the app names, all you need is just a way to seperate one from the other.
Wheter you do this by the real appname or just a screenshot of a running task.

The taskswitcher can than work/look the same as the tabs in IE mobile of wp7. Hit x to kill and see if there is a way to get a screenshot for each running process
 
Last edited:

fiinix

Retired Recognized Developer
Oct 9, 2010
570
224
31
Stockholm
Instead of the app id which needs to be translated back to the appname is it not possible to make a screenshot of each app like joe belfiores app did and link them to these processes? Its not nescessary to list the app names, all you need is just a way to seperate one from the other.
Wheter you do this by the real appname or just a screenshot of a running task.

The taskswitcher can than work/look the same as the tabs in IE mobile of wp7. Hit x to kill and see if there is a way to get a screenshot for each running process
Did some research on it, may be possible:
http://www.developerfusion.com/code/1708/screen-capture-to-the-clipboard/

Not so high priority right now, need some core features to work.

Also, Joe Belfiores has full super root, lol.
 

Marvin_S

Retired Recognized Developer
Dec 8, 2010
883
239
Last edited:

Heathcliff74

Inactive Recognized Developer
Dec 1, 2010
1,646
2,610
"ShellExecuteEx @ coredll.dll" exists and ill register that.

ShellExecuteEx and CreateProcess will return errorcode 0xbf (or 0x800700bf) which means "INVALID_EXE_SIGNATURE" or "cannot run in Windows NT mode" or "Image could not be loaded for execution" or "Cannot run %1 in Win32 mode".

It's not really clear to me what the returncode means exactly. But I guess that it means that the app that calls this method is not properly signed (probably needs TCB signature).
 

Top Liked Posts

  • There are no posts matching your filters.
  • 27
    The DllImport Project

    This project is part "Real DllImport" and also not the same time. It has limited DllImport to only types "void();" (well isn't that DllImport :D)

    Other CORE functions that require multiple [IN] or/and [OUT] are to complex for the code right now (there are so many possibilities).


    Terms of use, using the code (free to use, under my name "fiinix00 @ XDA"~ in app)

    As posted to JaxBot :)
    Well thanks for asking, this project is free for everyone, the one purpose it was made for.
    The only thing i needed back is my name (fiinix @ XDA) included in whose projects (external) that take use of my code base. There is no licence or something (GNU e.g.), it just make people mad and confused.

    So feel free to take advantage of the code whenever you want, just remember, i want my name on it. =D



    UPDATE @ (2011y-03m-26d - 23:08)

    Ohyeah, i can control zune from my application (Resume, Stop, Pause, NextSong, PrevSong, ShutdownZune, StartZune, ... to come)

    Turn on/off radio remote from code. (DAMN, the radio begins to play without "No antenna" but no sound, plugin again and it sounds :/)


    UPDATE @ (2011-03-27 - 14:35)
    - Set clipboard (lol, doesent even have NODO): DllImportCaller.lib.Clipboard_SET("Hello");
    - Get clipboard: DllImportCaller.lib.Clipboard_GET(ref [string]);
    - Enchanted: Phone.Clipboard.Value { get { ... } set { ... } }
    - Basic calls against void without arguments: DllImportCaller.lib.VoidCall( [DLL] , [Method] );
    - API for verifying method existence: DllImportCaller.NativeMethodExists( [DLL] , [Method] );
    - Raw API for controlling vibrator (unlimited "on", also continues to vibrate on exit, dont forget to turn off :D): Phone.Vibrator. { Vibrate(), Stop() }


    Source code + test XAP updated (2011-03-27-17:38) (Clipboard GET; is corrupt)

    HELLO THERE TASKMANAGER!!
    (I can now enumerate the running processes on the phone :D)
    Proof: http://moitox.com/WP7tskMngr.png


    Hook to keyboard, for some reason it only show interest in the "Search" button.

    Documentation of proc:
    [WP7Process].{ CreationTime, ExitTime, KernelTime, UserTime, <-UpdateTimes(), Kill(exitCode), { PROCESSENTRY32 RAW } }

    ^ for "currentProcess.Kill()" use "Phone.TaskManager.GentlyExitCurrentProcess();" the Kill(exitCode) KILLS

    WP7Process[] = Phone.TaskManager.Named("taskhost");
    WP7Process = Phone.TaskManager.CurrentProcess();


    Documentation of network
    - ConnectionType { Unk0, Unk1, Unk2, Connected, Unk3 ... }
    - ConnectionType = Phone.Network.GetWirlessState;



    Phone.KeyboardHook.IsKeyDown(int key)
    > Search = 124 (lol)


    Misc finds

    DllImportCaller.NativeMethodExists("urlmon", "IsIntranetAvailable");
    DllImportCaller.NativeMethodExists("urlmon", "ObtainUserAgentString");

    - Code updated! (2011-03-28-22:12)


    Added "Phone.DEP", dep is a wrapper against info stored in "Microsoft.Phone.Info.DeviceExtendedProperties"

    Full "TaskHost.exe" support

    HostInformation = Phone.TaskHost.GetCurrenHostInfo();

    HostInformation {
    fDehydrating = 0,
    fRehydrated = 0,
    hHostWnd = -25821178 /* This silverlight managed window (host window) */
    szAppDataFolder = "\\Applications\\Data\\8DC5214E-88FA-4C2D-A379-2CD74FE24B72\\Data"
    szAppInstallFolder = "\\Applications\\Install\\8DC5214E-88FA-4C2D-A379-2CD74FE24B72\\Install"
    szAppIsolatedStorePath = "\\Applications\\Data\\8DC5214E-88FA-4C2D-A379-2CD74FE24B72\\Data\\IsolatedStore"
    szProductId = "{8DC5214E-88FA-4C2D-A379-2CD74FE24B72}"
    szTaskPage = "MainPage.xaml" /* Current page? */
    szUri = "app://8DC5214E-88FA-4C2D-A379-2CD74FE24B72/_default"
    ullLastInstanceId = 39 /* fully retarded property? */
    }

    Code updated! (2011-03-29-23:25)

    new Phone functionality

    Phone.OS.{ Shutdown(ewxCode) } /* 1.0.2 can still call it with "DllImportCaller.lib.ShutdownOS" (failed tho on mine in 1.0.2) */

    Added "GetLastError7" (C++ ::GetLastError()) for better C# side error handling.

    Code updated! (2011-04-03-12:37)


    Code updated! (2011-04-04-21:48)
    - App launcher code!!
    - Enchanted IO support
    - 1.0.6!

    Code updated! (2011-04-05-22:08)
    - Enchanted task support
    - Console7.Title { get; set; } etc.


    Code updated! (2011-04-08-00:03)
    - Stable%: 97 :/
    - Battery support (see battery info (CORE only))
    - Phone.Sound { MasterVolume!! { get; set; }, etc } (controlling phone master volume over all processes)
    - Phone.OS.Kernel.ResetDevice(); (instant stops kernel, instant shutdown, not recommended!)


    Code updated! (2011-04-09-22:39)
    - Enchanted "Phone.Battery" class
    - Phone.TaskManager.+GetCurrentProcessId
    - WiFi Controll! (On/Off) (from code!)
    - Bluetooth Controll! (On/Off) (from code here toe!)
    - Phone.OS.+GetSystemStartupItems(),+GetDesktopWindowHandle()
    - New class "Phone.Search."+SearchFor,+OpenSearch,+BindSearchButtonToPage (FAILS)
    - New class "Phone.XboxLive"+GetIsXboxLiveEnable,+GetIsSignedIn
    - Yep: 1.0.9!

    Code updated! (2011-04-17-22:01) //damn, not update in 8 days~
    - Phone.OS.OSLanguage { SubLanguageID, PrimaryLanguageID }
    - Phone.WP7Process.+ CurrentProcessID (int),+GetCurrentProcess() returns guaranteed the right taskhost @class_WP7Process
    - Improved Phone.OS.Memory
    - + Extra i don't remember :) (8 days)

    Code updated! (2011-05-22-21:25)
    - 1.2.1 (because 1.2 methods was commented out to set things right (less crash))
    - HUGE improvements
    - Removed unneeded **** to speed things up
    - Screenshot 161 ms per capture (non-save-to-gallery) =D
    - =D

    Mango support added(2011-10-26-19:30)
    - yep, "ATL" Mango compiled. I have not yet tested to run it on a NoDo.
    - Trying to implement a ASM virtual machine; example:
    Code:
    [ASMMethod(Dll = "coredll", EntryPoint = "GetLastError")]
    public delegate int GetLastError();
    
    var last = ASMGenerator.GenerateDelegateFor<GetLastError>();
    int code = last();

    Custom tile support added(2011-11-07-23:08)
    - Custom core tiles ftw!
    [/CODE]

    Source: Attatchment
    -Compile VS2008 folder with C++ compiler from WM6 SDK
    -Windows Mobile SDK 6 PRO
    -Visual Studio 2010 (+ WP7 Silverlight SDK)

    Test-app: Attatchment
    -Deploy
    -No need anymore to do a initialize button call, automatic called on first use in code "DllImportcaller.lib.cctor" by JIT (Net Framework just in time).
    -Do some tests from the scrolling list. (due there are more CORE back-code API's than buttons, all tests can not be tested).


    OLDER VERSIONS WILL BE DEPRECATED AND WILL BE REPLACED BY NEWER, MAX ATTACHMENTS IS 8.
    2
    Dumping this picture because it soooo wrong haha
    Corrupt code system ftw :p

    Also, i can create any type of tile (Wide tile shown in attachment)
    - TemplateType14

    Default is TemplateType5 = 5
    2
    Well, there we go. I did just shut down the phone with code (phone sided code)! :D

    DllImportCaller.lib.ShutdownOS();
    2
    Some new info for you guys.
    I think i have cracked the tile system, creating custom tiles, executing what ever you want.

    I extracted COM+ dll's from the system _itself_ that controls the managed shell-tile system, and instead of being controlled by MS restrictions (sandbox tile creation), i can create my own tiles (with what ever i want)

    Thats about it :)
    - Dont be to excited now, im not 100% it will work; if there are internal C++ checks too.

    edit: **** yar! 500'th post. Go XDA :p

    edit 2:
    CONFIRMED It works woah!
    Code:
    var tiles = HackedShellTile.ActiveTiles.ToArray();

    All tiles on the front screen has a token; DllImport Projects token is "CSharp___DllImportToken" with "/" as uri (normal launch; no "/?ebayProduct=1337")
    - CSharp___DllImportToken comes originality from WMAppManifest.xml (WP7 project) under xml:
    Code:
    <PrimaryToken TokenID="CSharp___DllImportToken" TaskName="_default">
    2
    Hi, first off thanks for your great work!

    I am referencing the CSharp___DllImport project in another project and when I run it I get a TargetInvocationException in Interop.cs for the following line:

    Code:
    return last = (uint)dynMethod.Invoke(null, new object[] { assemblyDLL, new Guid(guid) });

    Someone else in this thread had this problem before but there was no solution. Do you have an idea what I could do to fix that?

    Thanks!
    Have you copied all needed dll's and files localy to the specified project (Build Action: Content) ?

    Some of them (You can find them in the xap/rar):
    - WPInteropManifest.xml
    - DllImportMango.dll
    - Microsoft.Phone.InteropServices.dll

    And added "<Capability Name="ID_CAP_INTEROPSERVICES" />"?