WOW !! MUCH LOVE ! SO WORLD PEACE !
Fond bitcoin pour l'amélioration du site: 1memzGeKS7CB3ECNkzSn2qHwxU6NZoJ8o
  Dogecoin (tips/pourboires): DCLoo9Dd4qECqpMLurdgGnaoqbftj16Nvp


Home | Publier un mémoire | Une page au hasard

 > 

La réalisation d'une application de contrôle total des processus d'un ordinateur distant

( Télécharger le fichier original )
par Kitambala OMARI
Université pédagogique nationale (UPN) - Licence 2010
  

précédent sommaire suivant

Bitcoin is a swarm of cyber hornets serving the goddess of wisdom, feeding on the fire of truth, exponentially growing ever smarter, faster, and stronger behind a wall of encrypted energy

III.3. DÉVELOPPEMENT

III.3.1. Environnement de développement

Nous avons choisi de développer notre application dans l'environnement de développement intégré Visual Studio 2008, sous le langage Visual Basic 2008. Ce langage offre des fonctionnalités de développement réseau très élaborées et faciles d'utilisation à travers l'espace de nom System.Net.

Pour le développement, nous avons utilisé une machine à base de processeur Centrino Duo 2Ghz avec 1Go de mémoire centrale et Windows XP SP3 comme système d'exploitation.

III.3.2. Structure et déroulement de l'application

L'application est composée d'un module serveur et d'un module client. Le processus serveur tourne sur la machine que l'on désire contrôler.

Figure 16 : Interface du processus serveur

Le processus client tourne sur la machine que l'administrateur réseau compte utiliser pour contrôler la machine distante.

Figure 17 : Interface utilisateur du processus client.

Le processus serveur récupère tous les processus qui s'exécutent sur la machine sur laquelle il est installé puis envoie cette liste au processus client.

Le processus client reçoit du processus serveur la liste des processus distants à contrôler et les affiche. L'administrateur réseau peut alors cliquer sur les boutons de commandes appropriés pour contrôler les processus distants sélectionnés.

III.3.4. Code source

Code du processus Serveur

Option Strict On

Imports System.Net

Imports System.Net.Sockets

Public Class frmServeur

Private WithEvents sock As New cAsyncSocketServer(Me)

Private Const PORT As Integer = 8081

Private _readyToLeave As Boolean = True

Private Sub frmServeur_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

Try

sock.Disconnect()

Catch ex As Exception

'

End Try

End Sub

Private Sub sock_ConnexionAccepted()

'_ readyToLeave = False

Me.Text = "Connected"

End Sub

Private Sub sock_Disconnected()

'_ readyToLeave = True

End Sub

Private Sub sock_ReceivedData(ByRef data() As Byte, ByVal length As Integer) Try

' Recréer la classe de données

Dim cData As cSocketData = cSerialization.DeserializeObject(data)

' Extraire le type d'informations que nous devons envoyer

If cData.Type = cSocketData.DataType.Order Then

Select Case cData.Order

Case cSocketData.OrderType.CreateNew

Shell("explorer.exe")

Case cSocketData.OrderType.Kill CoreFunc.cLocalProcess.Kill(cData.Param1)

Case cSocketData.OrderType.RequestProcessList

Call sendProcList()

Case cSocketData.OrderType.Resume

Dim p As New CoreFunc.cLocalProcess(cData.Param1) p.ResumeProcess()

Case cSocketData.OrderType.Suspend

Dim p As New CoreFunc.cLocalProcess(cData.Param1) p.SuspendProcess()

End Select

End If

Catch ex As Exception MsgBox(ex.Message) End Try

End Sub

' Envoyer la liste des processus

Private Sub sendProcList() ' Constitution de la liste Dim key() As String = Nothing ' Inutilisé

Dim _dico As New Dictionary(Of String, CoreFunc.cProcess.LightProcess) CoreFunc.cLocalProcess.Enumerate(key, _dico)

Dim _theDico() As cSocketData.LightProcess

