Slashdot Mirror


Decompiling Java

Richard Rodger writes with a review of Godfrey Nolan's Decompiling Java. "I've just put this book down after reading it right through non-stop for four days. I haven't done that with a technical book since Learning Perl. Most techie book these days are quickie grab-bags, and you end up paying for a lot of dead trees that you aren't interested in." Read on for the rest of his review. Decompiling Java author Godfrey Nolan pages 264 publisher apress rating 8/10 reviewer Richard Rodger ISBN 1590592654 summary Learn how decompilation works in order to properly protect your intellectual property.

If you are interested in Decompiling Java, then this book tell you exactly how to do that. There's no fluff and every chapter counts. I can safely concur that Fiachra's observations are indeed correct. You'd better be prepared for some serious hard core details, but then that's what you'd paid for. It is really great to read a book that doesn't end each chapter with a few links to the real material because the author couldn't be bothered to write it up.

So what do you get? As a battle-hardened Java coder of not a few years programming, I wanted to find out about the gory details of bytecodes and how to get at them. Now it's a subject I always knew I should know about, but never took the time to read up on it. Decompiling Java puts all that knowledge into one place.

Here's a quick run-through of the chapters so you know what you're getting:

Ch.1 Introduction
Decompilation isn't just another coding tool - there are other, real world issues like ending up in jail to think about. Godfrey proposes a sort of code-of-honour for decompilers. This book could so easily have been positioned for the fr33ky kod3r skript kiddie market, and I'm glad that the author and publishers took a mature and sensible approach to the subject. I have had to decompile purchased code because of bugs and I'm glad that someone took the time to think about an ethical framework for doing this.

Ch.2 Ghost in the Machine
A good and solid introduction to the JVM and the classfile format. If you're in the market for this book, you probably already know most of this, but a refresher course is always good. For me, it definitely sorted out a lot on internal hand-waving on the subject. Just remember kids, the only thing to fear is fear itself - it's only binary data after all.

Ch.3 Tools of the Trade
Although the author builds his only decompiler later in the book, it nice to get a chapter devoted to the existing toolset and the Java decompiler scene.

Ch. 4 Protecting your Source
For the honest developer, knowing how to decompile code is more about protecting your own source code than breaking someone else's (who wants to read other people's smelly code anyway!). This chapter is one of the most directly practical. I had always assumed that obfuscation was a magic fix that I could apply if necessary. In reality, good obfuscation is just like good encryption (that is, uncommon, difficult to verify, and still subject to lateral attacks). Even compiled bytecode has relatively low entropy, so the value of obfuscation must be considered carefully.

Ch.5 Decompiler Design
This is were it starts getting a wee bit technical. Decompilation, as you can imagine, is a bit of a black art, and there are many ways of doing it. Some of them involve scary maths and some involve scary coding and the rest both. But that's why you don't meet many people who can write decompilers. Godfrey does a great job of taking you on a practical run through this fog of decompilers. At the end of this chapter you will be able to decide for yourself what approach is best suited to your problem domain. Again, this material can be challenging but it's like boot camp: You just gotta.

Ch.6 Decompiler Implementation
If the previous chapter hurt your brain and scared you silly then this chapter will have you weeping for joy. The author takes a practical, effective, and most importantly, understandable approach to actually implementing a compiler. Now, as he freely admits, his design may encounter difficulties with edge effects and infrequently used idioms, but it will take you to the point where you can solve them yourself. I really had to smile at how simple and effective the approach taken here is - instead of the expected multiple passes and mind bending parse tree manipulation, we have a single-pass, source-generating decompiler for Java. You won't follow it all first time, but it does work and you can verify it for yourself. Like I said at the start, you don't get that empty feeling from this book, and this chapter is pretty much why. I bought a book about decompiling Java, and now I can.

Ch.7 Case Studies
This chapter addresses the "why" of decompiling, returning again to the moral questions raised at the start. It's more food for thought than prescriptive preaching though, which again is refreshing. I have admit to dipping into this chapter while reading the rest of the book - the human interest angle always works a treat!

Of course, no book is perfect. What I think could have helped a bit overall would have been a introductory chapter to bytecode. But it's not a great loss and bytecode is actually pretty simple once you get your head around it. Still it might have lessened the learning curve somewhat.

