如何从DLL确定目标计算机?

如何从DLL确定目标计算机?,dll,cross-platform,Dll,Cross Platform,如何确定给定DLL可以在哪台计算机上运行。有很多平台,包括ARM、SH4、x64、x32。当我除了DLL本身没有其他信息时,怎么做 背景:存在抵消DLL,其中一些是不合适的。如何“离线”检测它们 解决方案 感谢您的帮助:我使用的解决方案是perl脚本 #!/usr/bin/perl # # usage: DllVer <exefile> # use strict; use warnings; use diagnostics; my $exe = $ARGV[0]; my

如何确定给定DLL可以在哪台计算机上运行。有很多平台,包括ARM、SH4、x64、x32。当我除了DLL本身没有其他信息时,怎么做

背景:存在抵消DLL,其中一些是不合适的。如何“离线”检测它们


解决方案

感谢您的帮助:我使用的解决方案是perl脚本

#!/usr/bin/perl 
# 
# usage: DllVer <exefile> 
# 
use strict;
use warnings;
use diagnostics;

my $exe = $ARGV[0]; 
my $doshdr; my $pehdr;
my %machines = (
    0x014c => "I386",
    0x0162 => "R3000",
    0x0166 => "R4000",
    0x0168 => "R10000",
    0x0169 => "WCEMIPSV2",
    0x0184 => "ALPHA",
    0x01a2 => "SH3",
    0x01a3 => "SH3DSP",
    0x01a4 => "SH3E",
    0x01a6 => "SH4",
    0x01c0 => "ARM",
    0x01c2 => "THUMB",
    0x01d3 => "AM33",
    0x01f0 => "POWERPC",
    0x01f1 => "POWERPCFP",
    0x0200 => "IA64",
    0x0266 => "MIPS16",
    0x0284 => "ALPHA64",
    0x0366 => "MIPSFPU",
    0x0466 => "MIPSFPU16",
    0x0520 => "TRICORE",
    0x8664 => "AMD64",
    0x9041 => "M32R",
    );

open(EXE, $exe) or die "can't open $exe: $!"; 
binmode(EXE); 
if (read(EXE, $doshdr, 68)) { 

   my ($magic,$skip,$offset)=unpack('a2a58l', $doshdr); 
   die("Not an executable") if ($magic ne 'MZ'); 

   seek(EXE, $offset, 0); 
   if (read(EXE, $pehdr, 6)){ 
       my ($sig,$skip,$machine)=unpack('a2a2v', $pehdr); 
       die("No a PE Executable") if ($sig ne 'PE'); 

       if (exists $machines{$machine}) {
           print $machines{$machine} . "\n";
       } 
       else{ 
            printf("Unknown machine type 0x%lx\n", $machine); 
       } 
   } 
} 

close(EXE); 
#/usr/bin/perl
# 
#用法:DllVer
# 
严格使用;
使用警告;
使用诊断;
my$exe=$ARGV[0];
我的$doshdr;我的$pehdr;
我的%machines=(
0x014c=>“I386”,
0x0162=>“R3000”,
0x0166=>“R4000”,
0x0168=>“R10000”,
0x0169=>“WCEMIPSV2”,
0x0184=>“ALPHA”,
0x01a2=>“SH3”,
0x01a3=>“SH3DSP”,
0x01a4=>“SH3E”,
0x01a6=>“SH4”,
0x01c0=>“手臂”,
0x01c2=>“拇指”,
0x01d3=>“AM33”,
0x01f0=>“POWERPC”,
0x01f1=>“POWERPCFP”,
0x0200=>“IA64”,
0x0266=>“MIPS16”,
0x0284=>“字母64”,
0x0366=>“MIPSFPU”,
0x0466=>“MIPSFPU16”,
0x0520=>“TRICORE”,
0x8664=>“AMD64”,
0x9041=>“M32R”,
);
打开(EXE,$EXE)或死亡“无法打开$EXE:$!”;
binmode(EXE);
如果(读(EXE,$doshdr,68)){
my($magic,$skip,$offset)=解包($a2a58l',$doshdr);
如果($magic ne'MZ'),则为die(“非可执行文件”);
seek(EXE,$offset,0);
如果(读(EXE,$pehdr,6)){
my($sig,$skip,$machine)=解包($a2a2v',$pehdr);
如果($sig ne'PE'),则为die(“无PE可执行文件”);
if(存在$machines{$machine}){
打印$machines{$machine}。“\n”;
} 
否则{
printf(“未知机器类型0x%lx\n”,$machine);
} 
} 
} 
关闭(EXE);

一种方法是使用dumpbin实用程序:

C:\Windows\System32>dumpbin /headers kernel32.dll
Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file kernel32.dll

PE signature found

File Type: DLL

FILE HEADER VALUES
             14C machine (x86)
               4 number of sections
        49E037DD time date stamp Sat Apr 11 08:25:33 2009
               0 file pointer to symbol table
               0 number of symbols
              E0 size of optional header
            2102 characteristics
                   Executable
                   32 bit word machine
                   DLL

OPTIONAL HEADER VALUES
             10B magic # (PE32)
            8.00 linker version
... etc ...
尝试以下perl脚本:

#!/usr/bin/perl 
# 
# usage: DllVer <exefile> 
# 
$exe = $ARGV[0]; 

open(EXE, $exe) or die "can't open $exe: $!"; 
binmode(EXE); 
if (read(EXE, $doshdr, 68)) { 

   ($magic,$skip,$offset)=unpack('a2a58l', $doshdr); 
   die("Not an executable") if ($magic ne 'MZ'); 

   seek(EXE,$offset,SEEK_SET); 
   if (read(EXE, $pehdr, 6)){ 
       ($sig,$skip,$machine)=unpack('a2a2v', $pehdr); 
       die("No a PE Executable") if ($sig ne 'PE'); 

       if ($machine == 0x014c){ 
            print "i386\n"; 
       } 
       elsif ($machine == 0x0200){ 
            print "IA64\n"; 
       } 
       elsif ($machine == 0x8664){ 
            print "AMD64\n"; 
       } 
       else{ 
            printf("Unknown machine type 0x%lx\n", $machine); 
       } 
   } 
} 

close(EXE); 
#/usr/bin/perl
# 
#用法:DllVer
# 
$exe=$ARGV[0];
打开(EXE,$EXE)或死亡“无法打开$EXE:$!”;
binmode(EXE);
如果(读(EXE,$doshdr,68)){
($magic、$skip、$offset)=解包($a2a58l',$doshdr);
如果($magic ne'MZ'),则为die(“非可执行文件”);
seek(EXE,$offset,seek_SET);
如果(读(EXE,$pehdr,6)){
($sig、$skip、$machine)=解包($a2a2v',$pehdr);
如果($sig ne'PE'),则为die(“无PE可执行文件”);
如果($machine==0x014c){
打印“i386\n”;
} 
elsif($machine==0x0200){
打印“IA64\n”;
} 
elsif($machine==0x8664){
打印“AMD64\n”;
} 
否则{
printf(“未知机器类型0x%lx\n”,$machine);
} 
} 
} 
关闭(EXE);

对不起,天哪,我必须决定接受哪个答案,因为这两个答案都是完全正确的。perl脚本更适合我的需要,因为我计划批量检查数百个文件,而另一个答案使我不必解析一个工具的输出,而我实际上没有这个工具的源代码。无论如何,谢谢。我在我的问题下面放了一个稍微不同的脚本,为其他机器添加代码。谢谢,做得很好。