Be myself :: 'memo' 카테고리의 글 목록

달력

32024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

'memo'에 해당되는 글 4건

  1. 2015.08.15 리눅스 c로 coroutines 구현
  2. 2015.03.22 문자열 함수들 특징
  3. 2015.03.10 strcpy에 대한 팁.!
  4. 2014.12.26 qemu를 이용한 arm system 설치 1
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
#define MEM 64000

ucontext_t T1, T2, Main;
ucontext_t a;

int fn1()
{
  printf("this is from 1\n");
  setcontext(&Main);
}

void fn2()
{
  printf("this is from 2\n");
  setcontext(&a);
  printf("finished 1\n");
}

void start()
{
  getcontext(&a);
  a.uc_link=0;
  a.uc_stack.ss_sp=malloc(MEM);
  a.uc_stack.ss_size=MEM;
  a.uc_stack.ss_flags=0;
  makecontext(&a, (void*)&fn1, 0);
}

int main(int argc, char *argv[])
{
  start();
  getcontext(&Main);
  getcontext(&T1);
  T1.uc_link=0;
  T1.uc_stack.ss_sp=malloc(MEM);
  T1.uc_stack.ss_size=MEM;
  makecontext(&T1, (void*)&fn1, 0);
  swapcontext(&Main, &T1);

  getcontext(&T2);
  T2.uc_link=0;
  T2.uc_stack.ss_sp=malloc(MEM);
  T2.uc_stack.ss_size=MEM;
  T2.uc_stack.ss_flags=0;
  makecontext(&T2, (void*)&fn2, 0);
  swapcontext(&Main, &T2);
  printf("completed\n");
  exit(0);
}

[결과]

flack3r@ubuntu:/mnt/hgfs/Ctf$ ./test
this is from 1
this is from 2
this is from 1
completed


[*]주의 : swapcontext 와 setcontext의 역할은 비슷하지만 swapcontext는 현재 context정보를 첫번째 인자에 저장한 후 두번째 인자로 context가 변경되고 setcontext는 현재 context가 첫번째 인자로 바뀐다.

참조:http://stackoverflow.com/questions/21468529/context-switching-ucontext-t-and-makecontext

'memo' 카테고리의 다른 글

문자열 함수들 특징  (0) 2015.03.22
strcpy에 대한 팁.!  (0) 2015.03.10
qemu를 이용한 arm system 설치  (1) 2014.12.26
Posted by flack3r
|

문자열 함수들 특징

2015. 3. 22. 14:36

보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

strcpy에 대한 팁.!

memo 2015. 3. 10. 23:26

저게 스트링을 특정 메모리에 카피할 때 , 마지막 널바이트까지 같이 카피해준다. 따라서 저 방법을 이용하면 널바이트 쓰기를 우회 할 수 있는 트릭으로 작용할 수도 있다..!!!

'memo' 카테고리의 다른 글

리눅스 c로 coroutines 구현  (0) 2015.08.15
문자열 함수들 특징  (0) 2015.03.22
qemu를 이용한 arm system 설치  (1) 2014.12.26
Posted by flack3r
|

QEMU를 이용한 armv7 설치

1 처음엔 당연히 qemu를 설치해야 한다.
sudo apt-get install qemu-user-static qemu-system-arm

 

2. 그 다음 커널을 넣을 이미지 파일이 필요하고, arm system의 경우 바이오스가 없기 때문에 부트로더 역할을 하는 initrd라는 것이 필요하다. 그 다음 커널이 필요하게 된다. 따라서 다음과 같은 명령어를 입력하자 여기서 설치하는 커널은 armel이 아니라 armhf이다. 이것은 ARMv7명령어와 하드웨어 부동소수점 계산을 에뮬레이트 한다.
qemu-img create -f raw hda.img 3G

wget http://ftp.debian.org/debian/dists/wheezy/main/installer-armhf/current/images/vexpress/netboot/initrd.gz

wget http://ftp.debian.org/debian/dists/wheezy/main/installer-armhf/current/images/vexpress/netboot/vmlinuz-3.2.0-4-vexpress

 

3 자 이제 다음과 같은 명령어로 설치를 진행한다.
qemu-system-arm -nographic -M vexpress-a9 -kernel vmlinuz-3.2.0-4-vexpress -initrd initrd.gz -append "root=/dev/mmcblk0 console=ttyAMA0,115200" -drive if=sd,cache=unsafe,file=hda.img

 

4. 설치가 끝난 후 다시 qemu를 재실행하면 다시 설치화면으로 오기 때문에 커널과 부트로더가 설치된had.img를 마운트시켜 initrd.img파일을 뽑아와야 한다.

·                     mkdir mountdir

·                     mount -o loop,offset=$((512*2048)) hda.img mountdir/

·                     cp mountdir/initrd.img-3.2.0-4-vexpress .

·                     umount mountdir/

 

5. 자 그 다음 다음과 같은 명령어로 실행시키면 된다.

·                     qemu-system-arm -M vexpress-a9 -kernel vmlinuz-3.2.0-4-vexpress -initrd initrd.img-3.2.0-4-vexpress -append "root=/dev/mmcblk0p2" -drive if=sd,cache=unsafe,file=hda.img

 

6. 네트워크 세팅의 경우 DNS서버라던지 DHCP 같은 것들을 수작업으로 작업해야 하므로 복잡하다. 그래서 port redirection으로 ssh연결을 하는 방법을 설명하겠다. 일단 실행명령어에 -redir tcp:6666::22라는 명령어를 추가하여 실행시킨다. 그리고 초기 설치시 ssh서버 설치를 선택했어야 한다. 그 후 arm 가상환경에서 ssh-keygen -t rsa 명령어를 입력하고 게스트에서 ssh id@localhost –p 6666으로 접속하면 된다.!

* 주의할 점은 저렇게 순서대로 하면 파일시스템이 읽기 권한만 있어서 ssh-keygen 생성이 불가능하다. 따라서 처음에 mount -o remount,rw / 이렇게 쓰기권한을 주고 리마운트 시킨다.

'memo' 카테고리의 다른 글

리눅스 c로 coroutines 구현  (0) 2015.08.15
문자열 함수들 특징  (0) 2015.03.22
strcpy에 대한 팁.!  (0) 2015.03.10
Posted by flack3r
|