Vitali Kremez
  • Home
  • About
  • Contact
  • Cyber Security
  • Cyber Intel
  • Programming
  • Reverse Engineering
  • Exploit Development
  • Penetration Test
  • WIN32 Assembly
  • On Writing
    • Blog
    • LSAT
    • Photo
  • Honeypot
  • Forum

Win32 ASsesmbly

Win32: Process List

7/5/2016

0 Comments

 
 ShowProcess PROTO pid:DWORD
   
Core Functions
I. mov pbuf, ptr$(buffer)                          ; cast buffer address to a pointer


    invoke EnumProcesses,pbuf,4096,ADDR breq        ; enumerate processes
    shr breq, 2                                     ; get process cou​

II. invoke ShowProcess,[esi]

III.  mov hProcess, rv(OpenProcess,PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,FALSE,pid)
 .if hProcess != 0
      .if rv(EnumProcessModules,hProcess,ADDR hMod,4,ADDR cbNeeded) != 0
        invoke GetModuleBaseName,hProcess,hMod,pbuf,260
        mov ptxt, cat$(ptxt,"pid ",str$(pid)," ",pbuf)
      .else
        mov ptxt, cat$(ptxt,"pid ",str$(pid)," -fail- EnumProcessModules")
      .endif
    .else
      mov ptxt, cat$(ptxt,"pid ",str$(pid)," -fail- OpenProcess")
    .endif

Core Library
include \masm32\include\psapi.inc
includelib \masm32\lib\psapi.lib
Picture
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        List of All Processes and Its PIDs
        ----------------------------------------------------- *

    include \masm32\include\psapi.inc
    includelib \masm32\lib\psapi.lib

    ShowProcess PROTO pid:DWORD

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL breq  :DWORD
    LOCAL pbuf  :DWORD
    LOCAL buffer[4096]:BYTE

    push esi
    push edi

    mov pbuf, ptr$(buffer)                          ; cast buffer address to a pointer

    invoke EnumProcesses,pbuf,4096,ADDR breq        ; enumerate processes
    shr breq, 2                                     ; get process count

    mov esi, pbuf
    mov edi, breq

  @@:
    invoke ShowProcess,[esi]
    add esi, 4
    sub edi, 1
    jnz @B

    pop edi
    pop esi

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

ShowProcess proc pid:DWORD

    LOCAL hProcess  :DWORD
    LOCAL hMod      :DWORD
    LOCAL cbNeeded  :DWORD
    LOCAL pbuf      :DWORD
    LOCAL ptxt      :DWORD
    LOCAL buf[260]  :BYTE
    LOCAL txt[260]  :BYTE

    mov pbuf, ptr$(buf)
    mov ptxt, ptr$(txt)

    mov hProcess, rv(OpenProcess,PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,FALSE,pid)
                           
    .if hProcess != 0
      .if rv(EnumProcessModules,hProcess,ADDR hMod,4,ADDR cbNeeded) != 0
        invoke GetModuleBaseName,hProcess,hMod,pbuf,260
        mov ptxt, cat$(ptxt,"pid ",str$(pid)," ",pbuf)
      .else
        mov ptxt, cat$(ptxt,"pid ",str$(pid)," -fail- EnumProcessModules")
      .endif
    .else
      mov ptxt, cat$(ptxt,"pid ",str$(pid)," -fail- OpenProcess")
    .endif

    print ptxt,13,10

    invoke CloseHandle,hProcess

    ret

ShowProcess endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
0 Comments



Leave a Reply.

    Author

    Vitali Kremez

    Archives

    July 2016
    June 2016
    May 2016

    Categories

    All

    RSS Feed

Powered by Create your own unique website with customizable templates.
  • Home
  • About
  • Contact
  • Cyber Security
  • Cyber Intel
  • Programming
  • Reverse Engineering
  • Exploit Development
  • Penetration Test
  • WIN32 Assembly
  • On Writing
    • Blog
    • LSAT
    • Photo
  • Honeypot
  • Forum