I am building an application that opens Wireshark services (Wireshark has several services) in order to to different things on Wireshark files like edit, change format, statistics, etc. Each option usually uses a different service, so I want to build my classes with inheritance.
I was wondering if what I want to do is appropriate.
Main class WiresharkServices
with the following members and methods:
public class WiresharkProcesses
{
protected string _filePath; //the file path who send to Wiresahrk process
protected string _capinfos;
protected string _dumpcap;
protected string _editcap;
protected string _mergecap;
protected string _rawshark;
protected string _text2pcap;
protected string _tshark;
protected string _wireshark;
public void initializeServices()
{
if (Directory.Exists(@"C:\Program Files (x86)\Wireshark"))
{
_capinfos = @"C:\Program Files (x86)\Wireshark\_capinfos.exe";
_dumpcap = @"C:\Program Files (x86)\Wireshark\_dumpcap.exe";
_editcap = @"C:\Program Files (x86)\Wireshark\editcap.exe";
_mergecap = @"C:\Program Files (x86)\Wireshark\_mergecap.exe";
_rawshark = @"C:\Program Files (x86)\Wireshark\_rawshark.exe";
_text2pcap = @"C:\Program Files (x86)\Wireshark\_text2pcap.exe";
_tshark = @"C:\Program Files (x86)\Wireshark\_tshark.exe";
_wireshark = @"C:\Program Files (x86)\Wireshark\_wireshark.exe";
}
else if (Directory.Exists(@"C:\Program Files\Wireshark"))
{
_capinfos = @"C:\Program File)\Wireshark\_capinfos.exe";
_dumpcap = @"C:\Program Files\Wireshark\_dumpcap.exe";
_editcap = @"C:\Program Files\Wireshark\editcap.exe";
_mergecap = @"C:\Program Files\Wireshark\_mergecap.exe";
_rawshark = @"C:\Program Files\Wireshark\_rawshark.exe";
_text2pcap = @"C:\Program Files\Wireshark\_text2pcap.exe";
_tshark = @"C:\Program Files\Wireshark\_tshark.exe";
_wireshark = @"C:\Program Files\Wireshark\_wireshark.exe";
}
}
}
When the application is running, I am of course checking if Wireshark is installed on the machine. If not, I throw an exception:
WiresharkServices wservices = new WiresharkServices();
wservices .initializeServices();
and in each class its own methods.
Child class example which receives a file path to convert it to another Wireshark format:
public class Editcap : WiresharkProcesses
{
private string _newFileName;
public void startProcess(string filePath)
{
FileInfo file = new FileInfo(filePath);
_newFileName = file.FullName.Replace(file.Extension, "_new") + ".pcap";
ProcessStartInfo editcapProcess = new ProcessStartInfo(string.Format("\"{0}\"", _editcap))
{
Arguments = string.Format("{2}{0}{2} -F libpcap {2}{1}{2}", file.FullName, _newFileName, "\""),
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
UseShellExecute = false,
ErrorDialog = false
};
using (Process editcap = Process.Start(editcapProcess))
{
editcap.WaitForExit();
}
}
public string getNewFileName()
{
return _newFileName;
}
}