Commit 5234b73c authored by Marko Mikulicic's avatar Marko Mikulicic Committed by Sergey Lyubka

Add simple core dumper for ESP

    PUBLISHED_FROM=ec98516ce6aa1c841344adc7aae20b044b3d349b
parent c566e2eb
...@@ -674,31 +674,79 @@ void MD5_Final(unsigned char digest[16], MD5_CTX *ctx) { ...@@ -674,31 +674,79 @@ void MD5_Final(unsigned char digest[16], MD5_CTX *ctx) {
/* Amalgamated: #include "base64.h" */ /* Amalgamated: #include "base64.h" */
#define BASE64_ENCODE_BODY \
static const char *b64 = \
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; \
int i, j, a, b, c; \
\
for (i = j = 0; i < src_len; i += 3) { \
a = src[i]; \
b = i + 1 >= src_len ? 0 : src[i + 1]; \
c = i + 2 >= src_len ? 0 : src[i + 2]; \
\
BASE64_OUT(b64[a >> 2]); \
BASE64_OUT(b64[((a & 3) << 4) | (b >> 4)]); \
if (i + 1 < src_len) { \
BASE64_OUT(b64[(b & 15) << 2 | (c >> 6)]); \
} \
if (i + 2 < src_len) { \
BASE64_OUT(b64[c & 63]); \
} \
} \
\
while (j % 4 != 0) { \
BASE64_OUT('='); \
} \
BASE64_FLUSH()
#define BASE64_OUT(ch) \
do { \
dst[j++] = (ch); \
} while (0)
#define BASE64_FLUSH() \
do { \
dst[j++] = '\0'; \
} while (0)
void cs_base64_encode(const unsigned char *src, int src_len, char *dst) { void cs_base64_encode(const unsigned char *src, int src_len, char *dst) {
static const char *b64 = BASE64_ENCODE_BODY;
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; }
int i, j, a, b, c;
for (i = j = 0; i < src_len; i += 3) { #undef BASE64_OUT
a = src[i]; #undef BASE64_FLUSH
b = i + 1 >= src_len ? 0 : src[i + 1];
c = i + 2 >= src_len ? 0 : src[i + 2];
dst[j++] = b64[a >> 2]; #define BASE64_OUT(ch) \
dst[j++] = b64[((a & 3) << 4) | (b >> 4)]; do { \
if (i + 1 < src_len) { cb((ch)); \
dst[j++] = b64[(b & 15) << 2 | (c >> 6)]; j++; \
} } while (0)
if (i + 2 < src_len) {
dst[j++] = b64[c & 63]; #define BASE64_FLUSH()
}
} void cs_base64_encode2(const unsigned char *src, int src_len,
while (j % 4 != 0) { cs_base64_cb_t cb) {
dst[j++] = '='; BASE64_ENCODE_BODY;
}
dst[j++] = '\0';
} }
#undef BASE64_OUT
#undef BASE64_FLUSH
#define BASE64_OUT(ch) \
do { \
fprintf(f, "%c", (ch)); \
j++; \
} while (0)
#define BASE64_FLUSH()
void cs_fprint_base64(FILE *f, const unsigned char *src, int src_len) {
BASE64_ENCODE_BODY;
}
#undef BASE64_OUT
#undef BASE64_FLUSH
/* Convert one byte of encoded base64 input stream to 6-bit chunk */ /* Convert one byte of encoded base64 input stream to 6-bit chunk */
static unsigned char from_b64(unsigned char ch) { static unsigned char from_b64(unsigned char ch) {
/* Inverse lookup map */ /* Inverse lookup map */
......
...@@ -402,11 +402,18 @@ void MD5_Final(unsigned char *md, MD5_CTX *c); ...@@ -402,11 +402,18 @@ void MD5_Final(unsigned char *md, MD5_CTX *c);
#if !defined(BASE64_H_INCLUDED) && !defined(DISABLE_BASE64) #if !defined(BASE64_H_INCLUDED) && !defined(DISABLE_BASE64)
#define BASE64_H_INCLUDED #define BASE64_H_INCLUDED
#include <stdio.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef void (*cs_base64_cb_t)(char ch);
void cs_base64_encode(const unsigned char *src, int src_len, char *dst); void cs_base64_encode(const unsigned char *src, int src_len, char *dst);
void cs_base64_encode2(const unsigned char *src, int src_len,
cs_base64_cb_t cb);
void cs_fprint_base64(FILE *f, const unsigned char *src, int src_len);
int cs_base64_decode(const unsigned char *s, int len, char *dst); int cs_base64_decode(const unsigned char *s, int len, char *dst);
#ifdef __cplusplus #ifdef __cplusplus
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment