'컴퓨터 이야기'에 해당되는 글 95건

  1. 2011.01.07 soccer UVA
  2. 2011.01.05 Bridge
  3. 2011.01.02 Vito's Family
  4. 2011.01.01 Erdos Numbers
  5. 2010.09.07 DLL Injection 을 이용한 Win32 API Hooking (2)
  6. 2010.09.07 DLL Injection 을 이용한 Win32 API Hooking (1)
  7. 2010.09.02 라인 트레이서 중간 점검
  8. 2010.08.19 MS Visual Studio Macro 에서 h 과 cpp 파일간의 이동
  9. 2010.08.16 projecteuler.net : Problem 25
  10. 2010.07.30 어느 정도... 윤곽을 보이네요.
  11. 2010.07.27 이스케이프 문자와 기타 반복자
  12. 2010.07.22 YOU JUST ACTIVATED MY TRAP CARD 1
  13. 2010.07.20 KSF Creator2 1.3 final 3
  14. 2010.07.19 API 후킹
  15. 2010.07.18 Reverse Engineering 카테고리 열었어요.

soccer UVA

컴퓨터 이야기/C++ 2011. 1. 7. 01:38
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <ctime>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
using namespace std;

#ifdef mycom
ifstream fin("input");
#else
#define fin cin
#endif

class team
{
public:
 int score;
 int wincounter;
 int goaldiff;
 int manygoal;
 int gamecounter;
 string teamname;

 ////////////
 int drawcounter;
 int losecounter;
 int sibalgoal;
 team() { 
  score = 0;
  wincounter = 0;
  goaldiff = 0;
  manygoal = 0;
  gamecounter = 0;
  drawcounter=0;
  losecounter=0;
  sibalgoal=0;
 }
 
 bool operator<(const team& t) const
 {
  if(this->score == t.score)
  {
   if(this->wincounter == t.wincounter)
   {
    if(this->goaldiff == t.goaldiff)
    {
     if(this->manygoal == t.manygoal)
     {
      if(this->gamecounter == t.gamecounter)
      {
       char ateam[100];
       char bteam[100];
       strcpy(ateam, teamname.c_str());
       strcpy(bteam, t.teamname.c_str());
       for(int i=0; i<strlen(ateam); i++)
        ateam[i] = toupper(ateam[i]);
       for(int i=0; i<strlen(bteam); i++)
        bteam[i] = toupper(bteam[i]);
       string a = ateam;
       string b = bteam;
       return a > b;
      }
      else
      {
       return this->gamecounter > t.gamecounter;
      }
     }
     else
     {
      return this->manygoal < t.manygoal;
     }
    }
    else
    {
     return this->goaldiff < t.goaldiff;
    }
   }
   else
   {
    return this->wincounter < t.wincounter;
   }
  }
  else
  {
   return this->score < t.score;
  }
 }
};


int main()
{
 int N;
 
 fin >> N;
 fin.ignore(1024, '\n');
 for(int n=1; n<=N; n++)
 {
  int T;
  
  string tonorname;
  char temptonorname[1024];
  
  fin.getline(temptonorname, 1024);
  tonorname = temptonorname;
  fin >> T;
  fin.ignore(1024, '\n');
  vector<team> teams;
  for(int j=1; j<=T; j++)
  {
   char temp[1024];
   fin.getline(temp, 1024);
   team tempteam;
   tempteam.teamname = temp;
   teams.push_back(tempteam);
  }

  int G;
  fin >> G;
  fin.ignore(1024, '\n');
  for(int g=1; g<=G; g++)
  {
   char temp[1024];
   char* p;
   
   int Ascore, Bscore;
   string Aname;
   string Bname;
   fin.getline(temp, 1024);
   p = strtok(temp, "#");
   Aname = p;
   p = strtok(0, "@");
   Ascore = atoi(p);
   p = strtok(0, "#");
   Bscore = atoi(p);
   p = strtok(0, "#");
   Bname = p;
   for(vector<team>::iterator iter = teams.begin(); iter != teams.end(); ++iter)
   {
    if((*iter).teamname == Aname)
    {
     if(Ascore > Bscore)
     {
      iter->score += 3;
      iter->wincounter++;
     }
     else if(Ascore == Bscore)
     {
      iter->drawcounter++;
      iter->score += 1;
     }
     else
      iter->losecounter++;
     iter->sibalgoal += Bscore;
     iter->manygoal += Ascore;
     iter->gamecounter++;
     iter->goaldiff += Ascore - Bscore;
    }
    else if( (*iter).teamname == Bname)
    {
     if(Bscore > Ascore)
     {
      iter->score += 3;
      iter->wincounter++;
     }
     else if(Ascore == Bscore)
     {
      iter->score += 1;
      iter->drawcounter++;
     }
     else
      iter->losecounter++;
     iter->sibalgoal += Ascore;
     iter->manygoal += Bscore;
     iter->gamecounter++;
     iter->goaldiff += Bscore - Ascore;
    }
   }

  }
  sort(teams.rbegin(), teams.rend());
  cout << tonorname << endl;
  for(int i = 0; i<teams.size(); i++)
  {
   printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", 
    i+1,
    teams[i].teamname.c_str(),
    teams[i].score,
    teams[i].gamecounter, 
    teams[i].wincounter,
    teams[i].drawcounter,
    teams[i].losecounter,
    teams[i].goaldiff,
    teams[i].manygoal,
    teams[i].sibalgoal);
  }
  if(n != N)
   cout << endl;
 }
 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

