Rizin
unix-like reverse engineering framework and cli tools
base64.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2011-2016 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: MIT
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <rz_util/rz_base64.h>
8 #include "sdb.h"
9 
10 RZ_API void sdb_encode_raw(char *bout, const ut8 *bin, int len) {
11  rz_base64_encode(bout, bin, len);
12 }
13 
14 RZ_API int sdb_decode_raw(ut8 *bout, const char *bin, int len) {
15  return rz_base64_decode(bout, bin, len);
16 }
17 
18 RZ_API char *sdb_encode(const ut8 *bin, int len) {
19  char *out;
20  if (!bin) {
21  return NULL;
22  }
23  if (len < 0) {
24  len = strlen((const char *)bin);
25  }
26  if (!len) {
27  return strdup("");
28  }
29  out = calloc(8 + (len * 2), sizeof(char));
30  if (!out) {
31  return NULL;
32  }
34  return out;
35 }
36 
37 RZ_API ut8 *sdb_decode(const char *in, int *len) {
38  ut8 *out;
39  ut32 size;
40  int olen, ilen;
41  if (len) {
42  *len = 0;
43  }
44  if (!in) {
45  return NULL;
46  }
47  ilen = strlen(in);
48  if (!ilen) {
49  return NULL;
50  }
51  size = (ilen * 3) + 16;
52  if (size < (ut32)ilen) {
53  return NULL;
54  }
55  out = calloc(1, size);
56  if (!out) {
57  return NULL;
58  }
59  olen = sdb_decode_raw(out, in, ilen);
60  if (!olen) {
61  free(out);
62  return NULL;
63  }
64  out[olen] = 0;
65  if (len) {
66  *len = olen;
67  }
68  return out;
69 }
size_t len
Definition: 6502dis.c:15
RZ_API ut8 * sdb_decode(const char *in, int *len)
Definition: base64.c:37
RZ_API void sdb_encode_raw(char *bout, const ut8 *bin, int len)
Definition: base64.c:10
RZ_API int sdb_decode_raw(ut8 *bout, const char *bin, int len)
Definition: base64.c:14
RZ_API char * sdb_encode(const ut8 *bin, int len)
Definition: base64.c:18
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define RZ_API
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
RZ_API size_t rz_base64_encode(char *bout, const ut8 *bin, size_t sz)
Definition: ubase64.c:81
RZ_API int rz_base64_decode(ut8 *bout, const char *bin, int len)
Definition: ubase64.c:48
Definition: malloc.c:26