Re: LZ: Self Encrypting Programs


Re: LZ: Self Encrypting Programs

Having a run-time self encrypting program is fun and easy!  

The only part of the code that isn't encrypted is a small loader at the 
begining.  All it does is go through the whole program and XOR it with a 
byte stored in memory.  Because you are XORing, the procedure to decrypt 
and encrypt are the same.  There should'nt be any complications with 
ZShell as long as you set the checksum update bit and everything.  The 
loop to do this is really small, you'll probably only add about just over 
20 bytes or so.  The only problem is that unlike a PC program, where you 
just have to decrypt and not worry about it because you are only 
decrypting the copy in memory and not the one on the disk.  You can't 
just do this on the 85 because the copy in memory is the only copy you 
have.  A simple fix for this is to have a second byte in the unencrypted 
loader that is a flag as to weither the program is currently encrypted or 
not.  Then if the program is killed for some reason (which really 
shouldn't happen in the 85 enviroment) then if run again, it will still 
work properlly.  Another improvement that is so easy that it is worth 
doing is to have it change the encryption byte that it uses to XOR after 
everytime you decrypt.  This is ok, as long as you change it only when 
the program is decrypted and you use the same one to decrypt as you 
encrypted with.  If you want to get fancy you can use multi-byte keys, 
but that's kinda a waste.  Just remember to re-encrypt the program 
before you exit, otherwise it won't work correctly.  Anyway, hope this helps.

This is the word of Site, the site of sites.