peass-ng/PEASS-ng · error · ArgumentException

illegal object in GetInstance:

Error message

illegal object in GetInstance: 

What it means

DerGraphicString.GetInstance() only accepts byte[], DerGraphicString, or an Asn1TaggedObject. If the object is any other type, the library throws an ArgumentException naming the offending runtime type via Platform.GetTypeName(obj). This is a type-mismatch guard, not a data corruption error.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGraphicString.cs:38

        {
            if (obj == null || obj is DerGraphicString)
            {
                return (DerGraphicString)obj;
            }

            if (obj is byte[])
            {
                try
                {
                    return (DerGraphicString)FromByteArray((byte[])obj);
                }
                catch (Exception e)
                {
                    throw new ArgumentException("encoding error in GetInstance: " + e.ToString(), "obj");
                }
            }

            throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj), "obj");
        }

        /**
         * return a Graphic String from a tagged object.
         *
         * @param obj the tagged object holding the object we want
         * @param explicit true if the object is meant to be explicitly
         *              tagged false otherwise.
         * @exception IllegalArgumentException if the tagged object cannot
         *               be converted.
         * @return a DerGraphicString instance, or null.
         */
        public static DerGraphicString GetInstance(Asn1TaggedObject obj, bool isExplicit)
        {
            Asn1Object o = obj.GetObject();

            if (isExplicit || o is DerGraphicString)
            {

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Check the object's concrete Asn1Object type before calling GetInstance
  2. Parse via Asn1Object.FromByteArray and pattern-match on the result type
  3. If a tagged object is intended, use the GetInstance(Asn1TaggedObject, bool) overload explicitly
  4. Fix the ASN.1 schema assumption that produced the unexpected type

Example fix

// before
var s = DerGraphicString.GetInstance(parsedObject);
// after
var s = parsedObject as DerGraphicString
    ?? DerGraphicString.GetInstance(((Asn1TaggedObject)parsedObject).GetObject());
Defensive patterns

Strategy: type-guard

Type guard

DerGraphicString TryAsGraphicString(object o) =>
    o as DerGraphicString ?? (o is Asn1TaggedObject t ? t.GetObject() as DerGraphicString : null);

Try / catch

try { var s = DerGraphicString.GetInstance(obj); }
catch (ArgumentException ex) when (ex.Message.StartsWith("illegal object")) {
    throw new InvalidDataException($"unexpected ASN.1 type: {obj?.GetType().Name}", ex);
}

Prevention

When it happens

Trigger: Calling DerGraphicString.GetInstance(object) with an object that is neither byte[], DerGraphicString, nor Asn1TaggedObject (e.g. a DerUtf8String, string, or Asn1Sequence).

Common situations: Misreading ASN.1 structure so a different ASN.1 type is passed in; switching between overloads; generic parsing code that assumes all parsed objects are GraphicStrings.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/b36417a901376d47. Report an issue: GitHub.