PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

WinCE PE Compactor?

I have been using UPX for my different projects on the PC for the past few years. Now that I have a project for the PocketPC I would like to compact the .exe the same way.

Are there any tools that will do this for the PocketPC executable files?

If not, anyone would be interested in allowing UPX to support WinCE's PE? The source codes for UPX are available.
this would probably be a waste of time for a few reasons

1) most exes are already very small, store your data outside of your exe
2) evc does a great job of compacting exes, much better than vs
3) ce file systems use an on the fly built in compression system, so your actual disk/memory savings using a compactor will be much less than the reduced file size (at least i think they do)
Regarding #3, that's correct.

Dan East
Dan East wrote:Regarding #3, that's correct.

Dan East

Yes,

the internal object storage is compressed by a weak compression algorithm.
Not the data on SD cards, CF- cards or the internal flashdisk (mostly FAT16/32).

Frank
www.WinCESoft.de
I was talking about compressing the .exe using a compression algorythm that uncompresses it at load time into memory. A 600k .exe can be compressed to 170k easily with a good compression, and when you run it, it is uncompressed to memory and ran.

Take a look at Upx.
I was talking about compressing the .exe using a compression algorythm that uncompresses it at load time into memory.

I think you missed the point of the other posts. This is what happens already. If you use UPX along with it then the UPX'd exe will be compressed by the OS. This means that you're likely making the UPX'd executable larger (a crap compression system compressing a compressed block will suffer badly) and decompressing it twice - once from the OS and once from UPX.

In short: yuck.
This was discussed a number of years ago here at PM. I'm pretty sure I posted the results of some informal testing regarding this compression. zlib can make files smaller than they would be otherwise, because the OS uses a faster / less efficient algorithm.

Dan East
I tried searching for my post that showed how much files were compressed by the OS, but all I found was this:
http://www.pocketmatrix.com/forums/viewtopic.php?t=5898

Dan East
I looked at virtually every PE compressor at one point a while back and turned up nothing... So, I suspect you'll be writing your own (or updating UPX or similar) yourself.

It should be noted that *compression* might not be the goal here, as it frankly was not for me... Back in the pre-Windows days, there was a considerable amount you could do to make an EXE very difficult on crackers... Similar tricks can be played with PE's, although perhaps not quite as successfully.

A great story I have about this (well, great to me anyway)... when I took my Assembly class some years ago, our final was to create a program that the teacher could not crack... it was a simple program... enter a password and have a message displayed... it had to be self-contained, and so contain the password itself, and there could be only one real password... he was exceptionally good at defeating all sorts of executable protection schemes (one might ask why he was so good, and why he felt this made a good final project, but I digress)... in something like 20 years of teaching, he never had a student present him something he couldn't crack in under a week (had a couple that took a few days, most were a few hours at most)... until he met me... I coded the program in about the most obtuse and crazy ways I could think of so that even if he had the actual source in front of him it would be tough to figure out the password... THEN I ran it through 6 different EXE encryptors, compressors, etc. The end result is that it took him something like EIGHT MONTHS to finally crack it, and it was only after figuring out what I had done (and after my A in the class was long since in the books!). Incidentally, it took him 9 hours he said AFTER he got it to a completely unprotected form, so my obtusde coding would have earned me an A anyway!
@fzammetti:
Nice story :)
I do remember there were a bunch of generic executable unpackers
(one of them beeing called cup386) which were pretty good in unpacking all those funny executable crunchers.
Some of them even emulated x86 machine code to step through the anti-debugging code ;)

fzammetti wrote:It should be noted that *compression* might not be the goal here, as it frankly was not for me... Back in the pre-Windows days, there was a considerable amount you could do to make an EXE very difficult on crackers... Similar tricks can be played with PE's, although perhaps not quite as successfully.

This is actually one of the most important advantages of a PE-compressor.
It's not so much about saving space it's more about protection and the proof-of-concept :D
Okay back in the DOS-days you could do even worse stuff by hooking the single-step/breakpoint interrupts and stuff like that but I'm sure similar stuff can be done on ARM to prevent remote-debugging.

