11 Commits
Author SHA1 Message Date
pancake@flubox 4bc37cd723 * Initial support for plan9
- Use 'mk' to build.
  - Needs to be cleaned up
  - system and env access are ugly hacks
  - Some vars have been renamed to avoid p9 collisions
* Handle return values of read/write calls
  - Ubuntu's gcc is no warning anymore
2009-09-23 18:26:53 +02:00
[email protected] 763874f484 * Fixed c99 pedantic warning (signed issue in scanf) 2009-09-03 13:45:49 +00:00
[email protected] 11bebe5268 * mkdir before install 2009-09-03 11:17:48 +00:00
pancake@flubox fc76d60385 * Fix segfault when extending an invalid-format character (f.ex: px*) 2009-09-02 16:58:48 +02:00
[email protected] 0f3faf1144 * Add 'uninstall' makefile target
* Added DESTDIR in makefile
2009-09-01 22:51:53 +00:00
[email protected] 86f8b84cb4 * Update ChangeLog file
* Do not build with -g
2009-09-01 22:31:48 +00:00
[email protected] 02c4366a6f * Add manpages for ired and vired
* Compile with debugging information by default
* Added 'make dist' target
* Fix double free in cmd.c
* Fix disassemble mode in 'p' key of vired
2009-09-01 22:30:01 +00:00
[email protected] af5d0384c4 * Rename from red to ired to avoid program name collisions
--HG--
rename : red.c => ired.c
2009-09-01 21:17:05 +00:00
pancake@flubox f80aa1f2b6 * Fix search command. Oops :) 2009-07-17 11:47:55 +02:00
[email protected] 02d6fe4b53 * Fix segfault in cmd_search() 2009-07-12 01:22:15 +00:00
[email protected] 5ce5aeff66 * Bump revision number to 0.2 2009-07-11 16:31:06 +00:00
11 changed files with 688 additions and 60 deletions

No files matched your search

+415
View File
@@ -0,0 +1,415 @@
== release 0.2
changeset: 41:6fd885d7d0c2
tag: tip
user: [email protected]
date: Tue Sep 01 22:30:01 2009 +0000
files: ChangeLog Makefile cmd.c ired.1 vired vired.1
description:
* Add manpages for ired and vired
* Compile with debugging information by default
* Added 'make dist' target
* Fix double free in cmd.c
* Fix disassemble mode in 'p' key of vired
changeset: 40:97b4743c4dc6
user: [email protected]
date: Tue Sep 01 21:17:05 2009 +0000
files: Makefile ired.c red.c
description:
* Rename from red to ired to avoid program name collisions
changeset: 39:03da6e158902
user: pancake@flubox
date: Fri Jul 17 11:47:55 2009 +0200
files: Makefile cmd.c
description:
* Fix search command. Oops :)
changeset: 38:1715fc1d195e
user: [email protected]
date: Sun Jul 12 01:22:15 2009 +0000
files: cmd.c
description:
* Fix segfault in cmd_search()
changeset: 37:8ff91ac81732
user: [email protected]
date: Sat Jul 11 16:31:06 2009 +0000
files: ChangeLog red.h
description:
* Bump revision number to 0.2
== release 0.1
changeset: 36:ba4108a3c6d5
tag: tip
user: [email protected]
date: Sat Jul 11 16:28:35 2009 +0000
files: cmd.c
description:
* Fix gcc warning. Release 0.1
changeset: 35:a69c81ce6b79
user: [email protected]
date: Sat Jul 11 16:15:18 2009 +0000
files: Makefile
description:
* Use CFLAGS when compiling
changeset: 34:d3c02ddef876
user: [email protected]
date: Sat Jul 11 16:14:37 2009 +0000
files: cmd.c
description:
* Fix '!' command segfault
- Initialize buf in search command
changeset: 33:cd894a746246
user: [email protected]
date: Sat Jul 11 13:58:12 2009 +0000
files: util.c
description:
* Use 'isascii' instead of buf[0] for pz and pZ
changeset: 32:795733b782ee
user: [email protected]
date: Sat Jul 11 13:41:51 2009 +0000
files: io.c red.h
description:
* Full implementation of the w32 IO API
changeset: 31:af7a10ccfed7
user: [email protected]
date: Sat Jul 11 13:20:11 2009 +0000
files: Makefile red.h
description:
* First build for w32
- Added 'make w32'
- TODO: Use w32 IO API instead of posix by default on w32
changeset: 30:23d74ef2b61b
user: [email protected]
date: Sat Jul 11 13:09:01 2009 +0000
files: README
description:
* Some minor changes in README
changeset: 29:f46469969239
user: [email protected]
date: Sat Jul 11 13:02:59 2009 +0000
files: Makefile util.c
description:
* Added support for 'K' 'M' and 'G' suffix in str2ull function
- Added support for octal input (start with '0')
- po command shows in the same octal way ('0' prefix)
* Fix hexstr2bin with spaces
* Do not make loc vired
changeset: 28:bdcc2e8cfb90
user: [email protected]
date: Sat Jul 11 10:58:28 2009 +0000
files: cmd.c
description:
* Some code review and simplification -10LOC
changeset: 27:b944c1a84437
user: [email protected]
date: Sat Jul 11 10:54:29 2009 +0000
files: README red.c
description:
* Minor fix in README
* Remove end '.' in error message
changeset: 26:26582b52ed09
user: [email protected]
date: Sat Jul 11 10:52:13 2009 +0000
files: util.c
description:
* Fix build
changeset: 25:05b4d6b61a48
user: [email protected]
date: Sat Jul 11 10:50:22 2009 +0000
files: README
description:
* Fix README
changeset: 24:ef1a2671bbc6
user: [email protected]
date: Sat Jul 11 10:47:11 2009 +0000
files: cmd.c io.c red.c util.c
description:
* hexdump() now gets a 3rd argument to set the width
* Show filesize when no args given to 'r' command
- Truncate file when removing bytes (f.ex: r-10)
* Fix segfault in cmd_system() when no BLOCK is used, but [X]OFFSET is
* skipspaces() is now skipping 'all' spaces, not only the first one
* Some code cleanup (-5 LOC) - now is 499 LOC :P
changeset: 23:4f672b5b67b9
user: [email protected]
date: Sat Jul 11 01:26:54 2009 +0000
files: cmd.c vired
description:
* Fix segfault coz an uninitialized variable
* 'r' with no argument should return filesize
- not implemented
changeset: 22:0b6a9d1bcae2
user: [email protected]
date: Sat Jul 11 01:20:51 2009 +0000
files: Makefile cmd.c io.c red.c vired
description:
* Add command 'r' to resize and remove bytes
r128 : truncate file to 128 bytes
r-10 : remove 10 bytes from current seek
* Added io_truncate
* warning: 500LOC reached :)
changeset: 21:1de30455d1c5
user: [email protected]
date: Sat Jul 11 00:34:57 2009 +0000
files: red.c
description:
* Simplify argv parsing (-1 LOC)
changeset: 20:d37eb8dbb125
user: [email protected]
date: Sat Jul 11 00:27:02 2009 +0000
files: cmd.c red.c util.c
description:
* Add '?' in help message
* Simplify and add more checks in cmd_system()
- setenv FILE once
* Simplify code for parsing arguments
- Minor simplification in hexstr2raw
changeset: 19:f455f21e48f9
user: [email protected]
date: Sat Jul 11 00:07:45 2009 +0000
files: Makefile cmd.c red.c util.c
description:
* Code cleanup (-18 LOC)
- Move print_fmt stuff into utils.c
* Use static in more functions
changeset: 18:de171facddfb
user: [email protected]
date: Fri Jul 10 23:43:24 2009 +0000
files: Makefile cmd.c
description:
* Fix some valgrind warnings in the print format command
- Some uninitialized variable usage
- Out of buffer reads are now controlled
- repeat last print format until the end of the block
changeset: 17:48f165d7837a
user: [email protected]
date: Fri Jul 10 23:22:23 2009 +0000
files: cmd.c util.c vired
description:
* Set vired block size to 256
- Set P='' to avoid env interference
* Do not overwrite bsize
changeset: 16:edef8bd2b6ca
user: [email protected]
date: Fri Jul 10 20:41:16 2009 +0000
files: README cmd.c red.c
description:
* Initial implementation of the 'p' command to print
current block as a formatted buffer ('p' for help)
* Add 'X' command in the help message
* Do not parse '@' if ! is used
changeset: 15:7097e08566c4
user: pancake@flubox
date: Fri Jul 10 20:00:12 2009 +0200
files: util.c vired
description:
* Added support for 's+b' and 's-b'
changeset: 14:1c28afb4af0b
user: pancake@flubox
date: Fri Jul 10 19:54:26 2009 +0200
files: README cmd.c
description:
* Define new 'p' command in README
* Fix help message for 'w' command
changeset: 13:963aaffb26b7
user: pancake@flubox
date: Fri Jul 10 18:40:27 2009 +0200
files: cmd.c
description:
* Fix obsize in cmd_bsize()
changeset: 12:fc86586c1084
user: pancake@flubox
date: Fri Jul 10 18:29:30 2009 +0200
files: cmd.c red.c util.c
description:
* Split hexdump() in util.c
* Added support for ':' syntax for temporal blocksize
* Added '-' for slurping stdin like hexdump -C
changeset: 11:dff8083d3b66
user: pancake@flubox
date: Fri Jul 10 18:10:09 2009 +0200
files: cmd.c util.c
description:
* Fix end-of-file and out-of-file IO reads
-2 LOC :)
changeset: 10:0ef965f1cd6b
user: pancake@flubox
date: Tue Jul 07 18:28:24 2009 +0200
files: README cmd.c red.c util.c
description:
* Use ut64 and ut8 instead of ull and uc8
- More consistent type names. radare and libr must change this too
changeset: 9:ce9c10de16dd
user: pancake@flubox
date: Tue Jul 07 18:00:01 2009 +0200
files: io.c red.c util.c
description:
* Use oneliner switch statements for single ops
- Safe -29 LOC
* Fix previous commit (broken build)
* Internal io fd has been renamed to fix a bug
changeset: 8:5ff3f119598c
user: pancake@flubox
date: Tue Jul 07 17:49:35 2009 +0200
files: io.c
description:
* io layer rewritten as cpp macros
- earn -23LOC
changeset: 7:f3d9af189f4c
user: pancake@flubox
date: Tue Jul 07 11:53:45 2009 +0200
files: vired
description:
* Do not use 'read -n' coz is posix shell
changeset: 6:e9dd080db646
user: [email protected]
date: Tue Jul 07 09:41:52 2009 +0000
files: README cmd.c io.c red.c util.c vired
description:
* Added '>' and '<' command to dump and load bytes
from/to files and current block
* Added '.' command to interpret files
* Fix vired for iphoneos (no /dev/stderr, only /dev/tty)
* Some code simplification (reduced some LOCs)
changeset: 5:62eeb4806234
user: [email protected]
date: Mon Jul 06 10:11:34 2009 +0000
files: cmd.c red.c vired
description:
* Implement '/' search command for hex and strings
* Export OFFSET, XOFFSET, FILE and BLOCK environment
to the system '!' command
* Rename '-s' to '-n'
* Make vired self-sufficient
- 'p' toggles between hexa and disasm (using rasm2 -d -)
- Added 'b' key to change block size
- '?' key show help
changeset: 4:3aec8e4c3367
user: [email protected]
date: Sun Jul 05 23:33:51 2009 +0000
files: Makefile cmd.c io.c red.c vired
description:
* Initial import of 'vired'
- The shellscript implementation of the visual mode for 'red'
* Added support to relative change the block size
* Added '!' command to run shell commands
* Added 'X' command to print curblock as hexpairs
changeset: 3:d81b7e09cbce
user: [email protected]
date: Sun Jul 05 22:49:48 2009 +0000
files: cmd.c io.c red.c red.h util.c
description:
* Abstract io stuff in io.c
* 's' command displays curseek when no arg given
- s+ and s- are used to do relative seeks
* Fix 64 bit hexa parsing
* 256 bytes as default block size
changeset: 2:0081ce1e5731
user: [email protected]
date: Sat Jul 04 20:42:27 2009 +0000
files: Makefile cmd.c red.c util.c
description:
* Implement 'w' command to write hexpairs and strings
* Fix hexdump for short buffers
* Added help message and flags for the shell
-h for help
-i [file] interpret file
-s silent
-v version
changeset: 1:75196ad1be66
user: [email protected]
date: Fri Jul 03 20:12:28 2009 +0000
files: Makefile red.c
description:
* Add install target.
* Fix 0arg run
changeset: 0:ed796be9f25e
user: pancake@flubox
date: Fri Jul 03 20:11:24 2009 +0200
files: Makefile README cmd.c red.c red.h util.c
description:
* Initial import of 'red' the raw editor
- A minimalistic implementation of the radare shell
+24 -6
View File
@@ -1,20 +1,38 @@
CC?=gcc
CCw32?=i486-mingw32-gcc
CFLAGS+=-Wall -O2
CFLAGS+=-O2 -Wall
PREFIX?=/usr
DESTDIR?=
all:
${CC} ${CFLAGS} red.c -o red
${CC} ${CFLAGS} ired.c -o ired
dist:
if [ -z "${VERSION}" ]; then echo "make dist VERSION=0.3" ; exit 1 ; fi
mkdir -p ired-${VERSION}
cd ired-${VERSION} ; hg clone .. . ; rm -rf .hg
tar czvf ired-${VERSION}.tar.gz ired-${VERSION}
rm -rf ired-${VERSION}
w32:
${CCw32} ${CFLAGS} red.c -o red.exe
${CCw32} ${CFLAGS} ired.c -o ired.exe
loc:
@wc -l *.c *.h | grep total
clean:
rm -f red red.o
rm -f ired ired.o
install:
cp red ${PREFIX}/bin
cp vired ${PREFIX}/bin
mkdir -p ${DESTDIR}${PREFIX}/bin
cp ired ${DESTDIR}${PREFIX}/bin
cp vired ${DESTDIR}${PREFIX}/bin
mkdir -p ${DESTDIR}${PREFIX}/share/man/man1
cp ired.1 ${DESTDIR}${PREFIX}/share/man/man1
cp vired.1 ${DESTDIR}${PREFIX}/share/man/man1
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/ired
rm -f ${DESTDIR}${PREFIX}/bin/vired
rm -f ${DESTDIR}${PREFIX}/share/man/man1/ired.1
rm -f ${DESTDIR}${PREFIX}/share/man/man1/vired.1
+40 -25
View File
@@ -18,7 +18,7 @@ static void cmd_print(char *arg) {
print_fmt(buf, arg, len);
free(buf);
} else printf(
"ob/wW/dD/qQ byte (oct,hex), word, dword, qword (little, big endian)\n"
"ob/wW/dD/qQ byte (oct,hex), word, dword, qword (lil, big endian)\n"
"i/I/f/F int32 (lil, big), float (lil, big)\n"
"s/S short int16 (lil, big)\n"
"z/Z zero-terminatted string (ascii, wide-ascii)\n"
@@ -36,7 +36,7 @@ static void cmd_bytedump(char *arg) {
}
void cmd_search(char *arg) {
unsigned char *buf = NULL;
unsigned char *buf;
unsigned int i, len, hit=0;
arg = skipspaces(arg);
if (*arg=='"') {
@@ -44,14 +44,14 @@ void cmd_search(char *arg) {
len = strlen(arg)-1;
arg[len]='\0';
} else len = hexstr2raw(arg);
if ((buf = getcurblk("", &len)))
if ((buf = getcurblk("", &bsize)))
do {
for(i=0;i<bsize;i++) {
if (arg[hit++]!=buf[i]) hit = 0;
else if (hit == len)
printf("0x%llx\n", seek+i-len+1);
printf("0x%"LLF"x\n", curseek+i-len+1);
}
seek+=bsize;
curseek += bsize;
} while(io_read(buf, bsize)>0);
free(buf);
}
@@ -66,28 +66,35 @@ static void cmd_bsize(char *arg) {
}
static void cmd_seek(char *arg) {
if (!*arg) printf("%lld\n", seek);
else if (*arg=='+') oseek = seek += str2ut64(arg+1);
else if (*arg=='-') oseek = seek -= str2ut64(arg+1);
else oseek = seek = str2ut64(arg);
if (!*arg) printf("%"LLF"d\n", curseek);
else if (*arg=='+') curseek += str2ut64(arg+1);
else if (*arg=='-') curseek -= str2ut64(arg+1);
else curseek = str2ut64(arg);
oldseek = curseek;
}
static void cmd_dump(char *file) {
unsigned int len = bsize;
void *buf = getcurblk("", &len);
FILE *fd = fopen(file, "wb");
fwrite(buf, len, 1, fd);
if (fwrite(buf, len, 1, fd)<len)
perror("fwrite");
fclose(fd);
free(buf);
}
static void cmd_load(char *file) {
int len;
void *buf;
FILE *fd = fopen(file, "rb");
if (!fd) return;
buf = malloc(bsize);
if (!buf) return;
io_write(buf, fread(buf, 1, bsize, fd));
len = fread(buf, 1, bsize, fd);
if (len<bsize)
perror("fread");
if (io_write(buf, len)<len)
perror("io_write");
fclose(fd);
free(buf);
}
@@ -100,14 +107,15 @@ static void cmd_write(char *arg) {
len = strlen(arg)-1;
arg[len]='\0';
} else len = hexstr2raw(arg);
io_seek(seek, SEEK_SET);
io_write(arg, len);
io_seek(curseek, SEEK_SET);
if (io_write(arg, len)<len)
perror("io_write");
}
static void cmd_help(char *arg) {
if (*arg) {
ut64 ret = str2ut64(arg);
printf("0x%llx %lld 0%llo\n", ret, ret, ret);
printf("0x%"LLF"x %"LLF"d 0%"LLF"o\n", ret, ret, ret);
} else printf(
"s[+-addr] seek to relative or absolute address\n"
"b[+-size] change block size\n"
@@ -127,22 +135,26 @@ static void cmd_help(char *arg) {
static void cmd_resize(char *arg) {
unsigned int len;
if (!*arg) printf("%lld\n", io_seek(0, SEEK_END));
int ret = 0;
if (!*arg) printf("%"LLF"d\n", (long long int)io_seek(0, SEEK_END));
else if (*arg=='-') {
ut8 *buf = malloc(bsize);
ut64 i, n = str2ut64(arg+1);
if (buf) {
ut64 i, n = str2ut64(arg+1);
for(i=0;;i+=len) {
io_seek(seek+n+i, SEEK_SET);
io_seek(curseek+n+i, SEEK_SET);
len = io_read(buf, bsize);
if (len<1) break;
io_seek(seek+i, SEEK_SET);
io_write(buf, len);
io_seek(curseek+i, SEEK_SET);
if (io_write(buf, len)<len)
perror("io_write");
}
free(buf);
ret = io_truncate(io_seek(0, SEEK_END)-n);
}
io_truncate(io_seek(0, SEEK_END)-n);
} else io_truncate(str2ut64(arg));
} else ret = io_truncate(str2ut64(arg));
if (ret<0)
perror("truncate");
}
static void cmd_system(char *arg) {
@@ -154,21 +166,24 @@ static void cmd_system(char *arg) {
buf = getcurblk("", &len);
if (buf) {
setenv("BLOCK", ".curblk", 1);
fwrite(buf, len, 1, fd);
if (fwrite(buf, len, 1, fd)<len)
perror("fwrite");
fclose(fd);
free(buf);
buf = NULL;
}
}
}
if (strstr(arg, "OFFSET")) {
sprintf(str, "%lld", seek);
sprintf(str, "%"LLF"d", curseek);
setenv("OFFSET", str, 1); // XXX
}
if (strstr(arg, "XOFFSET")) {
sprintf(str, "0x%llx", seek);
sprintf(str, "0x%"LLF"x", curseek);
setenv("XOFFSET", str, 1); // XXX
}
io_system(arg);
if (io_system(arg)<0)
perror("system");
unlink(".curblk");
free(buf);
}
+6 -6
View File
@@ -1,11 +1,7 @@
/* Copyleft 2009 -- pancake /at/ nopcode /dot/ org */
#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#if __WIN32__
#include <windows.h>
static HANDLE _fd = NULL;
@@ -27,9 +23,13 @@ static int io_read(void *x, int y) {
#define io_seek(x,y) SetFilePointer(_fd,x,0,!y?FILE_BEGIN:y==1?FILE_CURRENT:FILE_END)
#define io_close() CloseHandle(_fd)
#define io_system(x) system(x)
#define io_truncate(x) { io_seek(x,SEEK_SET); SetEndOfFile(_fd); }
#define io_truncate(x) 0; { io_seek(x,SEEK_SET); SetEndOfFile(_fd); }
#else
#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#include <fcntl.h>
static int _fd = -1;
static inline int io_open(char *file) {
_fd = open(file, O_RDWR|O_CREAT, 0644);
+115
View File
@@ -0,0 +1,115 @@
.Dd Sep 1, 2009
.Dt IRED 1
.Os
.Th IRED 1
.Sh NAME
ired \- interactive raw editor
.Sh SYNOPSIS
.Nm ired
.Op Fl hnv
.Op Fl i Ar script
.Ar file ...
.Sh DESCRIPTION
Simple and minimal hexadecimal editor based on radare concepts
.Pp
The program arguments are:
.Pp
.Bl -tag -width Fl
.It Fl h
Show help message
.It Fl v
Show version information
.It Fl n
Do not be verbose
.It Fl i Ar script
Interpret a script file as ired commands.
.Pp
Same as "ired file < script"
.El
.PP
.Sh COMMANDS
.Pp
.Bl -tag -width Fl
.It s[+-addr]
seek to relative or absolute address
.Pp
> s 0x400 # seek to offset 0x400
.Pp
> s+20 # seek 20 bytes forward
.It b[+-size]
change block size
.Pp
> b 5 # set block size to 5 bytes
.Pp
> b +128 # increase block size in 128 bytes
.It w[hex|"str"]
write hexpair or string
.Pp
> w 001122 # write 0x00 0x11 0x22
.Pp
> w"Hello World" # write "Hello World" string without quotes
.It /[hex|"str"]
search hexpair or string
.Pp
> /894722 # search bytes 0x89 0x47 0x22
.Pp
> /"lib" # search string 'lib'
.It x[size]
hexdump
.Pp
> x 256 # dump 256 bytes in hexadecimal
.It X[size]
hexpair dump
.Pp
> X 0x100 # dump 256 bytes in hexpairs
.It p[fmt]
print formatted current block ('p' for help)
.Pp
ob/wW/dD/qQ byte (oct,hex), word, dword, qword (lil, big endian)
.Pp
i/I/f/F int32 (lil, big), float (lil, big)
.Pp
s/S short int16 (lil, big)
.Pp
z/Z zero-terminatted string (ascii, wide-ascii)
.Pp
./:/* skip 1 or 4 chars, repeat last format instead of cycle
.It r[-[num]]
truncate or -remove N bytes
.Pp
> r 1024 # resize file to 1024 bytes
.Pp
> r-10 # remove 10 bytes from current seek and shrink file
.It .[file]
interpret file
.Pp
> .script # run file 'script'
.It <[file]
load file in current seek
.Pp
> <curblock.bin # load blocksize bytes from file
.It >[file]
dump current block to file
.Pp
> >curblock.bin # dump current block to a file
.It !cmd
run shell command
.Pp
> !cp $BLOCK $FILE.curblock # save current block
.It ?expr
calculate numeric expression
.Pp
> ?1024
.Pp
0x400 1024 02000
.It q
quit
.El
.Sh SEE ALSO
.Pp
.Xr vired(1)
.Sh AUTHORS
.PP
pancake <@nopcode.org>
+13 -12
View File
@@ -5,7 +5,7 @@
static int verbose = 1;
static char *script = 0;
static ut64 oseek, seek = 0LL;
static ut64 oldseek, curseek = 0LL;
static unsigned int obsize, bsize = 256;
static int red_cmd(char *cmd); // XXX : recursive depenency
@@ -18,7 +18,7 @@ int red_slurpin() {
len = read(0, buf, 4096);
if (len<1) break;
hexdump(buf, len, 16);
seek += len;
curseek += len;
}
return 0;
}
@@ -29,8 +29,8 @@ static char *red_interpret(char *file) {
if (fd != NULL) {
file = NULL;
for(;;) {
fgets(buf, 1023, fd);
if (feof(fd)) break;
if (fgets(buf, 1023, fd) == NULL)
break;
red_cmd(buf);
}
fclose(fd);
@@ -40,6 +40,7 @@ static char *red_interpret(char *file) {
static int red_cmd(char *cmd) {
switch(*cmd) {
case ';': case '#': break; // comment
case 'q': return 0;
case '>': cmd_dump(cmd+1); break;
case '<': cmd_load(cmd+1); break;
@@ -62,15 +63,15 @@ static int red_cmd(char *cmd) {
static int red_prompt() {
char *at, *at2, line[4096];
if (verbose) {
printf("[0x%08llx]> ", seek);
printf("[0x%08"LLF"x]> ", curseek);
fflush(stdout);
}
fgets(line, 4095, stdin);
if (feof(stdin)) return 0;
if (fgets(line, 4095, stdin) == NULL)
return 0;
line[strlen(line)-1] = 0;
if (line[0] != '!') {
at = strchr(line, '@');
oseek = seek;
oldseek = curseek;
obsize = bsize;
if (at) {
*at = 0; at++;
@@ -79,20 +80,20 @@ static int red_prompt() {
*at2 = 0; at2++;
if (*at2) bsize = (int)str2ut64(at2);
}
if (*at) seek = str2ut64(at);
if (*at) curseek = str2ut64(at);
}
}
return red_cmd(skipspaces(line));
}
static void red_open(char *file) {
oseek = 0;
oldseek = 0;
setenv("FILE", file, 1);
if (io_open(file) != -1) {
if (script)
script = red_interpret(script);
while(red_prompt()) {
seek = oseek;
curseek = oldseek;
bsize = obsize;
}
io_close();
@@ -100,7 +101,7 @@ static void red_open(char *file) {
}
static int red_help() {
puts("red [-hnv] [-i script] [file] [..]");
puts("ired [-hnv] [-i script] [file] [..]");
return 0;
}
+10
View File
@@ -0,0 +1,10 @@
</$objtype/mkfile
CC=pcc
ALL=ired
9ired:
$CC -Dplan9 -D_POSIX_SOURCE -D_BSD_EXTENSION $CFLAGS -o 9ired ired.c
clean:
rm -f ired.$O 9ired
+15 -3
View File
@@ -1,11 +1,23 @@
#define VERSION "0.1"
#define VERSION "0.3"
#include "io.c"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#if(plan9)
static int setenv(char *var, char *val, int force) {
char str[128];
snprintf(str, sizeof(str), "echo %s > /env/%s", var, val);
if (system(str)<0)
perror("system");
return force;
}
#define LLF "L"
#else
#define LLF "ll"
#endif
#include "util.c"
#include "cmd.c"
+9 -6
View File
@@ -1,5 +1,7 @@
/* Copyleft 2009 -- pancake /at/ nopcode /dot/ org */
#include <ctype.h>
static inline char *skipspaces(char *arg) {
while (*arg==' '||*arg=='\t') arg++;
return arg;
@@ -8,7 +10,7 @@ static inline char *skipspaces(char *arg) {
static inline void hexdump(const ut8 *buf, unsigned int len, int w) {
unsigned int i, j;
for(i=0;i<len;i+=w) {
printf("0x%08llx ", seek+i);
printf("0x%08" LLF "x ", curseek+i);
for(j=i;j<i+w;j++) {
if (j>=len) {
printf(j%2?" ":" ");
@@ -52,6 +54,7 @@ static void print_fmt(const ut8 *buf, char *fmt, unsigned int len) {
case 'Z': for(i=0; inc<len && isascii(buf[0]);i++) { printf("%c", buf[0]); buf+=2; inc+=2; } if(i)printf("\n"); break;
case '*': rep = lup; break;
default: fprintf(stderr, "Unknown format '%c' (%d)\n", up, up);
return;
}
if (!rep) lup = up;
buf += inc;
@@ -68,9 +71,9 @@ static ut64 str2ut64(char *str) {
if (str[0]=='b'&&str[1]==0)
ret = bsize;
else if (str[0]=='0') {
if (str[1]=='x') sscanf(str, "0x%llx", &ret);
else sscanf(str, "0x%llo", &ret);
} else sscanf(str, "%lld", &ret);
if (str[1]=='x') sscanf(str, "0x%"LLF"x", &ret);
else sscanf(str, "0x%"LLF"o", &ret);
} else sscanf(str, "%"LLF"u", &ret);
str+=strlen(str)-1;
if (*str=='K') ret *= 1024;
else if (*str=='M') ret *= 1024*1024;
@@ -87,7 +90,7 @@ static int hex2byte(ut8 *val, ut8 c) {
}
static int hexstr2raw(char *arg) {
ut8 *ptr, c = 0, d = 0;
ut8 *ptr, c = 0, d;
unsigned int j = 0, len = 0;
for (ptr=(ut8 *)arg;*ptr;ptr++) {
if (*ptr==' ') continue;
@@ -111,7 +114,7 @@ static void *getcurblk(char *arg, unsigned int *len) {
if (*len <1) *len = bsize;
}
if ((buf = malloc(*len)) != NULL) {
if (io_seek(seek, SEEK_SET)<0) {
if (io_seek((int)curseek, SEEK_SET)<0) {
free(buf);
buf = NULL;
} else *len = io_read(buf, *len);
+2 -2
View File
@@ -3,7 +3,7 @@
# copyleft: pancake at nopcode dot org @ 2009
if [ -n "$1" ]; then
$0 | red -n $@
$0 | ired -n $@
exit 0
fi
@@ -22,7 +22,7 @@ echo "b 256"
while : ; do
echo "!clear"
case $P in
'd') echo '!echo X | red -s $BLOCK | rasm2 -o $OFFSET -d -' ;;
'd') echo '!echo X | ired -n $BLOCK | rasm2 -o $OFFSET -d -' ;;
*) echo x ;;
esac
A=`dd if=/dev/tty count=1 bs=1 2>/dev/null`
+39
View File
@@ -0,0 +1,39 @@
.Dd Sep 1, 2009
.Dt VIRED 1
.Os
.Th VIRED 1
.Sh NAME
vired \- visual interactive raw editor
.Sh SYNOPSIS
.Nm vired
.Ar file
.Sh DESCRIPTION
Visual mode for ired(1)
.Pp
.Sh KEYS
.Bl -tag -width Fl
.It hjkl
seek left(-1), down(+16), up(-16), right(+1)
.It +-*/
change block size (+1,-1,+16,-16)
.It :[cmd]
input ired command
.It b
prompt to change block size
.It s
prompt seek address
.It r
prompt for resize, remove command
.It p
change print mode
.It ?
show help
.It q
quit program
.Pp
.Sh SEE ALSO
.Pp
.Xr ired(1)
.Sh AUTHORS
.PP
pancake <@nopcode.org>