Rizin
unix-like reverse engineering framework and cli tools
jvm.h File Reference
#include <rz_types.h>
#include <rz_util.h>
#include "bytecode.h"

Go to the source code of this file.

Classes

struct  jvm_t
 

Typedefs

typedef struct jvm_t JavaVM
 

Functions

void bytecode_snprint (RzStrBuf *sb, Bytecode *bytecode)
 
void bytecode_clean (Bytecode *bytecode)
 
bool jvm_init (JavaVM *jvm, const ut8 *buffer, const ut32 size, ut64 pc, ut64 section)
 
bool jvm_fetch (JavaVM *jvm, Bytecode *bytecode)
 

Typedef Documentation

◆ JavaVM

typedef struct jvm_t JavaVM

Function Documentation

◆ bytecode_clean()

void bytecode_clean ( Bytecode bytecode)

Definition at line 1536 of file jvm.c.

1536  {
1537  rz_return_if_fail(bytecode);
1538  free(bytecode->extra);
1539 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
void * extra
Definition: bytecode.h:244

References bytecode_t::extra, free(), and rz_return_if_fail.

Referenced by java_analysis(), and java_disassemble().

◆ bytecode_snprint()

void bytecode_snprint ( RzStrBuf sb,
Bytecode bytecode 
)

Definition at line 1458 of file jvm.c.

1458  {
1459  rz_return_if_fail(sb && bytecode);
1460  ut64 address;
1461  if (bytecode->opcode == BYTECODE_AA_TABLESWITCH) {
1462  rz_return_if_fail(bytecode->extra);
1463  TableSwitch *ts = (TableSwitch *)bytecode->extra;
1464 
1465  address = bytecode->pc + ts->pc_default;
1466  rz_strbuf_setf(sb, "%s default: 0x%" PFMT64x, bytecode->name, address);
1467  } else if (bytecode->opcode == BYTECODE_AB_LOOKUPSWITCH) {
1468  rz_return_if_fail(bytecode->extra);
1469  LookupSwitch *ls = (LookupSwitch *)bytecode->extra;
1470 
1471  address = bytecode->pc + ls->pc_default;
1472  rz_strbuf_setf(sb, "%s default: 0x%" PFMT64x, bytecode->name, address);
1473  } else if (bytecode->type[0] > 0 && !bytecode->type[1]) {
1474  if (bytecode->type[0] == BYTECODE_TYPE_NUMBER) {
1475  rz_strbuf_setf(sb, "%s %d", bytecode->name, bytecode->args[0]);
1476  } else if (bytecode->type[0] == BYTECODE_TYPE_CONST_POOL) {
1477  rz_strbuf_setf(sb, "%s " JAVA_ASM_CONSTANT_POOL_STR "%u", bytecode->name, bytecode->args[0]);
1478  } else if (bytecode->type[0] == BYTECODE_TYPE_ADDRESS) {
1479  address = bytecode->pc + bytecode->args[0];
1480  rz_strbuf_setf(sb, "%s 0x%" PFMT64x, bytecode->name, address);
1481  } else if (bytecode->type[0] == BYTECODE_TYPE_ATYPE) {
1482  const char *type = NULL;
1483  switch (bytecode->args[0]) {
1484  case 4:
1485  type = "bool";
1486  break;
1487  case 5:
1488  type = "char";
1489  break;
1490  case 6:
1491  type = "float";
1492  break;
1493  case 7:
1494  type = "double";
1495  break;
1496  case 8:
1497  type = "byte";
1498  break;
1499  case 9:
1500  type = "short";
1501  break;
1502  case 10:
1503  type = "int";
1504  break;
1505  case 11:
1506  type = "long";
1507  break;
1508  default:
1509  break;
1510  }
1511  if (type) {
1512  rz_strbuf_setf(sb, "%s %s", bytecode->name, type);
1513  } else {
1514  rz_strbuf_setf(sb, "%s unknown_type_%u", bytecode->name, bytecode->args[0]);
1515  }
1516  } else {
1517  rz_strbuf_setf(sb, "%s %u", bytecode->name, bytecode->args[0]);
1519  }
1520  } else if (bytecode->type[0] > 0 && bytecode->type[1] > 0) {
1521  if (bytecode->type[0] == BYTECODE_TYPE_NUMBER &&
1522  bytecode->type[1] == BYTECODE_TYPE_NUMBER) {
1523  rz_strbuf_setf(sb, "%s %d %d", bytecode->name, bytecode->args[0], bytecode->args[1]);
1524  } else if (bytecode->type[0] == BYTECODE_TYPE_CONST_POOL &&
1525  bytecode->type[1] == BYTECODE_TYPE_NUMBER) {
1526  rz_strbuf_setf(sb, "%s " JAVA_ASM_CONSTANT_POOL_STR "%u %d", bytecode->name, bytecode->args[0], bytecode->args[1]);
1527  } else {
1528  rz_strbuf_setf(sb, "%s %d %d", bytecode->name, bytecode->args[0], bytecode->args[1]);
1530  }
1531  } else {
1532  rz_strbuf_setf(sb, "%s", bytecode->name);
1533  }
1534 }
static SblHeader sb
Definition: bin_mbn.c:26
#define BYTECODE_AA_TABLESWITCH
Definition: bytecode.h:178
#define BYTECODE_AB_LOOKUPSWITCH
Definition: bytecode.h:179
@ BYTECODE_TYPE_CONST_POOL
Definition: bytecode.h:217
@ BYTECODE_TYPE_ATYPE
Definition: bytecode.h:219
@ BYTECODE_TYPE_ADDRESS
Definition: bytecode.h:218
@ BYTECODE_TYPE_NUMBER
Definition: bytecode.h:216
#define JAVA_ASM_CONSTANT_POOL_STR
Definition: const.h:7
#define NULL
Definition: cris-opc.c:27
int type
Definition: mipsasm.c:17
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define PFMT64x
Definition: rz_types.h:393
ut64 pc
Definition: bytecode.h:239
char name[32]
Definition: bytecode.h:235
ut16 opcode
Definition: bytecode.h:237
ut32 type[2]
Definition: bytecode.h:241
st32 args[2]
Definition: bytecode.h:240
ut32 pc_default
Definition: bytecode.h:230
ut32 pc_default
Definition: bytecode.h:223
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References bytecode_t::args, BYTECODE_AA_TABLESWITCH, BYTECODE_AB_LOOKUPSWITCH, BYTECODE_TYPE_ADDRESS, BYTECODE_TYPE_ATYPE, BYTECODE_TYPE_CONST_POOL, BYTECODE_TYPE_NUMBER, bytecode_t::extra, JAVA_ASM_CONSTANT_POOL_STR, bytecode_t::name, NULL, bytecode_t::opcode, bytecode_t::pc, tableswitch_t::pc_default, lookupswitch_t::pc_default, PFMT64x, rz_return_if_fail, rz_strbuf_setf(), rz_warn_if_reached, sb, bytecode_t::type, type, and ut64().

Referenced by java_disassemble().

◆ jvm_fetch()

bool jvm_fetch ( JavaVM jvm,
Bytecode bytecode 
)

Definition at line 1553 of file jvm.c.

1553  {
1554  rz_return_val_if_fail(jvm && bytecode, false);
1555 
1556  return decode_instruction(jvm, bytecode);
1557 }
static bool decode_instruction(JavaVM *jvm, Bytecode *bytecode)
Definition: jvm.c:125
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

References decode_instruction(), and rz_return_val_if_fail.

Referenced by java_analysis(), and java_disassemble().

◆ jvm_init()

bool jvm_init ( JavaVM jvm,
const ut8 buffer,
const ut32  size,
ut64  pc,
ut64  section 
)

Definition at line 1541 of file jvm.c.

1541  {
1542  rz_return_val_if_fail(jvm && buffer && size > 0, false);
1543 
1544  jvm->buffer = buffer;
1545  jvm->size = size;
1546  jvm->current = 0;
1547  jvm->pc = pc;
1548  jvm->section = section;
1549 
1550  return true;
1551 }
struct buffer buffer
voidpf void uLong size
Definition: ioapi.h:138
Definition: buffer.h:15
const ut8 * buffer
Definition: jvm.h:11
ut64 pc
Definition: jvm.h:14
ut64 section
Definition: jvm.h:15
ut32 current
Definition: jvm.h:13
ut32 size
Definition: jvm.h:12

References jvm_t::buffer, jvm_t::current, jvm_t::pc, pc, rz_return_val_if_fail, jvm_t::section, and jvm_t::size.

Referenced by java_analysis(), and java_disassemble().