SlideShare a Scribd company logo
1 of 20
Download to read offline
Understanding CIL
James Crowley
Developer Fusion
http://www.developerfusion.co.uk/
Overview
 Generating and understanding CIL
 De-compiling CIL
 Protecting against de-compilation
 Merging assemblies
Common Language Runtime (CLR)
 Core component of the .NET Framework
on which everything else is built.
 A runtime environment which provides
A unified type system
Metadata
Execution engine, that deals with programs
written in a Common Intermediate Language
(CIL)
Common Intermediate Language
 All compilers targeting the CLR translate
their source code into CIL
 A kind of assembly language for an
abstract stack-based machine, but is not
specific to any hardware architecture
 Includes instructions specifically designed
to support object-oriented concepts
Platform Independence
 The intermediate language is not interpreted, but
is not platform specific.
 The CLR uses JIT (Just-in-time) compilation to
translate the CIL into native code
 Applications compiled in .NET can be moved to
any machine, providing there is a CLR
implementation for it (Mono, SSCLI etc)
Demo
 Generating IL using the C# compiler
Some familiar keywords with some additions:
.method – this is a method
hidebysig – the method hides other methods with
the same name and signature.
cil managed – written in CIL and should be
executed by the execution engine (C++ allows
portions that are not)
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 31 (0x1f)
.maxstack 2
.locals init (int32 V_0,
int32 V_1,
int32 V_2)
IL_0000: ldc.i4.s 50
IL_0002: stloc.0
IL_0003: ldc.i4.s 20
IL_0005: stloc.1
IL_0006: ldloc.0
IL_0007: ldloc.1
IL_0008: call int32 ILDemo.Demo::Remainder(int32,
int32)
IL_000d: stloc.2
IL_000e: ldstr "Remainder is: {0}"
IL_0013: ldloc.2
IL_0014: box [mscorlib]System.Int32
IL_0019: call void [mscorlib]System.Console::WriteLine(string,
object)
IL_001e: ret
} // end of method Demo::Main
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 31 (0x1f)
.maxstack 2
.locals init (int32 V_0,
int32 V_1,
int32 V_2)
IL_0000: ldc.i4.s 50
IL_0002: stloc.0
IL_0003: ldc.i4.s 20
IL_0005: stloc.1
IL_0006: ldloc.0
IL_0007: ldloc.1
IL_0008: call int32 ILDemo.Demo::Remainder(int32,
int32)
IL_000d: stloc.2
IL_000e: ldstr "Remainder is: {0}"
IL_0013: ldloc.2
IL_0014: box [mscorlib]System.Int32
IL_0019: call void [mscorlib]System.Console::WriteLine(string,
object)
IL_001e: ret
} // end of method Demo::Main
.entrypoint – the program’s entry point
.maxstack 2 – specifies maximum depth of the
stack at any point during execution
.locals – defines storage locations for variables
local to this method, with new names V_0, V_1,
V_2 (replacing a, b, result)
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 31 (0x1f)
.maxstack 2
.locals init (int32 V_0,
int32 V_1,
int32 V_2)
IL_0000: ldc.i4.s 50
IL_0002: stloc.0
IL_0003: ldc.i4.s 20
IL_0005: stloc.1
IL_0006: ldloc.0
IL_0007: ldloc.1
IL_0008: call int32 ILDemo.Demo::Remainder(int32,
int32)
IL_000d: stloc.2
IL_000e: ldstr "Remainder is: {0}"
IL_0013: ldloc.2
IL_0014: box [mscorlib]System.Int32
IL_0019: call void [mscorlib]System.Console::WriteLine(string,
object)
IL_001e: ret
} // end of method Demo::Main
ldc.i4.s – loads the 4-byte integer constant “50”
onto the stack (“s” defines some additional
behaviours to keep the number of op-codes down)
stloc.0 – takes the top value on the stack (ie 50)
and stores it in the local variable at index 0 (ie V_0,
or “a” with our original naming)
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 31 (0x1f)
.maxstack 2
.locals init (int32 V_0,
int32 V_1,
int32 V_2)
IL_0000: ldc.i4.s 50
IL_0002: stloc.0
IL_0003: ldc.i4.s 20
IL_0005: stloc.1
IL_0006: ldloc.0
IL_0007: ldloc.1
IL_0008: call int32 ILDemo.Demo::Remainder(int32,
int32)
IL_000d: stloc.2
IL_000e: ldstr "Remainder is: {0}"
IL_0013: ldloc.2
IL_0014: box [mscorlib]System.Int32
IL_0019: call void [mscorlib]System.Console::WriteLine(string,
object)
IL_001e: ret
} // end of method Demo::Main
ldloc.0 and ldloc.1 – loads the value of the local
variable at index 0 (“a”) and index 1 (“b”) onto the
stack
call – makes a call to our Remainder method. The
two arguments are popped off the stack during the
call, and we get the result of the method execution
pushed back on.
Stloc.2 – store the result (which is at the top of the
stack) in local variable at index 2 (“result”)
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 31 (0x1f)
.maxstack 2
.locals init (int32 V_0,
int32 V_1,
int32 V_2)
IL_0000: ldc.i4.s 50
IL_0002: stloc.0
IL_0003: ldc.i4.s 20
IL_0005: stloc.1
IL_0006: ldloc.0
IL_0007: ldloc.1
IL_0008: call int32 ILDemo.Demo::Remainder(int32,
int32)
IL_000d: stloc.2
IL_000e: ldstr "Remainder is: {0}"
IL_0013: ldloc.2
IL_0014: box [mscorlib]System.Int32
IL_0019: call void [mscorlib]System.Console::WriteLine(string,
object)
IL_001e: ret
} // end of method Demo::Main
ldstr – loads the string constant onto a stack
ldloc.2 – loads the variable “result” onto the stack
box – turns the “result” variable (a value type) into
an object (reference type)
call – makes the call to WriteLine
ret – returns execution to the callee
Things to note…
 Optimisation largely occurs at the JIT
