From 634e72a9475e6f8f860c9bece7938af54b13d9e3 Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Wed, 11 Oct 2023 09:10:49 +0000 Subject: [PATCH 01/20] Setup module folder structure --- jdwp/__init__.py | 0 jdwp/common.py | 84 ++++++++++++++++++++++++++++++++++++++++ jdwp/reference_type.py | 0 jdwp/thread_reference.py | 0 4 files changed, 84 insertions(+) create mode 100644 jdwp/__init__.py create mode 100644 jdwp/common.py create mode 100644 jdwp/reference_type.py create mode 100644 jdwp/thread_reference.py diff --git a/jdwp/__init__.py b/jdwp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jdwp/common.py b/jdwp/common.py new file mode 100644 index 0000000..ad1fa19 --- /dev/null +++ b/jdwp/common.py @@ -0,0 +1,84 @@ +"""Basic types for JDWP messages.""" + + +class Type: + pass + + +class String(Type): + pass + + +class Int(Type): + pass + + +# Define Field class +class Field: + def __init__(self, name, type): + self.name = name + self.type = type + + +# Define Struct class +class Struct: + def __init__(self, fields): + self.fields = fields + + +# Define Command class +class Command: + def __init__(self, name, id, out, reply): + self.name = name + self.id = id + self.out = out + self.reply = reply + + +# Define CommandSet class +class CommandSet: + def __init__(self, name, id, commands): + self.name = name + self.id = id + self.commands = commands + + +# Create JDWP message descriptions +Version = Command( + name="version", + id=1, + out=None, + reply=Struct( + [ + Field("description", String), + Field("jdwp major", Int), + Field("jdwp minor", Int), + Field("vm version", String), + Field("vm name", String), + ] + ), +) + +ClassesBySignature = Command( + name="classes by signature", + id=2, + out=Struct( + [ + Field("signature", String), + ] + ), + reply=Struct( + [ + # ... (other fields) + ] + ), +) + +VirtualMachine = CommandSet( + name="VirtualMachine", + id=1, + commands=[ + Version, + ClassesBySignature, + ], +) diff --git a/jdwp/reference_type.py b/jdwp/reference_type.py new file mode 100644 index 0000000..e69de29 diff --git a/jdwp/thread_reference.py b/jdwp/thread_reference.py new file mode 100644 index 0000000..e69de29 From f574e351e306120d726eba0f34c9331a0df37147 Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Wed, 11 Oct 2023 15:12:42 +0000 Subject: [PATCH 02/20] Build referenceType and threaReference command set --- jdwp/commands/reference_type.py | 576 ++++++++++++++++++++++++++++++ jdwp/commands/thread_reference.py | 411 +++++++++++++++++++++ 2 files changed, 987 insertions(+) create mode 100644 jdwp/commands/reference_type.py create mode 100644 jdwp/commands/thread_reference.py diff --git a/jdwp/commands/reference_type.py b/jdwp/commands/reference_type.py new file mode 100644 index 0000000..e9497c1 --- /dev/null +++ b/jdwp/commands/reference_type.py @@ -0,0 +1,576 @@ +"""JDWP Commands for Reference Type Command Set.""" +from jdwp.common import Command, CommandSet, Field, Struct, Types + + +Signature = Command( + name="Signature", + id=1, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The Reference type ID."), + ] + ), + reply=Struct( + [ + Field( + "signature", Types.STRING, "The JNI signature for the reference type." + ), + ] + ), + error=Struct([]), +) + +ClassLoader = Command( + name="Class loader", + id=2, + out=Struct( + [ + Field( + "refType", + Types.REFERENCE_TYPE_ID, + "The reference type ID.", + ), + ] + ), + reply=Struct( + [ + Field( + "classLoaderID", + Types.CLASS_LOADER, + "The class loader for the reference type.", + ), + ] + ), + error=Struct([]), +) + +Modifiers = Command( + name="Modifiers", + id=3, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), + reply=Struct( + [ + Field( + "modBits", + Types.INT, + "Modifier bits as defined in Chapter 4 of The Java™ Virtual Machine Specification. ", + ), + ] + ), + error=Struct([]), +) + +Fields = Command( + name="Fields", + id=4, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), + reply=Struct( + [ + Field("declared", Types.INT, "Number of declared fields."), + Field("fieldID", Types.FIELD_ID, "Field ID."), + Field("name", Types.STRING, "Name of field."), + Field("signature", Types.STRING, "JNI Signature of field."), + Field( + "modBits", + Types.INT, + "The modifier bit flags (also known as access flags).", + ), + ] + ), + error=Struct( + [ + Field( + "CLASS_NOT_PREPARED", + Types.STRING, + "Class has been loaded but not yet prepared.", + ), + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +Methods = Command( + name="Methods", + id=5, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), + reply=Struct( + [ + Field("declared", Types.INT, "Number of declared methods."), + Field("methodID", Types.METHOD_ID, "Method ID."), + Field("name", Types.STRING, "Name of method."), + Field("signature", Types.STRING, "JNI signature of method."), + Field( + "modBits", + Types.INT, + "The modifier bit flags (also known as access flags).", + ), + ] + ), + error=Struct( + [ + Field( + "CLASS_NOT_PREPARED", + Types.STRING, + "Class has been loaded but not yet prepared.", + ), + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +GetValues = Command( + name="Get values", + id=6, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + Field("fields", Types.INT, "The number of values to get."), + ] + ), + reply=Struct( + [ + Field( + "values", + Types.INT, + "The number of values returned, always equal to fields.", + ), + Field("value", Types.VALUE, "The field value."), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("INVALID_FIELDID", Types.STRING, "Invalid field."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + + +SourceFile = Command( + name="Sourcefile", + id=7, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field( + "sourceFile", + Types.STRING, + "The source file name. No path information for the file is included", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field( + "ABSENT_INFORMATION", + Types.STRING, + "The source file attribute is absent.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +NestedTypes = Command( + name="Nested types", + id=8, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("classes", Types.INT, "The number of nested classes and interfaces"), + Field("refTypeTag", Types.BYTE, "Kind of following reference type."), + Field( + "typeID", Types.REFERENCE_TYPE_ID, "The nested class or interface ID." + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +Status = Command( + name="Status", + id=9, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("status", Types.INT, "Status bits: See JDWP.ClassStatus"), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +Interfaces = Command( + name="Interfaces", + id=10, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("interfaces", Types.INT, "The number of implemented interfaces"), + Field("interfaceType", Types.INTERFACE_ID, "Implemented interface."), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +ClassObject = Command( + name="Class object", + id=11, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct([Field("classObject", Types.CLASS_OBJECT_ID, "Class object.")]), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +SourceDebugExtension = Command( + name="Source debug extension", + id=12, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct([Field("extension", Types.STRING, "Extension attribute.")]), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field( + "ABSENT_INFORMATION", Types.STRING, "If the extension is not specified." + ), + Field( + "NOT_IMPLEMENTED", + Types.STRING, + "The functionality is not implemented in this virtual machine.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +SignatureWithGeneric = Command( + name="Signature with generic", + id=13, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field( + "signature", Types.STRING, "The JNI signature for the reference type." + ), + Field( + "genericSignature", + Types.STRING, + "The generic signature for the reference type or an empty string if there is none.", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +FieldsWithGeneric = Command( + name="Fields with generic", + id=14, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("declared", Types.INT, "Number of declared fields."), + Field("fieldID", Types.FIELD_ID, "Field ID."), + Field("name", Types.STRING, "The name of the field."), + Field("signature", Types.STRING, "The JNI signature of the field."), + Field( + "genericSignature", + Types.STRING, + "The generic signature of the field, or an empty string if there is none.", + ), + Field("modBits", Types.INT, "The modifier bit flags."), + ] + ), + error=Struct( + [ + Field( + "CLASS_NOT_PREPARED", + Types.STRING, + "Class has been loaded but not yet prepared.", + ), + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + + +MethodsWithGeneric = Command( + name="Methods with generic", + id=15, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("declared", Types.INT, "Number of declared methods."), + Field("methodID", Types.METHOD_ID, "Method ID."), + Field("name", Types.STRING, "The name of the method."), + Field("signature", Types.STRING, "The JNI signature of the method."), + Field( + "genericSignature", + Types.STRING, + "The generic signature of the method, or an empty string if there is none.", + ), + Field("modBits", Types.INT, "The modifier bit flags."), + ] + ), + error=Struct( + [ + Field( + "CLASS_NOT_PREPARED", + Types.STRING, + "Class has been loaded but not yet prepared.", + ), + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +Instances = Command( + name="Instances", + id=16, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + Field("maxInstances", Types.INT, "Maximum number of instances to return."), + ] + ), + reply=Struct( + [ + Field("instances", Types.INT, "The number of instances that follow."), + Field( + "instance", + Types.TAGGED_OBJECT_ID, + "An instance of this reference type.", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field("ILLEGAL_ARGUMENT", Types.STRING, "maxInstances is less than zero."), + Field( + "NOT_IMPLEMENTED", + Types.STRING, + "The functionality is not implemented in this virtual machine.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + + +ClassFileVersion = Command( + name="Class file version", + id=17, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The class.")]), + reply=Struct( + [ + Field("majorVersion", Types.INT, "Major version number"), + Field("minorVersion", Types.INT, "Minor version number"), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field( + "ABSENT_INFORMATION", + Types.STRING, + "The class file version information is absent for primitive and array types.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +ConstantPool = Command( + name="Constant pool", + id=18, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The class.")]), + reply=Struct( + [ + Field( + "count", Types.INT, "Total number of constant pool entries plus one." + ), + Field("bytes", Types.BYTE, "Raw bytes of constant pool"), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + Types.STRING, + "refType is not the ID of a reference type.", + ), + Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field( + "NOT_IMPLEMENTED", + Types.STRING, + "If the target virtual machine does not support the retrieval of constant pool information.", + ), + Field( + "ABSENT_INFORMATION", + Types.STRING, + "The Constant Pool information is absent for primitive and array types.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +ReferenceType = CommandSet( + name="VirtualMachine", + id=2, + commands=[ + Signature, + ClassLoader, + Modifiers, + Fields, + Methods, + GetValues, + SourceFile, + NestedTypes, + Status, + Interfaces, + ClassObject, + SourceDebugExtension, + SignatureWithGeneric, + FieldsWithGeneric, + MethodsWithGeneric, + Instances, + ClassFileVersion, + ConstantPool, + ], +) diff --git a/jdwp/commands/thread_reference.py b/jdwp/commands/thread_reference.py new file mode 100644 index 0000000..ab5feb1 --- /dev/null +++ b/jdwp/commands/thread_reference.py @@ -0,0 +1,411 @@ +"""JDWP Commands for ThreadReference Command Set.""" + +from jdwp.common import Command, CommandSet, Field, Struct, Types + +Name = Command( + name="Name", + id=1, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct([Field("threadName", Types.STRING, "The thread name.")]), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + + +Suspend = Command( + name="Suspend", + id=2, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +Resume = Command( + name="Resume", + id=3, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +Status = Command( + name="Status", + id=4, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field( + "threadStatus", + Types.INT, + "One of the thread status codes. See JDWP.ThreadStatus", + ), + Field( + "suspendStatus", + Types.INT, + "One of the suspend status codes. See JDWP.SuspendStatus", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +ThreadGroup = Command( + name="Thread group", + id=5, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field( + "threadGroupID", + Types.THREAD_GROUP_ID, + "The thread group of this thread.", + ) + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +Frames = Command( + name="Frames", + id=6, + out=Struct( + [ + Field("threadID", Types.THREAD_ID, "The thread object ID."), + Field("startFrame", Types.INT, "The index of the first frame to retrieve."), + Field( + "length", + Types.INT, + "The count of frames to retrieve (-1 means all remaining).", + ), + ] + ), + reply=Struct( + [ + Field("frames", Types.INT, "The number of frames retrieved"), + Field("frameID", Types.FRAME_ID, "The ID of this frame."), + Field("location", Types.LOCATION, "The location of this frame."), + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +FrameCount = Command( + name="Frame count", + id=7, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [Field("frameCount", Types.INT, "The count of frames on this thread's stack.")] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +OwnedMonitors = Command( + name="Owned monitors", + id=8, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field("owned", Types.INT, "The number of owned monitors"), + Field("monitor", Types.TAGGED_OBJECT_ID, "An owned monitor"), + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field( + "NOT_IMPLEMENTED", + Types.STRING, + "The functionality is not implemented in this virtual machine.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +CurrentContendedMonitor = Command( + name="Current contended monitor", + id=9, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field( + "monitor", + Types.OBJECT_ID, + "The contended monitor, or null if there is no current contended monitor.", + ) + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field( + "NOT_IMPLEMENTED", + Types.STRING, + "The functionality is not implemented in this virtual machine.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +Stop = Command( + name="Stop", + id=10, + out=Struct( + [ + Field("threadID", Types.THREAD_ID, "The thread object ID."), + Field( + "throwable", + Types.OBJECT_ID, + "Asynchronous exception. This object must be an instance of java.lang.Throwable or a subclass", + ), + ] + ), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + Types.STRING, + "If thread is not a known ID or the asynchronous exception has been garbage collected.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +Interrupt = Command( + name="Interrupt", + id=11, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +SuspendCount = Command( + name="Suspend count", + id=12, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field( + "suspendCount", + Types.INT, + "The number of outstanding suspends of this thread.", + ) + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +OwnedMonitorsStackDepthInfo = Command( + name="Owned monitors stack depth info", + id=13, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field("owned", Types.INT, "The number of owned monitors"), + Field("monitor", Types.TAGGED_OBJECT_ID, "An owned monitor"), + Field( + "stack_depth", + Types.INT, + "Stack depth location where monitor was acquired", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), + Field( + "NOT_IMPLEMENTED", + Types.STRING, + "The functionality is not implemented in this virtual machine.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + +ForceEarlyReturn = Command( + name="Force early return", + id=14, + out=Struct( + [ + Field("threadID", Types.THREAD_ID, "The thread object ID."), + Field("value", Types.VALUE, "The value to return."), + ] + ), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + Types.STRING, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field("INVALID_OBJECT", Types.STRING, "Thread or value is not a known ID."), + Field( + "THREAD_NOT_SUSPENDED", + Types.STRING, + "If the specified thread has not been suspended by an event.", + ), + Field( + "THREAD_NOT_ALIVE", + Types.STRING, + "Thread has not been started or is now dead.", + ), + Field( + "OPAQUE_FRAME", + Types.STRING, + "Attempted to return early from a frame corresponding to a native method. Or the implementation is unable to provide this functionality on this frame.", + ), + Field( + "NO_MORE_FRAMES", + Types.STRING, + "There are no more Java or JNI frames on the call stack.", + ), + Field( + "NOT_IMPLEMENTED", + Types.STRING, + "The functionality is not implemented in this virtual machine.", + ), + Field( + "TYPE_MISMATCH", + Types.STRING, + "Value is not an appropriate type for the return value of the method.", + ), + Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + ] + ), +) + + +ThreadReference = CommandSet( + name="ThreadReference", + id=11, + commands=[ + Name, + Suspend, + Resume, + Status, + ThreadGroup, + Frames, + FrameCount, + OwnedMonitors, + CurrentContendedMonitor, + Stop, + Interrupt, + SuspendCount, + OwnedMonitorsStackDepthInfo, + ForceEarlyReturn, + ], +) From 91e35dce6b0eb65e8547abd15f3bb5b0cf45557e Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Wed, 11 Oct 2023 15:13:07 +0000 Subject: [PATCH 03/20] Build consants for jdwp commands --- jdwp/constants/class_status.py | 12 ++++++ jdwp/constants/errors.py | 64 ++++++++++++++++++++++++++++++++ jdwp/constants/event_kind.py | 33 ++++++++++++++++ jdwp/constants/invoke_options.py | 9 +++++ jdwp/constants/step_depth.py | 11 ++++++ jdwp/constants/step_size.py | 10 +++++ jdwp/constants/suspend_policy.py | 11 ++++++ jdwp/constants/suspend_status.py | 9 +++++ jdwp/constants/tag.py | 23 ++++++++++++ jdwp/constants/thread_status.py | 12 ++++++ jdwp/constants/type_tag.py | 11 ++++++ 11 files changed, 205 insertions(+) create mode 100644 jdwp/constants/class_status.py create mode 100644 jdwp/constants/errors.py create mode 100644 jdwp/constants/event_kind.py create mode 100644 jdwp/constants/invoke_options.py create mode 100644 jdwp/constants/step_depth.py create mode 100644 jdwp/constants/step_size.py create mode 100644 jdwp/constants/suspend_policy.py create mode 100644 jdwp/constants/suspend_status.py create mode 100644 jdwp/constants/tag.py create mode 100644 jdwp/constants/thread_status.py create mode 100644 jdwp/constants/type_tag.py diff --git a/jdwp/constants/class_status.py b/jdwp/constants/class_status.py new file mode 100644 index 0000000..0cd2b8e --- /dev/null +++ b/jdwp/constants/class_status.py @@ -0,0 +1,12 @@ +"""Class Status enum class.""" + +from enum import Enum + + +class ClassStatus(Enum): + """ClassStatus constants for JDWP.""" + + VERIFIED = 1 + PREPARED = 2 + INITIALIZED = 4 + ERROR = 8 diff --git a/jdwp/constants/errors.py b/jdwp/constants/errors.py new file mode 100644 index 0000000..df211ab --- /dev/null +++ b/jdwp/constants/errors.py @@ -0,0 +1,64 @@ +"""Errors enum class.""" +from enum import Enum + + +class ErrorConstants(Enum): + """Error constants for JDWP.""" + + NONE = 0 + INVALID_THREAD = 10 + INVALID_THREAD_GROUP = 11 + INVALID_PRIORITY = 12 + THREAD_NOT_SUSPENDED = 13 + THREAD_SUSPENDED = 14 + THREAD_NOT_ALIVE = 15 + INVALID_OBJECT = 20 + INVALID_CLASS = 21 + CLASS_NOT_PREPARED = 22 + INVALID_METHODID = 23 + INVALID_LOCATION = 24 + INVALID_FIELDID = 25 + INVALID_FRAMEID = 30 + NO_MORE_FRAMES = 31 + OPAQUE_FRAME = 32 + NOT_CURRENT_FRAME = 33 + TYPE_MISMATCH = 34 + INVALID_SLOT = 35 + DUPLICATE = 40 + NOT_FOUND = 41 + INVALID_MONITOR = 50 + NOT_MONITOR_OWNER = 51 + INTERRUPT = 52 + INVALID_CLASS_FORMAT = 60 + CIRCULAR_CLASS_DEFINITION = 61 + FAILS_VERIFICATION = 62 + ADD_METHOD_NOT_IMPLEMENTED = 63 + SCHEMA_CHANGE_NOT_IMPLEMENTED = 64 + INVALID_TYPESTATE = 65 + HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66 + DELETE_METHOD_NOT_IMPLEMENTED = 67 + UNSUPPORTED_VERSION = 68 + NAMES_DONT_MATCH = 69 + CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70 + METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71 + NOT_IMPLEMENTED = 99 + NULL_POINTER = 100 + ABSENT_INFORMATION = 101 + INVALID_EVENT_TYPE = 102 + ILLEGAL_ARGUMENT = 103 + OUT_OF_MEMORY = 110 + ACCESS_DENIED = 111 + VM_DEAD = 112 + INTERNAL = 113 + UNATTACHED_THREAD = 115 + INVALID_TAG = 500 + ALREADY_INVOKING = 502 + INVALID_INDEX = 503 + INVALID_LENGTH = 504 + INVALID_STRING = 506 + INVALID_CLASS_LOADER = 507 + INVALID_ARRAY = 508 + TRANSPORT_LOAD = 509 + TRANSPORT_INIT = 510 + NATIVE_METHOD = 511 + INVALID_COUNT = 512 diff --git a/jdwp/constants/event_kind.py b/jdwp/constants/event_kind.py new file mode 100644 index 0000000..42f1b64 --- /dev/null +++ b/jdwp/constants/event_kind.py @@ -0,0 +1,33 @@ +"""EventKind enum class.""" + +from enum import Enum + + +class EventKind(Enum): + """EventKind constants for JDWP.""" + + SINGLE_STEP = 1 + BREAKPOINT = 2 + FRAME_POP = 3 + EXCEPTION = 4 + USER_DEFINED = 5 + THREAD_START = 6 + THREAD_DEATH = 7 + THREAD_END = 7 + CLASS_PREPARE = 8 + CLASS_UNLOAD = 9 + CLASS_LOAD = 10 + FIELD_ACCESS = 20 + FIELD_MODIFICATION = 21 + EXCEPTION_CATCH = 30 + METHOD_ENTRY = 40 + METHOD_EXIT = 41 + METHOD_EXIT_WITH_RETURN_VALUE = 42 + MONITOR_CONTENDED_ENTER = 43 + MONITOR_CONTENDED_ENTERED = 44 + MONITOR_WAIT = 45 + MONITOR_WAITED = 46 + VM_START = 90 + VM_INIT = 90 + VM_DEATH = 99 + VM_DISCONNECTED = 100 diff --git a/jdwp/constants/invoke_options.py b/jdwp/constants/invoke_options.py new file mode 100644 index 0000000..cf5c632 --- /dev/null +++ b/jdwp/constants/invoke_options.py @@ -0,0 +1,9 @@ +"""Invoke options enum class.""" +from enum import IntEnum + + +class InvokeOptions(IntEnum): + """Invoke options constants for JDWP.""" + + INVOKE_SINGLE_THREADED = 0x01 + INVOKE_NONVIRTUAL = 0x02 diff --git a/jdwp/constants/step_depth.py b/jdwp/constants/step_depth.py new file mode 100644 index 0000000..9361940 --- /dev/null +++ b/jdwp/constants/step_depth.py @@ -0,0 +1,11 @@ +"""Step depth enum class.""" + +from enum import Enum + + +class StepDepth(Enum): + """StepDepth constants for JDWP.""" + + INTO = 0 + OVER = 1 + OUT = 2 diff --git a/jdwp/constants/step_size.py b/jdwp/constants/step_size.py new file mode 100644 index 0000000..499a0e6 --- /dev/null +++ b/jdwp/constants/step_size.py @@ -0,0 +1,10 @@ +"""Step size enum class.""" + +from enum import Enum + + +class StepSize(Enum): + """StepSize constants for JDWP.""" + + MIN = 0 + LINE = 1 diff --git a/jdwp/constants/suspend_policy.py b/jdwp/constants/suspend_policy.py new file mode 100644 index 0000000..8be31e2 --- /dev/null +++ b/jdwp/constants/suspend_policy.py @@ -0,0 +1,11 @@ +"""Suspend policy enum class.""" + +from enum import Enum + + +class SuspendPolicy(Enum): + """SuspendPolicy constants for JDWP.""" + + NONE = 0 + EVENT_THREAD = 1 + ALL = 2 diff --git a/jdwp/constants/suspend_status.py b/jdwp/constants/suspend_status.py new file mode 100644 index 0000000..8e94a4e --- /dev/null +++ b/jdwp/constants/suspend_status.py @@ -0,0 +1,9 @@ +"""Suspend status enum class.""" + +from enum import Enum + + +class SuspendStatus(Enum): + """SuspendStatus constants for JDWP.""" + + SUSPEND_STATUS_SUSPENDED = 0x1 diff --git a/jdwp/constants/tag.py b/jdwp/constants/tag.py new file mode 100644 index 0000000..8a6dc0e --- /dev/null +++ b/jdwp/constants/tag.py @@ -0,0 +1,23 @@ +"""Tag enum class.""" +from enum import Enum + + +class Tag(Enum): + """Tag constants for JDWP.""" + + ARRAY = 91 + BYTE = 66 + CHAR = 67 + OBJECT = 76 + FLOAT = 70 + DOUBLE = 68 + INT = 73 + LONG = 74 + SHORT = 83 + VOID = 86 + BOOLEAN = 90 + STRING = 115 + THREAD = 116 + THREAD_GROUP = 103 + CLASS_LOADER = 108 + CLASS_OBJECT = 99 diff --git a/jdwp/constants/thread_status.py b/jdwp/constants/thread_status.py new file mode 100644 index 0000000..7bbab1f --- /dev/null +++ b/jdwp/constants/thread_status.py @@ -0,0 +1,12 @@ +"""Threat status enum class.""" +from enum import Enum + + +class ThreadStatus(Enum): + """ThreadStatus constants for JDWP.""" + + ZOMBIE = 0 + RUNNING = 1 + SLEEPING = 2 + MONITOR = 3 + WAIT = 4 diff --git a/jdwp/constants/type_tag.py b/jdwp/constants/type_tag.py new file mode 100644 index 0000000..fafa73a --- /dev/null +++ b/jdwp/constants/type_tag.py @@ -0,0 +1,11 @@ +"""Type tag enum class.""" + +from enum import Enum + + +class TypeTag(Enum): + """TypeTag constants for JDWP.""" + + CLASS = 1 + INTERFACE = 2 + ARRAY = 3 From 2570ac7ef7bc387e40d99f00b2399d1a14f03d79 Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Wed, 11 Oct 2023 15:13:28 +0000 Subject: [PATCH 04/20] Build common file for jdwp constants --- jdwp/common.py | 96 +++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 60 deletions(-) diff --git a/jdwp/common.py b/jdwp/common.py index ad1fa19..d33060f 100644 --- a/jdwp/common.py +++ b/jdwp/common.py @@ -1,84 +1,60 @@ """Basic types for JDWP messages.""" +from typing import List + + +class Types: + """Types class.""" + + STRING = str + INT = int + BYTE = float + BOOLEAN = bool + DICT = dict + REFERENCE_TYPE_ID = "referenceTypeID" + CLASS_LOADER = "classLoader" + FIELD_ID = "fieldID" + METHOD_ID = "methodID" + VALUE = "value" + INTERFACE_ID = "interfaceID" + CLASS_OBJECT_ID = "classObjectID" + TAGGED_OBJECT_ID = "taggedObjectID" + THREAD_ID = "threadID" + THREAD_GROUP_ID = "threadGroupID" + OBJECT_ID = "objectID" + LOCATION = "location" -class Type: - pass - -class String(Type): - pass - - -class Int(Type): - pass - - -# Define Field class class Field: - def __init__(self, name, type): + """Field class.""" + + def __init__(self, name: str, type: str, description: str): self.name = name self.type = type + self.description = description -# Define Struct class class Struct: - def __init__(self, fields): + """Struct class.""" + + def __init__(self, fields: List[Field]): self.fields = fields -# Define Command class class Command: - def __init__(self, name, id, out, reply): + """Command class.""" + + def __init__(self, name: str, id: int, out: Struct, reply: Struct): self.name = name self.id = id self.out = out self.reply = reply -# Define CommandSet class class CommandSet: - def __init__(self, name, id, commands): + """Command set class.""" + + def __init__(self, name: str, id: int, commands: List[Command]): self.name = name self.id = id self.commands = commands - - -# Create JDWP message descriptions -Version = Command( - name="version", - id=1, - out=None, - reply=Struct( - [ - Field("description", String), - Field("jdwp major", Int), - Field("jdwp minor", Int), - Field("vm version", String), - Field("vm name", String), - ] - ), -) - -ClassesBySignature = Command( - name="classes by signature", - id=2, - out=Struct( - [ - Field("signature", String), - ] - ), - reply=Struct( - [ - # ... (other fields) - ] - ), -) - -VirtualMachine = CommandSet( - name="VirtualMachine", - id=1, - commands=[ - Version, - ClassesBySignature, - ], -) From 013df5b9b81863cc296810cd2c1eed92675f3a9a Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Wed, 11 Oct 2023 15:28:45 +0000 Subject: [PATCH 05/20] Integrate error constants class in commands. --- jdwp/commands/reference_type.py | 278 ++++++++++++++++++++++++-------- jdwp/reference_type.py | 0 jdwp/thread_reference.py | 0 3 files changed, 211 insertions(+), 67 deletions(-) delete mode 100644 jdwp/reference_type.py delete mode 100644 jdwp/thread_reference.py diff --git a/jdwp/commands/reference_type.py b/jdwp/commands/reference_type.py index e9497c1..5078fdd 100644 --- a/jdwp/commands/reference_type.py +++ b/jdwp/commands/reference_type.py @@ -1,5 +1,6 @@ """JDWP Commands for Reference Type Command Set.""" from jdwp.common import Command, CommandSet, Field, Struct, Types +from jdwp.constants.errors import ErrorConstants Signature = Command( @@ -17,7 +18,23 @@ ), ] ), - error=Struct([]), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), ) ClassLoader = Command( @@ -41,7 +58,23 @@ ), ] ), - error=Struct([]), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), ) Modifiers = Command( @@ -57,7 +90,23 @@ ), ] ), - error=Struct([]), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), ) Fields = Command( @@ -81,16 +130,22 @@ [ Field( "CLASS_NOT_PREPARED", - Types.STRING, + ErrorConstants.CLASS_NOT_PREPARED, "Class has been loaded but not yet prepared.", ), Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -116,16 +171,22 @@ [ Field( "CLASS_NOT_PREPARED", - Types.STRING, + ErrorConstants.CLASS_NOT_PREPARED, "Class has been loaded but not yet prepared.", ), Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -153,12 +214,22 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("INVALID_FIELDID", Types.STRING, "Invalid field."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "INVALID_FIELDID", + ErrorConstants.INVALID_FIELDID, + "One or more fieldIDs are invalid.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -185,16 +256,22 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), Field( "ABSENT_INFORMATION", - Types.STRING, - "The source file attribute is absent.", + ErrorConstants.ABSENT_INFORMATION, + "The source file attribute is not present.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), ] ), ) @@ -220,11 +297,17 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -246,11 +329,17 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -273,11 +362,17 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -295,11 +390,17 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -317,19 +418,27 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), Field( - "ABSENT_INFORMATION", Types.STRING, "If the extension is not specified." + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "ABSENT_INFORMATION", + ErrorConstants.ABSENT_INFORMATION, + "The source debug extension attribute is not present.", ), Field( "NOT_IMPLEMENTED", - Types.STRING, + ErrorConstants.NOT_IMPLEMENTED, "The functionality is not implemented in this virtual machine.", ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -358,11 +467,17 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -393,16 +508,22 @@ [ Field( "CLASS_NOT_PREPARED", - Types.STRING, + ErrorConstants.CLASS_NOT_PREPARED, "Class has been loaded but not yet prepared.", ), Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -434,16 +555,22 @@ [ Field( "CLASS_NOT_PREPARED", - Types.STRING, + ErrorConstants.CLASS_NOT_PREPARED, "Class has been loaded but not yet prepared.", ), Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -471,17 +598,27 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), - Field("ILLEGAL_ARGUMENT", Types.STRING, "maxInstances is less than zero."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), Field( "NOT_IMPLEMENTED", - Types.STRING, + ErrorConstants.NOT_IMPLEMENTED, "The functionality is not implemented in this virtual machine.", ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "Illegal Argument", + ErrorConstants.ILLEGAL_ARGUMENT, + "maxInstances is less than zero.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -501,16 +638,22 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), Field( - "ABSENT_INFORMATION", - Types.STRING, + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "ABSENT INFORMATION", + ErrorConstants.ABSENT_INFORMATION, "The class file version information is absent for primitive and array types.", ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -531,21 +674,22 @@ [ Field( "INVALID_CLASS", - Types.STRING, + ErrorConstants.INVALID_CLASS, "refType is not the ID of a reference type.", ), - Field("INVALID_OBJECT", Types.STRING, "refType is not a known ID."), Field( - "NOT_IMPLEMENTED", - Types.STRING, - "If the target virtual machine does not support the retrieval of constant pool information.", + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", ), Field( - "ABSENT_INFORMATION", - Types.STRING, - "The Constant Pool information is absent for primitive and array types.", + "ABSENT INFORMATION", + ErrorConstants.ABSENT_INFORMATION, + "The class file version information is absent for primitive and array types.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), ] ), ) diff --git a/jdwp/reference_type.py b/jdwp/reference_type.py deleted file mode 100644 index e69de29..0000000 diff --git a/jdwp/thread_reference.py b/jdwp/thread_reference.py deleted file mode 100644 index e69de29..0000000 From 4ef140f584236217a1ed8d31d16f4f90cb299a7d Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Wed, 11 Oct 2023 16:02:43 +0000 Subject: [PATCH 06/20] Integrate error constants enum class in the error fields of the commands. --- jdwp/commands/thread_reference.py | 193 +++++++++++++++++++++--------- 1 file changed, 137 insertions(+), 56 deletions(-) diff --git a/jdwp/commands/thread_reference.py b/jdwp/commands/thread_reference.py index ab5feb1..7392cbd 100644 --- a/jdwp/commands/thread_reference.py +++ b/jdwp/commands/thread_reference.py @@ -1,6 +1,7 @@ """JDWP Commands for ThreadReference Command Set.""" from jdwp.common import Command, CommandSet, Field, Struct, Types +from jdwp.constants.errors import ErrorConstants Name = Command( name="Name", @@ -11,11 +12,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -30,11 +37,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -48,11 +61,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -79,11 +98,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -105,11 +130,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -139,11 +170,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -159,11 +196,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -182,16 +225,22 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), Field( - "NOT_IMPLEMENTED", - Types.STRING, + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "NOT IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, "The functionality is not implemented in this virtual machine.", ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -213,16 +262,22 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), Field( - "NOT_IMPLEMENTED", - Types.STRING, + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "NOT IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, "The functionality is not implemented in this virtual machine.", ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -245,15 +300,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), Field( "INVALID_OBJECT", - Types.STRING, - "If thread is not a known ID or the asynchronous exception has been garbage collected.", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), ] ), ) @@ -267,11 +324,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -293,11 +356,17 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -321,16 +390,22 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "thread is not a known ID."), Field( - "NOT_IMPLEMENTED", - Types.STRING, + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "NOT IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, "The functionality is not implemented in this virtual machine.", ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) @@ -349,41 +424,47 @@ [ Field( "INVALID_THREAD", - Types.STRING, + ErrorConstants.INVALID_THREAD, "Passed thread is null, is not a valid thread or has exited.", ), - Field("INVALID_OBJECT", Types.STRING, "Thread or value is not a known ID."), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), Field( "THREAD_NOT_SUSPENDED", - Types.STRING, + ErrorConstants.THREAD_NOT_SUSPENDED, "If the specified thread has not been suspended by an event.", ), Field( "THREAD_NOT_ALIVE", - Types.STRING, + ErrorConstants.THREAD_NOT_ALIVE, "Thread has not been started or is now dead.", ), Field( "OPAQUE_FRAME", - Types.STRING, + ErrorConstants.OPAQUE_FRAME, "Attempted to return early from a frame corresponding to a native method. Or the implementation is unable to provide this functionality on this frame.", ), Field( "NO_MORE_FRAMES", - Types.STRING, + ErrorConstants.NO_MORE_FRAMES, "There are no more Java or JNI frames on the call stack.", ), Field( - "NOT_IMPLEMENTED", - Types.STRING, + "NOT IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, "The functionality is not implemented in this virtual machine.", ), Field( "TYPE_MISMATCH", - Types.STRING, + ErrorConstants.TYPE_MISMATCH, "Value is not an appropriate type for the return value of the method.", ), - Field("VM_DEAD", Types.STRING, "The virtual machine is not running."), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), ] ), ) From 0ce49fc61539af3b9b5dafa27269fe099116b9cd Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Wed, 11 Oct 2023 16:02:55 +0000 Subject: [PATCH 07/20] Added flake8 --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4b16ddc..b2aa526 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ bpftools-arm64.tar.gz bpftools-min-arm64.tar.gz bpftools-x86_64.tar.gz bpftools-min-x86_64.tar.gz + +.flake8 \ No newline at end of file From b4a410238c3a1dca41a3aca4ca3ba17625445ed9 Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Wed, 11 Oct 2023 16:09:13 +0000 Subject: [PATCH 08/20] Add error field to the command class. --- jdwp/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jdwp/common.py b/jdwp/common.py index d33060f..d8aafc8 100644 --- a/jdwp/common.py +++ b/jdwp/common.py @@ -44,11 +44,12 @@ def __init__(self, fields: List[Field]): class Command: """Command class.""" - def __init__(self, name: str, id: int, out: Struct, reply: Struct): + def __init__(self, name: str, id: int, out: Struct, reply: Struct, error: Struct): self.name = name self.id = id self.out = out self.reply = reply + self.error = error class CommandSet: From 609b03362d365f02e2781a57de76143e63f90267 Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Thu, 12 Oct 2023 06:07:11 +0000 Subject: [PATCH 09/20] Restructed jdwp project. --- projects/jdwp/__init__.py | 0 projects/jdwp/constants/class_status.py | 12 + projects/jdwp/constants/errors.py | 64 ++ projects/jdwp/constants/event_kind.py | 33 + projects/jdwp/constants/invoke_options.py | 9 + projects/jdwp/constants/step_depth.py | 11 + projects/jdwp/constants/step_size.py | 10 + projects/jdwp/constants/suspend_policy.py | 11 + projects/jdwp/constants/suspend_status.py | 9 + projects/jdwp/constants/tag.py | 23 + projects/jdwp/constants/thread_status.py | 12 + projects/jdwp/constants/type_tag.py | 11 + .../jdwp/defs/command_sets/reference_type.py | 48 ++ .../defs/command_sets/thread_reference.py | 40 + projects/jdwp/defs/commands/reference_type.py | 695 ++++++++++++++++++ .../jdwp/defs/commands/thread_reference.py | 470 ++++++++++++ projects/jdwp/defs/schema.py | 78 ++ 17 files changed, 1536 insertions(+) create mode 100644 projects/jdwp/__init__.py create mode 100644 projects/jdwp/constants/class_status.py create mode 100644 projects/jdwp/constants/errors.py create mode 100644 projects/jdwp/constants/event_kind.py create mode 100644 projects/jdwp/constants/invoke_options.py create mode 100644 projects/jdwp/constants/step_depth.py create mode 100644 projects/jdwp/constants/step_size.py create mode 100644 projects/jdwp/constants/suspend_policy.py create mode 100644 projects/jdwp/constants/suspend_status.py create mode 100644 projects/jdwp/constants/tag.py create mode 100644 projects/jdwp/constants/thread_status.py create mode 100644 projects/jdwp/constants/type_tag.py create mode 100644 projects/jdwp/defs/command_sets/reference_type.py create mode 100644 projects/jdwp/defs/command_sets/thread_reference.py create mode 100644 projects/jdwp/defs/commands/reference_type.py create mode 100644 projects/jdwp/defs/commands/thread_reference.py create mode 100644 projects/jdwp/defs/schema.py diff --git a/projects/jdwp/__init__.py b/projects/jdwp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/projects/jdwp/constants/class_status.py b/projects/jdwp/constants/class_status.py new file mode 100644 index 0000000..0cd2b8e --- /dev/null +++ b/projects/jdwp/constants/class_status.py @@ -0,0 +1,12 @@ +"""Class Status enum class.""" + +from enum import Enum + + +class ClassStatus(Enum): + """ClassStatus constants for JDWP.""" + + VERIFIED = 1 + PREPARED = 2 + INITIALIZED = 4 + ERROR = 8 diff --git a/projects/jdwp/constants/errors.py b/projects/jdwp/constants/errors.py new file mode 100644 index 0000000..df211ab --- /dev/null +++ b/projects/jdwp/constants/errors.py @@ -0,0 +1,64 @@ +"""Errors enum class.""" +from enum import Enum + + +class ErrorConstants(Enum): + """Error constants for JDWP.""" + + NONE = 0 + INVALID_THREAD = 10 + INVALID_THREAD_GROUP = 11 + INVALID_PRIORITY = 12 + THREAD_NOT_SUSPENDED = 13 + THREAD_SUSPENDED = 14 + THREAD_NOT_ALIVE = 15 + INVALID_OBJECT = 20 + INVALID_CLASS = 21 + CLASS_NOT_PREPARED = 22 + INVALID_METHODID = 23 + INVALID_LOCATION = 24 + INVALID_FIELDID = 25 + INVALID_FRAMEID = 30 + NO_MORE_FRAMES = 31 + OPAQUE_FRAME = 32 + NOT_CURRENT_FRAME = 33 + TYPE_MISMATCH = 34 + INVALID_SLOT = 35 + DUPLICATE = 40 + NOT_FOUND = 41 + INVALID_MONITOR = 50 + NOT_MONITOR_OWNER = 51 + INTERRUPT = 52 + INVALID_CLASS_FORMAT = 60 + CIRCULAR_CLASS_DEFINITION = 61 + FAILS_VERIFICATION = 62 + ADD_METHOD_NOT_IMPLEMENTED = 63 + SCHEMA_CHANGE_NOT_IMPLEMENTED = 64 + INVALID_TYPESTATE = 65 + HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66 + DELETE_METHOD_NOT_IMPLEMENTED = 67 + UNSUPPORTED_VERSION = 68 + NAMES_DONT_MATCH = 69 + CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70 + METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71 + NOT_IMPLEMENTED = 99 + NULL_POINTER = 100 + ABSENT_INFORMATION = 101 + INVALID_EVENT_TYPE = 102 + ILLEGAL_ARGUMENT = 103 + OUT_OF_MEMORY = 110 + ACCESS_DENIED = 111 + VM_DEAD = 112 + INTERNAL = 113 + UNATTACHED_THREAD = 115 + INVALID_TAG = 500 + ALREADY_INVOKING = 502 + INVALID_INDEX = 503 + INVALID_LENGTH = 504 + INVALID_STRING = 506 + INVALID_CLASS_LOADER = 507 + INVALID_ARRAY = 508 + TRANSPORT_LOAD = 509 + TRANSPORT_INIT = 510 + NATIVE_METHOD = 511 + INVALID_COUNT = 512 diff --git a/projects/jdwp/constants/event_kind.py b/projects/jdwp/constants/event_kind.py new file mode 100644 index 0000000..42f1b64 --- /dev/null +++ b/projects/jdwp/constants/event_kind.py @@ -0,0 +1,33 @@ +"""EventKind enum class.""" + +from enum import Enum + + +class EventKind(Enum): + """EventKind constants for JDWP.""" + + SINGLE_STEP = 1 + BREAKPOINT = 2 + FRAME_POP = 3 + EXCEPTION = 4 + USER_DEFINED = 5 + THREAD_START = 6 + THREAD_DEATH = 7 + THREAD_END = 7 + CLASS_PREPARE = 8 + CLASS_UNLOAD = 9 + CLASS_LOAD = 10 + FIELD_ACCESS = 20 + FIELD_MODIFICATION = 21 + EXCEPTION_CATCH = 30 + METHOD_ENTRY = 40 + METHOD_EXIT = 41 + METHOD_EXIT_WITH_RETURN_VALUE = 42 + MONITOR_CONTENDED_ENTER = 43 + MONITOR_CONTENDED_ENTERED = 44 + MONITOR_WAIT = 45 + MONITOR_WAITED = 46 + VM_START = 90 + VM_INIT = 90 + VM_DEATH = 99 + VM_DISCONNECTED = 100 diff --git a/projects/jdwp/constants/invoke_options.py b/projects/jdwp/constants/invoke_options.py new file mode 100644 index 0000000..cf5c632 --- /dev/null +++ b/projects/jdwp/constants/invoke_options.py @@ -0,0 +1,9 @@ +"""Invoke options enum class.""" +from enum import IntEnum + + +class InvokeOptions(IntEnum): + """Invoke options constants for JDWP.""" + + INVOKE_SINGLE_THREADED = 0x01 + INVOKE_NONVIRTUAL = 0x02 diff --git a/projects/jdwp/constants/step_depth.py b/projects/jdwp/constants/step_depth.py new file mode 100644 index 0000000..9361940 --- /dev/null +++ b/projects/jdwp/constants/step_depth.py @@ -0,0 +1,11 @@ +"""Step depth enum class.""" + +from enum import Enum + + +class StepDepth(Enum): + """StepDepth constants for JDWP.""" + + INTO = 0 + OVER = 1 + OUT = 2 diff --git a/projects/jdwp/constants/step_size.py b/projects/jdwp/constants/step_size.py new file mode 100644 index 0000000..499a0e6 --- /dev/null +++ b/projects/jdwp/constants/step_size.py @@ -0,0 +1,10 @@ +"""Step size enum class.""" + +from enum import Enum + + +class StepSize(Enum): + """StepSize constants for JDWP.""" + + MIN = 0 + LINE = 1 diff --git a/projects/jdwp/constants/suspend_policy.py b/projects/jdwp/constants/suspend_policy.py new file mode 100644 index 0000000..8be31e2 --- /dev/null +++ b/projects/jdwp/constants/suspend_policy.py @@ -0,0 +1,11 @@ +"""Suspend policy enum class.""" + +from enum import Enum + + +class SuspendPolicy(Enum): + """SuspendPolicy constants for JDWP.""" + + NONE = 0 + EVENT_THREAD = 1 + ALL = 2 diff --git a/projects/jdwp/constants/suspend_status.py b/projects/jdwp/constants/suspend_status.py new file mode 100644 index 0000000..8e94a4e --- /dev/null +++ b/projects/jdwp/constants/suspend_status.py @@ -0,0 +1,9 @@ +"""Suspend status enum class.""" + +from enum import Enum + + +class SuspendStatus(Enum): + """SuspendStatus constants for JDWP.""" + + SUSPEND_STATUS_SUSPENDED = 0x1 diff --git a/projects/jdwp/constants/tag.py b/projects/jdwp/constants/tag.py new file mode 100644 index 0000000..8a6dc0e --- /dev/null +++ b/projects/jdwp/constants/tag.py @@ -0,0 +1,23 @@ +"""Tag enum class.""" +from enum import Enum + + +class Tag(Enum): + """Tag constants for JDWP.""" + + ARRAY = 91 + BYTE = 66 + CHAR = 67 + OBJECT = 76 + FLOAT = 70 + DOUBLE = 68 + INT = 73 + LONG = 74 + SHORT = 83 + VOID = 86 + BOOLEAN = 90 + STRING = 115 + THREAD = 116 + THREAD_GROUP = 103 + CLASS_LOADER = 108 + CLASS_OBJECT = 99 diff --git a/projects/jdwp/constants/thread_status.py b/projects/jdwp/constants/thread_status.py new file mode 100644 index 0000000..7bbab1f --- /dev/null +++ b/projects/jdwp/constants/thread_status.py @@ -0,0 +1,12 @@ +"""Threat status enum class.""" +from enum import Enum + + +class ThreadStatus(Enum): + """ThreadStatus constants for JDWP.""" + + ZOMBIE = 0 + RUNNING = 1 + SLEEPING = 2 + MONITOR = 3 + WAIT = 4 diff --git a/projects/jdwp/constants/type_tag.py b/projects/jdwp/constants/type_tag.py new file mode 100644 index 0000000..fafa73a --- /dev/null +++ b/projects/jdwp/constants/type_tag.py @@ -0,0 +1,11 @@ +"""Type tag enum class.""" + +from enum import Enum + + +class TypeTag(Enum): + """TypeTag constants for JDWP.""" + + CLASS = 1 + INTERFACE = 2 + ARRAY = 3 diff --git a/projects/jdwp/defs/command_sets/reference_type.py b/projects/jdwp/defs/command_sets/reference_type.py new file mode 100644 index 0000000..5cd2b1d --- /dev/null +++ b/projects/jdwp/defs/command_sets/reference_type.py @@ -0,0 +1,48 @@ +"""Command Set: ReferenceType.""" + +from jdwp.defs.schema import CommandSet +from jdwp.defs.commands.reference_type import ( + Signature, + ClassLoader, + Modifiers, + Fields, + Methods, + GetValues, + SourceFile, + NestedTypes, + Status, + Interfaces, + ClassObject, + SourceDebugExtension, + SignatureWithGeneric, + FieldsWithGeneric, + MethodsWithGeneric, + Instances, + ClassFileVersion, + ConstantPool, +) + +ReferenceType = CommandSet( + name="VirtualMachine", + id=2, + commands=[ + Signature, + ClassLoader, + Modifiers, + Fields, + Methods, + GetValues, + SourceFile, + NestedTypes, + Status, + Interfaces, + ClassObject, + SourceDebugExtension, + SignatureWithGeneric, + FieldsWithGeneric, + MethodsWithGeneric, + Instances, + ClassFileVersion, + ConstantPool, + ], +) diff --git a/projects/jdwp/defs/command_sets/thread_reference.py b/projects/jdwp/defs/command_sets/thread_reference.py new file mode 100644 index 0000000..67d088e --- /dev/null +++ b/projects/jdwp/defs/command_sets/thread_reference.py @@ -0,0 +1,40 @@ +"""Command Set: ThreadReference.""" + +from jdwp.defs.schema import CommandSet +from jdwp.defs.commands.thread_reference import ( + Name, + Suspend, + Resume, + Status, + ThreadGroup, + Frames, + FrameCount, + OwnedMonitors, + CurrentContendedMonitor, + Stop, + Interrupt, + SuspendCount, + OwnedMonitorsStackDepthInfo, + ForceEarlyReturn, +) + +ThreadReference = CommandSet( + name="ThreadReference", + id=11, + commands=[ + Name, + Suspend, + Resume, + Status, + ThreadGroup, + Frames, + FrameCount, + OwnedMonitors, + CurrentContendedMonitor, + Stop, + Interrupt, + SuspendCount, + OwnedMonitorsStackDepthInfo, + ForceEarlyReturn, + ], +) diff --git a/projects/jdwp/defs/commands/reference_type.py b/projects/jdwp/defs/commands/reference_type.py new file mode 100644 index 0000000..89b93cb --- /dev/null +++ b/projects/jdwp/defs/commands/reference_type.py @@ -0,0 +1,695 @@ +"""JDWP Commands for Reference Type Command Set.""" +from jdwp.defs.schema import Command, Field, Struct, Types +from jdwp.constants.errors import ErrorConstants + + +Signature = Command( + name="Signature", + id=1, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The Reference type ID."), + ] + ), + reply=Struct( + [ + Field( + "signature", Types.STRING, "The JNI signature for the reference type." + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +ClassLoader = Command( + name="Class loader", + id=2, + out=Struct( + [ + Field( + "refType", + Types.REFERENCE_TYPE_ID, + "The reference type ID.", + ), + ] + ), + reply=Struct( + [ + Field( + "classLoaderID", + Types.CLASS_LOADER, + "The class loader for the reference type.", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Modifiers = Command( + name="Modifiers", + id=3, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), + reply=Struct( + [ + Field( + "modBits", + Types.INT, + "Modifier bits as defined in Chapter 4 of The Java™ Virtual Machine Specification. ", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Fields = Command( + name="Fields", + id=4, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), + reply=Struct( + [ + Field("declared", Types.INT, "Number of declared fields."), + Field("fieldID", Types.FIELD_ID, "Field ID."), + Field("name", Types.STRING, "Name of field."), + Field("signature", Types.STRING, "JNI Signature of field."), + Field( + "modBits", + Types.INT, + "The modifier bit flags (also known as access flags).", + ), + ] + ), + error=Struct( + [ + Field( + "CLASS_NOT_PREPARED", + ErrorConstants.CLASS_NOT_PREPARED, + "Class has been loaded but not yet prepared.", + ), + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Methods = Command( + name="Methods", + id=5, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), + reply=Struct( + [ + Field("declared", Types.INT, "Number of declared methods."), + Field("methodID", Types.METHOD_ID, "Method ID."), + Field("name", Types.STRING, "Name of method."), + Field("signature", Types.STRING, "JNI signature of method."), + Field( + "modBits", + Types.INT, + "The modifier bit flags (also known as access flags).", + ), + ] + ), + error=Struct( + [ + Field( + "CLASS_NOT_PREPARED", + ErrorConstants.CLASS_NOT_PREPARED, + "Class has been loaded but not yet prepared.", + ), + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +GetValues = Command( + name="Get values", + id=6, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + Field("fields", Types.INT, "The number of values to get."), + ] + ), + reply=Struct( + [ + Field( + "values", + Types.INT, + "The number of values returned, always equal to fields.", + ), + Field("value", Types.VALUE, "The field value."), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "INVALID_FIELDID", + ErrorConstants.INVALID_FIELDID, + "One or more fieldIDs are invalid.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + + +SourceFile = Command( + name="Sourcefile", + id=7, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field( + "sourceFile", + Types.STRING, + "The source file name. No path information for the file is included", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "ABSENT_INFORMATION", + ErrorConstants.ABSENT_INFORMATION, + "The source file attribute is not present.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +NestedTypes = Command( + name="Nested types", + id=8, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("classes", Types.INT, "The number of nested classes and interfaces"), + Field("refTypeTag", Types.BYTE, "Kind of following reference type."), + Field( + "typeID", Types.REFERENCE_TYPE_ID, "The nested class or interface ID." + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Status = Command( + name="Status", + id=9, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("status", Types.INT, "Status bits: See JDWP.ClassStatus"), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Interfaces = Command( + name="Interfaces", + id=10, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("interfaces", Types.INT, "The number of implemented interfaces"), + Field("interfaceType", Types.INTERFACE_ID, "Implemented interface."), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +ClassObject = Command( + name="Class object", + id=11, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct([Field("classObject", Types.CLASS_OBJECT_ID, "Class object.")]), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +SourceDebugExtension = Command( + name="Source debug extension", + id=12, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct([Field("extension", Types.STRING, "Extension attribute.")]), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "ABSENT_INFORMATION", + ErrorConstants.ABSENT_INFORMATION, + "The source debug extension attribute is not present.", + ), + Field( + "NOT_IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, + "The functionality is not implemented in this virtual machine.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +SignatureWithGeneric = Command( + name="Signature with generic", + id=13, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field( + "signature", Types.STRING, "The JNI signature for the reference type." + ), + Field( + "genericSignature", + Types.STRING, + "The generic signature for the reference type or an empty string if there is none.", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +FieldsWithGeneric = Command( + name="Fields with generic", + id=14, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("declared", Types.INT, "Number of declared fields."), + Field("fieldID", Types.FIELD_ID, "Field ID."), + Field("name", Types.STRING, "The name of the field."), + Field("signature", Types.STRING, "The JNI signature of the field."), + Field( + "genericSignature", + Types.STRING, + "The generic signature of the field, or an empty string if there is none.", + ), + Field("modBits", Types.INT, "The modifier bit flags."), + ] + ), + error=Struct( + [ + Field( + "CLASS_NOT_PREPARED", + ErrorConstants.CLASS_NOT_PREPARED, + "Class has been loaded but not yet prepared.", + ), + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + + +MethodsWithGeneric = Command( + name="Methods with generic", + id=15, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + ] + ), + reply=Struct( + [ + Field("declared", Types.INT, "Number of declared methods."), + Field("methodID", Types.METHOD_ID, "Method ID."), + Field("name", Types.STRING, "The name of the method."), + Field("signature", Types.STRING, "The JNI signature of the method."), + Field( + "genericSignature", + Types.STRING, + "The generic signature of the method, or an empty string if there is none.", + ), + Field("modBits", Types.INT, "The modifier bit flags."), + ] + ), + error=Struct( + [ + Field( + "CLASS_NOT_PREPARED", + ErrorConstants.CLASS_NOT_PREPARED, + "Class has been loaded but not yet prepared.", + ), + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Instances = Command( + name="Instances", + id=16, + out=Struct( + [ + Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), + Field("maxInstances", Types.INT, "Maximum number of instances to return."), + ] + ), + reply=Struct( + [ + Field("instances", Types.INT, "The number of instances that follow."), + Field( + "instance", + Types.TAGGED_OBJECT_ID, + "An instance of this reference type.", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "NOT_IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, + "The functionality is not implemented in this virtual machine.", + ), + Field( + "Illegal Argument", + ErrorConstants.ILLEGAL_ARGUMENT, + "maxInstances is less than zero.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + + +ClassFileVersion = Command( + name="Class file version", + id=17, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The class.")]), + reply=Struct( + [ + Field("majorVersion", Types.INT, "Major version number"), + Field("minorVersion", Types.INT, "Minor version number"), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "ABSENT INFORMATION", + ErrorConstants.ABSENT_INFORMATION, + "The class file version information is absent for primitive and array types.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +ConstantPool = Command( + name="Constant pool", + id=18, + out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The class.")]), + reply=Struct( + [ + Field( + "count", Types.INT, "Total number of constant pool entries plus one." + ), + Field("bytes", Types.BYTE, "Raw bytes of constant pool"), + ] + ), + error=Struct( + [ + Field( + "INVALID_CLASS", + ErrorConstants.INVALID_CLASS, + "refType is not the ID of a reference type.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "refType is not a known ID.", + ), + Field( + "ABSENT INFORMATION", + ErrorConstants.ABSENT_INFORMATION, + "The class file version information is absent for primitive and array types.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) diff --git a/projects/jdwp/defs/commands/thread_reference.py b/projects/jdwp/defs/commands/thread_reference.py new file mode 100644 index 0000000..d08d306 --- /dev/null +++ b/projects/jdwp/defs/commands/thread_reference.py @@ -0,0 +1,470 @@ +"""JDWP Commands for ThreadReference Command Set.""" + +from jdwp.defs.schema import Command, Field, Struct, Types +from jdwp.constants.errors import ErrorConstants + +Name = Command( + name="Name", + id=1, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct([Field("threadName", Types.STRING, "The thread name.")]), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + + +Suspend = Command( + name="Suspend", + id=2, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Resume = Command( + name="Resume", + id=3, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Status = Command( + name="Status", + id=4, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field( + "threadStatus", + Types.INT, + "One of the thread status codes. See JDWP.ThreadStatus", + ), + Field( + "suspendStatus", + Types.INT, + "One of the suspend status codes. See JDWP.SuspendStatus", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +ThreadGroup = Command( + name="Thread group", + id=5, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field( + "threadGroupID", + Types.THREAD_GROUP_ID, + "The thread group of this thread.", + ) + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Frames = Command( + name="Frames", + id=6, + out=Struct( + [ + Field("threadID", Types.THREAD_ID, "The thread object ID."), + Field("startFrame", Types.INT, "The index of the first frame to retrieve."), + Field( + "length", + Types.INT, + "The count of frames to retrieve (-1 means all remaining).", + ), + ] + ), + reply=Struct( + [ + Field("frames", Types.INT, "The number of frames retrieved"), + Field("frameID", Types.FRAME_ID, "The ID of this frame."), + Field("location", Types.LOCATION, "The location of this frame."), + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +FrameCount = Command( + name="Frame count", + id=7, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [Field("frameCount", Types.INT, "The count of frames on this thread's stack.")] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +OwnedMonitors = Command( + name="Owned monitors", + id=8, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field("owned", Types.INT, "The number of owned monitors"), + Field("monitor", Types.TAGGED_OBJECT_ID, "An owned monitor"), + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "NOT IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, + "The functionality is not implemented in this virtual machine.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +CurrentContendedMonitor = Command( + name="Current contended monitor", + id=9, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field( + "monitor", + Types.OBJECT_ID, + "The contended monitor, or null if there is no current contended monitor.", + ) + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "NOT IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, + "The functionality is not implemented in this virtual machine.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Stop = Command( + name="Stop", + id=10, + out=Struct( + [ + Field("threadID", Types.THREAD_ID, "The thread object ID."), + Field( + "throwable", + Types.OBJECT_ID, + "Asynchronous exception. This object must be an instance of java.lang.Throwable or a subclass", + ), + ] + ), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +Interrupt = Command( + name="Interrupt", + id=11, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +SuspendCount = Command( + name="Suspend count", + id=12, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field( + "suspendCount", + Types.INT, + "The number of outstanding suspends of this thread.", + ) + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +OwnedMonitorsStackDepthInfo = Command( + name="Owned monitors stack depth info", + id=13, + out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), + reply=Struct( + [ + Field("owned", Types.INT, "The number of owned monitors"), + Field("monitor", Types.TAGGED_OBJECT_ID, "An owned monitor"), + Field( + "stack_depth", + Types.INT, + "Stack depth location where monitor was acquired", + ), + ] + ), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "NOT IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, + "The functionality is not implemented in this virtual machine.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) + +ForceEarlyReturn = Command( + name="Force early return", + id=14, + out=Struct( + [ + Field("threadID", Types.THREAD_ID, "The thread object ID."), + Field("value", Types.VALUE, "The value to return."), + ] + ), + reply=Struct([]), + error=Struct( + [ + Field( + "INVALID_THREAD", + ErrorConstants.INVALID_THREAD, + "Passed thread is null, is not a valid thread or has exited.", + ), + Field( + "INVALID_OBJECT", + ErrorConstants.INVALID_OBJECT, + "thread is not a known ID.", + ), + Field( + "THREAD_NOT_SUSPENDED", + ErrorConstants.THREAD_NOT_SUSPENDED, + "If the specified thread has not been suspended by an event.", + ), + Field( + "THREAD_NOT_ALIVE", + ErrorConstants.THREAD_NOT_ALIVE, + "Thread has not been started or is now dead.", + ), + Field( + "OPAQUE_FRAME", + ErrorConstants.OPAQUE_FRAME, + "Attempted to return early from a frame corresponding to a native method. Or the implementation is unable to provide this functionality on this frame.", + ), + Field( + "NO_MORE_FRAMES", + ErrorConstants.NO_MORE_FRAMES, + "There are no more Java or JNI frames on the call stack.", + ), + Field( + "NOT IMPLEMENTED", + ErrorConstants.NOT_IMPLEMENTED, + "The functionality is not implemented in this virtual machine.", + ), + Field( + "TYPE_MISMATCH", + ErrorConstants.TYPE_MISMATCH, + "Value is not an appropriate type for the return value of the method.", + ), + Field( + "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." + ), + ] + ), +) diff --git a/projects/jdwp/defs/schema.py b/projects/jdwp/defs/schema.py new file mode 100644 index 0000000..d560637 --- /dev/null +++ b/projects/jdwp/defs/schema.py @@ -0,0 +1,78 @@ +"""Basic types for JDWP messages.""" + +from dataclasses import dataclass +from typing import List, Union +from enum import Enum + + +class PrimitiveType(Enum): + """Primitive type class.""" + + STRING = "string" + INT = "int" + BYTE = "byte" + BOOLEAN = "boolean" + DICT = "dict" + REFERENCE_TYPE_ID = "referenceTypeID" + CLASS_LOADER = "classLoader" + FIELD_ID = "fieldID" + METHOD_ID = "methodID" + VALUE = "value" + INTERFACE_ID = "interfaceID" + CLASS_OBJECT_ID = "classObjectID" + TAGGED_OBJECT_ID = "taggedObjectID" + THREAD_ID = "threadID" + THREAD_GROUP_ID = "threadGroupID" + OBJECT_ID = "objectID" + LOCATION = "location" + + +class Array(Enum): + """Array class type.""" + + pass + + +class TaggedUnion(Enum): + """Tagged Union class type""" + + pass + + +Types = Union[PrimitiveType, Array, TaggedUnion] + + +@dataclass(frozen=True) +class Field: + """Field class.""" + + name: str + type = Types + description: str + + +@dataclass(frozen=True) +class Struct: + """Struct class.""" + + fields: List[Field] + + +@dataclass(frozen=True) +class Command: + """Command class.""" + + name: str + id: int + out: Struct + reply: Struct + error: Struct + + +@dataclass(frozen=True) +class CommandSet: + """Command set class.""" + + name: str + id: int + commands: List[Command] From b77aab7c2fb2d086067dbd6a9ccf2a5262329f5f Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Thu, 12 Oct 2023 06:08:50 +0000 Subject: [PATCH 10/20] Updated field name --- projects/jdwp/constants/invoke_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/jdwp/constants/invoke_options.py b/projects/jdwp/constants/invoke_options.py index cf5c632..44789fe 100644 --- a/projects/jdwp/constants/invoke_options.py +++ b/projects/jdwp/constants/invoke_options.py @@ -6,4 +6,4 @@ class InvokeOptions(IntEnum): """Invoke options constants for JDWP.""" INVOKE_SINGLE_THREADED = 0x01 - INVOKE_NONVIRTUAL = 0x02 + INVOKE_NON_VIRTUAL = 0x02 From 489d945573b2a0b7ca6e8e1f800c2f06181eac93 Mon Sep 17 00:00:00 2001 From: Daquiver1 Date: Thu, 12 Oct 2023 06:09:32 +0000 Subject: [PATCH 11/20] Reverted previous commit. --- .vscode/settings.json | 6 + jdwp/__init__.py | 0 jdwp/commands/reference_type.py | 720 ---------------------- jdwp/commands/thread_reference.py | 492 --------------- jdwp/common.py | 61 -- jdwp/constants/class_status.py | 12 - jdwp/constants/errors.py | 64 -- jdwp/constants/event_kind.py | 33 - jdwp/constants/invoke_options.py | 9 - jdwp/constants/step_depth.py | 11 - jdwp/constants/step_size.py | 10 - jdwp/constants/suspend_policy.py | 11 - jdwp/constants/suspend_status.py | 9 - jdwp/constants/tag.py | 23 - jdwp/constants/thread_status.py | 12 - jdwp/constants/type_tag.py | 11 - projects/jdwp/constants/invoke_options.py | 2 +- 17 files changed, 7 insertions(+), 1479 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 jdwp/__init__.py delete mode 100644 jdwp/commands/reference_type.py delete mode 100644 jdwp/commands/thread_reference.py delete mode 100644 jdwp/common.py delete mode 100644 jdwp/constants/class_status.py delete mode 100644 jdwp/constants/errors.py delete mode 100644 jdwp/constants/event_kind.py delete mode 100644 jdwp/constants/invoke_options.py delete mode 100644 jdwp/constants/step_depth.py delete mode 100644 jdwp/constants/step_size.py delete mode 100644 jdwp/constants/suspend_policy.py delete mode 100644 jdwp/constants/suspend_status.py delete mode 100644 jdwp/constants/tag.py delete mode 100644 jdwp/constants/thread_status.py delete mode 100644 jdwp/constants/type_tag.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3445835 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "none" +} diff --git a/jdwp/__init__.py b/jdwp/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/jdwp/commands/reference_type.py b/jdwp/commands/reference_type.py deleted file mode 100644 index 5078fdd..0000000 --- a/jdwp/commands/reference_type.py +++ /dev/null @@ -1,720 +0,0 @@ -"""JDWP Commands for Reference Type Command Set.""" -from jdwp.common import Command, CommandSet, Field, Struct, Types -from jdwp.constants.errors import ErrorConstants - - -Signature = Command( - name="Signature", - id=1, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The Reference type ID."), - ] - ), - reply=Struct( - [ - Field( - "signature", Types.STRING, "The JNI signature for the reference type." - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ClassLoader = Command( - name="Class loader", - id=2, - out=Struct( - [ - Field( - "refType", - Types.REFERENCE_TYPE_ID, - "The reference type ID.", - ), - ] - ), - reply=Struct( - [ - Field( - "classLoaderID", - Types.CLASS_LOADER, - "The class loader for the reference type.", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Modifiers = Command( - name="Modifiers", - id=3, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), - reply=Struct( - [ - Field( - "modBits", - Types.INT, - "Modifier bits as defined in Chapter 4 of The Java™ Virtual Machine Specification. ", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Fields = Command( - name="Fields", - id=4, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), - reply=Struct( - [ - Field("declared", Types.INT, "Number of declared fields."), - Field("fieldID", Types.FIELD_ID, "Field ID."), - Field("name", Types.STRING, "Name of field."), - Field("signature", Types.STRING, "JNI Signature of field."), - Field( - "modBits", - Types.INT, - "The modifier bit flags (also known as access flags).", - ), - ] - ), - error=Struct( - [ - Field( - "CLASS_NOT_PREPARED", - ErrorConstants.CLASS_NOT_PREPARED, - "Class has been loaded but not yet prepared.", - ), - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Methods = Command( - name="Methods", - id=5, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), - reply=Struct( - [ - Field("declared", Types.INT, "Number of declared methods."), - Field("methodID", Types.METHOD_ID, "Method ID."), - Field("name", Types.STRING, "Name of method."), - Field("signature", Types.STRING, "JNI signature of method."), - Field( - "modBits", - Types.INT, - "The modifier bit flags (also known as access flags).", - ), - ] - ), - error=Struct( - [ - Field( - "CLASS_NOT_PREPARED", - ErrorConstants.CLASS_NOT_PREPARED, - "Class has been loaded but not yet prepared.", - ), - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -GetValues = Command( - name="Get values", - id=6, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - Field("fields", Types.INT, "The number of values to get."), - ] - ), - reply=Struct( - [ - Field( - "values", - Types.INT, - "The number of values returned, always equal to fields.", - ), - Field("value", Types.VALUE, "The field value."), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "INVALID_FIELDID", - ErrorConstants.INVALID_FIELDID, - "One or more fieldIDs are invalid.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - - -SourceFile = Command( - name="Sourcefile", - id=7, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field( - "sourceFile", - Types.STRING, - "The source file name. No path information for the file is included", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "ABSENT_INFORMATION", - ErrorConstants.ABSENT_INFORMATION, - "The source file attribute is not present.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -NestedTypes = Command( - name="Nested types", - id=8, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("classes", Types.INT, "The number of nested classes and interfaces"), - Field("refTypeTag", Types.BYTE, "Kind of following reference type."), - Field( - "typeID", Types.REFERENCE_TYPE_ID, "The nested class or interface ID." - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Status = Command( - name="Status", - id=9, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("status", Types.INT, "Status bits: See JDWP.ClassStatus"), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Interfaces = Command( - name="Interfaces", - id=10, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("interfaces", Types.INT, "The number of implemented interfaces"), - Field("interfaceType", Types.INTERFACE_ID, "Implemented interface."), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ClassObject = Command( - name="Class object", - id=11, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct([Field("classObject", Types.CLASS_OBJECT_ID, "Class object.")]), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -SourceDebugExtension = Command( - name="Source debug extension", - id=12, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct([Field("extension", Types.STRING, "Extension attribute.")]), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "ABSENT_INFORMATION", - ErrorConstants.ABSENT_INFORMATION, - "The source debug extension attribute is not present.", - ), - Field( - "NOT_IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -SignatureWithGeneric = Command( - name="Signature with generic", - id=13, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field( - "signature", Types.STRING, "The JNI signature for the reference type." - ), - Field( - "genericSignature", - Types.STRING, - "The generic signature for the reference type or an empty string if there is none.", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -FieldsWithGeneric = Command( - name="Fields with generic", - id=14, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("declared", Types.INT, "Number of declared fields."), - Field("fieldID", Types.FIELD_ID, "Field ID."), - Field("name", Types.STRING, "The name of the field."), - Field("signature", Types.STRING, "The JNI signature of the field."), - Field( - "genericSignature", - Types.STRING, - "The generic signature of the field, or an empty string if there is none.", - ), - Field("modBits", Types.INT, "The modifier bit flags."), - ] - ), - error=Struct( - [ - Field( - "CLASS_NOT_PREPARED", - ErrorConstants.CLASS_NOT_PREPARED, - "Class has been loaded but not yet prepared.", - ), - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - - -MethodsWithGeneric = Command( - name="Methods with generic", - id=15, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("declared", Types.INT, "Number of declared methods."), - Field("methodID", Types.METHOD_ID, "Method ID."), - Field("name", Types.STRING, "The name of the method."), - Field("signature", Types.STRING, "The JNI signature of the method."), - Field( - "genericSignature", - Types.STRING, - "The generic signature of the method, or an empty string if there is none.", - ), - Field("modBits", Types.INT, "The modifier bit flags."), - ] - ), - error=Struct( - [ - Field( - "CLASS_NOT_PREPARED", - ErrorConstants.CLASS_NOT_PREPARED, - "Class has been loaded but not yet prepared.", - ), - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Instances = Command( - name="Instances", - id=16, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - Field("maxInstances", Types.INT, "Maximum number of instances to return."), - ] - ), - reply=Struct( - [ - Field("instances", Types.INT, "The number of instances that follow."), - Field( - "instance", - Types.TAGGED_OBJECT_ID, - "An instance of this reference type.", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "NOT_IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "Illegal Argument", - ErrorConstants.ILLEGAL_ARGUMENT, - "maxInstances is less than zero.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - - -ClassFileVersion = Command( - name="Class file version", - id=17, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The class.")]), - reply=Struct( - [ - Field("majorVersion", Types.INT, "Major version number"), - Field("minorVersion", Types.INT, "Minor version number"), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "ABSENT INFORMATION", - ErrorConstants.ABSENT_INFORMATION, - "The class file version information is absent for primitive and array types.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ConstantPool = Command( - name="Constant pool", - id=18, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The class.")]), - reply=Struct( - [ - Field( - "count", Types.INT, "Total number of constant pool entries plus one." - ), - Field("bytes", Types.BYTE, "Raw bytes of constant pool"), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "ABSENT INFORMATION", - ErrorConstants.ABSENT_INFORMATION, - "The class file version information is absent for primitive and array types.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ReferenceType = CommandSet( - name="VirtualMachine", - id=2, - commands=[ - Signature, - ClassLoader, - Modifiers, - Fields, - Methods, - GetValues, - SourceFile, - NestedTypes, - Status, - Interfaces, - ClassObject, - SourceDebugExtension, - SignatureWithGeneric, - FieldsWithGeneric, - MethodsWithGeneric, - Instances, - ClassFileVersion, - ConstantPool, - ], -) diff --git a/jdwp/commands/thread_reference.py b/jdwp/commands/thread_reference.py deleted file mode 100644 index 7392cbd..0000000 --- a/jdwp/commands/thread_reference.py +++ /dev/null @@ -1,492 +0,0 @@ -"""JDWP Commands for ThreadReference Command Set.""" - -from jdwp.common import Command, CommandSet, Field, Struct, Types -from jdwp.constants.errors import ErrorConstants - -Name = Command( - name="Name", - id=1, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct([Field("threadName", Types.STRING, "The thread name.")]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - - -Suspend = Command( - name="Suspend", - id=2, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Resume = Command( - name="Resume", - id=3, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Status = Command( - name="Status", - id=4, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field( - "threadStatus", - Types.INT, - "One of the thread status codes. See JDWP.ThreadStatus", - ), - Field( - "suspendStatus", - Types.INT, - "One of the suspend status codes. See JDWP.SuspendStatus", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ThreadGroup = Command( - name="Thread group", - id=5, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field( - "threadGroupID", - Types.THREAD_GROUP_ID, - "The thread group of this thread.", - ) - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Frames = Command( - name="Frames", - id=6, - out=Struct( - [ - Field("threadID", Types.THREAD_ID, "The thread object ID."), - Field("startFrame", Types.INT, "The index of the first frame to retrieve."), - Field( - "length", - Types.INT, - "The count of frames to retrieve (-1 means all remaining).", - ), - ] - ), - reply=Struct( - [ - Field("frames", Types.INT, "The number of frames retrieved"), - Field("frameID", Types.FRAME_ID, "The ID of this frame."), - Field("location", Types.LOCATION, "The location of this frame."), - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -FrameCount = Command( - name="Frame count", - id=7, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [Field("frameCount", Types.INT, "The count of frames on this thread's stack.")] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -OwnedMonitors = Command( - name="Owned monitors", - id=8, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field("owned", Types.INT, "The number of owned monitors"), - Field("monitor", Types.TAGGED_OBJECT_ID, "An owned monitor"), - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "NOT IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -CurrentContendedMonitor = Command( - name="Current contended monitor", - id=9, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field( - "monitor", - Types.OBJECT_ID, - "The contended monitor, or null if there is no current contended monitor.", - ) - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "NOT IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Stop = Command( - name="Stop", - id=10, - out=Struct( - [ - Field("threadID", Types.THREAD_ID, "The thread object ID."), - Field( - "throwable", - Types.OBJECT_ID, - "Asynchronous exception. This object must be an instance of java.lang.Throwable or a subclass", - ), - ] - ), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Interrupt = Command( - name="Interrupt", - id=11, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -SuspendCount = Command( - name="Suspend count", - id=12, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field( - "suspendCount", - Types.INT, - "The number of outstanding suspends of this thread.", - ) - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -OwnedMonitorsStackDepthInfo = Command( - name="Owned monitors stack depth info", - id=13, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field("owned", Types.INT, "The number of owned monitors"), - Field("monitor", Types.TAGGED_OBJECT_ID, "An owned monitor"), - Field( - "stack_depth", - Types.INT, - "Stack depth location where monitor was acquired", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "NOT IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ForceEarlyReturn = Command( - name="Force early return", - id=14, - out=Struct( - [ - Field("threadID", Types.THREAD_ID, "The thread object ID."), - Field("value", Types.VALUE, "The value to return."), - ] - ), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "THREAD_NOT_SUSPENDED", - ErrorConstants.THREAD_NOT_SUSPENDED, - "If the specified thread has not been suspended by an event.", - ), - Field( - "THREAD_NOT_ALIVE", - ErrorConstants.THREAD_NOT_ALIVE, - "Thread has not been started or is now dead.", - ), - Field( - "OPAQUE_FRAME", - ErrorConstants.OPAQUE_FRAME, - "Attempted to return early from a frame corresponding to a native method. Or the implementation is unable to provide this functionality on this frame.", - ), - Field( - "NO_MORE_FRAMES", - ErrorConstants.NO_MORE_FRAMES, - "There are no more Java or JNI frames on the call stack.", - ), - Field( - "NOT IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "TYPE_MISMATCH", - ErrorConstants.TYPE_MISMATCH, - "Value is not an appropriate type for the return value of the method.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - - -ThreadReference = CommandSet( - name="ThreadReference", - id=11, - commands=[ - Name, - Suspend, - Resume, - Status, - ThreadGroup, - Frames, - FrameCount, - OwnedMonitors, - CurrentContendedMonitor, - Stop, - Interrupt, - SuspendCount, - OwnedMonitorsStackDepthInfo, - ForceEarlyReturn, - ], -) diff --git a/jdwp/common.py b/jdwp/common.py deleted file mode 100644 index d8aafc8..0000000 --- a/jdwp/common.py +++ /dev/null @@ -1,61 +0,0 @@ -"""Basic types for JDWP messages.""" - -from typing import List - - -class Types: - """Types class.""" - - STRING = str - INT = int - BYTE = float - BOOLEAN = bool - DICT = dict - REFERENCE_TYPE_ID = "referenceTypeID" - CLASS_LOADER = "classLoader" - FIELD_ID = "fieldID" - METHOD_ID = "methodID" - VALUE = "value" - INTERFACE_ID = "interfaceID" - CLASS_OBJECT_ID = "classObjectID" - TAGGED_OBJECT_ID = "taggedObjectID" - THREAD_ID = "threadID" - THREAD_GROUP_ID = "threadGroupID" - OBJECT_ID = "objectID" - LOCATION = "location" - - -class Field: - """Field class.""" - - def __init__(self, name: str, type: str, description: str): - self.name = name - self.type = type - self.description = description - - -class Struct: - """Struct class.""" - - def __init__(self, fields: List[Field]): - self.fields = fields - - -class Command: - """Command class.""" - - def __init__(self, name: str, id: int, out: Struct, reply: Struct, error: Struct): - self.name = name - self.id = id - self.out = out - self.reply = reply - self.error = error - - -class CommandSet: - """Command set class.""" - - def __init__(self, name: str, id: int, commands: List[Command]): - self.name = name - self.id = id - self.commands = commands diff --git a/jdwp/constants/class_status.py b/jdwp/constants/class_status.py deleted file mode 100644 index 0cd2b8e..0000000 --- a/jdwp/constants/class_status.py +++ /dev/null @@ -1,12 +0,0 @@ -"""Class Status enum class.""" - -from enum import Enum - - -class ClassStatus(Enum): - """ClassStatus constants for JDWP.""" - - VERIFIED = 1 - PREPARED = 2 - INITIALIZED = 4 - ERROR = 8 diff --git a/jdwp/constants/errors.py b/jdwp/constants/errors.py deleted file mode 100644 index df211ab..0000000 --- a/jdwp/constants/errors.py +++ /dev/null @@ -1,64 +0,0 @@ -"""Errors enum class.""" -from enum import Enum - - -class ErrorConstants(Enum): - """Error constants for JDWP.""" - - NONE = 0 - INVALID_THREAD = 10 - INVALID_THREAD_GROUP = 11 - INVALID_PRIORITY = 12 - THREAD_NOT_SUSPENDED = 13 - THREAD_SUSPENDED = 14 - THREAD_NOT_ALIVE = 15 - INVALID_OBJECT = 20 - INVALID_CLASS = 21 - CLASS_NOT_PREPARED = 22 - INVALID_METHODID = 23 - INVALID_LOCATION = 24 - INVALID_FIELDID = 25 - INVALID_FRAMEID = 30 - NO_MORE_FRAMES = 31 - OPAQUE_FRAME = 32 - NOT_CURRENT_FRAME = 33 - TYPE_MISMATCH = 34 - INVALID_SLOT = 35 - DUPLICATE = 40 - NOT_FOUND = 41 - INVALID_MONITOR = 50 - NOT_MONITOR_OWNER = 51 - INTERRUPT = 52 - INVALID_CLASS_FORMAT = 60 - CIRCULAR_CLASS_DEFINITION = 61 - FAILS_VERIFICATION = 62 - ADD_METHOD_NOT_IMPLEMENTED = 63 - SCHEMA_CHANGE_NOT_IMPLEMENTED = 64 - INVALID_TYPESTATE = 65 - HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66 - DELETE_METHOD_NOT_IMPLEMENTED = 67 - UNSUPPORTED_VERSION = 68 - NAMES_DONT_MATCH = 69 - CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70 - METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71 - NOT_IMPLEMENTED = 99 - NULL_POINTER = 100 - ABSENT_INFORMATION = 101 - INVALID_EVENT_TYPE = 102 - ILLEGAL_ARGUMENT = 103 - OUT_OF_MEMORY = 110 - ACCESS_DENIED = 111 - VM_DEAD = 112 - INTERNAL = 113 - UNATTACHED_THREAD = 115 - INVALID_TAG = 500 - ALREADY_INVOKING = 502 - INVALID_INDEX = 503 - INVALID_LENGTH = 504 - INVALID_STRING = 506 - INVALID_CLASS_LOADER = 507 - INVALID_ARRAY = 508 - TRANSPORT_LOAD = 509 - TRANSPORT_INIT = 510 - NATIVE_METHOD = 511 - INVALID_COUNT = 512 diff --git a/jdwp/constants/event_kind.py b/jdwp/constants/event_kind.py deleted file mode 100644 index 42f1b64..0000000 --- a/jdwp/constants/event_kind.py +++ /dev/null @@ -1,33 +0,0 @@ -"""EventKind enum class.""" - -from enum import Enum - - -class EventKind(Enum): - """EventKind constants for JDWP.""" - - SINGLE_STEP = 1 - BREAKPOINT = 2 - FRAME_POP = 3 - EXCEPTION = 4 - USER_DEFINED = 5 - THREAD_START = 6 - THREAD_DEATH = 7 - THREAD_END = 7 - CLASS_PREPARE = 8 - CLASS_UNLOAD = 9 - CLASS_LOAD = 10 - FIELD_ACCESS = 20 - FIELD_MODIFICATION = 21 - EXCEPTION_CATCH = 30 - METHOD_ENTRY = 40 - METHOD_EXIT = 41 - METHOD_EXIT_WITH_RETURN_VALUE = 42 - MONITOR_CONTENDED_ENTER = 43 - MONITOR_CONTENDED_ENTERED = 44 - MONITOR_WAIT = 45 - MONITOR_WAITED = 46 - VM_START = 90 - VM_INIT = 90 - VM_DEATH = 99 - VM_DISCONNECTED = 100 diff --git a/jdwp/constants/invoke_options.py b/jdwp/constants/invoke_options.py deleted file mode 100644 index cf5c632..0000000 --- a/jdwp/constants/invoke_options.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Invoke options enum class.""" -from enum import IntEnum - - -class InvokeOptions(IntEnum): - """Invoke options constants for JDWP.""" - - INVOKE_SINGLE_THREADED = 0x01 - INVOKE_NONVIRTUAL = 0x02 diff --git a/jdwp/constants/step_depth.py b/jdwp/constants/step_depth.py deleted file mode 100644 index 9361940..0000000 --- a/jdwp/constants/step_depth.py +++ /dev/null @@ -1,11 +0,0 @@ -"""Step depth enum class.""" - -from enum import Enum - - -class StepDepth(Enum): - """StepDepth constants for JDWP.""" - - INTO = 0 - OVER = 1 - OUT = 2 diff --git a/jdwp/constants/step_size.py b/jdwp/constants/step_size.py deleted file mode 100644 index 499a0e6..0000000 --- a/jdwp/constants/step_size.py +++ /dev/null @@ -1,10 +0,0 @@ -"""Step size enum class.""" - -from enum import Enum - - -class StepSize(Enum): - """StepSize constants for JDWP.""" - - MIN = 0 - LINE = 1 diff --git a/jdwp/constants/suspend_policy.py b/jdwp/constants/suspend_policy.py deleted file mode 100644 index 8be31e2..0000000 --- a/jdwp/constants/suspend_policy.py +++ /dev/null @@ -1,11 +0,0 @@ -"""Suspend policy enum class.""" - -from enum import Enum - - -class SuspendPolicy(Enum): - """SuspendPolicy constants for JDWP.""" - - NONE = 0 - EVENT_THREAD = 1 - ALL = 2 diff --git a/jdwp/constants/suspend_status.py b/jdwp/constants/suspend_status.py deleted file mode 100644 index 8e94a4e..0000000 --- a/jdwp/constants/suspend_status.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Suspend status enum class.""" - -from enum import Enum - - -class SuspendStatus(Enum): - """SuspendStatus constants for JDWP.""" - - SUSPEND_STATUS_SUSPENDED = 0x1 diff --git a/jdwp/constants/tag.py b/jdwp/constants/tag.py deleted file mode 100644 index 8a6dc0e..0000000 --- a/jdwp/constants/tag.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Tag enum class.""" -from enum import Enum - - -class Tag(Enum): - """Tag constants for JDWP.""" - - ARRAY = 91 - BYTE = 66 - CHAR = 67 - OBJECT = 76 - FLOAT = 70 - DOUBLE = 68 - INT = 73 - LONG = 74 - SHORT = 83 - VOID = 86 - BOOLEAN = 90 - STRING = 115 - THREAD = 116 - THREAD_GROUP = 103 - CLASS_LOADER = 108 - CLASS_OBJECT = 99 diff --git a/jdwp/constants/thread_status.py b/jdwp/constants/thread_status.py deleted file mode 100644 index 7bbab1f..0000000 --- a/jdwp/constants/thread_status.py +++ /dev/null @@ -1,12 +0,0 @@ -"""Threat status enum class.""" -from enum import Enum - - -class ThreadStatus(Enum): - """ThreadStatus constants for JDWP.""" - - ZOMBIE = 0 - RUNNING = 1 - SLEEPING = 2 - MONITOR = 3 - WAIT = 4 diff --git a/jdwp/constants/type_tag.py b/jdwp/constants/type_tag.py deleted file mode 100644 index fafa73a..0000000 --- a/jdwp/constants/type_tag.py +++ /dev/null @@ -1,11 +0,0 @@ -"""Type tag enum class.""" - -from enum import Enum - - -class TypeTag(Enum): - """TypeTag constants for JDWP.""" - - CLASS = 1 - INTERFACE = 2 - ARRAY = 3 diff --git a/projects/jdwp/constants/invoke_options.py b/projects/jdwp/constants/invoke_options.py index 44789fe..cf5c632 100644 --- a/projects/jdwp/constants/invoke_options.py +++ b/projects/jdwp/constants/invoke_options.py @@ -6,4 +6,4 @@ class InvokeOptions(IntEnum): """Invoke options constants for JDWP.""" INVOKE_SINGLE_THREADED = 0x01 - INVOKE_NON_VIRTUAL = 0x02 + INVOKE_NONVIRTUAL = 0x02 From 749ac8c3eae4f2f7f2000968c9e3d70aa9533a23 Mon Sep 17 00:00:00 2001 From: Christian Abrokwa Date: Wed, 25 Oct 2023 07:03:32 +0000 Subject: [PATCH 12/20] Move all files in constants dir to constants --- projects/jdwp/constants/class_status.py | 12 -- projects/jdwp/constants/errors.py | 64 -------- projects/jdwp/constants/event_kind.py | 33 ---- projects/jdwp/constants/invoke_options.py | 9 -- projects/jdwp/constants/step_depth.py | 11 -- projects/jdwp/constants/step_size.py | 10 -- projects/jdwp/constants/suspend_policy.py | 11 -- projects/jdwp/constants/suspend_status.py | 9 -- projects/jdwp/constants/tag.py | 23 --- projects/jdwp/constants/thread_status.py | 12 -- projects/jdwp/constants/type_tag.py | 11 -- projects/jdwp/defs/constants.py | 177 ++++++++++++++++++++++ 12 files changed, 177 insertions(+), 205 deletions(-) delete mode 100644 projects/jdwp/constants/class_status.py delete mode 100644 projects/jdwp/constants/errors.py delete mode 100644 projects/jdwp/constants/event_kind.py delete mode 100644 projects/jdwp/constants/invoke_options.py delete mode 100644 projects/jdwp/constants/step_depth.py delete mode 100644 projects/jdwp/constants/step_size.py delete mode 100644 projects/jdwp/constants/suspend_policy.py delete mode 100644 projects/jdwp/constants/suspend_status.py delete mode 100644 projects/jdwp/constants/tag.py delete mode 100644 projects/jdwp/constants/thread_status.py delete mode 100644 projects/jdwp/constants/type_tag.py create mode 100644 projects/jdwp/defs/constants.py diff --git a/projects/jdwp/constants/class_status.py b/projects/jdwp/constants/class_status.py deleted file mode 100644 index 0cd2b8e..0000000 --- a/projects/jdwp/constants/class_status.py +++ /dev/null @@ -1,12 +0,0 @@ -"""Class Status enum class.""" - -from enum import Enum - - -class ClassStatus(Enum): - """ClassStatus constants for JDWP.""" - - VERIFIED = 1 - PREPARED = 2 - INITIALIZED = 4 - ERROR = 8 diff --git a/projects/jdwp/constants/errors.py b/projects/jdwp/constants/errors.py deleted file mode 100644 index df211ab..0000000 --- a/projects/jdwp/constants/errors.py +++ /dev/null @@ -1,64 +0,0 @@ -"""Errors enum class.""" -from enum import Enum - - -class ErrorConstants(Enum): - """Error constants for JDWP.""" - - NONE = 0 - INVALID_THREAD = 10 - INVALID_THREAD_GROUP = 11 - INVALID_PRIORITY = 12 - THREAD_NOT_SUSPENDED = 13 - THREAD_SUSPENDED = 14 - THREAD_NOT_ALIVE = 15 - INVALID_OBJECT = 20 - INVALID_CLASS = 21 - CLASS_NOT_PREPARED = 22 - INVALID_METHODID = 23 - INVALID_LOCATION = 24 - INVALID_FIELDID = 25 - INVALID_FRAMEID = 30 - NO_MORE_FRAMES = 31 - OPAQUE_FRAME = 32 - NOT_CURRENT_FRAME = 33 - TYPE_MISMATCH = 34 - INVALID_SLOT = 35 - DUPLICATE = 40 - NOT_FOUND = 41 - INVALID_MONITOR = 50 - NOT_MONITOR_OWNER = 51 - INTERRUPT = 52 - INVALID_CLASS_FORMAT = 60 - CIRCULAR_CLASS_DEFINITION = 61 - FAILS_VERIFICATION = 62 - ADD_METHOD_NOT_IMPLEMENTED = 63 - SCHEMA_CHANGE_NOT_IMPLEMENTED = 64 - INVALID_TYPESTATE = 65 - HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66 - DELETE_METHOD_NOT_IMPLEMENTED = 67 - UNSUPPORTED_VERSION = 68 - NAMES_DONT_MATCH = 69 - CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70 - METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71 - NOT_IMPLEMENTED = 99 - NULL_POINTER = 100 - ABSENT_INFORMATION = 101 - INVALID_EVENT_TYPE = 102 - ILLEGAL_ARGUMENT = 103 - OUT_OF_MEMORY = 110 - ACCESS_DENIED = 111 - VM_DEAD = 112 - INTERNAL = 113 - UNATTACHED_THREAD = 115 - INVALID_TAG = 500 - ALREADY_INVOKING = 502 - INVALID_INDEX = 503 - INVALID_LENGTH = 504 - INVALID_STRING = 506 - INVALID_CLASS_LOADER = 507 - INVALID_ARRAY = 508 - TRANSPORT_LOAD = 509 - TRANSPORT_INIT = 510 - NATIVE_METHOD = 511 - INVALID_COUNT = 512 diff --git a/projects/jdwp/constants/event_kind.py b/projects/jdwp/constants/event_kind.py deleted file mode 100644 index 42f1b64..0000000 --- a/projects/jdwp/constants/event_kind.py +++ /dev/null @@ -1,33 +0,0 @@ -"""EventKind enum class.""" - -from enum import Enum - - -class EventKind(Enum): - """EventKind constants for JDWP.""" - - SINGLE_STEP = 1 - BREAKPOINT = 2 - FRAME_POP = 3 - EXCEPTION = 4 - USER_DEFINED = 5 - THREAD_START = 6 - THREAD_DEATH = 7 - THREAD_END = 7 - CLASS_PREPARE = 8 - CLASS_UNLOAD = 9 - CLASS_LOAD = 10 - FIELD_ACCESS = 20 - FIELD_MODIFICATION = 21 - EXCEPTION_CATCH = 30 - METHOD_ENTRY = 40 - METHOD_EXIT = 41 - METHOD_EXIT_WITH_RETURN_VALUE = 42 - MONITOR_CONTENDED_ENTER = 43 - MONITOR_CONTENDED_ENTERED = 44 - MONITOR_WAIT = 45 - MONITOR_WAITED = 46 - VM_START = 90 - VM_INIT = 90 - VM_DEATH = 99 - VM_DISCONNECTED = 100 diff --git a/projects/jdwp/constants/invoke_options.py b/projects/jdwp/constants/invoke_options.py deleted file mode 100644 index cf5c632..0000000 --- a/projects/jdwp/constants/invoke_options.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Invoke options enum class.""" -from enum import IntEnum - - -class InvokeOptions(IntEnum): - """Invoke options constants for JDWP.""" - - INVOKE_SINGLE_THREADED = 0x01 - INVOKE_NONVIRTUAL = 0x02 diff --git a/projects/jdwp/constants/step_depth.py b/projects/jdwp/constants/step_depth.py deleted file mode 100644 index 9361940..0000000 --- a/projects/jdwp/constants/step_depth.py +++ /dev/null @@ -1,11 +0,0 @@ -"""Step depth enum class.""" - -from enum import Enum - - -class StepDepth(Enum): - """StepDepth constants for JDWP.""" - - INTO = 0 - OVER = 1 - OUT = 2 diff --git a/projects/jdwp/constants/step_size.py b/projects/jdwp/constants/step_size.py deleted file mode 100644 index 499a0e6..0000000 --- a/projects/jdwp/constants/step_size.py +++ /dev/null @@ -1,10 +0,0 @@ -"""Step size enum class.""" - -from enum import Enum - - -class StepSize(Enum): - """StepSize constants for JDWP.""" - - MIN = 0 - LINE = 1 diff --git a/projects/jdwp/constants/suspend_policy.py b/projects/jdwp/constants/suspend_policy.py deleted file mode 100644 index 8be31e2..0000000 --- a/projects/jdwp/constants/suspend_policy.py +++ /dev/null @@ -1,11 +0,0 @@ -"""Suspend policy enum class.""" - -from enum import Enum - - -class SuspendPolicy(Enum): - """SuspendPolicy constants for JDWP.""" - - NONE = 0 - EVENT_THREAD = 1 - ALL = 2 diff --git a/projects/jdwp/constants/suspend_status.py b/projects/jdwp/constants/suspend_status.py deleted file mode 100644 index 8e94a4e..0000000 --- a/projects/jdwp/constants/suspend_status.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Suspend status enum class.""" - -from enum import Enum - - -class SuspendStatus(Enum): - """SuspendStatus constants for JDWP.""" - - SUSPEND_STATUS_SUSPENDED = 0x1 diff --git a/projects/jdwp/constants/tag.py b/projects/jdwp/constants/tag.py deleted file mode 100644 index 8a6dc0e..0000000 --- a/projects/jdwp/constants/tag.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Tag enum class.""" -from enum import Enum - - -class Tag(Enum): - """Tag constants for JDWP.""" - - ARRAY = 91 - BYTE = 66 - CHAR = 67 - OBJECT = 76 - FLOAT = 70 - DOUBLE = 68 - INT = 73 - LONG = 74 - SHORT = 83 - VOID = 86 - BOOLEAN = 90 - STRING = 115 - THREAD = 116 - THREAD_GROUP = 103 - CLASS_LOADER = 108 - CLASS_OBJECT = 99 diff --git a/projects/jdwp/constants/thread_status.py b/projects/jdwp/constants/thread_status.py deleted file mode 100644 index 7bbab1f..0000000 --- a/projects/jdwp/constants/thread_status.py +++ /dev/null @@ -1,12 +0,0 @@ -"""Threat status enum class.""" -from enum import Enum - - -class ThreadStatus(Enum): - """ThreadStatus constants for JDWP.""" - - ZOMBIE = 0 - RUNNING = 1 - SLEEPING = 2 - MONITOR = 3 - WAIT = 4 diff --git a/projects/jdwp/constants/type_tag.py b/projects/jdwp/constants/type_tag.py deleted file mode 100644 index fafa73a..0000000 --- a/projects/jdwp/constants/type_tag.py +++ /dev/null @@ -1,11 +0,0 @@ -"""Type tag enum class.""" - -from enum import Enum - - -class TypeTag(Enum): - """TypeTag constants for JDWP.""" - - CLASS = 1 - INTERFACE = 2 - ARRAY = 3 diff --git a/projects/jdwp/defs/constants.py b/projects/jdwp/defs/constants.py new file mode 100644 index 0000000..4202eba --- /dev/null +++ b/projects/jdwp/defs/constants.py @@ -0,0 +1,177 @@ +from enum import Enum, IntEnum + + +class ErrorConstants(Enum): + """Error constants for JDWP.""" + + NONE = 0 + INVALID_THREAD = 10 + INVALID_THREAD_GROUP = 11 + INVALID_PRIORITY = 12 + THREAD_NOT_SUSPENDED = 13 + THREAD_SUSPENDED = 14 + THREAD_NOT_ALIVE = 15 + INVALID_OBJECT = 20 + INVALID_CLASS = 21 + CLASS_NOT_PREPARED = 22 + INVALID_METHODID = 23 + INVALID_LOCATION = 24 + INVALID_FIELDID = 25 + INVALID_FRAMEID = 30 + NO_MORE_FRAMES = 31 + OPAQUE_FRAME = 32 + NOT_CURRENT_FRAME = 33 + TYPE_MISMATCH = 34 + INVALID_SLOT = 35 + DUPLICATE = 40 + NOT_FOUND = 41 + INVALID_MONITOR = 50 + NOT_MONITOR_OWNER = 51 + INTERRUPT = 52 + INVALID_CLASS_FORMAT = 60 + CIRCULAR_CLASS_DEFINITION = 61 + FAILS_VERIFICATION = 62 + ADD_METHOD_NOT_IMPLEMENTED = 63 + SCHEMA_CHANGE_NOT_IMPLEMENTED = 64 + INVALID_TYPESTATE = 65 + HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66 + DELETE_METHOD_NOT_IMPLEMENTED = 67 + UNSUPPORTED_VERSION = 68 + NAMES_DONT_MATCH = 69 + CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70 + METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71 + NOT_IMPLEMENTED = 99 + NULL_POINTER = 100 + ABSENT_INFORMATION = 101 + INVALID_EVENT_TYPE = 102 + ILLEGAL_ARGUMENT = 103 + OUT_OF_MEMORY = 110 + ACCESS_DENIED = 111 + VM_DEAD = 112 + INTERNAL = 113 + UNATTACHED_THREAD = 115 + INVALID_TAG = 500 + ALREADY_INVOKING = 502 + INVALID_INDEX = 503 + INVALID_LENGTH = 504 + INVALID_STRING = 506 + INVALID_CLASS_LOADER = 507 + INVALID_ARRAY = 508 + TRANSPORT_LOAD = 509 + TRANSPORT_INIT = 510 + NATIVE_METHOD = 511 + INVALID_COUNT = 512 + + +class ClassStatus(Enum): + """ClassStatus constants for JDWP.""" + + VERIFIED = 1 + PREPARED = 2 + INITIALIZED = 4 + ERROR = 8 + + +class EventKind(Enum): + """EventKind constants for JDWP.""" + + SINGLE_STEP = 1 + BREAKPOINT = 2 + FRAME_POP = 3 + EXCEPTION = 4 + USER_DEFINED = 5 + THREAD_START = 6 + THREAD_DEATH = 7 + THREAD_END = 7 + CLASS_PREPARE = 8 + CLASS_UNLOAD = 9 + CLASS_LOAD = 10 + FIELD_ACCESS = 20 + FIELD_MODIFICATION = 21 + EXCEPTION_CATCH = 30 + METHOD_ENTRY = 40 + METHOD_EXIT = 41 + METHOD_EXIT_WITH_RETURN_VALUE = 42 + MONITOR_CONTENDED_ENTER = 43 + MONITOR_CONTENDED_ENTERED = 44 + MONITOR_WAIT = 45 + MONITOR_WAITED = 46 + VM_START = 90 + VM_INIT = 90 + VM_DEATH = 99 + VM_DISCONNECTED = 100 + + +class InvokeOptions(IntEnum): + """Invoke options constants for JDWP.""" + + INVOKE_SINGLE_THREADED = 0x01 + INVOKE_NONVIRTUAL = 0x02 + + +class StepDepth(Enum): + """StepDepth constants for JDWP.""" + + INTO = 0 + OVER = 1 + OUT = 2 + + +class StepSize(Enum): + """StepSize constants for JDWP.""" + + MIN = 0 + LINE = 1 + + +class SuspendPolicy(Enum): + """SuspendPolicy constants for JDWP.""" + + NONE = 0 + EVENT_THREAD = 1 + ALL = 2 + + +class SuspendStatus(Enum): + """SuspendStatus constants for JDWP.""" + + SUSPEND_STATUS_SUSPENDED = 0x1 + + +class Tag(Enum): + """Tag constants for JDWP.""" + + ARRAY = 91 + BYTE = 66 + CHAR = 67 + OBJECT = 76 + FLOAT = 70 + DOUBLE = 68 + INT = 73 + LONG = 74 + SHORT = 83 + VOID = 86 + BOOLEAN = 90 + STRING = 115 + THREAD = 116 + THREAD_GROUP = 103 + CLASS_LOADER = 108 + CLASS_OBJECT = 99 + + +class ThreadStatus(Enum): + """ThreadStatus constants for JDWP.""" + + ZOMBIE = 0 + RUNNING = 1 + SLEEPING = 2 + MONITOR = 3 + WAIT = 4 + + +class TypeTag(Enum): + """TypeTag constants for JDWP.""" + + CLASS = 1 + INTERFACE = 2 + ARRAY = 3 From 25f1f2d7a8742dc7276c3cd09360f3d0b1a33648 Mon Sep 17 00:00:00 2001 From: Christian Abrokwa Date: Wed, 25 Oct 2023 07:51:33 +0000 Subject: [PATCH 13/20] Improved immutability by using sequence type. --- projects/jdwp/defs/schema.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/projects/jdwp/defs/schema.py b/projects/jdwp/defs/schema.py index d560637..c05afee 100644 --- a/projects/jdwp/defs/schema.py +++ b/projects/jdwp/defs/schema.py @@ -1,8 +1,13 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. + """Basic types for JDWP messages.""" from dataclasses import dataclass -from typing import List, Union +from typing import Optional from enum import Enum +from collections.abc import Set, Sequence + +from projects.jdwp.defs.constants import ErrorType class PrimitiveType(Enum): @@ -39,7 +44,7 @@ class TaggedUnion(Enum): pass -Types = Union[PrimitiveType, Array, TaggedUnion] +Type = PrimitiveType | Array | TaggedUnion @dataclass(frozen=True) @@ -47,7 +52,7 @@ class Field: """Field class.""" name: str - type = Types + type = Type description: str @@ -55,7 +60,7 @@ class Field: class Struct: """Struct class.""" - fields: List[Field] + fields: Sequence[Field] @dataclass(frozen=True) @@ -64,9 +69,9 @@ class Command: name: str id: int - out: Struct - reply: Struct - error: Struct + out: Optional[Struct] + reply: Optional[Struct] + error: Set[ErrorType] @dataclass(frozen=True) @@ -75,4 +80,4 @@ class CommandSet: name: str id: int - commands: List[Command] + commands: Sequence[Command] From f163c2b9327cba13974998a3a4d5425269424dfa Mon Sep 17 00:00:00 2001 From: Christian Abrokwa Date: Wed, 25 Oct 2023 07:52:05 +0000 Subject: [PATCH 14/20] Change name of errors class. --- projects/jdwp/defs/constants.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/projects/jdwp/defs/constants.py b/projects/jdwp/defs/constants.py index 4202eba..3c84b3b 100644 --- a/projects/jdwp/defs/constants.py +++ b/projects/jdwp/defs/constants.py @@ -1,7 +1,9 @@ -from enum import Enum, IntEnum +# Copyright (c) Meta Platforms, Inc. and affiliates. +from enum import Enum, Flag -class ErrorConstants(Enum): + +class ErrorType(Enum): """Error constants for JDWP.""" NONE = 0 @@ -102,7 +104,7 @@ class EventKind(Enum): VM_DISCONNECTED = 100 -class InvokeOptions(IntEnum): +class InvokeOptions(Flag): """Invoke options constants for JDWP.""" INVOKE_SINGLE_THREADED = 0x01 From 79be56a4fbb98567092996e197bbefe6fa74ecb4 Mon Sep 17 00:00:00 2001 From: Christian Abrokwa Date: Wed, 25 Oct 2023 07:52:50 +0000 Subject: [PATCH 15/20] Updated error field --- .../jdwp/defs/command_sets/reference_type.py | 68 +- .../defs/command_sets/thread_reference.py | 40 - projects/jdwp/defs/commands/reference_type.py | 695 ------------------ .../jdwp/defs/commands/thread_reference.py | 470 ------------ 4 files changed, 30 insertions(+), 1243 deletions(-) delete mode 100644 projects/jdwp/defs/command_sets/thread_reference.py delete mode 100644 projects/jdwp/defs/commands/reference_type.py delete mode 100644 projects/jdwp/defs/commands/thread_reference.py diff --git a/projects/jdwp/defs/command_sets/reference_type.py b/projects/jdwp/defs/command_sets/reference_type.py index 5cd2b1d..910330b 100644 --- a/projects/jdwp/defs/command_sets/reference_type.py +++ b/projects/jdwp/defs/command_sets/reference_type.py @@ -1,48 +1,40 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. + """Command Set: ReferenceType.""" -from jdwp.defs.schema import CommandSet -from jdwp.defs.commands.reference_type import ( - Signature, - ClassLoader, - Modifiers, - Fields, - Methods, - GetValues, - SourceFile, - NestedTypes, - Status, - Interfaces, - ClassObject, - SourceDebugExtension, - SignatureWithGeneric, - FieldsWithGeneric, - MethodsWithGeneric, - Instances, - ClassFileVersion, - ConstantPool, +from jdwp.defs.schema import CommandSet, Type +from jdwp.defs.schema import Command, Field, Struct +from projects.jdwp.defs.constants import ErrorType +from collections.abc import Sequence + + +Signature = Command( + name="Signature", + id=1, + out=Struct( + [ + Field("refType", Type.REFERENCE_TYPE_ID, "The Reference type ID."), + ] + ), + reply=Struct( + [ + Field( + "signature", Type.STRING, "The JNI signature for the reference type." + ), + ] + ), + error=Sequence[ + ErrorType.INVALID_CLASS, + ErrorType.INVALID_OBJECT, + ErrorType.VM_DEAD, + ], ) + ReferenceType = CommandSet( - name="VirtualMachine", + name="ReferenceType", id=2, commands=[ Signature, - ClassLoader, - Modifiers, - Fields, - Methods, - GetValues, - SourceFile, - NestedTypes, - Status, - Interfaces, - ClassObject, - SourceDebugExtension, - SignatureWithGeneric, - FieldsWithGeneric, - MethodsWithGeneric, - Instances, - ClassFileVersion, - ConstantPool, ], ) diff --git a/projects/jdwp/defs/command_sets/thread_reference.py b/projects/jdwp/defs/command_sets/thread_reference.py deleted file mode 100644 index 67d088e..0000000 --- a/projects/jdwp/defs/command_sets/thread_reference.py +++ /dev/null @@ -1,40 +0,0 @@ -"""Command Set: ThreadReference.""" - -from jdwp.defs.schema import CommandSet -from jdwp.defs.commands.thread_reference import ( - Name, - Suspend, - Resume, - Status, - ThreadGroup, - Frames, - FrameCount, - OwnedMonitors, - CurrentContendedMonitor, - Stop, - Interrupt, - SuspendCount, - OwnedMonitorsStackDepthInfo, - ForceEarlyReturn, -) - -ThreadReference = CommandSet( - name="ThreadReference", - id=11, - commands=[ - Name, - Suspend, - Resume, - Status, - ThreadGroup, - Frames, - FrameCount, - OwnedMonitors, - CurrentContendedMonitor, - Stop, - Interrupt, - SuspendCount, - OwnedMonitorsStackDepthInfo, - ForceEarlyReturn, - ], -) diff --git a/projects/jdwp/defs/commands/reference_type.py b/projects/jdwp/defs/commands/reference_type.py deleted file mode 100644 index 89b93cb..0000000 --- a/projects/jdwp/defs/commands/reference_type.py +++ /dev/null @@ -1,695 +0,0 @@ -"""JDWP Commands for Reference Type Command Set.""" -from jdwp.defs.schema import Command, Field, Struct, Types -from jdwp.constants.errors import ErrorConstants - - -Signature = Command( - name="Signature", - id=1, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The Reference type ID."), - ] - ), - reply=Struct( - [ - Field( - "signature", Types.STRING, "The JNI signature for the reference type." - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ClassLoader = Command( - name="Class loader", - id=2, - out=Struct( - [ - Field( - "refType", - Types.REFERENCE_TYPE_ID, - "The reference type ID.", - ), - ] - ), - reply=Struct( - [ - Field( - "classLoaderID", - Types.CLASS_LOADER, - "The class loader for the reference type.", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Modifiers = Command( - name="Modifiers", - id=3, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), - reply=Struct( - [ - Field( - "modBits", - Types.INT, - "Modifier bits as defined in Chapter 4 of The Java™ Virtual Machine Specification. ", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Fields = Command( - name="Fields", - id=4, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), - reply=Struct( - [ - Field("declared", Types.INT, "Number of declared fields."), - Field("fieldID", Types.FIELD_ID, "Field ID."), - Field("name", Types.STRING, "Name of field."), - Field("signature", Types.STRING, "JNI Signature of field."), - Field( - "modBits", - Types.INT, - "The modifier bit flags (also known as access flags).", - ), - ] - ), - error=Struct( - [ - Field( - "CLASS_NOT_PREPARED", - ErrorConstants.CLASS_NOT_PREPARED, - "Class has been loaded but not yet prepared.", - ), - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Methods = Command( - name="Methods", - id=5, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID.")]), - reply=Struct( - [ - Field("declared", Types.INT, "Number of declared methods."), - Field("methodID", Types.METHOD_ID, "Method ID."), - Field("name", Types.STRING, "Name of method."), - Field("signature", Types.STRING, "JNI signature of method."), - Field( - "modBits", - Types.INT, - "The modifier bit flags (also known as access flags).", - ), - ] - ), - error=Struct( - [ - Field( - "CLASS_NOT_PREPARED", - ErrorConstants.CLASS_NOT_PREPARED, - "Class has been loaded but not yet prepared.", - ), - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -GetValues = Command( - name="Get values", - id=6, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - Field("fields", Types.INT, "The number of values to get."), - ] - ), - reply=Struct( - [ - Field( - "values", - Types.INT, - "The number of values returned, always equal to fields.", - ), - Field("value", Types.VALUE, "The field value."), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "INVALID_FIELDID", - ErrorConstants.INVALID_FIELDID, - "One or more fieldIDs are invalid.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - - -SourceFile = Command( - name="Sourcefile", - id=7, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field( - "sourceFile", - Types.STRING, - "The source file name. No path information for the file is included", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "ABSENT_INFORMATION", - ErrorConstants.ABSENT_INFORMATION, - "The source file attribute is not present.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -NestedTypes = Command( - name="Nested types", - id=8, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("classes", Types.INT, "The number of nested classes and interfaces"), - Field("refTypeTag", Types.BYTE, "Kind of following reference type."), - Field( - "typeID", Types.REFERENCE_TYPE_ID, "The nested class or interface ID." - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Status = Command( - name="Status", - id=9, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("status", Types.INT, "Status bits: See JDWP.ClassStatus"), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Interfaces = Command( - name="Interfaces", - id=10, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("interfaces", Types.INT, "The number of implemented interfaces"), - Field("interfaceType", Types.INTERFACE_ID, "Implemented interface."), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ClassObject = Command( - name="Class object", - id=11, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct([Field("classObject", Types.CLASS_OBJECT_ID, "Class object.")]), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -SourceDebugExtension = Command( - name="Source debug extension", - id=12, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct([Field("extension", Types.STRING, "Extension attribute.")]), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "ABSENT_INFORMATION", - ErrorConstants.ABSENT_INFORMATION, - "The source debug extension attribute is not present.", - ), - Field( - "NOT_IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -SignatureWithGeneric = Command( - name="Signature with generic", - id=13, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field( - "signature", Types.STRING, "The JNI signature for the reference type." - ), - Field( - "genericSignature", - Types.STRING, - "The generic signature for the reference type or an empty string if there is none.", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -FieldsWithGeneric = Command( - name="Fields with generic", - id=14, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("declared", Types.INT, "Number of declared fields."), - Field("fieldID", Types.FIELD_ID, "Field ID."), - Field("name", Types.STRING, "The name of the field."), - Field("signature", Types.STRING, "The JNI signature of the field."), - Field( - "genericSignature", - Types.STRING, - "The generic signature of the field, or an empty string if there is none.", - ), - Field("modBits", Types.INT, "The modifier bit flags."), - ] - ), - error=Struct( - [ - Field( - "CLASS_NOT_PREPARED", - ErrorConstants.CLASS_NOT_PREPARED, - "Class has been loaded but not yet prepared.", - ), - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - - -MethodsWithGeneric = Command( - name="Methods with generic", - id=15, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - ] - ), - reply=Struct( - [ - Field("declared", Types.INT, "Number of declared methods."), - Field("methodID", Types.METHOD_ID, "Method ID."), - Field("name", Types.STRING, "The name of the method."), - Field("signature", Types.STRING, "The JNI signature of the method."), - Field( - "genericSignature", - Types.STRING, - "The generic signature of the method, or an empty string if there is none.", - ), - Field("modBits", Types.INT, "The modifier bit flags."), - ] - ), - error=Struct( - [ - Field( - "CLASS_NOT_PREPARED", - ErrorConstants.CLASS_NOT_PREPARED, - "Class has been loaded but not yet prepared.", - ), - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Instances = Command( - name="Instances", - id=16, - out=Struct( - [ - Field("refType", Types.REFERENCE_TYPE_ID, "The reference type ID."), - Field("maxInstances", Types.INT, "Maximum number of instances to return."), - ] - ), - reply=Struct( - [ - Field("instances", Types.INT, "The number of instances that follow."), - Field( - "instance", - Types.TAGGED_OBJECT_ID, - "An instance of this reference type.", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "NOT_IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "Illegal Argument", - ErrorConstants.ILLEGAL_ARGUMENT, - "maxInstances is less than zero.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - - -ClassFileVersion = Command( - name="Class file version", - id=17, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The class.")]), - reply=Struct( - [ - Field("majorVersion", Types.INT, "Major version number"), - Field("minorVersion", Types.INT, "Minor version number"), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "ABSENT INFORMATION", - ErrorConstants.ABSENT_INFORMATION, - "The class file version information is absent for primitive and array types.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ConstantPool = Command( - name="Constant pool", - id=18, - out=Struct([Field("refType", Types.REFERENCE_TYPE_ID, "The class.")]), - reply=Struct( - [ - Field( - "count", Types.INT, "Total number of constant pool entries plus one." - ), - Field("bytes", Types.BYTE, "Raw bytes of constant pool"), - ] - ), - error=Struct( - [ - Field( - "INVALID_CLASS", - ErrorConstants.INVALID_CLASS, - "refType is not the ID of a reference type.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "refType is not a known ID.", - ), - Field( - "ABSENT INFORMATION", - ErrorConstants.ABSENT_INFORMATION, - "The class file version information is absent for primitive and array types.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) diff --git a/projects/jdwp/defs/commands/thread_reference.py b/projects/jdwp/defs/commands/thread_reference.py deleted file mode 100644 index d08d306..0000000 --- a/projects/jdwp/defs/commands/thread_reference.py +++ /dev/null @@ -1,470 +0,0 @@ -"""JDWP Commands for ThreadReference Command Set.""" - -from jdwp.defs.schema import Command, Field, Struct, Types -from jdwp.constants.errors import ErrorConstants - -Name = Command( - name="Name", - id=1, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct([Field("threadName", Types.STRING, "The thread name.")]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - - -Suspend = Command( - name="Suspend", - id=2, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Resume = Command( - name="Resume", - id=3, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Status = Command( - name="Status", - id=4, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field( - "threadStatus", - Types.INT, - "One of the thread status codes. See JDWP.ThreadStatus", - ), - Field( - "suspendStatus", - Types.INT, - "One of the suspend status codes. See JDWP.SuspendStatus", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ThreadGroup = Command( - name="Thread group", - id=5, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field( - "threadGroupID", - Types.THREAD_GROUP_ID, - "The thread group of this thread.", - ) - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Frames = Command( - name="Frames", - id=6, - out=Struct( - [ - Field("threadID", Types.THREAD_ID, "The thread object ID."), - Field("startFrame", Types.INT, "The index of the first frame to retrieve."), - Field( - "length", - Types.INT, - "The count of frames to retrieve (-1 means all remaining).", - ), - ] - ), - reply=Struct( - [ - Field("frames", Types.INT, "The number of frames retrieved"), - Field("frameID", Types.FRAME_ID, "The ID of this frame."), - Field("location", Types.LOCATION, "The location of this frame."), - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -FrameCount = Command( - name="Frame count", - id=7, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [Field("frameCount", Types.INT, "The count of frames on this thread's stack.")] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -OwnedMonitors = Command( - name="Owned monitors", - id=8, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field("owned", Types.INT, "The number of owned monitors"), - Field("monitor", Types.TAGGED_OBJECT_ID, "An owned monitor"), - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "NOT IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -CurrentContendedMonitor = Command( - name="Current contended monitor", - id=9, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field( - "monitor", - Types.OBJECT_ID, - "The contended monitor, or null if there is no current contended monitor.", - ) - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "NOT IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Stop = Command( - name="Stop", - id=10, - out=Struct( - [ - Field("threadID", Types.THREAD_ID, "The thread object ID."), - Field( - "throwable", - Types.OBJECT_ID, - "Asynchronous exception. This object must be an instance of java.lang.Throwable or a subclass", - ), - ] - ), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -Interrupt = Command( - name="Interrupt", - id=11, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -SuspendCount = Command( - name="Suspend count", - id=12, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field( - "suspendCount", - Types.INT, - "The number of outstanding suspends of this thread.", - ) - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -OwnedMonitorsStackDepthInfo = Command( - name="Owned monitors stack depth info", - id=13, - out=Struct([Field("threadID", Types.THREAD_ID, "The thread object ID.")]), - reply=Struct( - [ - Field("owned", Types.INT, "The number of owned monitors"), - Field("monitor", Types.TAGGED_OBJECT_ID, "An owned monitor"), - Field( - "stack_depth", - Types.INT, - "Stack depth location where monitor was acquired", - ), - ] - ), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "NOT IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) - -ForceEarlyReturn = Command( - name="Force early return", - id=14, - out=Struct( - [ - Field("threadID", Types.THREAD_ID, "The thread object ID."), - Field("value", Types.VALUE, "The value to return."), - ] - ), - reply=Struct([]), - error=Struct( - [ - Field( - "INVALID_THREAD", - ErrorConstants.INVALID_THREAD, - "Passed thread is null, is not a valid thread or has exited.", - ), - Field( - "INVALID_OBJECT", - ErrorConstants.INVALID_OBJECT, - "thread is not a known ID.", - ), - Field( - "THREAD_NOT_SUSPENDED", - ErrorConstants.THREAD_NOT_SUSPENDED, - "If the specified thread has not been suspended by an event.", - ), - Field( - "THREAD_NOT_ALIVE", - ErrorConstants.THREAD_NOT_ALIVE, - "Thread has not been started or is now dead.", - ), - Field( - "OPAQUE_FRAME", - ErrorConstants.OPAQUE_FRAME, - "Attempted to return early from a frame corresponding to a native method. Or the implementation is unable to provide this functionality on this frame.", - ), - Field( - "NO_MORE_FRAMES", - ErrorConstants.NO_MORE_FRAMES, - "There are no more Java or JNI frames on the call stack.", - ), - Field( - "NOT IMPLEMENTED", - ErrorConstants.NOT_IMPLEMENTED, - "The functionality is not implemented in this virtual machine.", - ), - Field( - "TYPE_MISMATCH", - ErrorConstants.TYPE_MISMATCH, - "Value is not an appropriate type for the return value of the method.", - ), - Field( - "VM_DEAD", ErrorConstants.VM_DEAD, "The virtual machine is not running." - ), - ] - ), -) From 03c3c641b1fd5037922edd1af7e86fe765162121 Mon Sep 17 00:00:00 2001 From: Christian Abrokwa Date: Wed, 25 Oct 2023 09:04:54 +0000 Subject: [PATCH 16/20] Updated code so pyre will run on new files. --- projects/jdwp/BUCK | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/jdwp/BUCK b/projects/jdwp/BUCK index 0db4b80..4874881 100644 --- a/projects/jdwp/BUCK +++ b/projects/jdwp/BUCK @@ -8,7 +8,7 @@ python_binary( python_library( - name = "lib", - srcs = [], + name = "defs", + srcs = glob(["**/*.py"]), visibility = ["PUBLIC"], ) From a61aa870ea62082edbae4cf0920a13685cea2f1b Mon Sep 17 00:00:00 2001 From: Christian Abrokwa Date: Wed, 25 Oct 2023 12:39:31 +0000 Subject: [PATCH 17/20] Fixed incompatible type error --- projects/jdwp/defs/command_sets/reference_type.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/jdwp/defs/command_sets/reference_type.py b/projects/jdwp/defs/command_sets/reference_type.py index 910330b..224b4ab 100644 --- a/projects/jdwp/defs/command_sets/reference_type.py +++ b/projects/jdwp/defs/command_sets/reference_type.py @@ -23,11 +23,11 @@ ), ] ), - error=Sequence[ + error={ ErrorType.INVALID_CLASS, ErrorType.INVALID_OBJECT, ErrorType.VM_DEAD, - ], + }, ) From b753df14007a76b284c75d9378dcbb25093248dd Mon Sep 17 00:00:00 2001 From: Christian Abrokwa Date: Wed, 25 Oct 2023 12:49:01 +0000 Subject: [PATCH 18/20] Fixed typo --- projects/jdwp/defs/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/jdwp/defs/schema.py b/projects/jdwp/defs/schema.py index c05afee..49b6c83 100644 --- a/projects/jdwp/defs/schema.py +++ b/projects/jdwp/defs/schema.py @@ -52,7 +52,7 @@ class Field: """Field class.""" name: str - type = Type + type: Type description: str From 56096e6bc57cb3e450b069be3c0d7702b1376908 Mon Sep 17 00:00:00 2001 From: Christian Abrokwa Date: Wed, 25 Oct 2023 12:49:18 +0000 Subject: [PATCH 19/20] Updated path for type. --- projects/jdwp/defs/command_sets/reference_type.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/projects/jdwp/defs/command_sets/reference_type.py b/projects/jdwp/defs/command_sets/reference_type.py index 224b4ab..1df5014 100644 --- a/projects/jdwp/defs/command_sets/reference_type.py +++ b/projects/jdwp/defs/command_sets/reference_type.py @@ -2,10 +2,9 @@ """Command Set: ReferenceType.""" -from jdwp.defs.schema import CommandSet, Type -from jdwp.defs.schema import Command, Field, Struct + +from projects.jdwp.defs.schema import Command, Field, Struct, CommandSet, Type from projects.jdwp.defs.constants import ErrorType -from collections.abc import Sequence Signature = Command( From 03d51f93bd45d0ce175ba8d8b837c18e16c3a5fb Mon Sep 17 00:00:00 2001 From: Christian Abrokwa Date: Wed, 25 Oct 2023 13:53:48 +0000 Subject: [PATCH 20/20] Change name of buck file --- projects/jdwp/BUCK | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/jdwp/BUCK b/projects/jdwp/BUCK index 4874881..bbad7db 100644 --- a/projects/jdwp/BUCK +++ b/projects/jdwp/BUCK @@ -8,7 +8,7 @@ python_binary( python_library( - name = "defs", + name = "lib", srcs = glob(["**/*.py"]), visibility = ["PUBLIC"], )