Thursday, 1 October 2009

Obfuscating

Low-level security is often needed in a compiled app.
Things like hiding a secret string from the casual hacker with a hex-editor.

When the pro edition of RB of allowed me to use IDEScripts, I had a simple script that changed the currently selected code to a series of chr() functions.

Recently, I found a need for a similar facility but I don't have REAL Studio. So I decided to write the beginnings of a standalone app whose purpose is to allow me to generate useful bits of code to paste into the source I am currently developing.

Under these circumstances, I was able to do a slightly more thorough job of hiding the string and making it more difficult for future enhancements to the compiler to optimise my code away.

The general idea is that I give the helper app my password and from it, the code produces a new function with a meaningless name and no reference to the original string.

In the main app, this function uses a MemoryBlock to convert integers in random sequence to a Base64Encoded string representing the password. The function then returns the Base64Decoded version of the string.

I've uploaded the source as part of code.google.com/rbjottings where the whole set of snippets can be downloaded by SVN or you can look at the source for these routines at obfuscateTest Window1 because all the code is contained in that window.

The methods involved are

Function generator _
(inText As String, ByRef functionName As String) As String
Function randomIdentifier _
(minLength As Integer = 6, maxLength As Integer = 10) As String
which are called using code like
dim fName As String
taCode.Text = generator( tfPlainText.Text, fName )
if chkAddcaller.Value Then
taCode.Text = taCode.Text + EndOfLine + EndOfLine + _
"Sub Caller() " +EndOfLine + _
" Dim s as String = " + fName + "()" + EndOfLine + _
"End Sub"
end if
where taCode is a TextArea and tfPlainText is a TextField

Obviously this simple obfuscation is completely useless where real encryption is required.

However, where the aim is merely to hide slightly sensitive information from prying eyes, this will force them to work much harder to find the string.

Sunday, 26 July 2009

How can I help improve RB?

When I was developing large apps for other people to use, one of my recurring nightmares was that old bugs, once fixed, would return in a future version and make me look unprofessional.

Consequently, one of my most important tools was an ever-growing suite of test scenarios which I ran my app through before issuing a new release. I also asked my beta testers to run these scenarios where practical.

It seems to me that if my app were a programming language, this sort of suite would be particularly easy to produce.
No doubt RS have an extensive testing suite but they don't make it public for users to test. Also, I sometimes wonder if they share my nightmare.

I keep wondering about starting an open-source project which would host tests of current and previous bugs.

  • Have I the time and enthusiasm to produce the original framework?
  • Do I know enough about the current bugs?
  • Would someone else be more appropriate as the project owner?

Of course, there was Joe Strout's excellent ROTOR which ran several tests that could be automated and which many of us ran on each new beta and release for a while but those tests all seem to pretty much pass these days (except the encoding of external files) and it has fallen out of sight.

My preference now would be for something that runs unit tests where possible but which also includes tests which required user-involvement.
There would be a project (or projects) with windows describing what the user needed to do and what result was being looked for.
This would allow tests to be run on as many platforms as possible by beta testers, new users and anyone who starts using the latest version.

Hopefully, if there were user reports quoting problems found by the testing suite, RS would be able to check it out for themselves.

It seems to me that this would be a more positive step than just producing a list of bugs.

Perhaps I'll manage to get this started at some point. Or perhaps someone else will come up with the idea and the enthusiasm first and run with it.

Sunday, 8 February 2009

Editfields that update each other

I've been creating a number of EditFields lately where the TextChange event of each updates all the others.

I pretty soon got fed up with wrapping every bit of update code in "alreadyUpdating" flags, so I decided to create a simple EditField subclass with a Changed event that only fires if the EditField has the focus.

As I thought this might be useful for others, I've put a sample project on my website. it uses the subclass to allow entry of hex, binary or decimal numbers, while the two other fields are updated.

I've also added the source to the SVN repository at Google Code.