Quantcast

Maximum PC

It is currently Thu Jul 24, 2014 7:50 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Possible to run other applications from mine? (MFC/C++)
PostPosted: Fri Aug 28, 2009 6:56 am 
8086
8086

Joined: Tue May 09, 2006 9:58 am
Posts: 67
Location: Pittsburgh
Can anyone tell me if this is even possible? What I want to do is something like the following:

I have a small user interface I developed in Visual Studio (2005). I want this program to launch another Windows program that was developed by someone else at the press of a button.

The other application I would run normally brings up a big window with lots of complicated menus. In this case, I would like to hide all this from the user (they don't need to see it) and let it run in the background. All they would see is my simpler interface I developed. So is it possible to either launch this other application and keep it minimized, or maybe specify the position of the window to be off-screen (this might be preferred)?

If anyone has any ideas how to accomplish this, it would be greatly appreciated. Thanks!


Top
  Profile  
 
 Post subject: Re: Possible to run other applications from mine? (MFC/C++)
PostPosted: Fri Aug 28, 2009 7:47 am 
Super Mario Banhammer
Super Mario Banhammer

Joined: Fri Aug 25, 2006 11:20 am
Posts: 595
JeffV wrote:
Can anyone tell me if this is even possible? What I want to do is something like the following:

I have a small user interface I developed in Visual Studio (2005). I want this program to launch another Windows program that was developed by someone else at the press of a button.

The other application I would run normally brings up a big window with lots of complicated menus. In this case, I would like to hide all this from the user (they don't need to see it) and let it run in the background. All they would see is my simpler interface I developed. So is it possible to either launch this other application and keep it minimized, or maybe specify the position of the window to be off-screen (this might be preferred)?

If anyone has any ideas how to accomplish this, it would be greatly appreciated. Thanks!


Couple of questions on this.

1. Is the Child Process a windowless application or console application or does it have its own gui?
2. If it has its own gui is their an sdk or api available for this application?
3. If it has its own gui and there is an sdk or api for this application is it redistributable under appropriate licenses?

Generally speaking without an sdk or api written to expose methods and properties to the developer where a windows GUI is involved there is no way to "access" the executable at the command level (like passing runtime parameters to the application in the case of a DOS style command) other than running the application.

That said it is possible to call an external process or library inside a program written in .NET (C# C++ VB J++ or other .NET language) by creating a reference to an object in your project and then using the CreateObject function to open an instance of an object.

Consider the following example:

C#

Code:
using Excel = Microsoft.Office.Interop.Excel;
.
.
.
public class ExcelObjectTest()
{
.
.
.
private static string m_OutputFilePath = "";
private static string m_OutputFileName = "";
private static string m_OutputFileExtension = "";
public static string OutputFilePath{get{return m_OutputfilePath;}set{m_OutputFilePath = value;}}
public static string OutputFileName{get{return m_OutputFileName;}set{m_OutputFileName=value;}}
public static string OutputFileExtension{get{return m_OutputFileExtension;}set{m_OutputFileExtension=value;}}
    public ExcelObjectTest()
    {
        try
        {
             OutputFilePath = "C:\\ExcelFiles\";
             OutputFileName = "MyExcelFile";
             OutputFileExtension = "xls";
             ExcelFileName = OutputFilePath + OutputFileName + "." + OutputFileExtension;
             Excel.Application objExcel = new Excel.Application();
             Excel.Workbooks oWorkbooks = (Excel.Workbooks)objExcel.Workbooks;
             Excel.Workbook objbook = (Excel.Workbook)(oWorkbooks.Add(objOpt));
             Excel.Sheets objSheets = (Excel.Sheets)objbook.Worksheets;
             Excel.Worksheet objSheet = (Excel.Worksheet)(objSheets.get_Item(1));

             objSheet.Cells[1, 1] = "PRODUCT";
             objSheet.Cells[1, 2] = "GL";
             Range objRange;
             objRange = objSheet.UsedRange; 
             objRange.Columns.AutoFit();
             objRange.Rows.AutoFit();
             objRange = null;
             objbook.SaveAs(ExcelFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
               
             objbook.Close(XlSaveAction.xlSaveChanges, ExcelFileName, Type.Missing);
             objSheet = null;
             objbook = null;
        catch(Exception ex)
        {
            //Implement exception handler here
        }
        finally
        {
            // do cleanup here
            // because its Excel use a kill process call to ensure garbage cleanup happens in a timely fashion
           KillExcell(Excel);
         }
    }


}


The previous code snippet shows one way to instantiate an object within your application. There are other ways to do this in .NET each with its advantages and disadvantages. The important parts of the code are the using line and the instantiation lines. If your object follows a particular object application model like Office and has a library that can be included int the solution or project the set a reference to the object call the using/imports functionality Instantiate the object and set its properties (if exposed) then end any methods used Close any subsidiary objects then the object itself then destroy the object or call for garbage cleanup.

If the application does not have this and it uses a Windows GUI its still possible to use the application directly through either an api call or by setting a reference directly to the application through the using/imports call and then obtaining a list of properties and methods through either CreateObject or CreateServer for the object.

Now again I must stress that a runtime redistributable or License must be available to use these methods. Using another application without the owners permission is Illegal and it is probably impossible to do if that functionality is not exposed by the application in question.


HTH


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 9:59 am 
8086
8086

Joined: Tue May 09, 2006 9:58 am
Posts: 67
Location: Pittsburgh
Thanks for your reply. To answer a few of your questions:

This other application I want to run from mine is a GUI based application being developed by a colleague of mine using a combination of Visual C++ and Labview. There is no sdk or api, but since he is still developing it, he can add anything I need him to. At the moment I've been working with a sort of early demo version. Because we are working together, there are no licensing type issues to be concerned with.

The GUI I created is in Visual C++. I haven't used .NET or C# before, so I was hoping I could avoid having to port anything to a new language. Is there a method similar to the using/import call method for Visual C++?


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 10:34 am 
Super Mario Banhammer
Super Mario Banhammer

Joined: Fri Aug 25, 2006 11:20 am
Posts: 595
JeffV wrote:
Thanks for your reply. To answer a few of your questions:

This other application I want to run from mine is a GUI based application being developed by a colleague of mine using a combination of Visual C++ and Labview. There is no sdk or api, but since he is still developing it, he can add anything I need him to. At the moment I've been working with a sort of early demo version. Because we are working together, there are no licensing type issues to be concerned with.

The GUI I created is in Visual C++. I haven't used .NET or C# before, so I was hoping I could avoid having to port anything to a new language. Is there a method similar to the using/import call method for Visual C++?


Jeff,

Visual C++ is a .NET language. I used the C# language example because that is what language I wrote the example in. Visual C++, C#, VB, J++ or any other .NET language that remains compliant with the Common Language Runtime (CLR) will have similar functions and methods exposed. If you have access to the source code for your colleagues application and it has a library already compiled you could reference the library (.dll or .exe) in your project then set a using directive as per my code example and any methods or properties marked public will be available to your application. Similarly if you have access to the actual classes through the source then you could add those classes to your project and either Instance them:
Code:
Object myobject = new Object();
or Derive from them:

Code:
abstract class Program   //abstract keyword means it has to be inherited
{                                  //or derived from

    abstract string MyString();
   

}

public class DerivedClass:Program
{
     virtual string MyString()
     {
         return "Hello World";
     }
}



Visual C++ has a slightly different syntax and it allows for multiple inheritance (careful with that as it can get you in trouble quickly when you are trying to determine which base class is controlling the current scope)
but it still allows this to happen. Best of all with C++ and proper use of unmanaged code you can point to specific addresses in memory efficiently, use pointers, and various other object oriented tasks not necessarily available directly in C# VB or other .NET language.

Also I think the syntax for using/Imports in C++ is uses as in
Code:
uses System.IO;


Last edited by MaxFan on Fri Aug 28, 2009 11:44 am, edited 1 time in total.

Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 10:40 am 
Northwood
Northwood
User avatar

Joined: Sun Jul 15, 2007 6:37 pm
Posts: 2261
Location: No. 1 Thread Killer
At Jeff, for what you're doing, I think CodeCaving could work really well.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 11:39 am 
Super Mario Banhammer
Super Mario Banhammer

Joined: Fri Aug 25, 2006 11:20 am
Posts: 595
Dwood15 wrote:
At Jeff, for what you're doing, I think CodeCaving could work really well.


Dwood,

Could you be a little more specific about CodeCaving what it is what it does etc.? I am totally unfamiliar with the particulars of CodeCaving.

Additionally from what I could find about it on doing a Google search for it was this:

"Codecaving allows you to get the effects of modifying an offset that could be blacklisted by poor anti-cheat software (ex: Warden in Warcraft 3), since you never modify it directly.
You could therefore take the offsets of some hack and make them almost "undetectable" (considering you keep that hack private or simply for yourself)."

If that is what you are refering to and it is what I think it is, I dont think that helps Jeff much in his quest to reuse his colleagues application using MFC/C++. It also would be considered a hack or cheat that would be specifically against the forum rules here.

If this is Not what you are refering to maybe you could help Jeff (and me!) out by explaining to us what CodeCaving is?


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 12:00 pm 
Northwood
Northwood
User avatar

Joined: Sun Jul 15, 2007 6:37 pm
Posts: 2261
Location: No. 1 Thread Killer
eh... Codecaving is a bit difficult to explain.

That link you got is quite biased. Codeproject explains this best, imho: http://www.codeproject.com/KB/cpp/codecave.aspx

Quote:
It is true that codecaves have an important and useful place in the underground world of hacking, but they can be used for legitimate reasons as well (as with anything programming related that can be used for good or bad).


Check that site for more info on CodeCaving if you want to go indepth. In Short, what you're doing with CCs is that you're getting an address (5 bytes at the very least) that you get from OllyDebug or CheatEngine (I've used both for legitimate reasons before) What happens next is best understood with the following:

Image


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 12:17 pm 
Super Mario Banhammer
Super Mario Banhammer

Joined: Fri Aug 25, 2006 11:20 am
Posts: 595
Dwood15 wrote:
eh... Codecaving is a bit difficult to explain.

That link you got is quite biased. Codeproject explains this best, imho: http://www.codeproject.com/KB/cpp/codecave.aspx

Quote:
It is true that codecaves have an important and useful place in the underground world of hacking, but they can be used for legitimate reasons as well (as with anything programming related that can be used for good or bad).


Check that site for more info on CodeCaving if you want to go indepth. In Short, what you're doing with CCs is that you're getting an address (5 bytes at the very least) that you get from OllyDebug or CheatEngine (I've used both for legitimate reasons before) What happens next is best understood with the following:

Image


Sounds like your simply walking the heap or something similar. However as Jeff has already pointed out he has access to the source code. Much simpler to just implement the source classes in a normal fashion as part of his project. Even if his colleague balks at handing him the source, if the compiled executable or library exposes inheritable functionality, setting an object reference to the library and then making use of or instantiating that object within a new application is much much easier than doing an in memory debug and looking for a particular address+offset.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 28, 2009 1:35 pm 
Northwood
Northwood
User avatar

Joined: Sun Jul 15, 2007 6:37 pm
Posts: 2261
Location: No. 1 Thread Killer
Oh if he has access to source code then nvm. Sorry I must have missed that part! >.<


Top
  Profile  
 
 Post subject:
PostPosted: Mon Aug 31, 2009 12:39 pm 
8086
8086

Joined: Tue May 09, 2006 9:58 am
Posts: 67
Location: Pittsburgh
MaxFan: Thanks for the help. I did a little more research into the option you mentioned of using/importing the .exe of the other application. I found this page, which seems to be what you're talking about (using C++):

http://msdn.microsoft.com/en-us/library/yab9swk4.aspx

I will have to play around with this and see if it works. It sounds like it might be the best solution for what I'm doing. If I can successfully import the data from the .exe using the #using keyword, and if I can call any public member function in that application, I'm thinking this should do what I want.
I will give it a try. Thanks!


Top
  Profile  
 
 Post subject:
PostPosted: Tue Sep 01, 2009 12:40 pm 
8086
8086

Joined: Tue May 09, 2006 9:58 am
Posts: 67
Location: Pittsburgh
Well, after having some issues with this, I came up with a completely different method to do this and already have it working. I ended up doing the following:

1. Installed Windows PowerShell
2. Installed WASP (Windows Automation Snapin for PowerShell) http://www.codeplex.com/WASP
3. Used CreateProcess() from my application to run a powershell script to start the other application and reposition the window off-screen.

I can also run a script to close the other application whenever I want.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Sep 01, 2009 12:56 pm 
Super Mario Banhammer
Super Mario Banhammer

Joined: Fri Aug 25, 2006 11:20 am
Posts: 595
Glad to hear you resolved the issue.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group