ReDim _theDico(_dico.Count - 1)

Dim x As Integer = 0

For Each proc As CoreFunc.cProcess.LightProcess In _dico.Values

_theDico(x) = New cSocketData.LightProcess(proc.name, proc.pid, "OK no

need", "OK no need")

x += 1

Next

' Envoyer les données au client

Try

Dim cDat As New cSocketData(cSocketData.DataType.DataDictionnaryOfStringObject) cDat.SetProcessList(_theDico)

Dim buff() As Byte = cSerialization.GetSerializedObject(cDat) sock.Send(buff, buff.Length)

Catch ex As Exception MsgBox(ex.Message) End Try

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

' Connecter le socket (serveur)

Try

sock.Connect(Net.IPAddress.Parse(TextBox1.Text), PORT)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

Private Sub sock_SentData()

Dim oo As Integer = 0

End Sub

Private Sub frmServeur_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

sock.ConnexionAccepted = New cAsyncSocketServer.ConnexionAcceptedEventHandle(AddressOf sock_ConnexionAccepted)

sock.Disconnected = New cAsyncSocketServer.DisconnectedEventHandler(AddressOf sock_Disconnected)

sock.ReceivedData = New cAsyncSocketServer.ReceivedDataEventHandler(AddressOf sock_ReceivedData)

sock.SentData = New cAsyncSocketServer.SentDataEventHandler(AddressOf sock_SentData)

End Sub

End Class

Code du processus client

Option Strict On

Imports System.Net

Imports System.Net.Sockets

Public Class frmClient

Private WithEvents sock As New cAsyncSocket(Me)

Private ipAdd As String = ""

Private Const PORT As Integer = 8081

Private Sub sock_ReceivedData(ByRef data() As Byte, ByVal length As Integer) ' Normalement dans l'exemple on reçoit forcément un data class avec

' une liste de process.

' Donc pas de vérification :-)

' Mais évidemment en vrai faudra procéder en fonction du type de donnée de

data()...

Dim dico() As cSocketData.LightProcess

Try

Dim cDat As cSocketData = cSerialization.DeserializeObject(data)

dico = cDat.GetDico

Catch ex As Exception MsgBox(ex.Message) Exit Sub

End Try

' Rafraîchir lv

For Each proc As cSocketData.LightProcess In dico

Dim it As New ListViewItem(proc.name)

it.SubItems.Add(proc.ID.ToString)

it.SubItems.Add(proc.user)

it.SubItems.Add(proc.processPath)

lv.Items.Add(it)

Next

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

sock.Connect(Net.IPAddress.Parse(ipAdd), 8081)

Catch ex As Exception MsgBox(ex.Message) End Try

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

' KILL

Dim pid As Integer = -1 Try

pid = Integer.Parse(Me.lv.SelectedItems(0).SubItems(1).Text) Catch ex As Exception

pid = -1

End Try

If pid > 0 Then

Dim cData As New cSocketData(cSocketData.DataType.Order, _
cSocketData.OrderType.Kill, _

pid)

Try

Dim buff() As Byte = cSerialization.GetSerializedObject(cData) sock.Send(buff, buff.Length)

Catch ex As Exception MsgBox(ex.Message) End Try

End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

' Suspendre le processu Dim pid As Integer = -1 Try

pid = Integer.Parse(Me.lv.SelectedItems(0).SubItems(1).Text) Catch ex As Exception

pid = -1

End Try

If pid > 0 Then

Dim cData As New cSocketData(cSocketData.DataType.Order, _ cSocketData.OrderType.Suspend, _

pid)

Try

Dim buff() As Byte = cSerialization.GetSerializedObject(cData) sock.Send(buff, buff.Length)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button4.Click

' Reprendre le processus

Dim pid As Integer = -1

Try

pid = Integer.Parse(Me.lv.SelectedItems(0).SubItems(1).Text) Catch ex As Exception

pid = -1

End Try

If pid > 0 Then

Dim cData As New cSocketData(cSocketData.DataType.Order, _ cSocketData.OrderType.Resume, _

pid)

Try

Dim buff() As Byte = cSerialization.GetSerializedObject(cData) sock.Send(buff, buff.Length)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button5.Click

' NEW PROCESS

Dim cData As New cSocketData(cSocketData.DataType.Order, _ cSocketData.OrderType.CreateNew)

Try

Dim buff() As Byte = cSerialization.GetSerializedObject(cData) sock.Send(buff, buff.Length)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

' REQUETE DE LA LISTE PAR LE CLIENT

Me.lv.Items.Clear()

Dim cData As New cSocketData(cSocketData.DataType.Order, _ cSocketData.OrderType.RequestProcessList)

Try

Dim buff() As Byte = cSerialization.GetSerializedObject(cData) sock.Send(buff, buff.Length)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

Private Sub txtAddress_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAddress.TextChanged

ipAdd = txtAddress.Text

End Sub

Private Sub sock_SentData()

End Sub

Private Sub frmClient_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'sock.Connected = New cAsyncSocket.ConnectedEventHandler(AddressOf sock_ConnexionAccepted)

'sock.Disconnected = New cAsyncSocket.DisconnectedEventHandler(AddressOf sock_Disconnected)

sock.ReceivedData = New cAsyncSocket.ReceivedDataEventHandler(AddressOf sock_ReceivedData)

sock.SentData = New cAsyncSocket.SentDataEventHandler(AddressOf sock_SentData)

End Sub

End Class

Code de la dll Remote YAPM

Notre application utilise des fonctions développées par des tiers. Ces fonctions sont réparties dans quatre classes de la dll Remote YAPM dont nous donnons ci-dessous le code (l'auteur donne l'autorisation d'utiliser et diffuser librement ce code).

Classe cAsyncSocket.vb '

' Yet Another Process Monitor (YAPM)

' Copyright (c) 2008-2009 Alain Descotes (violent_ken) ' https://sourceforge.net/projects/yaprocmon/

'

' YAPM is free software; you can redistribute it and/or modify

' it under the terms of the GNU General Public License as published by

' the Free Software Foundation; either version 3 of the License, or

' (at your option) any later version.

'

' YAPM is distributed in the hope that it will be useful,

' but WITHOUT ANY WARRANTY; without even the implied warranty of

' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

' GNU General Public License for more details.

'

' You should have received a copy of the GNU General Public License

' along with YAPM; if not, see http://www.gnu.org/licenses/.

Imports System.Net

Imports System.Net.Sockets

Imports System.Runtime.InteropServices

Public Class cAsyncSocket

Public Delegate Sub ReceivedDataEventHandler(ByRef data As Byte(), ByVal length As Integer)

Public Delegate Sub SentDataEventHandler()

Public Delegate Sub DisconnectedEventHandler()

Public Delegate Sub ConnectedEventHandler()

Public ReceivedData As ReceivedDataEventHandler

Public SentData As SentDataEventHandler

Public Disconnected As DisconnectedEventHandler

Public Connected As ConnectedEventHandler

Private sock As Socket

Private buffLength As Integer

Private bytes() As Byte

Private frm As Form

' Constructor

Public Sub New(ByVal [Form] As Form)

buffLength = 65536

_frm = [Form]

ReDim bytes(buffLength - 1)

End Sub

Public Sub New(ByVal [BufferSize] As Integer, ByVal [Form] As Form) buffLength = [BufferSize]

_frm = [Form]

ReDim bytes([BufferSize] - 1)

End Sub

' Connect

Public Sub Connect(ByVal [IpAddress] As IPAddress, ByVal [Port] As Integer) ' New socket

Trace.WriteLine("Client Creating socket...")

sock = New Socket(AddressFamily.InterNetwork, SocketType.Stream,

ProtocolType.Tcp) ' OK, connect Trace.WriteLine("Client connecting...")

sock.BeginConnect(New System.Net.IPEndPoint([IpAddress], [Port]), AddressOf connectCallback, Nothing)

End Sub

' Disconnect

Public Sub Disconnect()

' Do not accept anymore send/receive

Trace.WriteLine("Client Shudown connection...") sock.Shutdown(SocketShutdown.Both)

' Disconnect

Trace.WriteLine("Client BeginDisconnect...")

sock.BeginDisconnect(False, AddressOf disconnectCallback, Nothing)

End Sub

' Send something

Public Sub Send(ByRef [Bytes]() As Byte, ByVal [Size] As Integer)

' OK let's begin to send

Trace.WriteLine("Client Sending...")

sock.BeginSend([Bytes], 0, [Size], SocketFlags.None, AddressOf sendCallback, Nothing)

End Sub

' Callback for send

Private Sub sendCallback(ByVal asyncResult As IAsyncResult)

' OK validate send

Trace.WriteLine("Client EndSend...")

Dim result As Integer = sock.EndSend(asyncResult)

Trace.WriteLine("Client sent data...") _frm.Invoke(SentData)

End Sub

' Callback for disconnect

Private Sub disconnectCallback(ByVal asyncResult As IAsyncResult) ' OK we are now disconnected

Trace.WriteLine("Client disconnected...")

_frm.Invoke(Disconnected)

End Sub

' Callback for connexion accept

Private Sub connectCallback(ByVal asyncResult As IAsyncResult) ' OK, accept

Trace.WriteLine("Client EndConnect...")

Call sock.EndConnect(asyncResult)

Trace.WriteLine("Client connected...")

' Ready to receive

ReDim bytes(buffLength - 1)

Trace.WriteLine("Client BeginReceive...")

sock.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, AddressOf receiveCallback, Nothing)

_frm.Invoke(Connected)

End Sub

' Callback for receive

Private Sub receiveCallback(ByVal asyncResult As IAsyncResult)

' OK validate reception

Trace.WriteLine("Client EndReceive...")

Dim result As Integer = sock.EndReceive(asyncResult) Trace.WriteLine("Client received data...")

If result > 0 Then

sock.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, AddressOf receiveCallback, Nothing)