순열  (0) 2011.01.07
부분집합  (0) 2011.01.07
Bridge  (0) 2011.01.05
Vito's Family  (0) 2011.01.02
Erdos Numbers  (0) 2011.01.01
:

Bridge

컴퓨터 이야기/C++ 2011. 1. 5. 01:05
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <time.h>
#include <set>
using namespace std;


#ifdef mycom
#include <fstream>
ifstream fin("input");
#else
#define fin cin
#endif

vector<int> A;
vector<int> B;

 

 


int main()
{
 int testcase;

 testcase = 1;
 fin >> testcase;

 int hours;
 string solution; 
 solution.resize(10000);
 for(int i=1; i<=testcase; i++)
 {
  solution = "";

  hours = 0;
  int n;
  fin >> n;

  for(int j=1; j<=n; j++)
  {
   int temp;
   fin >> temp;
   A.push_back(temp);
  }

  sort(A.begin(), A.end());
  //saram 에 대한 처리가 들어감
  while(A.empty() == false)
  {
   if(A.size() == 1)
   {
    vector<int>::iterator b = A.begin();
    int _A = *b;

    B.insert(B.begin(), A.begin(), A.end());
    A.clear();

    char buf[256];
    sprintf(buf, "%d\n", _A);
    solution += buf;
    hours += _A;
   }
   else if(A.size() == 2)
   {
    vector<int>::iterator b = A.begin();
    int _A = *b;
    b++;
    int _B = *b;

    B.insert(B.begin(), A.begin(), A.end());
    A.clear();
    char buf[256];
    sprintf(buf, "%d %d\n", _A, _B);
    solution += buf;
    hours += _B;
   }
   else if(A.size() == 3)
   {
    vector<int>::iterator b = A.begin();
    int _A = *b;
    b++;
    int _B = *b;
    b++;
    int _C = *b;


    B.insert(B.begin(), A.begin(), A.end());
    A.clear();
    char buf[256];

    sprintf(buf, "%d %d\n", _A, _B);
    solution += buf;

    sprintf(buf, "%d\n", _A);
    solution += buf;

    sprintf(buf, "%d %d\n", _A, _C);
    solution += buf;
    hours += _A + _B + _C;
   }
   else if(A.size() >= 4)
   {
    vector<int>::iterator b = A.begin();
    vector<int>::reverse_iterator rb = A.rbegin();
    int _A = *b;
    b++;
    int _B = *b;
    int _Z = *rb;
    rb++;
    int _Y = *rb;

    A.erase(find(A.begin(), A.end(), _Y));
    A.erase(find(A.begin(), A.end(), _Z));
    //A.erase(_Y);
    //A.erase(_Z);
    B.push_back(_Y);
    B.push_back(_Z);
    if(_A + 2*_B + _Z <= 2*_A + _Y + _Z)
    {    
     char buf[256];
     sprintf(buf, "%d %d\n", _A, _B);
     solution += buf;
     sprintf(buf, "%d\n", _A);
     solution += buf;
     sprintf(buf, "%d %d\n", _Y, _Z);
     solution += buf;
     sprintf(buf, "%d\n", _B);
     solution += buf;

     hours += _A + 2*_B + _Z;
    }
    else
    {
     char buf[256];
     sprintf(buf, "%d %d\n", _A, _Z);
     solution += buf;
     sprintf(buf, "%d\n", _A);
     solution += buf;
     sprintf(buf, "%d %d\n", _A, _Y);
     solution += buf;
     sprintf(buf, "%d\n", _A);
     solution += buf;
     hours += 2*_A + _Y + _Z;
    }
   }
   sort(A.begin(), A.end());
   sort(B.begin(), B.end());
  }
  cout << hours <<endl << solution;
  if(testcase  != i)
   cout << endl;
 }

 return 0;
}

 


