Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   AutoIt (http://forum.oszone.net/forumdisplay.php?f=103)
-   -   [решено] Проверка отличия в процессах (http://forum.oszone.net/showthread.php?t=137927)

RageHunter 17-04-2009 02:25 1096371

Проверка отличия в процессах
 
Здравствуйте!
Много раз пробовал как можно это реализовать но так ни чего и не пришло в голову. В AutoIt есть команды для проверки (есть ли такой процесс), отключения и т.д. процессов, но нет команды для сравнивания процесса.
Предположим есть 2 файла с одинаковыми названиями например programs.exe и programs.exe при запуске 1 и 2 процесы так же называются programs.exe и отличить их не возможно, хотя программы разные и например CRC у них разное. Так вот прошу подскажите как и что написать что бы AutoIt сравнил процессы programs.exe можду собой и с первым или вторым файлом и дал результат какой файл запущен, а какой нет (вся проблема в том что я знаю как выполнить сравнение файлов например по тому же самому CRC но как сравнить файл с процессом хз). И еще может какая-то библиотека может в этом помочь?

Заранее Спасибо за ответы!

Creat0R 17-04-2009 03:03 1096375

Цитата:

Цитата RageHunter
как и что написать что бы AutoIt сравнил процессы programs.exe можду собой и с первым или вторым файлом и дал результат какой файл запущен »

Можно отличить по пути к исполняемому файлу:

Код:

$Path = _ProcessGetPath("AutoIt3.exe")
ConsoleWrite($Path)

;===============================================================================
;
; Function Name:    _ProcessGetPath()
; Description:      Get the executable path of certain process.
;
; Parameter(s):    $vProcess - PID or name of a process.
;
; Requirement(s):  AutoIt v3.2.8.1 or higher.
;                  Kernel32.dll (included with Windows)
;                  Psapi.dll (included with most Windows versions)
;
; Return Value(s):  On Success - Returns full path to the executed process.
;                  On Failure - Returns -1 and sets @Error to:
;                                                              1 - Given process not exists.
;                                                              2 - Error to call Kernel32.dll.
;                                                              3 - Error to open Psapi.dll.
;                                                              4 - Unable to locate path of executed process,
;                                                                  (or can be other error related to DllCall).
;
; Author(s):        G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru)
;
;===============================================================================

Func _ProcessGetPath($vProcess)
    Local $iPID = ProcessExists($vProcess)
    If Not $iPID Then Return SetError(1, 0, -1)

    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If Not IsArray($aProc) Or Not $aProc[0] Then Return SetError(2, 0, -1)

    Local $vStruct = DllStructCreate('int[1024]')

    Local $hPsapi_Dll = DllOpen('Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then Return SetError(3, 0, '')

    DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
        'hwnd', $aProc[0], _
        'ptr', DllStructGetPtr($vStruct), _
        'int', DllStructGetSize($vStruct), _
        'int_ptr', 0)
    Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
        'hwnd', $aProc[0], _
        'int', DllStructGetData($vStruct, 1), _
        'str', '', _
        'int', 2048)

    DllClose($hPsapi_Dll)

    If Not IsArray($aRet) Or StringLen($aRet[3]) = 0 Then Return SetError(4, 0, '')
    Return $aRet[3]
EndFunc


proxy 17-04-2009 03:30 1096378

Для своих AutoIt файлов делал так: по процессу получал Handle GUI окна этого процесса и проверял на верность - мое коно или нет ...

amel27 17-04-2009 05:17 1096389

Creat0R, не пойму зачем EnumProcessModules, и без нее вроде работает... :dont-know
Код:

$sProcess  = "svchost.exe"
$sFilePath = _WinAPI_ProcessGetFilePath($sProcess)
If @error Then Exit MsgBox(16, "Ошибка", "код ошибки:"&@TAB& @error &@CRLF&"расширение:"&@TAB& @extended)
MsgBox(0, "Сообщение", "процесс:"&@TAB& $sProcess &@CRLF&"путь:"&@TAB& $sFilePath)

Func _WinAPI_ProcessGetFilePath($process)
    $process = ProcessExists($process)
    If $process =0 Then Return SetError(1, 0, "") ; ОШИБКА: процесс не найден
    ; Открытие процесса

    Local $aRet = DllCall('kernel32.dll', 'ptr', 'OpenProcess', _
        'int', BitOR(0x400,0x10), 'int', 0, 'int', $process)
    Local $hProc = $aRet[0], $tFilePath = DllStructCreate("char[300]")
    If $aRet[0]=0 Then
        $aRet = DllCall('kernel32.dll', 'int', 'GetLastError')
        Return SetError(2, $aRet[0], "")          ; ОШИБКА открытия процесса
    EndIf
    ; Получение пути к файлу образа
    $aRet = DllCall("Psapi.dll", "dword", "GetModuleFileNameExA", _
        "ptr", $hProc, "ptr", 0, "ptr", DllStructGetPtr($tFilePath), "dword", 300)
    If $aRet=0 Then
        $aRet = DllCall('kernel32.dll', 'int', 'GetLastError')
        Return SetError(3, $aRet[0], "")          ; ОШИБКА получения имени
    EndIf
    ; Закрытие описателя и возврат значения
    DllCall('kernel32.dll','ptr', 'CloseHandle','ptr', $hProc)
    Return DllStructGetData($tFilePath, 1)
EndFunc ;==> _WinAPI_ProcessGetFilePath


RageHunter 17-04-2009 10:13 1096492

Цитата:

Цитата amel27
Creat0R, не пойму зачем EnumProcessModules, и без нее вроде работает...
Код:

$sProcess = "svchost.exe"
$sFilePath = _WinAPI_ProcessGetFilePath($sProcess)
If @error Then Exit MsgBox(16, "Ошибка", "код ошибки:"&@TAB& @error &@CRLF&"расширение:"&@TAB& @extended)
MsgBox(0, "Сообщение", "процесс:"&@TAB& $sProcess &@CRLF&"путь:"&@TAB& $sFilePath)
Func _WinAPI_ProcessGetFilePath($process)
 $process = ProcessExists($process)
 If $process =0 Then Return SetError(1, 0, "") ; ОШИБКА: процесс не найден
 ; Открытие процесса
 Local $aRet = DllCall('kernel32.dll', 'ptr', 'OpenProcess', _
 'int', BitOR(0x400,0x10), 'int', 0, 'int', $process)
 Local $hProc = $aRet[0], $tFilePath = DllStructCreate("char[300]")
 If $aRet[0]=0 Then
 $aRet = DllCall('kernel32.dll', 'int', 'GetLastError')
 Return SetError(2, $aRet[0], "") ; ОШИБКА открытия процесса
 EndIf
 ; Получение пути к файлу образа
 $aRet = DllCall("Psapi.dll", "dword", "GetModuleFileNameEx", _
 "ptr", $hProc, "ptr", 0, "ptr", DllStructGetPtr($tFilePath), "dword", 300)
 If $aRet=0 Then
 $aRet = DllCall('kernel32.dll', 'int', 'GetLastError')
 Return SetError(3, $aRet[0], "") ; ОШИБКА получения имени
 EndIf
 ; Закрытие описателя и возврат значения
 DllCall('kernel32.dll','ptr', 'CloseHandle','ptr', $hProc)
 Return DllStructGetData($tFilePath, 1)
EndFunc ;==> _WinAPI_ProcessGetFilePath


Спасибо, то что надо!

Creat0R 17-04-2009 14:42 1096722

Цитата:

Цитата amel27
зачем EnumProcessModules »

Не знаю, я делал по аналогу другой-подобной функции, тогда ещё плохо понимал как оно вообще работает, главное что работало :tongue:

Цитата:

Цитата RageHunter
Спасибо, то что надо! »

Для этого есть ссылочка под каждым сообщением: Полезное сообщение
;)


Время: 11:15.

Время: 11:15.
© OSzone.net 2001-