[Mono-dev] My findings about PocketPC/Compact Framework apps.

Corwin Light-Williams mess at thethirdman.org
Tue Dec 6 17:35:22 EST 2005

I've perused the lists and bugzilla, and this topic comes up every  
now and then- sorry to rehash it.

I want to target .NET Compact Framework 2.0 on Windows Mobile 5,  
using mono as my compiler. If you simply compile an app using mcs/ 
gmcs on the command line, it doesn't work. Fine, I maybe expected  
that. So I decompiled it using Microsoft's ildasm- the output was  
fine. I then recompiled it using Microsoft's ilasm, and it worked! I  
deduced (as others have) that it must be in the PEFile part of the app.

So I compiled a version of Mono's ilasm, using GMCS and the 2.0 gac,  
and lo and behold, I can do the same thing I did with Microsoft's  
tools- disassemble and reassemble, and generate an app that runs on  
PocketPC. Except ilasm doesn't seem to link DLLs properly, or maybe  
my patched build was wrong- I could make an app that linked against  
system libraries work, but not an app that links against the .NETCF's  
System.Windows.Forms.dll. Damn.

So a little poking around reveals that gmcs and ilasm use two  
different PEFile writers- ilasm uses PEAPI.PEFile, whereas gmcs uses  
the C stuff, natively referenced through System.Reflection.Emit. Aha!

I then made 4 different EXE files, from the same source.

- One compiled using gmcs.
- One compiled using csc.
- One compiled using Microsoft ILASM to compile a decompiled EXE.
- One compiled using Mono ILASM to compile a decompiled EXE.

They all are slightly different- a byte here and there. But guess  
what gmcs had different that the latter three had all in common?  
Here's GMCS's text section:

CLI Header
-> ImportTables
-> EntryPoint
Strings, Guid, Blob, etc

Here's what the other three have:

CLI Header
Strings, Guid, Blob, etc
-> ImportTables
-> EntryPoint

So I patched reflection.c to place the ImportTables a little later,  
which still (to my surprise) generated an app that ran on Windows.  
When I took it to the PocketPC, sure enough, it ran without complaint  
or crash, although sadly it did nothing.

I feel like I'm close here, and I'm wondering if anyone has any  
comments or help.

Thanks for reading a long message!


More information about the Mono-devel-list mailing list