Open gsuberland opened 2 years ago
The cpool
op is not a general-purpose operation intended for use by any architecture. Instead, it is intended to handle the "constant pool" in java .class
files and similar constructs (hence the name). In a .class
file, the constant pool is a data structure which stores (among many other things) information needed to model JVM bytecode operations correctly.
A simple example is the getfield
instruction, which pushes a field of an object onto the operand stack. That field can be either 4 or 8 bytes, depending on whether it's an int
/long
/object reference, etc. In order to determine whether it's 4 or 8 bytes, you need to look at data in the constant pool - it's not directly encoded in the bytes of the instruction. When the decompiler is processing a method in a .class
file and encounters a getfield
instruction, it has to pause and ask the rest of Ghidra to examine the data in the constant pool and report back how many bytes are being pushed onto the operand stack.
Essentially, properly modelling this instruction requires information located in another part of the binary being analyzed. That other part of the binary is a data structure that itself needs to be parsed and analyzed. The cpool
op is the way that the decompiler can get information from this data structure. Note that this isn't the same as handling something like an indirect call whose destination is only known at runtime.
I'm really struggling to understand what
cpool
does and how it works. The existing documentation oncpool
can be summarised as follows:From sleigh_ref.html
From sleigh_constructors.html
From pseudo-ops.html
I was unable to form an understanding of how
cpool
and the constant pool works based on the existing documentation, even when referring to usages ofcpool
in existing implementations.The questions I have are:
cpuid(eax)
intocpuid(IA_CPUID_VERSION_INFO)
when the value ofeax
is known to be 1.cpool
aid in this task?cpool
is "generally an object reference". What does this mean? What kind of object, and where does the reference come from? What is the purpose of the object?METHOD_INDEX
a special keyword, or something defined by the example code? Where is it defined? What does it do?$(CPOOL_METHOD)
do? Where is it defined?cpool
special in this regard? From where do these architecture-dependent details arise?cpool
can be used "where some details about how instructions behave can be deferred until run-time". Presumably this is referring to something like calling instance methods by vtable index in an IL? Clarification would be appreciated.It'd be helpful if the SLEIGH documentation around constant pools and
cpool
could be expanded to help answer these questions.