On Tuesday 23 August 2005 01:41 pm, Horst von Brand wrote:
> Aca va un parche que lo endecenta para el uso de hoy. Ojala funcione...
Compila, pero no funciona. El diff que sigue si hace que funcione (al menos
por aca).
Saludos,
-ag
--- ../old/tarx.c 2005-08-23 23:02:02.282420270 -0400
+++ tarx.c 2005-08-23 23:01:30.651447490 -0400
@@ -4,6 +4,11 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <tar.h>
#define NAMSIZ 100 /* why isn't there a tar.h??? */
#define FLAG (NAMSIZ+8+8+8+12+12+8) /* offset of is-a-link flag */
@@ -11,16 +16,16 @@
int offset;
char value;
} matches[] = { /* pattern-match table for header blocks */
- NAMSIZ+6, ' ',
- NAMSIZ+7, '\0',
- NAMSIZ+8+6, ' ',
- NAMSIZ+8+7, '\0',
- NAMSIZ+16+6, ' ',
- NAMSIZ+16+7, '\0',
- NAMSIZ+24+11, ' ',
- NAMSIZ+36+11, ' ',
- NAMSIZ+48+6, '\0',
- 0, 0,
+ { NAMSIZ+6, ' ' },
+ { NAMSIZ+7, '\0' },
+ { NAMSIZ+8+6, ' ' },
+ { NAMSIZ+8+7, '\0' },
+ { NAMSIZ+16+6, ' ' },
+ { NAMSIZ+16+7, '\0' },
+ { NAMSIZ+24+11, ' ' },
+ { NAMSIZ+36+11, ' ' },
+ { NAMSIZ+48+6, '\0' },
+ { 0, 0, }
};
#ifndef MAXBLOCK
@@ -40,14 +45,14 @@
int opened = 0; /* are we writing a file? */
int f; /* the file descriptor, if any */
-long fsize; /* number of bytes not yet written to file */
+unsigned long fsize; /* number of bytes not yet written to file */
char op = 'x'; /* what operation is being done? */
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
#ifndef lint
-static char RCSid[] = "$Header$";
+static const char RCSid[] = "$Header$";
#endif
int debug = 0;
@@ -60,9 +65,15 @@
#define mkprogname(a) (a)
#endif
+char *readblock(int);
+void doblock(char *, int, char **);
+int istar(char *);
+int match(char *, int, char **);
+
/*
- main - parse arguments and handle options
*/
+int
main(argc, argv)
int argc;
char *argv[];
@@ -70,8 +81,6 @@
int c;
int errflg = 0;
register char *block;
- extern char *readblock();
- extern char *malloc();
extern int optind;
extern char *optarg;
@@ -129,9 +138,6 @@
int desc;
{
register int count;
- extern int errno;
- extern int sys_nerr;
- extern char *sys_errlist[];
if (nleft > 0) {
whichnow++;
@@ -149,10 +155,7 @@
printf("---! bad block size (%d) - treated as bad\n", count);
nbad++;
} else {
- if (errno >= 0 && errno < sys_nerr)
- printf("---! error (%s)\n", sys_errlist[errno]);
- else
- printf("---! error %d\n", errno);
+ printf("---! error (%s)\n", strerror(errno));
nbad++;
}
if (nbad >= badlimit)
@@ -173,6 +176,7 @@
/*
- doblock - process a block
*/
+void
doblock(block, argc, argv)
char *block;
int argc;
@@ -252,6 +256,13 @@
else
printf("--- symlink %s to %s\n", block+FLAG+1, block);
break;
+ case '5':
+ f = mkdir(block, 0700);
+ if (f < 0)
+ printf("---! unable to create directory %s\n", block);
+ else
+ printf("--- create directory %s\n", block);
+ break;
default:
printf("---! unknown flag value %c\n", block[FLAG]);
break;
@@ -291,6 +302,8 @@
{
register int loop;
+ if (!memcmp(block + 257, TMAGIC, TMAGLEN-1))
+ return 1;
for (loop = 0; matches[loop].offset != 0; loop++)
if (block[matches[loop].offset] != matches[loop].value)
return(0);
From [EMAIL PROTECTED] Wed Aug 24 02:41:01 2005
From: [EMAIL PROTECTED] (Astor Giacomo)
Date: Wed Aug 24 02:39:01 2005
Subject: Dump de memoria de otro proceso
In-Reply-To: <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]>
Message-ID: <[EMAIL PROTECTED]>
On Tuesday 23 August 2005 05:29 pm, Bernardo Suarez wrote:
[Mis disculpas de antemano si mensajes como este no son bienvenidos en
esta lista. En ese caso no repetire la ofensa!]
[...]
> Por lo tanto me ayudaría mucho alguna utilidad que me permita hacer un
> dump hexadecimal de la memoria usada por otro proceso. Como no he
> podido detectar que parte del programa se come la memoria, quizas sea
> una buena pista saber con que la estoy llenando... Alguien
> tiene/conoce/sabe como hacer algo así?
Perl es conocido por ser extremadamente ineficiente en lo que a uso de memoria
se refiere.
Puedes tratar con lo de mas abajo. Aunque escrito a la rapida y, por eso,
bastante rustico, hace lo que necesitas (o pareces necesitar).
$ gcc -o memdump memdump.c
$ cat /proc/$$/maps
[...]
049bc000-049be000 rw-p 049bc000 00:00 0
08047000-080d8000 r-xp 00000000 03:41 145525 /bin/bash
080d8000-080de000 rw-p 00090000 03:41 145525 /bin/bash
080de000-080e3000 rw-p 080de000 00:00 0
09bea000-09c2c000 rw-p 09bea000 00:00 0 <-- el "heap"
b7de1000-b7de3000 rw-p b7de1000 00:00 0
[...]
$ ./memdump $$ 0x09bea000
[...]
Ojo que al terminar `memdump' con ^C o con "q" en less(1)
tienes que continuar manualmente el otro proceso (con
kill -CONT $pid). Arreglar eso es tarea para el lector :-)
Ocioso a las 2:20am,
-ag
---
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/ptrace.h>
#define SYSERR(x,t) \
if ((x) < 0) { perror(t); pexit(1); }
pid_t mem_pid = 0;
void pexit(int x)
{
if (mem_pid) ptrace(PTRACE_DETACH, mem_pid, 0, 0);
exit(x);
}
void memdump(int f, off_t offset, int bin)
{
unsigned char data[16];
int sofar = 0, n, k;
SYSERR(lseek(f, offset, SEEK_SET), "lseek");
while ((n = read(f, data, sizeof(data))) > 0) {
const unsigned char *p;
if (bin) {
write(1, data, n);
continue;
}
printf("%08lx - ", offset + sofar);
for (p = data; p < &data[n]; p++)
printf("%02x ", *p);
printf("| ");
for (p = data; p < &data[n]; p++)
printf("%c", isprint(*p) ? *p : '.');
putchar('\n');
sofar += n;
}
}
int main(int argc, char **argv)
{
int r, status, fd, bin;
pid_t pid;
off_t off;
char buf[32];
if (argc < 3) {
printf("Usage: %s PID ADDRESS\n", argv[0]);
exit(1);
}
pid = atoi(argv[1]);
off = (off_t)strtol(argv[2], 0, 0);
bin = argv[3] ? atoi(argv[3]) : 0;
snprintf(buf, sizeof(buf), "/proc/%u/mem", pid);
SYSERR(fd = open(buf, O_RDONLY), buf);
SYSERR(r = ptrace(PTRACE_ATTACH, pid, 0, 0), "ptrace");
while ((r = waitpid(pid, &status, WUNTRACED)) < 0 && errno == EINTR)
;
mem_pid = pid;
SYSERR(r, "waitpid");
if (!WIFSTOPPED(status)) {
fprintf(stderr, "Child not stopped!?\n");
exit(1);
}
memdump(fd, off, bin);
close(fd);
pexit(0);
}