Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Aug 2014 10:40:16 +0000 (UTC)
From:      Alexey Dokuchaev <danfe@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r366391 - in head/sysutils: . scanmem scanmem/files
Message-ID:  <201408281040.s7SAeGLx067928@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: danfe
Date: Thu Aug 28 10:40:16 2014
New Revision: 366391
URL: http://svnweb.freebsd.org/changeset/ports/366391
QAT: https://qat.redports.org/buildarchive/r366391/

Log:
  Add quick and dirty port of scanmem, a simple interactive debugging utility
  for Linux, used to locate the address of a variable in an executing process.
  
  WWW: http://code.google.com/p/scanmem/

Added:
  head/sysutils/scanmem/
  head/sysutils/scanmem/Makefile   (contents, props changed)
  head/sysutils/scanmem/distinfo   (contents, props changed)
  head/sysutils/scanmem/files/
  head/sysutils/scanmem/files/patch-commands.c   (contents, props changed)
  head/sysutils/scanmem/files/patch-handlers.c   (contents, props changed)
  head/sysutils/scanmem/files/patch-interrupt.h   (contents, props changed)
  head/sysutils/scanmem/files/patch-maps.c   (contents, props changed)
  head/sysutils/scanmem/files/patch-maps.h   (contents, props changed)
  head/sysutils/scanmem/files/patch-ptrace.c   (contents, props changed)
  head/sysutils/scanmem/pkg-descr   (contents, props changed)
Modified:
  head/sysutils/Makefile

Modified: head/sysutils/Makefile
==============================================================================
--- head/sysutils/Makefile	Thu Aug 28 10:36:27 2014	(r366390)
+++ head/sysutils/Makefile	Thu Aug 28 10:40:16 2014	(r366391)
@@ -861,6 +861,7 @@
     SUBDIR += scalpel
     SUBDIR += scan_ffs
     SUBDIR += scanbuttond
+    SUBDIR += scanmem
     SUBDIR += schedutils
     SUBDIR += scprotect
     SUBDIR += screen

Added: head/sysutils/scanmem/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/scanmem/Makefile	Thu Aug 28 10:40:16 2014	(r366391)
@@ -0,0 +1,31 @@
+# Created by: Alexey Dokuchaev <danfe@FreeBSD.org>
+# $FreeBSD$
+
+PORTNAME=	scanmem
+PORTVERSION=	0.13
+CATEGORIES=	sysutils
+MASTER_SITES=	GOOGLE_CODE
+DISTNAME=	${PORTNAME}-${PORTVERSION}_
+
+MAINTAINER=	danfe@FreeBSD.org
+COMMENT=	Locate and modify a variable in an executing process
+
+LICENSE=	GPLv3
+
+ONLY_FOR_ARCHS=	i386 amd64
+ONLY_FOR_ARCHS_REASON=	requires linprocfs(5)
+
+USES=		readline
+GNU_CONFIGURE=	yes
+
+WRKSRC=		${WRKDIR}/${PORTNAME}-${PORTVERSION}
+
+PLIST_FILES=	bin/scanmem man/man1/scanmem.1.gz
+PORTDOCS=	README
+
+OPTIONS_DEFINE=	DOCS
+
+post-patch:
+	@${REINPLACE_CMD} -e 's,/proc/,/compat/linux&,' ${WRKSRC}/configure
+
+.include <bsd.port.mk>

Added: head/sysutils/scanmem/distinfo
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/scanmem/distinfo	Thu Aug 28 10:40:16 2014	(r366391)
@@ -0,0 +1,2 @@
+SHA256 (scanmem-0.13_.tar.gz) = 36f6b99e26c171dc1caa59e5338f4369391224c8e9b5506bf96a5382831e27b1
+SIZE (scanmem-0.13_.tar.gz) = 240619