compilation stage, rather than when we
are generating IL – so that all languages
targeting the CLR can benefit.
 The underlying IL contains all the info
required to reconstruct your original
source code (minus comments and
variable names)
Demo
 Decompilation using .NET Reflector
De-compilation & Obfuscation
 Can’t easily prevent code from being
decompiled, but we can make it harder to
“understand” the intention of the code.
 Various techniques, including
variable renaming
control flow obfuscation
string encryption
Obfuscation Software
 PreEmptive - Dotfuscator (basic
community edition included in VS 2003)
 Remotesoft Obfuscator
 WiseOwl - Demeanor for .NET
Merging Assemblies
 We can combine the IL of multiple
assemblies to combine assemblies,
without access to the original source code
 For example, merging a required COM
interop wrapper into our main assembly.
ILMerge
 Utility from Microsoft Research that
automatically merges the IL and re-
compiles the assembly.
Demo
 Merging Assemblies
Wrapping Up
 Any questions?
Why do we care?
 Decompilation
 The underlying IL contains all the info required to reconstruct
your original source code (minus comments and variable names)
 .NET Reflector
 ILDASM/ILASM
 Merging multiple assemblies
 We can merge assemblies by merging their IL (ILMerge)
 New Languages
 We can implement new .NET languages provided we can emit
the correct IL

More Related Content

What's hot

FPGA design with CλaSH
FPGA design with CλaSHFPGA design with CλaSH
FPGA design with CλaSHConrad Parker
 
Python Part 1
Python Part 1Python Part 1
Python Part 1Sunil OS
 
Arduino C maXbox web of things slide show
Arduino C maXbox web of things slide showArduino C maXbox web of things slide show
Arduino C maXbox web of things slide showMax Kleiner
 
Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Raimon Ràfols
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixirbrien_wankel
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2ytoshima
 
The bytecode gobbledygook
The bytecode gobbledygookThe bytecode gobbledygook
The bytecode gobbledygookRaimon Ràfols
 
constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++HalaiHansaika
 
