Skip to content

Instantly share code, notes, and snippets.

@hydrogen18
Created November 4, 2016 02:12
Show Gist options
  • Save hydrogen18/7ae1a1f79fe420377fe27e30dd31b8f5 to your computer and use it in GitHub Desktop.
Save hydrogen18/7ae1a1f79fe420377fe27e30dd31b8f5 to your computer and use it in GitHub Desktop.
import urllib2
import urllib
from bs4 import BeautifulSoup
from io import open
import sys
response = urllib.urlopen("http://wiiubrew.org/wiki/Hardware/OTP")
soup = BeautifulSoup(response.read())
headings = soup.find_all('h2')
otp_contents = None
for heading in headings:
if heading.text.strip () == "OTP Contents":
otp_contents = heading
contents_table = otp_contents.find_next('table')
defns = []
for table_row in contents_table.find_all('tr'):
row_data = table_row.find_all('td');
values = [rd.text for rd in row_data]
print values
if len(values) != 0:
offset = int(values[1].strip().split(' ')[0], 16)
size = int(values[2].strip().split(' ')[0], 16)
defns.append({"bank": values[0], "offset": offset, "size": size, "desc": values[3].strip()})
# Open the first argument as a file for input
with open(sys.argv[1], 'rb') as fin:
for defn in defns:
fin.seek(defn['offset'])
v = fin.read(defn['size'])
sys.stdout.write(u"Offset 0x%x\nValue " % (defn['offset'],))
for x in v:
sys.stdout.write(u'%X' % ord(x))
sys.stdout.write(u'\nDescription: %s\n\n' % (defn['desc'],))
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment