/* * NVRAM WakeUp * Copyright (C) 2001-2005, Sergei Haller. * Copyright (C) 2002, Bernhard Rosenkraenzer * * $Id: guess.c 835 2005-03-16 22:43:39Z bistr-o-math $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #define CVSREV_guess_c \ "$Id: guess.c 835 2005-03-16 22:43:39Z bistr-o-math $" #include #include #include #include #include #include #include #include "nvram-wakeup.h" #define MAXFILES 4 /* We need four files ro guess the values */ /* * defined in nvram-wakeup.h: * * MAXNVRAMSIZE 0x100 -- possible addresses 0x00, .., 0xFF */ #define MINNVRAMSIZE 0x72 /* but at least 0x00, .., 0x71 */ unsigned char byte[MAXFILES][MAXNVRAMSIZE]; /* * unsigned char calculate_read( const unsigned char b, * const unsigned char nr, * const unsigned char sh, * const unsigned int bcd) { * unsigned char msk = 255 >> (8-nr) << sh; * unsigned char retval = (msk & b) >> sh; * if (bcd) * retval = (retval >> 4)*10 + ((unsigned char)(retval << 4) >> 4); * return retval; * } */ /* suppose nr == 5, sh == 1; * b = b7 ... b0 and c = c7 ... c0 (in binary notation). * * this function compares if * * b7 b6 0 0 0 0 0 b0 == c7 c6 0 0 0 0 0 c0 */ unsigned char is_equal_else( const unsigned char b, const unsigned char c, const unsigned char nr, const unsigned char sh ) { unsigned char not_msk = ~(255 >> (8-nr) << sh); return (not_msk & b) == (not_msk & c); } int could_it_be(const unsigned int *test, const unsigned int *stat, const char *str, const unsigned int addr, const unsigned int nr) { unsigned int i, shift, could_be, retval=0, differs_else, reset_day, reset_mon, rtc_day_0_is_c0, rtc_mon_0_is_c0; if (strncmp(str, "rtc", 3) == 0) { /* in BCD notation */ could_be = 1; differs_else = 0; reset_day = 0; reset_mon = 0; rtc_day_0_is_c0 = 0; rtc_mon_0_is_c0 = 0; for (i = 0; i 01, 00:00:00 */ /* nvram-wakeup -s 2015320694 --> 11, 12:13:14 */ /* nvram-wakeup -s 2014412699 --> 31, 23:59:59 */ int main(int argc, char **argv) { unsigned int act_size = MAXNVRAMSIZE; int retval, fd[MAXFILES], is_diff; unsigned int i, addr, sz_of_diff_addr=0, sz_of_chk_addr=0; unsigned char *diff_addr = malloc(sz_of_diff_addr), *addr_ptr, *chk_addr = malloc(sz_of_chk_addr); const unsigned int mon [] = { 12, 10, 1, 1}, day [] = { 31, 11, 1, 1}, hour[] = { 23, 12, 0, 0}, min [] = { 59, 13, 0, 0}, sec [] = { 59, 14, 0, 0}, stat[] = { 1, 1, 1, 0}; char *files[MAXFILES]; set_progname(argv[0]); enable_debug(); fprintf(stderr, CVSREV_guess_c "\n"); if (argc>1) { fprintf(stderr, "Too many arguments.\n"); leave(1); } /* open the files */ for (i = 0; ichk_addr[1]?chk_addr[0]:chk_addr[1])); } else { fprintf(stderr, "Couldn't guess checksum addresses (out of %u).\n", sz_of_chk_addr); } printf("\n"); return 0; }