Protect Ruby code - ruby

I'm writing Ruby app and I want to use some top-secret algorithms. So how would be the best to protect them from unauthorized access.
I have 2 ideas:
write them in C and load using FFI (I wonder if It's possible this way)
Marshal ruby code, encode it and then store in file
Maybe someone know better idea or can show me that these ideas are stupid or wrong. Thanks in advice.

You cannot protect the algorithm you are writing by changing it to C .. May be you can encrypt the source files. Try truecrypt
Edit
After some googling i found these articles related to ruby code obfuscation
protecting-your-ruby-source-code-for-end-user-applications/
Ruby Encoder Protects Source Code for US Department of Defense Project
http://rubyencoder.com/

You can try some code obfuscation techniques. For example RubyEncoder compiles Ruby source code into a encrypted bytecode format. And here is another thread related to your question Ruby obfuscator

If you are willing to craft your own solution instead of buying and already made one like RubyEncoder, as stated on other answer here, there is an article that try to describe a method to protect your source code, and you can also implement all sort of protection you think is feasible, as you are going to do all by hand:
http://mountcastle.posterous.com/protecting-your-ruby-source-code-for-end-user

Related

Wanting to make an Xposed module

So I'm wanting to make an xposed module but cannot find any good video tutorials out there let alone an updated one also I know C# Decently and hardly any Java... Any help to help me get started would be appreciated. Thanks
You will need Java to create any Xposed modules. Android itself is based on (primarily) Java, so you will need Java knowledge to make Xposed modules.
That said, C# and Java are extremely similar languages, and you can quickly pick up the other if you know one.
As for Tutorials, Rovo89 (the creator of Xposed) has a simple tutorial here at https://github.com/rovo89/XposedBridge/wiki/Development-tutorial. This tutorial is almost completely upto-date, and you can use this to create your first module.
You will find another detailed tutorial here - https://forum.xda-developers.com/showthread.php?t=2709324. Keep in mind that this link is very old, so wherever there are any conflicts, go by Rovo89's tutorial.
After going through the beginner tutorial mentioned by Akhil, you will want to look at the API docs http://api.xposed.info/reference/packages.html and read through source code of some huge modules like GravityBox to get an idea of how the Framework is used. For teaching purpose mod some app which is open source and then move on to closed source app by reverse engineering them. For reverse engineering I use ByteCodeViewer.

Create WordPress plugins using Ruby

I would like to create a WordPress plugin using Ruby (language). I understand that PHP is the primary server-side language used with WP. I don't know PHP, but know a great deal about Ruby, which is also a server-side language. Can anybody help?
based on previous experience and some reviews of similar questions on SO, there are ways you can call Ruby from within your Wordpress code. The simplest and elegant solution I've seen to this is here : http://code.tutsplus.com/tutorials/build-a-custom-api-to-connect-wordpress-with-ruby-on-rails--cms-21189
There are loads of arguments for going with both solutions at the same time, but probably the easiest read is this https://bernardic.ca/2012/07/08/rails-vs-wordpress/
Enjoy!

Extracting source code from a document for testing

I wrote tutorials for some Ruby gems I wrote. It is in markdown (Kramdown) text document. To ensure the integrity of the source code in the tutorials as the development of the gems continue I want to extract the source code from the tutorial document and run test to ensure the code is correct and working. Before reinventing the wheel I searched but found nothing on this kind of problem. Is there any software that can help me solve my problem? Ruby software would be cool but I'm not particular about the language. I'm sure I can't be the first person to encounter this problem.
The other option is to only have place holders in the tutorial documents and have all the files externally en then populate the document prior to publishing. This would mean a lot more loose files but would be significantly easier to implement.
Org mode in emacs can do that, but it means you can't write in Markdown.
Are you after something like Ruby DocTest?

Ruby source code analyzer (something like pylint)

Does Ruby have any tools along the lines of pylint for analyzing source code for errors and simple coding standards?
It would be nice if it could be integrated with cruisecontrolrb for continuous integration.
Or does everyone write such good tests that they don't need source code checkers!
I reviewed a bunch of Ruby tools that are available here
http://devver.wordpress.com/2008/10/03/ruby-tools-roundup/
most of the tools were mentioned by webmat, but if you want more information I go pretty in depth with examples.
I also highly recommend using Metric-Fu it gives you a on gem/plugin install of 3 of the more popular tools and is built with cruisecontrolrb integration in mind.
The creator has a great post that should help get you up and running in no time.
http://jakescruggs.blogspot.com/2008/04/dead-simple-rails-metrics-with-metricfu.html
There has been a lot of activity in Ruby tools lately which I think is a good sign of a growing and maturing language.
Check these out:
on Ruby Inside, an article presenting Towelie, Flay and Simian, all tools to find code duplication
Towelie
flay
Simian (a more general tool that supports Ruby among other languages)
reek: a code smell detector for Ruby
Roodi: checks the style of your Ruby code
flog: a code complexity analyzer
rcov: will give you a C0 (if I remember correctly) code coverage analysis. But be careful though. 100% coverage is very costly and doesn't mean perfect code.
heckle: changes your code in subtle manners and runs your test suite to see if it catches it. Brutal :-)
Since they're all command-line tools they can all be integrated simply as cc.rb tasks. Just whip out your regex skillz to pick the important part of the output.
I recommend you first try them out by hand to see if they play well with your codebase and if you like the info they give you. Once you find a few that give you value, then spend time integrating them in your cc.
One recently-updated interesting-looking tool is Ruby Object Oriented Design Inferometer - roodi for short. It's at v1.3.0, so I'm guessing it's fairly mature.
I haven't tried it myself, because my code is of course already beyond reproach (hah).
As for test coverage (oh dear, I haven't tried this one either) there's rcov
Also (look, I am definitely going to try some of these today. One at least) you might care to take a look at flog and flay for another style checker and a refactoring candidate finder.
There's also the built-in warnings you can enable with a quick:
ruby -w
Or setting the global variable $VERBOSE to true at any point.
Code metrics on ruby toolbox website.
Rubocop is a widely-used static code analyzer.
I just released Excellent which implements several checks on Ruby code. It combines roodi, reek and flog and also adds some Rails specific checks:
gem sources -a http://gems.github.com
sudo gem install simplabs-excellent
May be helpful...

A couple of questions on the architecture of Ruby

I am primarily a fluent .NET developer (as can be seen from the amount of posts and threads I make about .NET), but I thought it would be good to learn RoR.
In doing so, I have a few questions about the architecture of the language (Ruby) and the framework (RoR):
1) In .NET, every object is derived from System but inherits System.Object. So when I type System., I get a list of namespaces and then in those namespaces, classes and more namespaces.
Does Ruby not have this sort of hierarchy?
2) In some cases, I don't get the intellisense. For example, I wrote the class as outlined here (http://wiki.rubyonrails.org/rails/pages/HowToSendEmailsWithActionMailer) but in the line recipients user.email, nothing comes up when I type "user.".
Any idea why?
Thank
Dave Thomas (Pragmatic Programmers) has an excellent screencast series on the Ruby object model/metaprogramming. We watched this in a local Ruby user's group. The series isn't free, but it's not expensive either. You might want to check out the free preview to see if you think it is worth your time.
And to give you an answer. Yes, everything in Ruby derives from Object. You can find the docs on this at http://corelib.rubyonrails.org/. Look for the Object class.
I'm not sure why you aren't getting intellisense, partly because you haven't specified your IDE. It's possible that you can't because you've added the method dynamically and no intellisense is available.
If we compare .NET to Rails then yes, there is this kind of hierarchy there. And in general, you can achieve this kind of hierarchy in any Ruby application via using modules.
I guess it's because of Ruby's dynamic nature.
Ruby is a pure OO language meaning that everything from classes to objects derive from the Object class.
Download NetBeans. There is full intellisense support for Ruby and Ruby on Rails.
http://www.netbeans.org/features/ruby/index.html
Intellisense support probably won't get you what you think it will get you. Because Ruby is a dynamic language, Intellisense, or code completion, is difficult. What you will find is that either the drop down is so flooded with possible completions as to be useless. Or in your case nothing at all.
It's not 100% useless, but I have never found it terribly valuable.

Resources