MessageBox(내용,타이틀,옵션)

MessageBox 옵션 :

  • MB_ABORTRETRYIGNORE   The message box contains three pushbuttons: Abort, Retry, and Ignore.

  • MB_OK   The message box contains one pushbutton: OK.

  • MB_OKCANCEL   The message box contains two pushbuttons: OK and Cancel.

  • MB_RETRYCANCEL   The message box contains two pushbuttons: Retry and Cancel.

  • MB_YESNO   The message box contains two pushbuttons: Yes and No.

  • MB_YESNOCANCEL   The message box contains three pushbuttons: Yes, No, and Cancel.

Message-Box Modality

  • MB_APPLMODAL   The user must respond to the message box before continuing work in the current window. However, the user can move to the windows of other applications and work in those windows. The default is MB_APPLMODAL if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.

  • MB_SYSTEMMODAL   All applications are suspended until the user responds to the message box. System-modal message boxes are used to notify the user of serious, potentially damaging errors that require immediate attention and should be used sparingly.

  • MB_TASKMODAL   Similar to MB_APPLMODAL, but not useful within a Microsoft Foundation class application. This flag is reserved for a calling application or library that does not have a window handle available.

Message-Box Icons

  • MB_ICONEXCLAMATION   An exclamation-point icon appears in the message box.

  • MB_ICONINFORMATION   An icon consisting of an “i” in a circle appears in the message box.

  • MB_ICONQUESTION   A question-mark icon appears in the message box.

  • MB_ICONSTOP   A stop-sign icon appears in the message box.

Message-Box Default Buttons

  • MB_DEFBUTTON1   The first button is the default. Note that the first button is always the default unless MB_DEFBUTTON2 or MB_DEFBUTTON3 is specified.

  • MB_DEFBUTTON2   The second button is the default.

  • MB_DEFBUTTON3   The third button is the default.


From MSDN


ex)

#include<Windows.h>


#define CONTENT "Error code:1401 - 응용 프로그램 구성이 올바르지 않기 때문에 이 응용 프로그램을 시작하지 못했습니다. 이 문제를 해결하려면 응용 프로그램을 다시 설치하십시오.\nDLL <C:\\Program Files\Autodesk\3ds Max 9\Plugins\CurveCtl.dle> failed to initialize."

int main(){

MessageBox(NULL,CONTENT,"Error ",MB_RETRYCANCEL | MB_ICONSTOP);

return 0;

}



'System > Windows' 카테고리의 다른 글

Message HOOK - Window  (0) 2012.08.20
CreateProcess  (2) 2012.08.03
파일복사 api  (0) 2012.08.02
WinAPI 레지스트리  (0) 2012.07.27
CreateWindow  (0) 2012.07.26
#include<Windows.h>

API선언, 상수, 데이터타입, 필요한 헤더들 포함.


Winmain

- Windows 프로그램의 엔트리 포인트


hInstance

- 프로그램의 인스턴스 핸들

- 인스턴스(Instance) : 클래스가 메모리에 실제로 구현된 실체


WndClass

-윈도우를 생성하는 클래스




typedef struct tagWNDCLASS{

UINT style;

WNDPROC lpfnWndProc;

int            cbClsExtra;

int            cbWndExtra;

HINSTANCE    hInstance;

HICON            hIcon;

HCURSOR        hCursor;

HBRUSH            hbrBackground;

LPCSTR            lpszMenuName;

LPCSTR            lpszCLassName;

}WNDCLASS;



style : 윈도우의 스타일 지정

lpfnWndProc : 메시지 발생시 여기서 지정한 함수를 호출하여 메시지를 처리함.

cbClsExtra,cbWndExtra : 예약영역

hInstance : 윈도우 클래스를 사용하느 프로그램

hIcon,hCursor : 마우스 커서와 아이콘 지정

hbrBackground : 배경 색지정

lpszMenuName : 프로그램이 사용할 메뉴 지정

lpszClassName : 클래스 이름 정의


윈도우 클래스를 정의한 후에는 다음과 같이 등록한다.

RegisterClass(&ClassName);


윈도우 생성 함수 : CreateWindow


HWND CreateWindow(lpszClassName,lpszWindowName,dwStyle,x,y,nWidth,nHeight,hwndParent,hmenu,hinst,lpvParam);


lpszClassName : 생성하고자 하는 윈도우 클래스 지정

lpszWindowName : 타이틀 바에 나타날 문자

dwStyle : 윈도우 형태 지정

X,Y,nWidth,nHeigth : 윈도우 크기와 위치 지정

hWndParent : 부모윈도우 존재 시 부모윈도우 핸들 지정

hmenu : 윈도우에서 사용할 메뉴의 핸들 지정

hinst : 윈도우를 만드는 주체 지정

lpvParam : 보통 NULL


화면 출력함수

ShowWindow(hWnd,nCmdShow);


hwnd : 출력하고자 하는 윈도우의 핸들 값

nCmdShow : 화면에 출력하는 방식 지정.


윈도우 창띄우기 소스


#include <windows.h>

 

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);


int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR lpCmdString, int CmdShow )

{

    WNDCLASS windowClass;

    HWND hWnd;


    windowClass.cbClsExtra = 0;

    windowClass.cbWndExtra = 0;

    windowClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);

    windowClass.hCursor = LoadCursor (NULL, IDC_ARROW);

    windowClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);

    windowClass.hInstance = hInstance;

    windowClass.lpfnWndProc = (WNDPROC)WndProc;

    windowClass.lpszClassName = "ClassName";

    windowClass.lpszMenuName = NULL;

    windowClass.style = CS_HREDRAW | CS_VREDRAW;

 

    if (!RegisterClass (&windowClass))

    {

        MessageBox(NULL, "Error : Cannot Register Window Class", "ERROR", MB_OK);

        return (0);

    } // end if

 

    hWnd = CreateWindow ("ClassName",   // 클래스명

       "Taesun1114",   // 윈도우 타이틀

       WS_OVERLAPPEDWINDOW | 

       WS_VISIBLE |

       WS_SYSMENU |

       WS_CLIPCHILDREN |

       WS_CLIPSIBLINGS,

       100,     // 윈도우 좌표 x

       100,     // 윈도우 좌표 y

       640,     // 윈도우 너비

       480,     // 윈도우 높이

       NULL, 

       NULL, 

       hInstance, 

       NULL);

 

    if ( hWnd == NULL )

    {

        MessageBox(NULL, "Error : Failed to Create Window", "ERROR", MB_OK);

        return (0);

    } // end if

 

    ShowWindow ( hWnd , CmdShow);

    UpdateWindow ( hWnd );

 

    MSG msg;

    while(1)

    {

        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))

        {

            if (msg.message == WM_QUIT)

                break;

 

            TranslateMessage(&msg); 

DispatchMessage (&msg);

        } // end if

    } // end while

 

    return msg.wParam;

}


LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam){

switch(iMessage)

{

case WM_DESTROY:

PostQuitMessage(0);

return 0;

}

return (DefWindowProc(hWnd,iMessage,wParam,lParam));

}


윈도우가 띄어짐!!


'System > Windows' 카테고리의 다른 글

Message HOOK - Window  (0) 2012.08.20
CreateProcess  (2) 2012.08.03
파일복사 api  (0) 2012.08.02
WinAPI 레지스트리  (0) 2012.07.27
WinApi MessageBox  (0) 2012.07.26

1) Flag register


Flag register는 CPU 내부 기구중 하나로 산술 연산 결과의 상태를 보여주는 레지스터이다.

(상태 레지스터)

CPU에 의해 세팅되며, 프로세서의 상태를 결정한다.


상태 플래그


CF (Carry Falg)

부호 없는 산술 연산에 쓰임.


PF(Parity Flag)

1인 비트의 수가 짝수면 1, 홀수면 0으로 설정된다.