'컴퓨터 이야기 > C++' 카테고리의 다른 글

부분집합  (0) 2011.01.07
soccer UVA  (0) 2011.01.07
Vito's Family  (0) 2011.01.02
Erdos Numbers  (0) 2011.01.01
MS Visual Studio Macro 에서 h 과 cpp 파일간의 이동  (0) 2010.08.19
:

Vito's Family

컴퓨터 이야기/C++ 2011. 1. 2. 15:39
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <time.h>
#include <set>
#include <cmath>
using namespace std;
//#define mycom
#ifdef mycom
#include <fstream>
ifstream fin("input");
#else
#define fin cin
#endif

using namespace std;
int main()
{
 int casenumber;
 fin >> casenumber;

 for(int i=1; i<=casenumber; i++)
 {
  int headnumber;
  fin >> headnumber;
  vector<int> s;
  for(int j=1; j<=headnumber; j++)
  {
   int temp;
   fin >> temp;
   s.push_back(temp);
  }
  
  int nmin = numeric_limits<int>::max();
  
  for(vector<int>::iterator iter = s.begin(); iter != s.end(); ++iter)
  {
   int sum = 0;
   for(vector<int>::iterator iter2 = s.begin(); iter2 != s.end(); ++iter2)
   {
    sum += abs(*iter - *iter2);
   }
   nmin = min(sum, nmin);
  }

  cout << nmin << endl;
 }
 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

soccer UVA  (0) 2011.01.07
Bridge  (0) 2011.01.05
Erdos Numbers  (0) 2011.01.01
MS Visual Studio Macro 에서 h 과 cpp 파일간의 이동  (0) 2010.08.19
projecteuler.net : Problem 25  (0) 2010.08.16
:

Erdos Numbers

컴퓨터 이야기/C++ 2011. 1. 1. 16:12
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <time.h>
using namespace std;
#define mycom
#ifdef mycom
#include <fstream>
ifstream fin("input");
#else
#define fin cin
#endif

struct Node
{
 string vertex;
 Node* adj;
 bool operator==(const Node& n) const
 {
  return (vertex == n.vertex);
 }
 bool operator<(const Node& n) const
 {
  return vertex < n.vertex;
 }
};


vector<Node> graph;


void CreateVertex(const string& v)
{
 Node n;
 n.vertex = v;
 n.adj = 0;
 bool bfind = false;
 if( find(graph.begin(), graph.end(), n) == graph.end() ) // 없
  graph.push_back(n);
}


void link(const string& from, const string& to)
{
 Node s;
 s.vertex = from;
 vector<Node>::iterator fromiter = find(graph.begin(), graph.end(), s);
 Node* p = new Node;
 p->vertex = to;
 p->adj = fromiter->adj;
 fromiter->adj = p;
}


int sina;
int non;
int saram;

 


int mymin = 9999999;
map<string, bool> visit;
void dfs(const string& curnode, int mycount)
{
 //해가 맞는가?
 //아니면
 //모든 경우에 대해 백트
 visit[curnode] = true;
 ///cout << curnode << endl;
 if(curnode == "Erdos, P.")
 {
  if (mycount < mymin)
   mymin = mycount;
 } else
 {
  Node s;
  s.vertex = curnode;
  Node* p = &(*find(graph.begin(), graph.end(), s));
  while(p)
  {   
   if(mymin > mycount )
   {
    if( p->adj && !visit[p->adj->vertex] )
     dfs(p->adj->vertex, mycount + 1);
   }
   p = p->adj;
  }
 }
 visit[curnode] = false;
}


int main()
{

 
 fin >> sina;
 for (int i = 1; i <= sina; i++)
 {
  //memset(graph, 0, sizeof(graph));


  fin >> non >> saram;
  //
  char t;
  while (fin.get(t) && t != '\n')
   ;
  
  for (int j = 1; j <= non; j++)
  {


   char temp[1024];
   fin.getline(temp, 1024);
   int startpos = 0;
   vector<string> v;
   for (int i = 0; i < strlen(temp); i++)
   { // 문자열 파싱.
    if (strncmp(&temp[i], ".,", 2) == 0 || strncmp(&temp[i], ".:", 2) == 0)
    {
     string strtemp;
     strtemp.assign(&temp[startpos], &temp[i + 1]);
     v.push_back(strtemp);


     startpos = i + 3;
    }
   }

   
   //이어주기
   for (int z = 0; z < v.size(); z++)
   {
    for (int z2 = 0; z2 < v.size(); z2++)
    {
     if(z != z2)
     {
      CreateVertex(v[z]);
      CreateVertex(v[z2]);
      link(v[z], v[z2]);
      //link(v[z2], v[z]);
     }
    }
   }
   
  }
  
  //for(map<string, int>::iterator i = dic.begin(); i != dic.end(); i++)
  // cout << i->first << i->second << endl;
  //while (fin.get(t) && t != '\n');
  cout << "Scenario " << i << endl;
  
  char temp[1024];
  for (int j = 1; j <= saram; j++)
  {
   fin.getline(temp, 1024);
   
   mymin = numeric_limits<int>::max();
   clock_t start = clock(); 
   dfs(temp, 0);
   //cout << clock() - start << endl;
   if (mymin == numeric_limits<int>::max())
    cout << temp << " " << "infinity" << endl;
   else
    cout << temp << " " << mymin << endl;
  }
 }


 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

Bridge  (0) 2011.01.05
Vito's Family  (0) 2011.01.02
MS Visual Studio Macro 에서 h 과 cpp 파일간의 이동  (0) 2010.08.19
projecteuler.net : Problem 25  (0) 2010.08.16
API 후킹  (0) 2010.07.19
:

DLL Injection 을 이용한 Win32 API Hooking (2)

컴퓨터 이야기/Reverse Engineering 2010. 9. 7. 02:22

이전 글과 이어서 이번엔 그냥 단순히

다른 프로세스에 DLL 파일을 집어넣는 작업을 해보겠습니다.

DLL 파일은 아무 DLL 파일이든지 상관없으니까


#include <windows.h>
#define MB_OUT MB_OK
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
 HANDLE hThread = NULL;
 switch( fdwReason )
 {
  case DLL_PROCESS_ATTACH :
   MessageBoxA(0, "dll 진입", "dll 진입", MB_OUT);
   break;
 }
 return TRUE;
}
 

DLL 프로젝트로 다음과 같은 코드를 넣고 컴파일을 합니다. 여기서 나온 파일을 dllproject.dll 라고 치고
c:\dllproject.dll 로 옮깁니다.

이제 이 dll 파일을 넣을 타겟 프로그램을 설정하여야 하는데. 이걸로 합니다.

DLL Injection 의 개요는 다음과 같습니다.
#1 타겟프로그램의 적당한 곳에 메모리를 할당한 후 dll 경로를 저장합니다. ("c:\\dllproject.dll" 라는 문자열)
#2 메모리에 맵핑되어있는 kernel32.dll 의 LoadLibraryA 함수의 주소를 구합니다.
#3 타겟 프로그램에 스레드를 생성시켜 LoadLibraryA 함수의 인자로 dll 경로가 전달되게 합니다.
--<1> 스레드를 생성시킬 때 스레드 함수 주소로 #2 에서 구한 LoadLibraryA 의 주소를 넣습니다.
--<2> 인자로 타겟프로그램안에 저장되어있는 "c:\\dllproject.dll" 라는 문자열을 인자로 넘깁니다.

코드로 보면 확실해집니다.

#include <cstdio>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>

// DLL Inject : 다른 프로세스의 주소 공간에 특정 DLL을 넣는다.
void DllInject(DWORD pid, char* path); // processid 와 dll 경로를 받음
 
int main()
{

 HWND hNotepad = FindWindow("ThunderRT6FormDC", 0); // "ThunderRT6FormDC" 인 클래스를 찾아서 ~
 DWORD pid;
 GetWindowThreadProcessId(hNotepad, &pid); // hWnd 로 부터 processid 얻음.
 DllInject(pid, "C:\\dllproject.dll");
 return 0;
}


void DllInject(DWORD pid, char* path)
{
//#1 과정 진행
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
 void* dllpath = VirtualAllocEx(hProcess, 0, // 원하는 주소(0은 알아서 해달라)
  _tcslen(path)+1, // 크기
  MEM_RESERVE | MEM_COMMIT, // 예약과 동시 확정
  PAGE_READWRITE);
 // 이제 DLL의 경로를 담을 문자열 복사
 // WriteProcessMemory()는 다른 프로세스 주소 공간에 무언가를 쓸 수 있다.
 // 타겟의 주소공간에 메모리를 할당하고, DLL의 경로를 복사해준다.
 // VirtualAlloc은 가상 메모리를 할당하는 API이지만, Ex가 붙으면 다른 프로세스의 주소공간을 할당할 수 있다.
 DWORD len;
 WriteProcessMemory(hProcess, dllpath, path, _tcslen(path)+1, &len);
//#1 과정 끝

//#2 과정 진행
 HMODULE hDll = GetModuleHandle("kernel32.dll"); // kernel32.dll 모듈의 핸들값을 GetModuleHandle로 구한다.
 PTHREAD_START_ROUTINE loadlibthread = (PTHREAD_START_ROUTINE)GetProcAddress(hDll, "LoadLibraryA");
//#2 과정 끝

//#3 과정 진행
 // 타겟에 새로운 스레드를 만든다.
 // CreateRemoteThread는 다른 프로세스에 스레드를 생성시킨다.
 HANDLE hThread = CreateRemoteThread(hProcess, // 타겟 핸들
  0, 0, 
  loadlibthread, dllpath, // 함수, 인자
  0, 0);
 CloseHandle(hThread);
 CloseHandle(hProcess);
//#3 과정 끝
}


네 c:\dllproject.dll 위치시키고 프로그램을 실행시켰더니 예상대로 이렇게 뜹니다.





그리고 Process Explorer 로 확인해본 결과 메모리에 이제 dllproject.dll 가 떠있군요.

이로써 Win32 API Hooking 을 하기 위한 기초작업은 다 된겁니다.
:

DLL Injection 을 이용한 Win32 API Hooking (1)

컴퓨터 이야기/Reverse Engineering 2010. 9. 7. 01:55

후킹은 원래 진행되어야하는 프로세스를 중간에 낚아채서 내가 원하는 코드를 집어넣는 작업을 말합니다.      
        
다른 프로그램에서 MessageBox 를 호출 하는 순간을 잡을 수 있다. .!! 흥분되지 않습니까?
        
        
Win32 API 하에서 다른 프로세스나 전역적으로 호출되는 API 함수를 후킹하는것을        
        
API Hooking 이라고 함. 어디에 어떻게 쓰이느냐. 사람마다 응용하기 나름인데 디버깅 관점에서 보면         
API 함수로 호출되는 파라메터의 값을 뿌려줄 수도 있고,        
리버싱에서 보면 중간에 추가적인 기능을 다른 프로그램에 삽입할 수 있다는 것.        
        
전체적인 구조를 보면 MessageBox 가 호출이 되면 my.dll 에 있는 MyMessageBox 가 호출 되고         
MyMessageBox 의 형태는         
MyMessageBox { 내가 조작해야될 명령들, ..., call kernel32!MessageBox }         
같은 형태가 될거고         
MyMessageBox 가 리턴되면서 원래 있던 프로그램으로 입싹 닦고 유유히 사라지는거죠.        
        
API Hooking 하는 방법은 여러가지 방법이 있지만 저는 일반적인 방법인         
실행중인 프로세스의  DLL Injection 을 이용하여 Import Table 을 조작해 API Hooking 을 해보려고 합니다.         
        
다음 글에서는 기본적인 API Hooking 은 제외한 DLL injection 하는데 까지만 해보겠습니다.
:

라인 트레이서 중간 점검

컴퓨터 이야기 2010. 9. 2. 01:54


김창희 - 하드웨어
한경수 - 프로그래밍

        
알디 : 잘가네, 좀 어설프긴 해도        
친구 : 지금 여기서 좀만 다듬으면 되겠다        
알디 : 커브돌 때 좀 더 빨리 돌아야 하나? 빨리 돌면 더 안되지 않나?        
친구 : 그치        
친구 : 이제 길만 외면 된다        
알디 : 건전지잡고 따라가야되는건 쫌..ㅋ        
친구 : 난 이거 최고 마지막은 무선으로 되야한다 전기공급이. 무선으로 된다든데 그게         
알디 : 야 반대방향으로 돌아보자.         
친구 : 아 또 안되노 아 ~        
알디 : 아 왜 이래 어?        
친구 : 건전지 묶있다        
알디 : 어~ 꺼라꺼라 ㅇㅋㅇㅋ        
        
        
부끄러운 목소리        
        
        
        
하드웨어 제어가 생각보다 어렵구나... 소프트웨어만 해서 이런건 생소했음..    
:

MS Visual Studio Macro 에서 h 과 cpp 파일간의 이동

컴퓨터 이야기/C++ 2010. 8. 19. 16:04


매크로를 쓰면 된다(ALT+F11)


Public Module SwitchCHPP
    Sub OpenPartnerFile()
        Dim filename As String
        Dim partnerFilename As String
        filename = DTE.ActiveDocument.FullName
        If (filename.EndsWith(".h")) Then
            partnerFilename = filename.Substring(0, filename.Length() - 2) + ".cpp"
        End If
        If (filename.EndsWith(".cpp")) Then
            partnerFilename = filename.Substring(0, filename.Length() - 4) + ".h"
        End If
        DTE.ItemOperations.OpenFile(partnerFilename)
    End Sub
End Module
그리고 옵션에서 단축키로 등록해서 ALT+O 와 같은 단축키로 등록시켜두면 유용하다.

'컴퓨터 이야기 > C++' 카테고리의 다른 글

Vito's Family  (0) 2011.01.02
Erdos Numbers  (0) 2011.01.01
projecteuler.net : Problem 25  (0) 2010.08.16
API 후킹  (0) 2010.07.19
C++ 의 mutable 키워드를 아시나요?  (0) 2010.07.17
:

projecteuler.net : Problem 25

컴퓨터 이야기/C++ 2010. 8. 16. 05:12


피보나치 수열이 천자리수가 되는 첫번 째 항은 무엇인가? 가 문제인데

음...... 생각 많이 하다가 도저히 안되겠어서 시간이 느리더라도 프로그램으로 구해보려고 했다.

하지만 예상밖으로 1초만에 항을 구할 수 있었고, 답은 4000항 정도쯤.

근데 자리수가 바뀔려면 몇번째 항을 넘어가야 바뀌는걸까 궁금해서 코딩을 해봤다.



BigInteger fibo[] = new BigInteger[10000];
  fibo[1] = new BigInteger("1");
  fibo[2] = new BigInteger("1");
  BigInteger cmp = new BigInteger("1");
  
  for(int j=1; j<=20; j++)
  {
   cmp = new BigInteger("1");
   for(int i=1; i<=j; i++)
    cmp = cmp.multiply(new BigInteger("10"));
   
   
   for(int i=3; i<10000; i++)
   {
    fibo[i] = fibo[i-1].add(fibo[i-2]);
    if(fibo[i].compareTo(cmp) == 1)
    {
     System.out.println(i + "항에서 자리수가 바뀜");
     //System.out.println(fibo[i].toString());
     break;
    }
    
   } 
  }

결과는
7항에서 자리수가 바뀜
12항에서 자리수가 바뀜5
17항에서 자리수가 바뀜5
21항에서 자리수가 바뀜4
26항에서 자리수가 바뀜5
31항에서 자리수가 바뀜5
36항에서 자리수가 바뀜5
40항에서 자리수가 바뀜4
45항에서 자리수가 바뀜5
50항에서 자리수가 바뀜5
55항에서 자리수가 바뀜5
60항에서 자리수가 바뀜5
64항에서 자리수가 바뀜4
69항에서 자리수가 바뀜5
74항에서 자리수가 바뀜5
79항에서 자리수가 바뀜5
84항에서 자리수가 바뀜5
88항에서 자리수가 바뀜4
93항에서 자리수가 바뀜5
98항에서 자리수가 바뀜5

잘 보시라 대부분 4항이나 5항째에서 바뀌는것을 알 수 있다. 왜 그런걸까?

작은 수 뿐만 아니라 큰수에도 똑같이 적용이 되던데, 이건 예외가 있는건가?

또 하나의 규칙을 발견할 수 있다. 바뀔 때 네번혹은 다섯번마다 4의 항간격이 나타난다는 것이다.

이게 사실인가? 사실이면 증명을 어떻게 할까?



'컴퓨터 이야기 > C++' 카테고리의 다른 글

Erdos Numbers  (0) 2011.01.01
MS Visual Studio Macro 에서 h 과 cpp 파일간의 이동  (0) 2010.08.19
API 후킹  (0) 2010.07.19
C++ 의 mutable 키워드를 아시나요?  (0) 2010.07.17
파일 다이얼로그  (0) 2010.07.17
:

어느 정도... 윤곽을 보이네요.

컴퓨터 이야기/Rhythm Nerd 2010. 7. 30. 09:24



필기.txt 의 일부 내용을 가져온다면

판정상의 문제가 있음. 해당 스텝 진행이 아니면 아예 판정이 안뜸.
mp3 재생하는 부분 싱크 맞추기 코드 추가할려면 해야됨.
SIGNLE, DOUBLE 속성 얻어오는데에 LoadKSF 를 쓰고 있는건 낭비임. 고쳐야됨.
RhythmNerd::DrawNotes 여기에 중복되는 코드조각들이 너무 많음
(firsttime < starttime*10 상태에서 배속 조절하면 문제가 발생함. // ok
해당 노트에서 딱 |E4| 하면 걸쳐야ㄷ외는데 몇픽셀 이격됨 // ok
다른 KSF 하다가 다른 KSF 하면 이전거에 영항 받아져있음 static 문제로 보임 // ok
setKSF 하는 부분에서 부터 createTable // 탐닉 완료 ㅋㅋ
drawNote 까지 좀 이상함. 정밀 탐독할 필요가 있음. // 탐닉 완료

음. 일단 어느정도 돌아가네.

변칙적인 KSF 패턴들도 처리가능하고. 흠, 뿌듯;;

'컴퓨터 이야기 > Rhythm Nerd' 카테고리의 다른 글

Rhythm Nerd 인터페이스 구상중.  (0) 2010.07.16
Rhythm Nerd 0.00000001  (0) 2010.07.16
Rhythm Nerd 0.0000000000001  (0) 2010.07.03
:

이스케이프 문자와 기타 반복자

컴퓨터 이야기/정규식 2010. 7. 27. 05:40
Non Greedy repeats

기본적으로 정규식은 greedy 방법을 사용한다. greedy 방법은 가능한한 최대의 입력을 취급한다는 이야기다.
non-greedy 방법은 가능한한 최소의 입력을 받는다.

abcdaXbcdabcdX 와 같은 문자가 있으면
(a.+X).* 로 매치했을 때 abcdaXbcdabcdX 가 매치되지만
아래와 같은
(a.+?X).* 같은 표현으로 매치하면 abcdaX 가 매치된다.
*?
+?

{n,}?

{n,m}?

이까지는 이해가 가는데

?? 라는 표현도 있음.

예를 들어 표현하면

a??c 를 했을 때

abc444ac 라는게 있다면 abc 를 찾는게 아니고 ac 를 찾음

가능한한 짧은걸 찾음.

 

Back references

std::string s("apple banana");
 std::tr1::regex rg("(.+) (.+)");
 s = std::tr1::regex_replace(s,rg,std::string("$2 $1"));
 cout << s << endl;

결과값 : banana apple
매치하면서 썼던 문자집합을 $n 와 같은 표현으로 사용가능.


 

이스케이프 문자 

같은 표현

\d

[0-9]

\l

소문자

\s

모든공백문자

\u

대문자

\w

대소문자와 밑줄을 포함하는 모든 영숫자 [a-zA-Z0-9_] 와 같음

\h

\v

수직 탭

\D

[^0-9] 와 같음

\L

소문자를 제외한 것

\S

공백이 아닌 문자

\U

대문자를 제외한것

\W

[^a-zA-Z0-9_] 와 같음

\H

수평탭을 제외한 것

\V

수직탭을 제외한 것


 

'컴퓨터 이야기 > 정규식' 카테고리의 다른 글

정규식 입문  (1) 2010.06.21
정규식 ( Regular Expression ) 소개  (0) 2010.06.20
:

YOU JUST ACTIVATED MY TRAP CARD

컴퓨터 이야기 2010. 7. 22. 00:32

프로그램 버전ㅋㅋ


:

KSF Creator2 1.3 final

컴퓨터 이야기/KSF Creator2 2010. 7. 20. 01:30
군 입대를 시작으로 사실상 손을 못대게 된 프로젝트 ..

지금이야 언제든지 손대는게 가능하지만 별다른 요청이 들어오지 않아서 방치중.

:

API 후킹

컴퓨터 이야기/C++ 2010. 7. 19. 02:53
API 후킹이 뭐냐면, 말 그대로 다른 프로그램이 특정 API 를 호출할 때 낚아채는 기법을 말함

아래 void main() 에서 핸들값을 적절한 다른 값으로 바꾸세요.

아래 소스 방법은 Dll Injection 임. 메모리에 로드된 import table 을 바꿔치기 해서 내가 원하는 dll 을 호출하게 만듬.
#include <iostream>
#include <windows.h>

// DLL Inject : 다른 프로세스의 주소 공간에 특정 DLL을 넣는다.
void DllInject(DWORD pid, char* path)
{
        HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);

        // 내 프로세스에 있는 KERNEL32.DLL의 주소와 LoadLibrary의 주소를 구한다.
        HMODULE hDll = GetModuleHandle("kernel32.dll"); // kernel32.dll 모듈의 핸들값을 GetModuleHandle로 구한다.
        PTHREAD_START_ROUTINE f = (PTHREAD_START_ROUTINE)GetProcAddress(hDll, "LoadLibraryA");


        // 계산기의 주소공간에 메모리를 할당하고, DLL의 경로를 복사해준다.
        // VirtualAlloc은 가상 메모리를 할당하는 API이지만, Ex가 붙으면 다른 프로세스의 주소공간을 할당할 수 있다.
        void* p = VirtualAllocEx(hProcess, 0, // 원하는 주소(0은 알아서 해달라)
                strlen(path)+1, // 크기
                MEM_RESERVE | MEM_COMMIT, // 예약과 동시 확정
                PAGE_READWRITE);

        // 이제 DLL의 경로를 담을 문자열 복사
        // WriteProcessMemory()는 다른 프로세스 주소 공간에 무언가를 쓸 수 있다.
        DWORD len;
        WriteProcessMemory(hProcess, p, path, strlen(path)+1, &amp;len);

        // 계산기에 새로운 스레드를 만든다.
        // CreateRemoteThread는 다른 프로세스에 스레드를 생성시킨다.
        HANDLE hThread = CreateRemoteThread(hProcess, // 계산기 핸들
                0, 0, 
                f, p, // 함수, 파리미터
                0, 0);


        CloseHandle(hThread);
        CloseHandle(hProcess);
}

void main()
{
        using namespace std;
        HWND hwnd = (HWND)0x0005115A;
        DWORD pid;
        DWORD tid = GetWindowThreadProcessId(hwnd, &amp;pid);
        DllInject(pid, "C:\\spy1.dll");
}
[DLL]
#include <urlmon.h>
#include <iostream>
#include <commctrl.h>
#include<windows.h>
#include<dbghelp.h>
#include<stdio.h>
#pragma comment(lib,"dbghelp.lib")



// Repalce 부분..

void Replace( char *dll_name,                          // dll 이름

                                         PROC proc,             // hooking 할 함수

                                         PROC new_proc,     // 새로운 함수

                                         HMODULE hMod)     // .idata 섹션을 조사할 모듈 핸들

                                                                         // (exe 주소)

{

             // hMod 주소에서 .idata의 위치를 찾는다.

             ULONG sz;

             PIMAGE_IMPORT_DESCRIPTOR pImport = (PIMAGE_IMPORT_DESCRIPTOR)

                        ImageDirectoryEntryToDatahMod, 

                        TRUE,IMAGE_DIRECTORY_ENTRY_IMPORT,       // IMPORT하고 있는 곳

                         &amp;sz);



             if(pImport==0)                // .idata section이 없는 경우.

                          return;



             //===================================================

             // .idata에서 원하는 dll의 위치를 찾는다.

             for(;pImport-&gt;Name;++pImport)

             {

                          char* p = (char*)hMod+pImport-&gt;Name;



                          if(strcmpi(p,dll_name)==0)                   // 찾은 경우

                                       break;

             }

             if(pImport-&gt;Name==0)             return; // .idata항목에 해당하는 DLL이 없다.

             //====================================================

             // thunktable에서 원하는 함수를 찾아서 바꾸어 쓴다.

             PIMAGE_THUNK_DATA pThunk=(PIMAGE_THUNK_DATA)

             ((char*)hMod+pImport-&gt;FirstThunk);



             

             for(;pThunk-&gt;u1.Function;++pThunk)

             {

                          PROC* pf=(PROC*)&amp;(pThunk-&gt;u1.Function);



                          if(*pf==proc)                // 찾은 경우.

                          {

                                       *pf=new_proc;              // 덮어쓴다.

                          }

             }

}



