Compare commits
43 Commits
Author | SHA1 | Date |
---|---|---|
pancake | 9116caab2c | |
pancake | 325544a810 | |
pancake | 275e16719a | |
pancake | 56a53b96ae | |
pancake | f1d94b0e59 | |
pancake | 66edf036e6 | |
pancake | bbd430cb02 | |
Vasilyy | cbcbd5f020 | |
Sylvain Pelissier | cb53db44f0 | |
RoboSchmied | 1b82a57694 | |
Armin Weihbold | 180fea967b | |
Francesco Tamagni | fe6ab75db6 | |
Francesco Tamagni | de85a1ecf0 | |
Francesco Tamagni | 26fec0c650 | |
Francesco Tamagni | b8e7e0d583 | |
pancake | 116b4a51c1 | |
pancake | 8ab4d394a1 | |
pancake | 757cbcef2f | |
pancake | 44b6a981a3 | |
Francesco Tamagni | 685ae3272c | |
pancake | 308bfbe7ac | |
ReWithMe | 43be88e4e3 | |
Armin Weihbold | 4bf463a996 | |
astralia | 9127a15bec | |
astralia | 0b4e450875 | |
astralia | 961fe2c90c | |
Sándor Oroszi | c1aa6d41d9 | |
pancake | 1a89246567 | |
pancake | 653eb3bfbb | |
astralia | 6c97a92e1d | |
pancake | 4eedc8a548 | |
pancake | 3986df3a0b | |
pancake | 194cd870f9 | |
pancake | da7e2dc2bc | |
pancake | 148d9a301f | |
pancake | 453638891d | |
pancake | 8471613246 | |
pancake | a8f1e83152 | |
pancake | 6ab4b68013 | |
pancake | 0f93f7cb3d | |
pancake | 4b72abc8c5 | |
pancake | 41d4a03363 | |
pancake | a6752fec33 |
|
@ -29,9 +29,8 @@ jobs:
|
|||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
# Override language selection by uncommenting this and choosing your languages
|
||||
# with:
|
||||
# languages: go, javascript, csharp, python, cpp, java
|
||||
with:
|
||||
languages: c
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
|
|
|
@ -72,7 +72,7 @@ Using the `r2pm` tool you can browse and install many plugins and tools that use
|
|||
* [r2poke](https://github.com/radareorg/radare2-extras/tree/master/r2poke) Integration with GNU/Poke for extended binary parsing capabilities
|
||||
* [r2yara](https://github.com/radareorg/r2yara) Run Yara from r2 or use r2 primitives from Yara
|
||||
* [radius2](https://github.com/nowsecure/radius2): A fast symbolic execution engine based on boolector and esil
|
||||
* [r2sarif](https://github.com/radareorg/radare2-extras/tree/master/sarif/local) Run a Language Model in localhost with Llama inside r2!
|
||||
* [r2sarif](https://github.com/radareorg/radare2-extras/tree/master/sarif) import/export SARIF documents, streamlining vulnerability reporting and visualization in binaries
|
||||
|
||||
## Usage
|
||||
|
||||
|
|
15
USAGE.md
15
USAGE.md
|
@ -17,7 +17,7 @@ flags.
|
|||
|
||||
### radare2
|
||||
|
||||
```
|
||||
```sh
|
||||
r2 - # same as r2 malloc://4096; "the playground"
|
||||
r2 /bin/ls # standard way to run r2
|
||||
r2 -w ls # open in read-write
|
||||
|
@ -26,7 +26,7 @@ r2 -d ls # start debugging the ls in PATH
|
|||
|
||||
### rasm2
|
||||
|
||||
```
|
||||
```sh
|
||||
rasm2 -L # list all supported assembler/disassembler/emulator plugins
|
||||
rasm2 -a arm -b 64 'nop' # assemble a nop in 64-bit ARM
|
||||
rasm2 -d 90 # disassemble 0x90; nop, if you're using x86
|
||||
|
@ -34,13 +34,20 @@ rasm2 -d 90 # disassemble 0x90; nop, if you're using x86
|
|||
|
||||
### rabin2
|
||||
|
||||
```
|
||||
```sh
|
||||
rabin2 -s /bin/ls # list symbols in a binary
|
||||
rabin2 -z /bin/ls # find strings
|
||||
```
|
||||
|
||||
### rax2
|
||||
### rafind2
|
||||
|
||||
```sh
|
||||
rafind2 -s lib /bin/ls # search for strings matching 'lib' in /bin/ls
|
||||
```
|
||||
|
||||
### rax2
|
||||
|
||||
```sh
|
||||
rax2 '10+0x20' # compute the result
|
||||
rax2 -k 10+32 # keep the same base as input (10)
|
||||
rax2 -h # convert between (hex, octal, decimal.. bases)
|
||||
|
|
|
@ -49,7 +49,8 @@ symstall install-symlink:
|
|||
cd .. && ln -fs "${BTOP}/r2pm/r2pm" "${DESTDIR}${BINDIR}/r2pm"
|
||||
cd .. && rm -rf "${DESTDIR}${DATADIR}/radare2/${VERSION}/r2pm"
|
||||
cd .. && mkdir -p "${DESTDIR}${DATADIR}/radare2/${VERSION}/"
|
||||
-cd .. && ln -fs "${DESTDIR}${BINDIR}/radare2" "${DESTDIR}${BINDIR}/r2"
|
||||
rm -f "${DESTDIR}${BINDIR}/r2"
|
||||
-cd .. && ln -fs "${BTOP}/radare2/radare2" "${DESTDIR}${BINDIR}/r2"
|
||||
-cd .. && ln -fs "${DESTDIR}${BINDIR}/radare2" "${DESTDIR}${BINDIR}/r2p"
|
||||
-cd .. && ln -fs "${BTOP}/preload/libr2.$(EXT_SO)" "${DESTDIR}${LIBDIR}/libr2.$(EXT_SO)"
|
||||
-cd .. && cd "${DESTDIR}${LIBDIR}" && \
|
||||
|
|
|
@ -18,6 +18,7 @@ endif
|
|||
CFLAGS:=-I$(LTOP)/include $(CFLAGS)
|
||||
|
||||
ifeq (${ANDROID},1)
|
||||
CFLAGS+=-lm
|
||||
LDFLAGS+=-lm
|
||||
else
|
||||
ifneq (${OSTYPE},linux)
|
||||
|
|
|
@ -186,6 +186,7 @@ crypto.rot
|
|||
crypto.serpent
|
||||
crypto.sm4
|
||||
crypto.xor
|
||||
crypto.strhash
|
||||
debug.bf
|
||||
debug.evm
|
||||
debug.rv32ima
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
# r2pipe2
|
||||
|
||||
This document is a draft for the RFC to redesign the r2pipe protocol to cope with all the current limitations. This new protocol must fullfil the following requirements:
|
||||
|
||||
* non-blocking command execution
|
||||
* capture stderr messages
|
||||
* capture logging
|
||||
* return code associated
|
||||
* extensible with metadata
|
||||
|
||||
## Proposal
|
||||
|
||||
My proposal consists in defining a new protocol based on JSON, and keep using the well known communication channels we have to send commands and receive output.
|
||||
|
||||
When connecting, the first char use to be a null byte on the current r2pipe implementation. Let's name it 'r2pipe1'. In this new protocol the first byte will be an open brace '{'. So the r2pipe1 implementations will be able to detect when they are speaking to an r2pipe2 instance and select the right version of the protocol.
|
||||
|
||||
## Handshake
|
||||
|
||||
This is a sample communication of this hipothethic r2pipe2 protocol:
|
||||
|
||||
>>>>>>>
|
||||
```json
|
||||
{
|
||||
"protocol": "r2pipe",
|
||||
"version": "2.0"
|
||||
}
|
||||
```
|
||||
|
||||
<<<<<<
|
||||
```json
|
||||
{
|
||||
"protocol": "r2pipe",
|
||||
"peer": {
|
||||
"name": "radare2"
|
||||
"version": "5.9.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Running commands
|
||||
|
||||
>>>>>>>
|
||||
```json
|
||||
{
|
||||
"command": "ij",
|
||||
"expect": "text/json",
|
||||
"seqid": 1,
|
||||
}
|
||||
```
|
||||
|
||||
Note that the client requested a json response, so the output is embedded inside the returned document instead of handling it as a string.
|
||||
|
||||
The sequence id can be used when running commands in background, this way we can keep track of which is the response of the execution of a command without having to block the client or even execute many commands and wait for them.
|
||||
|
||||
<<<<<<
|
||||
```json
|
||||
{
|
||||
"responses": [{
|
||||
"seqid": 1,
|
||||
"command": "ij",
|
||||
"time": 3824,
|
||||
"logs: "",
|
||||
"stderr": "invalid file",
|
||||
"output": {
|
||||
"core": {
|
||||
"type":"Executable file",
|
||||
"file":"/bin/ls",
|
||||
"fd":4,
|
||||
"size":9488
|
||||
}, "bin":{
|
||||
"arch":"arm",
|
||||
"baddr":4294967296,
|
||||
"binsz":88816,
|
||||
"bintype":"mach0",
|
||||
"bits":64,"canary":true
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
--pancake
|
|
@ -13,6 +13,7 @@ _rax2() {
|
|||
'-F[stdin slurp C hex ; rax2 -F < shellcode.c]'
|
||||
'-h[help ; rax2 -h]'
|
||||
'-i[dump as C array ; rax2 -i < bytes]'
|
||||
'-j[json format output; rax2 -j 0x1234]'
|
||||
'-k[keep base ; rax2 -k 33+3 -> 36]'
|
||||
'-K[randomart ; rax2 -K 0x34 1020304050]'
|
||||
'-L[bin -> hex ; rax2 -L 1111111]'
|
||||
|
|
|
@ -1046,8 +1046,8 @@ do_decl:
|
|||
}
|
||||
lbit_pos = 0;
|
||||
// FIXME: Here it handles bitfields only in a way
|
||||
// of the same endianess as the host system (this code was compiled for)
|
||||
// It should depend on the endianess of the `asm.arch` instead.
|
||||
// of the same endianness as the host system (this code was compiled for)
|
||||
// It should depend on the endianness of the `asm.arch` instead.
|
||||
if (bit_size >= 0) {
|
||||
bt = type1.t & VT_BTYPE;
|
||||
if (bt != VT_INT8 &&
|
||||
|
|
|
@ -74,6 +74,7 @@ R_API RAnalOp *r_anal_op_clone(RAnalOp *op) {
|
|||
}
|
||||
|
||||
|
||||
#if 0
|
||||
R_API RList *r_anal_op_list_new(void) {
|
||||
RList *list = r_list_new ();
|
||||
if (list) {
|
||||
|
@ -81,6 +82,7 @@ R_API RList *r_anal_op_list_new(void) {
|
|||
}
|
||||
return list;
|
||||
}
|
||||
#endif
|
||||
|
||||
R_API void r_anal_op_init(RAnalOp *op) {
|
||||
if (op) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare2 - BSD - Copyright 2017-2022 - pancake */
|
||||
/* radare2 - BSD - Copyright 2017-2024 - pancake */
|
||||
|
||||
#include <r_arch.h>
|
||||
#include <r_lib.h>
|
||||
|
|
|
@ -157,7 +157,7 @@ char *pic_pic18_disassemble(const ut8 *b, int blen, int *opsz) {
|
|||
{
|
||||
ut32 dword_instr = *(ut32 *)b;
|
||||
//I dont even know how the bits are arranged but it works !!!
|
||||
//`the wierdness of little endianess`
|
||||
//`the wierdness of little endianness`
|
||||
if (dword_instr >> 28 != 0xf) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -2110,7 +2110,7 @@ static const ut8 *parse_attr_value(RBin *bin, const ut8 *obuf, int obuf_len, RBi
|
|||
value->address = READ16 (buf);
|
||||
break;
|
||||
case DW_FORM_addrx3:
|
||||
// I need to add 3byte endianess free read here TODO
|
||||
// I need to add 3byte endianness free read here TODO
|
||||
value->kind = DW_AT_KIND_ADDRESS;
|
||||
buf += 3;
|
||||
break;
|
||||
|
|
|
@ -134,12 +134,10 @@ static bool __is_valid_ident(ut8 *e_ident) {
|
|||
}
|
||||
|
||||
static bool init_ehdr(ELFOBJ *eo) {
|
||||
ut8 *e_ident;
|
||||
ut8 ehdr[sizeof (Elf_(Ehdr))] = {0};
|
||||
int i, len;
|
||||
|
||||
e_ident = (ut8*)&eo->ehdr.e_ident;
|
||||
int i;
|
||||
|
||||
ut8 *e_ident = (ut8*)&eo->ehdr.e_ident;
|
||||
if (r_buf_read_at (eo->b, 0, e_ident, EI_NIDENT) != EI_NIDENT) {
|
||||
R_LOG_DEBUG ("read (magic)");
|
||||
return false;
|
||||
|
@ -151,7 +149,7 @@ static bool init_ehdr(ELFOBJ *eo) {
|
|||
|
||||
eo->endian = (e_ident[EI_DATA] == ELFDATA2MSB)? 1: 0;
|
||||
|
||||
len = r_buf_read_at (eo->b, 0, ehdr, sizeof (ehdr));
|
||||
int len = r_buf_read_at (eo->b, 0, ehdr, sizeof (ehdr));
|
||||
if (len < 32) { // tinyelf != sizeof (Elf_(Ehdr))) {
|
||||
R_LOG_DEBUG ("read (ehdr)");
|
||||
return false;
|
||||
|
@ -244,7 +242,6 @@ static bool read_phdr(ELFOBJ *eo) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!load_header_found) {
|
||||
const ut64 load_addr = Elf_(get_baddr) (eo);
|
||||
eo->ehdr.e_phoff = Elf_(v2p) (eo, load_addr + eo->ehdr.e_phoff);
|
||||
|
@ -5179,6 +5176,18 @@ typedef struct {
|
|||
ut64 plt_va;
|
||||
} GotPltBounds;
|
||||
|
||||
static bool is_important(RBinElfReloc *reloc) {
|
||||
switch (reloc->type) {
|
||||
case 21:
|
||||
case 22:
|
||||
case 1026:
|
||||
return true;
|
||||
}
|
||||
|
||||
R_LOG_DEBUG ("Reloc type %d not used for imports", reloc->type);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool reloc_fill_local_address(ELFOBJ *eo) {
|
||||
RBinElfReloc *reloc;
|
||||
GotPltBounds ri = {0};
|
||||
|
@ -5225,8 +5234,7 @@ static bool reloc_fill_local_address(ELFOBJ *eo) {
|
|||
r_buf_read_at (eo->b, rvaddr, (ut8*)&n32, 4);
|
||||
pltptr = n32;
|
||||
#endif
|
||||
bool ismagic = (reloc->type == 21 || reloc->type == 22);
|
||||
// if (pltptr && pltptr != -1 && ismagic) {
|
||||
bool ismagic = is_important (reloc);
|
||||
if (ismagic) {
|
||||
// text goes after the plt. so its possible that some symbols are pointed locally, thats all lsym is about
|
||||
if (pltptr > baddr) {
|
||||
|
@ -5246,6 +5254,9 @@ static bool reloc_fill_local_address(ELFOBJ *eo) {
|
|||
#endif
|
||||
// TODO: if (reloc->type == 22) { // on arm! // extra check of bounds
|
||||
ut64 naddr = baddr + pltptr + (index * 12) + 0x20;
|
||||
if (reloc->type == 1026) {
|
||||
naddr = baddr + pltptr + (index * 16) + 64 - 16;
|
||||
}
|
||||
if (naddr != UT64_MAX) {
|
||||
// this thing registers an 'rsym.${importname}' as a flag when loading the relocs from core/cbin.c
|
||||
reloc->laddr = naddr;
|
||||
|
|
|
@ -436,16 +436,33 @@ R_IPI RList *r_bin_le_get_sections(RBinLEObj *bin) {
|
|||
s->paddr = ((ut64)page.offset << pageshift) + pages_start_off;
|
||||
}
|
||||
}
|
||||
s->vsize = h->pagesize;
|
||||
s->vsize = R_MIN (h->pagesize, sec->vsize - page_size_sum);
|
||||
s->vaddr = sec->vaddr + page_size_sum;
|
||||
s->perm = sec->perm;
|
||||
s->size = page.size;
|
||||
s->size = R_MIN (page.size, s->vsize);
|
||||
s->add = true;
|
||||
s->bits = sec->bits;
|
||||
r_list_append (l, s);
|
||||
page_size_sum += s->vsize;
|
||||
}
|
||||
if (entry->page_tbl_entries) {
|
||||
if (page_size_sum < sec->vsize) {
|
||||
RBinSection *s = R_NEW0 (RBinSection);
|
||||
if (!s) {
|
||||
r_bin_section_free (sec);
|
||||
return l;
|
||||
}
|
||||
ut64 remainder_size = sec->vsize - page_size_sum;
|
||||
s->vsize = remainder_size;
|
||||
s->vaddr = sec->vaddr + page_size_sum;
|
||||
s->perm = sec->perm;
|
||||
s->size = 0;
|
||||
s->add = true;
|
||||
s->bits = sec->bits;
|
||||
s->name = r_str_newf ("%s.page.zerofill", sec->name);
|
||||
s->is_data = sec->is_data;
|
||||
r_list_append (l, s);
|
||||
}
|
||||
r_bin_section_free (sec);
|
||||
}
|
||||
}
|
||||
|
@ -517,16 +534,13 @@ R_IPI RList *r_bin_le_get_relocs(RBinLEObj *bin) {
|
|||
break;
|
||||
}
|
||||
ut64 repeat = 0;
|
||||
ut64 source = 0;
|
||||
st16 source = 0;
|
||||
if (header.source & F_SOURCE_LIST) {
|
||||
repeat = r_buf_read8_at (bin->buf, offset);
|
||||
offset += sizeof (ut8);
|
||||
} else {
|
||||
source = r_buf_read_ble16_at (bin->buf, offset, h->worder);
|
||||
if (source == UT16_MAX) {
|
||||
break;
|
||||
}
|
||||
offset += sizeof (ut16);
|
||||
offset += sizeof (st16);
|
||||
}
|
||||
ut32 ordinal;
|
||||
if (header.target & F_TARGET_ORD16) {
|
||||
|
@ -618,14 +632,19 @@ R_IPI RList *r_bin_le_get_relocs(RBinLEObj *bin) {
|
|||
}
|
||||
rel->addend += additive;
|
||||
}
|
||||
if (!repeat) {
|
||||
rel->vaddr = cur_page_offset + source;
|
||||
rel->paddr = cur_section ? cur_section->paddr + source : 0;
|
||||
if (!repeat && source >= 0) {
|
||||
/* Negative source means we already handled the cross-page
|
||||
* fixup in the previous page, so there's no need to dupe it
|
||||
*/
|
||||
rel->vaddr = cur_page_offset + (st64) source;
|
||||
rel->paddr = cur_section ? cur_section->paddr + (st64) source : 0;
|
||||
r_list_append (l, rel);
|
||||
rel_appended = true;
|
||||
}
|
||||
|
||||
if (header.target & F_TARGET_CHAIN) {
|
||||
// TODO: add tests for this case
|
||||
ut64 source = 0;
|
||||
ut32 fixupinfo = r_buf_read_ble32_at (bin->buf, cur_page_offset + source, h->worder);
|
||||
ut64 base_target_address = rel->addend - (fixupinfo & 0xFFFFF);
|
||||
do {
|
||||
|
|
|
@ -4491,7 +4491,7 @@ static void walk_codesig(RBinFile *bf, ut32 addr, ut32 size) {
|
|||
cb_printf = printf;
|
||||
}
|
||||
struct MACH0_(obj_t) *bo = bf->bo->bin_obj;
|
||||
SuperBlob sb;
|
||||
SuperBlob sb = {0};
|
||||
if (r_buf_fread_at (bo->b, addr, (ut8*)&sb, "3I", 1) != -1) {
|
||||
cb_printf ("0x%08"PFMT64x" superblob.magic = 0x%08x\n", (ut64)addr, sb.magic);
|
||||
cb_printf ("0x%08"PFMT64x" superblob.length = 0x%08x\n", (ut64)addr + 4, sb.length);
|
||||
|
|
|
@ -251,6 +251,14 @@ typedef struct {
|
|||
uint32_t pad;
|
||||
} cache_img_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
uint32_t page_size;
|
||||
uint32_t page_starts_count;
|
||||
uint32_t padding;
|
||||
uint64_t value_add;
|
||||
} cache_slide5_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
uint32_t page_size;
|
||||
|
|
|
@ -75,7 +75,11 @@ static void demangle_freepascal_unit(RStrBuf *ds, char *mangled, size_t mangled_
|
|||
r_strbuf_append_n (ds, mangled, end - mangled);
|
||||
}
|
||||
} else {
|
||||
r_strbuf_append_n (ds, mangled, end - mangled);
|
||||
if (end > mangled) {
|
||||
r_strbuf_append_n (ds, mangled, end - mangled);
|
||||
} else {
|
||||
// should never happen
|
||||
}
|
||||
}
|
||||
} else {
|
||||
r_strbuf_append_n (ds, mangled, mangled_len);
|
||||
|
|
|
@ -1216,7 +1216,7 @@ static RList* fields(RBinFile *bf) {
|
|||
addr += 0x4;
|
||||
|
||||
if (r_buf_read8_at (bf->buf, 0x04) == 1) {
|
||||
ROW ("Entry point", 4, r_buf_read_le32_at (bf->buf, addr), "x", NULL);
|
||||
ROW ("EntryPoint", 4, r_buf_read_le32_at (bf->buf, addr), "x", NULL);
|
||||
addr += 0x4;
|
||||
ROW ("PhOff", 4, r_buf_read_le32_at (bf->buf, addr), "x", NULL);
|
||||
addr += 0x4;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2013-2022 - pancake */
|
||||
/* radare - LGPL - Copyright 2013-2024 - pancake */
|
||||
|
||||
#include <r_cons.h>
|
||||
#include <r_util/r_assert.h>
|
||||
|
|
|
@ -1508,6 +1508,9 @@ now the console color is reset with each \n (same stuff do it here but in correc
|
|||
// XXX this function is a huge bottleneck
|
||||
R_API int r_cons_get_cursor(int *rows) {
|
||||
// This implementation is very slow
|
||||
if (rows) {
|
||||
*rows = 0;
|
||||
}
|
||||
return 0;
|
||||
#if 0
|
||||
RConsContext *c = C;
|
||||
|
@ -2257,7 +2260,7 @@ R_API void r_cons_mark(ut64 addr, const char *name) {
|
|||
if (mark) {
|
||||
RConsContext *ctx = getctx ();
|
||||
mark->addr = addr;
|
||||
int row, col = r_cons_get_cursor (&row);
|
||||
int row = 0, col = r_cons_get_cursor (&row);
|
||||
mark->name = strdup (name); // TODO. use a const pool
|
||||
mark->pos = ctx->buffer_len;
|
||||
mark->col = col;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2009-2023 - pancake, nibble */
|
||||
/* radare - LGPL - Copyright 2009-2024 - pancake, nibble */
|
||||
|
||||
#include <r_cons.h>
|
||||
#include <r_util/r_print.h>
|
||||
|
@ -502,9 +502,10 @@ static int cmp(const void *a, const void *b) {
|
|||
a = ca;
|
||||
b = cb;
|
||||
}
|
||||
int res = strcmp (a, b);
|
||||
free (da);
|
||||
free (db);
|
||||
return strcmp (a, b);
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool gron(RStrBuf *sb, RJson *node, const char *root) {
|
||||
|
|
|
@ -3077,22 +3077,22 @@ static bool bin_sections(RCore *r, PJ *pj, int mode, ut64 laddr, int va, ut64 at
|
|||
r_list_foreach (sections, iter, section) {
|
||||
char perms[] = "----";
|
||||
int va_sect = va;
|
||||
ut64 addr;
|
||||
ut64 addr, size;
|
||||
|
||||
if (va && !(section->perm & R_PERM_R)) {
|
||||
va_sect = VA_NOREBASE;
|
||||
}
|
||||
addr = rva (r->bin, section->paddr, section->vaddr, va_sect);
|
||||
|
||||
size = va ? section->vsize : section->size;
|
||||
if (name && strcmp (section->name, name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (printHere && !(addr <= r->offset && r->offset < (addr + section->size))) {
|
||||
if (printHere && !(addr <= r->offset && r->offset < (addr + size))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (at != UT64_MAX && (!section->size || !is_in_range (at, addr, section->size))) {
|
||||
if (at != UT64_MAX && (!size || !is_in_range (at, addr, size))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -3160,7 +3160,7 @@ static bool bin_sections(RCore *r, PJ *pj, int mode, ut64 laddr, int va, ut64 at
|
|||
str = r_str_newf ("%s.%s", type, section->name);
|
||||
}
|
||||
r_name_filter (str, R_FLAG_NAME_SIZE);
|
||||
ut64 size = r->io->va? section->vsize: section->size;
|
||||
|
||||
r_flag_set (r->flags, str, addr, size);
|
||||
R_FREE (str);
|
||||
|
||||
|
|
|
@ -3556,7 +3556,7 @@ R_API int r_core_config_init(RCore *core) {
|
|||
r_config_set_getter (cfg, "arch.bits", (RConfigCallback)cb_archbits_getter);
|
||||
SETCB ("arch.platform", "", &cb_arch_platform, "define arch platform to use");
|
||||
n = NODECB ("arch.endian", R_SYS_ENDIAN? "big": "little", &cb_archendian);
|
||||
SETDESC (n, "set arch endianess");
|
||||
SETDESC (n, "set arch endianness");
|
||||
SETOPTIONS (n, "big", "little", "bigswap", "littleswap", NULL);
|
||||
n = NODECB ("arch.arch", "null", &cb_archarch);
|
||||
SETDESC (n, "select the architecture to use");
|
||||
|
|
|
@ -260,7 +260,8 @@ static const RCoreHelpMessage help_msg_equalg = {
|
|||
|
||||
static const RCoreHelpMessage help_msg_b = {
|
||||
"Usage:", "b[f] [arg]\n", "Get/Set block size",
|
||||
"b", " 33", "set block size to 33",
|
||||
"b", " 32", "set block size to 33",
|
||||
"b", "=32", "same as 'b 32'",
|
||||
"b", " eip+4", "numeric argument can be an expression",
|
||||
"b", "", "display current block size",
|
||||
"b", "+3", "increase blocksize by 3",
|
||||
|
@ -2676,8 +2677,9 @@ static int cmd_bsize(void *data, const char *input) {
|
|||
case '\0': // "b"
|
||||
r_cons_printf ("0x%x\n", core->blocksize);
|
||||
break;
|
||||
case '=':
|
||||
case ' ':
|
||||
r_core_block_size (core, r_num_math (core->num, input));
|
||||
r_core_block_size (core, r_num_math (core->num, input + 1));
|
||||
break;
|
||||
default:
|
||||
case '?': // "b?"
|
||||
|
|
|
@ -12261,7 +12261,7 @@ static void cmd_anal_graph(RCore *core, const char *input) {
|
|||
{
|
||||
core->graph->is_callgraph = true;
|
||||
r_core_cmdf (core, "ag-;.agR*;");
|
||||
r_core_agraph_print(core, -1, input + 1);
|
||||
r_core_agraph_print (core, -1, input + 1);
|
||||
core->graph->is_callgraph = false;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -265,7 +265,7 @@ static RCoreHelpMessage help_msg_question_e = {
|
|||
"?eg", " 10 20", "move cursor to column 10, row 20",
|
||||
"?ef", " text", "echo text with thin ascii art frame around",
|
||||
"?en", " nonl", "echo message without ending newline",
|
||||
"?ep", " 10 20 30", "draw a pie char with given portion sizes",
|
||||
"?ep", " 10 20,ten twe", "render pie chart with portions and (e hex.cols for size)",
|
||||
"?es", " msg", "speak message using the text-to-speech program (e cfg.tts)",
|
||||
"?et", " msg", "change terminal title",
|
||||
NULL
|
||||
|
@ -1337,17 +1337,36 @@ static int cmd_help(void *data, const char *input) {
|
|||
break;
|
||||
case 'p':
|
||||
{
|
||||
char *word, *str = strdup (input + 2);
|
||||
char *word, *str = strdup (r_str_trim_head_ro (input + 2));
|
||||
char *legend = strchr (str, ',');
|
||||
RList *llist = NULL;
|
||||
if (legend) {
|
||||
*legend = 0;
|
||||
r_str_trim (legend + 1);
|
||||
llist = r_str_split_list (strdup (legend + 1), " ", 0);
|
||||
}
|
||||
r_str_trim (str);
|
||||
RList *list = r_str_split_list (str, " ", 0);
|
||||
ut64 *nums = calloc (sizeof (ut64), r_list_length (list));
|
||||
int *nums = calloc (sizeof (ut64), r_list_length (list));
|
||||
char **text = calloc (sizeof (char *), r_list_length (list));
|
||||
int i = 0;
|
||||
r_list_foreach (list, iter, word) {
|
||||
nums[i] = r_num_math (core->num, word);
|
||||
i++;
|
||||
}
|
||||
int j = 0;
|
||||
r_list_foreach (llist, iter, word) {
|
||||
if (j >= i) {
|
||||
break;
|
||||
}
|
||||
text[j] = word;
|
||||
j++;
|
||||
}
|
||||
int size = r_config_get_i (core->config, "hex.cols");
|
||||
r_print_pie (core->print, nums, r_list_length (list), size);
|
||||
r_print_pie (core->print, r_list_length (list), nums, (const char**)text, size);
|
||||
free (text);
|
||||
r_list_free (list);
|
||||
r_list_free (llist);
|
||||
}
|
||||
break;
|
||||
case ' ': {
|
||||
|
|
|
@ -605,7 +605,17 @@ static int cmd_meta_comment(RCore *core, const char *input) {
|
|||
case '+':
|
||||
case ' ':
|
||||
{
|
||||
const char *newcomment = r_str_trim_head_ro (input + 2);
|
||||
const char *arg = r_str_trim_head_ro (input + 2);
|
||||
const char *newcomment = arg;
|
||||
if (r_str_startswith (arg, "base64:")) {
|
||||
char *s = (char *)sdb_decode (arg + 7, NULL);
|
||||
if (s) {
|
||||
newcomment = s;
|
||||
} else {
|
||||
R_LOG_ERROR ("Invalid base64 string");
|
||||
break;
|
||||
}
|
||||
}
|
||||
const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr);
|
||||
char *text;
|
||||
char *nc = strdup (newcomment);
|
||||
|
@ -655,7 +665,7 @@ static int cmd_meta_comment(RCore *core, const char *input) {
|
|||
char *newcomment;
|
||||
const char *arg = input + 2;
|
||||
while (*arg && *arg == ' ') arg++;
|
||||
if (!strncmp (arg, "base64:", 7)) {
|
||||
if (r_str_startswith (arg, "base64:")) {
|
||||
char *s = (char *)sdb_decode (arg + 7, NULL);
|
||||
if (s) {
|
||||
newcomment = s;
|
||||
|
|
|
@ -1442,6 +1442,7 @@ R_API void r_core_file_reopen_remote_debug(RCore *core, char *uri, ut64 addr) {
|
|||
return;
|
||||
}
|
||||
|
||||
core->dbg->main_arena_resolved = false;
|
||||
RList *old_sections = __save_old_sections (core);
|
||||
ut64 old_base = core->bin->cur->bo->baddr_shift;
|
||||
int bits = core->rasm->config->bits;
|
||||
|
@ -1512,6 +1513,7 @@ R_API void r_core_file_reopen_debug(RCore *core, const char *args) {
|
|||
return;
|
||||
}
|
||||
|
||||
core->dbg->main_arena_resolved = false;
|
||||
RList *old_sections = __save_old_sections (core);
|
||||
ut64 old_base = (core->bin->cur && core->bin->cur->bo)? core->bin->cur->bo->baddr_shift: 0;
|
||||
int bits = core->rasm->config->bits;
|
||||
|
|
|
@ -459,12 +459,12 @@ static RCoreHelpMessage help_msg_piE = {
|
|||
"Usage:", "piE[q]", " # print esil of N bytes",
|
||||
"piE", "", "print esil of the instructions found in N bytes",
|
||||
"piEq", "", "same as above but without displaying the instruction address",
|
||||
// "piej", "", "same but in JSON format",
|
||||
// "piEj", "", "same but in JSON format",
|
||||
NULL
|
||||
};
|
||||
|
||||
static RCoreHelpMessage help_msg_pie = {
|
||||
"Usage:", "pie[fq]", " # print esil of N instructions",
|
||||
"Usage:", "pie[bqf]", " # print esil of N instructions",
|
||||
"pie", "", "print esil of N instructions",
|
||||
"pieb", "", "alias for `pie $Fi`",
|
||||
"pieq", "", "same as above but hiding the offset",
|
||||
|
@ -5608,8 +5608,6 @@ static bool cmd_pi(RCore *core, const char *input, int len, int l, ut8 *block) {
|
|||
return false;
|
||||
}
|
||||
|
||||
#include "esil2c.c"
|
||||
|
||||
static void core_print_decompile(RCore *core, const char *input) {
|
||||
int i, count = r_num_get (core->num, input);
|
||||
if (count < 1) {
|
||||
|
@ -5617,11 +5615,8 @@ static void core_print_decompile(RCore *core, const char *input) {
|
|||
}
|
||||
ut64 addr = core->offset;
|
||||
int minopsize = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE);
|
||||
int bits = r_config_get_i (core->config, "asm.bits");
|
||||
int ss = 16 * 1024;
|
||||
REsil *esil = r_esil_new (ss, 0, bits);
|
||||
// r_esil_setup (esil, core->anal, true, 0, 0);
|
||||
esil2c_setup (core, esil);
|
||||
const int bits = r_config_get_i (core->config, "asm.bits");
|
||||
REsilC *ec = r_esil_toc_new (core->anal, bits);
|
||||
for (i = 0; i < count; i++) {
|
||||
RAnalOp *op = r_core_anal_op (core, addr, R_ARCH_OP_MASK_BASIC | R_ARCH_OP_MASK_ESIL);
|
||||
if (!op) {
|
||||
|
@ -5629,9 +5624,9 @@ static void core_print_decompile(RCore *core, const char *input) {
|
|||
continue;
|
||||
}
|
||||
const char *es = R_STRBUF_SAFEGET (&op->esil);
|
||||
r_esil_set_pc (esil, addr);
|
||||
r_esil_set_pc (ec->esil, addr);
|
||||
r_cons_printf ("addr_0x%08"PFMT64x"_0: // %s\n", addr, es);
|
||||
char *cstr = esil2c (core, esil, es);
|
||||
char *cstr = r_esil_toc (ec, es);
|
||||
if (cstr) {
|
||||
r_cons_printf ("%s", cstr);
|
||||
free (cstr);
|
||||
|
@ -5639,9 +5634,7 @@ static void core_print_decompile(RCore *core, const char *input) {
|
|||
addr += (op->size > 0)? op->size: minopsize;
|
||||
r_anal_op_free (op);
|
||||
}
|
||||
esil2c_free (esil->user);
|
||||
esil->user = NULL;
|
||||
r_esil_free (esil);
|
||||
r_esil_toc_free (ec);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -549,6 +549,7 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) {
|
|||
RBinSection *s;
|
||||
RAnalOp op;
|
||||
ut64 ret = 0;
|
||||
r_anal_op_init (&op);
|
||||
|
||||
if (ok) {
|
||||
*ok = false;
|
||||
|
|
|
@ -300,7 +300,7 @@ static GHT GH(tcache_chunk_size)(RCore *core, GHT brk_start) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void GH(update_arena_with_tc)(GH(RHeap_MallocState_tcache) *cmain_arena, MallocState *main_arena) {
|
||||
static void GH(update_arena_with_tc)(GH(RHeap_MallocState_227) *cmain_arena, MallocState *main_arena) {
|
||||
int i = 0;
|
||||
main_arena->mutex = cmain_arena->mutex;
|
||||
main_arena->flags = cmain_arena->flags;
|
||||
|
@ -323,7 +323,7 @@ static void GH(update_arena_with_tc)(GH(RHeap_MallocState_tcache) *cmain_arena,
|
|||
main_arena->GH(max_system_mem) = cmain_arena->max_system_mem;
|
||||
}
|
||||
|
||||
static void GH(update_arena_without_tc)(GH(RHeap_MallocState) *cmain_arena, MallocState *main_arena) {
|
||||
static void GH(update_arena_without_tc)(GH(RHeap_MallocState_223) *cmain_arena, MallocState *main_arena) {
|
||||
size_t i = 0;
|
||||
main_arena->mutex = cmain_arena->mutex;
|
||||
main_arena->flags = cmain_arena->flags;
|
||||
|
@ -348,18 +348,18 @@ static void GH(update_arena_without_tc)(GH(RHeap_MallocState) *cmain_arena, Mall
|
|||
static bool GH(update_main_arena)(RCore *core, GHT m_arena, MallocState *main_arena) {
|
||||
const bool tcache = r_config_get_b (core->config, "dbg.glibc.tcache");
|
||||
if (tcache) {
|
||||
GH(RHeap_MallocState_tcache) *cmain_arena = R_NEW0 (GH(RHeap_MallocState_tcache));
|
||||
GH(RHeap_MallocState_227) *cmain_arena = R_NEW0 (GH(RHeap_MallocState_227));
|
||||
if (!cmain_arena) {
|
||||
return false;
|
||||
}
|
||||
(void)r_io_read_at (core->io, m_arena, (ut8 *)cmain_arena, sizeof (GH(RHeap_MallocState_tcache)));
|
||||
(void)r_io_read_at (core->io, m_arena, (ut8 *)cmain_arena, sizeof (GH(RHeap_MallocState_227)));
|
||||
GH(update_arena_with_tc)(cmain_arena, main_arena);
|
||||
} else {
|
||||
GH(RHeap_MallocState) *cmain_arena = R_NEW0 (GH(RHeap_MallocState));
|
||||
GH(RHeap_MallocState_223) *cmain_arena = R_NEW0 (GH(RHeap_MallocState_223));
|
||||
if (!cmain_arena) {
|
||||
return false;
|
||||
}
|
||||
(void)r_io_read_at (core->io, m_arena, (ut8 *)cmain_arena, sizeof (GH(RHeap_MallocState)));
|
||||
(void)r_io_read_at (core->io, m_arena, (ut8 *)cmain_arena, sizeof (GH(RHeap_MallocState_223)));
|
||||
GH(update_arena_without_tc)(cmain_arena, main_arena);
|
||||
}
|
||||
return true;
|
||||
|
@ -548,6 +548,21 @@ static void GH(print_arena_stats)(RCore *core, GHT m_arena, MallocState *main_ar
|
|||
PRINT_GA ("}\n\n");
|
||||
}
|
||||
|
||||
typedef struct GH(expected_arenas) {
|
||||
GH(RHeap_MallocState_227) expected_227;
|
||||
GH(RHeap_MallocState_223) expected_223;
|
||||
GH(RHeap_MallocState_212) expected_212;
|
||||
} GH(expected_arenas_s);
|
||||
|
||||
static GH(expected_arenas_s) GH (get_expected_main_arena_structures ) (RCore *core, GHT addend) {
|
||||
GH(expected_arenas_s) expected_arenas = {
|
||||
.expected_227 = {.next = addend, .attached_threads = 1},
|
||||
.expected_223 = {.next = addend, .attached_threads = 1},
|
||||
.expected_212 = {.next = addend}
|
||||
};
|
||||
return expected_arenas;
|
||||
}
|
||||
|
||||
static GHT GH (get_main_arena_offset_with_relocs) (RCore *core, const char *libc_path) {
|
||||
RBin *bin = core->bin;
|
||||
RBinFile *bf = r_bin_cur (bin);
|
||||
|
@ -565,7 +580,7 @@ static GHT GH (get_main_arena_offset_with_relocs) (RCore *core, const char *libc
|
|||
}
|
||||
|
||||
// Get .data section to limit search
|
||||
RList* section_list = r_bin_get_sections (bin);
|
||||
RList *section_list = r_bin_get_sections(bin);
|
||||
RListIter *iter;
|
||||
RBinSection *section;
|
||||
RBinSection *data_section = NULL;
|
||||
|
@ -579,32 +594,58 @@ static GHT GH (get_main_arena_offset_with_relocs) (RCore *core, const char *libc
|
|||
R_LOG_WARN ("get_main_arena_with_relocs: Failed to find .data section in %s", libc_path);
|
||||
return GHT_MAX;
|
||||
}
|
||||
GH(section_content) libc_data = GH (get_section_content) (core, libc_path, ".data");
|
||||
GH(section_content) libc_data = GH (get_section_content)(core, libc_path, ".data");
|
||||
|
||||
// TODO: switch for version, this is valid for >= 2.27 malloc_state
|
||||
GHT next_field_offset = offsetof(GH(RHeap_MallocState_tcache), next);
|
||||
GHT malloc_state_size = sizeof (GH(RHeap_MallocState_tcache));
|
||||
if (!core->dbg->glibc_version_resolved && !GH (resolve_glibc_version)(core)) {
|
||||
R_LOG_WARN("get_main_arena_offset_with_relocs: glibc_version could not be resolved");
|
||||
return GHT_MAX;
|
||||
}
|
||||
GHT next_field_offset = GHT_MAX;
|
||||
GHT malloc_state_size = GHT_MAX;
|
||||
|
||||
if (core->dbg->glibc_version_d >= 2.27) {
|
||||
next_field_offset = offsetof (GH(RHeap_MallocState_227), next);
|
||||
malloc_state_size = sizeof (GH(RHeap_MallocState_227));
|
||||
} else if (core->dbg->glibc_version_d >= 2.23) {
|
||||
next_field_offset = offsetof (GH(RHeap_MallocState_223), next);
|
||||
malloc_state_size = sizeof (GH(RHeap_MallocState_223));
|
||||
} else if (core->dbg->glibc_version_d >= 2.12) {
|
||||
next_field_offset = offsetof (GH(RHeap_MallocState_212), next);
|
||||
malloc_state_size = sizeof (GH(RHeap_MallocState_212));
|
||||
} else {
|
||||
R_LOG_WARN ("get_main_arena_offset_with_relocs: cannot handle glibc version %.2f", core->dbg->glibc_version_d);
|
||||
return GHT_MAX;
|
||||
}
|
||||
|
||||
// Iterate over relocations and look for malloc_state structure
|
||||
RRBNode *node;
|
||||
RBinReloc *reloc;
|
||||
RHeap_MallocState_tcache_64 expected;
|
||||
|
||||
r_crbtree_foreach (relocs, node, RBinReloc, reloc) {
|
||||
// We only care about relocations in .data section
|
||||
if (reloc->vaddr - next_field_offset < data_section->vaddr ||
|
||||
reloc->vaddr > data_section->vaddr + data_section->size)
|
||||
continue;
|
||||
//eprintf("vaddr: %p addend: %p \n", reloc->vaddr, reloc->addend);
|
||||
// If reloc->addend is the offset of main_arena, then reloc->vaddr should be the offset of main_arena.next
|
||||
if (reloc->vaddr - next_field_offset == reloc->addend) {
|
||||
//eprintf("candidate found\n");
|
||||
// Candidate found, to be sure compare data with expected malloc_state
|
||||
GHT search_start = reloc->addend - data_section->vaddr;
|
||||
expected.next = reloc->addend;
|
||||
if (memcmp (libc_data.buf + search_start, &expected, malloc_state_size)) {
|
||||
GH(expected_arenas_s) expected_arenas = GH(get_expected_main_arena_structures) (core, reloc->addend);
|
||||
void *expected_p = NULL;
|
||||
|
||||
if (core->dbg->glibc_version_d >= 2.27) {
|
||||
expected_p = (void *)&expected_arenas.expected_227;
|
||||
} else if (core->dbg->glibc_version_d >= 2.23) {
|
||||
expected_p = (void *)&expected_arenas.expected_223;
|
||||
} else if (core->dbg->glibc_version_d >= 2.12) {
|
||||
expected_p = (void *)&expected_arenas.expected_212;
|
||||
} // else checked above
|
||||
if (!memcmp (libc_data.buf + search_start, expected_p, malloc_state_size)) {
|
||||
R_LOG_WARN ("Found main_arena offset with relocations");
|
||||
main_arena = reloc->addend - data_section->vaddr;
|
||||
break;
|
||||
} else {
|
||||
R_LOG_WARN ("get_main_arena_offset_with_relocs: main_arena candidate did not match");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1293,7 +1334,7 @@ static void GH (print_tcache_instance)(RCore *core, GHT m_arena, MallocState *ma
|
|||
PRINT_YA ("Tcache thread arena @ ");
|
||||
PRINTF_BA (" 0x%"PFMT64x, (ut64)ta->GH (next));
|
||||
mmap_start = ((ta->GH (next) >> 16) << 16);
|
||||
tcache_start = mmap_start + sizeof (GH (RHeapInfo)) + sizeof (GH (RHeap_MallocState_tcache)) + GH (MMAP_ALIGN);
|
||||
tcache_start = mmap_start + sizeof (GH (RHeapInfo)) + sizeof (GH (RHeap_MallocState_227)) + GH (MMAP_ALIGN);
|
||||
|
||||
if (!GH (update_main_arena) (core, ta->GH (next), ta)) {
|
||||
free (ta);
|
||||
|
@ -1347,10 +1388,10 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena,
|
|||
brk_start = ((m_state >> 16) << 16) ;
|
||||
brk_end = brk_start + main_arena->GH(system_mem);
|
||||
if (tcache) {
|
||||
tcache_initial_brk = brk_start + sizeof (GH(RHeapInfo)) + sizeof (GH(RHeap_MallocState_tcache)) + GH(MMAP_ALIGN);
|
||||
tcache_initial_brk = brk_start + sizeof (GH(RHeapInfo)) + sizeof (GH(RHeap_MallocState_227)) + GH(MMAP_ALIGN);
|
||||
initial_brk = tcache_initial_brk + offset;
|
||||
} else {
|
||||
initial_brk = brk_start + sizeof (GH(RHeapInfo)) + sizeof (GH(RHeap_MallocState)) + MMAP_OFFSET;
|
||||
initial_brk = brk_start + sizeof (GH(RHeapInfo)) + sizeof (GH(RHeap_MallocState_223)) + MMAP_OFFSET;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,12 @@ R_API bool r_core_hack_arm64(RCore *core, const char *op, const RAnalOp *analop)
|
|||
break;
|
||||
default:
|
||||
switch (buf[3]) {
|
||||
case 0x36: // tbz
|
||||
r_core_cmdf (core, "wx 37 @ $$+3");
|
||||
break;
|
||||
case 0x37: // tbnz
|
||||
r_core_cmdf (core, "wx 36 @ $$+3");
|
||||
break;
|
||||
case 0x34: // cbz
|
||||
case 0xb4: // cbz
|
||||
r_core_cmdf (core, "wx 35 @ $$+3");
|
||||
|
|
|
@ -105,7 +105,7 @@ R_API bool r_crypto_job_set_key(RCryptoJob *cj, const ut8* key, int keylen, int
|
|||
keylen = strlen ((const char *)key);
|
||||
}
|
||||
if (!cj->h || !cj->h->set_key) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
cj->key_len = keylen;
|
||||
cj->key = calloc (1, cj->key_len);
|
||||
|
@ -222,7 +222,7 @@ R_API void r_crypto_list(RCrypto *cry, PrintfCallback cb_printf, int mode) {
|
|||
pj_ks (pj, "type", "hash");
|
||||
pj_ks (pj, "name", cp->meta.name);
|
||||
switch (cp->type) {
|
||||
case R_CRYPTO_TYPE_HASH:
|
||||
case R_CRYPTO_TYPE_HASHER:
|
||||
pj_ks (pj, "type", "hash");
|
||||
break;
|
||||
case R_CRYPTO_TYPE_ENCRYPT:
|
||||
|
|
|
@ -53,7 +53,7 @@ RCryptoPlugin r_crypto_plugin_entropy = {
|
|||
.author = "pancake",
|
||||
.license = "MIT",
|
||||
},
|
||||
.type = R_CRYPTO_TYPE_HASH,
|
||||
.type = R_CRYPTO_TYPE_HASHER,
|
||||
.update = update,
|
||||
.end = end
|
||||
};
|
||||
|
|
|
@ -51,7 +51,7 @@ static bool ror_check(const char *algo) {
|
|||
}
|
||||
|
||||
static bool update(RCryptoJob *cj, const ut8 *buf, int len) {
|
||||
if (!cj->flag) {
|
||||
if (cj->flag != R_CRYPTO_DIR_ENCRYPT) {
|
||||
return false;
|
||||
}
|
||||
ut8 *obuf = calloc (1, len);
|
||||
|
|
|
@ -53,7 +53,7 @@ static void rot_decrypt(ut8 key, const ut8 *inbuf, ut8 *outbuf, int buflen) {
|
|||
}
|
||||
|
||||
static bool rot_set_key(RCryptoJob *cj, const ut8 *key, int keylen, int mode, int direction) {
|
||||
cj->flag = direction;
|
||||
cj->flag = direction == R_CRYPTO_DIR_ENCRYPT;
|
||||
return rot_init (&cj->rot_key, key, keylen);
|
||||
}
|
||||
|
||||
|
@ -67,10 +67,13 @@ static bool update(RCryptoJob *cj, const ut8 *buf, int len) {
|
|||
if (!obuf) {
|
||||
return false;
|
||||
}
|
||||
if (cj->flag == 0) {
|
||||
switch (cj->flag) {
|
||||
case R_CRYPTO_DIR_ENCRYPT:
|
||||
rot_crypt (cj->rot_key, buf, obuf, len);
|
||||
} else if (cj->flag == 1) {
|
||||
break;
|
||||
case R_CRYPTO_DIR_DECRYPT:
|
||||
rot_decrypt (cj->rot_key, buf, obuf, len);
|
||||
break;
|
||||
}
|
||||
r_crypto_job_append (cj, obuf, len);
|
||||
free (obuf);
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/* radare - LGPL - Copyright 2024 - pancake */
|
||||
|
||||
#include <r_lib.h>
|
||||
#include <r_crypto.h>
|
||||
|
||||
static bool update(RCryptoJob *cj, const ut8 *buf, int len) {
|
||||
char *s = r_str_ndup ((const char *)buf, len);
|
||||
int n = r_str_hash (s);
|
||||
free (s);
|
||||
cj->output = malloc (4);
|
||||
r_write_ble32 (cj->output, n, cj->c->bigendian);
|
||||
eprintf ("0x%x\n", n);
|
||||
cj->output_len = 4;
|
||||
return true;
|
||||
}
|
||||
|
||||
RCryptoPlugin r_crypto_plugin_strhash = {
|
||||
.meta = {
|
||||
.name = "strhash",
|
||||
.author = "pancake",
|
||||
.license = "MIT",
|
||||
},
|
||||
.type = R_CRYPTO_TYPE_HASHER,
|
||||
.implements = "strhash",
|
||||
.update = update,
|
||||
.end = update
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
R_API RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_CRYPTO,
|
||||
.data = &r_crypto_plugin_strhash,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
|
@ -18,6 +18,9 @@ static bool xor_init(struct xor_state *const state, const ut8 *key, int keylen)
|
|||
}
|
||||
state->key_size = keylen;
|
||||
state->key = malloc (keylen);
|
||||
if (state->key == NULL) {
|
||||
return false;
|
||||
}
|
||||
memcpy (state->key, key, keylen);
|
||||
return true;
|
||||
}
|
||||
|
@ -27,7 +30,7 @@ static bool xor_init(struct xor_state *const state, const ut8 *key, int keylen)
|
|||
*/
|
||||
|
||||
static void xor_crypt(struct xor_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen) {
|
||||
int i;//index for input
|
||||
int i;
|
||||
for (i = 0; i < buflen; i++) {
|
||||
outbuf[i] = inbuf[i] ^ state->key[(i%state->key_size)];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
OBJ_STRHASH=crypto_strhash.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_STRHASH}
|
||||
TARGET_STRHASH=crypto_strhash.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_STRHASH}
|
||||
|
||||
${TARGET_STRHASH}: ${OBJ_STRHASH}
|
||||
$(CC) $(call libname,crypto_strhash) ${LDFLAGS} ${CFLAGS} -o ${TARGET_STRHASH} ${OBJ_STRHASH}
|
|
@ -686,8 +686,6 @@ R_API bool r_debug_select(RDebug *dbg, int pid, int tid) {
|
|||
core->offset = r_debug_reg_get (dbg, "PC");
|
||||
}
|
||||
|
||||
dbg->main_arena_resolved = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,15 +58,18 @@ R_API bool r_debug_use(RDebug *dbg, const char *str) {
|
|||
if (plugin && plugin->reg_profile) {
|
||||
char *p = plugin->reg_profile (dbg);
|
||||
if (p) {
|
||||
r_reg_set_profile_string (dbg->reg, p);
|
||||
if (dbg->anal && dbg->reg != dbg->anal->reg) {
|
||||
r_reg_free (dbg->anal->reg);
|
||||
dbg->anal->reg = dbg->reg;
|
||||
if (!r_reg_set_profile_string (dbg->reg, p)) {
|
||||
R_LOG_ERROR ("Cannot set the register profile once");
|
||||
} else {
|
||||
if (dbg->anal && dbg->reg != dbg->anal->reg) {
|
||||
r_reg_free (dbg->anal->reg);
|
||||
dbg->anal->reg = dbg->reg;
|
||||
}
|
||||
if (plugin && plugin->init_debugger) {
|
||||
plugin->init_debugger (dbg);
|
||||
}
|
||||
r_reg_set_profile_string (dbg->reg, p);
|
||||
}
|
||||
if (plugin && plugin->init_debugger) {
|
||||
plugin->init_debugger (dbg);
|
||||
}
|
||||
r_reg_set_profile_string (dbg->reg, p);
|
||||
free (p);
|
||||
} else {
|
||||
R_LOG_ERROR ("Cannot retrieve reg profile from debug plugin (%s)", plugin->meta.name); //dbg->current->plugin.meta.name);
|
||||
|
|
|
@ -12,7 +12,7 @@ pre: libr_esil.$(EXT_SO) libr_esil.$(EXT_AR)
|
|||
|
||||
include $(STATIC_ESIL_PLUGINS)
|
||||
STATIC_OBJS=$(subst ..,p/..,$(subst esil_,p/esil_,$(STATIC_OBJ)))
|
||||
OBJS=esil.o esil_plugin.o esil_handler.o esil_stats.o esil_trace.o
|
||||
OBJS=esil.o esil_plugin.o esil_handler.o esil_stats.o esil_trace.o esil_toc.o
|
||||
OBJS+=${STATIC_OBJS}
|
||||
|
||||
include ../rules.mk
|
||||
|
|
|
@ -1,23 +1,9 @@
|
|||
/* radare - LGPL - Copyright 2021 - pancake */
|
||||
/* radare - LGPL - Copyright 2021-2024 - pancake */
|
||||
|
||||
typedef struct {
|
||||
RCore *core;
|
||||
RStrBuf *sb;
|
||||
} EsilC;
|
||||
|
||||
static char *esil2c(RCore *core, REsil *esil, const char *expr) {
|
||||
EsilC *user = esil->user;
|
||||
RStrBuf *sb = r_strbuf_new ("");
|
||||
user->sb = sb;
|
||||
if (!r_esil_parse (esil, expr)) {
|
||||
R_LOG_ERROR ("Invalid ESIL expression");
|
||||
}
|
||||
user->sb = NULL;
|
||||
return r_strbuf_drain (sb);
|
||||
}
|
||||
#include <r_esil.h>
|
||||
|
||||
static bool esil2c_eq(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *dst = r_esil_pop (esil);
|
||||
char *src = r_esil_pop (esil);
|
||||
|
||||
|
@ -38,7 +24,7 @@ static bool esil2c_eq(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_peek8(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *src = r_esil_pop (esil);
|
||||
|
||||
if (!src) {
|
||||
|
@ -51,7 +37,7 @@ static bool esil2c_peek8(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_poke8(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *dst = r_esil_pop (esil);
|
||||
char *src = r_esil_pop (esil);
|
||||
|
||||
|
@ -67,7 +53,7 @@ static bool esil2c_poke8(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_addeq(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *dst = r_esil_pop (esil);
|
||||
char *src = r_esil_pop (esil);
|
||||
|
||||
|
@ -83,7 +69,7 @@ static bool esil2c_addeq(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_add(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *dst = r_esil_pop (esil);
|
||||
char *src = r_esil_pop (esil);
|
||||
|
||||
|
@ -99,7 +85,7 @@ static bool esil2c_add(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_subeq(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *dst = r_esil_pop (esil);
|
||||
char *src = r_esil_pop (esil);
|
||||
|
||||
|
@ -115,7 +101,7 @@ static bool esil2c_subeq(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_xor(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *dst = r_esil_pop (esil);
|
||||
char *src = r_esil_pop (esil);
|
||||
|
||||
|
@ -134,7 +120,7 @@ static bool esil2c_xor(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_sub(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *dst = r_esil_pop (esil);
|
||||
char *src = r_esil_pop (esil);
|
||||
const bool lgtm = (src && dst);
|
||||
|
@ -148,7 +134,7 @@ static bool esil2c_sub(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_dec(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *src = r_esil_pop (esil);
|
||||
if (!src) {
|
||||
return false;
|
||||
|
@ -159,7 +145,7 @@ static bool esil2c_dec(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_inc(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *src = r_esil_pop (esil);
|
||||
if (!src) {
|
||||
return false;
|
||||
|
@ -170,7 +156,7 @@ static bool esil2c_inc(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_neg(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *src = r_esil_pop (esil);
|
||||
if (!src) {
|
||||
return false;
|
||||
|
@ -184,7 +170,7 @@ static bool esil2c_neg(REsil *esil) {
|
|||
}
|
||||
|
||||
static bool esil2c_goto(REsil *esil) {
|
||||
EsilC *user = esil->user;
|
||||
REsilC *user = esil->user;
|
||||
char *src = r_esil_pop (esil);
|
||||
if (!src) {
|
||||
return false;
|
||||
|
@ -194,7 +180,7 @@ static bool esil2c_goto(REsil *esil) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static void esil2c_free(EsilC *user) {
|
||||
static void esil2c_free(REsilC *user) {
|
||||
free (user);
|
||||
}
|
||||
|
||||
|
@ -208,10 +194,10 @@ static bool esil2c_mr(REsil *esil, ut64 addr, ut8 *buf, int len) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static void esil2c_setup(RCore *core, REsil *esil) {
|
||||
EsilC *user = R_NEW (EsilC);
|
||||
static void esil2c_setup(REsil *esil) {
|
||||
R_RETURN_IF_FAIL (esil);
|
||||
REsilC *user = R_NEW (REsilC);
|
||||
esil->user = user;
|
||||
esil->anal = core->anal;
|
||||
esil->verbose = true; // r_config_get_b (core->config, "esil.verbose");
|
||||
esil->cb.mem_read = esil2c_mr;
|
||||
esil->cb.mem_write = esil2c_mw;
|
||||
|
@ -233,3 +219,41 @@ static void esil2c_setup(RCore *core, REsil *esil) {
|
|||
// r_esil_set_op (esil, "+=", esil2c_set, 0, 2, R_ESIL_OP_TYPE_REG_WRITE);
|
||||
}
|
||||
|
||||
R_API REsilC *r_esil_toc_new(struct r_anal_t *anal, const int bits) {
|
||||
REsilC *ec = R_NEW0 (REsilC);
|
||||
if (ec) {
|
||||
int ss = 16 * 1024;
|
||||
REsil *esil = r_esil_new (ss, 0, bits);
|
||||
if (esil) {
|
||||
esil2c_setup (esil);
|
||||
ec->anal = anal;
|
||||
ec->esil = esil;
|
||||
} else {
|
||||
R_FREE (ec);
|
||||
}
|
||||
}
|
||||
return ec;
|
||||
}
|
||||
|
||||
R_API void r_esil_toc_free(REsilC *ec) {
|
||||
if (ec) {
|
||||
if (ec->esil) {
|
||||
esil2c_free (ec->esil->user);
|
||||
ec->esil->user = NULL;
|
||||
r_esil_free (ec->esil);
|
||||
}
|
||||
free (ec);
|
||||
}
|
||||
}
|
||||
|
||||
R_API char *r_esil_toc(REsilC *ec, const char *expr) {
|
||||
REsil *esil = ec->esil;
|
||||
RStrBuf *sb = r_strbuf_new ("");
|
||||
ec->sb = sb;
|
||||
if (!r_esil_parse (esil, expr)) {
|
||||
R_LOG_ERROR ("Invalid ESIL expression");
|
||||
}
|
||||
ec->sb = NULL;
|
||||
return r_strbuf_drain (sb);
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ r_esil_sources = [
|
|||
'esil_plugin.c',
|
||||
'esil_stats.c',
|
||||
'esil_trace.c',
|
||||
'esil_toc.c',
|
||||
'p/esil_null.c',
|
||||
'p/esil_dummy.c',
|
||||
]
|
||||
|
|
|
@ -1018,7 +1018,7 @@ R_API void r_anal_op_fini(RAnalOp *op);
|
|||
R_API char *r_anal_mnemonics(RAnal *anal, int id, bool json);
|
||||
R_API int r_anal_op_reg_delta(RAnal *anal, ut64 addr, const char *name);
|
||||
R_API bool r_anal_op_is_eob(RAnalOp *op);
|
||||
R_API RList *r_anal_op_list_new(void);
|
||||
// R_API RList *r_anal_op_list_new(void);
|
||||
R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask);
|
||||
R_API int r_anal_opasm(RAnal *anal, ut64 pc, const char *s, ut8 *outbuf, int outlen);
|
||||
R_API char *r_anal_op_tostring(RAnal *anal, RAnalOp *op);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#define R2_CRYPTO_H
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_list.h>
|
||||
#include <r_th.h>
|
||||
#include <r_crypto/r_des.h>
|
||||
#include <r_hash.h>
|
||||
|
@ -24,10 +23,12 @@ enum {
|
|||
R_CRYPTO_MODE_CFB,
|
||||
};
|
||||
|
||||
// TODO: use encode/decode wordings
|
||||
// TODO: use encode/decode wordings?
|
||||
enum {
|
||||
R_CRYPTO_DIR_DECRYPT = 0,
|
||||
R_CRYPTO_DIR_ENCRYPT = 1,
|
||||
R_CRYPTO_DIR_NONE = -1,
|
||||
R_CRYPTO_DIR_HASH = 0,
|
||||
R_CRYPTO_DIR_DECRYPT = 1,
|
||||
R_CRYPTO_DIR_ENCRYPT = 2,
|
||||
};
|
||||
|
||||
typedef struct r_crypto_t {
|
||||
|
@ -41,6 +42,7 @@ typedef struct r_crypto_t {
|
|||
int output_size;
|
||||
int dir;
|
||||
#endif
|
||||
bool bigendian;
|
||||
void *user;
|
||||
RList *plugins;
|
||||
} RCrypto;
|
||||
|
@ -66,8 +68,8 @@ typedef struct r_crypto_job_t {
|
|||
|
||||
typedef enum {
|
||||
R_CRYPTO_TYPE_ENCODER = 'e',
|
||||
R_CRYPTO_TYPE_HASH = 'h',
|
||||
R_CRYPTO_TYPE_ENCRYPT = 'c',
|
||||
R_CRYPTO_TYPE_HASHER = 'h',
|
||||
R_CRYPTO_TYPE_ENCRYPT = 'c', // CIPHER
|
||||
} RCryptoType;
|
||||
|
||||
typedef bool (*RCryptoJobSetIVCallback)(RCryptoJob *ci, const ut8 *iv, int ivlen);
|
||||
|
@ -118,6 +120,7 @@ R_API ut8 *r_crypto_job_get_output(RCryptoJob *cry, int *size);
|
|||
#endif
|
||||
|
||||
/* plugin pointers */
|
||||
extern RCryptoPlugin r_crypto_plugin_strhash;
|
||||
extern RCryptoPlugin r_crypto_plugin_aes;
|
||||
extern RCryptoPlugin r_crypto_plugin_des;
|
||||
extern RCryptoPlugin r_crypto_plugin_rc4;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare2 - LGPL - Copyright 2022-2023 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2022-2024 - pancake */
|
||||
|
||||
#ifndef R_ESIL_H
|
||||
#define R_ESIL_H
|
||||
|
@ -347,6 +347,16 @@ typedef struct r_esil_operation_t {
|
|||
ut32 type;
|
||||
} REsilOp;
|
||||
|
||||
// esil2c
|
||||
typedef struct {
|
||||
REsil *esil;
|
||||
RStrBuf *sb;
|
||||
void *anal; // RAnal*
|
||||
} REsilC;
|
||||
R_API REsilC *r_esil_toc_new(struct r_anal_t *anal, int bits);
|
||||
R_API void r_esil_toc_free(REsilC *ec);
|
||||
R_API char *r_esil_toc(REsilC *esil, const char *expr);
|
||||
|
||||
R_API bool r_esil_set_op(REsil *esil, const char *op, REsilOpCb code, ut32 push, ut32 pop, ut32 type);
|
||||
R_API REsilOp *r_esil_get_op(REsil *esil, const char *op);
|
||||
R_API void r_esil_del_op(REsil *esil, const char *op);
|
||||
|
|
|
@ -115,7 +115,39 @@ typedef RHeapChunk32 *mfastbinptr32;
|
|||
typedef RHeapChunk32 *mchunkptr32;
|
||||
*/
|
||||
|
||||
typedef struct r_malloc_state_32 {
|
||||
// 2.23 > GLIBC_VERSION >= 2.12
|
||||
// https://github.com/bminor/glibc/blob/glibc-2.12/malloc/malloc.c#L2362-L2400
|
||||
typedef struct r_malloc_state_212_32 {
|
||||
int mutex;
|
||||
int flags;
|
||||
ut32 fastbinsY[NFASTBINS];
|
||||
ut32 top;
|
||||
ut32 last_remainder;
|
||||
ut32 bins[NBINS * 2 - 2];
|
||||
unsigned int binmap[BINMAPSIZE];
|
||||
ut32 next;
|
||||
ut32 next_free;
|
||||
ut32 system_mem;
|
||||
ut32 max_system_mem;
|
||||
} RHeap_MallocState_212_32;
|
||||
|
||||
typedef struct r_malloc_state_212_64 {
|
||||
int mutex;
|
||||
int flags;
|
||||
ut64 fastbinsY[NFASTBINS];
|
||||
ut64 top;
|
||||
ut64 last_remainder;
|
||||
ut64 bins[NBINS * 2 - 2];
|
||||
unsigned int binmap[BINMAPSIZE];
|
||||
ut64 next;
|
||||
ut64 next_free;
|
||||
ut64 system_mem;
|
||||
ut64 max_system_mem;
|
||||
} RHeap_MallocState_212_64;
|
||||
|
||||
// 2.27 > GLIBC_VERSION >= 2.23
|
||||
// https://github.com/bminor/glibc/blob/1c9a5c270d8b66f30dcfaf1cb2d6cf39d3e18369/malloc/malloc.c#L1678-L1716
|
||||
typedef struct r_malloc_state_223_32 {
|
||||
int mutex; /* serialized access */
|
||||
int flags; /* flags */
|
||||
ut32 fastbinsY[NFASTBINS]; /* array of fastchunks */
|
||||
|
@ -128,9 +160,9 @@ typedef struct r_malloc_state_32 {
|
|||
unsigned int attached_threads; /* threads attached */
|
||||
ut32 system_mem; /* current allocated memory of current arena */
|
||||
ut32 max_system_mem; /* maximum system memory */
|
||||
} RHeap_MallocState_32;
|
||||
} RHeap_MallocState_223_32;
|
||||
|
||||
typedef struct r_malloc_state_64 {
|
||||
typedef struct r_malloc_state_223_64 {
|
||||
int mutex; /* serialized access */
|
||||
int flags; /* flags */
|
||||
ut64 fastbinsY[NFASTBINS]; /* array of fastchunks */
|
||||
|
@ -143,7 +175,7 @@ typedef struct r_malloc_state_64 {
|
|||
unsigned int attached_threads; /* threads attached */
|
||||
ut64 system_mem; /* current allocated memory of current arena */
|
||||
ut64 max_system_mem; /* maximum system memory */
|
||||
} RHeap_MallocState_64;
|
||||
} RHeap_MallocState_223_64;
|
||||
|
||||
typedef struct r_tcache_perthread_struct_32 {
|
||||
ut16 counts[TCACHE_MAX_BINS];
|
||||
|
@ -183,7 +215,9 @@ typedef struct {
|
|||
} RHeapTcache;
|
||||
} RTcache_32;
|
||||
|
||||
typedef struct r_malloc_state_tcache_32 {
|
||||
// GLIBC_VERSION >= 2.27
|
||||
// https://github.com/bminor/glibc/blob/glibc-2.34/malloc/malloc.c#L1831
|
||||
typedef struct r_malloc_state_227_32 {
|
||||
int mutex; /* serialized access */
|
||||
int flags; /* flags */
|
||||
int have_fast_chunks; /* have fast chunks */
|
||||
|
@ -194,12 +228,12 @@ typedef struct r_malloc_state_tcache_32 {
|
|||
unsigned int binmap[BINMAPSIZE]; /* bitmap of bins */
|
||||
ut32 next; /* double linked list of chunks */
|
||||
ut32 next_free; /* double linked list of free chunks */
|
||||
unsigned int attached_threads; /* threads attached */
|
||||
ut32 attached_threads; /* threads attached */
|
||||
ut32 system_mem; /* current allocated memory of current arena */
|
||||
ut32 max_system_mem; /* maximum system memory */
|
||||
} RHeap_MallocState_tcache_32;
|
||||
} RHeap_MallocState_227_32;
|
||||
|
||||
typedef struct r_malloc_state_tcache_64 {
|
||||
typedef struct r_malloc_state_227_64 {
|
||||
int mutex; /* serialized access */
|
||||
int flags; /* flags */
|
||||
int have_fast_chunks; /* have fast chunks */
|
||||
|
@ -210,10 +244,10 @@ typedef struct r_malloc_state_tcache_64 {
|
|||
unsigned int binmap[BINMAPSIZE]; /* bitmap of bins */
|
||||
ut64 next; /* double linked list of chunks */
|
||||
ut64 next_free; /* double linked list of free chunks */
|
||||
unsigned int attached_threads; /* threads attached */
|
||||
ut64 attached_threads; /* threads attached */
|
||||
ut64 system_mem; /* current allocated memory of current arena */
|
||||
ut64 max_system_mem; /* maximum system memory */
|
||||
} RHeap_MallocState_tcache_64;
|
||||
} RHeap_MallocState_227_64;
|
||||
|
||||
typedef struct r_malloc_state {
|
||||
int mutex; /* serialized access */
|
||||
|
|
|
@ -283,7 +283,7 @@ R_API void r_print_init_rowoffsets(RPrint *p);
|
|||
R_API ut32 r_print_rowoff(RPrint *p, int i);
|
||||
R_API void r_print_set_rowoff(RPrint *p, int i, ut32 offset, bool overwrite);
|
||||
R_API int r_print_row_at_off(RPrint *p, ut32 offset);
|
||||
R_API int r_print_pie(RPrint *p, ut64 *values, int nvalues, int size);
|
||||
R_API void r_print_pie(RPrint *p, int nvalues, int *values, const char **text, int size);
|
||||
R_API void r_print_graphline(RPrint *print, const ut8 *buf, size_t len);
|
||||
|
||||
// WIP
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2008-2023 - mrmacete, pancake */
|
||||
/* radare - LGPL - Copyright 2008-2024 - mrmacete, pancake */
|
||||
|
||||
#include <r_io.h>
|
||||
#include <r_lib.h>
|
||||
|
@ -24,6 +24,20 @@ typedef struct {
|
|||
size_t length;
|
||||
} RDyldRebaseInfos;
|
||||
|
||||
typedef struct {
|
||||
ut8 version;
|
||||
ut64 slide;
|
||||
ut8 *one_page_buf;
|
||||
ut32 page_size;
|
||||
ut64 start_of_data;
|
||||
ut16 *page_starts;
|
||||
ut32 page_starts_count;
|
||||
ut64 delta_mask;
|
||||
ut32 delta_shift;
|
||||
ut32 high8_shift;
|
||||
ut64 value_add;
|
||||
} RDyldRebaseInfo5;
|
||||
|
||||
typedef struct {
|
||||
ut8 version;
|
||||
ut64 slide;
|
||||
|
@ -180,6 +194,7 @@ static RList * r_io_dsc_slice_get_rebase_infos_by_range(RIODscSlice * slice, ut6
|
|||
static void rebase_bytes_v1(RIODscSlice * slice, RDyldRebaseInfo1 *rebase_info, ut8 *buf, ut64 offset, int count, ut64 buf_off);
|
||||
static void rebase_bytes_v2(RIODscSlice * slice, RDyldRebaseInfo2 *rebase_info, ut8 *buf, ut64 offset, int count, ut64 buf_off);
|
||||
static void rebase_bytes_v3(RIODscSlice * slice, RDyldRebaseInfo3 *rebase_info, ut8 *buf, ut64 offset, int count, ut64 buf_off);
|
||||
static void rebase_bytes_v5(RIODscSlice * slice, RDyldRebaseInfo5 *rebase_info, ut8 *buf, ut64 offset, int count, ut64 buf_off);
|
||||
|
||||
static int r_io_posix_open(const char *file, int perm, int mode, bool nocache);
|
||||
static int r_io_dsc_object_read(RIO *io, RIODesc *fd, ut8 *buf, int count);
|
||||
|
@ -774,6 +789,10 @@ static void r_io_dsc_slice_rebase_bytes(RIODscSlice * slice, ut64 off_local, ut8
|
|||
rebase_bytes_v3 (slice, (RDyldRebaseInfo3 *) trimmed->info->info,
|
||||
buf, trimmed->off_local, trimmed->count, trimmed->buf_off);
|
||||
break;
|
||||
case 5:
|
||||
rebase_bytes_v5 (slice, (RDyldRebaseInfo5 *) trimmed->info->info,
|
||||
buf, trimmed->off_local, trimmed->count, trimmed->buf_off);
|
||||
break;
|
||||
default:
|
||||
R_LOG_ERROR ("Unsupported rebase info version %d", trimmed->info->info->version);
|
||||
}
|
||||
|
@ -933,6 +952,79 @@ next_page:
|
|||
}
|
||||
}
|
||||
|
||||
static void rebase_bytes_v5(RIODscSlice * slice, RDyldRebaseInfo5 *rebase_info, ut8 *buf, ut64 offset, int count, ut64 buf_off) {
|
||||
int in_buf = buf_off;
|
||||
while (in_buf < count + buf_off) {
|
||||
ut64 offset_in_data = offset - rebase_info->start_of_data;
|
||||
ut64 page_index = offset_in_data / rebase_info->page_size;
|
||||
ut64 page_offset = offset_in_data % rebase_info->page_size;
|
||||
ut64 to_next_page = rebase_info->page_size - page_offset;
|
||||
|
||||
if (page_index >= rebase_info->page_starts_count) {
|
||||
goto next_page;
|
||||
}
|
||||
ut64 delta = rebase_info->page_starts[page_index];
|
||||
|
||||
if (delta == DYLD_CACHE_SLIDE_V3_PAGE_ATTR_NO_REBASE) {
|
||||
goto next_page;
|
||||
}
|
||||
|
||||
ut64 first_rebase_off = delta;
|
||||
if (first_rebase_off < page_offset + count) {
|
||||
if (first_rebase_off < page_offset) {
|
||||
ut64 back_size = page_offset - first_rebase_off;
|
||||
ut8 * back_bytes = malloc (back_size);
|
||||
if (!back_bytes) {
|
||||
return;
|
||||
}
|
||||
bool got_back_bytes = false;
|
||||
RIO_FREAD_AT_INTO_DIRECT (slice->fd, offset - back_size, back_bytes, back_size, got_back_bytes);
|
||||
if (!got_back_bytes) {
|
||||
free (back_bytes);
|
||||
return;
|
||||
}
|
||||
|
||||
int cursor = 0;
|
||||
while (cursor <= back_size - 8) {
|
||||
ut64 raw_value = r_read_le64 (back_bytes + cursor);
|
||||
delta = ((raw_value & rebase_info->delta_mask) >> rebase_info->delta_shift) * 8;
|
||||
cursor += delta;
|
||||
if (!delta) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
first_rebase_off += cursor;
|
||||
|
||||
free (back_bytes);
|
||||
|
||||
if (!delta) {
|
||||
goto next_page;
|
||||
}
|
||||
}
|
||||
do {
|
||||
ut64 position = in_buf + first_rebase_off - page_offset;
|
||||
if (position + 8 > count) {
|
||||
break;
|
||||
}
|
||||
ut64 raw_value = r_read_le64 (buf + position);
|
||||
delta = ((raw_value & rebase_info->delta_mask) >> rebase_info->delta_shift) * 8;
|
||||
if (position >= buf_off) {
|
||||
ut64 new_value = (raw_value & 0x3ffffffff) + rebase_info->value_add + rebase_info->slide;
|
||||
if (!R_IS_PTR_AUTHENTICATED (raw_value)) {
|
||||
new_value = ((raw_value << rebase_info->high8_shift) & 0xFF00000000000000ULL) | new_value;
|
||||
}
|
||||
r_write_le64 (buf + position, new_value);
|
||||
}
|
||||
first_rebase_off += delta;
|
||||
} while (delta);
|
||||
}
|
||||
next_page:
|
||||
in_buf += to_next_page;
|
||||
offset += to_next_page;
|
||||
}
|
||||
}
|
||||
|
||||
static void rebase_bytes_v3(RIODscSlice * slice, RDyldRebaseInfo3 *rebase_info, ut8 *buf, ut64 offset, int count, ut64 buf_off) {
|
||||
int in_buf = buf_off;
|
||||
while (in_buf < count + buf_off) {
|
||||
|
@ -1059,10 +1151,17 @@ static RDSCHeader * r_io_dsc_read_header(int fd, ut64 offset) {
|
|||
}
|
||||
|
||||
static bool is_valid_magic(ut8 magic[16]) {
|
||||
return !strcmp ((char *) magic, "dyld_v1 arm64")
|
||||
|| !strcmp ((char *) magic, "dyld_v1 arm64e")
|
||||
|| !strcmp ((char *) magic, "dyld_v1 x86_64")
|
||||
|| !strcmp ((char *) magic, "dyld_v1 x86_64h");
|
||||
const char * ma = (const char *)magic;
|
||||
if (r_str_startswith (ma, "dyld_v1 ")) {
|
||||
const size_t off = strlen ("dyld_v1 ");
|
||||
const size_t left = 16 - off;
|
||||
return 0 \
|
||||
|| !strncmp (ma + off, " arm64", left)
|
||||
|| !strncmp (ma + off, " arm64e", left)
|
||||
|| !strncmp (ma + off, " x86_64", left)
|
||||
|| !strncmp (ma + off, "x86_64h", left);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool is_null_uuid(ut8 uuid[16]) {
|
||||
|
@ -1173,7 +1272,56 @@ static RDyldRebaseInfo *get_rebase_info(int fd, ut64 slideInfoOffset, ut64 slide
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (slide_info_version == 3) {
|
||||
if (slide_info_version == 5) {
|
||||
ut64 size = sizeof (cache_slide3_t);
|
||||
cache_slide5_t slide_info;
|
||||
bool got_info = false;
|
||||
RIO_FREAD_AT (fd, offset, slide_info, "4i1l", got_info);
|
||||
if (!got_info) {
|
||||
R_LOG_ERROR ("Could not read slide info v5");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ut64 page_starts_offset = offset + size;
|
||||
ut64 page_starts_size = slide_info.page_starts_count * 2;
|
||||
|
||||
if (page_starts_size + size > slideInfoSize) {
|
||||
R_LOG_ERROR ("Size mismatch in slide info v5");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (page_starts_size > 0) {
|
||||
tmp_buf_1 = malloc (page_starts_size);
|
||||
if (!tmp_buf_1) {
|
||||
goto beach;
|
||||
}
|
||||
bool got_starts = false;
|
||||
RIO_FREAD_AT_INTO (fd, page_starts_offset, tmp_buf_1, "s", page_starts_size, slide_info.page_starts_count, got_starts);
|
||||
if (!got_starts) {
|
||||
R_LOG_ERROR ("Could not read slide info v3 page starts");
|
||||
goto beach;
|
||||
}
|
||||
}
|
||||
|
||||
RDyldRebaseInfo5 *rebase_info = R_NEW0 (RDyldRebaseInfo5);
|
||||
if (!rebase_info) {
|
||||
goto beach;
|
||||
}
|
||||
|
||||
rebase_info->version = 5;
|
||||
rebase_info->delta_mask = 0x7ff0000000000000ULL;
|
||||
rebase_info->delta_shift = 52; // right
|
||||
rebase_info->high8_shift = 22; // left
|
||||
rebase_info->start_of_data = start_of_data;
|
||||
rebase_info->page_starts = (ut16*) tmp_buf_1;
|
||||
rebase_info->page_starts_count = slide_info.page_starts_count;
|
||||
rebase_info->value_add = slide_info.value_add;
|
||||
rebase_info->page_size = slide_info.page_size;
|
||||
rebase_info->one_page_buf = one_page_buf;
|
||||
rebase_info->slide = slide;
|
||||
|
||||
return (RDyldRebaseInfo*) rebase_info;
|
||||
} else if (slide_info_version == 3) {
|
||||
ut64 size = sizeof (cache_slide3_t);
|
||||
cache_slide3_t slide_info;
|
||||
bool got_info = false;
|
||||
|
@ -1374,6 +1522,13 @@ beach:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void rebase_info5_free(RDyldRebaseInfo5 *rebase_info) {
|
||||
if (rebase_info) {
|
||||
R_FREE (rebase_info->page_starts);
|
||||
R_FREE (rebase_info);
|
||||
}
|
||||
}
|
||||
|
||||
static void rebase_info3_free(RDyldRebaseInfo3 *rebase_info) {
|
||||
if (rebase_info) {
|
||||
R_FREE (rebase_info->page_starts);
|
||||
|
@ -1409,6 +1564,8 @@ static void rebase_info_free(RDyldRebaseInfo *rebase_info) {
|
|||
rebase_info2_free ((RDyldRebaseInfo2*) rebase_info);
|
||||
} else if (version == 3) {
|
||||
rebase_info3_free ((RDyldRebaseInfo3*) rebase_info);
|
||||
} else if (version == 5) {
|
||||
rebase_info5_free ((RDyldRebaseInfo5*) rebase_info);
|
||||
} else {
|
||||
R_FREE (rebase_info);
|
||||
}
|
||||
|
|
|
@ -62,45 +62,65 @@ static bool lang_tsc_file(RLangSession *s, const char *file) {
|
|||
R_LOG_WARN ("file does not exist");
|
||||
return false;
|
||||
}
|
||||
bool use_node = true;
|
||||
if (r_sys_getenv_asbool ("R2_TSR2JS")) {
|
||||
use_node = false;
|
||||
}
|
||||
char *js_ofile = r_str_replace (strdup (file), ".ts", ".js", 0);
|
||||
char *qjs_ofile = r_str_replace (strdup (file), ".ts", ".r2.js", 0);
|
||||
char *qjs_ofile = NULL;
|
||||
if (use_node) {
|
||||
qjs_ofile = r_str_replace (strdup (file), ".ts", ".js", 0);
|
||||
} else {
|
||||
qjs_ofile = r_str_replace (strdup (file), ".ts", ".r2.js", 0);
|
||||
}
|
||||
int rc = 0;
|
||||
/// check of ofile exists and its newer than file
|
||||
if (!r_file_is_newer (qjs_ofile, file)) {
|
||||
char *name = strdup (file);
|
||||
char *dot = strchr (name, '.');
|
||||
if (dot) {
|
||||
*dot = 0;
|
||||
}
|
||||
// TODO: compile to stdout and remove the need of another tmp file
|
||||
rc = r_sys_cmdf ("tsc --target es2020 --allowJs --outFile %s --lib es2020,dom --moduleResolution node --module amd %s", js_ofile, file);
|
||||
if (rc == 0) {
|
||||
char *js_ifile = r_file_slurp (js_ofile, NULL);
|
||||
RStrBuf *sb = r_strbuf_new ("");
|
||||
char *js_ifile_orig = strdup (js_ifile);
|
||||
// r_strbuf_append (sb, js_require_qjs);
|
||||
js_ifile = patch_entrypoint (js_ifile, name);
|
||||
if (js_ifile) {
|
||||
r_strbuf_append (sb, "var Gmain;");
|
||||
r_strbuf_append (sb, js_ifile);
|
||||
r_strbuf_append (sb, js_entrypoint_qjs);
|
||||
} else {
|
||||
R_LOG_DEBUG ("Cannot find Gmain entrypoint");
|
||||
r_strbuf_append (sb, js_ifile_orig);
|
||||
if (use_node) {
|
||||
rc = r_sys_cmdf ("tsc %s", file);
|
||||
} else {
|
||||
char *name = strdup (file);
|
||||
char *dot = strchr (name, '.');
|
||||
if (dot) {
|
||||
*dot = 0;
|
||||
}
|
||||
// TODO: compile to stdout and remove the need of another tmp file
|
||||
rc = r_sys_cmdf ("tsc --target es2020 --allowJs --outFile %s --lib es2020,dom --moduleResolution node --module amd %s", js_ofile, file);
|
||||
if (rc == 0) {
|
||||
char *js_ifile = r_file_slurp (js_ofile, NULL);
|
||||
RStrBuf *sb = r_strbuf_new ("");
|
||||
char *js_ifile_orig = strdup (js_ifile);
|
||||
// r_strbuf_append (sb, js_require_qjs);
|
||||
js_ifile = patch_entrypoint (js_ifile, name);
|
||||
if (js_ifile) {
|
||||
r_strbuf_append (sb, "var Gmain;");
|
||||
r_strbuf_append (sb, js_ifile);
|
||||
r_strbuf_append (sb, js_entrypoint_qjs);
|
||||
} else {
|
||||
R_LOG_DEBUG ("Cannot find Gmain entrypoint");
|
||||
r_strbuf_append (sb, js_ifile_orig);
|
||||
}
|
||||
char *s = r_strbuf_drain (sb);
|
||||
free (js_ifile_orig);
|
||||
r_file_dump (qjs_ofile, (const ut8*)s, -1, 0);
|
||||
free (s);
|
||||
r_file_rm (js_ofile);
|
||||
}
|
||||
char *s = r_strbuf_drain (sb);
|
||||
free (js_ifile_orig);
|
||||
r_file_dump (qjs_ofile, (const ut8*)s, -1, 0);
|
||||
free (s);
|
||||
r_file_rm (js_ofile);
|
||||
}
|
||||
} else {
|
||||
R_LOG_DEBUG ("no need to compile");
|
||||
}
|
||||
// TODO: use r_lang_run_string() and avoid the need of the intermediate qjs file
|
||||
if (rc == 0) {
|
||||
r_lang_use (s->lang, "qjs");
|
||||
rc = r_lang_run_file (s->lang, qjs_ofile)? 0: -1;
|
||||
if (use_node) {
|
||||
r_lang_use (s->lang, "pipe");
|
||||
char *f = r_str_newf ("node %s", qjs_ofile);
|
||||
rc = r_lang_run_file (s->lang, f)? 0: -1;
|
||||
free (f);
|
||||
} else {
|
||||
r_lang_use (s->lang, "qjs");
|
||||
rc = r_lang_run_file (s->lang, qjs_ofile)? 0: -1;
|
||||
}
|
||||
}
|
||||
free (js_ofile);
|
||||
free (qjs_ofile);
|
||||
|
|
|
@ -603,3 +603,5 @@
|
|||
!:mime application/msword
|
||||
>546 string jbjb Microsoft Word Document 2
|
||||
!:mime application/msword
|
||||
|
||||
0 lelong 0x53445352 CODEVIEW_INFO header
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <r_io.h>
|
||||
#include <r_main.h>
|
||||
#include <r_hash.h>
|
||||
#include <r_util/r_print.h>
|
||||
#include <r_crypto.h>
|
||||
|
||||
|
@ -20,6 +19,7 @@ typedef struct {
|
|||
ut64 to;
|
||||
RHashSeed *_s;
|
||||
RHashSeed s;
|
||||
const char *algorithm;
|
||||
} RahashOptions;
|
||||
|
||||
static void compare_hashes(const RHash *ctx, RahashOptions *ro, const ut8 *compare, int length, int *ret, int rad) {
|
||||
|
@ -364,14 +364,14 @@ static bool is_power_of_two(const ut64 x) {
|
|||
return x && !(x & (x - 1));
|
||||
}
|
||||
|
||||
static void print_result(RahashOptions *ro, const char *algo, const ut8 *result, int result_size) {
|
||||
static void print_result(RahashOptions *ro, const ut8 *result, int result_size) {
|
||||
int i;
|
||||
switch (ro->mode) {
|
||||
case 'j':
|
||||
{
|
||||
PJ *pj = pj_new ();
|
||||
pj_o (pj);
|
||||
pj_ks (pj, "algo", algo);
|
||||
pj_ks (pj, "algo", ro->algorithm);
|
||||
pj_ks (pj, "mode", ro->direction? "encrypt": "decrypt");
|
||||
pj_ka (pj, "data");
|
||||
for (i = 0; i < result_size; i++) {
|
||||
|
@ -398,8 +398,9 @@ static void print_result(RahashOptions *ro, const char *algo, const ut8 *result,
|
|||
}
|
||||
}
|
||||
|
||||
// direction: 0 => decrypt, 1 => encrypt
|
||||
static int encrypt_or_decrypt(RahashOptions *ro, const char *algo, int direction, const char *hashstr, int hashstr_len, const ut8 *iv, int ivlen, int mode) {
|
||||
static int encrypt_or_decrypt(RahashOptions *ro, const char *hashstr, int hashstr_len, const ut8 *iv, int ivlen, int mode) {
|
||||
const int direction = ro->direction;
|
||||
const char *algo = ro->algorithm;
|
||||
// TODO: generalise this for all non key encoding/decoding.
|
||||
bool no_key_mode = !strcmp ("base64", algo) || !strcmp ("base91", algo) || !strcmp ("punycode", algo);
|
||||
if (no_key_mode || ro->s.len > 0) {
|
||||
|
@ -420,7 +421,7 @@ static int encrypt_or_decrypt(RahashOptions *ro, const char *algo, int direction
|
|||
int result_size = 0;
|
||||
ut8 *result = r_crypto_job_get_output (cj, &result_size);
|
||||
if (result) {
|
||||
print_result (ro, algo, result, result_size);
|
||||
print_result (ro, result, result_size);
|
||||
free (result);
|
||||
}
|
||||
} else {
|
||||
|
@ -438,7 +439,9 @@ static int encrypt_or_decrypt(RahashOptions *ro, const char *algo, int direction
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int encrypt_or_decrypt_file(RahashOptions *ro, const char *algo, int direction, const char *filename, const ut8 *iv, int ivlen, int mode) {
|
||||
static int encrypt_or_decrypt_file(RahashOptions *ro, const char *filename, const ut8 *iv, int ivlen, int mode) {
|
||||
const int direction = ro->direction;
|
||||
const char *algo = ro->algorithm;
|
||||
// TODO: generalise this for all non key encoding/decoding. aka crypto vs encoder plugins after moving all those hash algos to crypto plugins
|
||||
bool no_key_mode = !strcmp ("base64", algo) || !strcmp ("base91", algo) || !strcmp ("punycode", algo);
|
||||
if (no_key_mode || ro->s.len > 0) {
|
||||
|
@ -470,7 +473,7 @@ static int encrypt_or_decrypt_file(RahashOptions *ro, const char *algo, int dire
|
|||
int result_size = 0;
|
||||
ut8 *result = r_crypto_job_get_output (cj, &result_size);
|
||||
if (result) {
|
||||
print_result (ro, algo, result, result_size);
|
||||
print_result (ro, result, result_size);
|
||||
free (result);
|
||||
}
|
||||
free (buf);
|
||||
|
@ -490,12 +493,14 @@ static int encrypt_or_decrypt_file(RahashOptions *ro, const char *algo, int dire
|
|||
}
|
||||
|
||||
static void add_algo(RList *algos, const char *a) {
|
||||
R_RETURN_IF_FAIL (algos);
|
||||
if (R_STR_ISEMPTY (a)) {
|
||||
return;
|
||||
}
|
||||
RListIter *iter;
|
||||
const char *ua;
|
||||
char *ha = strdup (a);
|
||||
// TODO: Use a set
|
||||
RList *words = r_str_split_list (ha, ",", 0);
|
||||
r_list_foreach (words, iter, ua) {
|
||||
if (!r_list_find (algos, ua, (RListComparator)strcmp)) {
|
||||
|
@ -506,6 +511,16 @@ static void add_algo(RList *algos, const char *a) {
|
|||
free (ha);
|
||||
}
|
||||
|
||||
static bool check_base_flags(RahashOptions *ro) {
|
||||
const char *algo = ro->algorithm;
|
||||
switch (ro->direction) {
|
||||
case R_CRYPTO_DIR_ENCRYPT:
|
||||
case R_CRYPTO_DIR_DECRYPT:
|
||||
return !strcmp (algo, "base64") || !strcmp (algo, "base91");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_main_rahash2(int argc, const char **argv) {
|
||||
ut64 i;
|
||||
int c, rad = 0, bsize = 0, numblocks = 0, ule = 0;
|
||||
|
@ -513,8 +528,6 @@ R_API int r_main_rahash2(int argc, const char **argv) {
|
|||
char *algo = NULL;
|
||||
const char *seed = NULL;
|
||||
bool show_version = false;
|
||||
const char *decrypt = NULL;
|
||||
const char *encrypt = NULL;
|
||||
char *hashstr = NULL;
|
||||
ut8 *iv = NULL;
|
||||
int ivlen = -1;
|
||||
|
@ -534,8 +547,8 @@ R_API int r_main_rahash2(int argc, const char **argv) {
|
|||
bool listplugins = false;
|
||||
int _ret = 0;
|
||||
|
||||
ro->direction = -1;
|
||||
ro->incremental = true;
|
||||
// #define ret(x) {_ret=x;printf("%d\n", __LINE__);goto beach;}
|
||||
#define ret(x) {_ret=x;goto beach;}
|
||||
RGetopt opt;
|
||||
r_getopt_init (&opt, argc, argv, "p:jJD:rveE:a:i:I:S:s:x:b:nBhf:t:kLqc:X");
|
||||
|
@ -557,8 +570,22 @@ R_API int r_main_rahash2(int argc, const char **argv) {
|
|||
case 'S': seed = opt.arg; break;
|
||||
case 'I': ivseed = opt.arg; break;
|
||||
case 'n': numblocks = 1; break;
|
||||
case 'D': ro->direction = R_CRYPTO_DIR_DECRYPT; decrypt = opt.arg; break;
|
||||
case 'E': ro->direction = R_CRYPTO_DIR_ENCRYPT; encrypt = opt.arg; break;
|
||||
case 'D':
|
||||
if (ro->direction != -1) {
|
||||
R_LOG_ERROR ("Cannot use -D and -E at the same time");
|
||||
ret (1);
|
||||
}
|
||||
ro->direction = R_CRYPTO_DIR_DECRYPT;
|
||||
ro->algorithm = opt.arg;
|
||||
break;
|
||||
case 'E':
|
||||
if (ro->direction != -1) {
|
||||
R_LOG_ERROR ("Cannot use -D and -E at the same time");
|
||||
ret (1);
|
||||
}
|
||||
ro->direction = R_CRYPTO_DIR_ENCRYPT;
|
||||
ro->algorithm = opt.arg;
|
||||
break;
|
||||
case 'L': listplugins = true; break;
|
||||
case 'e': ule = 1; ro->endian = !ro->endian; break;
|
||||
case 'r': rad = 1; break;
|
||||
|
@ -581,11 +608,6 @@ R_API int r_main_rahash2(int argc, const char **argv) {
|
|||
ret (r_main_version_print ("rahash2", rad));
|
||||
}
|
||||
|
||||
algo = r_list_empty (algos) ? strdup ("sha1") : r_str_list_join (algos, ",");
|
||||
if (encrypt && decrypt) {
|
||||
R_LOG_ERROR ("Option -E and -D are incompatible with each other");
|
||||
ret (1);
|
||||
}
|
||||
if (listplugins) {
|
||||
if (rad == 'j' && ro->quiet) {
|
||||
rad = 'J';
|
||||
|
@ -593,19 +615,14 @@ R_API int r_main_rahash2(int argc, const char **argv) {
|
|||
algolist (rad);
|
||||
ret (0);
|
||||
}
|
||||
algo = r_list_empty (algos) ? strdup ("sha1") : r_str_list_join (algos, ",");
|
||||
if (compareStr) {
|
||||
int compareBin_len;
|
||||
if (bsize && !ro->incremental) {
|
||||
R_LOG_ERROR ("Option -c incompatible with -b and -B options");
|
||||
ret (1);
|
||||
}
|
||||
bool flag = false;
|
||||
if (encrypt) {
|
||||
flag = !strcmp (encrypt, "base64") || !strcmp (encrypt, "base91");
|
||||
} else if (decrypt) {
|
||||
flag = !strcmp (decrypt, "base64") || !strcmp (decrypt, "base91");
|
||||
}
|
||||
if (flag) {
|
||||
if (check_base_flags (ro)) {
|
||||
R_LOG_ERROR ("Option -c incompatible with -E base64, -E base91, -D base64 or -D base91 options");
|
||||
ret (1);
|
||||
}
|
||||
|
@ -720,10 +737,8 @@ R_API int r_main_rahash2(int argc, const char **argv) {
|
|||
if (!bytes_read && !hashstr_hex) {
|
||||
hashstr_len = r_str_unescape (nhashstr);
|
||||
}
|
||||
if (encrypt) {
|
||||
ret (encrypt_or_decrypt (ro, encrypt, R_CRYPTO_DIR_ENCRYPT, nhashstr, hashstr_len, iv, ivlen, 0));
|
||||
} else if (decrypt) {
|
||||
ret (encrypt_or_decrypt (ro, decrypt, R_CRYPTO_DIR_DECRYPT, nhashstr, hashstr_len, iv, ivlen, 0));
|
||||
if (ro->direction != -1) {
|
||||
ret (encrypt_or_decrypt (ro, nhashstr, hashstr_len, iv, ivlen, 0));
|
||||
} else {
|
||||
char *str = (char *) nhashstr;
|
||||
int strsz = hashstr_len;
|
||||
|
@ -815,14 +830,8 @@ R_API int r_main_rahash2(int argc, const char **argv) {
|
|||
ret (1);
|
||||
}
|
||||
|
||||
if (encrypt) {// for encrytion when files are provided
|
||||
int rt = encrypt_or_decrypt_file (ro, encrypt, 0, argv[i], iv, ivlen, 0);
|
||||
if (rt == -1) {
|
||||
continue;
|
||||
}
|
||||
ret (rt);
|
||||
} else if (decrypt) {
|
||||
int rt = encrypt_or_decrypt_file (ro, decrypt, 1, argv[i], iv, ivlen, 0);
|
||||
if (ro->direction != -1) {
|
||||
int rt = encrypt_or_decrypt_file (ro, argv[i], iv, ivlen, 0);
|
||||
if (rt == -1) {
|
||||
continue;
|
||||
}
|
||||
|
|
127
libr/main/rax2.c
127
libr/main/rax2.c
|
@ -3,25 +3,27 @@
|
|||
#define R_LOG_ORIGIN "rax2"
|
||||
|
||||
#include <r_main.h>
|
||||
#include <r_util/pj.h>
|
||||
#include <r_util/r_print.h>
|
||||
#include <r_util/r_str.h>
|
||||
|
||||
typedef enum {
|
||||
RAX2_FLAG_HEXSTR2RAW = (1 << 0), // -s
|
||||
RAX2_FLAG_SWAPENDIAN = (1 << 1), // -e
|
||||
RAX2_FLAG_RAW2HEXSTR = (1 << 2), // -S
|
||||
RAX2_FLAG_BINSTR2RAW = (1 << 3), // -b
|
||||
RAX2_FLAG_HASHSTRING = (1 << 4), // -x
|
||||
RAX2_FLAG_HASHSTRING = (1 << 4), // -X
|
||||
RAX2_FLAG_KEEPBASE = (1 << 5), // -k
|
||||
RAX2_FLAG_FLOATING = (1 << 6), // -f
|
||||
RAX2_FLAG_DECIMAL = (1 << 7), // -d
|
||||
RAX2_FLAG_RANDOMART = (1 << 8), // -K
|
||||
RAX2_FLAG_BINARYNUM = (1 << 9), // -n
|
||||
RAX2_FLAG_BINARYNUM = (1 << 9), // -x
|
||||
RAX2_FLAG_SHOWUNITS = (1 << 10), // -u
|
||||
RAX2_FLAG_TIMESTAMP = (1 << 11), // -t
|
||||
RAX2_FLAG_B64ENCODE = (1 << 12), // -E
|
||||
RAX2_FLAG_B64DECODE = (1 << 13), // -D
|
||||
RAX2_FLAG_SLURPHEX = (1 << 14), // -F
|
||||
RAX2_FLAG_BINARYRAW = (1 << 15), // -N
|
||||
RAX2_FLAG_BINARYRAW = (1 << 15), // -c
|
||||
RAX2_FLAG_SIGNEDWORD = (1 << 16), // -w
|
||||
RAX2_FLAG_STR2HEXSTR = (1 << 17), // -B
|
||||
RAX2_FLAG_MANYBASES = (1 << 18), // -r
|
||||
|
@ -29,12 +31,13 @@ typedef enum {
|
|||
RAX2_FLAG_DUMPCSTR = (1 << 20), // -i
|
||||
RAX2_FLAG_OCTAL2RAW = (1 << 21), // -o
|
||||
RAX2_FLAG_IPADDR2NUM = (1 << 22), // -I
|
||||
RAX2_FLAG_NEWLINE = (1 << 23), // -l
|
||||
RAX2_FLAG_NEWLINE = (1 << 23), // -n
|
||||
RAX2_FLAG_JSONBASES = (1 << 24), // -j
|
||||
} RaxAction;
|
||||
|
||||
static bool rax(RNum *num, char *str, int len, int last, ut64 *flags, int *fm);
|
||||
static bool rax(RNum *num, char *str, int len, int last, ut64 *flags, int *fm, PJ **pj);
|
||||
|
||||
static int use_stdin(RNum *num, ut64 *flags, int *fm) {
|
||||
static int use_stdin(RNum *num, ut64 *flags, int *fm, PJ **pj) {
|
||||
r_return_val_if_fail (num && flags, -1);
|
||||
if (!flags) {
|
||||
return 0;
|
||||
|
@ -42,7 +45,7 @@ static int use_stdin(RNum *num, ut64 *flags, int *fm) {
|
|||
int rc = 0;
|
||||
if (*flags & RAX2_FLAG_SLURPHEX) {
|
||||
char buf[1]= {0};
|
||||
if (!rax (num, buf, 1, 0, flags, fm)) {
|
||||
if (!rax (num, buf, 1, 0, flags, fm, pj)) {
|
||||
rc = 1;
|
||||
}
|
||||
} else {
|
||||
|
@ -52,7 +55,7 @@ static int use_stdin(RNum *num, ut64 *flags, int *fm) {
|
|||
if (!buf) {
|
||||
break;
|
||||
}
|
||||
if (!rax (num, buf, l, 0, flags, fm)) {
|
||||
if (!rax (num, buf, l, 0, flags, fm, pj)) {
|
||||
rc = 1;
|
||||
}
|
||||
free (buf);
|
||||
|
@ -166,21 +169,21 @@ static int help(void) {
|
|||
" -a show ascii table ; rax2 -a\n"
|
||||
" -b bin -> str ; rax2 -b 01000101 01110110\n"
|
||||
" -B str -> bin ; rax2 -B hello\n"
|
||||
" -c output in C string ; rax2 -c 0x1234 # \\x34\\x12\\x00\\x00\n"
|
||||
" -d force integer ; rax2 -d 3 -> 3 instead of 0x3\n"
|
||||
" -e swap endianness ; rax2 -e 0x33\n"
|
||||
" -D base64 decode ;\n"
|
||||
" -E base64 encode ;\n"
|
||||
" -D base64 decode ; rax2 -D \"aGVsbG8=\"\n"
|
||||
" -E base64 encode ; rax2 -E \"hello\"\n"
|
||||
" -f floating point ; rax2 -f 6.3+2.1\n"
|
||||
" -F stdin slurp code hex ; rax2 -F < shellcode.[c/py/js]\n"
|
||||
" -h help ; rax2 -h\n"
|
||||
" -i dump as C byte array ; rax2 -i < bytes\n"
|
||||
" -I IP address <-> LONG ; rax2 -I 3530468537\n"
|
||||
" -j json format output ; rax2 -j 0x1234 # same as r2 -c '?j 0x1234'\n"
|
||||
" -k keep base ; rax2 -k 33+3 -> 36\n"
|
||||
" -K randomart ; rax2 -K 0x34 1020304050\n"
|
||||
" -l newline ; append newline to output (for -E/-D/-r/..\n"
|
||||
" -L bin -> hex(bignum) ; rax2 -L 111111111 # 0x1ff\n"
|
||||
" -n binary number ; rax2 -n 0x1234 # 34120000\n"
|
||||
" -N binary number ; rax2 -N 0x1234 # \\x34\\x12\\x00\\x00\n"
|
||||
" -n newline ; append newline to output (for -E/-D/-r/..)\n"
|
||||
" -o octalstr -> raw ; rax2 -o \\162 \\62 # r2\n"
|
||||
" -r r2 style output ; rax2 -r 0x1234 # same as r2 -c '? 0x1234'\n"
|
||||
" -s hexstr -> raw ; rax2 -s 43 4a 50\n"
|
||||
|
@ -190,7 +193,8 @@ static int help(void) {
|
|||
" -u units ; rax2 -u 389289238 # 317.0M\n"
|
||||
" -v version ; rax2 -v\n"
|
||||
" -w signed word ; rax2 -w 16 0xffff\n"
|
||||
" -x hash string ; rax2 -x linux osx\n"
|
||||
" -x output in hexpairs ; rax2 -x 0x1234 # 34120000\n"
|
||||
" -X hash string ; rax2 -X linux osx\n"
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
@ -208,7 +212,7 @@ static bool invalid_length(ut64 flags) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm) {
|
||||
static bool rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm, PJ **pj) {
|
||||
const char *errstr = NULL;
|
||||
ut64 flags = *_flags;
|
||||
ut8 *buf;
|
||||
|
@ -237,7 +241,7 @@ static bool rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm)
|
|||
if (*str == '-') {
|
||||
while (str[1] && str[1] != ' ') {
|
||||
switch (str[1]) {
|
||||
case 'l':
|
||||
case 'n':
|
||||
*_flags |= RAX2_FLAG_NEWLINE;
|
||||
flags = *_flags;
|
||||
break;
|
||||
|
@ -248,18 +252,18 @@ static bool rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm)
|
|||
case 'e': flags ^= RAX2_FLAG_SWAPENDIAN; break;
|
||||
case 'S': flags ^= RAX2_FLAG_RAW2HEXSTR; break;
|
||||
case 'b': flags ^= RAX2_FLAG_BINSTR2RAW; break;
|
||||
case 'x': flags ^= RAX2_FLAG_HASHSTRING; break;
|
||||
case 'X': flags ^= RAX2_FLAG_HASHSTRING; break;
|
||||
case 'k': flags ^= RAX2_FLAG_KEEPBASE; break;
|
||||
case 'f': flags ^= RAX2_FLAG_FLOATING; break;
|
||||
case 'd': flags ^= RAX2_FLAG_DECIMAL; break;
|
||||
case 'K': flags ^= RAX2_FLAG_RANDOMART; break;
|
||||
case 'n': flags ^= RAX2_FLAG_BINARYNUM; break;
|
||||
case 'x': flags ^= RAX2_FLAG_BINARYNUM; break;
|
||||
case 'u': flags ^= RAX2_FLAG_SHOWUNITS; break;
|
||||
case 't': flags ^= RAX2_FLAG_TIMESTAMP; break;
|
||||
case 'E': flags ^= RAX2_FLAG_B64ENCODE; break;
|
||||
case 'D': flags ^= RAX2_FLAG_B64DECODE; break;
|
||||
case 'F': flags ^= RAX2_FLAG_SLURPHEX; break;
|
||||
case 'N': flags ^= RAX2_FLAG_BINARYRAW; break;
|
||||
case 'c': flags ^= RAX2_FLAG_BINARYRAW; break;
|
||||
case 'w': flags ^= RAX2_FLAG_SIGNEDWORD; break;
|
||||
case 'B': flags ^= RAX2_FLAG_STR2HEXSTR; break;
|
||||
case 'r': flags ^= RAX2_FLAG_MANYBASES; break;
|
||||
|
@ -267,10 +271,11 @@ static bool rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm)
|
|||
case 'i': flags ^= RAX2_FLAG_DUMPCSTR; break;
|
||||
case 'o': flags ^= RAX2_FLAG_OCTAL2RAW; break;
|
||||
case 'I': flags ^= RAX2_FLAG_IPADDR2NUM; break;
|
||||
case 'j': flags ^= RAX2_FLAG_JSONBASES; break;
|
||||
case 'v': return r_main_version_print ("rax2", 0);
|
||||
case '\0':
|
||||
*_flags = flags;
|
||||
return !use_stdin (num, _flags, fm);
|
||||
return !use_stdin (num, _flags, fm, pj);
|
||||
default:
|
||||
/* not as complete as for positive numbers */
|
||||
out_mode = (flags ^ 32)? '0': 'I';
|
||||
|
@ -289,7 +294,7 @@ static bool rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm)
|
|||
}
|
||||
*_flags = flags;
|
||||
if (last) {
|
||||
return !use_stdin (num, _flags, fm);
|
||||
return !use_stdin (num, _flags, fm, pj);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -347,7 +352,7 @@ dotherax:
|
|||
}
|
||||
return true;
|
||||
}
|
||||
if (flags & RAX2_FLAG_HASHSTRING) { // -x
|
||||
if (flags & RAX2_FLAG_HASHSTRING) { // -X
|
||||
int h = r_str_hash (str);
|
||||
printf ("0x%x\n", h);
|
||||
return true;
|
||||
|
@ -382,7 +387,7 @@ dotherax:
|
|||
free (m);
|
||||
return true;
|
||||
}
|
||||
if (flags & RAX2_FLAG_BINARYNUM) { // -n
|
||||
if (flags & RAX2_FLAG_BINARYNUM) { // -x
|
||||
ut64 n = r_num_calc (num, str, &errstr);
|
||||
if (errstr) {
|
||||
R_LOG_ERROR (errstr);
|
||||
|
@ -436,7 +441,7 @@ dotherax:
|
|||
}
|
||||
printf ("%" PFMT64d "\n", n);
|
||||
return true;
|
||||
} else if (flags & RAX2_FLAG_BINARYRAW) { // -N
|
||||
} else if (flags & RAX2_FLAG_BINARYRAW) { // -c
|
||||
ut64 n = r_num_calc (num, str, &errstr);
|
||||
if (errstr) {
|
||||
R_LOG_ERROR (errstr);
|
||||
|
@ -591,14 +596,73 @@ dotherax:
|
|||
printf ("double %lf\n", d);
|
||||
printf ("binary 0b%s\n", out);
|
||||
|
||||
/* ternary */
|
||||
r_num_to_ternary (out, n);
|
||||
printf ("ternary 0t%s\n", out);
|
||||
|
||||
// base36
|
||||
char b36str[16];
|
||||
b36_fromnum (b36str, n);
|
||||
printf ("base36 %s\n", b36str);
|
||||
|
||||
/* ternary */
|
||||
r_num_to_ternary (out, n);
|
||||
printf ("ternary 0t%s\n", out);
|
||||
|
||||
return true;
|
||||
} else if (flags & RAX2_FLAG_JSONBASES) {
|
||||
r_strf_buffer (256);
|
||||
char unit[8];
|
||||
char out[128];
|
||||
ut32 n32, s, a;
|
||||
double d;
|
||||
float f;
|
||||
const char *errstr = NULL;
|
||||
ut64 n = r_num_calc (num, str, &errstr);
|
||||
if (errstr) {
|
||||
R_LOG_ERROR (errstr);
|
||||
return false;
|
||||
}
|
||||
if (num->dbz) { // XXX should be done in errstr already
|
||||
R_LOG_ERROR ("division by zero");
|
||||
return false;
|
||||
}
|
||||
n32 = (ut32) (n & UT32_MAX);
|
||||
|
||||
if (!*pj) {
|
||||
*pj = pj_new ();
|
||||
pj_o (*pj);
|
||||
}
|
||||
|
||||
pj_ks (*pj, "int32", r_strf ("%d", (st32)(n & UT32_MAX)));
|
||||
pj_ks (*pj, "uint32", r_strf ("%u", (ut32)n));
|
||||
pj_ks (*pj, "int64", r_strf ("%"PFMT64d, (st64)n));
|
||||
pj_ks (*pj, "uint64", r_strf ("%"PFMT64u, (ut64)n));
|
||||
pj_ks (*pj, "hex", r_strf ("0x%08"PFMT64x, n));
|
||||
pj_ks (*pj, "octal", r_strf ("0%"PFMT64o, n));
|
||||
|
||||
/* decimal, hexa, octal */
|
||||
s = n >> 16 << 12;
|
||||
a = n & 0x0fff;
|
||||
r_num_units (unit, sizeof (unit), n);
|
||||
|
||||
pj_ks (*pj, "unit", unit);
|
||||
pj_ks (*pj, "segment", r_strf ("%04x:%04x", s, a));
|
||||
|
||||
/* binary and floating point */
|
||||
r_str_bits64 (out, n);
|
||||
memcpy (&f, &n32, sizeof (f));
|
||||
memcpy (&d, &n, sizeof (d));
|
||||
|
||||
pj_ks (*pj, "fvalue", r_strf ("%.1lf", num->fvalue));
|
||||
pj_ks (*pj, "float", r_strf ("%ff", f));
|
||||
pj_ks (*pj, "double", r_strf ("%lf", d));
|
||||
pj_ks (*pj, "binary", r_strf ("0b%s", out));
|
||||
char b36str[16];
|
||||
b36_fromnum (b36str, n);
|
||||
pj_ks (*pj, "base36", b36str);
|
||||
r_num_to_ternary (out, n);
|
||||
pj_ks (*pj, "ternary", r_strf ("0t%s", out));
|
||||
|
||||
if (last) {
|
||||
pj_end (*pj);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (flags & RAX2_FLAG_BINSTR2HEX) { // -L
|
||||
|
@ -726,16 +790,21 @@ R_API int r_main_rax2(int argc, const char **argv) {
|
|||
} else {
|
||||
RNum *num = r_num_new (NULL, NULL, NULL);
|
||||
ut64 flags = 0;
|
||||
PJ *pj = NULL;
|
||||
for (i = 1; i < argc; i++) {
|
||||
char *argv_i = strdup (argv[i]);
|
||||
if (argv_i) {
|
||||
len = r_str_unescape (argv_i);
|
||||
if (!rax (num, argv_i, len, i == argc - 1, &flags, &fm)) {
|
||||
if (!rax (num, argv_i, len, i == argc - 1, &flags, &fm, &pj)) {
|
||||
rc = 1;
|
||||
}
|
||||
free (argv_i);
|
||||
}
|
||||
}
|
||||
if (pj) {
|
||||
printf ("%s\n", pj_string (pj));
|
||||
pj_free (pj);
|
||||
}
|
||||
r_num_free (num);
|
||||
}
|
||||
return rc;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2014-2023 - pancake */
|
||||
/* radare - LGPL - Copyright 2014-2024 - pancake */
|
||||
|
||||
/* this helper api is here because it depends on r_util and r_socket */
|
||||
/* we should find a better place for it. r_io? */
|
||||
|
@ -478,7 +478,7 @@ static bool handle_redirection(const char *cmd, bool in, bool out, bool err) {
|
|||
R_LOG_ERROR ("Cannot create pipe");
|
||||
#elif R2__UNIX__
|
||||
if (in) {
|
||||
int pipes[2];
|
||||
int pipes[2] = { -1, -1 };
|
||||
if (pipe (pipes) != -1) {
|
||||
size_t cmdl = strlen (cmd)-2;
|
||||
if (write (pipes[1], cmd + 1, cmdl) != cmdl) {
|
||||
|
@ -1094,7 +1094,7 @@ R_API bool r_run_config_env(RRunProfile *p) {
|
|||
}
|
||||
if (p->_input) {
|
||||
char *inp;
|
||||
int f2[2];
|
||||
int f2[2] = { -1, -1 };
|
||||
if (pipe (f2) != -1) {
|
||||
close (0);
|
||||
#if !__wasi__
|
||||
|
|
|
@ -333,7 +333,7 @@ R_API int r_str_scanf(const char *buffer, const char *format, ...) {
|
|||
*long_ptr = (long) strtol (buf_ptr, &end_ptr, base);
|
||||
} else if ('L' == length_mod) {
|
||||
ut64_ptr = va_arg (args, ut64*);
|
||||
_BSCANF_CHECK_NULL (long_ptr);
|
||||
_BSCANF_CHECK_NULL (ut64_ptr);
|
||||
*ut64_ptr = (ut64) strtoll (buf_ptr, &end_ptr, base);
|
||||
} else if ('h' == length_mod) {
|
||||
short_ptr = va_arg (args, short*);
|
||||
|
|
205
libr/util/pie.c
205
libr/util/pie.c
|
@ -1,93 +1,154 @@
|
|||
/* radare2 - LGPL - Copyright 2018-2021 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2018-2024 - pancake */
|
||||
|
||||
#include <r_util.h>
|
||||
#include <r_util/r_print.h>
|
||||
#include <math.h>
|
||||
#define PI 3.1415
|
||||
#define O out[x + (y * size)]
|
||||
#define USE_SINCOS 0
|
||||
|
||||
// TODO: add support for colors
|
||||
// TODO: better rounding ascii art
|
||||
// TODO: add support for xy_factor
|
||||
#if 1
|
||||
#define A(c) out[(x+half) + ((y+half) * (half*2))] = c
|
||||
#else
|
||||
printf ("%c%c", c, c);
|
||||
#endif
|
||||
|
||||
static void drawSectorLine(char *out, int size, int percent) {
|
||||
int i, x, y;
|
||||
double A = (percent)*PI / 50;
|
||||
double foo = 0.1;
|
||||
for (i = (size - 1) / 2; i < (size - 3); i++) {
|
||||
x = y = (size - 1) / 2;
|
||||
x += (int)(cos (A) * foo + 1);
|
||||
y += (int)(sin (A) * foo + 1);
|
||||
foo += 1.1;
|
||||
O = '.';
|
||||
static void drawPieChart(char *out, int diameter, int numSlices, int sliceSizes[], const char **text) {
|
||||
int totalDegrees = 0;
|
||||
char sliceChars[] = "0123456789";
|
||||
int sliceCharCount = sizeof (sliceChars) / sizeof (sliceChars[0]);
|
||||
int radius = diameter / 2;
|
||||
int x, y, i;
|
||||
|
||||
// Calculate the start and end angle for each slice
|
||||
int sliceAngles[11]; // max slices is 10
|
||||
sliceAngles[0] = 0; // Starting angle for the first slice
|
||||
for (i = 0; i < numSlices; i++) {
|
||||
totalDegrees += (int)(360.0 * sliceSizes[i] / 100.0);
|
||||
sliceAngles[i+1] = totalDegrees;
|
||||
// printf ("%d\n", totalDegrees);
|
||||
}
|
||||
// Add the remaining slice if the sum of parts don't cover the whole pie
|
||||
if (totalDegrees < 360) {
|
||||
numSlices++;
|
||||
sliceAngles[numSlices] = 360;
|
||||
}
|
||||
|
||||
int half = radius;
|
||||
// Draw the pie chart
|
||||
for (y = -radius; y <= radius; y++) {
|
||||
for (x = -radius; x <= radius; x++) {
|
||||
double distance = sqrt (x * x + y * y);
|
||||
// Check if the current point is within the circle
|
||||
if (distance < radius) {
|
||||
double angle = atan2(y, x) * 180 / PI;
|
||||
if (angle < 0) {
|
||||
angle += 360;
|
||||
}
|
||||
int sliceIndex = -1;
|
||||
for (i = 0; i < numSlices; i++) {
|
||||
if (angle >= sliceAngles[i] && angle < sliceAngles[i+1]) {
|
||||
sliceIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (sliceIndex != -1) {
|
||||
const char ch = sliceChars[sliceIndex % sliceCharCount];
|
||||
A (ch);
|
||||
// printf ("%c%c", ch, ch);
|
||||
} else {
|
||||
A (' ');
|
||||
// printf (" "); // Should not happen, but just in case
|
||||
}
|
||||
} else {
|
||||
A (' ');
|
||||
// printf (" ");
|
||||
}
|
||||
}
|
||||
// printf ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
R_API int r_print_pie(RPrint *p, ut64 *values, int nvalues, int size) {
|
||||
R_API void r_print_pie(R_NULLABLE RPrint *p, int nvalues, int *values, const char **text, int size) {
|
||||
if (size < 1) {
|
||||
R_LOG_WARN ("No one cant eat such smol pie");
|
||||
return;
|
||||
}
|
||||
if (nvalues > 9) {
|
||||
R_LOG_WARN ("Cant render more than 10 portions in a pie chart");
|
||||
nvalues = 9;
|
||||
}
|
||||
ut8 *nv = calloc (nvalues, sizeof (ut8));
|
||||
char *out = calloc (size, size);
|
||||
char *out = calloc (size, size * size);
|
||||
|
||||
drawPieChart (out, size, nvalues, values, text);
|
||||
|
||||
const bool use_colors = p? p->flags & R_PRINT_FLAGS_COLOR: false;
|
||||
const char *fg_colors[10] = {
|
||||
Color_GREEN,
|
||||
Color_RED,
|
||||
Color_BLUE,
|
||||
Color_MAGENTA,
|
||||
Color_CYAN,
|
||||
Color_YELLOW,
|
||||
Color_WHITE,
|
||||
Color_GREEN,
|
||||
Color_RED,
|
||||
Color_YELLOW,
|
||||
};
|
||||
const char *bg_colors[10] = {
|
||||
Color_BGGREEN,
|
||||
Color_BGRED,
|
||||
Color_BGBLUE,
|
||||
Color_BGMAGENTA,
|
||||
Color_BGCYAN,
|
||||
Color_BGYELLOW,
|
||||
Color_BGWHITE,
|
||||
Color_BGGREEN,
|
||||
Color_BGRED,
|
||||
Color_BGYELLOW,
|
||||
};
|
||||
const char *leg[20] = {0};
|
||||
int i, x, y;
|
||||
if (nv && out) {
|
||||
ut64 total = 0;
|
||||
for (i = 0; i < nvalues; i++) {
|
||||
total += values[i];
|
||||
for (i = 0; i < 20; i++) {
|
||||
leg[i] = "??";
|
||||
}
|
||||
for (i = 0; i < nvalues;i++) {
|
||||
if (text[i]) {
|
||||
leg[i] = text[i];
|
||||
}
|
||||
total /= 100;
|
||||
if (total < 1) {
|
||||
total = 1;
|
||||
}
|
||||
for (i = 0; i < nvalues; i++) {
|
||||
nv[i] = values[i] / total;
|
||||
}
|
||||
for (x = 0; x < size; x++) {
|
||||
for (y = 0; y < size; y++) {
|
||||
O = ' ';
|
||||
}
|
||||
}
|
||||
#if USE_SINCOS
|
||||
float a = 0.0;
|
||||
int s = size / 2;
|
||||
while (a < 2 * PI) {
|
||||
x = s * cos (a) + (size / 2);
|
||||
y = s * sin (a) + (size / 2);
|
||||
O = '.';
|
||||
a += 0.1;
|
||||
}
|
||||
#else
|
||||
int radius = (size - 1) / 2;
|
||||
|
||||
// draw portions
|
||||
for (x = 0; x <= 2 * radius; x++) {
|
||||
for (y = 0; y <= 2 * radius; y++) {
|
||||
double distance = sqrt ((double)(x - radius) * (x - radius) + (y - radius) * (y - radius));
|
||||
O = (distance > radius - 0.5 && distance < radius + 0.5) ? 'x' : ' ';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
int amount = 0;
|
||||
for (i = 0; i < nvalues; i++) {
|
||||
drawSectorLine (out, size, nv[i] + amount);
|
||||
amount += nv[i];
|
||||
}
|
||||
|
||||
/// render
|
||||
if (p && p->cb_printf) {
|
||||
}
|
||||
int legend_idx = 0;
|
||||
if (nv && out && p && p->cb_printf) {
|
||||
for (y = 0; y < size; y++) {
|
||||
for (x = 0; x < size; x++) {
|
||||
for (y = 0; y < size; y++) {
|
||||
p->cb_printf ("%c%c", O, O);
|
||||
const char ch = out[x + (y * size)];
|
||||
if (use_colors && isdigit (ch)) {
|
||||
const int index = ch - '0';
|
||||
// p->cb_printf ("%s··"Color_RESET, fg_colors[index]);
|
||||
p->cb_printf ("%s##"Color_RESET, fg_colors[index]);
|
||||
} else {
|
||||
p->cb_printf ("%c%c", ch, ch);
|
||||
}
|
||||
p->cb_printf ("\n");
|
||||
}
|
||||
if (y > 0 && legend_idx < nvalues) {
|
||||
if (y % 2) {
|
||||
if (leg[legend_idx]) {
|
||||
if (use_colors) {
|
||||
p->cb_printf (" %s "Color_RESET" - %s",
|
||||
bg_colors[legend_idx], leg[legend_idx]);
|
||||
} else {
|
||||
p->cb_printf (" %c%c - %s",
|
||||
'0' + legend_idx,
|
||||
'0' + legend_idx,
|
||||
leg[legend_idx]);
|
||||
}
|
||||
}
|
||||
legend_idx++;
|
||||
}
|
||||
}
|
||||
p->cb_printf ("\n");
|
||||
}
|
||||
p->cb_printf ("\n");
|
||||
}
|
||||
free (out);
|
||||
free (nv);
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
main() {
|
||||
ut64 v[] = { 10, 20, 30, 40 };
|
||||
r_print_pie (NULL, &v, 4, 20);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -229,12 +229,16 @@ R_API bool r_strbuf_prepend(RStrBuf *sb, const char *s) {
|
|||
R_API bool r_strbuf_append(RStrBuf *sb, const char *s) {
|
||||
r_return_val_if_fail (sb && s, false);
|
||||
|
||||
int l = strlen (s);
|
||||
size_t l = strlen (s);
|
||||
return r_strbuf_append_n (sb, s, l);
|
||||
}
|
||||
|
||||
R_API bool r_strbuf_append_n(RStrBuf *sb, const char *s, size_t l) {
|
||||
r_return_val_if_fail (sb && s, false);
|
||||
if (l > ST32_MAX) {
|
||||
R_LOG_WARN ("Negative length used in r_strbuf_append_n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sb->weakref) {
|
||||
return false;
|
||||
|
|
283
man/radiff2.1
283
man/radiff2.1
|
@ -1,96 +1,193 @@
|
|||
.Dd Nov 14, 2023
|
||||
.Dt RADIFF2 1
|
||||
.Sh NAME
|
||||
.Nm radiff2
|
||||
.Nd unified binary diffing utility
|
||||
.Sh SYNOPSIS
|
||||
.Nm radiff2
|
||||
.Op Fl 1AabcCdDhOrspxXvzZ
|
||||
.Op Fl B Ar baddr
|
||||
.Op Fl G Ar cmd
|
||||
.Op Fl S Ar algo
|
||||
.Op Fl g Ar sym
|
||||
.Op Fl i Ar i,s
|
||||
.Op Fl m Ar graphmode
|
||||
.Op Fl t Ar 0-100
|
||||
.Ar file1
|
||||
.Ar file2
|
||||
.Sh DESCRIPTION
|
||||
radiff2 implements many binary diffing algorithms for data and code.
|
||||
.Pp
|
||||
.Bl -tag -width Fl
|
||||
.It Fl 1
|
||||
Binary output (GDIFF format)
|
||||
.It Fl A
|
||||
Analyze binary after loading it with RCore (see -C) and use -AA to run aaaa instead of aaa.
|
||||
.It Fl a
|
||||
Specify architecture (x86, arm, ..)
|
||||
.It Fl b
|
||||
Select register size bits for given arch
|
||||
.It Fl B Ar baddr
|
||||
Specify the base address to add to the offsets in the diff listings
|
||||
.It Fl c
|
||||
Count number of differences.
|
||||
.It Fl e [k=v]
|
||||
Specify eval config vars for all RCore instances created.
|
||||
.It Fl C
|
||||
Code diffing using graphdiff algorithm. Output columns are: file-a-address, percentage of most similar function in B file | file-b-address. (Use with -A to analyze the binaries to find more functions)
|
||||
.It Fl d
|
||||
Use delta diffing (slower).
|
||||
.It Fl D
|
||||
Show disasm instead of hexpairs (honors -a arch and -b bits)
|
||||
.It Fl g Ar sym | off1,off2
|
||||
Graph diff output of given symbol, or between two functions, at given offsets: one for each binary.
|
||||
.It Fl G Ar [cmd]
|
||||
Run given command after creating each core instance
|
||||
.It Fl h
|
||||
Show usage help message.
|
||||
.It Fl i Ar i, s, c, m, f
|
||||
Compare (i)mports, (s)ymbols, (c)lassnames, (m)ethods, (f)ields from given files (radiff2 -ii /bin/ls /bin/cat)
|
||||
.It Fl j
|
||||
Use JSON for output
|
||||
.It Fl n
|
||||
Suppress address names (show only addresses) when code diffing.
|
||||
.It Fl O
|
||||
Do code diffing with opcode bytes only.
|
||||
.It Fl m Ar [graphmode]
|
||||
Specify the graph mode (i)nteractive, (k)ey-value, (j)son, (J)son2, (t)iny, (d)ot, (s)tar, (g)ml, (m)ermaid
|
||||
.It Fl p
|
||||
Use physical addressing (io.va=0)
|
||||
.It Fl q
|
||||
Quiet mode: disable colors and reduce output
|
||||
.It Fl r
|
||||
Output in radare commands as a binary patch.
|
||||
.It Fl x
|
||||
Show two column hexdump diffing.
|
||||
.It Fl X
|
||||
Show two column hexII diffing.
|
||||
.It Fl s
|
||||
Compute edit distance (no substitution, Eugene W. Myers' O(ND) diff algorithm) between two files.
|
||||
.It Fl ss
|
||||
Compute Levenshtein edit distance (substitution is allowed, O(N^2)) between two files.
|
||||
.It Fl S Ar [name, namelen, dist, size, ...]
|
||||
Specify which column of the code diffing algo use for diffing
|
||||
.It Fl t Ar 0\-100
|
||||
Choose matching threshold for binary code diffing
|
||||
.It Fl T
|
||||
Load and analyze files in separate threads, this is an experimental feature which can result on segfaults, use it with care or use it to fix thread-safety bugs.
|
||||
.It Fl u
|
||||
Unified diff output
|
||||
.It Fl U
|
||||
Unified diff output using system\'s diff program
|
||||
.It Fl v
|
||||
.TH RADIFF2 1 "radiff2 tool" "Mar 16, 2024"
|
||||
.SH NAME
|
||||
radiff2 - binary diffing utility
|
||||
.SH SYNOPSIS
|
||||
.B radiff2
|
||||
[-1abcCdeGhijnropqsSxuUvVzZ] [-A[A]] [-B #] [-g sym] [-m graph_mode][-t %] file file
|
||||
|
||||
.SH DESCRIPTION
|
||||
radiff2 is a tool from the radare2 suite designed for binary diffing code and data.
|
||||
.PP
|
||||
It supports a wide range of formats and features, including architecture and
|
||||
bits specification, delta diffing, graph diffing, and more.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B -1
|
||||
Output in Generic binary DIFF (0xd1ffd1ff magic header).
|
||||
.TP
|
||||
.B -a [arch]
|
||||
Specify architecture plugin to use (x86, arm, etc.).
|
||||
.TP
|
||||
.B -A [-A]
|
||||
Run aaa or aaaa after loading each binary (see -C).
|
||||
.TP
|
||||
.B -b [bits]
|
||||
Specify register size for architecture (16 (thumb), 32, 64, etc.).
|
||||
.TP
|
||||
.B -B [baddr]
|
||||
Define the base address to add the offsets when listing.
|
||||
.TP
|
||||
.B -c
|
||||
Count of changes.
|
||||
.TP
|
||||
.B -C
|
||||
Graphdiff code (columns: off-A, match-ratio, off-B) (see -A).
|
||||
.TP
|
||||
.B -d
|
||||
Use delta diffing.
|
||||
.TP
|
||||
.B -D
|
||||
Show disasm instead of hexpairs.
|
||||
.TP
|
||||
.B -e [k=v]
|
||||
Set eval config var value for all RCore instances.
|
||||
.TP
|
||||
.B -g [arg]
|
||||
Graph diff of [sym] or functions in [off1,off2].
|
||||
.TP
|
||||
.B -G [cmd]
|
||||
Run an r2 command on every RCore instance created.
|
||||
.TP
|
||||
.B -i [ifscm]
|
||||
Diff imports | fields | symbols | classes | methods.
|
||||
.TP
|
||||
.B -j
|
||||
Output in JSON format.
|
||||
.TP
|
||||
.B -m [mode]
|
||||
Choose the graph output mode (aditsjJ).
|
||||
.TP
|
||||
.B -n
|
||||
Print bare addresses only (diff.bare=1).
|
||||
.TP
|
||||
.B -O
|
||||
Code diffing with opcode bytes only.
|
||||
.TP
|
||||
.B -p
|
||||
Use physical addressing (io.va=false) (only for radiff2 -AC).
|
||||
.TP
|
||||
.B -q
|
||||
Quiet mode (disable colors, reduce output).
|
||||
.TP
|
||||
.B -r
|
||||
Output in radare commands.
|
||||
.TP
|
||||
.B -s
|
||||
Compute edit distance (no substitution, Eugene W. Myers' O(ND) diff algorithm).
|
||||
.TP
|
||||
.B -ss
|
||||
Compute Levenshtein edit distance (substitution is allowed, O(N^2)).
|
||||
.TP
|
||||
.B -S [name]
|
||||
Sort code diff (name, namelen, addr, size, type, dist) (only for -C or -g).
|
||||
.TP
|
||||
.B -t [0-100]
|
||||
Set threshold for code diff (default is 70%).
|
||||
.TP
|
||||
.B -T
|
||||
Analyze files in threads (EXPERIMENTAL, 30% faster and crashy).
|
||||
.TP
|
||||
.B -u
|
||||
Unified output (---+++).
|
||||
.TP
|
||||
.B -U
|
||||
Unified output using system 'diff'.
|
||||
.TP
|
||||
.B -v
|
||||
Show version information.
|
||||
.It Fl V
|
||||
Be verbose sometimes
|
||||
.It Fl z
|
||||
Perform diff on extracted strings
|
||||
.It Fl Z
|
||||
Perform diff using zignatures instead of function list (NEW)
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Pp
|
||||
.Xr radare2(1)
|
||||
.Sh AUTHORS
|
||||
.TP
|
||||
.B -V
|
||||
Be verbose (current only for -s).
|
||||
.TP
|
||||
.B -x
|
||||
Show two-column hexdump diffing.
|
||||
.TP
|
||||
.B -X
|
||||
Show two-column hexII diffing.
|
||||
.TP
|
||||
.B -z
|
||||
Diff on extracted strings.
|
||||
.TP
|
||||
.B -Z
|
||||
Diff code comparing zignatures.
|
||||
|
||||
.SH "GRAPH OUTPUT FORMATS (-m [mode])"
|
||||
.TP
|
||||
.B .
|
||||
default is ASCII art.
|
||||
.TP
|
||||
.B s
|
||||
r2 commands.
|
||||
.TP
|
||||
.B d
|
||||
Graphviz dot.
|
||||
.TP
|
||||
.B g
|
||||
Graph Modelling Language (gml).
|
||||
.TP
|
||||
.B j
|
||||
JSON.
|
||||
.TP
|
||||
.B J
|
||||
JSON with disarm.
|
||||
.TP
|
||||
.B k
|
||||
sdb key-value.
|
||||
.TP
|
||||
.B t
|
||||
Tiny ascii art.
|
||||
.TP
|
||||
.B i
|
||||
Interactive ascii art.
|
||||
|
||||
.SH USAGE EXAMPLES
|
||||
.TP
|
||||
.B "Comparing two binaries"
|
||||
radiff2 bin1 bin2
|
||||
.TP
|
||||
.B "Using graph diffing to compare functions by name"
|
||||
radiff2 -g main bin1 bin2
|
||||
.TP
|
||||
.B "Counting the number of changes between two binaries"
|
||||
radiff2 -c bin1 bin2
|
||||
.TP
|
||||
.B "Outputting the diff in a unified format"
|
||||
radiff2 -u bin1 bin2
|
||||
.TP
|
||||
.B "Comparing the opcodes of two functions"
|
||||
radiff2 -O bin1 bin2
|
||||
|
||||
.SH 'C' COMMAND IN R2
|
||||
The 'c' command in r2 is used for various comparison operations within data inside the same file. Here are some examples of its usage:
|
||||
|
||||
.TP
|
||||
.B Compare a plain string with escaped chars
|
||||
c "string to compare"
|
||||
|
||||
.TP
|
||||
.B Compare byte at a specific address with current offset
|
||||
c1 0x100
|
||||
|
||||
.TP
|
||||
.B Compare block size bytes from current offset and the 0x100 offset
|
||||
cc 0x100
|
||||
|
||||
.TP
|
||||
.B Unified diff of disassembly from current seek and given address
|
||||
cud 0x200 @ 0x100
|
||||
|
||||
.TP
|
||||
.B Compare memory hexdumps in unified diff format
|
||||
cu 0x100 @ 0x200
|
||||
|
||||
For more detailed usage of the 'c' command, refer to the `c[?dfx] [argument]` help section.
|
||||
|
||||
|
||||
.SH SEE ALSO
|
||||
radare2(1)
|
||||
|
||||
.Sh WWW
|
||||
.Pp
|
||||
https://www.radare.org/
|
||||
.SH AUTHOR
|
||||
pancake <pancake@nopcode.org>
|
||||
|
|
94
man/rax2.1
94
man/rax2.1
|
@ -1,4 +1,4 @@
|
|||
.Dd Dec 28, 2023
|
||||
.Dd Mar 19, 2024
|
||||
.Dt RAX2 1
|
||||
.Sh NAME
|
||||
.Nm rax2
|
||||
|
@ -10,48 +10,76 @@
|
|||
.Sh DESCRIPTION
|
||||
This command is part of the radare project.
|
||||
.Pp
|
||||
This command allows you to convert values between positive and negative integer, float, octal, binary and hexadecimal values.
|
||||
Rax2 is a powerful calculator within the Radare2 suite, primarily used for
|
||||
numerical system conversions, encoding and decoding C strings, hexpairs, and
|
||||
base64, essential for binary analysis and reverse engineering tasks.
|
||||
.Pp
|
||||
The most common numerical bases include binary (base 2) for direct machine code
|
||||
interaction, hexadecimal (base 16) for memory addresses and compact data
|
||||
representation, and decimal (base 10) for human-readable calculations and
|
||||
interpretations.
|
||||
.Sh OPTIONS
|
||||
.Bl -tag -width Fl
|
||||
.It Fl a
|
||||
Show ASCII table
|
||||
.It Fl b
|
||||
Convert from binary string to character (rax2 \-b 01000101)
|
||||
.It Fl k
|
||||
Keep the same base as the input data
|
||||
.It Fl B
|
||||
Convert from character string to binary (rax2 \-B hello)
|
||||
.It Fl c
|
||||
Show hexadecimal C string from integer value
|
||||
.It Fl d
|
||||
Print the result in decimal (base 10)
|
||||
.It Fl D
|
||||
Decode the input data using base64
|
||||
.It Fl e
|
||||
Swap endian.
|
||||
Swap endianness
|
||||
.It Fl E
|
||||
Encode the input data using base64
|
||||
.It Fl f
|
||||
Interpret the input number as a 32bit dword and display it using IEEE 754
|
||||
standard for floating point arithmetic
|
||||
.It Fl F
|
||||
Read C strings from stdin and output in hexpairs. Useful to load shellcodes
|
||||
.It Fl h
|
||||
Show usage help message
|
||||
.It Fl k
|
||||
Keep the same base as the input data
|
||||
.It Fl K
|
||||
Show randomart key asciiart for values or hexpairs
|
||||
.It Fl i
|
||||
Dump stdin to C array in stdout (xxd replacement)
|
||||
.It Fl I
|
||||
Convert LONG to/from IP ADDRESS
|
||||
.It Fl l
|
||||
Append newline to the decoded output for human friendly-ness
|
||||
.It Fl K
|
||||
Show randomart key asciiart for values or hexpairs
|
||||
.It Fl j
|
||||
Show the output in json format, the same as the r2 `?j 0x804` command.
|
||||
.It Fl L
|
||||
Convert a bit stream (an arbitrary sequence of 0 and 1 of any length) to
|
||||
hexadecimal. The result can be larger than 64bits
|
||||
.It Fl n
|
||||
Append newline to the decoded output for human friendlyness
|
||||
.It Fl o
|
||||
Convert from octal string to char (rax2 -o 162 62)
|
||||
.It Fl r
|
||||
Show the same output as the r2's `? 0x804` command.
|
||||
When combined with -S (-rS) it will print r2 commands to write the actual binary into radare2
|
||||
.It Fl s
|
||||
Convert from hex string to character (rax2 \-s 43 4a 50)
|
||||
Convert from hex pairs string to character (rax2 \-s 43 4a 50)
|
||||
.It Fl S
|
||||
Convert from character to hex string (rax2 \-S C J P)
|
||||
.It Fl n
|
||||
Show hexpairs from integer value
|
||||
.It Fl N
|
||||
Show hexadecimal C string from integer value
|
||||
.It Fl t
|
||||
Convert epoch timestamp to human readable date format
|
||||
.It Fl u
|
||||
Convert given value to human readable units format
|
||||
.It Fl v
|
||||
Show program version
|
||||
.It Fl w
|
||||
Display the result as 16bit signed integer value
|
||||
.It Fl x
|
||||
Show hexpairs from integer value
|
||||
.It Fl X
|
||||
Convert a string into a hash
|
||||
.It Fl h
|
||||
Show usage help message
|
||||
.It Fl o
|
||||
Convert from octal string to char (rax2 -o 162 62)
|
||||
.El
|
||||
.Sh USAGE
|
||||
.Sh OUTPUT BASES
|
||||
.Pp
|
||||
Force output mode (numeric base)
|
||||
.Pp
|
||||
|
@ -62,6 +90,7 @@ Force output mode (numeric base)
|
|||
=10 decimal
|
||||
=16 hexadecimal
|
||||
.Pp
|
||||
.Sh USAGE
|
||||
Available variable types are:
|
||||
.Pp
|
||||
int \-> hex rax2 10
|
||||
|
@ -77,6 +106,7 @@ Available variable types are:
|
|||
bin \-> hex rax2 1100011b
|
||||
hex \-> bin rax2 Bx63
|
||||
.Pp
|
||||
.Sh EXAMPLES
|
||||
With no arguments, rax2 reads values from stdin. You can pass one or more values
|
||||
as arguments.
|
||||
.Pp
|
||||
|
@ -90,17 +120,35 @@ You can do 'unpack' hexpair encoded strings easily.
|
|||
$ rax2 \-s 41 42 43
|
||||
ABC
|
||||
.Pp
|
||||
And it supports some math operations.
|
||||
It supports some math operations:
|
||||
.Pp
|
||||
$ rax2
|
||||
0x5*101b+5
|
||||
$ rax2 1+1 "0x5*101b+5"
|
||||
2
|
||||
30
|
||||
.Pp
|
||||
Encode and decode binary file using base64:
|
||||
.Pp
|
||||
$ rax2 -E < /bin/ls > ls.b64
|
||||
$ rax2 -D < ls.b64 > ls
|
||||
.Pp
|
||||
$ cmp /bin/ls ls && echo $?
|
||||
0
|
||||
.Pp
|
||||
Use -B/-b to convert between binary and hexadecimal:
|
||||
.Pp
|
||||
$ rax2 -B 0x1123
|
||||
001100000111100000110001001100010011001000110011
|
||||
$ rax2 -b 001100000111100000110001001100010011001000110011
|
||||
0x1123
|
||||
.Pp
|
||||
It is a very useful tool for scripting, so you can read floating point values, or get the integer offset of a jump or a stack delta when analyzing programs.
|
||||
.Pp
|
||||
.Sh SEE ALSO
|
||||
.Pp
|
||||
.Xr radare2(1)
|
||||
.Sh WWW
|
||||
.Pp
|
||||
https://www.radare.org
|
||||
.Sh AUTHORS
|
||||
.Pp
|
||||
Written by pancake <pancake@nopcode.org>.
|
||||
|
|
|
@ -45,9 +45,16 @@ all::
|
|||
exit 1
|
||||
endif
|
||||
|
||||
ifeq ($(shell type llvm-ar > /dev/null && echo ok),ok)
|
||||
AR=llvm-ar
|
||||
RANLIB=llvm-ranlib
|
||||
CC_AR=llvm-ar -r ${LIBAR}
|
||||
else
|
||||
RANLIB=${CROSS}ranlib
|
||||
AR=${CROSS}ar
|
||||
CC_AR=${CROSS}ar -r ${LIBAR}
|
||||
endif
|
||||
|
||||
PARTIALLD=${CROSS}ld -r
|
||||
# -all_load
|
||||
ONELIB=0
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
ifeq (${_INCLUDE_MK_GCC_},)
|
||||
_INCLUDE_MK_GCC_=1
|
||||
CC?=ndk-gcc
|
||||
CC?=ndk-gcc -fPIC
|
||||
OBJCOPY?=objcopy
|
||||
RANLIB?=ranlib
|
||||
ONELIB=0
|
||||
AR?=ar
|
||||
CC_AR=${AR} q ${LIBAR}
|
||||
CFLAGS+=-MD
|
||||
CFLAGS+=-MD -fPIC
|
||||
CFLAGS_INCLUDE=-I
|
||||
LDFLAGS_LINK=-l
|
||||
LDFLAGS_LINKPATH=-L
|
||||
|
|
|
@ -56,7 +56,7 @@ ifeq ($(USE_CS4),1)
|
|||
CS_TIP=0efa3cc530ea188c0e03c945ab884ee19dd16342
|
||||
CS_BRA=v4
|
||||
else
|
||||
CS_TIP=58528853111377ba2f8ecb781f8d3bdc595900ed
|
||||
CS_TIP=2971910d6eedfa52174854d89b9de7fc1d755b90
|
||||
CS_BRA=v5
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -25,7 +25,7 @@ if not capstone_dep.found() or not get_option('use_sys_capstone')
|
|||
'fix-x86-16.patch',
|
||||
]
|
||||
elif capstone_version == 'v5'
|
||||
CS_TIP = '58528853111377ba2f8ecb781f8d3bdc595900ed'
|
||||
CS_TIP = '2971910d6eedfa52174854d89b9de7fc1d755b90'
|
||||
CS_BRA = 'v5'
|
||||
patches_files = [
|
||||
'fix-x86-16.patch'
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
BUILD=1
|
||||
FLAGS=""
|
||||
PREFIX="/data/data/org.radare.radare2installer/radare2"
|
||||
export PAGER=cat
|
||||
MAKE=make
|
||||
gmake --help >/dev/null 2>&1
|
||||
[ $? = 0 ] && MAKE=gmake
|
||||
|
@ -59,7 +60,7 @@ x64-static|static-x64)
|
|||
NDK_ARCH=x86
|
||||
STATIC_BUILD=1
|
||||
;;
|
||||
arm64-static|static-arm64)
|
||||
aarch64-static|static-aarch64|arm64-static|static-arm64)
|
||||
NDK_ARCH=aarch64
|
||||
STATIC_BUILD=1
|
||||
;;
|
||||
|
@ -127,7 +128,7 @@ if [ "${BUILD}" = 1 ]; then
|
|||
echo ./configure --with-compiler=android \
|
||||
--with-ostype=android \
|
||||
--prefix=${PREFIX} ${CFGFLAGS}
|
||||
cp -f plugins.android.cfg plugins.cfg
|
||||
cp -f dist/plugins-cfg/plugins.android.cfg plugins.cfg
|
||||
./configure --with-compiler=android --with-ostype=android \
|
||||
--prefix=${PREFIX} ${CFGFLAGS} || exit 1
|
||||
${MAKE} -s -j 4 || exit 1
|
||||
|
@ -159,7 +160,6 @@ rm -rf "${HERE}/${D}/${PREFIX}/bin/r2pm"
|
|||
|
||||
# use busybox style symlinkz
|
||||
cd binr/blob
|
||||
#${MAKE} || exit 1
|
||||
#CFLAGS=-static LDFLAGS=-static ${MAKE} -j4 || exit 1
|
||||
${MAKE} -j4 || exit 1
|
||||
${MAKE} install PREFIX="${PREFIX}" DESTDIR="${HERE}/${D}" || exit 1
|
||||
|
|
|
@ -60,6 +60,11 @@ if [ ! -x /work ]; then
|
|||
echo "Using data from ${HOME}/.r2androidrc.."
|
||||
else
|
||||
#[ -z "${SDK}" ] && SDK="${HOME}/Downloads/android-sdk-${OS}"
|
||||
if [ -z "${NDK}" ]; then
|
||||
if [ -d /usr/lib/android-ndk ]; then
|
||||
NDK="/usr/lib/android-ndk" # ubuntu
|
||||
fi
|
||||
fi
|
||||
if [ -z "${NDK}" ]; then
|
||||
# Checking if Android NDK is installed with macOS's brew
|
||||
D=/usr/local/Caskroom/android-ndk/
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
OSNAME=$(uname)
|
||||
unset LINK
|
||||
|
||||
. `dirname $0`/make-jobs.inc.sh
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
# find
|
||||
cd "$(dirname $0)"/..
|
||||
pwd
|
||||
export PAGER=cat
|
||||
unset LINK
|
||||
|
||||
if [ "${SHELL}" = "/data/data/com.termux/files/usr/bin/bash" ]; then
|
||||
echo "Termux environment detected. Installing necessary packages"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
cd "$(dirname $0)"/..
|
||||
pwd
|
||||
unset LINK
|
||||
|
||||
if [ -z "${PREFIX}" ]; then
|
||||
echo "PREFIX env var not set, are you running this script from Termux?"
|
||||
|
|
|
@ -112,6 +112,10 @@ EOF
|
|||
EXPECT_ERR=<<EOF
|
||||
DEBUG: RCoreCmd: =!
|
||||
DEBUG: Dynamic tag 16 not handled
|
||||
DEBUG: Reloc type 23 not used for imports
|
||||
DEBUG: Reloc type 23 not used for imports
|
||||
DEBUG: Reloc type 23 not used for imports
|
||||
DEBUG: Reloc type 23 not used for imports
|
||||
DEBUG: bin object have no information
|
||||
DEBUG: add dt.dyn.entry tag=3 value=0x0002fde8
|
||||
DEBUG: add dt.dyn.entry tag=2 value=0x00000188
|
||||
|
|
|
@ -7,7 +7,7 @@ EXPECT=<<EOF
|
|||
0x00000010 0x00000010 0x00000002 Type
|
||||
0x00000012 0x00000012 0x00000003 Machine
|
||||
0x00000014 0x00000014 0x00000001 Version
|
||||
0x00000018 0x00000018 0x08048300 Entry point
|
||||
0x00000018 0x00000018 0x08048300 EntryPoint
|
||||
0x0000001c 0x0000001c 0x00000034 PhOff
|
||||
0x00000020 0x00000020 0x000007cc ShOff
|
||||
0x00000024 0x00000024 0x00000000 Flags
|
||||
|
@ -30,7 +30,7 @@ EXPECT=<<EOF
|
|||
0x00000010 0x00000002 Type
|
||||
0x00000012 0x00000003 Machine
|
||||
0x00000014 0x00000001 Version
|
||||
0x00000018 0x08048300 Entry point
|
||||
0x00000018 0x08048300 EntryPoint
|
||||
0x0000001c 0x00000034 PhOff
|
||||
0x00000020 0x000007cc ShOff
|
||||
0x00000024 0x00000000 Flags
|
||||
|
@ -60,9 +60,9 @@ pf.Machine w
|
|||
'f header.Version 1 0x00000014
|
||||
'f header.Version.value 1 0x00000001
|
||||
pf.Version x
|
||||
'f header.Entry point 1 0x00000018
|
||||
'f header.Entry point.value 1 0x08048300
|
||||
pf.Entry point x
|
||||
'f header.EntryPoint 1 0x00000018
|
||||
'f header.EntryPoint.value 1 0x08048300
|
||||
pf.EntryPoint x
|
||||
'f header.PhOff 1 0x0000001c
|
||||
'f header.PhOff.value 1 0x00000034
|
||||
pf.PhOff x
|
||||
|
@ -155,7 +155,7 @@ EXPECT=<<EOF
|
|||
]
|
||||
},
|
||||
{
|
||||
"name": "Entry point",
|
||||
"name": "EntryPoint",
|
||||
"vaddr": 24,
|
||||
"paddr": 24,
|
||||
"value": 134513408,
|
||||
|
|
|
@ -224,7 +224,7 @@ EXPECT=<<EOF
|
|||
EOF
|
||||
RUN
|
||||
|
||||
NAME=swap endianess
|
||||
NAME=swap endianness
|
||||
FILE=malloc://1024
|
||||
CMDS=<<EOF
|
||||
wx deadbeef00000000adde
|
||||
|
|
|
@ -34,4 +34,16 @@ SHA512_Constants
|
|||
0x0000000c: yara0_SHA512_Constants_3 : d728ae22
|
||||
0x00000010: yara0_SHA512_Constants_4 : 22ae28d7
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=yara: versions
|
||||
FILE=malloc://1024
|
||||
CMDS=<<EOF
|
||||
yrv~yara?
|
||||
yara version~yara?
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
2
|
||||
2
|
||||
EOF
|
||||
RUN
|
|
@ -0,0 +1,135 @@
|
|||
NAME=random39855 relocs
|
||||
FILE=bins/elf/random_39855/random_39855.o
|
||||
CMDS=<<EOF
|
||||
s sym.func_9
|
||||
e emu.str=true
|
||||
af
|
||||
pd 20
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
/ 628: sym.func_9 (int64_t arg1, int64_t arg2, int64_t arg3, int64_t arg4, int64_t arg5, int64_t arg_120h);
|
||||
| ; arg int64_t arg1 @ x0
|
||||
| ; arg int64_t arg2 @ x1
|
||||
| ; arg int64_t arg3 @ x2
|
||||
| ; arg int64_t arg4 @ x3
|
||||
| ; arg int64_t arg5 @ x4
|
||||
| ; arg int64_t arg_120h @ sp+0x240
|
||||
| ; var int64_t var_ch @ sp+0xc
|
||||
| ; var int64_t var_10h @ sp+0x10
|
||||
| ; var int64_t var_18h @ sp+0x18
|
||||
| ; var int64_t var_1ch @ sp+0x1c
|
||||
| ; var int64_t var_20h @ sp+0x20
|
||||
| ; var int64_t var_28h @ sp+0x28
|
||||
| ; var int64_t var_40h @ sp+0x40
|
||||
| ; var int64_t var_4fh @ sp+0x4f
|
||||
| ; var int64_t var_50h @ sp+0x50
|
||||
| ; var int64_t var_5ch @ sp+0x5c
|
||||
| ; var int64_t var_90h @ sp+0x90
|
||||
| ; var int64_t var_100h @ sp+0x100
|
||||
| ; var int64_t var_110h @ sp+0x110
|
||||
| 0x08000800 ff8304d1 sub sp, sp, 0x120
|
||||
| 0x08000804 fd7b10a9 stp x29, x30, [sp, 0x100]
|
||||
| 0x08000808 fc8b00f9 str x28, [sp, 0x110]
|
||||
| 0x0800080c fd030491 add x29, var_100h
|
||||
| 0x08000810 a92301d1 sub x9, x29, 0x48
|
||||
| 0x08000814 e91300f9 str x9, [sp, 0x20]
|
||||
| 0x08000818 e90308aa mov x9, x8
|
||||
| 0x0800081c e81340f9 ldr x8, [var_20h] ; 0x5 ; 5
|
||||
| 0x08000820 e21700f9 str x2, [sp, 0x28] ; arg3
|
||||
| 0x08000824 002100f9 str x0, [x8, 0x40] ; arg1
|
||||
| 0x08000828 011d00f9 str x1, [x8, 0x38] ; arg2
|
||||
| 0x0800082c 031900f9 str x3, [x8, 0x30] ; arg4
|
||||
| 0x08000830 041500f9 str x4, [x8, 0x28] ; arg5
|
||||
| 0x08000834 08000090 adrp x8, segment.ehdr ; 0x8000000; RELOC 32 .rodata @ 0x080057f8 + 0x18
|
||||
| 0x08000838 08010091 add x8, x8, 0 ; RELOC 32 .rodata @ 0x080057f8 + 0x18 ; segment.ehdr
|
||||
| 0x0800083c 0001c03d ldr q0, [x8] ; 0xe2 ; 226 ; segment.ehdr
|
||||
| 0x08000840 2001803d str q0, [x9]
|
||||
| 0x08000844 080940f9 ldr x8, [x8, 0x10] ; 0xe2 ; 226
|
||||
| 0x08000848 280900f9 str x8, [x9, 0x10]
|
||||
| 0x0800084c 5f0000b9 str wzr, [x2] ; arg3
|
||||
EOF
|
||||
EXPECT_ERR=<<EOF
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08000074
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x080000a0
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08000168
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08000200
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08000750
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08000834
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08000874
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08000ae4
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08000b00
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08001568
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08001574
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08001bec
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08001c0c
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08002254
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08002274
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08002298
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x080022bc
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08002830
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x0800283c
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08003444
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x080037dc
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x08003974
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x080039a4
|
||||
WARN: Poorly supported AARCH64 instruction reloc type 275 at 0x080039d8
|
||||
WARN: Relocs has not been applied. Please use `-e bin.relocs.apply=true` or `-e bin.cache=true` next time
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=random39855 relocs bin
|
||||
FILE=bins/elf/random_39855/random_39855
|
||||
CMDS=<<EOF
|
||||
e emu.str=true
|
||||
s sym.func_9
|
||||
af
|
||||
pd 20
|
||||
pxq 8 @ str.O_n_
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
/ 628: sym.func_9 (int64_t arg1, int64_t arg2, int64_t arg3, int64_t arg4, int64_t arg5, int64_t arg_120h);
|
||||
| ; arg int64_t arg1 @ x0
|
||||
| ; arg int64_t arg2 @ x1
|
||||
| ; arg int64_t arg3 @ x2
|
||||
| ; arg int64_t arg4 @ x3
|
||||
| ; arg int64_t arg5 @ x4
|
||||
| ; arg int64_t arg_120h @ sp+0x240
|
||||
| ; var int64_t var_ch @ sp+0xc
|
||||
| ; var int64_t var_10h @ sp+0x10
|
||||
| ; var int64_t var_18h @ sp+0x18
|
||||
| ; var int64_t var_1ch @ sp+0x1c
|
||||
| ; var int64_t var_20h @ sp+0x20
|
||||
| ; var int64_t var_28h @ sp+0x28
|
||||
| ; var int64_t var_40h @ sp+0x40
|
||||
| ; var int64_t var_4fh @ sp+0x4f
|
||||
| ; var int64_t var_50h @ sp+0x50
|
||||
| ; var int64_t var_5ch @ sp+0x5c
|
||||
| ; var int64_t var_90h @ sp+0x90
|
||||
| ; var int64_t var_100h @ sp+0x100
|
||||
| ; var int64_t var_110h @ sp+0x110
|
||||
| 0x00000f94 ff8304d1 sub sp, sp, 0x120
|
||||
| 0x00000f98 fd7b10a9 stp x29, x30, [sp, 0x100]
|
||||
| 0x00000f9c fc8b00f9 str x28, [sp, 0x110]
|
||||
| 0x00000fa0 fd030491 add x29, var_100h
|
||||
| 0x00000fa4 a92301d1 sub x9, x29, 0x48
|
||||
| 0x00000fa8 e91300f9 str x9, [sp, 0x20]
|
||||
| 0x00000fac e90308aa mov x9, x8
|
||||
| 0x00000fb0 e81340f9 ldr x8, [var_20h] ; 0x5
|
||||
| 0x00000fb4 e21700f9 str x2, [sp, 0x28] ; arg3
|
||||
| 0x00000fb8 002100f9 str x0, [x8, 0x40] ; arg1
|
||||
| 0x00000fbc 011d00f9 str x1, [x8, 0x38] ; arg2
|
||||
| 0x00000fc0 031900f9 str x3, [x8, 0x30] ; arg4
|
||||
| 0x00000fc4 041500f9 str x4, [x8, 0x28] ; arg5
|
||||
| 0x00000fc8 280000b0 adrp x8, 0x5000
|
||||
| 0x00000fcc 08e13e91 add x8, x8, 0xfb8 ; str.O_n_
|
||||
| 0x00000fd0 0001c03d ldr q0, [x8] ; 0xe2 ; str.O_n_
|
||||
| 0x00000fd4 2001803d str q0, [x9]
|
||||
| 0x00000fd8 080940f9 ldr x8, [x8, 0x10] ; 0xe2
|
||||
| 0x00000fdc 280900f9 str x8, [x9, 0x10]
|
||||
| 0x00000fe0 5f0000b9 str wzr, [x2] ; arg3
|
||||
0x00005fb8 0x5a8a51be3e7c0a4f O.|>.Q.Z
|
||||
EOF
|
||||
EXPECT_ERR=<<EOF
|
||||
WARN: Relocs has not been applied. Please use `-e bin.relocs.apply=true` or `-e bin.cache=true` next time
|
||||
EOF
|
||||
RUN
|
|
@ -0,0 +1,58 @@
|
|||
NAME=arm64 relocs for android
|
||||
FILE=bins/elf/libtool-checker.so
|
||||
CMDS=<<EOF
|
||||
s..ad4
|
||||
af
|
||||
pds
|
||||
?e imports
|
||||
ii
|
||||
?e relocs
|
||||
ir
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
0x00000ae0 arg1
|
||||
0x00000ae4 arg2
|
||||
0x00000ae8 arg3
|
||||
0x00000aec arg1
|
||||
0x00000af8 bl rsym._ZN7_JNIEnv14GetArrayLengthEP7_jarray
|
||||
0x00000b24 bl rsym._ZN7_JNIEnv21GetObjectArrayElementEP13_jobjectArrayi
|
||||
0x00000b3c bl rsym._ZN7_JNIEnv17GetStringUTFCharsEP8_jstringPh
|
||||
0x00000b48 bl rsym._Z6existsPKc
|
||||
0x00000b64 bl rsym._ZN7_JNIEnv21ReleaseStringUTFCharsEP8_jstringPKc
|
||||
;-- _JNIEnv::GetArrayLength(_jarray*):
|
||||
0x00000b98 _JNIEnv::GetArrayLength(_jarray*)
|
||||
;-- _JNIEnv::GetObjectArrayElement(_jobjectArray*, int):
|
||||
0x00000bd0 _JNIEnv::GetObjectArrayElement(_jobjectArray*, int)
|
||||
imports
|
||||
[Imports]
|
||||
nth vaddr bind type lib name
|
||||
-----------------------------------
|
||||
3 0x000008f0 GLOBAL FUNC __cxa_finalize
|
||||
4 0x00000920 GLOBAL FUNC fclose
|
||||
5 0x00000940 GLOBAL FUNC __android_log_print
|
||||
6 0x00000970 GLOBAL FUNC fopen
|
||||
7 0x00000980 GLOBAL FUNC __cxa_atexit
|
||||
|
||||
relocs
|
||||
[Relocations]
|
||||
|
||||
vaddr paddr type name
|
||||
---------------------------------
|
||||
0x00002d78 0x00001d78 ADD_64 0x000009a0
|
||||
0x00002d80 0x00001d80 ADD_64 0x00000990
|
||||
0x00002d88 0x00001d88 ADD_64 0x00002d88
|
||||
0x00002fa8 0x00001fa8 SET_64 __cxa_finalize
|
||||
0x00002fb0 0x00001fb0 SET_64 exists(char const*)
|
||||
0x00002fb8 0x00001fb8 SET_64 _JNIEnv::GetObjectArrayElement(_jobjectArray*, int)
|
||||
0x00002fc0 0x00001fc0 SET_64 fclose
|
||||
0x00002fc8 0x00001fc8 SET_64 _JNIEnv::GetStringUTFChars(_jstring*, unsigned char*)
|
||||
0x00002fd0 0x00001fd0 SET_64 __android_log_print
|
||||
0x00002fd8 0x00001fd8 SET_64 _JNIEnv::GetArrayLength(_jarray*)
|
||||
0x00002fe0 0x00001fe0 SET_64 _JNIEnv::ReleaseStringUTFChars(_jstring*, char const*)
|
||||
0x00002fe8 0x00001fe8 SET_64 fopen
|
||||
0x00002ff0 0x00001ff0 SET_64 __cxa_atexit
|
||||
|
||||
|
||||
13 relocations
|
||||
EOF
|
||||
RUN
|
|
@ -75,3 +75,11 @@ EXPECT=<<EOF
|
|||
ffffffffffffffffffff
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=sections list here bss
|
||||
FILE=bins/elf/analysis/main_wrong_sect
|
||||
CMDS=iS.@0x00600914~bss~?
|
||||
EXPECT=<<EOF
|
||||
1
|
||||
EOF
|
||||
RUN
|
||||
|
|
|
@ -20,69 +20,70 @@ CMDS=iS
|
|||
EXPECT=<<EOF
|
||||
[Sections]
|
||||
|
||||
nth paddr size vaddr vsize perm type name
|
||||
--------------------------------------------------------
|
||||
0 0x0000d200 0x1000 0x00010000 0x1000 -r-x ---- obj.1.page.0
|
||||
1 0x0000e200 0x1000 0x00011000 0x1000 -r-x ---- obj.1.page.1
|
||||
2 0x0000f200 0x1000 0x00012000 0x1000 -r-x ---- obj.1.page.2
|
||||
3 0x00010200 0x1000 0x00013000 0x1000 -r-x ---- obj.1.page.3
|
||||
4 0x00011200 0x1000 0x00014000 0x1000 -r-x ---- obj.1.page.4
|
||||
5 0x00012200 0x1000 0x00015000 0x1000 -r-x ---- obj.1.page.5
|
||||
6 0x00013200 0x1000 0x00016000 0x1000 -r-x ---- obj.1.page.6
|
||||
7 0x00014200 0x1000 0x00017000 0x1000 -r-x ---- obj.1.page.7
|
||||
8 0x00015200 0x1000 0x00018000 0x1000 -r-x ---- obj.1.page.8
|
||||
9 0x00016200 0x1000 0x00019000 0x1000 -r-x ---- obj.1.page.9
|
||||
10 0x00017200 0x1000 0x0001a000 0x1000 -r-x ---- obj.1.page.10
|
||||
11 0x00018200 0x1000 0x0001b000 0x1000 -r-x ---- obj.1.page.11
|
||||
12 0x00019200 0x1000 0x0001c000 0x1000 -r-x ---- obj.1.page.12
|
||||
13 0x0001a200 0x1000 0x0001d000 0x1000 -r-x ---- obj.1.page.13
|
||||
14 0x0001b200 0x1000 0x0001e000 0x1000 -r-x ---- obj.1.page.14
|
||||
15 0x0001c200 0x1000 0x0001f000 0x1000 -r-x ---- obj.1.page.15
|
||||
16 0x0001d200 0x1000 0x00020000 0x1000 -r-x ---- obj.1.page.16
|
||||
17 0x0001e200 0x1000 0x00021000 0x1000 -r-x ---- obj.1.page.17
|
||||
18 0x0001f200 0x1000 0x00022000 0x1000 -r-x ---- obj.1.page.18
|
||||
19 0x00020200 0x1000 0x00023000 0x1000 -r-x ---- obj.1.page.19
|
||||
20 0x00021200 0x1000 0x00024000 0x1000 -r-x ---- obj.1.page.20
|
||||
21 0x00022200 0x1000 0x00025000 0x1000 -r-x ---- obj.1.page.21
|
||||
22 0x00023200 0x1000 0x00026000 0x1000 -r-x ---- obj.1.page.22
|
||||
23 0x00024200 0x1000 0x00027000 0x1000 -r-x ---- obj.1.page.23
|
||||
24 0x00025200 0x1000 0x00028000 0x1000 -r-x ---- obj.1.page.24
|
||||
25 0x00026200 0x1000 0x00029000 0x1000 -r-x ---- obj.1.page.25
|
||||
26 0x00027200 0x1000 0x0002a000 0x1000 -r-x ---- obj.1.page.26
|
||||
27 0x00028200 0x1000 0x0002b000 0x1000 -r-x ---- obj.1.page.27
|
||||
28 0x00029200 0x1000 0x0002c000 0x1000 -r-x ---- obj.1.page.28
|
||||
29 0x0002a200 0x1000 0x0002d000 0x1000 -r-x ---- obj.1.page.29
|
||||
30 0x0002b200 0x1000 0x0002e000 0x1000 -r-x ---- obj.1.page.30
|
||||
31 0x0002c200 0x1000 0x0002f000 0x1000 -r-x ---- obj.1.page.31
|
||||
32 0x0002d200 0x1000 0x00030000 0x1000 -r-x ---- obj.1.page.32
|
||||
33 0x0002e200 0x1000 0x00031000 0x1000 -r-x ---- obj.1.page.33
|
||||
34 0x0002f200 0x1000 0x00032000 0x1000 -r-x ---- obj.1.page.34
|
||||
35 0x00030200 0x1000 0x00033000 0x1000 -r-x ---- obj.1.page.35
|
||||
36 0x00031200 0x1000 0x00034000 0x1000 -r-x ---- obj.1.page.36
|
||||
37 0x00032200 0x1000 0x00035000 0x1000 -r-x ---- obj.1.page.37
|
||||
38 0x00033200 0x1000 0x00036000 0x1000 -r-x ---- obj.1.page.38
|
||||
39 0x00034200 0x1000 0x00037000 0x1000 -r-x ---- obj.1.page.39
|
||||
40 0x00035200 0x1000 0x00038000 0x1000 -r-x ---- obj.1.page.40
|
||||
41 0x00036200 0x1000 0x00039000 0x1000 -r-x ---- obj.1.page.41
|
||||
42 0x00037200 0x1000 0x0003a000 0x1000 -r-x ---- obj.1.page.42
|
||||
43 0x00038200 0x1000 0x0003b000 0x1000 -r-x ---- obj.1.page.43
|
||||
44 0x00039200 0x1000 0x0003c000 0x1000 -r-x ---- obj.1.page.44
|
||||
45 0x0003a200 0x1000 0x00040000 0x1000 -rw- ---- obj.2.page.0
|
||||
46 0x0003b200 0x1000 0x00041000 0x1000 -rw- ---- obj.2.page.1
|
||||
47 0x0003c200 0x1000 0x00042000 0x1000 -rw- ---- obj.2.page.2
|
||||
48 0x0003d200 0x1000 0x00043000 0x1000 -rw- ---- obj.2.page.3
|
||||
49 0x0003e200 0x1000 0x00044000 0x1000 -rw- ---- obj.2.page.4
|
||||
50 0x0003f200 0x1000 0x00045000 0x1000 -rw- ---- obj.2.page.5
|
||||
51 0x00040200 0x1000 0x00046000 0x1000 -rw- ---- obj.2.page.6
|
||||
52 0x00041200 0x1000 0x00047000 0x1000 -rw- ---- obj.2.page.7
|
||||
53 0x00042200 0x1000 0x00048000 0x1000 -rw- ---- obj.2.page.8
|
||||
54 0x00043200 0x1000 0x00049000 0x1000 -rw- ---- obj.2.page.9
|
||||
55 0x00044200 0x1000 0x0004a000 0x1000 -rw- ---- obj.2.page.10
|
||||
56 0x00045200 0x1000 0x0004b000 0x1000 -rw- ---- obj.2.page.11
|
||||
57 0x00046200 0x1000 0x0004c000 0x1000 -rw- ---- obj.2.page.12
|
||||
58 0x00047200 0x1000 0x0004d000 0x1000 -rw- ---- obj.2.page.13
|
||||
59 0x00048200 0x1000 0x0004e000 0x1000 -rw- ---- obj.2.page.14
|
||||
60 0x00049200 0xd8c 0x0004f000 0x1000 -rw- ---- obj.2.page.15
|
||||
nth paddr size vaddr vsize perm type name
|
||||
---------------------------------------------------------
|
||||
0 0x0000d200 0x1000 0x00010000 0x1000 -r-x ---- obj.1.page.0
|
||||
1 0x0000e200 0x1000 0x00011000 0x1000 -r-x ---- obj.1.page.1
|
||||
2 0x0000f200 0x1000 0x00012000 0x1000 -r-x ---- obj.1.page.2
|
||||
3 0x00010200 0x1000 0x00013000 0x1000 -r-x ---- obj.1.page.3
|
||||
4 0x00011200 0x1000 0x00014000 0x1000 -r-x ---- obj.1.page.4
|
||||
5 0x00012200 0x1000 0x00015000 0x1000 -r-x ---- obj.1.page.5
|
||||
6 0x00013200 0x1000 0x00016000 0x1000 -r-x ---- obj.1.page.6
|
||||
7 0x00014200 0x1000 0x00017000 0x1000 -r-x ---- obj.1.page.7
|
||||
8 0x00015200 0x1000 0x00018000 0x1000 -r-x ---- obj.1.page.8
|
||||
9 0x00016200 0x1000 0x00019000 0x1000 -r-x ---- obj.1.page.9
|
||||
10 0x00017200 0x1000 0x0001a000 0x1000 -r-x ---- obj.1.page.10
|
||||
11 0x00018200 0x1000 0x0001b000 0x1000 -r-x ---- obj.1.page.11
|
||||
12 0x00019200 0x1000 0x0001c000 0x1000 -r-x ---- obj.1.page.12
|
||||
13 0x0001a200 0x1000 0x0001d000 0x1000 -r-x ---- obj.1.page.13
|
||||
14 0x0001b200 0x1000 0x0001e000 0x1000 -r-x ---- obj.1.page.14
|
||||
15 0x0001c200 0x1000 0x0001f000 0x1000 -r-x ---- obj.1.page.15
|
||||
16 0x0001d200 0x1000 0x00020000 0x1000 -r-x ---- obj.1.page.16
|
||||
17 0x0001e200 0x1000 0x00021000 0x1000 -r-x ---- obj.1.page.17
|
||||
18 0x0001f200 0x1000 0x00022000 0x1000 -r-x ---- obj.1.page.18
|
||||
19 0x00020200 0x1000 0x00023000 0x1000 -r-x ---- obj.1.page.19
|
||||
20 0x00021200 0x1000 0x00024000 0x1000 -r-x ---- obj.1.page.20
|
||||
21 0x00022200 0x1000 0x00025000 0x1000 -r-x ---- obj.1.page.21
|
||||
22 0x00023200 0x1000 0x00026000 0x1000 -r-x ---- obj.1.page.22
|
||||
23 0x00024200 0x1000 0x00027000 0x1000 -r-x ---- obj.1.page.23
|
||||
24 0x00025200 0x1000 0x00028000 0x1000 -r-x ---- obj.1.page.24
|
||||
25 0x00026200 0x1000 0x00029000 0x1000 -r-x ---- obj.1.page.25
|
||||
26 0x00027200 0x1000 0x0002a000 0x1000 -r-x ---- obj.1.page.26
|
||||
27 0x00028200 0x1000 0x0002b000 0x1000 -r-x ---- obj.1.page.27
|
||||
28 0x00029200 0x1000 0x0002c000 0x1000 -r-x ---- obj.1.page.28
|
||||
29 0x0002a200 0x1000 0x0002d000 0x1000 -r-x ---- obj.1.page.29
|
||||
30 0x0002b200 0x1000 0x0002e000 0x1000 -r-x ---- obj.1.page.30
|
||||
31 0x0002c200 0x1000 0x0002f000 0x1000 -r-x ---- obj.1.page.31
|
||||
32 0x0002d200 0x1000 0x00030000 0x1000 -r-x ---- obj.1.page.32
|
||||
33 0x0002e200 0x1000 0x00031000 0x1000 -r-x ---- obj.1.page.33
|
||||
34 0x0002f200 0x1000 0x00032000 0x1000 -r-x ---- obj.1.page.34
|
||||
35 0x00030200 0x1000 0x00033000 0x1000 -r-x ---- obj.1.page.35
|
||||
36 0x00031200 0x1000 0x00034000 0x1000 -r-x ---- obj.1.page.36
|
||||
37 0x00032200 0x1000 0x00035000 0x1000 -r-x ---- obj.1.page.37
|
||||
38 0x00033200 0x1000 0x00036000 0x1000 -r-x ---- obj.1.page.38
|
||||
39 0x00034200 0x1000 0x00037000 0x1000 -r-x ---- obj.1.page.39
|
||||
40 0x00035200 0x1000 0x00038000 0x1000 -r-x ---- obj.1.page.40
|
||||
41 0x00036200 0x1000 0x00039000 0x1000 -r-x ---- obj.1.page.41
|
||||
42 0x00037200 0x1000 0x0003a000 0x1000 -r-x ---- obj.1.page.42
|
||||
43 0x00038200 0x1000 0x0003b000 0x1000 -r-x ---- obj.1.page.43
|
||||
44 0x00039200 0x2ef 0x0003c000 0x2ef -r-x ---- obj.1.page.44
|
||||
45 0x0003a200 0x1000 0x00040000 0x1000 -rw- ---- obj.2.page.0
|
||||
46 0x0003b200 0x1000 0x00041000 0x1000 -rw- ---- obj.2.page.1
|
||||
47 0x0003c200 0x1000 0x00042000 0x1000 -rw- ---- obj.2.page.2
|
||||
48 0x0003d200 0x1000 0x00043000 0x1000 -rw- ---- obj.2.page.3
|
||||
49 0x0003e200 0x1000 0x00044000 0x1000 -rw- ---- obj.2.page.4
|
||||
50 0x0003f200 0x1000 0x00045000 0x1000 -rw- ---- obj.2.page.5
|
||||
51 0x00040200 0x1000 0x00046000 0x1000 -rw- ---- obj.2.page.6
|
||||
52 0x00041200 0x1000 0x00047000 0x1000 -rw- ---- obj.2.page.7
|
||||
53 0x00042200 0x1000 0x00048000 0x1000 -rw- ---- obj.2.page.8
|
||||
54 0x00043200 0x1000 0x00049000 0x1000 -rw- ---- obj.2.page.9
|
||||
55 0x00044200 0x1000 0x0004a000 0x1000 -rw- ---- obj.2.page.10
|
||||
56 0x00045200 0x1000 0x0004b000 0x1000 -rw- ---- obj.2.page.11
|
||||
57 0x00046200 0x1000 0x0004c000 0x1000 -rw- ---- obj.2.page.12
|
||||
58 0x00047200 0x1000 0x0004d000 0x1000 -rw- ---- obj.2.page.13
|
||||
59 0x00048200 0x1000 0x0004e000 0x1000 -rw- ---- obj.2.page.14
|
||||
60 0x00049200 0xd8c 0x0004f000 0x1000 -rw- ---- obj.2.page.15
|
||||
61 0x00000000 0x0 0x00050000 0x16030 -rw- ---- obj.2.page.zerofill
|
||||
|
||||
EOF
|
||||
RUN
|
||||
|
@ -158,7 +159,7 @@ cat $relocs~0x0004e~?
|
|||
cat $relocs~0x0004f~?
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
5241
|
||||
5239
|
||||
151
|
||||
160
|
||||
102
|
||||
|
@ -202,9 +203,9 @@ EXPECT=<<EOF
|
|||
179
|
||||
103
|
||||
128
|
||||
158
|
||||
157
|
||||
128
|
||||
9
|
||||
8
|
||||
0
|
||||
0
|
||||
282
|
||||
|
@ -215,14 +216,14 @@ EXPECT=<<EOF
|
|||
0
|
||||
0
|
||||
95
|
||||
82
|
||||
81
|
||||
45
|
||||
7
|
||||
6
|
||||
0
|
||||
0
|
||||
381
|
||||
561
|
||||
590
|
||||
588
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
@ -266,8 +267,9 @@ nth paddr size vaddr vsize perm type name
|
|||
13 0x0000e000 0x1000 0x0001d000 0x1000 -r-x ---- obj.1.page.13
|
||||
14 0x0000f000 0x1000 0x0001e000 0x1000 -r-x ---- obj.1.page.14
|
||||
15 0x00010000 0x1000 0x00020000 0x1000 -rw- ---- obj.2.page.0
|
||||
16 0x00000000 0x0 0x00030000 0x2000000 -rw- ---- obj.3
|
||||
17 0x00000000 0x0 0x02030000 0x800000 -rw- ---- obj.4
|
||||
16 0x00000000 0x0 0x00021000 0x1804 -rw- ---- obj.2.page.zerofill
|
||||
17 0x00000000 0x0 0x00030000 0x2000000 -rw- ---- obj.3
|
||||
18 0x00000000 0x0 0x02030000 0x800000 -rw- ---- obj.4
|
||||
|
||||
EOF
|
||||
RUN
|
||||
|
@ -351,10 +353,10 @@ nth paddr size vaddr vsize perm type name
|
|||
4 0x00005600 0x1000 0x00014000 0x1000 -r-x ---- obj.1.page.4
|
||||
5 0x00006600 0x1000 0x00015000 0x1000 -r-x ---- obj.1.page.5
|
||||
6 0x00007600 0x1000 0x00016000 0x1000 -r-x ---- obj.1.page.6
|
||||
7 0x00008600 0xe00 0x00017000 0x1000 -r-x ---- obj.1.page.7
|
||||
8 0x00009400 0x200 0x00020000 0x1000 -r-x ---- obj.2.page.0
|
||||
9 0x00009600 0x200 0x00030000 0x1000 -r-x ---- obj.3.page.0
|
||||
10 0x00001400 0x200 0x00040000 0x1000 -rw- ---- obj.4.page.0
|
||||
7 0x00008600 0xc10 0x00017000 0xc10 -r-x ---- obj.1.page.7
|
||||
8 0x00009400 0x8 0x00020000 0x8 -r-x ---- obj.2.page.0
|
||||
9 0x00009600 0x8 0x00030000 0x8 -r-x ---- obj.3.page.0
|
||||
10 0x00001400 0x200 0x00040000 0x824 -rw- ---- obj.4.page.0
|
||||
|
||||
EOF
|
||||
RUN
|
||||
|
@ -408,10 +410,21 @@ CMDS=<<EOF
|
|||
s 0x0001ef2d
|
||||
pd~debug~?
|
||||
pd 6~w~?
|
||||
pi 1 @ 0x0003b144
|
||||
pi 1 @ 0x0003b175
|
||||
pxwj 4@0xbc518
|
||||
pxwj 4@0xbc534
|
||||
iS.@0xbc518~obj.2.page.zerofill~?
|
||||
iS.@0xbc534~obj.2.page.zerofill~?
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
1
|
||||
1
|
||||
mov ecx, dword [0xbc518]
|
||||
mov ecx, dword [0xbc534]
|
||||
[0]
|
||||
[0]
|
||||
1
|
||||
1
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
|
|
@ -138,3 +138,16 @@ nth paddr size vaddr vsize perm type name
|
|||
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=PE: corkami 96workingsections.exe - iS. pa
|
||||
FILE=bins/pe/96emptysections.exe
|
||||
ARGS=-e io.va=false
|
||||
CMDS=<<EOF
|
||||
iS.@0x000013ff~sect_0~?
|
||||
iS.@0x00001400~sect_0~?
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
1
|
||||
0
|
||||
EOF
|
||||
RUN
|
||||
|
|
|
@ -686,7 +686,7 @@ va true
|
|||
0x00000010 0x00000010 0x00000002 Type
|
||||
0x00000012 0x00000012 0x00000003 Machine
|
||||
0x00000014 0x00000014 0x00000001 Version
|
||||
0x00000018 0x00000018 0x08048300 Entry point
|
||||
0x00000018 0x00000018 0x08048300 EntryPoint
|
||||
0x0000001c 0x0000001c 0x00000034 PhOff
|
||||
0x00000020 0x00000020 0x000007cc ShOff
|
||||
0x00000024 0x00000024 0x00000000 Flags
|
||||
|
|
|
@ -180,6 +180,7 @@ c ror LGPL pancake
|
|||
c rot MIT pancake
|
||||
c serpent-ecb LGPL pancake
|
||||
c sm4-ecb LGPL3 Sylvain Pelissier
|
||||
h strhash MIT pancake
|
||||
c xor MIT pancake
|
||||
h md5
|
||||
h sha1
|
||||
|
|
|
@ -56,7 +56,7 @@ RUN
|
|||
|
||||
NAME=rax2 -E | rax2 -D 2
|
||||
FILE=-
|
||||
CMDS=!rax2 -E hello | rax2 -D | rax2 -E | rax2 -D | rax2 -E | rax2 -D | rax2 -E | rax2 -lD
|
||||
CMDS=!rax2 -E hello | rax2 -D | rax2 -E | rax2 -D | rax2 -E | rax2 -D | rax2 -E | rax2 -nD
|
||||
EXPECT=<<EOF
|
||||
hello
|
||||
EOF
|
||||
|
@ -314,33 +314,33 @@ EXPECT=<<EOF
|
|||
EOF
|
||||
RUN
|
||||
|
||||
NAME=rax2 -n 0x1234
|
||||
NAME=rax2 -x 0x1234
|
||||
FILE=-
|
||||
CMDS=!rax2 -n 0x1234
|
||||
CMDS=!rax2 -x 0x1234
|
||||
EXPECT=<<EOF
|
||||
34120000
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=rax2 -n 0xFEDCBA9876543210
|
||||
NAME=rax2 -x 0xFEDCBA9876543210
|
||||
FILE=-
|
||||
CMDS=!rax2 -n 0xFEDCBA9876543210
|
||||
CMDS=!rax2 -x 0xFEDCBA9876543210
|
||||
EXPECT=<<EOF
|
||||
1032547698badcfe
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=rax2 -N 0xFEDCBA9876543210
|
||||
NAME=rax2 -c 0xFEDCBA9876543210
|
||||
FILE=-
|
||||
CMDS=!rax2 -N 0xFEDCBA9876543210
|
||||
CMDS=!rax2 -c 0xFEDCBA9876543210
|
||||
EXPECT=<<EOF
|
||||
\x10\x32\x54\x76\x98\xba\xdc\xfe
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=rax2 -N 0x1234
|
||||
NAME=rax2 -c 0x1234
|
||||
FILE=-
|
||||
CMDS=!rax2 -N 0x1234
|
||||
CMDS=!rax2 -c 0x1234
|
||||
EXPECT=<<EOF
|
||||
\x34\x12\x00\x00
|
||||
EOF
|
||||
|
@ -438,9 +438,9 @@ Fri Feb
|
|||
EOF
|
||||
RUN
|
||||
|
||||
NAME=rax2 -x linux osx
|
||||
NAME=rax2 -X linux osx
|
||||
FILE=-
|
||||
CMDS=!rax2 -x linux osx
|
||||
CMDS=!rax2 -X linux osx
|
||||
EXPECT=<<EOF
|
||||
0x5ca62a43
|
||||
0xad593a1
|
||||
|
@ -593,6 +593,14 @@ EXPECT=<<EOF
|
|||
EOF
|
||||
RUN
|
||||
|
||||
NAME=rax2 -j 0x1234
|
||||
FILE=-
|
||||
CMDS=!rax2 -j 0x1234
|
||||
EXPECT=<<EOF
|
||||
{"int32":"4660","uint32":"4660","int64":"4660","uint64":"4660","hex":"0x00001234","octal":"011064","unit":"4.6K","segment":"0000:0234","fvalue":"4660.0","float":"0.000000f","double":"0.000000","binary":"0b0001001000110100","base36":"0_3lg","ternary":"0t20101121"}
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=rax2 -v
|
||||
FILE=-
|
||||
CMDS=!rax2 -v | grep -c birth
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
#include <r_bin.h>
|
||||
#include <r_core.h>
|
||||
#include <math.h>
|
||||
#include "../../libr/include/r_heap_glibc.h"
|
||||
#define R_INCLUDE_BEGIN 1
|
||||
#include "../../libr/core/dmh_glibc.inc.c"
|
||||
#undef R_INCLUDE_BEGIN
|
||||
#include "minunit.h"
|
||||
|
||||
bool test_get_main_arena_offset_with_symbol (void) {
|
||||
RCore * core = r_core_new();
|
||||
GHT arena_offset;
|
||||
|
||||
// 2.21
|
||||
arena_offset = 0;
|
||||
arena_offset = GH (get_main_arena_offset_with_symbol) (core, "bins/elf/libc-2.21-debug.so");
|
||||
mu_assert_eq (arena_offset, 0x003c4c00, "Incorrect main_arena_offset for debug 2.21");
|
||||
|
||||
// 2.26
|
||||
arena_offset = 0;
|
||||
arena_offset = GH (get_main_arena_offset_with_symbol) (core, "bins/elf/libc-2.26-debug.so");
|
||||
mu_assert_eq (arena_offset, 0x003dac20, "Incorrect main_arena_offset for debug 2.26");
|
||||
|
||||
r_core_free (core);
|
||||
mu_end;
|
||||
}
|
||||
|
||||
bool test_get_main_arena_offset_with_relocs (void) {
|
||||
RCore *core = r_core_new ();
|
||||
|
||||
GHT arena_offset;
|
||||
core->dbg->glibc_version_resolved = true;
|
||||
|
||||
// 2.21
|
||||
arena_offset = 0;
|
||||
core->dbg->glibc_version_d = 2.21;
|
||||
arena_offset = GH (get_main_arena_offset_with_relocs) (core, "bins/elf/libc-2.21.so");
|
||||
mu_assert_eq (arena_offset, 0xb80, "Incorrect main_arena_offset for 2.21");
|
||||
|
||||
// 2.23
|
||||
arena_offset = 0;
|
||||
core->dbg->glibc_version_d = 2.23;
|
||||
arena_offset = GH (get_main_arena_offset_with_relocs) (core, "bins/elf/libc-2.23.so");
|
||||
mu_assert_eq (arena_offset, 0xaa0, "Incorrect main_arena_offset for 2.23");
|
||||
|
||||
// 2.26
|
||||
arena_offset = 0;
|
||||
core->dbg->glibc_version_d = 2.26;
|
||||
arena_offset = GH (get_main_arena_offset_with_relocs) (core, "bins/elf/libc-2.26.so");
|
||||
mu_assert_eq (arena_offset, 0xaa0, "Incorrect main_arena_offset for 2.26");
|
||||
|
||||
// 2.27
|
||||
arena_offset = 0;
|
||||
core->dbg->glibc_version_d = 2.27;
|
||||
arena_offset = GH (get_main_arena_offset_with_relocs) (core, "bins/elf/libc-2.27.so");
|
||||
mu_assert_eq (arena_offset, 0xaa0, "Incorrect main_arena_offset for 2.27");
|
||||
|
||||
// 2.28
|
||||
arena_offset = 0;
|
||||
arena_offset = GH (get_main_arena_offset_with_relocs) (core, "bins/elf/libc.so.6");
|
||||
mu_assert_eq (arena_offset, 0xaa0, "Incorrect main_arena_offset for 2.28");
|
||||
|
||||
// 2.31
|
||||
arena_offset = 0;
|
||||
arena_offset = GH (get_main_arena_offset_with_relocs) (core, "bins/elf/libc-2.31.so");
|
||||
mu_assert_eq (arena_offset, 0x9e0, "Incorrect main_arena_offset for 2.31");
|
||||
|
||||
// 2.32
|
||||
arena_offset = 0;
|
||||
arena_offset = GH (get_main_arena_offset_with_relocs) (core, "bins/elf/libc-2.32.so");
|
||||
mu_assert_eq (arena_offset, 0xa00, "Incorrect main_arena_offset for 2.32");
|
||||
|
||||
r_core_free (core);
|
||||
mu_end;
|
||||
}
|
||||
|
||||
bool all_tests () {
|
||||
mu_run_test (test_get_main_arena_offset_with_symbol);
|
||||
mu_run_test (test_get_main_arena_offset_with_relocs);
|
||||
return tests_passed != tests_run;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
return all_tests ();
|
||||
}
|
Loading…
Reference in New Issue