Added: head/sysutils/scanmem/files/patch-commands.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/scanmem/files/patch-commands.c	Thu Aug 28 10:40:16 2014	(r366391)
@@ -0,0 +1,11 @@
+--- commands.c.orig	2010-01-19 07:37:07 UTC
++++ commands.c
+@@ -104,7 +104,7 @@ bool execcommand(globals_t * vars, const
+ 
+     np = commands->head;
+ 
+-    str = tok = strdupa(commandline);
++    str = tok = strdup(commandline);
+ 
+     /* tokenize command line into an argument vector */
+     for (argc = 0; tok; argc++, str = NULL) {

Added: head/sysutils/scanmem/files/patch-handlers.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/scanmem/files/patch-handlers.c	Thu Aug 28 10:40:16 2014	(r366391)
@@ -0,0 +1,58 @@
+--- handlers.c.orig	2012-03-26 06:25:08 UTC
++++ handlers.c
+@@ -34,7 +34,6 @@
+ #include <signal.h>
+ #include <assert.h>
+ #include <setjmp.h>
+-#include <alloca.h>
+ #include <strings.h>            /*lint -esym(526,strcasecmp) */
+ #include <string.h>
+ #include <stdbool.h>
+@@ -123,9 +122,9 @@ bool handler__set(globals_t * vars, char
+         } else {
+             /* there is a '=', value+1 points to value string. */
+ 
+-            /* use strndupa() to copy the matchids into a new buffer */
++            /* use strndup() to copy the matchids into a new buffer */
+             settings[block].matchids =
+-                strndupa(argv[block + 1],
++                strndup(argv[block + 1],
+                          (size_t) (settings[block].value++ - argv[block + 1]));
+         }
+ 
+@@ -161,7 +160,7 @@ bool handler__set(globals_t * vars, char
+ 
+             /* remove any delay suffix from the value */
+             settings[block].value =
+-                strndupa(settings[block].value,
++                strndup(settings[block].value,
+                          (size_t) (delay - settings[block].value));
+         }                       /* if (strchr('/')) */
+     }                           /* for(block...) */
+@@ -207,7 +206,7 @@ bool handler__set(globals_t * vars, char
+                 unsigned num = 0;
+ 
+                 /* create local copy of the matchids for strtok() to modify */
+-                lmatches = strdupa(settings[block].matchids);
++                lmatches = strdup(settings[block].matchids);
+ 
+                 /* now seperate each match, spearated by commas */
+                 while ((id = strtok(lmatches, ",")) != NULL) {
+@@ -545,7 +544,7 @@ bool handler__dregion(globals_t * vars, 
+     if (*argv[1] == '!') {
+         invert = true;
+         /* create a copy of the argument for strtok(), +1 to skip '!' */
+-        block = strdupa(argv[1] + 1);
++        block = strdup(argv[1] + 1);
+         
+         /* check for lone '!' */
+         if (*block == '\0') {
+@@ -561,7 +560,7 @@ bool handler__dregion(globals_t * vars, 
+         
+     } else {
+         invert = false;
+-        block = strdupa(argv[1]);
++        block = strdup(argv[1]);
+     }
+ 
+     /* loop for every number specified, eg "1,2,3,4,5" */

Added: head/sysutils/scanmem/files/patch-interrupt.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/scanmem/files/patch-interrupt.h	Thu Aug 28 10:40:16 2014	(r366391)
@@ -0,0 +1,11 @@
+--- interrupt.h.orig	2009-12-14 15:15:26 UTC
++++ interrupt.h
+@@ -10,7 +10,7 @@
+ /* small header file to manage interrupted commands */
+ 
+ static sigjmp_buf jmpbuf;       /* used when aborting a command due to interrupt */
+-static sighandler_t oldsig;     /* reinstalled before longjmp */
++static sig_t oldsig;     /* reinstalled before longjmp */
+ static unsigned intused;
+ 
+ /* signal handler to handle interrupt during a commands */

Added: head/sysutils/scanmem/files/patch-maps.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/scanmem/files/patch-maps.c	Thu Aug 28 10:40:16 2014	(r366391)
@@ -0,0 +1,28 @@
+--- maps.c.orig	2011-01-13 09:22:33 UTC
++++ maps.c
+@@ -31,7 +31,6 @@
+ #include <stddef.h>
+ #include <stdlib.h>
+ #include <string.h>
+-#include <alloca.h>
+ #include <stdbool.h>
+ #include <unistd.h>
+ 
+@@ -56,7 +55,7 @@ bool readmaps(pid_t target, list_t * reg
+         return false;
+ 
+     /* construct the maps filename */
+-        snprintf(name, sizeof(name), "/proc/%u/maps", target);
++        snprintf(name, sizeof(name), "/compat/linux/proc/%u/maps", target);
+ 
+         /* attempt to open the maps file */
+         if ((maps = fopen(name, "r")) == NULL) {
+@@ -110,7 +109,7 @@ bool readmaps(pid_t target, list_t * reg
+                                 break;
+                             }
+                             /* test if the region is mapped to the executable */
+-                            snprintf(exename, sizeof(exename), "/proc/%u/exe", target);
++                            snprintf(exename, sizeof(exename), "/compat/linux/proc/%u/exe", target);
+                             if((linkbuf_size = readlink(exename, linkbuf, MAX_LINKBUF_SIZE)) > 0)
+                             {
+                                 linkbuf[linkbuf_size] = 0;

Added: head/sysutils/scanmem/files/patch-maps.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/scanmem/files/patch-maps.h	Thu Aug 28 10:40:16 2014	(r366391)
@@ -0,0 +1,10 @@
+--- maps.h.orig	2010-01-14 08:52:26 UTC
++++ maps.h
+@@ -23,6 +23,7 @@
+ #ifndef _MAPS_INC
+ #define _MAPS_INC            /* include guard */
+ 
++#include <sys/types.h>
+ #include "list.h"
+ 
+ /* determine what regions we need */

Added: head/sysutils/scanmem/files/patch-ptrace.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/scanmem/files/patch-ptrace.c	Thu Aug 28 10:40:16 2014	(r366391)
@@ -0,0 +1,61 @@
+--- ptrace.c.orig	2012-04-22 03:04:11 UTC
++++ ptrace.c
+@@ -22,11 +22,13 @@
+ 
+ #include "config.h"
+ 
++#if 0
+ /* for pread */
+ # ifdef _XOPEN_SOURCE
+ #  undef _XOPEN_SOURCE
+ # endif
+ # define _XOPEN_SOURCE 500
++#endif
+ 
+ #include <time.h>
+ #include <sys/types.h>
+@@ -376,7 +378,7 @@ bool checkmatches(globals_t * vars, 
+     return detach(vars->target);
+ }
+ 
+-/* read region using /proc/pid/mem */
++/* read region using /compat/linux/proc/pid/mem */
+ ssize_t readregion(pid_t target, void *buf, size_t count, unsigned long offset)
+ {
+     char mem[32];
+@@ -384,7 +386,7 @@ ssize_t readregion(pid_t target, void *b
+     ssize_t len;
+     
+     /* print the path to mem file */
+-    snprintf(mem, sizeof(mem), "/proc/%d/mem", target);
++    snprintf(mem, sizeof(mem), "/compat/linux/proc/%d/mem", target);
+     
+     /* attempt to open the file */
+     if ((fd = open(mem, O_RDONLY)) == -1) {
+@@ -498,7 +500,7 @@ bool searchregions(globals_t * vars, sca
+         }
+ 
+ #else     
+-        /* cannot use /proc/pid/mem */
++        /* cannot use /compat/linux/proc/pid/mem */
+         nread = r->size;
+ #endif
+         /* print a progress meter so user knows we havent crashed */
+@@ -632,7 +634,7 @@ bool setaddr(pid_t target, void *addr, c
+         return false;
+     }
+ 
+-    /* TODO: may use /proc/<pid>/mem here */
++    /* TODO: may use /compat/linux/proc/<pid>/mem here */
+     /* assume that sizeof(save.int64_value) (int64_t) is multiple of sizeof(long) */
+     for (i = 0; i < sizeof(saved.int64_value); i += sizeof(long)) 
+     {
+@@ -687,7 +689,7 @@ bool read_array(pid_t target, void *addr
+ #endif
+ }
+ 
+-/* TODO: may use /proc/<pid>/mem here */
++/* TODO: may use /compat/linux/proc/<pid>/mem here */
+ bool write_array(pid_t target, void *addr, const void *data, int len)
+ {
+     int i,j;

Added: head/sysutils/scanmem/pkg-descr
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/scanmem/pkg-descr	Thu Aug 28 10:40:16 2014	(r366391)
@@ -0,0 +1,8 @@
+Scanmem is a simple interactive debugging utility for Linux, used to locate
+the address of a variable in an executing process. This can be used for the
+analysis or modification of a hostile process on a compromised machine,
+reverse engineering, or as a "pokefinder" to cheat at video games.
+
+It requires linprocfs(5) to be mounted under /compat/linux/proc to operate.
+
+WWW: http://code.google.com/p/scanmem/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408281040.s7SAeGLx067928>