A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 94 lines 3.4 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * 9 * Copyright (C) 2013 Lorenzo Miori 10 * 11 * This program is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation; either version 2 14 * of the License, or (at your option) any later version. 15 * 16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 * KIND, either express or implied. 18 * 19 ****************************************************************************/ 20 21#include <stdio.h> 22#include <string.h> 23#include <stdlib.h> 24#include <stdarg.h> 25#include <getopt.h> 26#include <stdint.h> 27#include "common.h" 28#include "../../tools/fwpatcher/md5.h" 29 30uint8_t g_yp_key[] = 31{ 32 0xa3, 0x04, 0xb9, 0xcd, 0x34, 0x13, 0x4a, 0x19, 0x19, 0x31, 0xdf, 0xbb, 33 0x8f, 0x3d, 0x7f, 0x09, 0x42, 0x3c, 0x96, 0x33, 0x41, 0xa9, 0x95, 0xf1, 34 0xd0, 0xac, 0x16, 0x37, 0x57, 0x35, 0x28, 0xe7, 0x0b, 0xc2, 0x12, 0x09, 35 0x39, 0x42, 0xd2, 0x96, 0xf5, 0x00, 0xd2, 0x23, 0x37, 0x24, 0xe2, 0x8e, 36 0x50, 0x3c, 0x6e, 0x23, 0xeb, 0x68, 0xed, 0x31, 0xb7, 0xee, 0xc0, 0xc7, 37 0x09, 0xf8, 0x39, 0x9d, 0x51, 0xed, 0x17, 0x95, 0x64, 0x09, 0xe0, 0xf9, 38 0xf0, 0xef, 0x86, 0xc0, 0x04, 0x46, 0x89, 0x8a, 0x6e, 0x27, 0x69, 0xde, 39 0xc7, 0x31, 0x1e, 0xee, 0x3c, 0x3f, 0x17, 0x05, 0x44, 0xbb, 0xbb, 0x1d, 40 0x3d, 0x5d, 0x6e, 0xf2, 0x78, 0x15, 0xd6, 0x3c, 0xcc, 0x7d, 0x67, 0x1a, 41 0xb8, 0xd2, 0x79, 0x54, 0x97, 0xa2, 0x58, 0x58, 0xf7, 0x4e, 0x5e, 0x50, 42 0x42, 0x69, 0xdc, 0xe7, 0x3a, 0x87, 0x2e, 0x22 43}; 44 45char* firmware_components[] = {"MBoot", "Linux", "RootFS", "Sysdata"}; 46char* firmware_filenames[] = {"MBoot.bin", "zImage", "cramfs-fsl.rom", "SYSDATA.bin"}; 47 48void cyclic_xor(void *data, int datasize, void *xor, int xorsize) 49{ 50 for(int i = 0; i < datasize; i++) 51 *(uint8_t *)(data + i) ^= *(uint8_t *)(xor + (i % xorsize)); 52} 53 54size_t get_filesize(FILE* handle) 55{ 56 long size = 0; 57 long old_pos = ftell(handle); 58 fseek(handle, 0, SEEK_END); 59 size = ftell(handle); 60 fseek(handle, old_pos, SEEK_SET); 61 return size; 62} 63 64/* A very rough implementation... */ 65void join_path(char* destination, char* first, char* second) 66{ 67 memset(destination, 0, MAX_PATH); 68 if (first != NULL && strlen(first) > 0) 69 { 70 strcpy(destination, first); 71 if (destination[strlen(destination) - 1] != DIR_SEPARATOR) 72 { 73 int l = strlen(destination); 74 destination[l] = DIR_SEPARATOR; 75 destination[l + 1] = '\0'; 76 } 77 } 78 strcat(destination, second); 79} 80 81void md5sum(char* md5sum_string, char* data, unsigned long size) 82{ 83 uint8_t md5_checksum[16]; 84 md5_context c; 85 md5_starts(&c); 86 md5_update(&c, (unsigned char*)data, size); 87 md5_finish(&c, md5_checksum); 88 memset(md5sum_string, 0, MD5_DIGEST_LENGTH*2+1); 89 for (int i = 0; i < MD5_DIGEST_LENGTH; i++) 90 { 91 sprintf(md5sum_string, "%02x", md5_checksum[i]); 92 md5sum_string+=2; 93 } 94}