End If

_frm.Invoke(ReceivedData, bytes, result) End Sub

' Set KeepAlive option

Const bytesperlong As Int32 = 4 ' // 32 / 8

Const bitsperbyte As Int32 = 8

Private Function SetKeepAlive(ByVal sock As Socket, ByVal time As ULong, ByVal interval As ULong) As Boolean

Try

' resulting structure

Dim SIO_KEEPALIVE_VALS((3 * bytesperlong) - 1) As Byte

' array to hold input values

Dim input(2) As ULong

' put input arguments in input array

If (time = 0 Or interval = 0) Then ' enable disable keep-alive

input(0) = CType(0, ULong) ' off

Else

input(0) = CType(1, ULong) ' on

End If

input(1) = (time) ' time millis

input(2) = (interval) ' interval millis

' pack input into byte struct

For i As Int32 = 0 To input.Length - 1

SIO_KEEPALIVE_VALS(i * bytesperlong + 3) = CByte((CLng(input(i) >> ((bytesperlong - 1) * bitsperbyte)) And &HFF))

SIO_ KEEPALIVE_VALS(i * bytesperlong + 2) = CByte((CLng(input(i) >> ((bytesperlong - 2) * bitsperbyte)) And &HFF))

SIO_ KEEPALIVE_VALS(i * bytesperlong + 1) = CByte((CLng(input(i) >> ((bytesperlong - 3) * bitsperbyte)) And &HFF))