Python-oop
Python-oopPython-oop
Python-oopRTS Tech
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingRTS Tech
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorJussi Pohjolainen
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
Accelerating Habanero-Java Program with OpenCL Generation
Accelerating Habanero-Java Program with OpenCL GenerationAccelerating Habanero-Java Program with OpenCL Generation
Accelerating Habanero-Java Program with OpenCL GenerationAkihiro Hayashi
 
Giorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio Zoppi
 
C __paper.docx_final
C __paper.docx_finalC __paper.docx_final
C __paper.docx_finalSumit Sar
 

What's hot (20)

Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
FPGA design with CλaSH
FPGA design with CλaSHFPGA design with CλaSH
FPGA design with CλaSH
 
OOP Core Concept
OOP Core ConceptOOP Core Concept
OOP Core Concept
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
Arduino C maXbox web of things slide show
Arduino C maXbox web of things slide showArduino C maXbox web of things slide show
Arduino C maXbox web of things slide show
 
Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
Java Quiz
Java QuizJava Quiz
Java Quiz
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
 
The bytecode gobbledygook
The bytecode gobbledygookThe bytecode gobbledygook
The bytecode gobbledygook
 
constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++
 
Python-oop
Python-oopPython-oop
Python-oop
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
Qno 1 (c)
Qno 1 (c)Qno 1 (c)
Qno 1 (c)
 
Accelerating Habanero-Java Program with OpenCL Generation
Accelerating Habanero-Java Program with OpenCL GenerationAccelerating Habanero-Java Program with OpenCL Generation
Accelerating Habanero-Java Program with OpenCL Generation
 
ECAD lab manual
ECAD lab manualECAD lab manual
ECAD lab manual
 
Giorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrency
 
C __paper.docx_final
C __paper.docx_finalC __paper.docx_final
C __paper.docx_final
 

Similar to Understanding the Common Intermediate Language (CIL)

Common Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by ExampleCommon Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by ExampleGanesh Samarthyam
 
How to capture a variable in C# and not to shoot yourself in the foot
How to capture a variable in C# and not to shoot yourself in the footHow to capture a variable in C# and not to shoot yourself in the foot
How to capture a variable in C# and not to shoot yourself in the footSofia Fateeva
 
How to capture a variable in C# and not to shoot yourself in the foot
How to capture a variable in C# and not to shoot yourself in the footHow to capture a variable in C# and not to shoot yourself in the foot
How to capture a variable in C# and not to shoot yourself in the footPVS-Studio
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationWei-Ren Chen
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building BlocksMax Kleiner
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxgopikahari7
 
Digital design with Systemc
Digital design with SystemcDigital design with Systemc
Digital design with SystemcMarc Engels
 
How to design Programs using VHDL
How to design Programs using VHDLHow to design Programs using VHDL
How to design Programs using VHDLEutectics
 
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...Yandex
 
Finfisher- Nguyễn Chấn Việt
Finfisher- Nguyễn Chấn ViệtFinfisher- Nguyễn Chấn Việt
Finfisher- Nguyễn Chấn ViệtSecurity Bootcamp
 
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery BoardProgramming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery BoardGaurav Verma
 
Bh Usa 07 Butler And Kendall
Bh Usa 07 Butler And KendallBh Usa 07 Butler And Kendall
Bh Usa 07 Butler And KendallKarlFrank99
 

Similar to Understanding the Common Intermediate Language (CIL) (20)

Overview Of Msil
Overview Of MsilOverview Of Msil
Overview Of Msil
 
The zen of async: Best practices for best performance
The zen of async: Best practices for best performanceThe zen of async: Best practices for best performance
The zen of async: Best practices for best performance
 
MattsonTutorialSC14.pdf
MattsonTutorialSC14.pdfMattsonTutorialSC14.pdf
MattsonTutorialSC14.pdf
 
Common Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by ExampleCommon Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by Example
 
How to capture a variable in C# and not to shoot yourself in the foot
How to capture a variable in C# and not to shoot yourself in the footHow to capture a variable in C# and not to shoot yourself in the foot
How to capture a variable in C# and not to shoot yourself in the foot
 
How to capture a variable in C# and not to shoot yourself in the foot
How to capture a variable in C# and not to shoot yourself in the footHow to capture a variable in C# and not to shoot yourself in the foot
How to capture a variable in C# and not to shoot yourself in the foot
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building Blocks
 
