📄 ndiswrapper
字号:
#Examples:#Vendor#Vendor,ME,NT,NT.5.1#Vendor.NTx86 my $manu = getSection("manufacturer"); if(!$manu) { return -1; } my @lines = split("\n", $manu->{data}); for(my $i = 0; $i < @lines; $i++) { my $line = remComment($lines[$i]); (my $key, my $val) = getKeyVal($line, "="); if ($key eq $version{"Provider"}) { $strings{$key} = trim($val); } if($val) { my $section; my @flavours = split(",", $val); my $flavour = ""; if(@flavours == 1) { #Vendor $section = $val; } else { #Vendor,flavour1, flavour2 etc; for(my $i = 1; $i < @flavours; $i++) { my $flav = trim($flavours[$i]); $flav =~ s/\s*(\S+)\s*/$1/; if(uc($flav) eq "NT.5.1") { #This is the best (XP) $section = $flavours[0] . "." . $flav; $flavour = $flav; } elsif(substr(uc($flav),0,2) eq "NT" and $section eq "") { #This is the second best (win2k) $section = $flavours[0] . "." . $flav; $flavour = $flav; } } } my $res = parseVendor($flavour, $section); if(!$res) { return $res; } } }}## Parse a vendor section. This section contains the device-ids. Each poiting to a section with config info.# sub parseVendor{ my $flavour = shift; my $vendor_name = shift; my $vend = getSection($vendor_name); if(!$vend) { print "no vendor\n"; return -1; } my @lines = split("\n", $vend->{data}); for(my $i = 0; $i < @lines; $i++) { my $line = remComment($lines[$i]); (my $name, my $val) = getKeyVal($line, "="); if($val) { (my $section, my $id) = split(",", $val); $section = trim($section); $id = trim($id); ($bustype, my $vendor, my $device, my $subvendor, my $subdevice) = parseID($id); if($vendor) { parseDevice($flavour, $section, $vendor, $device, $subvendor, $subdevice); } } }}## This section contains pointers to registry sections and copyfiles sections. #sub parseDevice{ my $flavour = shift; my $device_sect = shift; my $device = shift; my $vendor = shift; my $subvendor = shift; my $subdevice = shift; my $dev = getSection("$device_sect.$flavour"); if(!$dev) { $dev = getSection("$device_sect.NT"); } if(!$dev) { $dev = getSection("$device_sect.NTx86"); } if(!$dev) { $dev = getSection("$device_sect"); } if(!$dev) { print "no dev $device_sect $flavour\n"; return -1; }# print "$device:$vendor:$subvendor:$subdevice $flavour\n"; my $copyfiles; my $addreg; my @lines = split("\n", $dev->{data}); for(my $i = 0; $i < @lines; $i++) { my $line = remComment($lines[$i]); (my $key, my $val) = getKeyVal($line, "="); if($key) { if(lc($key) eq "addreg") { $addreg = $val; } if(lc($key) eq "copyfiles") { $copyfiles = $val; } } } my $filename = "$device:$vendor"; if($subvendor) { $filename .= ":$subvendor:$subdevice" } $filename .= ".$bustype.conf"; if($bustype == 5) { addPCIFuzzEntry($device, $vendor, $subvendor, $subdevice); } if(!open(CONF, ">$confdir/$driver_name/$filename")) { print "Unable to create file $filename"; return -1; } my $ver=$version{"DriverVer"}; my $provider=$version{"Provider"}; my $providerstring = stripquotes(substStr(trim($provider))); printf CONF "NdisVersion|0x50001\n"; printf CONF "Environment|1\n"; printf CONF "BusType|$bustype\n"; printf CONF "mac_address|XX:XX:XX:XX:XX:XX\n"; printf CONF "ndis_version|$providerstring,$ver\n\n"; close(CONF); if(!open(CONF, "|sort|uniq >>$confdir/$driver_name/$filename")) { print "Unable to create file $filename"; return -1; } my @addregs = split(",", $addreg); for(my $i = 0; $i < @addregs; $i++) { my $reg = trim($addregs[$i]); addReg($reg); } my @copyfiles = split(",", $copyfiles); for(my $i = 0; $i < @copyfiles; $i++) { my $file = trim($copyfiles[$i]); copyfiles($file); } close(CONF);}## Process a copyfiles section.#sub copyfiles{ my $copy_name = shift; my $copy = getSection($copy_name); if(!$copy) { printf "Parse error in inf. Unable to find section $copy_name\n"; return -1; } my @lines = split("\n", $copy->{data}); for(my $i = 0; $i < @lines; $i++) { my $line = $lines[$i]; $line = trim($line); last if (!$line); last if ($line =~ /^\[/); my @files = split(",", $line); for (my $j = 0; $j < @files; $j++) { my $file = $files[$j]; $file =~ s/^;//; $file = trim(remComment($file)); $file =~ s/,+.*//; $file = trim($file); my $nocopy = 0; for(my $k = 0; $k < @copy_blacklist; $k++) { if($copy_blacklist[$k] eq lc($file)) { $nocopy = 1; } } my $dir = finddir($file); if($dir) { $dir = findfile("", $dir); } my $realname = findfile($dir, $file); if($realname) { my $newname = lc($realname); if($dir) { $realname = "$dir/$realname"; } if(!$nocopy) { `cp -u $instdir/$realname $confdir/$driver_name/$newname`; `chmod 644 $confdir/$driver_name/$newname`; } } } }}sub finddir{ my $filename = shift; my $sourcedisksfiles = getSection("sourcedisksfiles"); if(!$sourcedisksfiles) { return ""; } my @lines = split("\n", $sourcedisksfiles->{data}); for(my $i = 0; $i < @lines; $i++) { my $line = trim(remComment($lines[$i])); $line =~ /(.+)=.+,+(.*)/; my $file = trim($1); my $dir = trim($2); if($file and $dir and lc($filename) eq lc($file)) { return $dir; } } return "";}## Find a file in a case-insensitive way.#sub findfile{ my $dir = shift; my $file = shift; if(!opendir(DIR, "$instdir/$dir")) { print "Unable to open $instdir\n"; return ""; } my @allfiles = readdir(DIR); for(my $i = 0; $i < @allfiles; $i++) { if(lc($allfiles[$i]) eq lc($file)) { closedir(DIR); return $allfiles[$i]; } } closedir(DIR); return "";}## This section contains pointers to the section with the parameters to be# added to the registry.#sub addReg{ my $reg_name = shift; my $reg = getSection($reg_name); if(!$reg) { printf "Parse error in inf. Unable to find section $reg_name\n"; return -1; } my $param; my $type; my $val; my $found; my $gotParam = 0; my @lines = split("\n", $reg->{data}); for(my $i = 0; $i < @lines; $i++) { my $line = trim(remComment($lines[$i])); if($line) { $line =~ /([^,]*),([^,]*),([^,]*),([^,]*),(.*)/; my $hkr = trim($1); my $p1 = stripquotes(substStr(trim($2))); my $p2 = stripquotes(substStr(trim($3))); my $p3 = stripquotes(substStr(trim($4))); my $p4 = stripquotes(substStr(trim($5))); if($p1) { if($p1 =~ /ndi\\params\\(.+)/i) { $1 =~ /(.+)\\.*/; if($1 ne $param) { $found = 0; $param = $1; $type = ""; $val = ""; } if(lc($p2) eq "type") { $found++; $type = $p4; } elsif(lc($p2) eq "default") { $found++; $val = $p4; } if($found == 2) { $gotParam = 1; } } } else { #print "type 2: $reg_name '$p1', '$p2', '$p3', '$p4':'$line'\n"; $param = $p2; $val = $p4; $gotParam = 1; } if($gotParam and $param ne "BusType" and $param ne "") { my $s = "$param|$val"; if($param_fixlist{"$s"}) { my $sOld = $s; $s = $param_fixlist{"$s"}; print "Forcing parameter $sOld to $s\n"; } print CONF "$s\n"; $param = ""; $gotParam = 0; } } }}sub substStr{ my $s = shift; if($s =~ /^\%(.+)$\%/) { return getString($1); } return $s;}## Parse a device-id line.#sub parseID{ my $s = uc(shift); if($s =~ /PCI\\VEN_(\w+)&DEV_(\w+)&SUBSYS_(\w{4})(\S{4})/) { return (5, $1, $2, $4, $3); } elsif($s =~ /PCI\\VEN_(\w+)&DEV_(\w+)/) { return (5, $1, $2); } elsif($s =~ /USB\\VID_(\w+)&PID_(\w+)/) { return (0, $1, $2); }}## remove whitsepace at front and end.#sub trim{ my $s = shift; $s =~ s/^\s*//; $s =~ s/\s*$//; return $s;}sub stripquotes{ my $s = shift; $s =~ s/"(.*)"/$1/; return $s;}sub getKeyVal{ my $line = shift; $line = remComment($line); (my $key, my $val) = split("=", $line); if($line =~ /(.+)=(.+)/) { return (trim($1), trim($2)); }}sub remComment{ my $s = shift; $s=~ s/([^;]*);.*/$1/; return $s;}## Initialize the string symbol table#sub initStrings{ my $s = getSection("strings"); if(!$s) { return; } my @lines = split("\n", $s->{data}); for(my $i = 0; $i < @lines; $i++) { (my $key, my $val) = getKeyVal($lines[$i]); if($key) { $val =~ s/"(.+)"/$1/; $strings{$key} = $val;# print "$key=$val\n"; } }}## fetch a string from the symbol table#sub getString{ my $s = shift; return $strings{$s};}## Loacate a section.#sub getSection{ my $needle = shift; for(my $i = 0; $i < @sections; $i++) {# print "Searching: '" . lc($sections[$i]->{name}) . "' == '" . lc($needle) . "'\n"; if( lc($sections[$i]->{name}) eq lc($needle)) {# print "found!\n\n"; return $sections[$i]; } }# print "not found!\n\n"; return 0;}## Load inf and split into different sections.#sub loadinf{ my $filename = shift; my %def_section; my $section = \%def_section; if(!open(INF, $filename)) { return -1; } my $i = 0; $section->{name} = "none"; while(my $s = <INF>) { #Convert from unicode $s =~ s/\xff\xfe//; $s =~ s/\0//g; $s =~ s/\s*$//; #Remove trailing whitespace and \r $s .= "\n"; if($s =~ /^\[(.+)\]\s*/) { $sections[$i++] = $section; my %new_section; $section = \%new_section; $section->{name} = $1; } else { $section->{data} .= $s; } } $sections[$i++] = $section; close(INF);# print "Sections:\n";# for(my $i = 0; $i < @sections; $i++)# {# print $sections[$i]->{name} . "\n"; # }# print "\n";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -