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. The Lounge
  3. A quick way to 'protect' your code (or Howto crash Reflector .NET) [modified]

A quick way to 'protect' your code (or Howto crash Reflector .NET) [modified]

Scheduled Pinned Locked Moved The Lounge
csharptutorialphpdotnetvisual-studio
18 Posts 10 Posters 1 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.
  • S Simon P Stevens

    Norm .net wrote:

    It would be a whole lot simpler if everyone coded in IL binary, then they'd be no need for C#,F# VB.net, IL, bytecode, C++, assembly etc.etc... One common lanugage to unite us all.

    FTFY

    Simon

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

    I'm with you on that one.

    Two heads are better than one.

    1 Reply Last reply
    0
    • L Lost User

      leppie wrote:

      (I did report the bug to Redgate though) * Bonus points if someone can tell me how

      You sent them an email???

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #6

      Josh Gray wrote:

      You sent them an email???

      No, I posted a message on their forums. Unless you are completely confused by the *. That is a reference to the * (next to no-way) in my message.

      xacc.ide
      IronScheme - 1.0 RC 1 - out now!
      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

      1 Reply Last reply
      0
      • L leppie

        .method static object Foo(object obj)
        {
        ldarg.0
        dup
        brtrue.s L1
        ret
        L1:
        callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
        ret
        }

        While there is no way***** you can write this in C#, it is still valid and verifiable IL. I picked this up when writing an accessor for chained properties to do null checks without having to store and load from locals (which is a 'tad' more complex than the example shown above). (I did report the bug to Redgate though) * Bonus points if someone can tell me how to emit the above code using the C# compiler

        xacc.ide
        IronScheme - 1.0 RC 1 - out now!
        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

        modified on Thursday, April 22, 2010 6:21 AM

        A Offline
        A Offline
        Adam Maras
        wrote on last edited by
        #7

        I'm versed in .NET and C#, but not CIL. What exactly does this do, and why does it 1) not have a C# equivalent and 2) make Reflector eat shit?

        Adam Maras | Software Developer Microsoft Certified Professional Developer

        L 1 Reply Last reply
        0
        • L leppie

          .method static object Foo(object obj)
          {
          ldarg.0
          dup
          brtrue.s L1
          ret
          L1:
          callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
          ret
          }

          While there is no way***** you can write this in C#, it is still valid and verifiable IL. I picked this up when writing an accessor for chained properties to do null checks without having to store and load from locals (which is a 'tad' more complex than the example shown above). (I did report the bug to Redgate though) * Bonus points if someone can tell me how to emit the above code using the C# compiler

          xacc.ide
          IronScheme - 1.0 RC 1 - out now!
          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

          modified on Thursday, April 22, 2010 6:21 AM

          D Offline
          D Offline
          DaveAuld
          wrote on last edited by
          #8

          Contact form on red-gate.com website? :doh: Just seen your other post, how did you your write this bug is what you were asking..........em, you used your keyboard to enter information onto your computer, thats how :~

          Dave Don't forget to rate messages!
          Find Me On: Web|Facebook|Twitter|LinkedIn
          Waving? dave.m.auld[at]googlewave.com

          L 1 Reply Last reply
          0
          • D DaveAuld

            Contact form on red-gate.com website? :doh: Just seen your other post, how did you your write this bug is what you were asking..........em, you used your keyboard to enter information onto your computer, thats how :~

            Dave Don't forget to rate messages!
            Find Me On: Web|Facebook|Twitter|LinkedIn
            Waving? dave.m.auld[at]googlewave.com

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #9

            That was not the question... I am asking how to create that MSIL code in C#, if possible. I cant think of any way to do so.

            xacc.ide
            IronScheme - 1.0 RC 1 - out now!
            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

            1 Reply Last reply
            0
            • A Adam Maras

              I'm versed in .NET and C#, but not CIL. What exactly does this do, and why does it 1) not have a C# equivalent and 2) make Reflector eat shit?

              Adam Maras | Software Developer Microsoft Certified Professional Developer

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #10
              1. It is similar to:

              static object Foo(object obj)
              {
              if (obj == null)
              {
              return obj;
              }
              return obj.GetType();
              }

              But when you compile this in C#, it will use a bunch of store and load instructions. 1) I am not sure if C# ever emits the dup opcode. 2) Because it is buggy, and you should never trust the output of Reflector's reconstructed C# code :)

              xacc.ide
              IronScheme - 1.0 RC 1 - out now!
              ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

              D 1 Reply Last reply
              0
              • S Simon P Stevens

                Norm .net wrote:

                It would be a whole lot simpler if everyone coded in IL binary, then they'd be no need for C#,F# VB.net, IL, bytecode, C++, assembly etc.etc... One common lanugage to unite us all.

                FTFY

                Simon

                L Offline
                L Offline
                leppie
                wrote on last edited by
                #11

                Binary??? Man, that's so high-level. We should be shorting out transistors with DIP switches!

                xacc.ide
                IronScheme - 1.0 RC 1 - out now!
                ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                S 1 Reply Last reply
                0
                • L leppie

                  .method static object Foo(object obj)
                  {
                  ldarg.0
                  dup
                  brtrue.s L1
                  ret
                  L1:
                  callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
                  ret
                  }

                  While there is no way***** you can write this in C#, it is still valid and verifiable IL. I picked this up when writing an accessor for chained properties to do null checks without having to store and load from locals (which is a 'tad' more complex than the example shown above). (I did report the bug to Redgate though) * Bonus points if someone can tell me how to emit the above code using the C# compiler

                  xacc.ide
                  IronScheme - 1.0 RC 1 - out now!
                  ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                  modified on Thursday, April 22, 2010 6:21 AM

                  S Offline
                  S Offline
                  Super Lloyd
                  wrote on last edited by
                  #12

                  Perhaps.... You can write a small "IL Project" and merge it in your C# assembly! (How To[^] with Visual Studio)

                  A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                  N L 2 Replies Last reply
                  0
                  • S Super Lloyd

                    Perhaps.... You can write a small "IL Project" and merge it in your C# assembly! (How To[^] with Visual Studio)

                    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

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

                    For people who have far too much time on their hands.

                    Two heads are better than one.

                    P 1 Reply Last reply
                    0
                    • L leppie
                      1. It is similar to:

                      static object Foo(object obj)
                      {
                      if (obj == null)
                      {
                      return obj;
                      }
                      return obj.GetType();
                      }

                      But when you compile this in C#, it will use a bunch of store and load instructions. 1) I am not sure if C# ever emits the dup opcode. 2) Because it is buggy, and you should never trust the output of Reflector's reconstructed C# code :)

                      xacc.ide
                      IronScheme - 1.0 RC 1 - out now!
                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                      D Offline
                      D Offline
                      Daniel Grunwald
                      wrote on last edited by
                      #14

                      leppie wrote:

                      I am not sure if C# ever emits the dup opcode.

                      It does. For example, dup occurs when using the "??" operator, or when using the result of an assignment "return v = obj;".

                      L 1 Reply Last reply
                      0
                      • D Daniel Grunwald

                        leppie wrote:

                        I am not sure if C# ever emits the dup opcode.

                        It does. For example, dup occurs when using the "??" operator, or when using the result of an assignment "return v = obj;".

                        L Offline
                        L Offline
                        leppie
                        wrote on last edited by
                        #15

                        Interesting. Thanks :) Unfortunately, one still cannot 'utilize' the stack as I have via C#, not that I think it will make any difference to native code output, just easier to write IL without having to deal with locals as well.

                        xacc.ide
                        IronScheme - 1.0 RC 1 - out now!
                        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                        1 Reply Last reply
                        0
                        • S Super Lloyd

                          Perhaps.... You can write a small "IL Project" and merge it in your C# assembly! (How To[^] with Visual Studio)

                          A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                          L Offline
                          L Offline
                          leppie
                          wrote on last edited by
                          #16

                          Yes, ILMerge is nice. The original IL was generated from C# anyways, I just tweaked it to make it easier to write with Reflection.Emit. :)

                          xacc.ide
                          IronScheme - 1.0 RC 1 - out now!
                          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                          1 Reply Last reply
                          0
                          • N NormDroid

                            For people who have far too much time on their hands.

                            Two heads are better than one.

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

                            Nope; I won't touch it.

                            1 Reply Last reply
                            0
                            • L leppie

                              Binary??? Man, that's so high-level. We should be shorting out transistors with DIP switches!

                              xacc.ide
                              IronScheme - 1.0 RC 1 - out now!
                              ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                              S Offline
                              S Offline
                              Steve Mayfield
                              wrote on last edited by
                              #18

                              I was looking at high end video card last night and the ATI Radeon 9850 has 2.15 billion transistors - I better get started on the driver - flip, flip, no flip.......

                              Steve _________________ I C(++) therefore I am

                              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