A quick way to 'protect' your code (or Howto crash Reflector .NET) [modified]
-
.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 Editionmodified on Thursday, April 22, 2010 6:21 AM
-
.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 Editionmodified on Thursday, April 22, 2010 6:21 AM
-
It would be a whole lot simpler if everyone coded in IL, then they'd be no need for C#,F# VB.net etc.etc... One common lanugage to unite us all.
Two heads are better than one.
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
-
.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 Editionmodified on Thursday, April 22, 2010 6:21 AM
-
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
-
leppie wrote:
(I did report the bug to Redgate though) * Bonus points if someone can tell me how
You sent them an email???
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 -
.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 Editionmodified on Thursday, April 22, 2010 6:21 AM
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
-
.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 Editionmodified on Thursday, April 22, 2010 6:21 AM
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 -
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.comThat 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 -
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
- 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 -
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
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 -
.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 Editionmodified on Thursday, April 22, 2010 6:21 AM
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.
-
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.
-
- 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 Editionleppie 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;
". -
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;
".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 -
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.
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 -
Nope; I won't touch it.
-
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 EditionI 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