Decompiling Java is a great addition to that section of your bookshelf dedicated to serious books that will be around for a while. The JVM specification and Java bytecode are not going to change that much, so this book is something you'll be able to use for a long time. Personally the best thing about this book for me was that it took me to the next level. Not many books can do this. As a working coder, I pretty much put things like decompilation into the "too hard, just for academics, and I could never grok it", category. It's great when a book comes along that can can you out of that comfort zone.

You can purchase Decompiling Java from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, carefully read the book review guidelines, then visit the submission page.

50 of 221 comments (clear)

  1. no bytecode intro? by MankyD · · Score: 3, Interesting

    So it's a book about reconstructing bytecode into human interprettable info, but it doesn't have an intro to them? That seems awfully strange. Are you sure you didn't miss something?

    --
    -dave
    http://millionnumbers.com/ - own the number of your dreams
    1. Re:no bytecode intro? by MankyD · · Score: 4, Funny

      whoops. Sorry, I forgot first post was reserved for trolls.

      --
      -dave
      http://millionnumbers.com/ - own the number of your dreams
    2. Re:no bytecode intro? by pjt33 · · Score: 3, Informative

      More details aren't hard to find: the JVM specification is fairly readable and available from the Sun website.

  2. Better Java Book by Pingular · · Score: 4, Informative

    I've read both and I have to say Covert Java is slightly more in-depth, but perhaps more for people more familiar with Java.

    --

    When anger rises, think of the consequences.
    Confucius (551 BC - 479 BC)
    1. Re:Better Java Book by Pingular · · Score: 4, Informative

      'Fraid I don't have both of the books to hand at the moment, but have a look at these reviews/book descriptions if you like:
      Decompiling Java:
      Writing for those who want to learn Java by decompilation, Nolan, a specialist in web site optimization, explains how to turn partially compiled Java bytecodes back into source code so that readers can see what the original programmer was thinking. Early chapters unravel the Java classfile format and show how Java code is stored as bytecode and executed by the JVM. Later chapters focus on how to write a Java decompiler, and a final chapter offers case studies.
      Both Java and .NET use the idea of a "virtual machine," or VM. And while VMs are useful for some purposes, they undermine the security of your source code, because creation can be reversed, or "decompiled." Which makes this one-of-a-kind book extremely useful: you must understand decompilation, to properly protect your intellectual property.
      For example, how secure is your code after you run an obfuscator? The book will answer questions like this, and provide more thorough information about Java byte codes and the Java Virtual Machine (JVM) than any other book on the market. This book redresses the imbalance by providing insights into the features and limitations of today's decompilers and obfuscators, and offering a detailed look at what JVM's actually do.
      This is a fantastic in-depth book on decompilers and code obfuscation tools for Java. It covers the structure of Java code files, the opcodes, and the all of the tools required to decompile classes, and to obfuscate existing code. It's an invaluable reference for anyone who has to deploy Java in a non-secure environment, or for those that want to learn how the language really works.
      There is a lot of code to pour though, and there are no illustrations. I think the text could have used some illustrations, but that's not a big sticking point for me.
      If you are a serious Java gearhead you should have a look at this book. And if you have a specific interest in either de-compiling some Java or obscuring your deployed Java bytecode then this is a must have.
      Covert Java:
      "Covert Java" provides a fascinating and look at behind the scenes Java development tactics that are usually the domain of seasoned veterans. Definitely a read for those who want to master Java.
      --Floyd Marinescu, Author, EJB Design Patterns; General Manager & founder of TheServerSide Communities.
      As a Java developer, you may find yourself in a situation where you have to maintain someone else's code or use a third-party's library for your own application without documentation of the original source code. Rather than spend hours feeling like you want to bang your head against the wall, turn to Covert Java: Techniques for Decompiling, Patching, and Reverse Engineering. These techniques will show you how to better understand and work with third-party applications. Each chapter focuses on a technique to solve a specific problem, such as obfuscation in code or scalability vulnerabilities, outlining the issue and demonstrating possible solutions. Summaries at the end of each chapter will help you double check that you understood the crucial points of each lesson. You will also be able to download all code examples and sample applications for future reference from the publisher's website. Let Covert Java help you crack open mysterious codes!

      --

      When anger rises, think of the consequences.
      Confucius (551 BC - 479 BC)
  3. Been decompiling Java for awhile now... by twoslice · · Score: 5, Funny

    Everytime I take a piss after my morning cup of joe...

    --

    From excellent karma to terible karma with a single +5 funny post...
  4. another alternative = encrypted class files by ardiri · · Score: 5, Interesting

    in 1999 i wrote a paper on security in set-top boxes (one of my first papers); yay. but, one approach we had was to build a custom class loader that would actually load encrypted classes.

    the details of the paper are:

    1999 - Security in Set-Top boxes
    European Multimedia, Embedded Systems and Electronic Commerce
    EMMSEC '99, Stockholm, SWEDEN
    June 21-23, 1999

    COPY: (pdf)
    http://www.ardiri.com/publications/emmsec99 .pdf

    there was a lot of interest on this topic back in the time :) i had a number of successful prototypes built - but, unless you build the class loader into hardware (ie: cannot access the .class file), its just another hurdle, nothing more.

    1. Re:another alternative = encrypted class files by JavaNPerl · · Score: 4, Informative

      I believe encryption is probably not worth the effort for most people, it's not much of a hurdle to overcome. Ultimately all custom class loader execution paths will lead to a ClassLoader.defineClass call which can either be intercepted by creating a modified system class loader or by creating a JVMPI agent which listens for JVMPI_EVENT_CLASS_LOAD_HOOK events. If you can prevent these methods from being employed then you're probably operating in a secure environment where encryption would be overkill.

  5. What ethical problems? by jmorris42 · · Score: 5, Insightful

    Good review, but I have one major nit to pick.

    What ethical problems? Decompiling is perfectly moral and ethical. Whether it is illegal is a seperate and, for me, almost irelevant issue. If I legally own a copyrighted work I am allowed to read it, period and end of story. Corporate licences excepted, software is SOLD, not licensed despite the scary words on the box and the dread click through EULA.

    Hell, I learned assembly by writing a disassembler (in BASIC) and reading the Microsoft BASIC roms, then later reading the commented listings that ran in Color Computer Magazine. (TO avoid a copyright fight, and because M$ refused to grant them permission, CCM ran only the comments and memory locations, leaving the reader to run their own dissassembly for the opcodes.)

    The only ethical problem would be lifting the code and reusing it without permission and I think we all know that is wrong.

    --
    Democrat delenda est
    1. Re:What ethical problems? by Skim123 · · Score: 3, Insightful
      What ethical problems? Decompiling is perfectly moral and ethical. ... If I legally own a copyrighted work I am allowed to read it, period and end of story. Corporate licences excepted, software is SOLD, not licensed despite the scary words on the box and the dread click through EULA.

      I disagree here. I am a strong believer that people should be able to trade goods/services for prices/conditions they mutually agree upon. If I write software and say I will sell it to you for $x on condition that you do Y (perhaps Y is not decompiling the source), and you agree to these terms, I think it is morally repugnant of you to break our agreement and decompile. You had the choice to not purchase my product, after all.

      --

      I could not justify my existence if I were a turkey farmer. Would I terminate myself? Undoubtably, yes.

    2. Re:What ethical problems? by jmorris42 · · Score: 4, Interesting

      > I think it is morally repugnant of you to break our agreement and decompile.

      While you are welcome to your delusions, but out here in the real world we have some things called laws. Specifically the Uniform Commercial Code and the Copyright laws.

      You will note that I excepted commercial licenses, since those are actual signed contracts and are legally binding.

      According to the Uniform Commercial Code if goods are exchanged in regular trade there can't be strings attached; i.e. if it looks like a sale it IS a sale. If I buy a copy of Microsoft Windows from Newegg.com I did just that, I BOUGHT a copy of Windows. That means I can do anything with that copy, including read it. I can even copy it in whole or in part so long as such activity falls under the backup exception written into the law or by Fair Use. Of course any other reproduction is forbidden by the artifical monopoly rights granted to the author by copyright. While I have a lot of problems with how copyrights are currently operated (eternal instead of "limited times" as prescribed by the Constituition) I don't have a major problem with that limitation.

      But think about it, what you are saying is that you can sell me a copyrighted work that I am forbidden to read myself. What a load of fetid dingos kidneys! Ford can't forbid me from taking apart a Caddy and not only making, but SELLING plans; but you think your algorithms are so freaking special that you want the government to put me in jail for the crime of reading them? What are you smoking?

      --
      Democrat delenda est
    3. Re:What ethical problems? by YoJ · · Score: 4, Insightful

      It's that mutually agreed condition part that is problematic. When I buy hardware or software, I don't normally agree to any conditions on it. If I did, your philosophy would have merit. There are even good examples of things you buy where you must agree to conditions (like cell phones); you read a contract and sign your name. Software and hardware companies want to have it both ways. They want an enforceable contract that users agree to, but they also want to present their wares in a friendly way that makes people think they are buying something normally.

    4. Re:What ethical problems? by l1gunman · · Score: 2, Funny

      Ahem. Last time I checked Ford didn't make Caddys. So I doubt they'd have any qualms about your taking one apart and selling the plans. They might even encourage it!

    5. Re:What ethical problems? by Waffle+Iron · · Score: 2
      If you don't want to pay money for a book whose full contents I say you can't read, then fine - don't buy it.

      You can certainly restrict your customers such terms -- as long as you convince the buyer to read and sign a legally binding contract prior to the sale.

      If you don't get a signature, you can't expect any restrictions.

    6. Re:What ethical problems? by selderrr · · Score: 2, Insightful

      What about EULAs that are deliberately written in a style/technical language unreadable to the majority of the buyers ? Or written with intent to discourage complete reading (a EULA of 125 pages for instance, with 75% of its scentences longer than 10 lines and each one containing 15 buzwords that you have to go lookup online. NOBODY should be asked to read and accept all that. It's just plain stupid)

    7. Re:What ethical problems? by Skim123 · · Score: 2, Insightful
      You're serious, aren't you?

      Very.

      I just don't understand people with your greedy, assbackwards, mindset.

      I don't understand people with your mindset, a mindset that strips individuals of their rights. Listen, if I have created something, and want to sell it to you with conditions, why shouldn't I be able to do that? If you don't want to abide by those conditions: DON'T FREAKING BUY WHAT I'M SELLING. Have a little restraint, Mr. Consumer. Jebus.

      I am 100% for free trade between people. You, on the other hand, are against that, since you don't think a seller should be able to make a condition, and a buyer free to choose to accept or deny the sale based on that condition.

      Finally, capitalism works. In a true capitalistic marketplace, having unnecessary, artificial conditions wouldn't be benefitial to the seller, since other sellers could enter the market without such fluff conditions and make the sale. Going back to the author denying readers to read certain chapters, who would buy those books? Rather, the authors who granted full access would far outsell those who did not.

      --

      I could not justify my existence if I were a turkey farmer. Would I terminate myself? Undoubtably, yes.

    8. Re:What ethical problems? by aminorex · · Score: 2, Interesting

      You can't impose unlawful conditions. Freedom is nothing without laws. The fundamental principle here is that no one can freely contract to contravene the law. Does that help?

      --
      -I like my women like I like my tea: green-
    9. Re:What ethical problems? by jmorris42 · · Score: 2, Insightful

      > But then you say the GPL provides a license, yet nobody has to sign
      > anything to use GPL'd software, or copy it, or distribute it, as long
      > as they meet its conditions. So if I don't have to sign anything, then
      > the GPL isn't binding.

      Exactly correct. If you copy a GNU program and distribute it you do not have to accept the GPL. However when RMS and his squadron of elite attack lawyer ninjas descend upon you for violating their copyright, smiting thee with their rightous fury, only saying "I accept the GPL and have followed all of it's conditions" will make them stop, because otherwise that have you dead to rights on copyright infringement. See the difference? The GPL is a LICENSE to perform an action otherwise forbidden by law. You don't have to sign it, but if you want to take advantage of the additional freedoms it grants you must accept it in whole, both the THOU SHALL and the THOU SHALL NOT parts, because nothing else gives you the right to distribute a copy of a GPL licensed work.

      All the GPL is, in essence the following statement. "This program is copyrighted. This means that by law you may not copy it. However, because we are good hoopy froods and want software to be Free, we grant you the right to copy and redistribute it under the following conditions. By distributing copies it is presumed that you accepted the limitations of this license since nothing else gives you permission to distribute copies so any copies made under terms and conditions not covered by this license are by definition not permitted by this license. QED."

      Now take the typical EULA, it removes rights the end user already has, offers nothing of value in exchange and expects to be taken sight unseen in most cases. Where is the implied consent as in the GPL? By ignoring it I still have the right to run the program because I purchased it, I can reverse engineer it because I I bought the copy and have as much of a right to read it as my computer does.

      --
      Democrat delenda est
  6. This is one of the features of Java by coolsva · · Score: 2, Insightful

    It has always been the case with Java (and in general many other interpretted/pcode generating languages) that enable them to be decompiled. I remember, back in old VB days, you could take a VB (pre 3.0) executable and decompile to get the original source. Of course, variable names were changed (since VB compiler changed them when converting to pcode).
    As systems get more open/advanced, the sources are more difficult to hide. In case of web apps, there is no need to decompile anything, the javascripts are available for all to see in plain text. Even more advanced applications that use ASP pages that execute on the server, can be seen by changing the URL to list the source rather than execute them (I dont remember the exact syntax, but I think it is related to the alternate data stream in NTFS)
    That is the reason, we have copyright. On a more personal note, I think it serves the community if someone can see your implementation in code, get inspiration and either correct mistakes or expand on the code.

    1. Re:This is one of the features of Java by Anonymous Coward · · Score: 2, Interesting

      Java doesn't really have to be that vulnerable. Perhaps code compiled with javac is weak, but it could easily be made much stronger.

      Why? Well, Java bytecode is a lot more flexible than the Java language. Take exceptions for example. In the language we handle exceptions with try-catch-finally grammar productions. But in the bytecode we have a table that specifes ranges of bytecode addresses that mapped via an exception to a exception handler. The cute thing is that a "range of bytecodes" has nothing to do with control flow; control flow and weave in and out of the range, no restrictions. The handler can even be in the range. And yes, I have seen this happen as a cosmetic bug from a java compiler. But the decompiler has to produce a set of nicely nested grammar productions. Anyway, a range != a try-catch ... Big difference!

      So even a little automatic tweaking could defeat most of the decompilers out there.

      Lots of languages produce Java bytecode on back end as well. Some of the output from these are pretty bizzare.

    2. Re:This is one of the features of Java by airConditionedGypsy · · Score: 2, Insightful
      As systems get more open/advanced, the sources are more difficult to hide. In case of web apps, there is no need to decompile anything, the javascripts are available for all to see in plain text. Even more advanced applications that use ASP pages ...

      Web applications are typically implemented server-side. Javascript is client-side code.

      Javascript != web applications

      Perhaps what you are referring to is the source for ASP and JSP/servlets. There have been bugs in servlet containers (specifically, I believe the issue was that the web server in front of a servlet container wasn't configured correctly, and thus instead of passing the request to the SC for handling, just retrieved the file and returned the content to the user's browser), but the code in a JSP or ASP is executed on the server before it ever reaches the client -- this means that it is not possible in the normal course of events for a client to see the "source" contents of such a server-side object.

      This constraint can of course break down when web application servers are not built and/or configured correctly.

      --
      I bootleg Fizzy Lifting Drinks.
    3. Re:This is one of the features of Java by almaw · · Score: 3, Insightful

      How can the parent be modded +3 insightful?!?

      Even more advanced applications that use ASP pages that execute on the server, can be seen by changing the URL to list the source rather than execute them

      Are you smoking crack?

      You can't arbitrarily get at source code on someone's web server. Do you think eBay would want you seeing the passwords to their database servers?

      Web apps aren't written in JavaScript. Sure, there might be some to drive calendar selection or something, but pretty much all real apps (shopping carts, etc.) are done server side.

      Please get a clue and stop spreading your FUD around.

      Additionally, this isn't a "feature" of Java. It's just a side-effect of its machine-independent bytecode. You could argue that it's not all that hard to reverse engineer compiled C - if you step it through a debugger you can see what it does fairly easily.

      Systems being more "advanced" (let's wave our hands a little bit more) won't make it any more difficult to hide the source. Many many people run Java on the server side of web apps. It will always be impossible to view the source for such applications (unless the developers put it up for the world to see, of course). As for being "open", what do you mean? If you mean, "open source" then, well, duh... :)

    4. Re:This is one of the features of Java by johnmckeon · · Score: 2, Informative

      You can't arbitrarily get at source code on someone's web server. Do you think eBay would want you seeing the passwords to their database servers?

      I think he's referring to an old bug on IIS that would allow you to view the contents of a file on the server. I believe it was a sample ASP that MS included to demonstrate come capability of ASPs.

      I'm sure there are a few servers around that still have that enabled, but I'm sure most had that thing fixed 3-4 years ago.

  7. DJ Decompiler and JAD by Anonymous Coward · · Score: 3, Informative

    No Java developer should be without DJ Decompiler (which sits on top of JAD, the actual decompiler, command line only). Seriously, this book may be useful, but most people are way below needing to know any of this. If you do need to know it or are just curious, fine.

    Oh, and obfuscation, blah, any good IDE (like IntelliJ IDEA) is able to help you work around this junk.

  8. Being able to decompile code.... by tcopeland · · Score: 5, Interesting
    ...can be handy when trying to figure out the advantage of one coding idiom over another. On the PMD project (a Java static analysis tool) there was a discussion yesterday about code like this:
    if(logger.isLoggable(Level.FINEST) == true){
    // etc
    }
    which can be changed to
    if(logger.isLoggable(Level.FINEST)){
    // etc
    }
    to make it read (to me, anyway) a bit clearer.

    Anyhow, decompiling the classfile with "javap -c" shows that a couple of instructions get eliminated by dropping the explicit comparison to "true". So the classfile gets smaller, it loads faster, and (unless the JIT compiler is smart enough to do constant propagation on that conditional) it'll run faster, too.
    1. Re:Being able to decompile code.... by tcopeland · · Score: 2, Informative
      > Is there a good reason why it doesn't?

      The Java compiler does some optimization - for example, when given this code:
      class Test {
      int x = 2 + 2;
      }
      it does algebraic simplification to reduce that assignment to an aload followed by a iconst_4 instruction. And it does some constant propagation so that this:
      class Test {
      private static final int X = 2;
      int y = X + X;
      }
      also gets simplified to the aload/const sequence. I guess it's just some choices the compile designers made on which things were more feasible to attack.
    2. Re:Being able to decompile code.... by AuMatar · · Score: 3, Informative

      While I hate defending Java in any form, the two should be equivalent on a machine level. To see if a value is true (non-zero), you can do two things- subtract 0 and see if the result is 0, or AND it with 0xFFFF... To see if two things are both the same value, you subtract the two and check if the result is 0. The two are an equal number of instructions (and both test and cmp are quick instructions). On an asm level:

      mov eax, isLoggable
      cmp eax, 0 ;could also use test eax, 0xFFFFFFFF
      jnz skip_if ;if using test, do a jz skip_if ;etc
      skip_if: ;both branches continue here

      A check to true only changes the cmp to 1 instead of 0. It won't run any faster.

      --
      I still have more fans than freaks. WTF is wrong with you people?
  9. You didn't sell it. by eddy · · Score: 5, Insightful

    >knowing how to decompile code is more about protecting your own source code.

    There are many reasons to learn about, implement and use decompilers, but I don't think "to properly protect your intellectual property" should be one of them.

    I'm got somewhat interested in this book (never heard about it before), but I think I'm going to pass. Sounds like the decompiling described is too much of a one-trick pony -- which is fine, it's about decompiling java after all -- but I'd really like something like an extension and update of Cifuentes work in book form, with the lessons from the IDA team too.

    You know, from the beginning; starting with machine descriptions and disassembly for a generic front-end, efficent IR, and on up through the back end.

    Now that'd be a tome [worth paying for].

    --
    Belief is the currency of delusion.
  10. In Soviet Russia... by kkovach · · Score: 3, Funny

    the decompiler compiles you!

    Er... um...

    the compiler decompiles you!

    Er...

    the java decompiles itself!

    Ah, whatever.

    - Kevin

    --
    The less confident you are, the more serious you have to act.
  11. Maintainance nightmare by RealProgrammer · · Score: 2, Insightful
    I had always assumed that obfuscation was a magic fix that I could apply if necessary.

    Let me get this straight: the author recommends that 'honest' developers obfuscate their code?

    I've read programs that I thought were obfuscated, but later found out were just poorly written. Other times I've run into programmers who, tin hats firmly affixed, went to great lengths to make sure no one learned their Merlinesque techniques for getting the most out of BASIC.

    In context, the author seems to be talking about obfuscating object code. Yikes! What's the opposite of debugging? Buggery?

    Encrypting object code to make it harder to reverse engineer is a giant waste of time. Here are more productive ways to spend the the same amount of energy:

    • Making your programs work better
    • Asking other people to look over your code for bugs
    • Commenting the source so you (and others) can find bugs better
    • Replying to 'frist p0sts' on Slashdot

    In fact, I can't think of many worse wastes of time than making a compiled program hard to understand.

    --
    sigs, as if you care.
    1. Re:Maintainance nightmare by jjgm · · Score: 5, Insightful

      I'm sure he's talking about obfuscating the bytecode, not the source code.

    2. Re:Maintainance nightmare by nganju · · Score: 5, Informative

      You've misunderstood. Java obfuscation is an automated process done with a third-party tool that rearranges Java BYTECODE, not source code. The idea being that someone that tries to decompile the BYTECODE will get a bunch of spaghetti. It doesn't take any extra time or energy by the developer, just 5 seconds to run the tool on your .class files.

      --
      There are 2 kinds of people in this world. Those that can keep their train of thought,
    3. Re:Maintainance nightmare by shmert · · Score: 2, Interesting

      What's fun about decompiling obfuscated code is when you end up with variables and classes that have reserved names, e.g. a class called "if".

      I had to decompile and patch a ridiculously buggy JDBC driver for a commercial database which had been run through an obfuscator, and ran into that issue. Renaming was rather a hassle, I must say.

      I came to the conclusion that they had obfuscated their driver out of shame at the embarrasingly bad code, rather than to protect any intellectual property therein.

      --
      You drank my drink, you drunk!
  12. Consti-what? by Anonymous Coward · · Score: 2, Funny

    non-stop reading for 4 days and the first thing he does is post on /.?

    I might have gone the bathroom, or perhaps had a snack. Maybe a nap.

  13. Books online by truthsearch · · Score: 3, Informative

    Most techie book these days are quickie grab-bags, and you end up paying for a lot of dead trees that you aren't interested in.

    And so I suggest a service like O'Reilly's Safari Bookshelf. It includes the full text of over 2,000 technical books, many not published by them. No killing trees, far less money than buying books, plus full text search.

  14. Jad... by david.given · · Score: 4, Informative
    ...is pretty much the standard decompiler where I work. Alas, it's no longer free, as I've just found out when I searched for it's home page, but it works really well. I have, on occasion, used it as a pretty-printer for other people's code. It undoes obfuscation with ease.

    I have yet to try it on byte-code produced by non-Java languages, but I'd be interested to see the results...

    (It sucks that it's no longer free. The version I've got I installed through Debian, for goodness sake, years ago. Does anyone know any free alternatives that work as well?)

    1. Re:Jad... by cpereda_yahoo.com · · Score: 5, Informative

      I use it too and it's still free, you just can't include it in your own product without his permission.

    2. Re:Jad... by posisoft · · Score: 2, Informative

      DJ is 'only' a JAD front-end

  15. Sun has this info for free... by frankvl · · Score: 4, Informative

    Sun has put the Java bytecode specification online for free..

    Reverse engineering in Java is as simple as the compile process itself. Besides there are already free tools available so why bother??

  16. Opposite of debugging by BitwizeGHC · · Score: 3, Funny

    The opposite of debugging is, of course, "embuggening".

    Hat tip to Jebediah Springfield.

    --
    N4st0r, trixx0r h0bb1tz0rz! Th3y st0l3 0ur pr3c10uzz!
  17. Which is really surprising to me by devphil · · Score: 3, Insightful


    who, as a compiler hacker, would have expected an optimization pass to transform the first form into the second form before generating the bytecode.

    Or more precisely, to understand that both forms are testing for the same thing, and to produce identical simplified bytecode.

    --
    You cannot apply a technological solution to a sociological problem. (Edwards' Law)
  18. Doesn't work by lycono · · Score: 5, Informative

    This approach to "security" in Java is so trivially easy to circumvent that its worthless.

    There are a number of papers and articles detailing why this type of approach to "IP security" is so misguided. One such article is here: http://www.javaworld.com/javaworld/javaqa/2003-05/ 01-qa-0509-jcrypt.html

    The crux is that at some point in time, you have to deliver the encrypted class to the JVM in an unencrypted format. Intercepting this delivery is incredibly easy (no expert knowledge required, the details for doing so are detailed in the article above), at which time someone can just write the unecrypted class file out to disk (or wherever they wish). Voila! All your IP are belong to us.

    1. Re:Doesn't work by r7 · · Score: 4, Informative

      > "security" in Java is so trivially easy to circumvent

      Are you confusing encryption with obfuscation? If not I agree that class-level encryption has no ROI.

      Obfuscation, on the other hand, is an excellent tool for protecting IP. I use Proguard http://proguard.sourceforge.net/ via Ant and am happy with the result, having tried to grok the resulting byte code (using jad...) Good luck trying to work with that!

      R7

  19. Nothing beats decompiling hacker code... by RZ-1 · · Score: 3, Informative

    that was aimed to foil decompilers.

    Its starts off with public variable names like:
    public int YOU_DECOMPILING_NOOB =-1;
    public int NO_SKILLZ_4U=100;

    and then the obfusticator kicks in:
    where a1 and al(with an L) are switched around.
    The variable and method names look similar.

    if (a1.b1.x.y == al.b1.xl.y2){
    a1.v1.x.y &= al.b1.x1.y2 >> 0x4c;
    a1.b1.x( al.b1.x2 );
    }

    Ouch! Also, I think every decompiler has some weaknesses and isn't able to undo all code. I know Jad has some limitations. Unfortunately, I wasn't able to get the source of the code that broke the decompilers ;)

  20. Why read a book. Just download Jode by JPyObjC+Dude · · Score: 3, Informative

    I have been decompiling Java regularily. Just get Jode Jode Its very simple and effective. As long as the writers are not using ubfuscation tools, the code is fully readable in it's original form sans commenting.

  21. Good obfuscation WORKS by JavaRob · · Score: 3, Informative

    The simplest version of cracking a Java program is using JAD to decompile the source, making a few changes in source (like changing the license check to always return "full enterprise version" instead of "time-limited demo"), compiling your altered class, replacing it the JAR, and running the app.

    Most obfuscators will make this track impossible, by doing things like using language keywords (while, for, if, and so on) for class/method/variable names, so that when you decompile the thing it cannot be recompiled. They also mix stuff around in the classfile enough so that figuring out what method is doing what becomes non-trivial -- stupid things mostly (like naming methods l1(), ll(), I1(), Il(), etc.), plus a few tricks to stop JAD from fully decompiling the class.

    Enough of these little things add up to make the work involved in altering the decompiled class excessive and difficult.

    The more sophisticated Java cracker doesn't bother. They decompile enough source to get their bearings, then edit the appropriate bytecode directly, with a classfile editor. Fortunately, most people with this level of experience can just pay for the frickin software they want.

    I'm actually not obfuscating my Java code yet, but I'm going to start... it's just too easy to crack Java code without it. yGuard obfuscator is pretty decent LGPL one, that can run as an Ant task.

  22. Want to keep your code to yourself? Use C++. by Futurepower(R) · · Score: 2, Funny


    The books about decompiling Java are excellent advertisements for C++.

    1. Re:Want to keep your code to yourself? Use C++. by TheLink · · Score: 2, Funny

      Use Perl. Then you can keep the code to yourself. Heck how many people do you think will claim it's theirs? :)

      --
  23. Re:Links to books on Amazon by sjasja · · Score: 2, Insightful
    (Yes, Slashbots, those are affiliate links... that doesn't make them any less useful though, does it?)

    Yes, it does make them less useful. Because now it is impossible to tell whether you are saying things like "a more in-depth look" because you really mean it, or because you stand to make a quick buck by making bogus claims about the book.

    Nothing personal, of course; you can probably see yourself why the rest of us simply can't know if you are being honest or running an astroturf con.

  24. obfuscators don't work? by JavaRob · · Score: 2, Insightful

    Obfuscators DO work. They're certainly not foolproof, but they definitely make it more difficult to crack a program of any size.

    I'm not talking about tiny programs; but who even bothers decompiling tiny midlets? Isn't it obvious what they're doing? With tiny programs, if you know enough to be cracking Java programs, you might as well just write the thing out yourself. It's not magic.

    But for larger applications, any decent obfuscator can make it very time-consuming to decompile and edit the programs. I posted more on this in another thread, so let me just say you really have to try it out before you say obfuscators don't work. They definitely DO work at foiling the average cracker who won't spend hours and hours reconstructing a $100 piece of software.