这个输出究竟是什么(哪个characterset)以及如何将其转换为有意义的内容?
use Win32::API;
$EnumProcesses= new Win32::API( 'psapi', 'EnumProcesses','PNP');
$aBuffer = " " x 4096;
$bBuffer = " " x 4096;
$EnumProcesses->Call($aBuffer,4096,$bBuffer);
print $aBuffer,"\n",$bBuffer,"\n";
答案 0 :(得分:6)
您是否阅读过EnumProcesses文档以及其中的example内容?看起来你根本就没有处理角色数据。 EnumProcesses使用N个4字节(或DWORD)记录填充$abuffer
,每个进程一个。这个4字节的值只是一个数字,而不是4个字符。
如果您想获得有关特定流程的更多信息,您需要将此4字节数字(在Win API文档中称为“流程标识符”)提供给OpenProcess等函数或PrintProcessNameAndID。
这是将结果显示为4字节小端数字的代码:
use Modern::Perl; # strict, warnings, 5.10 features
use Win32::API;
my $EnumProcesses= new Win32::API( 'psapi', 'EnumProcesses','PNP');
my $process_ids_packed = " " x 4096;
my $num_processes_packed = " " x 4; # you don't need 4096 here.
$EnumProcesses->Call($process_ids_packed,4096,$num_processes_packed);
my ($num_processes) = unpack "V", $num_processes_packed;
my @process_ids = unpack "V$num_processes", $process_ids_packed;
for (@process_ids) {
say;
}
结果如下:
C:\Users\pgp\Documents\src\tmp>perl winapi.pl
0
4
252
392
464
472
520
536
544
596
692
748
780
788
912
964
412
456
908
1116
1212
1228
1460
1492
1520
1528
1576
1724
1740
1748
1988
2028
312
2288
2544
2592
2756
3004
3116
3216
3340
3048
2792
1320
2868
3760
2404
4196
2692
4084
1768
538976288
538976288
538976288
538976288
538976288
[... lots more lines ...]
538976288
538976288
538976288
538976288
538976288
538976288
答案 1 :(得分:0)