How Not To Code, part 7

For general and site related discussion.

Moderators: XtC, BuZz

Post Reply
kyz
Posts: 126
Joined: Thu Nov 14, 2002 1:58 am
Location: Edinburgh, Scotland
Contact:

How Not To Code, part 7

Post by kyz »

As you may know, I have a utility called ppcrack which decrypts any PowerPacker file in 20 minutes without the password.

However, it was failing on larger files. Why?

It turns out that PowerPacker's "encryptor", if told to encrypt more than 262144 bytes of data, will actually encrypt roughly <x mod 262144> bytes of data instead!

So, if your PowerPacked file is 262148 bytes long, only 4 bytes of that will be encrypted, the rest will be unencrypted! Isn't that wonderful?

Why does this happen? Let's look at the ppEncrypt function:

Code: Select all

; A0=buffer to encrypt, D0=length to encrypt, D1=encrypt key
ppEncrypt:
        addq.l  #3,d0
        lsr.l   #2,d0
        subq.l  #1,d0
1$      eor.l   d1,(a0)+
        dbra    d0,1$
        rts
What's wrong with this picture? The DBRA instruction only cares about the lower 16 bits of D0! Any bits higher than that are just ignored.

You might think this makes the encryption easier... it actually makes it more difficult. PowerPacked data starts at the end of the file, and must start with a 1 bit. If that section is encrypted, I can guess one of the bits of the key straight away, halving the time required to find the key. If it's not encrypted (due to this bug), I have to guess all the bits. Bah!

Post Reply