Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IGzB3-0006dc-QH for mharc-grub-devel@gnu.org; Fri, 03 Aug 2007 11:34:57 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IGzB2-0006dT-7e for grub-devel@gnu.org; Fri, 03 Aug 2007 11:34:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IGzAy-0006cM-J5 for grub-devel@gnu.org; Fri, 03 Aug 2007 11:34:55 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IGzAy-0006cJ-BT for grub-devel@gnu.org; Fri, 03 Aug 2007 11:34:52 -0400 Received: from ik-out-1112.google.com ([66.249.90.178]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IGzAv-0006Bc-F3 for grub-devel@gnu.org; Fri, 03 Aug 2007 11:34:50 -0400 Received: by ik-out-1112.google.com with SMTP id c29so423787ika for ; Fri, 03 Aug 2007 08:33:40 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=H9LSw5bPFMLOxYdWAWqyP5MqzNKa7BY5/NqFhholJI2So5xXPimCvw57jFKfpmSYIIQhaVv9MgqqNEiHbRgGHEZYY85JwYtAIijFhwIgrOyKMFZKF/XGfsQTL6dRKrIZvhkQ9W2j5jXMROt3sFdEi5e/Rw1NHoM9LYJlYV+aG3g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=Helj7vX0bBYR3SlFzzH2HR0yFxx8kooCY1j8680iHzCNatKtpstpc1943MO1E3b9ZhPom4RYGcPq/NjXzXhZN29LJplI3IR7WA77/A1ZI8pWLZ6YpdIcT+ye7NhwrsOy26hp0p8r4lhfPiwTvurg+euu1/onF0F/N6psP9QxjBg= Received: by 10.65.225.7 with SMTP id c7mr5948759qbr.1186155219409; Fri, 03 Aug 2007 08:33:39 -0700 (PDT) Received: by 10.64.48.11 with HTTP; Fri, 3 Aug 2007 08:33:38 -0700 (PDT) Message-ID: Date: Fri, 3 Aug 2007 23:33:38 +0800 From: Bean To: "The development of GRUB 2" MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Detected-Kernel: Linux 2.6 (newer, 2) Subject: New command dump X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2007 15:34:56 -0000 Hi, I have written a new command dump, it can hex dump content of file or memor= y. usage: dump [-s skip] [-n length] { FILE | (mem) } The output look just like command hexdump. If you use (mem) as filename, it will dump physical memory instead of file. when dumping memory, the default length is 256, but when dumping normal file, the default length is the whole file. Inside grub2, modules can call function dump directly: void dump(unsigned long base,char* buf, int len); --=20 Bean 2007-08-03 Bean =09* conf/common.rmk (pkgdata_MODULES): Add dump.mod. =09(dump_mod_SOURCES): New variable. =09(dump_mod_CFLAGS): Likewise. =09(dump_mod_LDFLAGS): Likewise. =09* include/grub/dump.h: New file. =09* commands/dump.c: New file. Index: conf/common.rmk =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/grub/grub2/conf/common.rmk,v retrieving revision 1.16 diff -u -p -r1.16 common.rmk --- conf/common.rmk=092 Aug 2007 19:12:52 -0000=091.16 +++ conf/common.rmk=093 Aug 2007 14:59:55 -0000 @@ -199,7 +199,7 @@ lvm_mod_LDFLAGS =3D $(COMMON_LDFLAGS) pkgdata_MODULES +=3D hello.mod boot.mod terminal.mod ls.mod=09\ =09cmp.mod cat.mod help.mod font.mod search.mod=09=09\ =09loopback.mod configfile.mod=09=09=09=09\ -=09terminfo.mod test.mod blocklist.mod +=09terminfo.mod test.mod blocklist.mod dump.mod # For hello.mod. hello_mod_SOURCES =3D hello/hello.c @@ -276,6 +276,11 @@ blocklist_mod_SOURCES =3D commands/blockli blocklist_mod_CFLAGS =3D $(COMMON_CFLAGS) blocklist_mod_LDFLAGS =3D $(COMMON_LDFLAGS) +# For blocklist.mod. +dump_mod_SOURCES =3D commands/dump.c +dump_mod_CFLAGS =3D $(COMMON_CFLAGS) +dump_mod_LDFLAGS =3D $(COMMON_LDFLAGS) + # Misc. pkgdata_MODULES +=3D gzio.mod elf.mod Index: include/grub/dump.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/grub/grub2/include/grub/dump.h,v diff -Nu include/grub/dump.h --- /dev/null=092007-08-03 21:55:33.600000000 +0800 +++ include/grub/dump.h=092007-08-03 18:27:57.000000000 +0800 @@ -0,0 +1,25 @@ +/* dump.h - prototypes for dump */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#ifndef GRUB_DUMP_H +#define GRUB_DUMP_H=091 + +void dump(unsigned long bse,char* buf,int len); + +#endif /* ! GRUB_DUMP_H */ Index: commands/dump.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/grub/grub2/commands/dump.c,v diff -Nu commands/dump.c --- /dev/null=092007-08-03 21:55:33.600000000 +0800 +++ commands/dump.c=092007-08-03 23:00:48.000000000 +0800 @@ -0,0 +1,144 @@ +/* dump.c - command to dump the contents of a file or memory */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct grub_arg_option options[] =3D { + {"skip", 's', 0, "skip offset bytes from the beginning of file.", 0, + ARG_TYPE_INT}, + {"length", 'n', 0, "read only length bytes", 0, ARG_TYPE_INT}, + {0, 0, 0, 0, 0, 0} +}; + +void +dump (unsigned long bse, char *buf, int len) +{ + int pos; + char line[80]; + + while (len > 0) + { + int cnt, i; + + pos =3D grub_sprintf (line, "%08lx ", bse); + cnt =3D 16; + if (cnt > len) +=09cnt =3D len; + + for (i =3D 0; i < cnt; i++) +=09{ +=09 pos +=3D grub_sprintf (&line[pos], "%02x ", (unsigned char) buf[i]); +=09 if ((i & 7) =3D=3D 7) +=09 line[pos++] =3D ' '; +=09} + + for (; i < 16; i++) +=09{ +=09 pos +=3D grub_sprintf (&line[pos], " "); +=09 if ((i & 7) =3D=3D 7) +=09 line[pos++] =3D ' '; +=09} + + line[pos++] =3D '|'; + + for (i =3D 0; i < cnt; i++) +=09line[pos++] =3D ((buf[i] >=3D 32) && (buf[i] < 127)) ? buf[i] : '.'; + + line[pos++] =3D '|'; + + line[pos] =3D 0; + + grub_printf ("%s\n", line); + + bse +=3D 16; + buf +=3D 16; + len -=3D cnt; + } +} + +static grub_err_t +grub_cmd_dump (struct grub_arg_list *state, int argc, char **args) +{ + grub_file_t file; + char buf[GRUB_DISK_SECTOR_SIZE]; + grub_ssize_t size, length; + unsigned long skip; + int is_file; + + if (argc !=3D 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); + + skip =3D (state[0].set) ? grub_strtoul (state[0].arg, 0, 0) : 0; + length =3D (state[1].set) ? grub_strtoul (state[1].arg, 0, 0) : 0; + + is_file =3D (grub_strcmp (args[0], "(mem)")); + if ((!is_file) && (!length)) + length =3D 256; + + if (is_file) + { + file =3D grub_gzfile_open (args[0], 1); + if (!file) +=09return 0; + + file->offset =3D skip; + + while ((size =3D grub_file_read (file, buf, sizeof (buf))) > 0) +=09{ +=09 unsigned long len; + +=09 len =3D ((length) && (size > length)) ? length : size; +=09 dump (skip, buf, len); +=09 skip +=3D len; +=09 if (length) +=09 { +=09 length -=3D len; +=09 if (!length) +=09=09break; +=09 } +=09} + + grub_file_close (file); + } + else + dump (skip, (char *) skip, length); + + return 0; +} +=0C + +GRUB_MOD_INIT (dump) +{ + (void) mod;=09=09=09/* To stop warning. */ + grub_register_command ("dump", grub_cmd_dump, GRUB_COMMAND_FLAG_BOTH, +=09=09=09 "dump [ -s offset ] [-n length] { FILE | (mem) }", +=09=09=09 "Dump the contents of a file or memory.", options); +} + +GRUB_MOD_FINI (dump) +{ + grub_unregister_command ("dump"); +}