// MessageBoxW를 대신할 함수

UINT WINAPI foo(HWND hwnd,PCWSTR s,PCWSTR title,UINT btn)

{

             // Console 참을 생성해서 출력해준다.



             AllocConsole();



             freopen("CONOUT$","wt",stdout);



             printf("Messagebox 호출");



             return 0;

}



BOOL WINAPI DllMain(HANDLE h,DWORD r,void*p)

{

             if(r==DLL_PROCESS_ATTACH)

             {

                          Replace("User32.dll",

                                       (PROC)MessageBoxA,

                                       (PROC)foo,

                                       GetModuleHandle(0));

             }

             return TRUE;

}



:

Reverse Engineering 카테고리 열었어요.

컴퓨터 이야기/Reverse Engineering 2010. 7. 18. 19:52

Reverse Engineering 이 뭐냐면...

소프트웨어 공학중에 하난데 이미 만들어진 프로그램을 역으로 풀어서 어떤 원리로 작동되는지 탐구하고 분석하는것을 말함.

순수한 학술 목적으로 발전할 수도 있지만 음지의 기술쪽으로 발달하면 흔히 말하는 크랙이나 키젠을 만들어내는쪽으로도 나올 수 있음.

주로 C/C++ 등으로 만든 Native Code 를 어셈블리어로 번역한 후 디버깅을 하면서 프로그램을 들여다 보는 쪽으로 나가지 않을까 생각중.

여러분 관심 있나요? ㅋㅋ 저도 잘 모르지만 잘해볼게요.

한 때 관심을 가지고 깔짝였는데 아마 깊이 있는 내용은 쓰지 못할거에요.
: