posted by 방랑군 2012. 1. 22. 22:36

출처 :  http://jok3.tistory.com/27 


역분석을 하다보면 api함수로 찾아줄때가 많은데 자주쓰이는 함수들을 정리해 봤습니다.
첨부파일은 원하는 함수를쓰면 그함수의 쓰임세가 설명되있는 도움말파일이라고 보시면 됩니다.





-파일 생성 & 열때.
16-bit : CreateFile
32-bit : CreateFileA
wide : CreateFileW


-파일 입출력(Read&Write)
ReadFile : 읽기
WriteFile : 쓰기

-파일 접근(Access)
SetFilePointer : 포인터 조정

-시스템 디렉토리 얻어오는 함수
16-bit : GetSystemDirectory
32-bit : GetSystemDirectoryA
wide : GetSystemDirectoryW


-.ini 구성설정에 관련된 함수들
16-bit : GetPrivateProfileString
GetPrivateProfileInt
WritePrivateProfileString
WritePrivateProfileInt
32-bit : GetPrivateProfileStringA
GetPrivateProfileIntA
WritePrivateProfileStringA
WritePrivateProfileIntA
wide : GetPrivateProfileStringW
GetPrivateProfileIntW
WritePrivateProfileStringW
WritePrivateProfileIntW

-레지스트리의 키를 생성 혹은 삭제할때
16-bit : RegCreateKey
RegDeleteKey
32-bit : RegCreateKeyA
RegDeleteKeyA
wide : RegCreateKeyW
RegDeleteKeyW

-현재 열려진 레지스트리 키를 읽을때
16-bit : RegQueryValue
32-bit : RegQueryValueA
wide : RegQueryValueW

-레지스트리 키를 열때
16-bit : RegCloseKey
RegOpenKey
32-bit : RegCloseKeyA
RegOpenKeyA
wide : RegCloseKeyW
RegOpenKeyW

-객체에서 문자열을 읽을때
16-bit : GetWindowText
GetDlgItemText
32-bit : GetWindowTextA
GetDlgItemTextA

wide : GetWindowTextW
GetDlgItemTextW

-정수여부 상관
GetDlgItemInt

-객체의 텍스트를 지정
16-bit : SetWindowText
SetDlgItemText
32-bit : SetWindowTextA
SetDlgItemTextA
wide : SetWindowTextW
SetDlgItemTextW


-메시지 박스
16bit : MessageBox
MessageBeep
32bit : MessageBoxA
MessageBoxExA
wide : MessageBoxW
MessageBoxExW

-메시지 관련
16bit : SendMessage
WSPRINTF
32bit :SendMessageA
wide : SendMessageW

-날짜와 시간을 구할때
GetSystemTime
GetLocalTime
SystemTimeToFileTime


-창을 생성 & 제거할때
16bit : CreateWindow
CreateWindowEx
DialogBoxParam
DestroyWindow
EndDialog
showwindow
bitblt
32bit : CreateWindowA
CreateWindowExA
DialogBoxParamA
wide : CreateWindowW
CreateWindowExW
DialogBoxParamW


-CD롬을 요구하는 함수 들
16bit : GetDriveType (만약 eax=5 라면 CD롬 체크 이다.)
GetLogicalDrives
GetLogicalDriveStrings
32bit : GetDriveTypeA
GetLogicalDrivesA
GetLogicalDriveStringsA
wide : GetDriveTypeW

-리턴 코드:
값 설명
0 Drive Cannot Be determined
1 Root Dir Does not exist
2 DriveRemoveable
3 A Fixed Disk (HardDrive)
4 Remote Drive(Network)
5 Cd-Rom Drive <==============
6 RamDisk

GetLogicalDrivesW
GetLogicalDriveStringsW

-Win NumberSerial:
GETWINDOWWORD
GETWINDOWLONG

+ORC가 제안한 훌륭한 함수
BOZOSLIVEHERE
HMEMCPY
GLOBALGETATOMNAME
posted by 방랑군 2012. 1. 22. 20:13
출처 :   http://blog.naver.com/alfustnals?Redirect=Log&logNo=140140341010 

 global 컨텍스트 키워드 :: 연산자

 global 컨텍스트 키워드 :: 연산자

 1] 모든 C# 프로그램의 기본 네임스페이스

 2] 다른 경우 ==> 명명되지 않는 전역 네임스페이스를 가리킵니다

 3] 네임스페이스 별칭 한정자는 global 일 수 있다. 

   ==> 전역 네임스페이스에서 조회가 실행

