Skip to content

Instantly share code, notes, and snippets.

@koturn
koturn / hello.c
Last active April 24, 2017 11:40
Hello World on Windows x64
#include <stdio.h>
#if defined(_MSC_VER)
# pragma section(".text", read, execute)
__declspec(allocate(".text"))
#elif defined(__GNUC__)
__attribute__((section(".text")))
#endif
const char code[] =
// push %rbp
@koturn
koturn / hello.c
Created April 6, 2017 23:36
x64なHello World
#include <unistd.h>
#include <sys/mman.h>
static const unsigned char code[] =
// mov $0x01,%rax
"\x48\xc7\xc0\x01\x00\x00\x00"
// mov $0x0d,%edx
"\xba\x0d\x00\x00\x00"
// mov $0x01,%edi
"\xbf\x01\x00\x00\x00"
@koturn
koturn / GeneratorElfX64.hpp
Last active April 3, 2017 16:55
x64のELF作るとこ
/*!
* @file GeneratorElfX64.hpp
* @brief x64 ELF binary generator
* @author koturn
*/
#ifndef GENERATOR_ELF_X64_HPP
#define GENERATOR_ELF_X64_HPP
#include <iostream>
@koturn
koturn / HelloWorldDump.txt
Created April 2, 2017 13:20
BrainfuckのHello, Worldをx64にしたやつ
hello.out: ファイル形式 elf64-x86-64
セクション .text の逆アセンブル:
00000000080480b0 <.text>:
80480b0: 48 bb 00 80 24 08 00 movabs $0x8248000,%rbx
80480b7: 00 00 00
80480ba: 80 03 0a addb $0xa,(%rbx)
@koturn
koturn / keymap.vim
Created March 22, 2017 14:49
previous,next,first,last系へのキー割り当て
nnoremap [a :<C-u>previous<CR>
nnoremap ]a :<C-u>next<CR>
nnoremap [A :<C-u>first<CR>
nnoremap ]A :<C-u>last<CR>
nnoremap [b :<C-u>bprevious<CR>
nnoremap ]b :<C-u>bnext<CR>
nnoremap [B :<C-u>bfirst<CR>
nnoremap ]B :<C-u>blast<CR>
@koturn
koturn / kuin.snip
Created February 19, 2017 13:59
Kuinのスニペット集です
snippet main
func main()
${0:TARGET}
end func
snippet fn
alias def
func ${1:#:name}(${2:#:args...})${3:\: ${4:\#:type\}}
${0:TARGET}
end func
@koturn
koturn / ArgumentParser.cs
Last active January 12, 2017 15:32
Simple argument parser.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace ArgumentParser
{
/// <summary>
@koturn
koturn / Makefile
Last active January 8, 2017 01:49
簡易的なプログラムのためのMakefile
CXX := g++ -std=gnu++14
CXXFLAGS := -Wall -Wextra -O3 -march=native -DNDEBUG
LDFLAGS := -s
TARGET := hoge
SRCS := $(wildcard *.cpp *.cxx *.cc)
OBJS := $(foreach PAT,%.cpp %.cxx %.cc,$(patsubst $(PAT),%.o,$(filter $(PAT),$(SRCS))))
ifeq ($(OS),Windows_NT)
TARGET := $(addsuffix .exe, $(TARGET))
else
@koturn
koturn / arrayTest.kn
Last active January 3, 2017 19:52
要素数を指定して配列を生成したときの挙動
func main()
var str: []char :: "abcdefgh"
var array: []char :: #[42]char
do cui@print((^array).toStr()) { => 8 になる}
do cui@print(array[0].toStr()) { => a になる}
end func
@koturn
koturn / brainfuck.kn
Last active January 8, 2017 07:58
まずは Hello, world! からだよね
func main()
var bfSource: []char :: "+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..+++.>-.------------.<++++++++.--------.+++.------.--------.>+."
var pc: int
var hp: int
var heap : []bit8 :: #[65536]bit8
var reader: @InputReader :: #@InputReader
while(pc < ^bfSource)
switch(bfSource[pc])
case '+'
do heap[hp] :+ 1b8