Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. \r\n

\r\n

Scheduled Pinned Locked Moved The Weird and The Wonderful
ruby
30 Posts 15 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    The correct code in C# is "\r\n" which is ldstr "\r\n" in MSIL (which is generated exactly like that by the C# compiler)

    D Offline
    D Offline
    David Skelly
    wrote on last edited by
    #16

    The OP doesn't say that the code was written in C#, it was reverse engineered using Reflector. Reflector is capable of taking code written in VB and decompiling it back into C#. The resulting C# code may look pretty odd, but you will at least be able to see what it is doing.

    J 1 Reply Last reply
    0
    • D David Skelly

      The OP doesn't say that the code was written in C#, it was reverse engineered using Reflector. Reflector is capable of taking code written in VB and decompiling it back into C#. The resulting C# code may look pretty odd, but you will at least be able to see what it is doing.

      J Offline
      J Offline
      jofli
      wrote on last edited by
      #17

      That's right, but afaik he only codes c#.

      D 1 Reply Last reply
      0
      • J jofli

        That's right, but afaik he only codes c#.

        D Offline
        D Offline
        David Skelly
        wrote on last edited by
        #18

        Well, OK, maybe he's just an idiot. As far as I am aware, Reflector doesn't stop people from writing bad code and will happily decompile bad C# back into bad C#. GIGO, as they say. For what it's worth, the MS .NET Framework implementation of C# Environment.NewLine returns a literal constant "\r\n". No idea what Mono does. So if the contractor wrote this in C#, goodness only knows what was going through his brain. Nothing, probably, if he's like some of the contractors I've known.

        1 Reply Last reply
        0
        • P PIEBALDconsult

          A BASIC developer new to C#?

          jofli wrote:

          Recieved

          And maybe didn't graduate high school either? :-D

          J Offline
          J Offline
          jofli
          wrote on last edited by
          #19

          PIEBALDconsult wrote:

          jofli wrote: Recieved And maybe didn't graduate high school either? Big Grin

          http://www.recieved.co.uk/[^] Well, at least he tried to use English namings. And I must admit that sometimes it's not that easy, if you're not a native speaker.

          1 Reply Last reply
          0
          • I Ian Shlasko

            No no no... It's harder to hide it that way. With code like this, you want it buried deeply inside a commonly-used DLL in a not-quite-obsolete language, so when you get laid off and the next guy in line decides to rewrite the code and modernize it, they have a heart attack when they see it. At least, That was probably what some of my predecessors were thinking...

            Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #20

            Ian Shlasko wrote:

            It's harder to hide it that way.

            No, it hides it in different places; your way has all the information in one place. Plus, using a resource and config makes it brittle -- if someone changes or removes the entries chaos will ensue.

            I 1 Reply Last reply
            0
            • J jofli

              Reflector showed me this 'gem' in a contractors project:

              string cBRK = Convert.ToChar(int.Parse("13")).ToString() + Convert.ToChar(int.Parse("10")).ToString();

              this.ReportStatus("93101Bytes" + cBRK + BytesRecieved.ToString() + cBRK + fileSize.ToString() + cBRK);

              kind regards, JoFli

              D Offline
              D Offline
              David Skelly
              wrote on last edited by
              #21

              Come to think of it, why are you having to reverse engineer the contractor's project? If he wrote the code while in your employ, I would expect that you would own the intellectual property rights to the code, and normally you would expect to have a copy of the source after his contract ends. Unless you bought this from him as a finished product rather than contracting his time to write it for you. In which case, he owns the copyright and reverse engineering it could be a breach of the licence terms (which normally forbid that sort of thing).

              T M 2 Replies Last reply
              0
              • P PIEBALDconsult

                Ian Shlasko wrote:

                It's harder to hide it that way.

                No, it hides it in different places; your way has all the information in one place. Plus, using a resource and config makes it brittle -- if someone changes or removes the entries chaos will ensue.

                I Offline
                I Offline
                Ian Shlasko
                wrote on last edited by
                #22

                Nah, the point is that everything looks normal from the outside... Then you drill down into the utility functions, and each one is completely illegible. So you've already ported half of the library, and now you don't want to touch it because you're afraid you'll miss something and break an edge condition.

                Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

                N 1 Reply Last reply
                0
                • I Ian Shlasko

                  Nah, the point is that everything looks normal from the outside... Then you drill down into the utility functions, and each one is completely illegible. So you've already ported half of the library, and now you don't want to touch it because you're afraid you'll miss something and break an edge condition.

                  Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

                  N Offline
                  N Offline
                  NormDroid
                  wrote on last edited by
                  #23

                  Nice thinking, job security at it's best.

                  Software Kinetics (requires SL3 beta) - Moving software

                  1 Reply Last reply
                  0
                  • D David Skelly

                    My guess is that this is an artifact of Reflector, not of the original coder. I do know that in VB, the Chr() function actually does use Convert.ToChar internally so my guess is that C# does the same. Who knows what Environment.NewLine does internally. I assume that the compiler has in-lined the Chr function, and Reflector has simply given you back what the compiler produced. Anyone with too much free time on their hands and a handy copy of Reflector is invited to experiment to find out what the compiler does with this sort of thing. Reflector is showing you what the code looks like after the compiler has munged it around and played merry havoc with your beautiful code.

                    C Offline
                    C Offline
                    ClementsDan
                    wrote on last edited by
                    #24

                    The Chr() = Convert.ToChar() thing makes some sense, but why int.Parse("13") instead of just 13?

                    1 Reply Last reply
                    0
                    • D David Skelly

                      My guess is that this is an artifact of Reflector, not of the original coder. I do know that in VB, the Chr() function actually does use Convert.ToChar internally so my guess is that C# does the same. Who knows what Environment.NewLine does internally. I assume that the compiler has in-lined the Chr function, and Reflector has simply given you back what the compiler produced. Anyone with too much free time on their hands and a handy copy of Reflector is invited to experiment to find out what the compiler does with this sort of thing. Reflector is showing you what the code looks like after the compiler has munged it around and played merry havoc with your beautiful code.

                      G Offline
                      G Offline
                      Gideon Engelberth
                      wrote on last edited by
                      #25

                      Looks like temp = Chr(13) + Chr(10) gets decompiled into temp = "\r\n"; so the compiler is smart enough to actually make the string when you call Chr with a constant. Environment.NewLine shows up as a property call in Reflector, but the JIT may inline it as a literal string. There's no way Reflector would generate what the OP is seeing unless the code really was that bad.

                      1 Reply Last reply
                      0
                      • I Ian Shlasko

                        If that's obfuscation, I'm not impressed... If I wanted to make it REALLY confusing, I'd do something like this:

                        const string blarphnik = "51209576120381929170992";
                        string elkabong = Convert.ToChar(int.Parse(blarphnik.SubString(1,2))

                        • int.Parse(blarphnik /* If I had a pet monkey, I'd name it blarphnik */.SubString(8 /* What a nice number */,1)))
                        • Convert.ToChar(int.Parse(blarphnik.SubString(18, 2))
                          / int.Parse(blarphnik.SubString(6,1) /* Todo: Fix this */));

                        And then I would publish this as part of a self-help book entitled "How to Drive a Programmer Insane"

                        Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

                        P Offline
                        P Offline
                        peterchen
                        wrote on last edited by
                        #26

                        Ian Shlasko wrote:

                        self-help book

                        Ian Shlasko wrote:

                        How to Drive a Programmer Insane

                        So your target audience, precisely, is ...?

                        Personally, I love the idea that Raymond spends his nights posting bad regexs to mailing lists under the pseudonym of Jane Smith. He'd be like a super hero, only more nerdy and less useful. [Trevel]
                        | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server

                        I L 2 Replies Last reply
                        0
                        • P peterchen

                          Ian Shlasko wrote:

                          self-help book

                          Ian Shlasko wrote:

                          How to Drive a Programmer Insane

                          So your target audience, precisely, is ...?

                          Personally, I love the idea that Raymond spends his nights posting bad regexs to mailing lists under the pseudonym of Jane Smith. He'd be like a super hero, only more nerdy and less useful. [Trevel]
                          | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server

                          I Offline
                          I Offline
                          Ian Shlasko
                          wrote on last edited by
                          #27

                          peterchen wrote:

                          So your target audience, precisely, is ...?

                          I don't think that far ahead

                          Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

                          1 Reply Last reply
                          0
                          • P peterchen

                            Ian Shlasko wrote:

                            self-help book

                            Ian Shlasko wrote:

                            How to Drive a Programmer Insane

                            So your target audience, precisely, is ...?

                            Personally, I love the idea that Raymond spends his nights posting bad regexs to mailing lists under the pseudonym of Jane Smith. He'd be like a super hero, only more nerdy and less useful. [Trevel]
                            | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #28

                            sane programmers with good reading skills, not a big audience IMO. :)

                            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                            1 Reply Last reply
                            0
                            • D David Skelly

                              Come to think of it, why are you having to reverse engineer the contractor's project? If he wrote the code while in your employ, I would expect that you would own the intellectual property rights to the code, and normally you would expect to have a copy of the source after his contract ends. Unless you bought this from him as a finished product rather than contracting his time to write it for you. In which case, he owns the copyright and reverse engineering it could be a breach of the licence terms (which normally forbid that sort of thing).

                              T Offline
                              T Offline
                              TobiasP
                              wrote on last edited by
                              #29

                              David Skelly wrote:

                              reverse engineering it could be a breach of the licence terms (which normally forbid that sort of thing)

                              Perhaps this could be the reason exactly why they forbid reverse engineering? :-D

                              1 Reply Last reply
                              0
                              • D David Skelly

                                Come to think of it, why are you having to reverse engineer the contractor's project? If he wrote the code while in your employ, I would expect that you would own the intellectual property rights to the code, and normally you would expect to have a copy of the source after his contract ends. Unless you bought this from him as a finished product rather than contracting his time to write it for you. In which case, he owns the copyright and reverse engineering it could be a breach of the licence terms (which normally forbid that sort of thing).

                                M Offline
                                M Offline
                                Mark Hurd
                                wrote on last edited by
                                #30

                                David Skelly wrote:

                                reverse engineering it could be a breach of the licence terms

                                But not in Australia: http://www.austlii.org/au/legis/cth/consol_act/ca1968133/s47d.html[^] and it refers to "adaptation" which is defined here: http://www.austlii.org/au/legis/cth/consol_act/ca1968133/s10.html#adaptation[^] at (ba), and that is a definition of decompilation, let alone reverse engineering in general. Of course the OP is in Germany, so that is irrelevant :-)

                                Regards, Mark Hurd, B.Sc.(Ma.) (Hons.)

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups