Skip to content

Instantly share code, notes, and snippets.

@paulll
Created March 28, 2016 17:45
Show Gist options
  • Save paulll/9929c15e85ac0760d3c2 to your computer and use it in GitHub Desktop.
Save paulll/9929c15e85ac0760d3c2 to your computer and use it in GitHub Desktop.
function aob_search()
# use something to identify process id
pid = parse(Int, readall(`pidof osu\!.exe`))
# maps file contains information about memory regions
# mem file is a pseudo-file containing process memory
maps_file = open("/proc/" * string(pid) * "/maps", "r")
mem_file = open("/proc/" * string(pid) * "/mem", "r")
pages = readall(maps_file);
close(maps_file)
lines = split(pages, '\n')
# its ok to manually edit this two lines, but remember
# that this arrays must be same size and type
search = [0x1d, 0xdd, 0x45, 0xf0, 0xdd, 0x1d]
buffer = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
offset = 0
for line in lines
# filter only rwxp memory regions
# and only which are not assigned to any file
if length(line) != 40 || line[19:22] != "rwxp"
continue
end
# line starts with something like "12345678-1234567A"
# extract range start and end
rng = parse(Int, line[1:8], 16) : parse(Int, line[10:17], 16)
print("scanning range: ", line[1:17], '\n')
seek(mem_file, rng[1])
# byte by byte reading every memory region
# and comparing scan buffer with search buffer
for offset_value in rng
# read a byte, move it to the end of the buffer,
# and pop buffer at the start
byte = readbytes(mem_file, 1)
buffer = append!(buffer[2:end], byte)
if buffer == search
offset = offset_value
break
end
end
if offset != 0
break
end
end
if offset == 0
print("search failed.\n")
return
end
# address is held next to the pattern
addr_arr = readbytes(mem_file, 4)
addr = addr_arr[1] + addr_arr[2]*0x100 + addr_arr[3]*0x10000 + addr_arr[4] * 0x1000000
print("detected address: ", addr, '\n')
return addr, mem_file
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment