C
cyl
Below is my code to enumerate services. The returned buffer $lpServices
is an array of the structure ENUM_SERVICE_STATUS. After unpacking it, I
got the memory address of the variable lpServiceName which points to
somewhere in the buffer $lpServices. My problem is how do I reference
the address? Unlike a C program, I cannot reference that value
directly. What should I do?
typedef struct _SERVICE_STATUS {
DWORD dwServiceType;
DWORD dwCurrentState;
DWORD dwControlsAccepted;
DWORD dwWin32ExitCode;
DWORD dwServiceSpecificExitCode;
DWORD dwCheckPoint;
DWORD dwWaitHint;
} SERVICE_STATUS;
typedef struct _ENUM_SERVICE_STATUS {
LPTSTR lpServiceName;
LPTSTR lpDisplayName;
SERVICE_STATUS ServiceStatus;
} ENUM_SERVICE_STATUS;
---CODE---
use Win32::API;
my $fnOpenSCManager = Win32::API->new('Advapi32.dll', 'OpenSCManager',
'PPI', 'I');
my $fnEnumServicesStatus = Win32::API->new('Advapi32.dll',
'EnumServicesStatus', 'IIIPIPPP', 'I');
my $hSCManager = $fnOpenSCManager->Call(0,0,0x000f003f);
die unless $hSCManager;
my $cbBufSize = 4;
my $pcbBytesNeeded = pack("N",0);
my $lpServicesReturned = pack("N",0);
my $lpResumeHandle = pack("N",0);
my @Services;
@Services[0 .. 36*$cbBufSize] = 0;
my $lpServices = pack("N*",@Services);
my $ret = $fnEnumServicesStatus->Call( $hSCManager,
0x3B, #SERVICE_DRIVER |
SERVICE_WIN32
0x3, #SERVICE_STATE_ALL
$lpServices,
36*$cbBufSize,
$pcbBytesNeeded,
$lpServicesReturned,
$lpResumeHandle
);
is an array of the structure ENUM_SERVICE_STATUS. After unpacking it, I
got the memory address of the variable lpServiceName which points to
somewhere in the buffer $lpServices. My problem is how do I reference
the address? Unlike a C program, I cannot reference that value
directly. What should I do?
typedef struct _SERVICE_STATUS {
DWORD dwServiceType;
DWORD dwCurrentState;
DWORD dwControlsAccepted;
DWORD dwWin32ExitCode;
DWORD dwServiceSpecificExitCode;
DWORD dwCheckPoint;
DWORD dwWaitHint;
} SERVICE_STATUS;
typedef struct _ENUM_SERVICE_STATUS {
LPTSTR lpServiceName;
LPTSTR lpDisplayName;
SERVICE_STATUS ServiceStatus;
} ENUM_SERVICE_STATUS;
---CODE---
use Win32::API;
my $fnOpenSCManager = Win32::API->new('Advapi32.dll', 'OpenSCManager',
'PPI', 'I');
my $fnEnumServicesStatus = Win32::API->new('Advapi32.dll',
'EnumServicesStatus', 'IIIPIPPP', 'I');
my $hSCManager = $fnOpenSCManager->Call(0,0,0x000f003f);
die unless $hSCManager;
my $cbBufSize = 4;
my $pcbBytesNeeded = pack("N",0);
my $lpServicesReturned = pack("N",0);
my $lpResumeHandle = pack("N",0);
my @Services;
@Services[0 .. 36*$cbBufSize] = 0;
my $lpServices = pack("N*",@Services);
my $ret = $fnEnumServicesStatus->Call( $hSCManager,
0x3B, #SERVICE_DRIVER |
SERVICE_WIN32
0x3, #SERVICE_STATE_ALL
$lpServices,
36*$cbBufSize,
$pcbBytesNeeded,
$lpServicesReturned,
$lpResumeHandle
);