I am trying to write a VST Host which basically should provide a better interface to control to Plugins at the same time. For that i looked searched for the best way to do it and stumbeld over VST.NET. Now i made this code to just simply open a plugin:
HostCmdStub cmdstub = new HostCmdStub();
VstPluginContext cont = VstPluginContext.Create("C:\\Program Files\\..\\Turnado.dll", cmdstub);
Logger(cont.PluginCommandStub.GetProductString());
cont.PluginCommandStub.Open();
(Code for the HostCmdStub taken from https://github.com/perivar/AudioVSTToolbox/blob/master/ProcessVSTPlugin/HostCommandStub.cs)
The Looger correctly logs Turnado so the dll seems to be loaded but nothing opens.
I don't really have any experience with VST.NET and my C# knowledge is also not that fresh. (If I could i would write the host in something like Java but there seems to be no good way to do so...also it seems not a good idea performance-wise).
Is there an obvious problem with my code or even a better way to create a host...I might even switch Programming language as i'm not that invested in the c#/VST.NET project yet.
Related
I'm trying to create a piece of software that allows the user to login and stream a byte[] of a dll to be used for injection. For example
public static byte[] getDLL()
{
using (WebClient wc = new WebClient())
{
Uri url = new Uri("http://mysite/dll.dll");
return wc.DownloadData(url);
}
}
I successfully managed to make this in C# using visual studio. However you can easily decompile the program and make it create the dll at a specific location on your computer therefore leaking it. And there's pretty much no way that I can prevent this.
Would I be better of using a language that's harder to decompile like say C++ or C for example or am I just going to run into the same problem what ever language I use? And is it really worth the effort.
You can't prevent decompiling anything, neither C# nor C++ or anything else.
Languages like C++ require more manual work compared to eg. C#, and obfuscators can make it harder to understand the code, but everything just slows down the one doing it, instead of preventing it.
(And stuff like DLLs and encryption won't help at all for securing the code)
If it is a problem that some user of the program can see the full code, you're doing something wrong. Any secret like passwords etc. don't belong in files the user gets, but on some server controlled by you and only reachable for the user through network connections etc.
I'm not very clear about the first paragraph of your question.But here is some idea for you.
Simply De-compiling is not an issue, if outsiders cant use generated code to hijack your assembly.
As my understanding there are plenty of tools to "reasonable de-compile" or browse the .NET assemblies content.
If you use C++ or C, there are de-compilers, The source code are generated by them are not accurate and need lot of manual works.
Secondly if you used native language such as C or C++ those has plenty of vulnerabilities. you have to use all the good practices to avoid injecting kind of issues. https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=637
There are tools for avoid de-compilation. you can google Obfuscator. some famous are Dotfuscator, Secure Team.
And also you can think about the project architecture changes. such as including DLL code in to the main EXE etc...
Also you can use key generation mechanism to verify the DLL. Just after loading the DLL exe call common function in the DLL and get the one time key and verify.
I'm virtually a complete novice, I've tried Googling for answers and become totally confused.
Using Visual Studio 2010, I have a C# application which is an email notifier for a friend. The external (Arduino) hardware works, the main code (from a website) works but I'm sending it to her on the other side of the world to use and she is very 'non-technical' - hence the need for a 'setup form'.
I have created a form where she can enter comm port (selected from a list), username and password (all to be used by the main code), but that form should run only when the application is first installed on the PC.
At the moment it runs in VS-2010 (though I need to iron out a couple of snags), validates and hides - but I don't know how to a) store the data and make it available to the main code, b) ensure that the form only runs at setup, or c) exactly what I need to do or include to create an installable application.
Could somebody either help or direct me to some tutorials that don't assume I understand all the terminology?
I just want to create something that she can instal from a memory stick. I know it can be done and it's proababy quite simple for those who understand - I'm trying to learn but I'm no longer young and it's a struggle.
Thanks
a) store the data and make it available to the main code,
write the data on a file!
you have millions of possibilities, for isntance reading and writing a plain text file can be done with few lines of code, but if you want to encrypt your file (it may be the case if you want to store the password) you can use System.Security.Cryptography as shown in this guide
b) ensure that the form only runs at setup,
once you have written the file, then it means that the program has run already at least once, so you don't need to ask the user again (just read the data from the file)
c) exactly what I need to do or include to create an installable application.
Visual Studio already comes with the Setup project for this task. See this good guide.
From your comment and link to the code project for the Arduino, I gather that this is your first venture into writing code in C#, or very close to it. And ideally you'd like to make this as easy for your friend as possible. The best advice I can give you is not to try to run before you learn to walk. If you try to create a custom setup project and use a configuration file, which is what you are talking about doing, you may hit so many barriers that you never get to a successful end of the project. That kind of experience is discouraging and I'd hate for you to lose the drive to ever want to try another software project.
Make this initial project easy on yourself. This is not good programming practice for most situations, but if you only have one user, hard-code her configruation information for this first version. In other words, put her username, password, com port, etc directly into the main program. This eliminates the need for both the configuration, and any custom setup form. If you still want to make the whole thing configurable and versatile, do that in your next version. Custom setup is not a beginner task. It will be a lot easier to take on with the encouragement of your friend's excitement and compliments over a first version that works.
Ok, so I was wondering how one would go about creating a program, that creates a second program(Like how most compression programs can create self extracting self excutables, but that's not what I need).
Say I have 2 programs. Each one containing a class. The one program I would use to modify and fill the class with data. The second file would be a program that also had the class, but empty, and it's only purpose is to access this data in a specific way. I don't know, I'm thinking if the specific class were serialized and then "injected" into the second file. But how would one be able to do that? I've found modifying files that were already compiled fascinating, though I've never been able to make changes that didn't cause errors.
That's just a thought. I don't know what the solution would be, that's just something that crossed my mind.
I'd prefer some information in say c or c++ that's cross-platform. The only other language I'd accept is c#.
also
I'm not looking for 3-rd party library's, or things such as Boost. If anything a shove in the right direction could be all I need.
++also
I don't want to be using a compiler.
Jalf actually read what I wrote
That's exactly what I would like to know how to do. I think that's fairly obvious by what I asked above. I said nothing about compiling the files, or scripting.
QUOTE "I've found modifying files that were already compiled fascinating"
Please read and understand the question first before posting.
thanks.
Building an executable from scratch is hard. First, you'd need to generate machine code for what the program would do, and then you need to encapsulate such code in an executable file. That's overkill unless you want to write a compiler for a language.
These utilities that generate a self-extracting executable don't really make the executable from scratch. They have the executable pre-generated, and the data file is just appended to the end of it. Since the Windows executable format allows you to put data at the end of the file, caring only for the "real executable" part (the exe header tells how big it is - the rest is ignored).
For instance, try to generate two self-extracting zip, and do a binary diff on them. You'll see their first X KBytes are exactly the same, what changes is the rest, which is not an executable at all, it's just data. When the file is executed, it looks what is found at the end of the file (the data) and unzips it.
Take a look at the wikipedia entry, go to the external links section to dig deeper:
http://en.wikipedia.org/wiki/Portable_Executable
I only mentioned Windows here but the same principles apply to Linux. But don't expect to have cross-platform results, you'll have to re-implement it to each platform. I couldn't imagine something that's more platform-dependent than the executable file. Even if you use C# you'll have to generate the native stub, which is different if you're running on Windows (under .net) or Linux (under Mono).
Invoke a compiler with data generated by your program (write temp files to disk if necessary) and or stored on disk?
Or is the question about the details of writing the local executable format?
Unfortunately with compiled languages such as C, C++, Java, or C#, you won't be able to just ``run'' new code at runtime, like you can do in interpreted languages like PHP, Perl, and ECMAscript. The code has to be compiled first, and for that you will need a compiler. There's no getting around this.
If you need to duplicate the save/restore functionality between two separate EXEs, then your best bet is to create a static library shared between the two programs, or a DLL shared between the two programs. That way, you write that code once and it's able to be used by as many programs as you want.
On the other hand, if you're really running into a scenario like this, my main question is, What are you trying to accomplish with this? Even in languages that support things like eval(), self modifying code is usually some of the nastiest and bug-riddled stuff you're going to find. It's worse even than a program written completely with GOTOs. There are uses for self modifying code like this, but 99% of the time it's the wrong approach to take.
Hope that helps :)
I had the same problem and I think that this solves all problems.
You can put there whatever code and if correct it will produce at runtime second executable.
--ADD--
So in short you have some code which you can hard-code and store in the code of your 1st exe file or let outside it. Then you run it and you compile the aforementioned code. If eveything is ok you will get a second executable runtime- compiled. All this without any external lib!!
Ok, so I was wondering how one would
go about creating a program, that
creates a second program
You can look at CodeDom. Here is a tutorial
Have you considered embedding a scripting language such as Lua or Python into your app? This will give you the ability to dynamically generate and execute code at runtime.
From wikipedia:
Dynamic programming language is a term used broadly in computer science to describe a class of high-level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. These behaviors could include extension of the program, by adding new code, by extending objects and definitions, or by modifying the type system, all during program execution. These behaviors can be emulated in nearly any language of sufficient complexity, but dynamic languages provide direct tools to make use of them.
Depending on what you call a program, Self-modifying code may do the trick.
Basically, you write code somewhere in memory as if it were plain data, and you call it.
Usually it's a bad idea, but it's quite fun.
http://forums.alliedmods.net/showthread.php?t=64767
The source acts like its missing a ton of stuff I can't find like uh TBX and some other things
I don't really know the language, but I have hoping I could get it to compile with delphi 2009/2010.net and then see about porting its IL. (to C# I guess)
The reasoning behind this is because pawnstudio is crash happy but the program (layout, syntax highlighting, the fact that the intellisense (clamsense) works with functions from includes, in the file, etc) is really easy to use.
Can anyone help?
That is a really, really bad idea. Stabilize first, then port (if needed). Porting introduces problems, and it is not nice when you cannot tell if the bug is existing or new.
[edit] I've downloaded the source. It is not what I'd call modern, well-refactored Delphi code. Long functions, no object-orientation visible, all code in the form event handlers.
TBX you can find at Torry
If you are using Delphi 7 you're using the VCL/various components native to delphi.
Those are NOT present in c# (in Delphi 2009/2010 probably yes), so you can't do a naive port, you will need to redo most of the program. (at least the interface part)
TBX is not yet supported but you can look at spTBX
It will not be very easy to port in C#.
If you don't know Delphi, you ought to get someone who does to help out. Delphi's an easier language to work with than most, but like any language it has subtleties, complexities and dark corners. If you try to port it without the necessary domain knowledge, then not only are you reinventing the wheel, you're reinventing it half-blind. Especially if you're not able to compile the original and test it.
What units does it say are missing, BTW?
Being able to create javascript code on the fly is pretty cool.
That is by using
HtmlPage.Window.Eval("alert('Hello World')");
But is there a way to do the same thing, with a C# method? Lets say something like
void MethodEval("MessageBox.Show('Hello World')");
Is it even possible, without having to recompile your code?
It's possible using tricks posted by others. However, it's usually a very bad idea.
.Net code typically runs in a more trusted context than a javascript browser sandbox, and has access to a much richer, and therefore potentially damaging, api.
Instead you use the System.Addin namespace to provide a very strict interface for extensions, plugins, and the like. If you're just trying to use a more "fluid" or functional programming environment you can use fun features like lamdba expressions and closures to pass functionality around internally.
You can do it right now. The ag DLR (Silverlight Dynamic Languages Runtime) can host javascript.
While Javascript cannot be hosted with the DLR outside the browser Ruby and Python can. Here's an example of a C# snippet using the DLR and hosting a piece of Python of code to demonstrate.
using IronPython.Hosting;
PythonEngine pythonEngine = new PythonEngine();
string script = #"import clr
clr.AddReference(""System.Windows.Forms"")
import System.Windows.Forms as WinForms
WinForms.MessageBox.Show(""Hello"", ""Hello World"")";
pythonEngine.Execute(script);
This is possible, but a little more tricky, using Microsoft's .NET framework.
The C# compiler is part of the base runtime, so you can compile an in-memory assembly, and execute code in there on the fly.
Here is a good MSDN blog post describing the basic process.
I have used this before to make a scripting engine for a C# project. With a little work wrapping this, you can make this quite easy to use. An open source project I've worked on has a project dedicated to this: Pluto.Scripting
We had examples and tests in that project which show dynamic compilation and execution of C#, VB.NET, and Boo.
If you don't mind Boo, you can use its interpreter.
Actually I kept on getting an error "unexpected indent" so changing the code to
PythonEngine pythonEngine = new PythonEngine();
string script = #"import clr; clr.AddReference(""System.Windows"");";
script += #"import System.Windows as Wins;";
script += #"Wins.MessageBox.Show(""Hello World"");";
pythonEngine.Execute(script);
Worked! interesting... Thanks
Why do you need this feature ? Shouldnt your code know its paths and include that logic ? If you cant forsee such use cases - then perhaps its not needed. The only real benefit is it opens an opportunity to be abused and attacked. It sounds like your in directly creating a potential for an exploit - its a shame because managed runtimes like Java/CLR dont allow code injection but you are bringing all that goodness back in...