11using System ;
22using System . Collections . Generic ;
3- #if NET35_OR_GREATER || NETCOREAPP
4- using System . Linq ;
5- #endif
63using System . Text ;
74using System . Text . RegularExpressions ;
85using BinaryObjectScanner . Interfaces ;
6+ using SabreTools . IO . Extensions ;
97using SabreTools . Matching ;
108using SabreTools . Matching . Content ;
119using SabreTools . Matching . Paths ;
@@ -68,7 +66,7 @@ namespace BinaryObjectScanner.Protection
6866 // TODO: Investigate reference to "CD32COPS.DLL" in "WETFLIPP.QZ_" in IA item "Triada_Russian_DVD_Complete_Collection_of_Erotic_Games".
6967 // TODO: Investigate cdcode.key for redump ID 108167, may be key-less cd-cops?
7068 // TODO: Document update 12 for redump ID 108167 bumping version, adding key, adding vista(?) support
71-
69+
7270 public class CDDVDCops : IExecutableCheck < NewExecutable > , IExecutableCheck < PortableExecutable > , IPathCheck
7371 {
7472 /// <inheritdoc/>
@@ -127,30 +125,18 @@ public class CDDVDCops : IExecutableCheck<NewExecutable>, IExecutableCheck<Porta
127125
128126 // Check the imported-name table
129127 // Found in "h3blade.exe" in Redump entry 85077.
130- #if NET20
131- bool intMatch = false ;
132- if ( nex . Model . ImportedNameTable ? . Values != null )
128+ if ( nex . Model . ImportedNameTable != null )
133129 {
134130 foreach ( var inte in nex . Model . ImportedNameTable . Values )
135131 {
136- if ( inte ? . NameString == null || inte . NameString . Length == 0 )
132+ if ( inte . NameString . IsNullOrEmpty ( ) )
137133 continue ;
138134
139- string ns = Encoding . ASCII . GetString ( inte . NameString ) ;
135+ string ns = Encoding . ASCII . GetString ( inte . NameString ! ) ;
140136 if ( ns . Contains ( "CDCOPS" ) )
141- {
142- intMatch = true ;
143- break ;
144- }
137+ return "CD-Cops" ;
145138 }
146139 }
147- #else
148- bool intMatch = nex . Model . ImportedNameTable ? . Values ?
149- . Select ( inte => inte ? . NameString == null ? string . Empty : Encoding . ASCII . GetString ( inte . NameString ) )
150- . Any ( s => s . Contains ( "CDCOPS" ) ) ?? false ;
151- #endif
152- if ( intMatch )
153- return "CD-Cops" ;
154140
155141 // Check the nonresident-name table
156142 // Found in "CDCOPS.DLL" in Redump entry 85077.
@@ -190,22 +176,22 @@ public class CDDVDCops : IExecutableCheck<NewExecutable>, IExecutableCheck<Porta
190176 // Found in "FGP.exe" in IA item "flaklypa-grand-prix-dvd"/Redump entry 108169.
191177 if ( pex . ContainsSection ( "UNICops" , exact : true ) )
192178 return "UNI-Cops" ;
193-
179+
194180 // Get the DATA section, if it exists
195181 // Found in "bib.dll" in IA item "https://archive.org/details/cover_202501"
196182 // This contains the version section that the Content Check looked for. There are likely other sections
197183 // that may contain it. Update when more are found.
198184 var strs = pex . GetFirstSectionStrings ( "DATA" ) ;
199185 if ( strs != null )
200186 {
201- var match = strs . Find ( s => s . Contains ( " ver. " ) && ( s . Contains ( "CD-Cops, " ) || s . Contains ( "DVD-Cops, " ) ) ) ;
187+ var match = strs . Find ( s => s . Contains ( " ver. " ) && ( s . Contains ( "CD-Cops, " ) || s . Contains ( "DVD-Cops, " ) ) ) ;
202188 if ( match != null )
203189 if ( match . Contains ( "CD-Cops" ) )
204190 return $ "CD-Cops { GetVersionString ( match ) } ";
205191 else if ( match . Contains ( "DVD-Cops" ) )
206192 return $ "DVD-Cops { GetVersionString ( match ) } ";
207193 }
208-
194+
209195 return null ;
210196 }
211197
@@ -281,7 +267,7 @@ public List<string> CheckDirectoryPath(string path, List<string>? files)
281267
282268 return version ;
283269 }
284-
270+
285271 private static string GetVersionString ( string match )
286272 {
287273 // Full string ends with # (i.e. "CD-Cops, ver. 1.72, #"), use that to compensate for comma in version
@@ -290,7 +276,7 @@ private static string GetVersionString(string match)
290276 var versionMatch = Regex . Match ( match , @"(?<=D-Cops,\s{1,}ver. )(.*?)(?=,\s{1,}#)" ) ;
291277 if ( versionMatch . Success )
292278 return versionMatch . Value ;
293-
279+
294280 return "(Unknown Version - Please report to us on GitHub)" ;
295281 }
296282 }
0 commit comments