tags:

views:

68

answers:

3

Right ive got a console application which outputs the data i need... to the console!

All i want to do, is have a windows form start up before this data begins to produce and then the data instead of print to console, get added to a list box on the form.

I dont wish to sound lazy but ive been going around in circles and im getting nowhere. I have my console code in Program.cs

Could someone please help? Thank you

using System;
using System.Collections.Generic;
using System.Runtime.Remoting;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using EasyHook;

namespace FileMon
{
    public class FileMonInterface : MarshalByRefObject
    {
        public void IsInstalled(Int32 InClientPID)
        {      
            Console.WriteLine("FileMon has been installed in target {0}.\r\n", InClientPID);
        }

        public void OnCreateFile(Int32 InClientPID, String[] InFileNames)
        {
            for (int i = 0; i < InFileNames.Length; i++)
            {
                String[] s = InFileNames[i].ToString().Split('\t');

                if (s[0].ToString().Contains("ROpen"))
                {
                    Console.WriteLine(DateTime.Now.Hour+":"+DateTime.Now.Minute+":"+DateTime.Now.Second+"."+DateTime.Now.Millisecond + "\t" + s[0] + "\t" + getProcessName(int.Parse(s[1])) + "\t" + getRootHive(s[2]));
                }
                else if (s[0].ToString().Contains("RQuery"))
                {
                    Console.WriteLine(DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second + "." + DateTime.Now.Millisecond + "\t" + s[0] + "\t" + getProcessName(int.Parse(s[1])) + "\t" + getRootHive(s[2]));
                }
                else if (s[0].ToString().Contains("RDelete"))
                {
                    Console.WriteLine(DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second + "." + DateTime.Now.Millisecond + "\t" + s[0] + "\t" + getProcessName(int.Parse(s[0])) + "\t" + getRootHive(s[1]));
                }
                else if (s[0].ToString().Contains("FCreate"))
                {
                    //Console.WriteLine(DateTime.Now.Hour+":"+DateTime.Now.Minute+":"+DateTime.Now.Second+"."+DateTime.Now.Millisecond + "\t" + s[0] + "\t" + getProcessName(int.Parse(s[1])) + "\t" + s[2]);
                }
            }
        }

        public void ReportException(Exception InInfo)
        {
            Console.WriteLine("The target process has reported an error:\r\n" + InInfo.ToString());
        }

        public void Ping()
        {
        }

        public String getProcessName(int ID)
        {
            String name = "";
            Process[] process = Process.GetProcesses();
            for (int i = 0; i < process.Length; i++)
            {
                if (process[i].Id == ID)
                {
                    name = process[i].ProcessName;
                }
            }
            return name;
        }

        public String getRootHive(String hKey)
        {
            int r = hKey.CompareTo("2147483648");
            int r1 = hKey.CompareTo("2147483649");
            int r2 = hKey.CompareTo("2147483650");
            int r3 = hKey.CompareTo("2147483651");
            int r4 = hKey.CompareTo("2147483653");

            if (r == 0)
            {
                return "HKEY_CLASSES_ROOT";
            }
            else if (r1 == 0)
            {
                return "HKEY_CURRENT_USER";
            }
            else if (r2 == 0)
            {
                return "HKEY_LOCAL_MACHINE";
            }
            else if (r3 == 0)
            {
                return "HKEY_USERS";
            }
            else if (r4 == 0)
            {
                return "HKEY_CURRENT_CONFIG";
            }
            else return hKey.ToString();
        }
    }

    static class Program 
    {
        static String ChannelName = null;
        static void Main()
        {

            try
            {
                Config.Register("A FileMon like demo application.", "FileMon.exe", "FileMonInject.dll");
                RemoteHooking.IpcCreateServer<FileMonInterface>(ref ChannelName, WellKnownObjectMode.SingleCall);
                Process[] p = Process.GetProcesses();
                for (int i = 0; i < p.Length; i++)
                {
                    try
                    {
                        RemoteHooking.Inject(p[i].Id, "FileMonInject.dll", "FileMonInject.dll", ChannelName);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
            catch (Exception ExtInfo)
            {
                Console.WriteLine("There was an error while connecting to target:\r\n{0}", ExtInfo.ToString());
            }
            Console.ReadLine();

        }
    }
}
+3  A: 

the only thing you need to understand to make this work, is that a WinForm is just another class in C#... create a winform and put a method on its class that you call from program.cs, instead of calling console.writeline

Derick Bailey
If you see my code above, i dont get how to define the form at the bottom in main, but then reference it at the top in the other class/interface....The contents of OnCreateFile is what i wish to output to the GUI
Tom
A: 

Are you using Visual Studio? The VS Form Designer will create a blank Form control if you create a Forms project; copy your code to it.

Check out the Creating a New Forms Application on MSDN.

Dour High Arch
+1  A: 

Why don't you just make a windows forms application? You can make a command line process if you need to execute something on the command line... seems more sensible than having a console app call a form, but I don't see why that wouldn't work either.

Brandi