ZF(Zero Flag)

연산 결과가 0이 되었을떄 설정


SF(Sign Flag)

연산 결과중에 음수로 바뀌었을 떄 설정


OF(Overflow Flag)

부호를 갖는 산술 연산에서 오버플로우 발생 유무 표시

1=overflow 

'O.S' 카테고리의 다른 글

IDT / LDT / GDT / SSDT  (1) 2012.09.26
Mutex  (0) 2012.05.16
Classic Problems of Synchronization / Monitor  (0) 2012.04.27
Synchronization Hardware  (0) 2012.04.27
Semaphore  (0) 2012.04.27

#include<stdio.h>


char ps[1000][1000];

int ps_id[1000];

char ps_name[1000][1000];

char kill[100];



int main()

{

    FILE *fp;

    FILE *fp1;

    int id;

    fp1=fopen("psid.txt","r");

    int count=0,i,dis=0;

    char temp[100];

    system("ps -e > test.txt");

    fp=fopen("test.txt","r");

    fscanf(fp1,"%d",&id);

    while(fgets(ps[count],1000,fp)){

        count++;

    }

    for(i=0;i<count;i++)

        sscanf(ps[i],"%d %*s %*s %s",&ps_id[i],ps_name[i]);

    for(i=0;i<count;i++){

        if(strcmp(ps_name[i],"a.out")==0){    //a.out만 원하는 프로그램명으로 바꾸면 됨.

            if(dis==0)

                dis=1;

            else{

                sprintf(kill,"kill -9 %d",ps_id[i]);

                printf("%s\n",kill);

                system(kill);

            }

        }

    }



    return 0;

}


ps -e >> test.txt 명령어로 모든프로세스를 test.txt파일에 저장하고 파일을 읽어들인다.

멀티프로세스 서버 소켓을 사용하던 도중 자식프로세스가 죽지 않고 남아있어서 심심해서 작성해봤는데... 실질적인 문제는 이게 아니고 자식프로세스가 좀비로 변해버려서 죽지않아요 ㅠㅠ


이 좀비들....ㅋ.....

'System > Linux' 카테고리의 다른 글

리눅스 core file  (0) 2013.03.18
nohup  (0) 2013.03.18
리눅스 tee 명령어  (0) 2013.03.14
Mac Address 바꾸기  (0) 2012.06.28
Linux 디렉토리 구조  (0) 2012.06.07






http://www.cyworld.com/Gh0st/5252965

'NetWork' 카테고리의 다른 글

Python 패킷 캡쳐(with. pypcap)  (1) 2021.03.10
RTP (Realtime Transport Protocol)  (0) 2013.03.04
tcphdr , tcphdr??  (0) 2012.07.09
ARP_Spoofing  (2) 2012.07.06
ICMP Protocol  (0) 2012.07.06

enum 열거형은 자주 사용되지는 않지만 알아두면 편리하다.


예를들어 알파벳을 이용할떄 


char buf[]="abcdef......z";

라고 선언을 하면 buf[0]=a~e까지는 쉽게알 수 있으나 q나 y같은건 몇번째 일까?

이럴때 


enum {a,b,c,d,e,f,.....,z}; 와 같이 사용하면,굳이 인덱스번호를 알지않아도, 바로 사용할수 있다.


ex)


int main(){


enum {a,b,c,d,e,f,....z};

char ch="a";


if(ch==a)  혹은 if(ch==0)이런식으로 사용해도 되는 것이다.


컴퓨터가 보기엔 별거 아니지만 소스코드를 짜는 사람입장으로서는 엄청나게 가독성이 상승하게 된다.


enum 사용 예제


#include <stdio.h>

enum week {sun, mon, tue, wed, thu, fri, sat};

int main(void)

{

    enum week day1;

    day1=fri;

    printf("day1 : %d\n", day1);

    printf("fri : %d\n", fri);

    day1=mon;

    printf("day1 : %d\n", day1);

    printf("mon : %d\n", mon);

    return 0;

}


'Programming > C' 카테고리의 다른 글

삼항연산자  (0) 2012.09.12
sscanf , sprintf  (0) 2012.07.06
문자열 붙이기 Strcat()  (0) 2012.07.04
Strtok 문자열 자르기  (0) 2012.06.29
Extern 함수  (0) 2012.05.21

/usr/include/netinet/tcp.h 중





음?ㅠ 보통 struct tcphdr *tcphdr; 이렇게 선언한후에 사용하잖아요 그러면 .... 두개의 구조체가 모두 선언된건가???


#include<stdio.h>

#include<netinet/tcp.h>


int main()

{

        struct tcphdr *tcphdr;

        printf("tcphdr tp_port : %d\n",tcphdr->th_dport);

        printf("tcphdr source : %d\n",tcphdr->source);

        return 0;

}


두번째구조체에있는 tcphdr->source는 인식하지만 첫번째 멤버는 없다고 나온다.

????????

'NetWork' 카테고리의 다른 글

RTP (Realtime Transport Protocol)  (0) 2013.03.04
VMware network  (0) 2012.07.10
ARP_Spoofing  (2) 2012.07.06
ICMP Protocol  (0) 2012.07.06
TCP / IP 프로토콜 스택  (0) 2012.04.25

ARP spoofing을 알기 전에 arp부터 짚고 넘어가자.

arp는 상대방 아이피는 알고 있으나 맥주소를 모를때, 브로드캐스트로 해당아이피를 가지고 있는 컴퓨터의 맥주소를 달라고 요청하는 패킷이다.


arp spoofing 은 이 arp패킷을 이용하여 맥주소를 속여 상대방의 패킷을 훔쳐보는 것을 말한다. 이는 2계층에서 작동하므로 같은 네트워크안에 있어야 한다.


로컬네트워크에서 MAC주소는 arp-a명령어로 확인할 수 있다.



※실습


vm 네트워크 안에서 두개의 os를 켜놓고 실습해보자. 일단 ip_scanner와 같은 툴로 네트워크 안의 활성화 되어 있는 아이피를 찾는다. 

공격자 ip : 192.168.15.128    MAC : 00:0c:29:46:ea:7c

희생자 ip : 192.168.15.129    MAC : 00:0c:29:ad:2c:cf

서버(게이트웨이) ip : 192.168.15.2 MAC : 00:50:56:e4:14:ae




send_arp <바꿀 타켓 ip > < 공격자의 MAC > <공격자 ip > <희생자 MAC>


send_arp 툴을 이용해서 서버에 공격자의 mac주소를 추가 시킨다. 위와 같이 명령어를 입력하면 다른 클라이언트에서 192.168.15.2.에 arp를 날리게 되면 서버의 mac과 공격자의 mac주소가 같이 날라가게 되고, 희생자 컴퓨터는 둘다 서버라고 믿고 두곳에 패킷을 날리게 된다.


명령어를 입력하고 wireshark로 패킷을 잡아보면 희생자컴퓨터의 패킷이 잡히는 것을 볼수가 있다.


 arp패킷을 필터링해서 보면,


arp응답으로 두개의 mac주소를 보내는 것을 알수 있다.


※대응방안

arp -a로 나오는 맥을 변하지 않게 정적으로 static옵션을 주어 설정할 수 있다. 이렇게 설정을 해 두면, mac address를 업데이트하라는 arp패킷에 업데이트 되지 않기 떄문에 보안상 중요하다고 할 수 있는데, static으로 설정하는 방법은,


arp -s < IP주소 > < MAC 주소 >


static설정이 보안상에 좋긴 하나, 만에 하나 잘못해서 설정하면 네트워크가 저멀리 날아갈지도.....바꾸기 전에 메모라도 해두는게 좋을 듯 하다.

'NetWork' 카테고리의 다른 글

VMware network  (0) 2012.07.10
tcphdr , tcphdr??  (0) 2012.07.09
ICMP Protocol  (0) 2012.07.06
TCP / IP 프로토콜 스택  (0) 2012.04.25
Wireshark_Network Analysis  (2) 2012.04.17

sscanf와 sprintf는 입력혹은 출력 대상이 모니터가 아닌 메모리라는 것을 제외 하면 scanf와 print와 같은 기능을 한다.


#include<stdio.h>

int sprintf(char *restrict s,const char* restrict format,....);

함수 호출 성공시 저장된 문자열의 길이, 실패시 EOF반환.


#include<stdio.h>

int sscanf(char *s,const char* restrict format, ...);

함수 호출 성공시 읽어 들인 데이터의 갯수, 실패시 EOF 반환.


sscanf 예제)

