• David P. Murphy (unregistered) in reply to Nate
    Anonymous:
    Don’t you think this was run through some sort of obfuscator utility? I doubt he actually wrote that himself.


    My best guess would be that what we're looking at is the preprocessor output of a .C file.

    ok
    dpm
  • (cs)

    Well, with a few assumptions on the names of some constants and functions, this code looks quite sensible, but without context and knowledge of the data stored in the sysobjs[], we will never know. I think this code was somehow generated, so I think it is not really a WTF, however, the knowledge about its generation process seems to be lost at the submitting source of this WTF.

    <font style="color: rgb(0, 0, 255);" size="2">    public static final int BASE = 0x00000032;
        public static final int REFERENCE = 0x0000004e - BASE;
        private static final int SEQUENCE = 0x0000004a - BASE;
        private static final int SIMPLE = 0x0000004d - BASE;

        private static final int BIT4 = 1 << 4;

        private byte getReference(int index) {
            return sysobjs[index * 8 + 1];
        }
        private byte getType(int index) {
            return sysobjs[index * 8 + 2];
        }
        private byte getBits(int index) {
            return sysobjs[index * 8 + 3];
        }
        private byte setPccoLv(int index, int value) {
            return sysobjs[index * 8 + 0] = (byte) value;
        }
        private byte getValue(int index) {
            return sysobjs[index * 8 + 5];
        }
        private byte setValue(int index, int value) {
            return sysobjs[index * 8 + 5] = (byte) value;
        }
        private void adjustNegativeValue(int index, int adjustment) {
            byte tmp = getValue(index);
            if (tmp < 0)
                setValue(index, tmp + adjustment);
        }

        void RstPccoLv(int curIdx) {
            if ((getType(curIdx) == REFERENCE) && (getReference(curIdx) > -1)) {
                setPccoLv(curIdx, 0);
                int refIndex = getReference(curIdx);
                adjustNegativeValue(refIndex, 4);
                if (getType(refIndex) == SIMPLE)
                    setPccoLv(curIdx, (getBits(curIdx) & BIT4) == 0 ? 0 : 1);
                else if (getType(refIndex) == SEQUENCE) {
                    setPccoLv(refIndex, 0);
                    refIndex++;
                    if (refIndex < nbObj) // bug: should be tested in while
                        while (getType(refIndex) == SEQUENCE)
                            setPccoLv(refIndex++, 0);
                }
            }
        }
    </font>

  • Pandemic (unregistered) in reply to eagle

    "This was probably (originally) machine-generated code and never meant for human maintenance."

    My machine resents your implication that it would ever generate a WTF like this.

     

  • Utunga (unregistered) in reply to Anonymous Coward

    The movie for the quote.. eart Of Darkness.

  • Rain Dog (unregistered) in reply to limelight
    limelight:
     
       
                    ///////////////////////////////////////////////////////////////////
                    // First section - when sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x18
                   ///////////////////////////////////////////////////////////////////

                    if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x18)
                    {
                      }
                    ///////////////////////////////////////////////////////////////////
                    // Second section - when sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b
                    ///////////////////////////////////////////////////////////////////
                    if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b)
                    {
                      }
                }
            }


    You've got your own WTF in your comments. Writing "when sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b" tells us nothing, because it's simply stated again below: "  if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b)"
  • (cs) in reply to anon
    Anonymous:
    hmm? *all* code is meant for human maintenance.


    Not hardly. Check some C# that was written by hand against some C# written with a designer program (e.g Visual Studio).

    Hand written code is spaced out and well indented and sparse, and machine generated code is dense and ugly, and contains tons of extra crap methods. Uuuuugly.


  • (cs) in reply to emurphy

    emurphy:
    While your machine is interestingly similar to brainfuck, I don't think it's quite the same type of stupid as the stupid machine to which dubwai alludes.

    <FONT face="Courier New" size=2>i'm pretty sure both machines can't add.</FONT>

    emurphy:
    What method of bit-numbering leads to '5' and(1) == '4', anyway? The sanest choices would be 1-based octal or 0-based hex, which should give you some idea just how little sanity there is to be had here.

    <FONT face="Courier New" size=2>ah, that was the dyslexia talking.  rather, 4:(100) & 1:(001) = 5:(101) ; jah?  or, if you wish, 5:(101) xor 1:(001) = 4:(100).  in any case, the machine can't add.</FONT>

  • wall of burgers (unregistered) in reply to Mr VacBob
    Anonymous:
    Anonymous:
    The *compiler* is doing work to calculate 0+1.  Only the most brain-dead compiler for any language would actually write out those additions.

    Sun javac will.



    Javac in general leaves most optimizations to the JIT compiler found in most VMs.

  • (cs) in reply to emptyset
    emptyset:

    emurphy:
    While your machine is interestingly similar to brainfuck, I don't think it's quite the same type of stupid as the stupid machine to which dubwai alludes.

    <font face="Courier New" size="2">i'm pretty sure both machines can't add.</font>

    emurphy:
    What method of bit-numbering leads to '5' and(1) == '4', anyway? The sanest choices would be 1-based octal or 0-based hex, which should give you some idea just how little sanity there is to be had here.

    <font face="Courier New" size="2">ah, that was the dyslexia talking.  rather, 4:(100) & 1:(001) = 5:(101) ; jah?  or, if you wish, 5:(101) xor 1:(001) = 4:(100).  in any case, the machine can't add.</font>



    And even on the off chance that it can, I sure as hell wouldn't trust it to.

  • (cs) in reply to Satanicpuppy

    What is this bitmask bullshit everyone is spouting. 1+1+1+1 does not equal 7 (0x1111). It's a really lame obfuscation trick is all. The main code is just an amazingly messy way to use pointer arithmatic.

    Satanicpuppy:
    Anonymous:
    hmm? *all* code is meant for human maintenance.
    Hand written code is spaced out and well indented and sparse, ....

    Except for what ends up here, of course. :p
  • (cs) in reply to ACoward
    ACoward:
    This was probably (originally) machine-generated code and never meant for human maintenance.  


    I also think that this code is machine generated. Must be a stupid generator, though. Maybe it was writen in language where it is easier to create a 0+1+1+1+1 string than calculating 4 (because the language does string handling better than arithmetic). Prolog comes to my mind...
  • Founder (unregistered) in reply to ammoQ

    I think this person thought that binary 1110 = 1+1+1+0 not 18+14+12+01

  • Pax (unregistered)

    WTF? WTFF is that???

  • Jo Momma (unregistered) in reply to foxyshadis
    foxyshadis:
    What is this bitmask bullshit everyone is spouting. 1+1+1+1 does not equal 7 (0x1111).


    Umm... 0x1111 is not 7..  I'm going to pretend you don't know that "0x" typically means hex (where 0x1111 = 4369), and that you think it means binary.  If that were the case, 0x1111 would be 15, and 0x0111 would be 7..

    And who claimed 1+1+1+1 was equal to 7 anyway?
  • josh (unregistered) in reply to Mr VacBob
    Anonymous:
    Anonymous:
    The *compiler* is doing work to calculate 0+1.  Only the most brain-dead compiler for any language would actually write out those additions.

    Sun javac will.



    Are you serious?  That's a pretty big WTF right there.  There is no way that loading two small constants and adding is going to be better in any way than loading one small constant.  I think I'll stand by my comment: if javac will write out code to do 0+1 instead of just 1, it's brain dead.

  • Metasheep (unregistered) in reply to josh

    A quick test reveals that it will optimize out some simple constant stuff.  I've seen it ignore stuff like empty for loops however.  That's where an obfuscator with a bytecode optimizer like Proguard comes in.

    As for everyone trying determine where it came from, it came from a J2ME porting project.  What it actually does is another matter entirely.

  • Oli (unregistered)

    Oh I get it, it's the source code to SQL Server 2000, right?

  • (cs) in reply to wall of burgers
    Anonymous:
    Anonymous:
    Anonymous:
    The *compiler* is doing work to calculate 0+1.  Only the most brain-dead compiler for any language would actually write out those additions.

    Sun javac will.



    Javac in general leaves most optimizations to the JIT compiler found in most VMs.


    True, but NOT this. Compile-time constant folding is REQUIRED by the Java spec to be done by any compliant compiler.

  • (cs) in reply to Chekov
    Anonymous:

    Anonymous:
    What movie is that quote from?!?!  "...things...terrible things...unspeakable things..."  It's driving me insane.

    He put creatures in our bodies... made us... do things... terrible things...



    Wodies. Please get the quote right ;)
  • (cs) in reply to Anonymous Coward

    Anonymous:
    What movie is that quote from?!?!  "...things...terrible things...unspeakable things..."  It's driving me insane.

    Event Horizon.

    TODO list : dump this programmer in a black hole

  • Cheez (unregistered) in reply to lgonggr

    It's not event horizon, that quote is

    It shows you things... horrible things... the dark, inside, from the other place. I won't go back there!

  • Justin (unregistered) in reply to Anonymous Coward
    Anonymous:
    What movie is that quote from?!?!  "...things...terrible things...unspeakable things..."  It's driving me insane.


    5 secs with google.com says Babylon 5.
  • (cs) in reply to emptyset
    emptyset:

    <font face="Courier New" size="2">ah, that was the dyslexia talking.  rather, 4:(100) & 1:(001) = 5:(101) ; jah?  or, if you wish, 5:(101) xor 1:(001) = 4:(100).  in any case, the machine can't add.</font>



    5 & 1 is 1. See, if you can't get the most basic things right, why don't you just shut up? The other users will love you all the more for it.

  • soundman32 (unregistered) in reply to Anonymous Coward

    It sounds like a line from Harry Potter (1), where he is buying his wand from Olivanders, and Olivander is talking about what Voldemort did with the wand that contains the other Phoenix tail feather.

  • (cs) in reply to emptyset

    I mean 4 & 1 is 0.

  • (cs) in reply to David P. Murphy
    Anonymous:

    My best guess would be that what we're looking at is the preprocessor output of a .C file.


    What kind of silly macro would produce this sort of crap?

  • (cs) in reply to Mr VacBob
    Anonymous:
    Anonymous:
    The *compiler* is doing work to calculate 0+1.  Only the most brain-dead compiler for any language would actually write out those additions.

    Sun javac will.



    I see no contradiction.

  • BLQ (unregistered)
    Alex Papadimoulis:
    if (sysobjs[curIdx * (0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) + (0 + 1 + 1)] == 0x0000004e - 0x00000032)
      {
        if (sysobjs[curIdx * (0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) + (0 + 1)] > -1)
        {
          sysobjs[curIdx * (0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) + (0)] = 0;
    

    First thing I thought of when I saw this was "Typographical Number Theory". Perhaps the programmer had just finished Hofstadter's Godel, Escher, Bach and thought they'd give it a go in RL?

    [N.B. In TNT, (see http://en.wikipedia.org/wiki/G%C3%B6del_numbering), you only have the number '0' and the operator 'successor to', hence '1' is 'S0', '2' is 'SS0', etc]

    Just be glad (s)he didn't read a book on Lawsonomy (http://www.lawsonomy.org/Lawsonomy100.html), or the whole thing would be written in 'zig-zag and swirl'!

  • (cs) in reply to Alexis de Torquemada
    Alexis de Torquemada:
    emptyset:

    <FONT face="Courier New" size=2>ah, that was the dyslexia talking.  rather, 4:(100) & 1:(001) = 5:(101) ; jah?  or, if you wish, 5:(101) xor 1:(001) = 4:(100).  in any case, the machine can't add.</FONT>



    5 & 1 is 1. See, if you can't get the most basic things right, why don't you just shut up? The other users will love you all the more for it.

    Alexis de Torquemada:
    I mean 4 & 1 is 0.

    See, Alexis, if you can't get the most basic things right... :)

  • anonymous (unregistered) in reply to anon

    Ever tried to maintain code that is generated by parser generator?

  • David P. Murphy (unregistered) in reply to Alexis de Torquemada
    Alexis de Torquemada:
    Anonymous:

    My best guess would be that what we're looking at is the preprocessor output of a .C file.


    What kind of silly macro would produce this sort of crap?



    It's certainly possible for the actual code to be non-silly.
    For instance, what would ONE_DAY expand to, given the following directives?

    #define ONE_SECOND                1
    #define ONE_MINUTE     (SECONDS_PER_MINUTE * ONE_SECOND)
    #define ONE_HOUR       (MINUTES_PER_HOUR   * ONE_MINUTE)
    #define ONE_DAY          (HOURS_PER_DAY    * ONE_HOUR)

    ok
    dpm


  • David P. Murphy (unregistered) in reply to David P. Murphy

    Missed pasting the first three directives:

    #define SECONDS_PER_MINUTE       60
    #define MINUTES_PER_HOUR         60
    #define HOURS_PER_DAY            24
    #define ONE_SECOND                1
    #define ONE_MINUTE     (SECONDS_PER_MINUTE * ONE_SECOND)
    #define ONE_HOUR       (MINUTES_PER_HOUR   * ONE_MINUTE)
    #define ONE_DAY          (HOURS_PER_DAY    * ONE_HOUR)

    ok
    dpm

  • (cs) in reply to lgonggr
    lgonggr:

    Anonymous:
    What movie is that quote from?!?!  "...things...terrible things...unspeakable things..."  It's driving me insane.

    Event Horizon.

    TODO list : dump this programmer in a black hole

    I know :)

    But I couldn't resist the mental visage of sending this programmer straight into enternal torment in hell.

  • (cs) in reply to lgonggr

    visage = vision of course[:$]

  • heinzkunz (unregistered) in reply to Mr VacBob
    Anonymous:
    Anonymous:
    The *compiler* is doing work to calculate 0+1.  Only the most brain-dead compiler for any language would actually write out those additions.

    Sun javac will.

    Wrong:

    cat X.java

    public class X { public static int n = 10 + 20; }

    javac X.java

    javap -v X

    static {}; Code: Stack=1, Locals=0, Args_size=0 0: bipush 30 2: putstatic #2; //Field n:I 5: return LineNumberTable: line 2: 0 }

    Note: 10 + 20 is 30

  • (cs) in reply to Enric Naval
    Enric Naval:

    See, Alexis, if you can't get the most basic things right... :)



    Both results are correct (in case you didn't notice). I only decided to give emptyset the benefit of the doubt that he meant something else when he originally wrote that "5 and (1)" = 1. That is, that "bit 1" somehow refers to the number 4 (of course, typically bit 1 refers to 1 << 1, e.g. 2, but that's another story).

    Anyway, it's human to err, but when someone else points out a potential mistake, and the person in question justifies it with another mistake, then it's obvious that said person has no idea what (s)he is talking about.

  • (cs) in reply to anonymous
    Anonymous:
    Ever tried to maintain code that is generated by parser generator?


    Ever tried to maintain code that is generated by a compiler? The typical trick is to maintain the input, not the output.

  • (cs) in reply to David P. Murphy
    Anonymous:

    #define SECONDS_PER_MINUTE       60
    #define MINUTES_PER_HOUR         60
    #define HOURS_PER_DAY            24
    #define ONE_SECOND                1
    #define ONE_MINUTE     (SECONDS_PER_MINUTE * ONE_SECOND)
    #define ONE_HOUR       (MINUTES_PER_HOUR   * ONE_MINUTE)
    #define ONE_DAY          (HOURS_PER_DAY    * ONE_HOUR)


    Using #defines for integer constants is a big WTF in modern C/C++, but more importantly, that still produces something remotely readable, e.g. ONE_DAY expands to (24 * (60 * (60 * 1))). A set of macros that expands to "0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1" would have to look something like this:

    #define ZERO 0
    #define ONE ZERO + 1
    #define TWO ONE + 1
    #define THREE TWO + 1
    ...

    and then EIGHT would expand to the above string. Strikes me as being a macro WTF, though. Especially since in this case, vital parentheses would be missing - e.g. "SIX * SEVEN" will produce a rather unorthodox result.

  • Frixus (unregistered) in reply to Mike R

    Like they say: "Zero One has tought you well... but you are not a Jed yet!"

  • Pepijn (unregistered) in reply to Mario
    I would say that even if you fixed the obvious top-level WTF, namely the bizarre numeric constants, the code that remained would be no less of a WTF.

    That is quite an achievement.


    What, a meta-WTF?


    No, a recursive WTF...
  • nobody (unregistered) in reply to Anonymous Coward

    Babylon 5 Episode 21 "Comes the Inquisitor", Season 2.

     

  • (cs) in reply to Alexis de Torquemada
    Alexis de Torquemada:

    A set of macros that expands to "0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1" would have to look something like this:

    #define ZERO 0
    #define ONE ZERO + 1
    #define TWO ONE + 1
    #define THREE TWO + 1
    ...

    and then EIGHT would expand to the above string.


    And what's wrong with the Peano axioms? Huh? HUH????

    All that positional numeral system crap is just syntactic sugar.

  • (cs) in reply to Alexis de Torquemada

    Alexis de Torquemada:
    Both results are correct (in case you didn't notice). I only decided to give emptyset the benefit of the doubt that he meant something else when he originally wrote that "5 and (1)" = 1. That is, that "bit 1" somehow refers to the number 4 (of course, typically bit 1 refers to 1 << 1, e.g. 2, but that's another story).

    <FONT face="Courier New" size=2>this is a great illustration of why any (human) code that uses bit manipulation can't be trusted.  whenever i see code logic based on bits, i destroy it with great magnitude.  abstraction is friend.</FONT>

  • (cs) in reply to Alexis de Torquemada

    Alexis de Torquemada:
    I mean 4 & 1 is 0.

    <FONT face="Courier New" size=2>yeah, if i felt i needed to save face, i would have told you the 'and()' function preformed as stated and had little to do with bitwise 'and'.</FONT>

  • (cs) in reply to Ayende Rahien
    Ayende Rahien:
    I'm willing to be that this is C++ with operator overloading for the indexing operator.
    They are using some sort of bit twiddling with the index in the operator, and wanted to have an explicit way to see the bit fields.


    I'm not sure that makes it any less of a wtf, though.
  • (cs) in reply to anonymous
    Anonymous:
    Ever tried to maintain code that is generated by parser generator?

    Yes. This is done by editing the parser description. Anything else would be a wtf.

    Do you maintain C by editing the generated machine code?
  • AnoneeMuss (unregistered) in reply to emptyset

    abstraction, you say?

    so who wrote the abstracted methods or functions that you're using? can't have been a human, as their code can't be trusted.

  • (cs) in reply to AnoneeMuss

    Anonymous:
    so who wrote the abstracted methods or functions that you're using? can't have been a human, as their code can't be trusted.

    <FONT face="Courier New" size=2>*sigh*</FONT>

    <FONT face="Courier New" size=2>the father, the son, and the holy ghost.</FONT>

  • (cs)

    I wonder what's going on here... recursive usage of array...

          if (sysobjs[
    sysobjs[
    curIdx * (0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) + (0 + 1)
    ] * (0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) + (0 + 1 + 1 + 1 + 1 + 1)
    ] < 0)

  • (cs) in reply to md2perpe
    md2perpe:
    I wonder what's going on here... recursive usage of array...
          if (sysobjs[
    sysobjs[
    curIdx * (0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) + (0 + 1)
    ] * (0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) + (0 + 1 + 1 + 1 + 1 + 1)
    ] < 0)


     

      Just from the looks of it, I would say that one of the "fields" in these structures contains some kind of relational reference to other structures.

Leave a comment on “Alone In The Code”

Log In or post as a guest

Replying to comment #:

« Return to Article