Movatterモバイル変換


[0]ホーム

URL:


兼雑記

この広告は、90日以上更新していないブログに表示しています。

C で curry 化 @x86

http://nicosia.is.s.u-tokyo.ac.jp/pub/essay/hagiya/h/curry

を Sun からx86 に。

C言語は便利で楽しいなあ、と思わざる得ないのである。

に激しく同意なのです。

#include <stdio.h>#include <stdlib.h>#include <sys/mman.h>int (*curry(int (*F)(), int A))() {  char *code = (char*)malloc(18);  *(char*)code = 0x55;  *(short int*)(code+1) = 0xe589;  *(short int*)(code+3) = 0x75ff;  *(char*)(code+5) = 0x08;  *(char*)(code+6) = 0x6a;  *(char*)(code+7) = (char)A;  *(char*)(code+8) = 0xe8;  *(int*)(code+9) = (int)F-((int)code+9+4);  *(short int*)(code+13) = 0xc483;  *(short int*)(code+15) = 0x08;  *(short int*)(code+16) = 0xc9;  *(short int*)(code+17) = 0xc3;  mprotect((void*)(((int)code+4095) & ~4095 - 4096),           4096, PROT_READ | PROT_EXEC);  return((int (*)())code);}int add(int x, int y) {  return(x + y);}int main() {  int (*c)();  c = curry(add, 100);  printf("%d\n", (*c)(10));}
検索
リンク
なにかあれば下記メールアドレスへ。shinichiro.hamaji _at_ gmail.com
shinichiro.h

引用をストックしました

引用するにはまずログインしてください

引用をストックできませんでした。再度お試しください

限定公開記事のため引用できません。

読者です読者をやめる読者になる読者になる

[8]ページ先頭

©2009-2025 Movatter.jp