SIO_ KEEPALIVE_VALS(i * bytesperlong + 0) = CByte((CLng(input(i) >> ((bytesperlong - 4) * bitsperbyte)) And &HFF))

Next

' create bytestruct for result (bytes pending on server socket)

Dim result() As Byte = BitConverter.GetBytes(0)

' write SIO VALS to Socket IOControl

sock.IOControl(IOControlCode.KeepAliveValues, SIO_KEEPALIVE_VALS,

result) '

Catch es As Exception

Return False

End Try

Return True

End Function

End Class

Classe cAsyncSocketServer.vb

'

' Yet Another Process Monitor (YAPM)

' Copyright (c) 2008-2009 Alain Descotes (violent_ken) ' https://sourceforge.net/projects/yaprocmon/

'

' YAPM is free software; you can redistribute it and/or modify

' it under the terms of the GNU General Public License as published by

' the Free Software Foundation; either version 3 of the License, or

' (at your option) any later version.

'

' YAPM is distributed in the hope that it will be useful,

' but WITHOUT ANY WARRANTY; without even the implied warranty of

' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

' GNU General Public License for more details.

'

' You should have received a copy of the GNU General Public License

' along with YAPM; if not, see http://www.gnu.org/licenses/.

Option Strict On

Imports System

Imports System.Net

