Clan x86

Technical (Development, Security, etc.) => General Programming => Topic started by: Blaze on September 05, 2005, 07:48:26 pm

Title: File Packing
Post by: Blaze on September 05, 2005, 07:48:26 pm
How does file packing work? I've searched google and haven't found anything other then SP2 fixes :-\.

I'm working on a project similiar to winzip/rar for the fun/experience and I'm wondering if its amazingly difficult or not..
Title: Re: File Packing
Post by: Newby on September 05, 2005, 07:59:07 pm
Check out this (http://en.wikipedia.org/wiki/Data_compression) document. It might help you.
Title: Re: File Packing
Post by: Joe on September 05, 2005, 08:14:38 pm
I wrote a little packing thing called JoPaQ (ripped from MoPaQ (MPQ)) once. It was pretty simple.

(DWORD) Number of Files
For each file {
  (DWORD) Name Length (word?)
  (VOID) File Name
  (DWORD) File Length (might want to make this a qword, whatever)
  (VOID) File Data
}

The DWORD+VOID combination is somewhat of a pascal string. I still have the code laying arround somewhere, although it never really worked.
Title: Re: File Packing
Post by: iago on September 06, 2005, 03:22:02 pm
google://huffman encoding

Huffman encoding is compression, not packing, but I assume that's what you're looking for. 
Title: Re: File Packing
Post by: Koga73 on September 14, 2005, 10:26:58 pm
Well, if your looking for a packer (itll recude the size of exes, works great, the exe will still run normally once packed), look up a program called UPX or ProcDump. And as for file compression, search for RLE, run length encryption. It works good for files with lots of repeats, such as:

111111111123456
becomes
10~123456

simple
Title: Re: File Packing
Post by: Blaze on September 14, 2005, 10:36:05 pm
...?
Title: Re: File Packing
Post by: Koga73 on September 14, 2005, 10:51:55 pm
ok, you read the binary of a file your wanting to compress. Then, you look for areas that have 4 or more of the same character all next to each other, so lets say you load it in as binary, and you see the following:

abcddddddddefghhhhijklmnnnnnnopqrstuvwxyzzzzzz

Well, using rle, you would make it:

abc8~defg4~hijklm6~nopqrstuvwxy6~z

It reduced the size from 47 characters to 34.

So, now, save the file as a .BLZ or something, lol. Then, to make the file usable again... go thro, and reexpand all the stuff you compressed.

Thats for the compression part, as for packing files and making a bunch of files into one... just take each individual files biary, and put it all into one file. The depacker will just rebreak it apart into many files.
Title: Re: File Packing
Post by: Blaze on September 15, 2005, 12:04:33 am
I  understood what you orginally posted..  :-[

I was just wondering why you were suggesting I use another program.  I also don't think rle is very realalistic for using on excutable.
Title: Re: File Packing
Post by: Sidoh on September 15, 2005, 12:51:19 am
I also don't think rle is very realalistic for using on excutable.

It's not.
Title: Re: File Packing
Post by: Koga73 on September 20, 2005, 03:33:49 pm
i just figured id mention some exe compressors, there pretty cool. They can comperss an exe, and the exe can still run perfectly without havign to be decompressed. How do these work?

UPX and ProcDump are some examples.
Title: Re: File Packing
Post by: Sidoh on September 20, 2005, 06:05:12 pm
i just figured id mention some exe compressors, there pretty cool. They can comperss an exe, and the exe can still run perfectly without havign to be decompressed. How do these work?

UPX and ProcDump are some examples.

I suppose it would depend on the operating system.  If it had a feature that detected and decrompressed the file data on the fly when it detected it was compressed, that would work.  Test the execution speeds of the same programs compressed and un-compressed and see if they're around the same.
Title: Re: File Packing
Post by: iago on September 20, 2005, 08:49:34 pm
i just figured id mention some exe compressors, there pretty cool. They can comperss an exe, and the exe can still run perfectly without havign to be decompressed. How do these work?

UPX and ProcDump are some examples.

I suppose it would depend on the operating system.  If it had a feature that detected and decrompressed the file data on the fly when it detected it was compressed, that would work.  Test the execution speeds of the same programs compressed and un-compressed and see if they're around the same.

Generally, they're uncompressed when they're loaded.  So the load time will be slightly higher, but the overall run time will be mostly the same. 
Title: Re: File Packing
Post by: rabbit on September 20, 2005, 09:28:21 pm
Yep.  The file is compressed into itself with instructions of how to decompress the file when it runs, then run it (instead of just running).  I love UPX :P
Title: Re: File Packing
Post by: Sidoh on September 20, 2005, 10:44:43 pm
Generally, they're uncompressed when they're loaded.  So the load time will be slightly higher, but the overall run time will be mostly the same. 
Sorry, that's what I meant.