記録 2014/03/24(Mon)
photo by Bert Heymans
これから「記録 日付」というタイトルの記事を更新する場合、なんの脈絡もなく色んな話題を詰め込むので、適当に興味ないところは飛ばして読んでください。
とりあえず今回の話題は
- リバースエンジニアリング
- 8946
- 本
- 勉強再開
- .vimrc
- Pythonでライフゲーム(ActiveStateに載ってたやつを書き写しコードリーディング)
です。
リバースエンジニアリング
この土日かなんかでちょっとやってました。
そんな時間をかけられないなぁという中途半端なモチベーションでやった結果、ただいま逆コンパイル…つまりアセンブラの読み解きの部分で挫折中です。
教材はネットで見つけた
バイナリと数式と: アーカイブ
ここにあるなんかの雑誌に連載されていた記事たち。
Ubuntuでやりたいなぁと探してた時に見つけた記事なのに結局Windowsでやるはめになりました。
IDA Pro、Ollydbgの使い方とかは大体わかったんですが、やっぱりアセンブリ言語は難しいですね。記事に言われるがままいくつか自分でも書いてnasmでコンパイルわーいとかやってたんですが、それでもやっぱり第三回の宿題逆コンパイルがさっぱりでした。
解説読んでもさっぱり。
まぁ基礎中の基礎は学んだ感じなので受験後タスクのstackにpushしときます(queueではない)
8946
White HackerzとかいうHow to become hackerを読んだことのある身からすれば、他のhackerに怒られるだろと思わざるをえない日本のHacker集団のつくってるCracking問題集ですね。
正答率の高いほうからやっていくとほぼすべてコード見てどうにかするタイプなのでちょこっと解いてました。
僕みたいな解き方してると大体の人が感じる思うんですが、サービス名の8946という数字が結構パスワードの答えになってたりして問題作成のテキトーさを感じます。
しばらくやってあきたのでこれもstackにpush(笑)
本
学校からもらってる図書カードで本を大人買いと言えるかどうか微妙な量買いました。
こちらです。
受験勉強に関係ないものばかり買ったつもりでしたが、「永久運動の夢」は熱力学第二法則(だったよな?)の裏側に迫っていたりバリバリ高校物理の理解にも役立ちそうな内容っぽいです。
ちなみにビブリア古書堂は合格発表前に行った旅行先のホテルにおいてあったのを読んではまったのですがどうやら全5巻あるようで…控えめに2巻までだけの購入にしたんですが、旅行中に読んでた部分があったのもあって、買って翌日の今日に2巻まで読了してしまいました。
今は面白くて(ryと永久運動の夢をちょっとずつ読み進めています。
勉強再開
親にもそろそろと言われましたし、なんか受動的だけど再開しました。
とりあえず物理一問と、解法の突破口をちょろっと。
あと日本史の教科書を読みました。このあともやります。
少しずつ受験生っぽく戻していこうと思います。
というわけで(?)東大受験生ブログランキング投票よろしくです(^O^)
.vimrc
githubに定期的に上げながらこの間完成したと思ったのですが…
よく考えたらコンソールで使ってる時シンタックスハイライトが無効になってしまっていて、せっかくだからもう一回作りなおしてみました。
詳細はコードのコメントで
my .vimrc current version on ubuntu
とりあえず、快適に戻ったのでWindowsにも適用してみて、それからGithubのリポジトリ更新しようかなぁとかGithubの意味がなくなるようなことを考えてます(笑)
Pythonでライフゲーム(ActiveStateに載ってたやつを書き写しコードリーディング)
Pygameを使ったやつです。チュートリアルにここにいっぱいソースコードあるよーってのってるActiveStateの一個をコードリーディングの題材として使ってみました。
とりあえず色々英語でコメント入れてそれぞれの意味をはっきりさせてみたり…
ただubuntuで実行してみたところ、一応動くんですが世代が更新されないバグが発生してて。
とりあえず原因がよくわからないので放置してます。
#! python # original place: # //code.activestate.com/recipes/578808-python-game-of-life/?in=lang-python # added some comments in english and revised something where error occurred by touyou import pygame #import pygame._view <- this is comment out because import error occurred from pygame.locals import * import sys import random pygame.init() class Cell(pygame.sprite.Sprite): def __init__(self, game, pos, num): pygame.sprite.Sprite.__init__(self) self.game = game self.num = num self.color = self.getColor() self.parent = 0 self.image = pygame.Surface([10,10]) self.image.fill((0,0,0)) self.rect = self.image.get_rect() self.rect.topleft = pos self.alive = False # at first, every cell died self.edge = False # flag whether cell is on the edge or not self.a_neighbors = [] # alive neighbors list self.d_neighbors = [] # dead neighbors list self.n = (num - 74) - 1 # neighbor in north self.e = (num + 1) - 1 # neighbor in east self.s = (num + 74) - 1 # neighbor in south self.w = (num - 1) - 1 # neighbor in west self.ne = (self.n + 1) # neighbor in north east self.se = (self.s + 1) # neighbor in south east self.nw = (self.n - 1) # neighbor in north west self.sw = (self.s - 1) # neighbor in south west # all neighbors list self.cell_list = [ self.n, self.e, self.s, self.w, self.ne, self.se, self.nw, self.sw] self.game.cells.append(self) # add itself to game's cell list def getColor(self): # create color of cell by random choice value = [i for i in range(100,255,25)] r = random.choice(value) g = random.choice(value) b = random.choice(value) return (r,g,b) def die(self): # kill this cell self.alive = False def live(self): # create this cell self.alive = True def update(self): if not self.edge: # check neighbors (they are dead or alive) self.a_neighbors = [] self.d_neighbors = [] neighbors = [self.game.cells[cell] for cell in self.cell_list] # we only need to know how many neighbors are alive for n in neighbors: if n.alive: self.a_neighbors.append(True) else: self.d_neighbors.append(True) if not self.game.running: # player's initial process if pygame.mouse.get_pressed()[0] and self.rect.collidepoint(self.game.mpos): self.alive = True self.image.fill(self.color) if pygame.mouse.get_pressed()[2] and self.rect.collidepoint(self.game.mpos) and self.alive: self.image.fill((0,0,0)) self.alive = False if self.alive: self.image.fill(self.color) else: if self.alive: self.image.fill(self.color) if not self.alive: self.image.fill((0,0,0)) else: self.image.fill((255,255,255)) class Game(): def __init__(self): # window setup pygame.display.set_caption('Game Of Life') # initiate the clock and screen self.clock = pygame.time.Clock() self.last_tick = pygame.time.get_ticks() self.screen_res = [740,490] self.font = pygame.font.SysFont("Impact", 19) self.sprites = pygame.sprite.Group() self.cells = [] self.generation = 0 self.population = 0 self.screen = pygame.display.set_mode(self.screen_res, pygame.HWSURFACE, 32) self.running = False self.createGrid() while 1: self.Loop() def createGrid(self): col = 0 row = 50 # there is information window on game window cell_num = 0 # memo: xrange is almost equal to range. it returns xrange object. # cell's height is 10 and its width is equal to it for y in xrange(44): for x in xrange(74): cell_num += 1 cell = Cell(self, [col, row], cell_num) if row == 50 or row == 480 or col == 0 or col == 730: cell.edge = True self.sprites.add(cell) col += 10 row += 10 col = 0 def Run(self): # this method is setting game's rule self.population = 0 for cell in self.cells: if cell.alive: self.population += 1 if len(cell.a_neighbors) < 2: cell.die() elif len(cell.a_neighbors) > 3: cell.die() elif len(cell.a_neighbors) == 2 or len(cell.a_neighbors) == 3: cell.live() else: if len(cell.a_neighbors) == 3: cell.live() def blitDirections(self): # setting information window text = self.font.render("Press Enter to begin, and Space to stop and clear board", 1, (255,255,255)) generations = self.font.render("Generation: %s" %str(self.generation), 1, (255,255,255)) pop = self.font.render("Pop: %s" %str(self.population), 1, (255,255,255)) self.screen.blit(text, (10, 15)) self.screen.blit(generations, (500,15)) self.screen.blit(pop, (650, 15)) def Loop(self): # main game loop self.eventLoop() self.Tick() self.Draw() pygame.display.update() def eventLoop(self): # the main event loop, detects keypresses for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_RETURN: self.runnning = True if event.key == K_SPACE: self.runnning = False self.sprites.empty() self.cells = [] self.createGrid() def Tick(self): # updates to player location and animation frame self.ttime = self.clock.tick() self.mpos = pygame.mouse.get_pos() self.keys_pressed = pygame.key.get_pressed() if self.running: self.generation += 1 self.Run() else: self.generation = 0 self.population = 0 def Draw(self): self.screen.fill(0) self.blitDirections() self.sprites.update() self.sprites.draw(self.screen) Game()
もしなんか分かる人いたら教えてくださいm(_ _)m
では以上。
それでは(*^^)v
追記:
どうでもいいけど、コメントの英語多少間違ってる部分あるけど気にしないでください(・_・;)(aliveの用法とか)