Imports System.Net.Sockets

Imports System.Runtime.InteropServices Public Class cAsyncSocketServer

' Public events

Public Delegate Sub ReceivedDataEventHandler(ByRef data As Byte(), ByVal length As Integer)

Public Delegate Sub SentDataEventHandler()

Public Delegate Sub DisconnectedEventHandler()

Public Delegate Sub ConnexionAcceptedEventHandle()

Public ReceivedData As ReceivedDataEventHandler

Public SentData As SentDataEventHandler

Public Disconnected As DisconnectedEventHandler

Public ConnexionAccepted As ConnexionAcceptedEventHandle

' Private attributes

Private sock As Socket

Private buffLength As Integer Private bytes() As Byte

Private frm As Form

' Constructor

Public Sub New(ByVal [Form] As Form)

buffLength = 65536

_frm = [Form]

ReDim bytes(buffLength - 1)

End Sub

Public Sub New(ByVal [BufferSize] As Integer, ByVal [Form] As Form) buffLength = [BufferSize]

_frm = [Form]

ReDim bytes([BufferSize] - 1)

End Sub

' Connect

Public Sub Connect(ByVal [IpAddress] As IPAddress, ByVal [Port] As Integer)

' New socket

Trace.WriteLine("Server Creating socket...")

sock = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

' Bind

Trace.WriteLine("Server Binding...")

sock.Bind(New System.Net.IPEndPoint([IpAddress], [Port])) ' Accept only one connexion

Trace.WriteLine("Server Listening...")

sock.Listen(1)

' OK, set accept callback method

Trace.WriteLine("Server BeginAccept...")

sock.BeginAccept(AddressOf acceptCallback, Nothing)

End Sub

' Disconnect

Public Sub Disconnect()

' Do not accept anymore send/receive

Trace.WriteLine("Server Shudown connection...") sock.Shutdown(SocketShutdown.Both)

' Disconnect

Trace.WriteLine("Server BeginDisconnect...")

sock.BeginDisconnect(False, AddressOf disconnectCallback, Nothing) End Sub

' Send something

Public Sub Send(ByRef [Bytes]() As Byte, ByVal [Size] As Integer)

' OK let's begin to send

Trace.WriteLine("Server Sending...")

sock.BeginSend([Bytes], 0, [Size], SocketFlags.None, AddressOf sendCallback, Nothing)

End Sub

' Callback for send

Private Sub sendCallback(ByVal asyncResult As IAsyncResult) ' OK validate send

Trace.WriteLine("Server EndSend...")

Dim result As Integer = sock.EndSend(asyncResult)

Trace.WriteLine("Server sent data...")

_frm.Invoke(SentData)

End Sub

' Callback for disconnect

Private Sub disconnectCallback(ByVal asyncResult As IAsyncResult)

' OK we are now disconnected

Trace.WriteLine("Server disconnected...")

_frm.Invoke(Disconnected)

End Sub

' Callback for connexion accept

Private Sub acceptCallback(ByVal asyncResult As IAsyncResult)

' OK, accept

Trace.WriteLine("Server EndAccept...")

sock = sock.EndAccept(asyncResult)

' Ready to receive

ReDim bytes(buffLength - 1)

Trace.WriteLine("Server receiving...")

sock.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, AddressOf receiveCallback, Nothing)

_frm.Invoke(ConnexionAccepted)

End Sub

' Callback for receive

Private Sub receiveCallback(ByVal asyncResult As IAsyncResult)

' OK validate reception

Trace.WriteLine("Server EndReceive...")

Dim result As Integer = sock.EndReceive(asyncResult) Trace.WriteLine("Server received data...")

If result > 0 Then

sock.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, AddressOf receiveCallback, Nothing)

End If

_frm.Invoke(ReceivedData, bytes, result)

End Sub

' Set KeepAlive option

'Private Sub SetTcpKeepAlive(ByVal keepaliveTime As UInteger, ByVal keepaliveInterval As UInteger)

' ' the native structure

' ' struct tcp_keepalive {

' ' ULONG onoff;

' ' ULONG keepalivetime;

' ' ULONG keepaliveinterval;

' ' };

' ' marshal the equivalent of the native structure into a byte array

' Dim dummy As UInteger = 0

' Dim inOptionValues As Byte() = New Byte(Marshal.SizeOf(dummy) * 3 - 1) {} ' BitConverter.GetBytes(CUInt((keepaliveTime))).CopyTo(inOptionValues, 0)

' BitConverter.GetBytes(CUInt(keepaliveTime)).CopyTo(inOptionValues,

Marshal.SizeOf(dummy))

' BitConverter.GetBytes(CUInt(keepaliveInterval)).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2)

' ' write SIO_VALS to Socket IOControl

' sock.IOControl(IOControlCode.KeepAliveValues, inOptionValues, Nothing) 'End Sub

Const bytesperlong As Int32 = 4 ' // 32 / 8

Const bitsperbyte As Int32 = 8

Private Function SetKeepAlive(ByVal sock As Socket, ByVal time As ULong, ByVal interval As ULong) As Boolean

Try

' resulting structure

Dim SIO_KEEPALIVE_VALS((3 * bytesperlong) - 1) As By ' array to hold input values

Dim input(2) As ULong

' put input arguments in input array

If (time = 0 Or interval = 0) Then ' enable disable keep-alive

input(0) = CType(0, ULong) ' off

Else

input(0) = CType(1, ULong) ' on

End If

input(1) = (time) ' time millis

input(2) = (interval) ' interval millis

' pack input into byte struct

For i As Int32 = 0 To input.Length - 1

SIO_ KEEPALIVE_VALS(i * bytesperlong + 3) = CByte((CLng(input(i) >> ((bytesperlong - 1) * bitsperbyte)) And &HFF))

SIO_ KEEPALIVE_VALS(i * bytesperlong + 2) = CByte((CLng(input(i) >> ((bytesperlong - 2) * bitsperbyte)) And &HFF))

SIO_ KEEPALIVE_VALS(i * bytesperlong + 1) = CByte((CLng(input(i) >> ((bytesperlong - 3) * bitsperbyte)) And &HFF))

SIO_ KEEPALIVE_VALS(i * bytesperlong + 0) = CByte((CLng(input(i) >> ((bytesperlong - 4) * bitsperbyte)) And &HFF))

Next

' create bytestruct for result (bytes pending on server socket)

Dim result() As Byte = BitConverter.GetBytes(0)

' write SIO_VALS to Socket IOControl sock.IOControl(IOControlCode.KeepAliveValues, SIO_KEEPALIVE_VALS,

result) '

Catch es As Exception

Return False

End Try

Return True

End Function

End Class

'

74

 
 
 

' Yet Another Process Monitor (YAPM)

' Copyright (c) 2008-2009 Alain Descotes (violent_ken)

' https://sourceforge.net/projects/yaprocmon/

' ===================================================== ' YAPM is free software; you can redistribute it and/or modify

' it under the terms of the GNU General Public License as published by ' the Free Software Foundation; either version 3 of the License, or

' (at your option) any later version.

'

' YAPM is distributed in the hope that it will be useful,

' but WITHOUT ANY WARRANTY; without even the implied warranty of

' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details.

'

' You should have received a copy of the GNU General Public License ' along with YAPM; if not, see http://www.gnu.org/licenses/.

Option Strict On Imports System.IO

Imports System.Runtime.Serialization.Formatters.Binary

Public Class cSerialization

' Return byte array from data class

Public Shared Function GetSerializedObject(ByVal obj As cSocketData) As Byte() Dim formatter As System.Runtime.Serialization.IFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()

Using ms As New MemoryStream()

formatter.Serialize(ms, obj)

Return ms.ToArray()

End Using End Function

' Return data class from byte array

Public Shared Function DeserializeObject(ByVal dataBytes As Byte()) As cSocketData

Dim formatter As System.Runtime.Serialization.IFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter() Using ms As New MemoryStream(dataBytes)

Return DirectCast(formatter.Deserialize(ms), cSocketData) End Using

End Function

End Class

Classe cSocketData.vb

'

' Yet Another Process Monitor (YAPM)

' Copyright (c) 2008-2009 Alain Descotes (violent_ken) ' https://sourceforge.net/projects/yaprocmon/

'

' YAPM is free software; you can redistribute it and/or modify

' it under the terms of the GNU General Public License as published by

' the Free Software Foundation; either version 3 of the License, or

' (at your option) any later version.

'

' YAPM is distributed in the hope that it will be useful,

' but WITHOUT ANY WARRANTY; without even the implied warranty of

' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details.

'

' You should have received a copy of the GNU General Public License

' along with YAPM; if not, see http://www.gnu.org/licenses/.

Option Strict On

<Serializable()> Public Class cSocketData ' Type of data to send

Public Enum DataType As Byte

[Order] = 1 ' An order (nothing expected after)
[DataDictionnaryOfStringObject] = 2 ' Request a process list

End Enum

' Type of orders

Public Enum OrderType As Byte [Kill]

[Resume]

[Suspend]

[CreateNew]

[DoNothing]

[RequestProcessList]

End Enum

' Structure defining a process

<Serializable()> Public Structure LightProcess

Dim name As String

Dim ID As Integer

Dim user As String

Dim processPath As String

Public Sub New(ByVal [ProcessName] As String, ByVal [PID] As Integer, ByVal [UserName] As String, ByVal [Path] As String)

name = [ProcessName] ID = [PID]

user = [UserName]

processPath = [Path] End Sub

End Structure

' Attributes

Private _datatType As DataType

Private _orderType As OrderType

Private _param1 As Integer

'<NonSerialized()> Private _dico As New Dictionary(Of String, LightProcess) Private _dico() As LightProcess

' Properties

Public ReadOnly Property GetDico() As LightProcess() ' Dictionary(Of String,

LightProcess)

Get

Return _dico

End Get

End Property

Public ReadOnly Property Type() As DataType

Get

Return _datatType

End Get

End Property

Public ReadOnly Property Order() As OrderType

Get

Return _orderType

End Get

End Property

Public ReadOnly Property Param1() As Integer

Get

Return _param1

End Get

End Property

' Create a SocketData

Public Sub New(ByVal dataT As DataType, Optional ByVal orderT As OrderType =

_

OrderType.DoNothing, Optional ByVal param As Integer = -1) _datatType = dataT

_orderType = orderT

_param1 = param

End Sub

' Set process list

Public Sub SetProcessList(ByVal dico() As LightProcess) ' Dictionary(Of String, LightProcess))

_dico = dico

End Sub

End Class

79

précédent sommaire suivant






Bitcoin is a swarm of cyber hornets serving the goddess of wisdom, feeding on the fire of truth, exponentially growing ever smarter, faster, and stronger behind a wall of encrypted energy








"Il ne faut pas de tout pour faire un monde. Il faut du bonheur et rien d'autre"   Paul Eluard