C# injecting C++ DLL - c#

I am trying to inject a C++ detour dll using a C# application using Syringe.
Here is what I have so far:
-A dll to inject which hook both recv/send from wsock32.dll and log the communication (http://pastebin.com/JvnmYuz0)
-A C++ loader which start the target application then load the dll to it ( pastebin . com/mX68nTnx) //Sorry, I cant post more than 2 links
-A C# app that inject the dll in any process (http://pastebin.com/FLRj45YF)
But I am having some problems:
1- I do not want to use the c++ loader to start the application then inject the dll, I use it only to test the dll hooking, and it is working well, it does hook and log to file the communication
2- I want to inject the c++ dll (in any process I want) using a c# application (using Syringe). I can inject it with no problems, but it does not hook the recv/send functions as it does when started with the c++ loader, however, it says that everything was attached successfully, but it does not log anything to the file, not even call MyRecv/MySend. I once received error 8 (ERROR_NOT_ENOUGH_MEMORY) from DetourTransactionCommit() while detouring send/recv functions, but now it says there is no error
3- After being able to handle the communication using MySend/MyRecv, I want to send the communication back to the C# application then do the work there.
I am very new at c++ and dll injecting but I have some experience with c#.
It does not need to necessary use the syringe method to inject.
I have tried to use EasyHook without success.
Any injecting method will be great, as long as I can inject the dll to any process then work the communication on a C# application. I do not want to do the work on the C++ dll because I am very new to C++ and it seems to be very very hard to do simple things, the learning curve is not very friendly
thanks
PS: I do not want to hack anything/anyone, I just want to create a Ultima Online tool

Related

Blender - commands in C# C++

I got a task to establish GMS2 -> Blender one way communication. Dll extending GMS2 needs to be written either in C# or C++. Problem with Blender is that it has no ports like Maya has. So I tought about a solution via sockets but not sure if that is the right way.
I don't request any code, just herebly asking for a pointer (pun).
Blender uses python to create addons, a python addon can be created that opens a socket and alters the internal data. One example would be the network render addon that is included with blender. You can also use the subprocess module to pipe data from an external program, see this question.
If you need to use C/C++ within the addon, you have several options. An addon for blender is a standard python module - with some required methods and properties. A python module can be a dynamic library compiled from C/C++. You can also use ctypes to access standard libraries from python code. Another option is to create a basic addon and use cython to turn it into C code which you can then add your code to, cube surfer and animation nodes are example addons that use cython to compile a shared library.

Can PHP Extensions be written using C#

Is it possible to create a PHP Extension using C#?
We have a need to connect PHP to in house libraries we have written in C#.NET 4.6 targeting Windows and would like to be as close as possible to PHP without needing to have a serivce we can call external to php, thus the idea of making an extension in house.
I've looked at a couple options:
Use PHP DOTNET extension to call C# assembly.
As far as I can tell this extension does not work with .NET 4+ and the C# code requires 4.6 sadly.
Write a PHP extension.
So far I have only seen examples for Windows using Win32 and C++, idealy it would be nice if the extension could be written in C#. I have thoughts on making a lib using the C# code we need, then utilizing that inside the Win32/C++ extension and trying that if I absolutly have to.
Call the C# code as an external service.
As a very last option this would be viable and I can see this being more flexible for other sources to use (i.e. PHP, Java, C#, etc)
It would be interesting to be able to write a PHP Extension using C# assuming this is possible. I can see how this may not be the "best" option if it is possible though.
Thanks for reading and advice!!!
Coming off of #SevaAlekseyev idea I was able to get PHP to call C# using COM.
<?php
$object = new COM('ComClassExample.ComClassExample');
echo '1 and 1 added: ' . $object->AddTheseUp(1,1);
?>
Using the following site I was able to make a C# dll that exposed itself like a COM object. https://whoisburiedhere.wordpress.com/2011/07/12/creating-a-com-object-from-scratch-with-c/
And with a little tweak to the Post-build event I was able to get the new version to load for PHP (had to copy because PHP was getting an access denied message)
iisreset /stop
copy /Y "$(TargetPath)" C:\com\$(TargetFileName)
$(frameworkdir)\$(frameworkversion)\regasm.exe C:\com\$(TargetFileName) /codebase /tlb /nologo
iisreset /start
#JuanDelaCruz Peachpie looks like an interesting tool to keep in mind but it looks like it is meant to be compiled before deployment which wont work in our shop for the moment.
Thanks all!

Can I use uncompiled C++ code in ASP.NET web application?

I've got a problem which I hope you can help me with.
I created ASP.NET 4.0 web application. I've also got .cpp file generated in some other app. This .cpp file contains functions, which always returns the same number of variables and which always takes the same number of parameters.
What I need to do is being able to use this functions in my web application.
But what is real problem is that I need to be able to replace this functions while running app. What I mean is administrator should be able to login, upload new cpp file, which will replace old functions with new ones. New ones will have the same names, parameters and result number, but will make calculations in a different way.
Is there any way this can be achieved?
Thanks for any help!
MattheW
Precompile the cpp code into dlls and let admin upload dll. Reference dll's from c# app using [DllImport("")] directive.
C++ will need to be compiled in some way or another. You can use a compiled dll written in C++ in your ASP.NET application but the code will still need to be compiled for ASP to be able to use it.
The compiled DLL can then be loaded and unloaded to accommodate changes to the function. You could perhaps even make the ASP.NET server compile the file somehow, but the code still needs to be compileable to a DLL to make it executable.
You need to expose the C++ code via another dll.
The first choice is pinvoke. See:
How to set up a C++ function so that it can be used by p/invoke?
It's also covered here:
http://msdn.microsoft.com/en-us/library/aa446538.aspx
Technically you could also expose via COM or write in managed C++ but those are both overkill if you're just trying to expose a few C++ functions.

rfid programming

I have 2 readers for RFID and some cards (from a Chinese company called "Daily RFID"). They
kind of work because they came with some demo software written in Delphi that reads the id of the card (myfare compatible, ISO14443A). The problem is that if I try to use the demo to write to them, it doesnt seem to work.
They have another demo written in C#, it compiles and runs, but when click on Connect, I get this error:
Unhanded exception.. unable to load
DLL 'BasicB.DLL'
So I put the DLL in %WINDOWS%/system32, but when I tried to run regsvr32 BasicB.dll, I got another error:
the module "BasicB.dll" was loaded but
hte entry-point DllRegisterServer was
not found. Make sure that "BasicB.dll"
is a valid DLL or OCX file and then
try again
I have written to the company but got no response.
I program in Objective-C, so I kind of understand c#, but how to make these cards work?
Should I continue with Delphi, and try to write to them with it? Or should I continue trying with C#? Either way, would I have to write the code to read/write to them, or is there any software to work with these modules?
You only use regsvr32 to register ActiveX (COM) DLLs. The DLL you're trying to register isn't one.
Putting the DLL in the %WINDOWS%\system32folder should be enough. In fact, it can be in your applications folder or anywhere on the PATH.

Pre-commit hooks in C# with SharpSVN

I'm new to SharpSVN (and frankly--pretty new to C# as well). I've been trying get a simple pre-commit hook working which checks for a comment. (i.e. the commit fails in the absence of a comment)
There are several posts (like this one) which are related and helpful, but I have a few fundamental questions that are keeping me from getting further:
1) How do I get code like the link above running in C#? (i.e. which C# context would I use-- console application? csharp class?)
2) In a Windows Server context, how do I call my compiled C# program?
I've tried this answer's methodology with no luck.
Thanks in advance.
If you are creating a pre-commit hook you should call it pre-commit.exe. (Subversion accepts hook with the extensions .exe, .cmd, .bat and .wsf.)
Hooks communicate via stdout, stderr and in some cases stdin, so you should compile your application as a console application.
To get the hook working you must place the .exe (and the required DLLs) in the hooks directory of the repository.
See How to access file information in a pre-commit hook using SharpSVN for some examplecode.
Compile your "hook" as a console application, and then write a batch file that calls your console application. The batch file needs to be named correctly and placed in the "hooks" folder of your Subversion repository.
For your specific case, the batch file should be called pre-commit.bat (or pre-commit.cmd).
I had to keep users from commiting to the wrong branch by mistake. So I wrote a pre-commit hook that would check the comment for a key value. If the comment doesn't start with the right key the commit is aborted.
Here is the project:
http://sourceforge.net/projects/csvnprecommit/
Feel free to use it as a base for your own hook or use it as is. If you find a bug submit it to the project.

Categories

Resources