From: Rik Hemsley Date: 2002-04-17T01:31:16+09:00 Subject: Re: crypting ruby source #if Jim Freeze > I think this is a good idea for some situations, especially > as you mention above for storing data. > And, I can't imagine this being too terribly difficult to implement. > > If I was implementing this I would do it as follows: > 1. Write a controller in c. Granted, this is the weak part > of the system, but unless there is internal cooperation from the > ruby parser and encrypting of the AST's, then, as far as code > is concerned, the security if through obscurity. > > 2. Write a special require module (in c) that decrypts its source. > > 3. Use the c controller to load the encrypted ruby code, decrypt > the require'd modules and run as normal. > > Again, the reason for the c controller is so that it is not trivial > to insert a watch point to read the code after it is un-encrypted. Something like this, perhaps. (Write 'decrypt' in C): -------------------------------- def crypt code [ code ].pack("m") end def decrypt buf buf.unpack("m").to_s end module Kernel alias oldload load def load(aFileName, wrap=false) if (aFileName =~ /.rx$/) puts "Loading encrypted file" File.open(aFileName) { |f| eval decrypt(f.read) } else oldload(aFileName, wrap) end end end load 'test.rx' ------------------------------ Quite lame, but I don't care :) Rik