java.lang.Object | |
↳ | com.pnfsoftware.jeb.core.units.code.asm.decompiler.ir.compiler.EIRCompiler |
Compiler of IR expressions, IR statements, IR CFG, IR routines, and IR programs (code and data).
Current limitations:
IEUntranslatedInstruction
is not supported.
<< ... >>
brackets. Leave the type info empty
(<<>>
) for EImm to specify they should be mutable but not carry any type information
(this is different than <<?>>
which specify a wildcard type of 1 slot with no
information.
Rules and syntax:
s32:var1 = i32:01h
/2: nop
will create an ENop of
size 2 instead of the default size 1
1A00: nop
will create an ENop statement whose mapping to a hypothetical native address is set to 0x1A00
global-context rID -> physical register EVar if possible RID -> virtual register EVar if possible gADDR -> memory-mapped global EVar if possible ptr_gAAA -> global symbol EVar if possible routine-context vID -> virtual routine-context EVar if possible (similar to global-context's R..) varADDR -> memory-mapped local stack EVar variable (negative stack offset rel.to SP0) parADDR -> memory-mapped local stack EVar variable (positive or null stack offset rel.to SP0) ptr_varADDR -> pointer (reference) to a local memory-mapped stack variable ptr_parADDR -> pointer (reference) to a local memory-mapped stack parameter $r.. -> copy of var $r..$N -> additional copy of var (N>=1) $r.._r.. -> copy of var pair $r.._r..$N -> additional copy of var pair (N>=1) $r..loX -> copy of var, truncated (LSB part) $r..hiX -> copy of var, truncated (MSB part) $r..loX$N -> additional copy of var, truncated (LSB part) $r..hiX$N -> additional copy of var, truncated (MSB part)
Specific rules for expression and statement compilation:
- PC-assigns can receive additional information, to be provided as end-of-line tags enclosed in
brackets:
- [BRANCH]
-> means the PC-assign should be generated as if it came from a normal
branching instruction
- [SUB]
-> means the PC-assign should be generated as if it came from call-to-sub
instruction
- [BRANCH_HINTS:offsets]
-> provide pseudo-native target hints for the branching
instructions; offsets must be a comma-separated list of pseudo-native offsets (not IR
offsets)
Specific rules for CFG compilation:
- N/A
Specific rules for routine compilation:
- routines may or may not be enclosed in PROC/ENDP
Specific rules for program compilation:
- routines must be enclosed in PROC/ENPD. The wanted name, wanted pseudo start address (native),
and IR prototype are all optional:
- data elements: see below.
PROC Name @NativeAddress :Prototype ... ... ENDP
Defining references: simulate dynamically resolved references to routine and data imported into the module, but physically located in an external component.
IMPORT CODE MethodName [:OptionalPrototype] IMPORT DATA FieldName [:OptionalType]
Defining data elements (native memory):
- syntax for raw bytes (does not create variable object, just memory init.) DB/DW/DD/DQ/DS @Address Value B,W,D,Q=BYTE, WORD, DWORD, QWORD (1, 2, 4, 8 byte), hex or decimal value endianness for memory-encoding matches the processor's (referenced in the native context, held by global context provided to the compiler) DB can also be used byte sequences: Value is an arbitrarily-long hex-encoded byte sequence or an escaped string - no zero terminator is appended examples: DB @100 0x11 DW @100 0x1122 DD @100 0x11223344 DQ @100 0x1122334455667788 DB @100 '11aabb660099ff414141141' <--- hex-encoded string (note the single-quotes, vs double-quotes for strings) DB @100 "Hello World!" <--- encode to ASCII [NOT SUPPORTED YET] DB @100 U"Hello World!" <--- encode to UTF8 [NOT SUPPORTED YET] DB @100 L"Hello World!" <--- encode to UTF16LE (note little-endian) - syntax for regular data items: DV Name @Address :TypeName [OptionalValue] where Value is an optional hex-encoded string whose length must be less than or equals to the size of the variable Type - syntax for string (ascii-encoded, 0-terminated) data items: DS Name @Address "Hello" the zero terminator is added implicitly, so the above string would translate to 6 bytes, not 5 - syntax for imported references: DR Name @Address &ImportName
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
class | EIRCompiler.CompiledExpression | A compiled expression. | |||||||||
class | EIRCompiler.CompiledField | ||||||||||
class | EIRCompiler.CompiledProgram | A compiled program. | |||||||||
class | EIRCompiler.CompiledRoutine | A compiled routine. | |||||||||
class | EIRCompiler.CompiledStatement | A compiled statement. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
EIRCompiler(IEGlobalContext gctx)
Create an IR compiler.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static <T extends IEGeneric> T |
cc(String s, IEGlobalContext gctx, Class<T> clazz)
Convenience method to parse an IR expression or statement.
| ||||||||||
static IEGeneric |
cc(String s, IEGlobalContext gctx)
Convenience method to parse an IR expression or statement.
| ||||||||||
CFG<IEStatement> |
compileCfg(String... slist)
Compile a sequence of statements and return the CFG.
| ||||||||||
CFG<IEStatement> |
compileCfg(IERoutineContext ctx, String... slist)
Compile a sequence of statements and return the CFG.
| ||||||||||
EIRCompiler.CompiledExpression |
compileExpression(IERoutineContext ctx, String s)
Compile a non-statement expression.
| ||||||||||
EIRCompiler.CompiledExpression |
compileExpression(String s)
Compile a non-statement expression.
| ||||||||||
EIRCompiler.CompiledProgram |
compileProgram(File file)
Compile an IR program made of 1 or more routines.
| ||||||||||
EIRCompiler.CompiledProgram |
compileProgram(List<String> slist)
Compile an IR program made of 1 or more routines.
| ||||||||||
EIRCompiler.CompiledProgram |
compileProgram(String... slist)
Compile an IR program made of 1 or more routines.
| ||||||||||
EIRCompiler.CompiledRoutine |
compileRoutine(String... slist)
Compile an IR routine.
| ||||||||||
EIRCompiler.CompiledStatement |
compileStatement(IERoutineContext ctx, String s)
Compile a single statement.
| ||||||||||
EIRCompiler.CompiledStatement |
compileStatement(String s)
Compile a single statement.
| ||||||||||
void |
reset()
Reset this compiler's state.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Create an IR compiler.
gctx | global IR context - one can be provided by getGlobalContext()
or, if no converter is available, can be created ad-hoc
|
---|
Convenience method to parse an IR expression or statement.
Convenience method to parse an IR expression or statement.
Compile a sequence of statements and return the CFG.
slist | statement list |
---|
Compile a sequence of statements and return the CFG.
ctx | optional routine context to be used; if null, a fresh context will be created |
---|---|
slist | statement list |
Compile a non-statement expression.
ctx | optional routine context to be used; if null, a fresh context will be created |
---|---|
s | pure expression string (not a statement) |
Compile a non-statement expression.
s | pure expression string (not a statement) |
---|
Compile an IR program made of 1 or more routines.
file | UTF8 encoded source file |
---|
IOException |
---|
Compile an IR program made of 1 or more routines.
slist | program source strings |
---|
Compile an IR program made of 1 or more routines.
slist | program source strings |
---|
Compile an IR routine.
slist | routine source |
---|
Compile a single statement.
ctx | optional routine context to be used; if null, a fresh context will be created |
---|---|
s | statement string |
Compile a single statement.
s | statement string |
---|
Reset this compiler's state. Note that the global IR context (IEGlobalContext
) is not
reset.