13 Commits
Author SHA1 Message Date
pancake@flubox 28d49ebd95 * Release ired 0.4
* Set PATH in vired to run it from current directory
2009-12-22 13:50:45 +01:00
[email protected] 4312ed31c8 * Updated manpages with documentation about environment
* Lot of small code cleanups (reduce code to 500LOC)
  - Sort include directives
  - Fix return value when file open fails
  - Reduce function exit points
  - More use of the ? operator
  - Bigger buffers for variables
* Add more checks in many places
  - Show errors when something is wrong
  - Check for negative values
  - Use ut8 and ut64 when possible
2009-10-07 02:48:18 +02:00
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 797 additions and 160 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
+95 -79
View File
@@ -1,8 +1,8 @@
/* Copyleft 2009 -- pancake /at/ nopcode /dot/ org */
static void cmd_hexdump(char *arg) {
unsigned int len = bsize;
unsigned char *buf = getcurblk(arg, &len);
int len = bsize;
ut8 *buf = getcurblk(arg, &len);
if (buf) {
hexdump(buf, len, 16);
free(buf);
@@ -10,15 +10,15 @@ static void cmd_hexdump(char *arg) {
}
static void cmd_print(char *arg) {
unsigned char *buf;
unsigned int len = bsize;
ut8 *buf;
int len = bsize;
if (*arg) {
buf = getcurblk(arg, &len);
if (!buf) return;
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"
@@ -26,32 +26,33 @@ static void cmd_print(char *arg) {
}
static void cmd_bytedump(char *arg) {
unsigned int i, len = bsize;
unsigned char *buf = getcurblk(arg, &len);
if (!buf) return;
for(i=0;i<len;i++)
printf("%02x", buf[i]);
printf("\n");
free(buf);
int i, len = bsize;
ut8 *buf = getcurblk(arg, &len);
if (buf) {
for(i=0;i<len;i++)
printf("%02x", buf[i]);
printf("\n");
free(buf);
}
}
void cmd_search(char *arg) {
unsigned char *buf = NULL;
unsigned int i, len, hit=0;
static void cmd_search(char *arg) {
ut8 *buf;
int i, len, hit = 0;
arg = skipspaces(arg);
if (*arg=='"') {
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,109 +67,124 @@ 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);
fclose(fd);
free(buf);
int len = bsize;
ut8 *buf = getcurblk("", &len);
if (len<1 || buf) {
FILE *fd = fopen(file, "wb");
if (fd) {
if (fwrite(buf, len, 1, fd)<len)
perror("fwrite");
fclose(fd);
} else perror("fopen");
free(buf);
} else perror("getcurblk");
}
static void cmd_load(char *file) {
void *buf;
FILE *fd = fopen(file, "rb");
if (!fd) return;
buf = malloc(bsize);
if (!buf) return;
io_write(buf, fread(buf, 1, bsize, fd));
fclose(fd);
free(buf);
if (fd) {
void *buf = malloc(bsize);
if (bsize>0 && buf) {
int len = fread(buf, 1, bsize, fd);
if (len<bsize)
perror("fread");
if (io_write(buf, len)<len)
perror("io_write");
} else perror("malloc");
free(buf);
fclose(fd);
} else perror("fopen");
}
static void cmd_write(char *arg) {
unsigned int len;
int len;
arg = skipspaces(arg);
if (*arg=='"') {
arg++;
len = strlen(arg)-1;
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 (len<1 || 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"
"w[hex|\"str\"] write hexpair or string\n"
"/[hex|\"str\"] search hexpair or string\n"
"x[size] hexdump\n"
"X[size] hexpair dump\n"
"p[fmt] print formatted current block ('p' for help)\n"
"r[-[num]] truncate or -remove N bytes\n"
".[file] interpret file\n"
"<[file] load file in current seek\n"
">[file] dump current block to file\n"
"!cmd run shell command\n"
"?expr calculate numeric expression\n"
"q quit\n");
"s[+-addr] seek to relative or absolute address\n"
"b[+-size] change block size\n"
"w[hex|\"str\"] write hexpair or string\n"
"/[hex|\"str\"] search hexpair or string\n"
"x[size] hexdump\n"
"X[size] hexpair dump\n"
"p[fmt] print formatted current block ('p' for help)\n"
"r[-[num]] truncate or -remove N bytes\n"
".[file] interpret file\n"
"<[file] load file in current seek\n"
">[file] dump current block to file\n"
"!cmd run shell command\n"
"?expr calculate numeric expression\n"
"q quit\n");
}
static void cmd_resize(char *arg) {
unsigned int len;
if (!*arg) printf("%lld\n", io_seek(0, SEEK_END));
int len, ret = 0;
if (!*arg) printf("%"LLF"d\n", (ut64)io_seek(0, SEEK_END));
else if (*arg=='-') {
ut8 *buf = malloc(bsize);
ut64 i, n = str2ut64(arg+1);
if (buf) {
for(i=0;;i+=len) {
io_seek(seek+n+i, SEEK_SET);
len = io_read(buf, bsize);
if (len<1) break;
io_seek(seek+i, SEEK_SET);
io_write(buf, len);
ut64 i, n = str2ut64(arg+1);
for(i=0;!ret;i+=len) {
io_seek(curseek+n+i, SEEK_SET);
if ((len = io_read(buf, bsize))>0) {
io_seek(curseek+i, SEEK_SET);
if (io_write(buf, len)<len)
perror("io_write"),ret=-1;
} else perror("io_read"), ret=-1;
}
free(buf);
if ((ret = io_seek(0, SEEK_END))>n)
ret = io_truncate(ret-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) {
unsigned int len = bsize;
char *buf = NULL, str[64];
int len = bsize;
char *buf, str[1024];
if (strstr(arg, "BLOCK")) {
FILE *fd = fopen(".curblk", "w");
FILE *fd = fopen(".curblk", "wb");
if (fd) {
buf = getcurblk("", &len);
if (buf) {
if ((buf = getcurblk("", &len))) {
setenv("BLOCK", ".curblk", 1);
fwrite(buf, len, 1, fd);
fclose(fd);
if (fwrite(buf, len, 1, fd)<len)
perror("fwrite");
free(buf);
}
fclose(fd);
}
}
if (strstr(arg, "OFFSET")) {
sprintf(str, "%lld", seek);
setenv("OFFSET", str, 1); // XXX
sprintf(str, "%"LLF"d", curseek);
setenv("OFFSET", str, 1);
}
if (strstr(arg, "XOFFSET")) {
sprintf(str, "0x%llx", seek);
setenv("XOFFSET", str, 1); // XXX
sprintf(str, "0x%"LLF"x", curseek);
setenv("XOFFSET", str, 1);
}
io_system(arg);
if (io_system(arg)<0)
perror("system");
unlink(".curblk");
free(buf);
}
+11 -11
View File
@@ -1,15 +1,9 @@
/* Copyleft 2009 -- pancake /at/ nopcode /dot/ org */
#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#if __WIN32__
#include <windows.h>
static HANDLE _fd = NULL;
#define setenv(x,y,z) SetEnvironmentVariable(x, y)
static inline int io_open(char *file) {
_fd = CreateFile(file, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
@@ -19,17 +13,22 @@ static inline int io_open(char *file) {
NULL, OPEN_ALWAYS, 0, NULL);
return (_fd==INVALID_HANDLE_VALUE)?-1:0;
}
static int io_read(void *x, int y) {
static inline int io_read(void *x, int y) {
DWORD ret;
return ReadFile(_fd,x,y,&ret,NULL)?ret:-1;
return ReadFile(_fd, x, y, &ret, NULL)?ret:-1;
}
#define setenv(x,y,z) SetEnvironmentVariable(x, y)
#define io_write(x,y) WriteFile(_fd, x, y, NULL, NULL)
#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);
@@ -41,5 +40,6 @@ static inline int io_open(char *file) {
#define io_seek(x,y) lseek(_fd, x, y)
#define io_close() close(_fd)
#define io_system(x) system(x)
#define io_truncate(x) ftruncate(_fd,(unsigned long)x)
#define io_truncate(x) ftruncate(_fd, (unsigned long)x)
#endif
+123
View File
@@ -0,0 +1,123 @@
.Dd Oct 7, 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
The following environment variables are defined when found in the command string:
.Pp
FILE is the filename of the current working file
.Pp
BLOCK points to the temporal filename with the current block dump
.Pp
OFFSET and XOFFSET are decimal and hexadecimal values of the current seek
.Pp
> !cp $BLOCK $FILE-$XOFFSET.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>
+37 -36
View File
@@ -5,42 +5,41 @@
static int verbose = 1;
static char *script = 0;
static ut64 oseek, seek = 0LL;
static unsigned int obsize, bsize = 256;
static ut64 oldseek, curseek = 0LL;
static int obsize, bsize = 256;
static int red_cmd(char *cmd); // XXX : recursive depenency
#include "red.h"
#include "util.c"
#include "cmd.c"
int red_slurpin() {
int len;
unsigned char buf[4096];
static void red_slurpin() {
ut8 buf[4096];
for(;;) {
len = read(0, buf, 4096);
int len = read(0, buf, 4096);
if (len<1) break;
hexdump(buf, len, 16);
seek += len;
curseek += len;
}
return 0;
}
static char *red_interpret(char *file) {
static void red_interpret(char *file) {
char buf[1024];
FILE *fd = fopen(file, "r");
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);
} else fprintf(stderr, "Cannot open script file '%s'\n", file);
return file;
}
static int red_cmd(char *cmd) {
switch(*cmd) {
case 'q': return 0;
case ';': case '#': break; // comment
case '>': cmd_dump(cmd+1); break;
case '<': cmd_load(cmd+1); break;
case '.': red_interpret(skipspaces(cmd+1)); break;
@@ -62,60 +61,62 @@ 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;
line[strlen(line)-1] = 0;
if (line[0] != '!') {
if (fgets(line, 4095, stdin) == NULL)
return 0;
line[strlen(line)-1] = '\0';
if (*line != '!') {
at = strchr(line, '@');
oseek = seek;
oldseek = curseek;
obsize = bsize;
if (at) {
*at = 0; at++;
at2 = strchr(at, ':');
*at = 0;
at2 = strchr(++at, ':');
if (at2) {
*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;
setenv("FILE", file, 1);
if (io_open(file) != -1) {
static int red_open(char *file) {
int ret = io_open(file);
if (ret != -1) {
oldseek = 0;
setenv("FILE", file, 1);
if (script)
script = red_interpret(script);
red_interpret(script);
while(red_prompt()) {
seek = oseek;
curseek = oldseek;
bsize = obsize;
}
io_close();
} else fprintf(stderr, "Cannot open '%s'\n", file);
return ret==-1 ?1:0;;
}
static int red_help() {
puts("red [-hnv] [-i script] [file] [..]");
puts("ired [-hnv] [-i script] [file] [..]");
return 0;
}
int main(int argc, char **argv) {
int i;
int i, ret = 1;
if (argc>1)
for(i=1;i<argc;i++) {
if (argv[i][0]=='-')
switch(argv[i][1]) {
case 'i': script = argv[++i]; break;
case 'n': verbose = 0; break;
case 'v': puts("red "VERSION" 2009"); return 0;
case 'h': return red_help();
case 0x0: return red_slurpin();
} else red_open(argv[i]);
} else return red_help();
return 0;
case 'v': puts("red "VERSION" 2009"); ret = 0; break;
case 'h': ret = red_help(); break;
case 0x0: red_slurpin(); ret = 0; break;
} else ret = red_open(argv[i]);
} else ret = red_help();
return ret;
}
+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
+14 -5
View File
@@ -1,11 +1,20 @@
#define VERSION "0.1"
#define VERSION "0.4"
#include <unistd.h>
#include <sys/types.h>
#include "io.c"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "util.c"
#include "cmd.c"
#if(plan9)
static int setenv(char *var, char *val, int force) {
char str[256];
snprintf(str, sizeof(str), "echo %s > /env/%s", var, val);
return system(str);
}
#define LLF "L"
#else
#define LLF "ll"
#endif
+23 -21
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,14 +10,13 @@ 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?" ":" ");
continue;
}
printf("%02x", buf[j]);
if (j%2) printf(" ");
printf(j%2?"%02x ":"%02x", buf[j]);
}
for(j=i;j<i+w;j++) {
if (j>=len) printf(" ");
@@ -26,7 +27,7 @@ static inline void hexdump(const ut8 *buf, unsigned int len, int w) {
}
static void print_fmt(const ut8 *buf, char *fmt, unsigned int len) {
unsigned int i, inc=0, lup=0, up, rep = 0;
unsigned int i, up, inc = 0, lup = 0, rep = 0;
char *ofmt = fmt;
do { /* TODO: needs cleanup */
for(;(*fmt||rep);fmt++) {
@@ -48,10 +49,11 @@ static void print_fmt(const ut8 *buf, char *fmt, unsigned int len) {
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); inc=8; break;
case '.': inc=1; break;
case ':': inc=4; break;
case 'z': for(i=0; inc<len && isascii(buf[0]);i++) { printf("%c", buf[0]); buf++; inc++; } if(i)printf("\n"); break;
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 'z': for(i=0; inc<len && isascii(buf[0]);i++) { printf(i?"%c\n":"%c", buf[0]); buf++; } inc++; break;
case 'Z': for(i=0; inc<len && isascii(buf[0]);i++) { printf(i?"%c\n":"%c", buf[0]); buf+=2; } inc+=2; break;
case '*': rep = lup; break;
default: fprintf(stderr, "Unknown format '%c' (%d)\n", up, up);
return;
}
if (!rep) lup = up;
buf += inc;
@@ -59,19 +61,19 @@ static void print_fmt(const ut8 *buf, char *fmt, unsigned int len) {
len -= inc;
}
fmt = ofmt;
} while(!rep && inc && inc <len);
} while(!rep && inc && inc<len);
}
static ut64 str2ut64(char *str) {
ut64 ret = 0LL;
str = skipspaces(str);
if (str[0]=='b'&&str[1]==0)
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);
str+=strlen(str)-1;
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;
else if (*str=='G') ret *= 1024*1024*1024;
@@ -79,17 +81,17 @@ static ut64 str2ut64(char *str) {
}
static int hex2byte(ut8 *val, ut8 c) {
if ('0' <= c && c <= '9') *val = (ut8)(*val) * 16 + ( c - '0');
if ('0' <= c && c <= '9') *val = (ut8)(*val) * 16 + ( c - '0');
else if (c >= 'A' && c <= 'F') *val = (ut8)(*val) * 16 + ( c - 'A' + 10);
else if (c >= 'a' && c <= 'f') *val = (ut8)(*val) * 16 + ( c - 'a' + 10);
else return 1;
return 0;
}
static int hexstr2raw(char *arg) {
ut8 *ptr, c = 0, d = 0;
static unsigned int hexstr2raw(char *arg) {
ut8 *ptr, d, c = 0;
unsigned int j = 0, len = 0;
for (ptr=(ut8 *)arg;*ptr;ptr++) {
for (ptr=(ut8 *)arg; *ptr; ptr++) {
if (*ptr==' ') continue;
d = c;
if (hex2byte(&c, *ptr))
@@ -104,14 +106,14 @@ static int hexstr2raw(char *arg) {
return len;
}
static void *getcurblk(char *arg, unsigned int *len) {
void *buf;
static void *getcurblk(char *arg, int *len) {
void *buf = NULL;
if (*arg) {
*len = (int)str2ut64(arg);
if (*len <1) *len = bsize;
if (*len<1) *len = bsize;
}
if ((buf = malloc(*len)) != NULL) {
if (io_seek(seek, SEEK_SET)<0) {
if (*len>0 && (buf = malloc(*len)) != NULL) {
if (io_seek((int)curseek, SEEK_SET)<0) {
free(buf);
buf = NULL;
} else *len = io_read(buf, *len);
+4 -2
View File
@@ -2,8 +2,10 @@
# vired: the visual raw editor
# copyleft: pancake at nopcode dot org @ 2009
PATH=.:$PATH
if [ -n "$1" ]; then
$0 | red -n $@
$0 | ired -n $@
exit 0
fi
@@ -22,7 +24,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`
+41
View File
@@ -0,0 +1,41 @@
.Dd Oct 7, 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 :
enter raw ired command
.It ?
show help
.It q
quit program
.Pp
.Sh SEE ALSO
.Pp
.Xr ired(1)
.Sh AUTHORS
.PP
pancake <@nopcode.org>