As the title says... Chat on...

User avatar
By cal
#18751 Moin,

background of this post is need for base64 encode method and trying to use the ROM version of this method.

The signature of the rom function "base64_encode" seems to be indeed

Code: Select allextern unsigned char * base64_encode(const unsigned char *src, size_t len, size_t *out_len);


Unfortunately it that seems to require the ROM memory management to be initialized because it uses mem_malloc.

As a brute force POC I added the following to the start of the nodemcu init function:

Code: Select allvoid nodemcu_init(void)
{
   unsigned char * base64;
   unsigned char * somemem;

    NODE_ERR("nodemcu_init\n");

    extern void mem_init(void * start_addr);
    extern unsigned char * base64_encode(const unsigned char *src, size_t len,
                   size_t *out_len);
    // get some mem from nodemcu heap
    somemem = c_malloc(8192);
    // fake rom malloc init
    mem_init(somemem);
    base64 = base64_encode("GPL or BSD?", 11, 0);

    NODE_ERR("base64:");
    NODE_ERR(base64);


This prints:
Code: Select allnodemcu_init
base64:R1BMIG9yIEJTRD8=


Which can be decoded:
Code: Select all$ echo R1BMIG9yIEJTRD8= | base64 -d
GPL or BSD?


mem_init looks cheap so it may be a way to conserve instruction memory here by using base64_encode from ROM.

Can't make my mind if it's too hacky... :lol:

Cal