Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Other pokemem methods #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions tcpgecko.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,59 @@ def writekern(self, address, value): #Only takes 4 bytes, may need to run multip
return

def pokemem(self, address, value): #Only takes 4 bytes, may need to run multiple times
"""
Parameters
----------
address : integer (4)
Address to poke
value : integer (4)
Value to write
"""
if not self.validrange(address, 4): raise BaseException("Address range not valid")
if not self.validaccess(address, 4, "write"): raise BaseException("Cannot write to address")
self.s.send(b"\x03") #cmd_pokemem
request = struct.pack(">II", int(address), int(value))
self.s.send(request) #Done, move on
return

def pokemem8(self, address, value):
"""
Parameters
----------
address : integer (4)
Address to poke
value : integer (1)
Value to write
"""
# In theory, you could just have pokemem do 'value.bit_length() - 1' and deduce the cmd to send
# as the packing will always need to be two unsigned ints regardless of the value size being 8 or 16
# Needs may vary down the road and keeping the methods separate may be for the best
if not self.validrange(address, 4): raise BaseException("Address range not valid")
if not self.validaccess(address, 4, "write"): raise BaseException("Cannot write to address")
self.s.send(b"\x01") #cmd_poke08
request = struct.pack(">II", int(address), int(value))
self.s.send(request) #Done, move on
return

def pokemem16(self, address, value):
"""
Parameters
----------
address : integer (4)
Address to poke
value : integer (2)
Value to write
"""
# In theory, you could just have pokemem do 'value.bit_length() - 1' and deduce the cmd to send
# as the packing will always need to be two unsigned ints regardless of the value size being 8 or 16
# Needs may vary down the road and keeping the methods separate may be for the best
if not self.validrange(address, 4): raise BaseException("Address range not valid")
if not self.validaccess(address, 4, "write"): raise BaseException("Cannot write to address")
self.s.send(b"\x02") #cmd_poke16
request = struct.pack(">II", int(address), int(value))
self.s.send(request) #Done, move on
return

def search32(self, address, value, size):
self.s.send(b"\x72") #cmd_search32
request = struct.pack(">III", address, value, size)
Expand Down