C
C#โ€ข2y ago
ogie1985

โ” How to reverse engineer your simple console app code?

Just curious. Is this possible with programs like x64dbg or... ?
67 Replies
Thinker
Thinkerโ€ข2y ago
You can use ILSpy or similar to open your DLL or EXE and view the IL code C# is ridiculously easy to reverse-engineer
ogie1985
ogie1985OPโ€ข2y ago
Maybe some background info from me: I see people doing stuff with x64dbg but this is not intented to reverse-engineer c# stuff?
Thinker
Thinkerโ€ข2y ago
I have no idea what x64dbg is
ogie1985
ogie1985OPโ€ข2y ago
Thinker
Thinkerโ€ข2y ago
ah, so an ASM viewer
ogie1985
ogie1985OPโ€ข2y ago
Didn't know there was a word for that
Thinker
Thinkerโ€ข2y ago
Well, C# compiles to IL, which looks kind of like ASM but more high-level. IL is a binary format which is emitted directly into DLL or EXE files by the C# compiler, which means that you can use a program like ILSpy which allows you to view the IL binary in an ASM-like format, and even as C# code. You can also go to Sharplab.io if you want to see the IL generated by some simple code
MODiX
MODiXโ€ข2y ago
thinker227#5176
sharplab.io (click here)
Console.WriteLine("Hello, world!");
Console.WriteLine("Hello, world!");
React with โŒ to remove this embed.
ogie1985
ogie1985OPโ€ข2y ago
Ohh I see. So IL is also called managed code right?
Thinker
Thinkerโ€ข2y ago
Afaik "managed code" refers to something else unrelated to IL
ogie1985
ogie1985OPโ€ข2y ago
Hmm reading this book C# in a nutshell and this sentence over here says: "C# is called a managed language because it compiles source code into managed code, which is represented in Intermediate Language (IL)"
x0rld ๐Ÿ‘ป ๐ŸŽƒ
for me it's managed because there is a garbage collector ๐Ÿค”
Thinker
Thinkerโ€ข2y ago
I think "managed" might just refer to the fact that there is an runtime Although you're better off asking about that in #allow-unsafe-blocks You can write unmanaged code if you just don't use managed types (everything that isn't a reference type or contains reference types as fields)
ogie1985
ogie1985OPโ€ข2y ago
I need to get a better understanding of this JIT thing. Because that "ASM Viewer" looks alot like that jit in sharplab.io
Thinker
Thinkerโ€ข2y ago
JIT is the ASM code that the Just In Time compiler generates at runtime
ogie1985
ogie1985OPโ€ข2y ago
So from what I've read and understand is that your code compiles to IL and the CLR converts it to JIT ?
Thinker
Thinkerโ€ข2y ago
You write C#, the C# gets compiled into IL by the compiler, the runtime runs the IL by running it through the JIT which turns the IL into machine code at runtime.
ogie1985
ogie1985OPโ€ข2y ago
ohhhh
Thinker
Thinkerโ€ข2y ago
Although there is also native Ahead Of Time (AOT) which compiles C# directly to architecture-specific machine code
ogie1985
ogie1985OPโ€ข2y ago
Ok, ok. That's a bit to deep :D. But I had a feeling that I had to understand this first to start reverse engineer stuff
x0rld ๐Ÿ‘ป ๐ŸŽƒ
just use ILSpy for classic program
Thinker
Thinkerโ€ข2y ago
Although be aware that depending on what you reverse engineer, it may or may not be against the terms of service of that thing. Although who tf cares about tos anyway.
ogie1985
ogie1985OPโ€ข2y ago
haha, yeah true. But btw it's just my own console app which i'm trying to run trough that I'll give a little sneakpeak of what i'm trying to accomplish
ogie1985
ogie1985OPโ€ข2y ago
ogie1985
ogie1985OPโ€ข2y ago
Trying to run this trough that program and I want to change the program via that tool to hit the first if statement But all I see is machine code with zero string references of what I'm showing lmao
ACiDCA7
ACiDCA7โ€ข2y ago
or from ilspy
ACiDCA7
ACiDCA7โ€ข2y ago
ogie1985
ogie1985OPโ€ข2y ago
I'll download ilspy realquick but I assume you cant change the behaviour of ur .exe
ACiDCA7
ACiDCA7โ€ข2y ago
you could use dnspy its ilspy but can debug runnign process meaning change variables on runtime theoretically you could also change the code, but it never worked for me^^ while i am at it.. i guess you are using visual studio to develop.. it can decompile aswell
ogie1985
ogie1985OPโ€ข2y ago
hmmm
x0rld ๐Ÿ‘ป ๐ŸŽƒ
there is a plugin to install ILSpy as a plugin in VS
ogie1985
ogie1985OPโ€ข2y ago
itneresting
ogie1985
ogie1985OPโ€ข2y ago
howCode
YouTube
Simple Reverse Engineering on Windows
In this video we'll be learning how to use simple reverse engineering techniques to see inside a Windows EXE and manipulate it. The program we'll be looking at asks for a secret code, we'll be manipulating the program to make it accept any code we give it. Go to https://howcode.org for more! Link to the program we'll be manipulating: http://h...
ogie1985
ogie1985OPโ€ข2y ago
if u skip to 6:32 that's exactly what im trying to do well sort of so u can basically open the .exe in vs studio and change code ?
x0rld ๐Ÿ‘ป ๐ŸŽƒ
you cannot change it with ilspy
ogie1985
ogie1985OPโ€ข2y ago
for my examply with IL spy you can change make it so it runs the first if statement?
MODiX
MODiXโ€ข2y ago
Ogie#1985
From Ogie#1985
React with โŒ to remove this embed.
x0rld ๐Ÿ‘ป ๐ŸŽƒ
well looks like you can change things with ilspy with the video you linked ๐Ÿค” never tried ยฏ\_(ใƒ„)_/ยฏ looks like ILSpy can edit the ILCode and you can export it after with save as
ACiDCA7
ACiDCA7โ€ข2y ago
if you look more closely in the vid he is using reflexil to change the il
x0rld ๐Ÿ‘ป ๐ŸŽƒ
oh yeah it's a plugin ? ๐Ÿค”
ACiDCA7
ACiDCA7โ€ข2y ago
GitHub
GitHub - sailro/Reflexil: The .NET Assembly Editor
The .NET Assembly Editor. Contribute to sailro/Reflexil development by creating an account on GitHub.
x0rld ๐Ÿ‘ป ๐ŸŽƒ
so just use that ogie
ogie1985
ogie1985OPโ€ข2y ago
Ilspy with reflexil okay Many people use x64dbg for some reason but hmm
ACiDCA7
ACiDCA7โ€ข2y ago
x64dbg is for native apps
ogie1985
ogie1985OPโ€ข2y ago
What do you mean with native apps?
x0rld ๐Ÿ‘ป ๐ŸŽƒ
C or C++ or anything compiled to native
ogie1985
ogie1985OPโ€ข2y ago
ohh nvm
Thinker
Thinkerโ€ข2y ago
apps containing native machine code
ogie1985
ogie1985OPโ€ข2y ago
isn't the console app converted to machine code after publishing ?
x0rld ๐Ÿ‘ป ๐ŸŽƒ
nop it's ILCode
Thinker
Thinkerโ€ข2y ago
C# is compiled to IL
ogie1985
ogie1985OPโ€ข2y ago
i see so the clr covnerts il to native code of the machine
ogie1985
ogie1985OPโ€ข2y ago
yeah ok
x0rld ๐Ÿ‘ป ๐ŸŽƒ
yeah
ogie1985
ogie1985OPโ€ข2y ago
hmmmmm Ok my theory was if it could get converted to machine code somehow you were able to do stuff with x64dbg on that simple console app
Thinker
Thinkerโ€ข2y ago
just use ILSpy
ogie1985
ogie1985OPโ€ข2y ago
I give up on x64dbg going to try ilspy now
x0rld ๐Ÿ‘ป ๐ŸŽƒ
at the runtime there is at some point machine code but it's clearly easier to manipulate ILCode
Thinker
Thinkerโ€ข2y ago
If you try to use x64dbg on IL then you'll just end up with garbage
ogie1985
ogie1985OPโ€ข2y ago
Reflexil doesn't work with latest version of ilspy or a tleast preview version I guess I'll just wait. Cba uninstalling and downgrading versions Thanks man dnspy did the job well I thought that editing the file/ change code would work but nvm
Monsieur Wholesome
Monsieur Wholesomeโ€ข2y ago
dnspy for the win dips
ogie1985
ogie1985OPโ€ข2y ago
naa dnspy had the option te modify code but it doesn't compile ๐Ÿ˜’ only solution is left to downgrade il spy and get reflixit for it but i guess ill open an issue on dn spy repo
ogie1985
ogie1985OPโ€ข2y ago
tldr; dnspy is waiting for release version 8 of ilspy. After that dnspy will be upodated to edit code. Huge source: https://github.com/dnSpyEx/dnSpy/discussions/149
ogie1985
ogie1985OPโ€ข2y ago
Also for context: dnspy publicly archived but dnSpyEx is an (fork) continuation of the dnSpy repo No one knows why the heck main repo closed but assumptions are buyouts and to remain silent
Accord
Accordโ€ข2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server