peass-ng/PEASS-ng · error · ArgumentException
illegal object in GetInstance:
Error message
illegal object in GetInstance:
What it means
DerEnumerated.GetInstance mirrors DerBoolean.GetInstance: it accepts only null or an existing DerEnumerated instance. Any other object type produces this ArgumentException, with the runtime type name appended, because ASN.1 ENUMERATED cannot be represented by other Der* classes.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerEnumerated.cs:26
: Asn1Object
{
private readonly byte[] bytes;
private readonly int start;
/**
* return an integer from the passed in object
*
* @exception ArgumentException if the object cannot be converted.
*/
public static DerEnumerated GetInstance(
object obj)
{
if (obj == null || obj is DerEnumerated)
{
return (DerEnumerated)obj;
}
throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj));
}
/**
* return an Enumerated from a tagged object.
*
* @param obj the tagged object holding the object we want
* @param explicitly true if the object is meant to be explicitly
* tagged false otherwise.
* @exception ArgumentException if the tagged object cannot
* be converted.
*/
public static DerEnumerated GetInstance(
Asn1TaggedObject obj,
bool isExplicit)
{
Asn1Object o = obj.GetObject();
if (isExplicit || o is DerEnumerated)View on GitHub (pinned to 53fb989abc)
Solutions
- Use the type named in the exception message, e.g. DerInteger.GetInstance(obj), then convert with new DerEnumerated(intVal) if semantics allow
- For tagged objects call GetInstance((Asn1TaggedObject)obj, true)
- Confirm the ASN.1 schema marks the field ENUMERATED and the encoder complies
- Catch ArgumentException and treat the field as invalid
Example fix
// before
var e = DerEnumerated.GetInstance(asn1Obj);
// after
var e = asn1Obj is DerEnumerated en ? en
: asn1Obj is DerInteger i ? new DerEnumerated(i.PositiveValue)
: throw new FormatException("not an ENUMERATED"); Defensive patterns
Strategy: type-guard
Validate before calling
bool ok = obj == null || obj is DerEnumerated;
Type guard
bool IsDerEnumerated(object o) => o is DerEnumerated;
Try / catch
try { var e = DerEnumerated.GetInstance(obj); }
catch (ArgumentException ex) { /* inspect type name in ex.Message, handle fallback */ } Prevention
- Match GetInstance to the actual ASN.1 type (DerInteger vs DerEnumerated)
- Unwrap Asn1TaggedObject before GetInstance
- Confirm schema types against the encoder implementation
- Add parser tests for wrong-type fields
When it happens
Trigger: Calling DerEnumerated.GetInstance(obj) with a DerInteger, DerSequence, DerOctetString, or any non-DerEnumerated object; parsing an ASN.1 field declared ENUMERATED that arrived encoded as a different type.
Common situations: Parsing X.509 extensions, CRL reason codes, or PKCS structures where an ENUMERATED field is unexpectedly an INTEGER (some encoders emit INTEGER for enumerated values); using the wrong GetInstance overload for tagged objects.
Related errors
- illegal object in GetInstance:
- unknown object encountered in constructed OCTET STRING:
- unknown tag {tagNo} encountered
- unexpected end-of-contents marker
- indefinite-length primitive encoding encountered
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/39f78b6878e5eaa2.
Report an issue: GitHub.