2

I was wondering if there is any tool or script for renaming all variables and method/function names in a piece of code (id specially be interested in one for java code, but recommendation for other languages are welcome).

I basically do not like to post my code in the web (stack overflow, forums, etc) with the original variable/method names (maybe I am too paranoid =D) and I would like to avoid to change them manually and possibly have some inconsistencies.

So I would be interested in something that does the whole re-factoring in a batch (all variables and all function names) and that I can apply just to a piece of code (I do not want/need to apply to the whole file)

I looked a bit around for it but could not find any (maybe I've been using the wrong keywords)

Abhishek kumar
  • 2,586
  • 5
  • 32
  • 38
Thomas
  • 2,751
  • 5
  • 31
  • 52
  • The big Java IDEs (NetBeans, IntelliJ IDEA, Eclipse) can do refactoring and can change your variable and method names. – Carsten Nov 15 '12 at 12:05
  • You could write your own tool using [LTK](http://www.eclipse.org/articles/Article-LTK/ltk.html). See [this](http://stackoverflow.com/questions/9129689/is-there-any-eclipse-refactoring-api-that-i-can-call-programmatically) – ShyJ Nov 15 '12 at 12:25

2 Answers2

1

What you are looking for is actually an obfuscation tool, which makes it more difficult for someone to de-compile and analyze your code once it's distributed.

Take a look at ProGuard (StackOverflow), which is used for minimizing and obfuscating compiled Java code.

Edit: Oops, just noticed that you want to obfuscate the actual Java code, not the byte code. My bad. In that case, I would probably look into doing it manually. Posting huge chunks of code to a forum is probably not improving the chances of getting a useful answer anyway. Small pieces demonstrating the issue is the way to go, IMO.

Community
  • 1
  • 1
Henrik Aasted Sørensen
  • 6,966
  • 11
  • 51
  • 60
0

You want an obfuscation tool. See our Java Obfuscator that operates on source code.

Used properly, you can "rename" the variables to scrambled names (or even names you choose), and still end up with functionally correct code that compiles and runs.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • Well the goal is not really to obfuscate as per making it difficult for people to understand the source dode. It is basically about renaming the variables/methods so the extract (to be pasted on a forum/stack overflow, etc) doesnt directly link to my final source code. – Thomas Jan 04 '13 at 15:13
  • The obfuscator is built on top of a prettyprinter. If you run it in two passes, first one to rename the identifiers you want to rename, and the second one to re-format the code, you'll generate nice looking code with arbitary renames. – Ira Baxter Jan 04 '13 at 16:10