:: ==> 네임스페이스 별칭 한정자

 식별자를 조회하는 데 사용

 ==> 두개의 식별자 사이에 온다.

사용이유

MSDN : http://msdn.microsoft.com/ 

System이라는 자체 네임스페이스는 만들지 않는 것이 좋으며, 이러한 네임스페이스를 만드는 코드는 거의 찾아볼 수 없습니다. 그러나 보다 큰 프로젝트에서는 여러 가지 형태의 네임스페이스 중복이 발생할 수 있습니다. 이러한 경우 전역 네임스페이스 한정자를 사용하면 확실하게 루트 네임스페이스를 지정할 수 있습니다.

예제

      MSDN 참조 : http://msdn.microsoft.com/ko-kr/library/c3ay4x3d(VS.90).aspx

------------------------------------------------------------------------------- 

using colAlias = System.Collections;
namespace System
{
    class TestClass
    {
        static void Main()
        {
            colAlias::Hashtable test = new colAlias::Hashtable();
            

            test.Add("A""1");
            test.Add("B""2");
            test.Add("C""3");


            foreach (string name in test.Keys)
            {
              global::System.Console.WriteLine(name + " " + test[name]);
            }
        }
    }
}

  
posted by 방랑군 2012. 1. 22. 00:14

1. byte[] 배열 합치기

C의 유연함에 익숙한 사용자는 갑갑할 수 밖에 없다. System.Array의 인스턴스는 특정 위치부터 배열을 복사하는 기능을 제공하지 않는데, 인터넷을 뒤져보니 그냥 for 루프로 돌리는 사람도 있고, CopyTo() 메서드를 잘못 이해해서 틀린 정보를 제공하는 사람도 있고 가지가지다.

 

<Array.CopyTo() 메서드의 틀린 사용 예>

byte[] a= new byte[3]{1,2,3};

byte[] b= new byte[4]{4,5,6,7};

byte[] c= byte[a.Length+b.Length];

a.CopyTo(c,0);

b.CopyTo(c,a.Length); 

 

 얼핏 보면 올바른 코드로 보이지만, CopyTo의 두 번째 인자는 목적 배열의 인덱스가 아니라 소스 배열의 인덱스라는데 이 코드의 치명적인 오류가 있다.

 즉, 위의 코드에의 결과는 c={7,2,3} 이 되어 버린다.

 

결론은 Array.Copy() 메서드를 사용한다.

 

위 코드는 아래처럼 바꾸면 된다.

Array.Copy(a, 0, c, 0, a.Length);

Array.Copy(b, 0, c, a.Length,b.Length);

 

2. htonl, ltons 소켓라이브러리 함수와 같은 기능을 하는 .NET 라이브러리는?

System.Net.IPAddress.HostToNetworkOrder()

System.Net.IPAddress.NetworkToHostOrder()

 

3. int, short 같은 정수를 byte[]으로 상호 변환하려면?

System.BitConverter의 메서드를 사용한다.

 

System.BitConverter.ToInt32(packet, 0);

 

4. 비동기 메서드 BeginXXX(), EndXXX()를 사용할 때 윈폼 컨트롤에 접근하는 코드는?

 비동기 메서드 BeginReceive, EndReceive 등을 사용할 때 EndReceive 에서는 AsyncCallback 개체를 사용하여 별도의 스레드에서 데이터를 수신하게 되는데, 이 스레드에서는 윈폼 컨트롤로 바로 출력할 수 없다. 이 때는 윈폼의 Invoke 메서드를 사용한다.

 

 Invoke의 첫 번째 인자는 Delegate이고 두 번째 인자는 관련된 변수이다. 아래는  EndReceive에서 byte[]형 데이터를 수신해서 ReceivedData 라는 사용자 이벤트를 발생했을 경우의 예이다.

        delegate void VerbosePrinter(string msg);

        void PrintText(string s)
        {
            txtOut.AppendText(s + "\r\n");
            txtOut.ScrollToCaret();
        }
        void p(string s)
        {
            this.Invoke(new VerbosePrinter(PrintText), s);
        }

        void cli_ReceivedData(object sender, byte[] bytes)
        {

               p(Encoding.Default.GetString(bytes);
        }