User File #45899430342247111

Upload All User Files

#45899430342247111 - JPC-rr Search Memory Lua Script

searchmemory.lua
System: DOS
786 downloads
Uploaded 3/21/2018 1:50 AM by c-square (see all 10)
Script to search memory in JPC-rr
--inputFilename="outputfile.out" -- Uncomment for searches after the first one
outputFilename="outputfile.out" -- Rename output file for subseqent searches
value = 6700 -- Value to search for

function string:split( inSplitPattern, outResults )
  if not outResults then
    outResults = { }
  end
  local theStart = 1
  local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
  while theSplitStart do
    table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
    theStart = theSplitEnd + 1
    theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
  end
  table.insert( outResults, string.sub( self, theStart ) )
  return outResults
end

function searchFor(byteList, value, filename)
	print("Searching " .. #byteList .. " values for " .. value);
	local input=1
	local output=0
	print("Opening Output File")
	outputBinary=io.open_write(filename)
	print("Output File Open")
	while byteList[input] do
		if value > 256 then
			memValue = jpcrr.read_word(byteList[input])
		else
			memValue = jpcrr.read_byte(byteList[input])
		end
		if memValue == value then
			if output == 0 then
				outputBinary.write("?",byteList[input])
			else
				outputBinary.write("?",","..byteList[input])
			end
			output = output + 1
		end
		if input % 10000 == 0 then
			print(input)
		end
		input=input+1
	end
	print("Search Complete!")
	print("Found " .. output .. " Matches")
	outputBinary:close()
end

-- Main
if inputFilename then
	print("Opening input file")
	inputBinary, error=io.open_read(inputFilename)
	print("Spitting input")
	searchStr = inputBinary.read()
	inputBinary:close()
	searchList = searchStr:split(",")
	print("Input split into " .. #searchList .. " items")
end
if not searchList then
	searchList={}
	for i=1,2090000 do
		searchList[i]=i
	end
end
searchFor(searchList, value, outputFilename)