How to combine many CS files into a DLL file? - c#

Basically what I'm trying to do is this:
1: Take an existing DLL file.
2: Edit some C# scripts inside. I'm doing this by using DotPeek to open in Visual Studio.
3: After editing the files, put them back into the original DLL file so the program works fine (modified by me).
So now I'm stuck on the last step, getting the files back into the DLL file so the program works. Any ideas? THANK YOU.

Extract all the source files from the dll, assemble a .csproj, and build it the same way as any other dll. That's the way I've done it. I'm sure there's some way to squirt individual types into the dll, but depending on the complexity of the dll, my method might be easiest (or completely impractical)

Related

How to reverse engineer an .exe that uses a .resource file to store an assembly?

Context
I work as a game developer at a studio that develops an MMO. We built an authoritative server but still run into issues with exploits and automation. I downloaded the main bot used to hack our game in an effort to determine how it exploits our server so we can patch accordingly.
Question
I decompiled the .exe using dotPeek to get the source files but ran into an issue: I only got the source files for the launcher. The launcher injects the core assembly into our application at runtime. It does so by storing the assembly as hex data in a .resource file. Any idea of how I can get the source code from this .resource file?
Solution
Thanks for everyone's help. I got the source files by extracting the binary data from the .resource file and writing it to a .dll file and then decompiling it using dotPeek. See my solution for more details.
Shouldn't you be able to use GetManifestResourceStream to get the embedded data?
Thanks everyone for the help - a combination of using a decompiler and reading the binary assembly data at runtime and writing it to a .dll file helped me get the source code:
I used dotPeek to decompile the launcher. In assembly explorer, I then right clicked the assembly and selected Export to Project... I then opened the project in Visual Studio and inserted a line that used File.WriteAllBytes to write the the byte[] (already available via their application, but this just got the binary data from the .resource file using ResourceManager.GetObject) to a .dll file. I then opened that .dll file in dotPeek and wala - source code visible.
I recommend designing around the problem, a kind of soft-captcha enforced by the server. The truth of your problem is: .Net is open to extension. Rather than engage in a 'cat and mouse arms race' around the client exe, think about how you detect non-human activity, or how to randomly demand human-only activity.
If your game is worth the attention, they will overcome you. They are many :)

How to merge several Visual Studio projects in 1 Launcher project

So i made 6 different little applications each in its own Project.
And my idea is now to build some kind of Launcher with 6 buttons each of them launching their respectives applications.
I know how to /Add/Existing Projects/Select Project, but my worry is more upon managing to run those application on a Button_Click.
I'm thinking about copy/paste-ing my .cs files of each apps, and their resources.
Should I ? Shouldn't I ?
What would be the best thing to do ?
EDIT1
Well, as i said, my apps are very small, i mean like very very small. It's mostly about automating templates mails sendings and opening/closing reports.
All my apps are in a single form each and they only refer to .png or .txt to store datas or dress up fancy-ish reports with images.
Right now, I'm in the process of importing FormX.cs one by one, as NonStatic said, re-referencing the UI and renaming some functions. I did 2 so far, and i'm hitting a generic file path issue.
I'm not sure how ressources are working once the .exe is built. Are they "embed" whereever the ressources file is located ? (Resources folder, or ..\bin\debug) or should i be carefull with this and systematicly put tehm in some specific folder ?
Also, thanks for your point Zdravko Danev, i was about to just copy/paste everything. You made me think slower about this. But i'm kind of searching for a real merged solution, "fusioned solution" if i may say. I don't want buttons to just run .EXEs. :p
EDIT2
I managed to copy/paste all my forms, was kinda easy, though time consumming to check every references.
But it's done.
Most definitely do not copy the code!
It is relatively easy to create a simple launcher. Take a look at Process.Start:
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
I think your question is not about merge projects but how to launch them in a uniformed application or launcher.
You could copy files together, rebuild user interface. In the user interface, calling methods in the copied files. Then you could public a single EXE file other than multiple files.
If your original projects generate dll files, you could build a new app which reference those dll files. Loading them when you need it and invoke methods from there.
If your original projects generate exe files, then #Zdravko's solution, using Process.Start() to launch those exe files with correct parameters.

Can I compile a single aspx.cs file into a DLL?

I'm attempting to make a single small update to a website written in C#/ASP.NET.
All I'm trying to do is change the email address a form submits to, which is why I'm not seeking out a proper C#/ASP.NET developer.
I've done a little research, and it seems that the site itself is using dll files in the /bin folder to run the forms and things. The form is contact.aspx.f3293f9sd.dll, so I've edited the corresponding contact.aspx.cs file.
What do I do now?
Can I build this single CS file into a single DLL and upload it? I've scoured the menus and see no such option, and Google results seems to imply that you need to add entire projects and build entire projects at once.
Is that correct? What's the process here?
What you need to do is open the solution file. Solution files are files composed of projects. The contact.aspx.cs file is part of one of those projects. You need to make your change in the file, then recompile your solution. Then you can upload the DLL file it outputs to your production. Make sure you compile in Release mode.

Integrating a .exe file into a visual studio project

broken to bare-bones scene:
I have a program in c# that calls a .exe inside cmd(using process.start), passing some required arguments.
What i'm trying to do: Include the exe into the project so that i don't have to call cmd.
Any idea?
If you just want to include so you don't have to ship two files then just include it into the project as "embedded resource" (see project item options) and then you can call ResourceManager.GetStream and write it to file and call Process.Start.
If you want integrate the functions of that exe so that the exe is not needed anymore (no Process.Start) then you need the source code...
EDIT:
the "write to file" is not necessary if the exe is .NET - then you can directly load it from the resource stream as Assembly/AppDomin and execute it.
You can add an exe as an embedded resource (just right click on a folder in the Solution explorer, Add Existing Item, then get properties on it and set it to be Embedded Resource). However, you may not be able to easily execute it in place - you'll need to save it to disk and then execute it (which doesn't solve your stated problem of having to ShellExecute the .exe file, but does solve the problem of having to ship more than one file to the end user).
If you have the source code, then you'll be able to repackage the exe as a dll, or integrate it directly into your program code.
If the exe is a .NET assembly, you could use ILMerge to merge the exe into your main assembly. You can then invoke the code in the exe directly.

What files are needed to "show C# code "?

I am new to SO and also to the C# language. I browsed for a bit and was not able to find anything relating to this subject. I program in other languages, mainly C and C++. When I want to show someone my code I show them the .c or .cpp files and any header files I have created.
However, if I want to show the source code to a program in C# what do I use?
It is especially confusing when I create a new WindowsFormApplicaiton
Technically all you need is the .cs files, but to make it easy on the person receiving this (and assuming you are using Visual Studio) just take the entire Visual Studio project directory (should include a .sln file, one or more .csproj files, all the .cs files, and any other assets) and zip/rar it.
The user on the receiving end can unzip the whole structure and double-click the .sln file, and they will get the same view in Visual Studio that you had.
A little more detail:
Forms are still just c# (.cs text) files.
The .csproj is an XML file that contains pointers to all your .cs files, as well as some project metadata.
The .sln file is an XML file that contains pointers to all your .csproj files, as well as some metadata about source control, project relationships, etc.
When you create a Winforms application, you get two .cs files: Program.cs and Form1.cs. When you are looking at the form, you can right-click on it and choose View Code. This is called a "code behind", and is where the implementation of the form lives.
You can use notepad (open the .cs file) or visual studio. If you don't have a pro copy you can use one of the express editions of visual studio. When in VS you can right click on the form and select View Code. I hope my response is on track with your question!

Categories