Move the base36 api from .h to .c ##api

This commit is contained in:
pancake 2023-06-12 04:24:53 +02:00
parent 388a878934
commit fd157a0362
11 changed files with 89 additions and 87 deletions

View File

@ -20,10 +20,9 @@ static bool get_functions_block_cb(RAnalBlock *block, void *user) {
R_API RList *r_anal_get_functions_in(RAnal *anal, ut64 addr) {
r_return_val_if_fail (anal, NULL);
RList *list = r_list_new ();
if (!list) {
return NULL;
if (list) {
r_anal_blocks_foreach_in (anal, addr, get_functions_block_cb, list);
}
r_anal_blocks_foreach_in (anal, addr, get_functions_block_cb, list);
return list;
}

View File

@ -1,10 +1,6 @@
/* radare2 - LGPL - Copyright 2009-2019 - nibble, pancake, maijin */
/* radare2 - LGPL - Copyright 2009-2023 - nibble, pancake, maijin */
#include <stdio.h>
#include <r_types.h>
#include <r_parse.h>
#include <config.h>
#include <r_util/r_base36.h>
#define isx86separator(x) ( \
(x) == ' '||(x) == '\t'||(x) == '\n'|| (x) == '\r'||(x) == ' '|| \

View File

@ -1,7 +1,6 @@
/* radare - LGPL - Copyright 2009-2023 - pancake */
#include <r_core.h>
#include <r_util/r_base36.h>
static RCoreHelpMessage help_msg_question_t = {
"Usage: ?t[0,1] [cmd]", "", "",

View File

@ -1,7 +1,6 @@
/* radare - LGPL - Copyright 2009-2023 - pancake */
#include <r_core.h>
#include <r_util/r_base36.h>
#include <limits.h>
#define R_CORE_MAX_DISASM (1024 * 1024 * 8)

View File

@ -35,6 +35,7 @@ int gettimeofday (struct timeval* p, void* tz);
#include "r_util/r_new_rbtree.h"
#include "r_util/r_intervaltree.h"
#include "r_util/r_big.h"
#include "r_util/r_base36.h"
#include "r_util/r_base64.h"
#include "r_util/r_base91.h"
#include "r_util/r_buf.h"

View File

@ -1,83 +1,15 @@
#ifndef R2_BASE36_H
#define R2_BASE36_H
#ifdef __cplusplus
extern "C" {
#endif
// R2_590 - this is not standard but will be introduced in r2-5.9
// R2_590 Move into libr/util/ubase64
static const char cb36[] = "0123456789abcdefghijklmnopqrstuvwxyz";
R_API void b36_fromnum(char *s, ut64 n);
R_API ut64 b36_tonum(const char *s);
static inline void b36_fromnum(char *s, ut64 n) {
const int amount = n? (log (n) / log (36)): 0;
char *p = s;
*p++ = '0';
*p++ = '_';
p += amount + 1;
*p-- = 0;
if (n == 0) {
*p = '0';
} else while (n > 0) {
*p-- = cb36[n % 36];
n /= 36;
}
}
static const ut64 pow36[36] = {
1, 36, 1296, 46656, 1679616, 60466176,
2176782336, 78364164096, 2821109907456,
101559956668416, 3656158440062976,
131621703842267136, 4738381338321616896,
9223372036854775808ULL,
};
static const int index36[0xff] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1,
-1, -1, -1, -1,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35,
-1, -1, -1, -1, -1, -1,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, // 256
};
// R2_590 Move into libr/util/ubase64
static inline ut64 b36_tonum(const char *s) {
ut64 n = 0;
int pos = 0;
if (r_str_startswith (s, "0_")) {
s += 2;
}
while (true) {
int idx = index36 [(unsigned char )*s];
if (idx < 0) {
break;
}
n += pow36[pos] * idx;
pos++;
s++;
}
return n;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -5,7 +5,6 @@
#include <r_main.h>
#include <r_util.h>
#include <r_util/r_print.h>
#include <r_util/r_base36.h>
// XXX don't use fixed sized buffers
#define STDIN_BUFFER_SIZE 354096

View File

@ -4,7 +4,7 @@ NAME=r_util
CFLAGS+=-DR2_PLUGIN_INCORE -I$(TOP)/shlr
PCLIBS=@LIBZIP@ @DL_LIBS@
OBJS=mem.o unum.o str.o hex.o file.o range.o charset.o xdg.o rxml.o
OBJS+=prof.o sys.o buf.o sys_w32.o ubase64.o base85.o base91.o
OBJS+=prof.o sys.o buf.o sys_w32.o ubase64.o base85.o base91.o base36.o
OBJS+=list.o chmod.o graph.o event.o alloc.o donut.o print_code.o
OBJS+=regex/regcomp.o regex/regerror.o regex/regexec.o uleb128.o rstr.o
OBJS+=sandbox.o calc.o thread.o thread_sem.o thread_lock.o thread_cond.o thread_chan.o

77
libr/util/base36.c Normal file
View File

@ -0,0 +1,77 @@
/* radare - LGPL - Copyright 2023 - pancake */
#include <r_util.h>
static const char cb36[] = "0123456789abcdefghijklmnopqrstuvwxyz";
R_API void b36_fromnum(char *s, ut64 n) {
const int amount = n? (log (n) / log (36)): 0;
char *p = s;
*p++ = '0';
*p++ = '_';
p += amount + 1;
*p-- = 0;
if (n == 0) {
*p = '0';
} else while (n > 0) {
*p-- = cb36[n % 36];
n /= 36;
}
}
static const ut64 pow36[36] = {
1, 36, 1296, 46656, 1679616, 60466176,
2176782336, 78364164096, 2821109907456,
101559956668416, 3656158440062976,
131621703842267136, 4738381338321616896,
9223372036854775808ULL,
};
static const int index36[0xff] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1,
-1, -1, -1, -1,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35,
-1, -1, -1, -1, -1, -1,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, // 256
};
R_API ut64 b36_tonum(const char *s) {
ut64 n = 0;
int pos = 0;
if (r_str_startswith (s, "0_")) {
s += 2;
}
while (true) {
int idx = index36 [(unsigned char )*s];
if (idx < 0) {
break;
}
n += pow36[pos] * idx;
pos++;
s++;
}
return n;
}

View File

@ -19,6 +19,7 @@ r_util_sources = [
'sstext.c',
'getopt.c',
'print_code.c',
'base36.c',
'base85.c',
'base91.c',
'bdiff.c',

View File

@ -5,7 +5,6 @@
#include <errno.h>
#include <math.h> /* for ceill */
#include <r_util.h>
#include <r_util/r_base36.h>
static ut64 r_num_tailff(RNum *num, const char *hex);