Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
.NET Day 2019 - Abusing the C# compiler by Fili...
Search
.NET Day
May 28, 2019
Technology
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
.NET Day 2019 - Abusing the C# compiler by Filip Wojcieszyn
.NET Day
May 28, 2019
More Decks by .NET Day
See All by .NET Day
.NET Day 2025: How to Lie with AI: Understanding Bias, Ethics, and the Hidden Risks in Machine Learning
dotnetday
0
40
.NET Day 2025: Most Expensive Design Mistakes (Ever) and how to avoid them
dotnetday
0
59
.NET Day 2025: Turbocharged: Writing High-Performance C# and .NET Code
dotnetday
0
64
.NET Day 2025: Developing ASP.NET Core Microservices with Dapr: A practical guide
dotnetday
0
51
.NET Day 2025: Enhancing Legal Document Analysis with Reflection Agents, Semantic Kernel, and Azure AI Search
dotnetday
0
37
.NET Day 2025: Future-Proof Your Blazor Apps with bUnit
dotnetday
0
34
.NET Day 2025: .NET Core Testing: pushing the limits
dotnetday
0
55
.NET Day 2025: The best ways to use the latest OpenAPI features in .NET 9!
dotnetday
0
50
.NET Day 2025: Supercharged Search with Semantic Search and Vector Embeddings
dotnetday
0
41
Other Decks in Technology
See All in Technology
PLATEAU で バーチャル花火大会
tatsuya1970
0
150
Breaking the Seal: Static Deobfuscation of Compiled V8 JavaScript Bytecode Malware
hshrzd
0
740
Forza Horizon 6 のテレメトリ機能で 自動運転に使えそうな学習データを集める話
henjin0
0
170
SO-101×VLAによる3色キューブのピック&プレース
abeja
0
190
FDEの心得
noriakioji
4
5k
私がブラウザを自作したくなった理由
supurazako
1
210
モバイルアプリ開発概論2026
recruitengineers
PRO
5
580
事業価値と Engineering 2026年度版
recruitengineers
PRO
49
23k
生成 AI の基礎 〜 サンプル実装で学ぶ基本原理
enakai00
7
4.4k
DatadogのBits Chatが開発組織にもたらしたもの / What Bits Chat Has Brought Us
sms_tech
1
260
ラジオの科学
frievea
0
300
ガバメントクラウドでのランサムウェア対策
techniczna
2
1.2k
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
Being A Developer After 40
akosma
91
590k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Mind Mapping
helmedeiros
PRO
1
310
We Are The Robots
honzajavorek
0
300
New Earth Scene 8
popppiees
3
2.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
610
Transcript
Abusing the C# Abusing the C# Compiler Compiler for fun
and no pro t for fun and no pro t
Filip W Filip W a random guy from the internet
• • strathweb.com @ lip_woj github.com/ lipw
None
What will we What will we learn? learn?
Nothing.
We will however see, that it doesn't take a lot
to violate the rules of C#.
C# Compiler C# Compiler
None
“ Compiler is the guardian of the integrity of the
language.
C# 6 Draft Spec Reading C# 6 Draft Spec Reading
High level C# building blocks High level C# building blocks
C# Languague Speci cation ECMA Standard, ~500 pages ⚙ Roslyn Compiler compiles C# code to Common Intermediate Language Tooling powered by the C# Compiler CLR / CoreCLR compiles CIL to machine code
Can you trust the Can you trust the compiler? compiler?
- Mads Torgersen, C# Lead Designer “ Customers will depend
on the new compiler behaving exactly the same way as the old one. Writing a new compiler for C# means trying to match the old compiler bug-for-bug.
Invalid C#, compiler error Invalid C#, compiler error static class
Foo {} class Bar { // error CS0722: 'Foo': static types cannot be used as return types Foo GetFoo() => null; }
Invalid C#, no compiler error Invalid C#, no compiler error
static class Foo {} interface IBar { // compiles fine Foo GetFoo(); }
Can the compiler produce a program that won't work? Yes
Let's assume that the code is 100% error free. Still
yes
Language Spec Compiler Runtime
Can the runtime allow you to violate the C# language
speci cation? Yes
Language Spec Compiler Runtime
- Eric Lippert “ A common technique (...) is to
have the compiler “lower” from high-level language features to low-level language features in the same language.
C# using block C# using block using(new C()) { //
do stuff }
Emitted IL Emitted IL IL_0000: nop IL_0001: newobj instance void
C::.ctor() IL_0006: stloc.0 .try { IL_0007: nop IL_0008: nop IL_0009: leave.s IL_0016 } // end .try finally { // sequence point: hidden IL_000b: ldloc.0 IL_000c: brfalse.s IL_0015 IL_000e: ldloc.0 IL_000f: callvirt instance void [mscorlib]System.IDisposable::Dispose() IL_0014: nop // sequence point: hidden IL_0015: endfinally } // end handler
“ This method terminates a process without running any active
try/ nally blocks or nalizers. - Environment.FailFast(...)
So far we have managed to So far we have
managed to ✅ Create an instance without calling a constructor ✅ Bypass a ' nally' clause ✅ Create an instance of an open generic
Can the compiler produce code that doesn’t behave as expected?
Yes
Language Spec Compiler Runtime
How badly can you abuse the language and the compiler?
Very badly
Language Spec Compiler Runtime
Thank you Thank you See you next year! lipw.github.io/dotnetday-zurich-2019 github.com/
lipw/2019-switzerland- netday-demos