public class JebInstance
extends java.lang.Object
This class represents a running instance of JEB, or context. The instance might be an automation (command-line, non-interactive) instance, or a GUI instance.
Objects of this class may not be instantiated by scripts. The current JEB instance reference is passed
to the script entry-point method, IScript.run()
.
IScript
Constructor and Description |
---|
JebInstance(java.lang.Object ctx_data)
Internal constructor, do not use.
|
Modifier and Type | Method and Description |
---|---|
boolean |
close()
Close the currently processed file.
|
java.lang.String |
decompile(java.lang.String partial_sig,
boolean is_class)
Decompile a class or a method.
|
java.lang.String |
decompile(java.lang.String partial_sig,
boolean is_class,
boolean regenerate,
java.util.List<Mark> marks)
Decompile a class or a method.
|
java.lang.String |
decompileClass(java.lang.String partial_sig)
Decompile a class.
|
java.lang.String |
decompileMethod(java.lang.String partial_sig)
Decompile a method.
|
void |
enableLogger(boolean enabled)
Enable or disable all output.
|
void |
exit()
Exit JEB.
|
java.lang.String |
generateAssembly()
Disassemble and generate assembly output for the DEX file.
|
java.util.List<Comment> |
getAllComments()
Retrieve all comments.
|
FileInformation |
getAnalyzedFileInformation()
Retrieve cached information about the underlying file that was originally opened for analysis.
|
int |
getApiVersion()
Get the API version number ("API level").
|
byte[] |
getAssets()
Get the assets stored in the currently processed APK.
|
java.lang.String |
getBaseDirectory()
Get the main JEB directory.
|
byte[] |
getCertificate()
Get the X509-encoded main certificate of the APK currently processed.
|
java.lang.String |
getClassComment(java.lang.String partial_sig)
Get a class comment.
|
java.lang.String |
getConfigurationPath()
Retrieve the configuration file path.
|
java.lang.Object |
getD()
Accessor method.
|
java.lang.String |
getDatabasePath()
Retrieve the JEB database (JDB) file path.
|
Class |
getDecompiledClassTree(java.lang.String partial_sig)
Get the AST root element that represents the Java code of a decompiled class.
|
Method |
getDecompiledMethodTree(java.lang.String partial_sig)
Get the AST root element that represents the Java code of a decompiled method.
|
Dex |
getDex()
Get a representation of the DEX file currently processed by JEB.
|
java.lang.String |
getFieldComment(java.lang.String partial_sig)
Get a field comment.
|
long |
getFreeMemory()
Get the free amount of memory.
|
java.lang.String |
getGlobalComment()
Get the global comment, or 'notes'.
|
java.lang.Object |
getGO()
Accessor method.
|
java.lang.String |
getInputPath()
Retrieve the input file path.
|
java.lang.String |
getInstructionComment(java.lang.String partial_sig,
int offset)
Get an instruction comment.
|
byte[] |
getLibraries()
Get the libraries stored in the currently processed APK.
|
java.lang.String |
getManifest()
Get a copy of the Android manifest file.
|
long |
getMaxMemory()
Get the maximum amount of memory that JEB will ever attempt to use.
|
java.lang.String |
getMethodComment(java.lang.String partial_sig)
Get a method comment.
|
java.lang.String |
getPluginsDirectory()
Get the plugins directory.
|
java.lang.String |
getProgramDirectory()
Get the program's directory.
|
byte[] |
getResources()
Get the decoded resources stored in the currently processed APK.
|
java.lang.String[] |
getScriptArguments()
Get the script arguments.
|
java.lang.String |
getScriptPath()
Retrieve the script file path.
|
java.lang.String |
getSignaturesDirectory()
Get the signatures directory.
|
java.lang.String |
getSoftwareVersion()
Get the version of JEB.
|
long |
getTotalMemory()
Get the total amount of memory currently reserved by JEB (used memory and free memory).
|
JebUI |
getUI()
Get an object that represents the current JEB user interface.
|
java.lang.String |
getUserEmail()
Get the JEB licensee's email address.
|
java.lang.String |
getUserGroup()
Get the JEB licensee's group or organization.
|
java.lang.String |
getUserName()
Get the JEB licensee's full name.
|
boolean |
isFileLoaded()
Determine if a file is currently being processed by JEB.
|
java.util.List<java.lang.Integer> |
listUserDataBlocks()
List the user data blocks stored in the currently opened JDB file.
|
boolean |
load(java.lang.String path)
Load a new file in JEB.
|
byte[] |
loadUserData(int id)
Retrieve a user data block stored in the JEB database.
|
void |
print(java.lang.String s)
Log a string to the JEB console.
|
boolean |
removeUserData(int id)
Delete a block of user data from the JEB database.
|
boolean |
renameClass(java.lang.String partial_sig,
java.lang.String new_name)
Rename a DEX class.
|
boolean |
renameField(java.lang.String partial_sig,
java.lang.String new_name)
Rename a DEX field.
|
boolean |
renameMethod(java.lang.String partial_sig,
java.lang.String new_name)
Rename a DEX method.
|
boolean |
save()
Save the changes for the currently processed file to a JEB database file (JDB), or update an existing JDB.
|
boolean |
setClassComment(java.lang.String partial_sig,
java.lang.String text)
Set a class comment.
|
boolean |
setEngineOption(EngineOption opt,
java.lang.String val)
Set an engine (APK/DEX parser, Decompiler) option - automation mode only.
|
boolean |
setFieldComment(java.lang.String partial_sig,
java.lang.String text)
Set a field comment.
|
boolean |
setGlobalComment(java.lang.String text)
Set the global comment, or 'notes'.
|
boolean |
setInstructionComment(java.lang.String partial_sig,
int offset,
java.lang.String text)
Set an instruction comment.
|
boolean |
setMethodComment(java.lang.String partial_sig,
java.lang.String text)
Set a method comment.
|
void |
setTerminationOnScriptError(boolean terminate_on_script_error)
Set JEB to terminate immediately if any script or plugin error happens.
|
void |
setTimeout(long millis)
Set a timeout for the current script execution.
|
boolean |
storeUserData(int id,
byte[] data,
boolean overwrite)
Save a block of user data to the JEB database.
|
public JebInstance(java.lang.Object ctx_data)
Internal constructor, do not use.
Clients should never create instances of this class directly.
An instance is passed as a parameter to the IScript.run
method.
ctx_data
- opaque context datapublic int getApiVersion()
Get the API version number ("API level").
The API level is a general indication of the range of features supported by the API.
public java.lang.String getSoftwareVersion()
Get the version of JEB.
public long getTotalMemory()
Get the total amount of memory currently reserved by JEB (used memory and free memory).
public long getFreeMemory()
Get the free amount of memory.
public long getMaxMemory()
Get the maximum amount of memory that JEB will ever attempt to use.
public java.lang.String getUserName()
Get the JEB licensee's full name.
public java.lang.String getUserEmail()
Get the JEB licensee's email address.
public java.lang.String getUserGroup()
Get the JEB licensee's group or organization.
public java.lang.String getBaseDirectory()
Get the main JEB directory.
public java.lang.String getProgramDirectory()
Get the program's directory.
public java.lang.String getPluginsDirectory()
Get the plugins directory. It contains scripts for custom actions.
public java.lang.String getSignaturesDirectory()
Get the signatures directory. It contains library binary signatures.
public java.lang.String[] getScriptArguments()
Get the script arguments.
The optional script arguments are provided after --
marker on the command-line.
public boolean isFileLoaded()
Determine if a file is currently being processed by JEB.
Most methods in this class need a file being opened and processed in order to return meaningful/non-null values.
public Dex getDex()
Get a representation of the DEX file currently processed by JEB.
Important note: when a file is closed (using close()
) and a new one loaded (using load(java.lang.String)
),
this reference gets stale. The client should get a reference on the newly loaded file before proceeding.
public JebUI getUI()
Get an object that represents the current JEB user interface.
If ran in command-line/automation mode, there is no UI object to return.
public void setTimeout(long millis)
Set a timeout for the current script execution.
By default, script execution has no timeout. If a timeout is set, the execution of a script will be forcefully stopped if its duration exceeds that timeout.
millis
- timeout in milliseconds, no data if less or equal than zeropublic void setTerminationOnScriptError(boolean terminate_on_script_error)
Set JEB to terminate immediately if any script or plugin error happens. By default, this value is false: JEB keeps running on script error. The exception is logged to the standard output before termination. The exit code returned is -3.
terminate_on_script_error
- whether or not JEB should terminate on script errorpublic void enableLogger(boolean enabled)
Enable or disable all output.
enabled
- whether or not the logger should be enabledpublic void print(java.lang.String s)
Log a string to the JEB console. A new line character is appended.
s
- the string to be loggedpublic boolean save()
Save the changes for the currently processed file to a JEB database file (JDB), or update an existing JDB.
public boolean close()
Close the currently processed file.
public boolean load(java.lang.String path)
Load a new file in JEB. If a file is already opened, it must be closed first.
path
- the file path (APK, DEX, or JDB)public void exit()
Exit JEB.
Note: This method terminates the program without asking for user input. One should ensure the database is saved before calling this method.
public java.lang.String getInputPath()
Retrieve the input file path.
The input path can be a JDB, APK, or DEX file.
public FileInformation getAnalyzedFileInformation()
Retrieve cached information about the underlying file that was originally opened for analysis.
That would be an APK file or a DEX file.
public java.lang.String getConfigurationPath()
Retrieve the configuration file path.
public java.lang.String getScriptPath()
Retrieve the script file path.
public java.lang.String getDatabasePath()
Retrieve the JEB database (JDB) file path.
The file may not exist, and may need to be created or updated using save()
.
public java.lang.String getManifest()
Get a copy of the Android manifest file.
public byte[] getCertificate()
Get the X509-encoded main certificate of the APK currently processed.
The certificate can be manipulated by external tools, for instance OpenSSL:
$ openssl x509 -in cert.bin -inform DER -noout -text
public byte[] getResources()
Get the decoded resources stored in the currently processed APK.
public byte[] getAssets()
Get the assets stored in the currently processed APK.
public byte[] getLibraries()
Get the libraries stored in the currently processed APK.
public boolean renameClass(java.lang.String partial_sig, java.lang.String new_name)
Rename a DEX class.
partial_sig
- class name, original or effective, can be anything as long as it uniquely identifies a classnew_name
- the new simple namepublic boolean renameField(java.lang.String partial_sig, java.lang.String new_name)
Rename a DEX field.
partial_sig
- field name, original or effective, can be anything as long as it uniquely identifies a fieldnew_name
- the new simple namepublic boolean renameMethod(java.lang.String partial_sig, java.lang.String new_name)
Rename a DEX method.
partial_sig
- method name, original or effective, can be anything as long as it uniquely identifies a methodnew_name
- the new simple namepublic boolean setGlobalComment(java.lang.String text)
Set the global comment, or 'notes'.
Caveat: this method just sets the global comment. It does not update the client's view responsible for displaying that comment, if any.
Therefore, if running a UI client with an attached comment view, a view refresh is recommended after setting the global comment.
See: JebInstance.getUI().getView(View.Type.NOTES).refresh()
text
- text commentpublic boolean setClassComment(java.lang.String partial_sig, java.lang.String text)
Set a class comment.
partial_sig
- class name, original or effective, can be anything as long as it uniquely identifies a classtext
- text commentpublic boolean setFieldComment(java.lang.String partial_sig, java.lang.String text)
Set a field comment.
partial_sig
- field name, original or effective, can be anything as long as it uniquely identifies a fieldtext
- text commentpublic boolean setMethodComment(java.lang.String partial_sig, java.lang.String text)
Set a method comment.
partial_sig
- method name, original or effective, can be anything as long as it uniquely identifies a methodtext
- text commentpublic boolean setInstructionComment(java.lang.String partial_sig, int offset, java.lang.String text)
Set an instruction comment.
partial_sig
- method name, original or effective, can be anything as long as it uniquely identifies a methodoffset
- bytecode offset within the method, in bytestext
- text commentpublic java.lang.String getGlobalComment()
Get the global comment, or 'notes'.
public java.lang.String getClassComment(java.lang.String partial_sig)
Get a class comment.
partial_sig
- class name, original or effective, can be anything as long as it uniquely identifies a classpublic java.lang.String getFieldComment(java.lang.String partial_sig)
Get a field comment.
partial_sig
- field name, original or effective, can be anything as long as it uniquely identifies a fieldpublic java.lang.String getMethodComment(java.lang.String partial_sig)
Get a method comment.
partial_sig
- method name, original or effective, can be anything as long as it uniquely identifies a methodpublic java.lang.String getInstructionComment(java.lang.String partial_sig, int offset)
Get an instruction comment.
partial_sig
- method name, original or effective, can be anything as long as it uniquely identifies a methodoffset
- bytecode offset within the method, in bytespublic java.util.List<Comment> getAllComments()
Retrieve all comments.
public boolean setEngineOption(EngineOption opt, java.lang.String val)
Set an engine (APK/DEX parser, Decompiler) option - automation mode only.
The APK/DEX options should be set before loading a file. The Decompiler options can be
set prior to calling the decompileClass(java.lang.String)
method.
opt
- option type. For boolean options, the value should be "true" or "false".
For integer options, the value should be a string representation of the decimal value.val
- option valuepublic java.lang.String decompileClass(java.lang.String partial_sig)
Decompile a class. Regardless of whether the class was already decompiled, a fresh decompilation will take place.
Equivalent to decompile
(partial_sig, true).
partial_sig
- class name, original or effective, can be anything as long as it uniquely identifies a classpublic java.lang.String decompileMethod(java.lang.String partial_sig)
Decompile a method. Regardless of whether the method was already decompiled, a fresh decompilation will take place.
Equivalent to decompile
(partial_sig, false).
partial_sig
- method name, original or effective, can be anything as long as it uniquely identifies a methodpublic java.lang.String decompile(java.lang.String partial_sig, boolean is_class)
Decompile a class or a method. Regardless of whether the class or method was already decompiled, a fresh decompilation will take place.
Equivalent to decompile
(partial_sig, is_class, true, null).
partial_sig
- class or method name, original or effective, can be anything as long as it uniquely identifies the itemis_class
- true if class, false if methodpublic java.lang.String decompile(java.lang.String partial_sig, boolean is_class, boolean regenerate, java.util.List<Mark> marks)
Decompile a class or a method.
partial_sig
- class or method name, original or effective, can be anything as long as it uniquely identifies the itemis_class
- true if class, false if methodregenerate
- true to force a fresh decompilationmarks
- optional output list, used to gather marks generated by the AST renderer.
Generally, if this parameter is non-null, you will want to set regenerate to False.
(If not, a fresh (tag-less) AST would be generated, yielding an empty markers list)public java.lang.String generateAssembly()
Disassemble and generate assembly output for the DEX file.
public Method getDecompiledMethodTree(java.lang.String partial_sig)
Get the AST root element that represents the Java code of a decompiled method.
The target method must be decompiled first; else, null will be returned.
partial_sig
- method name, original or effective, can be anything as long as it uniquely identifies a methodpublic Class getDecompiledClassTree(java.lang.String partial_sig)
Get the AST root element that represents the Java code of a decompiled class.
The target class must be decompiled first; else, null will be returned.
partial_sig
- class name, original or effective, can be anything as long as it uniquely identifies a classpublic java.lang.Object getGO()
Accessor method. Not for public use.
public java.lang.Object getD()
Accessor method. Not for public use.
public java.util.List<java.lang.Integer> listUserDataBlocks()
List the user data blocks stored in the currently opened JDB file.
public byte[] loadUserData(int id)
Retrieve a user data block stored in the JEB database.
id
- the block identifierpublic boolean storeUserData(int id, byte[] data, boolean overwrite)
Save a block of user data to the JEB database.
id
- the block identifierdata
- the data to be stored, mandatoryoverwrite
- allow block data overwriting, if the block already exists in the JDBpublic boolean removeUserData(int id)
Delete a block of user data from the JEB database.
id
- the block identifier