⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ndiswrapper

📁 ndiswrapper工具
💻
📖 第 1 页 / 共 2 页
字号:
sub parse_key_value {    my $line = shift;    $line = del_comment($line);    if ($line =~ /([^=]+)=(.+)/) {	return (trim($1), trim($2));    } else {	return 0;    }}sub get_target_os_section {    my $secn = shift;    my $arch = `uname -m`;    chomp($arch);    if ($arch =~ /64$/) {	$arch = "AMD64";    } else {	$arch = "X86";    }    chomp($secn);    printf DBG "secn: %s\n", $secn;    $secn =~ s/\.NT($arch)?(\.5\.1)?$//;    printf DBG "secn: %s\n", $secn;    my $lines = get_section($secn . ".NT" . $arch . ".5.1");    return $lines if ($lines);    $lines = get_section($secn . ".NT" . $arch);    return $lines if ($lines);    $lines = get_section($secn . ".NT.5.1");    return $lines if ($lines);    $lines = get_section($secn . ".NT");    return $lines if ($lines);    $lines = get_section($secn);    return $lines if ($lines);    printf DBG "couldn't find section \"$secn\" for \"$arch\"\n";    return 0;}sub get_section_value {    (my $secn, my $name) = @_;    return $parsed_sections{$secn}->{$name};}sub get_string_value {    my $key = shift;    if ($key =~ /%(.+)%/) {	$key = $1;	return get_section_value("Strings", $key);    } else {	return $key;    }}sub copy_file {    my $file = shift;    $file = trim(del_comment($file));    my $real_file = get_file($file);    if (length($real_file) gt 0) {	$file = lc($real_file);	copy("$src_dir/$real_file", "$confdir/$driver_name/$file") or	  warn "couldn't copy \"$src_dir/$real_file\" to " .	    "\"$confdir/$driver_name\": $! -\n" .	      "installation may be incomplete\n";	chmod(0644, "$confdir/$driver_name/$file");    } else {	warn "couldn't find \"$file\" in \"$src_dir\"; make sure " .	  "all driver files, including .inf, .sys (and .bin, if any) " .	    "are in \"$src_dir\" -\n" .	      "installation may be incomplete\n";    }}# for conf files with subvendor and subdevice, create conf files with just# vendor and devicesub create_fuzzy_conf {    my $driver = shift;    my $cwd = cwd();    chdir("$confdir/$driver") or die "couldn't chdir to $confdir/$driver: $!";    open(LS, "ls -1 . |") or die "couldn't open $confdir/$driver: $!";    while (my $file = <LS>) {	chomp($file);	if ($file =~ /^(.{4}):(.{4}):(.{4}):(.{4})\.([^.]+)\.conf$/) {	    my $fuzzy_file = "$1:$2.$5.conf";	    printf DBG "file: $file, fuzzy file: $fuzzy_file\n";	    if (! -e "$confdir/$driver/$fuzzy_file") {		symlink("$file", "$fuzzy_file") or		  warn "couldn't link $confdir/$driver/$file " .		    "to $confdir/$driver/$fuzzy_file: $!\n";	    }	}    }    chdir($cwd) or warn "couldn't chdir to $cwd: $!";    return 0;}# find a file in a case-insensitive way.sub get_file {    my $file = lc(shift);    if (opendir(DIR, "$src_dir")) {	my @allfiles = readdir(DIR);	foreach my $real_file (@allfiles) {	    if (lc($real_file) eq $file) {		closedir(DIR);		return $real_file;	    }	}	closedir(DIR);    } else {	warn "couldn't open \"$src_dir\" - installation may be incomplete\n";    }    return "";}sub strip_quotes {    my $s = shift;    $s =~ s/"(.*)"/$1/;    return $s;}sub del_comment {    my $s = shift;    $s =~ s/;.*//;    return $s;}# remove whitsepace at front and end.sub trim {    my $s = shift;    $s =~ s/^\s*//;    $s =~ s/\s*$//;    return $s;}sub device_driver_alias {    my ($devid, $driver) = @_;    my $done = 0;    $devid = uc($devid);    if (!($devid =~ /[0-9A-Z]{4}:[0-9A-Z]{4}/)) {	printf "'$devid' is not a valid device ID\n";	return 1;    }    open(LS, "ls -1 $confdir/$driver/ |") or      die "couldn't open $confdir/$driver: $!";    while (my $f = <LS>) {	chomp($f);	if ($f =~ /\.([0-9A-F]+).conf$/) {	    if (symlink("$f", "$confdir/$driver/$devid.$1.conf")) {		printf "driver '$driver' is used for '$devid'\n";		$done = 1;		last;	    } else {		warn "couldn't create symlink for \"$f\" -\n" .		  "installation may be incomplete\n";	    }	}    }    close(LS);    if ($done == 0) {	printf "driver '$driver' is not installed (properly)!\n";	return 1;    }    return 0;}sub generate_module_device_map {    my $mode = shift;    my $vendor, my $device, my $subvendor, my $subdevice, my $bustype, my $busid;    my $device_map;    if (-d "/etc/modprobe.d") {	$device_map = "/etc/modprobe.d/ndiswrapper";    } elsif (-d "/etc/modules.d") {	$device_map = "/etc/modules.d/ndiswrapper";    } else {	$device_map = "/etc/ndiswrapper/ndiswrapper";    }    open(CONF, "| sort >$device_map") or      die "couldn't create modules alias file $device_map: $!";    open(LS, "ls -1 $confdir|") or      die "couldn't open $confdir: $!";    while (my $driver = <LS>) {	chomp($driver);	my $stat = (stat("$confdir/$driver"))[2];	if (S_ISDIR($stat)) {	    open(LS2, "ls -1 $confdir/$driver/ |") or	      die "couldn't open $confdir/$driver: $!";	    while (my $file = <LS2>) {		chomp ($file);		if ($file =~ /.conf$/) {		    if ($file =~ /^(.{4}):(.{4}):(.{4}):(.{4})\.([^.]+)\.conf$/) {			($vendor, $device, $subvendor, $subdevice, $busid) =			  ($1, $2, "0000$3", "0000$4", $5);		    } elsif ($file =~ /(.{4}):(.{4})\.([^.]+)\.conf$/) {			($vendor, $device, $subvendor, $subdevice, $busid) =			  ($1, $2, "*", "*", "$3");		    }		    my $devstring;		    if ($busid eq $WRAP_USB_BUS) {			$devstring = sprintf("usb:v%sp%sd*dc*dsc*dp*ic*isc*ip*",					     $vendor, $device);		    } elsif ($busid eq $WRAP_PCI_BUS) {			$devstring = sprintf("pci:v0000%sd0000%ssv%ssd%sbc*sc*i*",					     $vendor, $device, $subvendor,					     $subdevice);		    } else {			warn "wrong bustype ($busid) for " .			  "configuration file $file - ignoring it\n";			next;		    }		    if ($mode == 0) {			printf CONF "alias %s ndiswrapper\n", $devstring;		    } else {			printf CONF "install %s /sbin/modprobe ndiswrapper\n",			  $devstring;		    }		}	    }	    close(LS2);	}    }    close(CONF);    close(LS);    printf "module configuration information is stored in $device_map\n";    return 0;}sub list_drivers {    my $s;    my $cards = get_cards();    open(LS, "ls -1 $confdir|") or die "couldn't open $confdir: $!";    while (my $driver = <LS>) {	chomp($driver);	if (-e "$confdir/$driver") {	    $s .= "$driver\t". install_status($cards, $driver) . "\n";	}    }    close(LS);    if ($s) {	printf "installed drivers:\n$s";    } else {	printf "no drivers installed\n$s";    }    return 0;}sub add_module_alias {    my $alias = 0;    open(MODPROBE, "modprobe -c|") or die "couldn't run modprobe: $!";    while (my $line = <MODPROBE>) {	if ($line =~ /^alias\s.+\sndiswrapper/) {	    printf "modprobe config already contains alias directive\n\n";	    $alias = 1;	} elsif ($line =~ /^install\s.*ndiswrapper/) {	    warn "module configuration contains directive $line;" .	      "you should delete that";	} elsif ($line =~ /^post-install\s+ndiswrapper/) {	    warn "module configuration contains directive $line;" .	      "you should delete that";	}    }    close(MODPROBE);    if ($alias) {	return 0;    }    printf "adding \"alias wlan0 ndiswrapper\" to $modconf ...\n";    system("echo \"alias wlan0 ndiswrapper\" >>$modconf") or      die "couldn't add module alias: $!";    if (-x "/sbin/update-modules") {	system("/sbin/update-modules");    }    return 0;}sub get_cards {#01:00.0 Class 0300: 1002:4c66 (rev 01)#        Subsystem: 1043:1732    my @cards = ();    my @lspci = ("/sbin/lspci", "/usr/sbin/lspci", "lspci");    foreach my $cmd (@lspci) {	if (open(LSPCI, "$cmd -vn|")) {	    my $card;	    while (my $line = <LSPCI>) {		if ($line =~ /^[0-9a-f]+.+\s+([0-9a-f]{4}):([0-9a-f]{4})/i) {		    $card = {vendor => uc($1), device => uc($2)};		    printf DBG "card: %s, %s\n", $1, $2;		} elsif ($line =~ /.+Subsystem:\s*([0-9a-f]{4}):([0-9a-f]{4})/i) {		    $card->{subvendor} = uc($1);		    $card->{subdevice} = uc($2);		    printf DBG "sub: %s, %s\n", $1, $2;		    push(@cards, $card);		}	    }	    last;	}    }    my @lsusb = ("/sbin/lsusb", "/usr/sbin/lsusb", "lsusb");    foreach my $cmd (@lsusb) {	if (open(LSUSB, "$cmd |")) {	    my $card;	    while (my $line = <LSUSB>) {		if ($line =~ /.*: ID\s(.{4}):(.{4}).*/) {		    $card = {vendor => uc($1), device => uc($2)};		    push(@cards, $card);		}	    }	    last;	}    }    return \@cards;}sub install_status {    my ($cards, $driver) = @_;    my $sys = 0;    my $conf = 0;    my $inf = 0;    my $vendor, my $device, my $subvendor, my $subdevice, my $busid;    if (!$cards) {	return;    }    open(LS2, "ls -1 $confdir/$driver|") or      die "couldn't open $confdir/$driver: $!";    while (my $file = <LS2>) 	{	chomp($file);	if ($file =~ /\.sys$/) {	    $sys = 1;	} elsif ($file =~ /\.inf$/) {	    $inf = 1;	} elsif ($file =~ /\.conf$/) {	    $conf = 1 if ($conf eq 0);	    if ($file =~ /^(.{4}):(.{4}):(.{4}):(.{4})\.([^.]+)\.conf$/) {		($vendor, $device, $subvendor, $subdevice, $busid) =		  (uc($1), uc($2), uc($3), uc($4), uc($5));		foreach my $card (@{$cards}) {		    if ($card->{vendor} eq $vendor and			$card->{device} eq $device and			$card->{subvendor} eq $subvendor and			$card->{subdevice} eq $subdevice) {			$conf = 3;			last;		    }		}	    } elsif ($file =~ /(.{4}):(.{4})\.([^.]+)\.conf/) {		($vendor, $device, $subvendor, $subdevice, $busid) =		  (uc($1), uc($2), "\\*", "\\*", uc($3));		foreach my $card (@{$cards}) {		    if ($card->{vendor} eq $vendor and			$card->{device} eq $device) {			my $stat = (lstat("$confdir/$driver/$file"))[2];			if (S_ISLNK($stat)) {			    $conf = 2;			} else {			    $conf = 3;			}			last;		    }		}	    }	}    }    close(LS2);    my $ret;    if ($sys eq 0 || $inf eq 0 || $conf eq 0) {	$ret = "invalid driver!";    } else {	if ($conf eq 1) {	    $ret = "\tdriver installed ";	} else {	    $ret = "\tdriver installed, hardware ($vendor:$device) present ";	}	my $devstring;	if ($busid eq $WRAP_USB_BUS) {	    $devstring =	      sprintf("usb:v%sp%sd", $vendor, $device);	} elsif ($busid eq $WRAP_PCI_BUS) {	    $devstring =	      sprintf("pci:v0000%sd0000%ssv", $vendor, $device);	}	my $alt_driver;	open(MODPROBE, "modprobe -c|") or die "couldn't run modprobe: $!";	while (my $line = <MODPROBE>) {	    chomp($line);	    $alt_driver = (split(' ', $line))[-1] if $line =~ /$devstring/;	    chomp($alt_driver);	    if (length($alt_driver) gt 0 and $alt_driver ne "ndiswrapper") {		$ret .= "(alternate driver: $alt_driver)";		last;	    }	}	close(MODPROBE);    }    return $ret;}## Local Variables: #### cperl-indent-level: 4 #### End: ##

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -