{"record":{"id":"de4942fd24ef8ec1","repo":"peass-ng/PEASS-ng","slug":"illegal-object-in-getinstance-de4942","errorCode":null,"errorMessage":"illegal object in GetInstance: ","messagePattern":"illegal object in GetInstance: ","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGeneralString.cs","lineNumber":20,"sourceCode":"using winPEAS._3rdParty.BouncyCastle.crypto.util;\nusing winPEAS._3rdParty.BouncyCastle.util;\n\nnamespace winPEAS._3rdParty.BouncyCastle.asn1\n{\n    public class DerGeneralString\n       : DerStringBase\n    {\n        private readonly string str;\n\n        public static DerGeneralString GetInstance(\n            object obj)\n        {\n            if (obj == null || obj is DerGeneralString)\n            {\n                return (DerGeneralString)obj;\n            }\n\n            throw new ArgumentException(\"illegal object in GetInstance: \"\n                    + Platform.GetTypeName(obj));\n        }\n\n        public static DerGeneralString GetInstance(\n            Asn1TaggedObject obj,\n            bool isExplicit)\n        {\n            Asn1Object o = obj.GetObject();\n\n            if (isExplicit || o is DerGeneralString)\n            {\n                return GetInstance(o);\n            }\n\n            return new DerGeneralString(((Asn1OctetString)o).GetOctets());\n        }\n\n        public DerGeneralString(","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGeneralString.cs#L2-L38","documentation":"This GetInstance overload performs a strict cast: it only accepts null or an existing DerGeneralString and returns it unchanged; it does not convert other object types. Anything else (e.g. DerUtf8String, DerPrintableString, byte[]) triggers ArgumentException naming the actual runtime type.","triggerScenarios":"Calling DerGeneralString.GetInstance(obj) with an Asn1Object that is a different string type (DerUtf8String, DerPrintableString, DerBmpString, etc.) or a non-ASN.1 object.","commonSituations":"Parsing certificates/protocols where a field encoded as another ASN.1 string type is fetched as GeneralString; code that assumed GetInstance converts between string types; changes in encoding by the data producer.","solutions":["Use the correct GetInstance for the actual type (e.g. DerUtf8String.GetInstance) or convert via obj.ToString()/GetString()","If any string type is acceptable, check 'obj is DerGeneralString' first and otherwise decode via Asn1Object.GetEncoded re-parse or accept a DerString base","Verify the ASN.1 module definition to confirm the field really is GeneralString"],"exampleFix":"// before\nvar gs = (DerGeneralString)DerGeneralString.GetInstance(obj); // throws if obj is DerUtf8String\n// after\nvar gs = obj is DerGeneralString g ? g\n       : new DerGeneralString(obj is Asn1String s ? s.GetString() : obj.ToString());","handlingStrategy":"type-guard","validationCode":"if (obj is DerGeneralString gs) { /* use gs */ }","typeGuard":"static bool IsDerGeneralString(Asn1Object o) => o is DerGeneralString;","tryCatchPattern":"try { var gs = DerGeneralString.GetInstance(obj); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"illegal object in GetInstance\")) { /* convert */ }","preventionTips":["Type-check before strict GetInstance calls","Know the declared ASN.1 type of each field"],"tags":["asn1","bouncycastle","type-cast","argument-validation"],"backgroundTag":"illegal-object-in-getinstance","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}