A friend of mine once wrote a PE-cruncher for Win95/NT and he already played around with his own WinCE PE-Loading framework but due to lack of time he stopped working on it, but he got pretty far already so it's definitely possible.
Some time ago I was working on a packer+cryptor+protector for WinCE. But due to a lack of time it was never finished. The latest alpha version is here - http://mamaich.kasone.com/wz/protector.rar
to use it - extract archive to your PC, and run:
Protector.exe infile outfile
It supports DLLs and EXE-files, can compress resources, import and export tables, has some primitive anti-debugger techniques. This version displayes an nag-screen and the protected program terminates after some time. It supports WM2003/2003SE/2005 OSes. 2002 and older were not tested but should work. Only ARM-based CPUs are supported.
Thanks guys for replies,

But I still don't understand how WinCE compresses .exe's when an .exe file on my desktop PC is 613k and once transfered to my PPC it's still 613k on my cf card?

I am trying to figure out what compression you are talking about, I see none.
IIRC, it's transparent compression, like software compression on the desktop... if won't tell you what the compressed size is, it'll still report the "real" size... although you can see both on the desktop, I guess you can't (without some 3rd-party tool any) on a PPC.

That's my recollection anyway... anyone else remember for certain?
It doesn't compress files on removable media - only stuff in the internal storage memory.

The file will of course report its uncompressed size. You can see the actual space consumed by comparing the drive free space with and without the file.

Dan East
Ok thanks, it's clearer now. Makes a lot of sense.
mamaich wrote:Some time ago I was working on a packer+cryptor+protector for WinCE.


very interesting - I planned to do something similar myself as a proof of concept for another protection scheme. Tell me if it gets updated or open sourced some day :D
diProtector · 15 Dec 2005, 10:01 UTC
Try diProtector - software protection against reverse engineering on different platforms for PDA developers (http://www.diprotector.com)
joshbu [MSFT] · 20 Dec 2005, 18:55 UTC
RE: Windows CE file system compression.

Windows CE supports 3 different 'compression' schemes (NONE, XPRESS, and LZX.) Each is a trade-off between decompression speed and compression rate. It's possible to use different schemes on different paritions within the flash, but usually things break down thus:

If the device has NOR flash, we recommend NONE for non-pageable code paritions (so they can XIP,) and possibly XPRESS for other code paritions or maybe still NONE if there is sufficent flash. If the OEM uses NONE all throughout, the entire OS can XIP, in which case there is no page pool, resulting in megabytes of RAM savings against a modest hit in code fetch time.

If the device has NAND flash (and most new ones do,) then compression is highly recommended, as you must block fetch for the flash part anyways.

Now, this really only applies to the OS paritions. I'm not really aware of anyone using compression on the user store parition, or on SD storage. I'll have to check to see if code executing from those paritions is even pageable.

I guess what I'm saying is don't rule out compaction because of the OS. On NAND espicaly, when data fetch is slower, there could be a load time advantage to be had.
It should be noted that a classic packer is different, and has a different purpose usually, than OS-level file system compression.

The way packers work (or at least did last time I wrote one) is to take an executable, and basically encode the entire thing in some fashion (whether compressed, encrypted or both) and then put a "wrapper" executable around that which knows how to decompress the real executable.

I've never dealt with one on any version of Windows, my experience was all back in the DOS days (and the C64 days before that). There, it was pretty easy to do... once you compressed the real executable, your "decompaction" routine would just reverse the process and place the real executable into memory at an appropriate location (like DecompactionRoutineLength+1) and jump to the first instruction. I'm not sure how you do the same thing with a Windows PE, be it desktop or not, but the theory has to be essentially the same.

File system compression on the other hand... wait, it actually is the SAME THING, its just that the decompaction routine is built into the OS. As well as the compaction routine, and both are done on-the-fly.

Still, usually different goals though. Classic compactors were more about obfuscation than space saving. :)
diProtector · 08 Feb 2006, 19:09 UTC
New version of diPacker released! Best price - only $24 !

Version 1.2 18th January 2006.
Bug fix: Access violation on 2003SE platforms on startup.
Bug fix: incorrect handling of PE-file resource section;
Minor bug fixes.

http://www.diprotector.com/products.htm
When can we expect a PC version of this cool software?

Btw, is it compatible with WM2005 too?
diProtector · 08 Feb 2006, 19:23 UTC
When can we expect a PC version of this cool software?


kornalius, it'll be available at summer'06

Btw, is it compatible with WM2005 too?


yes, of course.
diProtector wrote:
Btw, is it compatible with WM2005 too?


yes, of course.
And you are wrong. Like previous versions it does not compress WM5 native executables (THUMB).
As usual it cannot compress some programs (HaaliReader for example). It just crashes. And it crashed an all programs that I've tried.

You should test your "packer" before making announcements.
kornalius wrote:When can we expect a PC version of this cool software?
There are lots of better packers for PC, for example UPX (and it is open-source). Or AsPack/AsProtect (I recommend it).
diProtector · 10 Feb 2006, 07:40 UTC
And you are wrong. Like previous versions it does not compress WM5 native executables (THUMB).


It's not a bug, diProtector doesn't support old THUMB executables. Furthermore - I've never seen such executables many years. If you wish - I can add support for THUMB.

As usual it cannot compress some programs (HaaliReader for example). It just crashes. And it crashed an all programs that I've tried.


Can you tell me the versions of crashed software? I've tested with Haali's executable (reader.exe) version 2.0b243 - it works excellent.

There are lots of better packers for PC, for example UPX (and it is open-source). Or AsPack/AsProtect (I recommend it).


You're right. There are too much alternatives for PC. I don't know why you recommend Asprotector (I'll try to guess :), but there is too much "aspack die" and aspr stripper" results in google.
diProtector wrote:... Furthermore - I've never seen such executables many years. If you wish - I can add support for THUMB.
THUMB is native format for WM5 executables. And you should upgrade your protection for such files, because soon there would be more programs designed specially for WM5. You can test protector on WM5 emulator from VisualStudio 2005.
...
Can you tell me the versions of crashed software? I've tested with Haali's executable (reader.exe) version 2.0b243 - it works excellent.
I'll PM you the files that I was unable to compress.

You're right. There are too much alternatives for PC. I don't know why you recommend Asprotector (I'll try to guess :), but there is too much "aspack die" and aspr stripper" results in google.
I've recommended ASPR because it has lots of great features that should be implemented in a good protection. A well-used ASPR cannot be removed with any automatic tool, you'll still need some manual hacking. And of cause you'll need a valid serial number (even a blacklisted is enough). ASPR is just too popular and there are lots of tools that assist in its removing.
There are better protections, for example I like the idea of vmprotect (it is freeware by the way) or star-force (too hard to crack and with a high price), but they are harder to use or have compatibility problems.

Rebember - "If it runs, it can be defeated" (c) +ORC
The more would be the popularity of a protected program - the quicker it would be released by a warez group.
diProtector · 12 Feb 2006, 07:44 UTC
THUMB is native format for WM5 executables


Very interesting. I've always thinking that "THUMB" is an old 16-bit mode of the ARM processor. Can you give me please a link to THUMB format for WM5?

I'll PM you the files that I was unable to compress.


I'm waiting impatiently...
diProtector wrote:Very interesting. I've always thinking that "THUMB" is an old 16-bit mode of the ARM processor. Can you give me please a link to THUMB format for WM5?
WM5 uses ARM/THUMB mix of code. It uses THUMB in places where speed is not necessary to make image size smaller (though I've never seen it being used). Normally all EXE files use ARM instruction set, but you can instruct VC to compile some function as thumb. Only minor changes in your packer code would be necessary to support this.

I've attached the files I've tested.
THUMB directory contains WM5 native executables - Pocket Excel and a test program.
ARM - CAMERA.EXE and IA_Zip.EXE from my device. They compress normally but are not working at all. Camera is device-specific, ZIP should work everywhere

I've probably found why your program crashes. Last time I've executed it from SD-card which had too few free space left
Attachments:
here.rar (903 KB)
UPX is now updated to compress WinCE excecutables. Currently it can compress WM2003[se] apps without problems, WM5 apps can be compressed after some manual hacking.
mamaich wrote:UPX is now updated to compress WinCE excecutables. Currently it can compress WM2003[se] apps without problems,

Really-really without any problems?

Btw,
http://upx.sourceforge.net/#unstable wrote:All versions 1.1x and 1.9x are unstable beta releases - use them only for testing, and never distribute a program that is packed with them! There are known bugs.

The current stable release is 1.25, and the next stable release will be called version 2.00.
jaguard wrote:Really-really without any problems?
UPX has minor problems, that can be fixed by manual editing of PE-file (for example when it reports section size error).
And most of its versions above 1.25 should be considered very stable.
V 1.94 compressed all my executables which DiPacker just broke. And they run fine. I have not looked into its sources, but I can recommend a well-known UPX instead of DiPacker.