ASP.NET core
ASP.NET coreASP.NET core
ASP.NET core
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
 
Digital design with Systemc
Digital design with SystemcDigital design with Systemc
Digital design with Systemc
 
How to design Programs using VHDL
How to design Programs using VHDLHow to design Programs using VHDL
How to design Programs using VHDL
 
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
 
COM Introduction
COM IntroductionCOM Introduction
COM Introduction
 
01 dll basics
01 dll basics01 dll basics
01 dll basics
 
Finfisher- Nguyễn Chấn Việt
Finfisher- Nguyễn Chấn ViệtFinfisher- Nguyễn Chấn Việt
Finfisher- Nguyễn Chấn Việt
 
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery BoardProgramming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
Programming the ARM CORTEX M3 based STM32F100RBT6 Value Line Discovery Board
 
Bh Usa 07 Butler And Kendall
Bh Usa 07 Butler And KendallBh Usa 07 Butler And Kendall
Bh Usa 07 Butler And Kendall
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 

Recently uploaded

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Understanding the Common Intermediate Language (CIL)

  • 1. Understanding CIL James Crowley Developer Fusion http://www.developerfusion.co.uk/
  • 2. Overview  Generating and understanding CIL  De-compiling CIL  Protecting against de-compilation  Merging assemblies
  • 3. Common Language Runtime (CLR)  Core component of the .NET Framework on which everything else is built.  A runtime environment which provides A unified type system Metadata Execution engine, that deals with programs written in a Common Intermediate Language (CIL)
  • 4. Common Intermediate Language  All compilers targeting the CLR translate their source code into CIL  A kind of assembly language for an abstract stack-based machine, but is not specific to any hardware architecture  Includes instructions specifically designed to support object-oriented concepts
  • 5. Platform Independence  The intermediate language is not interpreted, but is not platform specific.  The CLR uses JIT (Just-in-time) compilation to translate the CIL into native code  Applications compiled in .NET can be moved to any machine, providing there is a CLR implementation for it (Mono, SSCLI etc)
  • 6. Demo  Generating IL using the C# compiler
  • 7. Some familiar keywords with some additions: .method – this is a method hidebysig – the method hides other methods with the same name and signature. cil managed – written in CIL and should be executed by the execution engine (C++ allows portions that are not) .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // Code size 31 (0x1f) .maxstack 2 .locals init (int32 V_0, int32 V_1, int32 V_2) IL_0000: ldc.i4.s 50 IL_0002: stloc.0 IL_0003: ldc.i4.s 20 IL_0005: stloc.1 IL_0006: ldloc.0 IL_0007: ldloc.1 IL_0008: call int32 ILDemo.Demo::Remainder(int32, int32) IL_000d: stloc.2 IL_000e: ldstr "Remainder is: {0}" IL_0013: ldloc.2 IL_0014: box [mscorlib]System.Int32 IL_0019: call void [mscorlib]System.Console::WriteLine(string, object) IL_001e: ret } // end of method Demo::Main
  • 8. .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // Code size 31 (0x1f) .maxstack 2 .locals init (int32 V_0, int32 V_1, int32 V_2) IL_0000: ldc.i4.s 50 IL_0002: stloc.0 IL_0003: ldc.i4.s 20 IL_0005: stloc.1 IL_0006: ldloc.0 IL_0007: ldloc.1 IL_0008: call int32 ILDemo.Demo::Remainder(int32, int32) IL_000d: stloc.2 IL_000e: ldstr "Remainder is: {0}" IL_0013: ldloc.2 IL_0014: box [mscorlib]System.Int32 IL_0019: call void [mscorlib]System.Console::WriteLine(string, object) IL_001e: ret } // end of method Demo::Main .entrypoint – the program’s entry point .maxstack 2 – specifies maximum depth of the stack at any point during execution .locals – defines storage locations for variables local to this method, with new names V_0, V_1, V_2 (replacing a, b, result)
  • 9. .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // Code size 31 (0x1f) .maxstack 2 .locals init (int32 V_0, int32 V_1, int32 V_2) IL_0000: ldc.i4.s 50 IL_0002: stloc.0 IL_0003: ldc.i4.s 20 IL_0005: stloc.1 IL_0006: ldloc.0 IL_0007: ldloc.1 IL_0008: call int32 ILDemo.Demo::Remainder(int32, int32) IL_000d: stloc.2 IL_000e: ldstr "Remainder is: {0}" IL_0013: ldloc.2 IL_0014: box [mscorlib]System.Int32 IL_0019: call void [mscorlib]System.Console::WriteLine(string, object) IL_001e: ret } // end of method Demo::Main ldc.i4.s – loads the 4-byte integer constant “50” onto the stack (“s” defines some additional behaviours to keep the number of op-codes down) stloc.0 – takes the top value on the stack (ie 50) and stores it in the local variable at index 0 (ie V_0, or “a” with our original naming)
  • 10. .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // Code size 31 (0x1f) .maxstack 2 .locals init (int32 V_0, int32 V_1, int32 V_2) IL_0000: ldc.i4.s 50 IL_0002: stloc.0 IL_0003: ldc.i4.s 20 IL_0005: stloc.1 IL_0006: ldloc.0 IL_0007: ldloc.1 IL_0008: call int32 ILDemo.Demo::Remainder(int32, int32) IL_000d: stloc.2 IL_000e: ldstr "Remainder is: {0}" IL_0013: ldloc.2 IL_0014: box [mscorlib]System.Int32 IL_0019: call void [mscorlib]System.Console::WriteLine(string, object) IL_001e: ret } // end of method Demo::Main ldloc.0 and ldloc.1 – loads the value of the local variable at index 0 (“a”) and index 1 (“b”) onto the stack call – makes a call to our Remainder method. The two arguments are popped off the stack during the call, and we get the result of the method execution pushed back on. Stloc.2 – store the result (which is at the top of the stack) in local variable at index 2 (“result”)
  • 11. .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // Code size 31 (0x1f) .maxstack 2 .locals init (int32 V_0, int32 V_1, int32 V_2) IL_0000: ldc.i4.s 50 IL_0002: stloc.0 IL_0003: ldc.i4.s 20 IL_0005: stloc.1 IL_0006: ldloc.0 IL_0007: ldloc.1 IL_0008: call int32 ILDemo.Demo::Remainder(int32, int32) IL_000d: stloc.2 IL_000e: ldstr "Remainder is: {0}" IL_0013: ldloc.2 IL_0014: box [mscorlib]System.Int32 IL_0019: call void [mscorlib]System.Console::WriteLine(string, object) IL_001e: ret } // end of method Demo::Main ldstr – loads the string constant onto a stack ldloc.2 – loads the variable “result” onto the stack box – turns the “result” variable (a value type) into an object (reference type) call – makes the call to WriteLine ret – returns execution to the callee
  • 12. Things to note…  Optimisation largely occurs at the JIT compilation stage, rather than when we are generating IL – so that all languages targeting the CLR can benefit.  The underlying IL contains all the info required to reconstruct your original source code (minus comments and variable names)
  • 14. De-compilation & Obfuscation  Can’t easily prevent code from being decompiled, but we can make it harder to “understand” the intention of the code.  Various techniques, including variable renaming control flow obfuscation string encryption
  • 15. Obfuscation Software  PreEmptive - Dotfuscator (basic community edition included in VS 2003)  Remotesoft Obfuscator  WiseOwl - Demeanor for .NET
  • 16. Merging Assemblies  We can combine the IL of multiple assemblies to combine assemblies, without access to the original source code  For example, merging a required COM interop wrapper into our main assembly.
  • 17. ILMerge  Utility from Microsoft Research that automatically merges the IL and re- compiles the assembly.
  • 19. Wrapping Up  Any questions?
  • 20. Why do we care?  Decompilation  The underlying IL contains all the info required to reconstruct your original source code (minus comments and variable names)  .NET Reflector  ILDASM/ILASM  Merging multiple assemblies  We can merge assemblies by merging their IL (ILMerge)  New Languages  We can implement new .NET languages provided we can emit the correct IL