#include<stdio.h>


int main()

{

        char buf[100];


        sscanf("HI~!Taesun1114's blog","%s",buf);


        printf("%s\n",buf);

        return 0;

}



sprintf 예제)
#include<stdio.h>

int main()
{
        char buf[100];

        sprintf(buf,"HI~!Taesun1114's blog");
        printf("%s\n",buf);
        return 0;
}



'Programming > C' 카테고리의 다른 글

삼항연산자  (0) 2012.09.12
열거형 enum  (0) 2012.07.09
문자열 붙이기 Strcat()  (0) 2012.07.04
Strtok 문자열 자르기  (0) 2012.06.29
Extern 함수  (0) 2012.05.21

ICMP 란?

 ->internet control message protocol의 줄임말로 다른 호스트 혹은 게이트웨이에 연결된 네트워크 상태를 알아보는데 사용된다. 대표적으로 ping이 있음.



ICMP packet 구조는 다음과 같으며, Header 타입은 다음과 같다.



리눅스에서는 /usr/include,netinet/ip_icmp.h에 정의 되어 있다.




ICMP Type을 바꿔서 요청을 보내보는 간단한 소스.


#include<stdio.h>

#include<sys/socket.h>

#include<arpa/inet.h>

#include<string.h>

#include<stdlib.h>

#include<netinet/ip.h>

#include<netinet/ip_icmp.h>

#include<netinet/in.h>

#include<net/ethernet.h>


int main(int argc,char *argv[])

{

int icmp_sock;

struct icmp *p,*rp;

struct sockaddr_in addr,from;

char buffer[1024];

struct ip *ip;

int hlen;

socklen_t sz;


icmp_sock=socket(PF_INET,SOCK_RAW,IPPROTO_ICMP);


p=(struct icmp*)buffer;

p->icmp_type=8;

p->icmp_code=0;

p->icmp_cksum=0;

p->icmp_seq=15;

p->icmp_id=1234;


addr.sin_addr.s_addr=inet_addr(argv[1]);

addr.sin_family=AF_INET;

sz=sizeof(from);

sendto(icmp_sock,p,sizeof(*p),MSG_DONTWAIT,(struct sockaddr*)&addr,sizeof(addr));

recvfrom(icmp_sock,buffer,1024,0,(struct sockaddr*)&from,&sz);

ip=(struct ip*)buffer;

hlen=ip->ip_hl*4;

rp=(struct icmp*)(buffer+hlen);

printf("icmp type : %d\n",rp->icmp_type);

close(icmp_sock);

}

p->icmp_type 부분을 8과 0으로 바꿔보자. 8과 0에 대한 것은 위의 icmp header type표에 나와있다.



wireshark 로 패킷을 잡아보면 type이 8인것을 확인 할 수 있다.

이번엔 type을 0으로 바꿔서 날려보면.


'NetWork' 카테고리의 다른 글

VMware network  (0) 2012.07.10
tcphdr , tcphdr??  (0) 2012.07.09
ARP_Spoofing  (2) 2012.07.06
TCP / IP 프로토콜 스택  (0) 2012.04.25
Wireshark_Network Analysis  (2) 2012.04.17

+ Recent posts