home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Enigma Amiga Life 110
/
EnigmaAmiga110CD.iso
/
software
/
varie
/
ksc_utils
/
grepmem.asm
< prev
next >
Wrap
Assembly Source File
|
2000-02-21
|
4KB
|
221 lines
; GrepMem v1.3 : hunts through memory for (exact) string matches
; by Kyzer/CSG
; $VER: GrepMem 1.3 (21.02.00)
;
incdir include:
include lvo/exec_lib.i
include lvo/dos_lib.i
include exec/execbase.i
include dos/dos.i
include dos/dosasl.i
incdir ""
error MACRO
IFLT ERROR_\1 - 127
moveq #ERROR_\1,d1
ELSE
move.l #ERROR_\1,d1
ENDC
jsr _LVOSetIoErr(a6)
ENDM
print MACRO
lea \1,a0
move.l a0,d1
IFNC '\2',''
lea \2,a0
move.l a0,d2
ENDC
; move.l dosbase(a5),a6
jsr _LVOVPrintf(a6)
ENDM
stackf MACRO ; stack_symbol, stackelement_symbol
IFND \1
\1 set 0
ENDC
\1 set \1-4
\2 equ \1
ENDM
stackf stk, dosbase ; DOSBase
stackf stk, padzero ;
stackf stk, endaddr ; these 4 filled by ReadArgs
stackf stk, begaddr ; ^
stackf stk, searchstr ; | This way up
stackf stk, rdargs
args=searchstr
stackf stk, end ; end address
stackf stk, start ; start address
stackf stk, address ; current search address
stackf stk, hitcnt ; number of matches
stackf stk, column ; current printout column
str=address
link a5,#stk
move.l 4.w,a6
lea dosname(pc),a1
moveq #37,d0
jsr _LVOOpenLibrary(a6)
move.l d0,dosbase(a5)
beq.s .nodos
move.l d0,a6
print title(pc)
lea templat(pc),a0
move.l a0,d1
lea args(a5),a0
move.l a0,d2
moveq #4-1,d3
.clrarg clr.l (a0)+
dbra d3,.clrarg
moveq #0,d3
jsr _LVOReadArgs(a6)
move.l d0,rdargs(a5)
beq.s .noargs
bsr.s Init ; Init will call Search if appropriate
move.l rdargs(a5),d1
jsr _LVOFreeArgs(a6)
.noargs jsr _LVOIoErr(a6)
move.l d0,d1
moveq #0,d2
jsr _LVOPrintFault(a6)
move.l a6,a1
move.l 4.w,a6
jsr _LVOCloseLibrary(a6)
.nodos unlk a5
moveq #0,d0
rts
Init clr.l hitcnt(a5) ; hits = 0
clr.w column(a5) ; start at column 2 on 1st line
lea padpos(pc),a0 ; set up pad character
move.b #"-",(a0)
tst.l padzero(a5)
beq.s 1$
move.b #"0",(a0)
1$
; set up start and end addresses
move.l begaddr(a5),d0
bne.s .got
clr.l start(a5)
move.l 4.w,a0
move.l MaxLocMem(a0),end(a5)
bra Search
.got move.l d0,a0
bsr.s hexconv
tst.l d1
beq.s .nhex
move.l d0,start(a5)
move.l endaddr(a5),d0
beq.s .noend
move.l d0,a0
bsr.s hexconv
tst.l d1
beq.s .nhex
move.l d0,end(a5)
bra.s Search
.nhex error BAD_NUMBER
rts
.noend error REQUIRED_ARG_MISSING
rts
hexconv include hex.asm
;--- Search routine ---------------------------------------------------------
Search move.l start(a5),a0
move.l end(a5),a1
cmp.l a0,a1
beq.s .cleanup ; if start=end then exit
bhi.s .noswap ; if start>end then swap start and end
exg.l a0,a1
.noswap move.l a0,start(a5)
move.l a1,end(a5)
move.l searchstr(a5),str(a5)
print begin(pc),str(a5)
; search routine
; a4=string to search for
; a3=current position in memory (outer)
; a2=current position in memory (inner)
move.l start(a5),a3
move.l searchstr(a5),a4
tst.b (a4) ; if string = '' then exit
beq.s .cleanup
.next_outer
move.b (a4),d0
cmp.b (a3)+,d0
bne.s .no_start
lea 1(a4),a1 ; a1=2nd byte of search string
move.l a3,a2 ; a2=2nd byte of matched memory
.next_inner
tst.b (a1) ; if search string ends during inner loop
beq.s .matched_whole ; then we must have matched fully
cmp.b (a1)+,(a2)+
beq.s .next_inner
.return
.no_start
cmp.l end(a5),a3
bne.s .next_outer
.cleanup
print done(pc),hitcnt(a5)
rts
.matched_whole
cmp.l a3,a4
beq.s 1$ ; don't report own copy
cmp.b #'"',-1(a3) ; don't report if begins with quotes
beq.s 1$
; we got a match!
move.l a3,address(a5)
print hit(pc),address(a5)
addq.l #1,hitcnt(a5)
; check for CTRL-C and die if neccessary
move.l 4.w,a6
moveq #0,d0
moveq #0,d1
jsr _LVOSetSignal(a6)
move.l dosbase(a5),a6
btst.l #SIGBREAKB_CTRL_C,d0
beq.s 2$
error BREAK
bra.s .cleanup
2$ addq.w #1,column(a5)
cmp.w #6,column(a5)
blt.s 1$
print newline(pc) ; write newline every 7 columns
clr.w column(a5)
1$ bra.s .return ; return to outer loop
begin dc.b 'Grepping memory for "%s" from $%lx to $%lx:',10,0
done dc.b 10,'Grep finished, %ld hit(s).',10,0
hit dc.b '$%-8lx ',0
newline=hit-2
padpos=hit+2
dc.b '$VER: '
title dc.b 'GrepMem 1.3 (21.02.00) by Kyzer/CSG',10,0
templat dc.b 'STRING/A,START,END,PADZERO/S',0
dosname dc.b 'dos.library',0