Skip to content

Commit

Permalink
Move trie, mixed, slist into Sdb's Attic, and DES from util to crypto…
Browse files Browse the repository at this point in the history
… ##refactor
  • Loading branch information
radare committed Nov 7, 2018
1 parent d7b84ca commit 71053f1
Show file tree
Hide file tree
Showing 47 changed files with 167 additions and 963 deletions.
2 changes: 1 addition & 1 deletion binr/rafind2/Makefile
@@ -1,6 +1,6 @@
BIN=rafind2

BINDEPS=r_search r_io r_asm r_anal r_reg r_cons r_lang
BINDEPS=r_search r_io r_asm r_anal r_reg r_cons r_lang r_crypto
BINDEPS+=r_socket r_parse r_util r_syscall r_flag r_hash

include ../rules.mk
Expand Down
1 change: 1 addition & 0 deletions binr/rafind2/meson.build
Expand Up @@ -3,6 +3,7 @@ executable('rafind2', 'rafind2.c',
dependencies: [
r_util_dep,
r_search_dep,
r_crypto_dep,
r_io_dep,
r_cons_dep
],
Expand Down
2 changes: 1 addition & 1 deletion binr/ragg2/Makefile
@@ -1,7 +1,7 @@
BIN=ragg2
BINDEPS=r_egg r_syscall r_asm
BINDEPS+=r_core r_hash r_debug r_fs r_config r_bp r_crypto r_cons
BINDEPS+=r_lang r_parse r_anal r_reg r_flag
BINDEPS+=r_lang r_parse r_anal r_reg r_flag r_crypto
BINDEPS+=r_bin r_search r_io r_socket
BINDEPS+=r_magic r_util

Expand Down
2 changes: 1 addition & 1 deletion binr/rahash2/Makefile
Expand Up @@ -3,7 +3,7 @@ BIN=rahash2
BINDEPS=r_io r_hash r_socket r_asm r_cons
BINDEPS+=r_anal r_syscall r_reg r_parse
BINDEPS+=r_flag r_lang r_crypto r_util
BINDEPS+=r_search
BINDEPS+=r_search r_crypto

include ../rules.mk

Expand Down
2 changes: 1 addition & 1 deletion binr/rasm2/Makefile
@@ -1,4 +1,4 @@
BIN=rasm2
BINDEPS=r_asm r_parse r_syscall r_anal r_reg r_hash
BINDEPS+=r_flag r_cons r_lang r_util r_search
BINDEPS+=r_flag r_cons r_lang r_util r_search r_crypto
include ../rules.mk
1 change: 1 addition & 0 deletions binr/rasm2/meson.build
Expand Up @@ -4,6 +4,7 @@ executable('rasm2', 'rasm2.c',
r_util_dep,
r_asm_dep,
r_anal_dep,
r_crypto_dep,
r_syscall_dep,
r_hash_dep,
sdb_dep
Expand Down
8 changes: 7 additions & 1 deletion binr/rax2/rax2.c
Expand Up @@ -568,7 +568,7 @@ static int use_stdin() {
return 0;
}

int main(int argc, char **argv) {
R_API int r_core_main_rax2(int argc, char **argv) {
int i;
num = r_num_new (NULL, NULL, NULL);
if (argc == 1) {
Expand All @@ -579,5 +579,11 @@ int main(int argc, char **argv) {
}
}
r_num_free (num);
num = NULL;
return 0;
}


int main(int argc, char **argv) {
return r_core_main_rax2 (argc, argv);
}
6 changes: 4 additions & 2 deletions libr/Makefile
Expand Up @@ -172,8 +172,10 @@ install-includes:
done)
${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr/r_util"
(cd include/r_util && for FILE in * ; do \
${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/libr/r_util/$$FILE" ; \
done)
${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/libr/r_util/$$FILE" ; done)
${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr/r_crypto"
(cd include/r_crypto && for FILE in * ; do \
${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/libr/r_crypto/$$FILE" ; done)
symstall install-symlink:
@cd .. && \
Expand Down
2 changes: 1 addition & 1 deletion libr/anal/Makefile
Expand Up @@ -4,7 +4,7 @@ EXTRA_TARGETS+=do
EXTRA_CLEAN=doclean

NAME=r_anal
DEPS=r_util r_reg r_syscall r_search r_cons r_flag r_hash
DEPS=r_util r_reg r_syscall r_search r_cons r_flag r_hash r_crypto
CFLAGS+=-DCORELIB -Iarch -I$(TOP)/shlr
CFLAGS+=-I$(LTOP)/asm/arch/include

Expand Down
2 changes: 2 additions & 0 deletions libr/anal/meson.build
Expand Up @@ -127,6 +127,7 @@ r_anal = library('r_anal', files,
r_util_dep,
r_reg_dep,
r_asm_dep,
r_crypto_dep,
r_search_dep,
r_cons_dep,
r_syscall_dep,
Expand Down Expand Up @@ -154,6 +155,7 @@ pkgconfig_mod.generate(
'r_util',
'r_reg',
'r_asm',
'r_crypto',
'r_syscall',
'r_search',
'r_cons',
Expand Down
2 changes: 1 addition & 1 deletion libr/anal/p/Makefile
Expand Up @@ -2,7 +2,7 @@ include ../../config.mk
include ../../../mk/platform.mk

CFLAGS+=-I../../include -I../arch -Wall -shared $(PIC_CFLAGS) ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
CFLAGS+=-L../../util -lr_util -L../../anal -lr_anal -L../../reg -lr_reg
CFLAGS+=-L../../util -lr_util -L../../anal -lr_anal -L../../reg -lr_reg -L../../crypto -lr_crypto
LDFLAGS+=${LINK}

CURDIR=
Expand Down
1 change: 1 addition & 0 deletions libr/anal/p/anal_avr.c
Expand Up @@ -8,6 +8,7 @@
#include <string.h>
#include <r_types.h>
#include <r_util.h>
#include <r_crypto.h>
#include <r_lib.h>
#include <r_asm.h>
#include <r_anal.h>
Expand Down
2 changes: 1 addition & 1 deletion libr/bin/format/mz/mz.c
Expand Up @@ -43,7 +43,7 @@ static void trv_segs (const void *seg, const void *segs) {
const ut8 * const mseg = (const ut8 * const)seg;
ut16 ** const msegs = (ut16 **)segs;
if (mseg && msegs && *msegs) {
r_write_le16(*msegs, r_read_le16(mseg));
r_write_le16 (*msegs, r_read_le16 (mseg));
*msegs = *msegs + 1;
}
}
Expand Down
6 changes: 3 additions & 3 deletions libr/bin/pdb/dbi.c
Expand Up @@ -3,7 +3,7 @@
#include "stream_file.h"
#include "tpi.h"

#define _ALIGN 4
#define PDB_ALIGN 4

///////////////////////////////////////////////////////////////////////////////
static void free_dbi_stream(void *stream) {
Expand Down Expand Up @@ -145,8 +145,8 @@ void parse_dbi_stream(void *parsed_pdb_stream, R_STREAM_FILE *stream_file) {
}
// TODO: rewrite for signature where can to do chech CAN_READ true?
sz = parse_dbi_ex_header (p_tmp, size, dbi_ex_header);
if ((sz % _ALIGN)) {
sz = sz + (_ALIGN - (sz % _ALIGN));
if ((sz % PDB_ALIGN)) {
sz = sz + (PDB_ALIGN - (sz % PDB_ALIGN));
}
i += sz;
p_tmp += sz;
Expand Down
5 changes: 3 additions & 2 deletions libr/core/cmd_debug.c
Expand Up @@ -3401,7 +3401,7 @@ static RTreeNode *add_trace_tree_child (Sdb *db, RTree *t, RTreeNode *cur, ut64
snprintf (dbkey, TN_KEY_LEN, TN_KEY_FMT, addr);
t_node = (struct trace_node *)(size_t)sdb_num_get (db, dbkey, NULL);
if (!t_node) {
t_node = (struct trace_node *)malloc (sizeof (*t_node));
t_node = R_NEW0 (struct trace_node);
t_node->addr = addr;
t_node->refs = 1;
sdb_num_set (db, dbkey, (ut64)(size_t)t_node, 0);
Expand Down Expand Up @@ -3475,7 +3475,8 @@ static void do_debug_trace_calls(RCore *core, ut64 from, ut64 to, ut64 final_add
}
if (debug_to != UT64_MAX && !r_debug_continue_until (dbg, debug_to)) {
break;
} else if (!r_debug_step (dbg, 1)) {
}
if (!r_debug_step (dbg, 1)) {
break;
}
debug_to = UT64_MAX;
Expand Down
12 changes: 6 additions & 6 deletions libr/core/p/Makefile
Expand Up @@ -2,24 +2,24 @@ include ../../config.mk
include ../../../mk/platform.mk
include ../../../shlr/zip/deps.mk

CFLAGS+=-I../../include -Wall -shared ${PIC_CFLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
CFLAGS+=-I../../include -Wall -shared
CFLAGS+=${PIC_CFLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
CFLAGS+=-L../../util -lr_util -L../../reg -lr_reg -L.. -lr_core
#CFLAGS+=-L../../db -lr_db
CFLAGS+=-L../../cons -lr_cons -L../../bin -lr_bin
CFLAGS+=-L../../parse -lr_parse -L../../io -lr_io -L../../fs -lr_fs
CFLAGS+=-L../../magic -lr_magic -L../../hash -lr_hash -L../../config -lr_config
CFLAGS+=-L../../magic -lr_magic -L../../hash -lr_hash
CFLAGS+=-L../../config -lr_config
CFLAGS+=-L../../anal -lr_anal -L../../egg -lr_egg -L../../flag -lr_flag
CFLAGS+=-L../../syscall -lr_syscall -L../../socket -lr_socket -L../../search -lr_search
CFLAGS+= -L../../lang -lr_lang -L../../debug -lr_debug
CFLAGS+=-L../../bp -lr_bp -L../../reg -lr_reg -L../../asm -lr_asm

#CFLAGS+=../../../shlr/sdb/src/libsdb.a

LDFLAGS+=$(STOP)/sdb/src/libsdb.a

include $(STOP)/java/deps.mk
include $(STOP)/gdb/deps.mk
include $(STOP)/windbg/deps.mk
#CFLAGS+=-L../../anal -lr_anal -L../../core -lr_core

LDFLAGS+=${LINK}

ifeq ($(WITHPIC),1)
Expand Down
3 changes: 2 additions & 1 deletion libr/crypto/Makefile
Expand Up @@ -9,7 +9,8 @@ foo:

include ${STATIC_CRYPTO_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst crypto_,p/crypto_,$(STATIC_OBJ)))
OBJS=${STATIC_OBJS} crypto.o

OBJS=${STATIC_OBJS} crypto.o des.o

pre:
@if [ ! -e ${LIBSO} ]; then rm -f ${STATIC_OBJS} ; fi
Expand Down
1 change: 1 addition & 0 deletions libr/util/des.c → libr/crypto/des.c
@@ -1,5 +1,6 @@
#include <r_types.h>
#include <r_util.h>

#define ROTL28(rs, sh) ((((rs) << (sh)) | ((rs) >> (28 - (sh)))) & 0x0FFFFFFF) // left 28
#define ROTL(rs, sh) (((rs) << (sh)) | ((rs) >> (32 - (sh)))) // left 32
#define ROTR(rs, sh) (((rs) >> (sh)) | ((rs) << (32 - (sh)))) // right 32
Expand Down
1 change: 1 addition & 0 deletions libr/crypto/meson.build
@@ -1,4 +1,5 @@
files = [
'des.c',
'crypto.c',
'p/crypto_aes.c',
'p/crypto_aes_algo.c',
Expand Down
8 changes: 4 additions & 4 deletions libr/crypto/p/crypto_des.c
Expand Up @@ -114,9 +114,9 @@ static bool update (RCrypto *cry, const ut8 *buf, int len) {
}

// Pad to the block size, do not append dummy block
const int diff = (BLOCK_SIZE - (len % BLOCK_SIZE)) % BLOCK_SIZE;
const int diff = (DES_BLOCK_SIZE - (len % DES_BLOCK_SIZE)) % DES_BLOCK_SIZE;
const int size = len + diff;
const int blocks = size / BLOCK_SIZE;
const int blocks = size / DES_BLOCK_SIZE;

ut8 *const obuf = calloc (1, size);
if (!obuf) {
Expand All @@ -140,12 +140,12 @@ static bool update (RCrypto *cry, const ut8 *buf, int len) {
int i;
if (cry->dir) {
for (i = 0; i < blocks; i++) {
ut32 next = (BLOCK_SIZE * i);
ut32 next = (DES_BLOCK_SIZE * i);
des_decrypt (&st, ibuf + next, obuf + next);
}
} else {
for (i = 0; i < blocks; i++) {
ut32 next = (BLOCK_SIZE * i);
ut32 next = (DES_BLOCK_SIZE * i);
des_encrypt (&st, ibuf + next, obuf + next);
}
}
Expand Down
1 change: 1 addition & 0 deletions libr/include/r_crypto.h
Expand Up @@ -3,6 +3,7 @@

#include <r_types.h>
#include <r_list.h>
#include <r_crypto/r_des.h>

#ifdef __cplusplus
extern "C" {
Expand Down
8 changes: 4 additions & 4 deletions libr/include/r_util/r_des.h → libr/include/r_crypto/r_des.h
Expand Up @@ -2,16 +2,16 @@
#define R_DES_H

#define DES_KEY_SIZE 8
#define BLOCK_SIZE 8
#define DES_BLOCK_SIZE 8

#ifdef __cplusplus
extern "C" {
#endif

typedef struct des_context_t {
ut32 round_key_lo[16]; // round key low
ut32 round_key_hi[16]; // round key hi
int round;
ut32 round_key_lo[16]; // round key low
ut32 round_key_hi[16]; // round key hi
int round;
} RDESContext;

R_API void r_des_permute_key (ut32 *keylo, ut32 *keyhi);
Expand Down
45 changes: 0 additions & 45 deletions libr/include/r_slist.h

This file was deleted.

9 changes: 8 additions & 1 deletion libr/include/r_types.h
Expand Up @@ -361,8 +361,15 @@ static inline void *r_new_copy(int size, void *data) {
#define typeof(arg) __typeof__(arg)
#endif

#undef r_offsetof
#if 1
#define r_offsetof(type, member) offsetof(type, member)
#else
#if __SDB_WINDOWS__ && !__CYGWIN__
#define r_offsetof(type, member) ((unsigned long) (ut64)&((type*)0)->member)
#else
#define r_offsetof(type, member) ((unsigned long) &((type*)0)->member)
#endif
#endif

#define R_BETWEEN(x,y,z) (((y)>=(x)) && ((y)<=(z)))
#define R_ROUND(x,y) ((x)%(y))?(x)+((y)-((x)%(y))):(x)
Expand Down
2 changes: 0 additions & 2 deletions libr/include/r_util.h
Expand Up @@ -39,12 +39,10 @@ int gettimeofday (struct timeval* p, void* tz);
#include "r_util/r_debruijn.h"
#include "r_util/r_cache.h"
#include "r_util/r_ctypes.h"
#include "r_util/r_des.h"
#include "r_util/r_file.h"
#include "r_util/r_hex.h"
#include "r_util/r_log.h"
#include "r_util/r_mem.h"
#include "r_util/r_mixed.h"
#include "r_util/r_name.h"
#include "r_util/r_num.h"
#include "r_util/r_graph.h"
Expand Down
29 changes: 0 additions & 29 deletions libr/include/r_util/r_mixed.h

This file was deleted.

0 comments on commit 71053f1

Please sign in to comment.