๋ชฉ๋ก์ ์ฒด ๊ธ (1103)
KoreanFoodie's Study

'๋ฆฌ๋ฒ์ฑ ํต์ฌ ์๋ฆฌ'์ ๋ด์ฉ ๋ฐ ์ด์๋ค๊ณผ ํด๊ฒฐ์ฑ ์ ๋ค๋ฃน๋๋ค. ์คํ ํ๋ก์ธ์ค์์ ์คํ ๋ฉ๋ชจ๋ฆฌ์ ์ญํ ์ ์๋์ ๊ฐ๋ค. A. ํจ์ ๋ด์ ๋ก์ปฌ ๋ณ์ ์์ ์ ์ฅ B. ํจ์ ํธ์ถ ์ ํ๋ผ๋ฏธํฐ ์ ๋ฌ C. ๋ณต๊ท ์ฃผ์(return address)์ ์ฅ ํ๋ก์ธ์ค์์ ์คํ ํฌ์ธํฐ(ESP)์ ์ด๊ธฐ ๊ฐ์ Stack Bottom์ชฝ(๊ทธ๋ฆผ ์๋์ชฝ)์ ๊ฐ๊น๋ค. PUSH ๋ช ๋ น์ผ๋ก ์คํ์ ๊ฐ์ ์ ๋ ฅํ๋ฉด ์คํ ํฌ์ธํฐ(ESP)๋ ๊ฐ์ํ๊ณ , POP ๋ช ๋ น์ผ๋ก ์คํ์์ ๊ฐ์ ๊บผ๋ด๋ฉด ์คํํฌ์ธํฐ๋ ์ฆ๊ฐํ๋ค. ์ฆ, ์คํ์ ๊ฑฐ๊พธ๋ก ์๋๋ค! POP EBP ๋ฅผ ํ๋ฉด EBP ๊ฐ์ด ๋ณํ๋๋ฐ, PUSH ์ ๊ฒฝ์ฐ์๋ PUSH EBP ๋ช ๋ น์ด๋ฅผ ์คํํด๋, ํ์ฌ์ EBP ๊ฐ(์: 0019FF38) ๊ฐ๋ง ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ๋์ง EBP ์์ฒด์ ๊ฐ์ ๋ฐ๋์ง ์๋๋ค. POP EBP ..

'๋ฆฌ๋ฒ์ฑ ํต์ฌ ์๋ฆฌ'์ ๋ด์ฉ ๋ฐ ์ด์๋ค๊ณผ ํด๊ฒฐ์ฑ ์ ๋ค๋ฃน๋๋ค. 1. CPU ๋ ์ง์คํฐ๋? ๋ ์ง์คํฐ(Register)๋ CPU ๋ด๋ถ์ ์กด์ฌํ๋ ๋ค๋ชฉ์ ์ ์ฅ ๊ณต๊ฐ์ด๋ค. ์ฐ๋ฆฌ๊ฐ ์ผ๋ฐ์ ์ผ๋ก ๋ฉ๋ชจ๋ฆฌ๋ผ๊ณ ์๊ธฐํ๋ RAM(Random Access Memory)๊ณผ๋ ์กฐ๊ธ ์ฑ๊ฒฉ์ด ๋ค๋ฅด๋ค. CPU๊ฐ RAM์ ์๋ ๋ฐ์ดํฐ๋ฅผ ์์ธ์ค(Access)ํ๊ธฐ ์ํด์๋ ๋ฌผ๋ฆฌ์ ์ผ๋ก ๋จผ ๊ธธ์ ๋์๊ฐ์ผ ํ๊ธฐ ๋๋ฌธ์ ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆฐ๋ค. ํ์ง๋ง ๋ ์ง์คํฐ๋ CPU์ ํ ๋ชธ์ด๊ธฐ ๋๋ฌธ์ ๊ณ ์์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํ ์ ์๋ค. ๋ ์ง์คํฐ์ ์ข ๋ฅ Basic program execution registers x87 FPU registers MMX registers XMM registers Control registers Memory management regis..

'๋ฆฌ๋ฒ์ฑ ํต์ฌ ์๋ฆฌ'์ ๋ด์ฉ ๋ฐ ์ด์๋ค๊ณผ ํด๊ฒฐ์ฑ ์ ๋ค๋ฃน๋๋ค. ๋ฐ์ดํธ ์ค๋๋ง : ๋ฐ์ดํธ ์ค๋๋ง์ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ๋ฐฉ์์ด๋ผ๊ณ ๊ธฐ์ตํ๋ฉด ๋๋ค. ํฌ๊ฒ ๋ ๊ฐ์ง๋ก, ๋น ์๋์ธ(Big Endian)๊ณผ ๋ฆฌํ ์๋์ธ(Little Endian)๋ฐฉ์์ด ์๋ค! TYPE | Name | SIZE | ๋ฐ์ดํฐ | ๋น ์๋์ธ Style | ๋ฆฌํ ์๋์ธ Style |:----|:----|:----|:----|:----|:-----| BYTE | b | 1 | 0x12; | [12] | [12] WORD | w | 2 | 0x1234; | [12][34] | [34][12] DWORD | dw | 4 | 0x12345678 | [12][34][56][78] | [78][56][34][12] char [] | str | 6 | "ab..

'๋ฆฌ๋ฒ์ฑ ํต์ฌ ์๋ฆฌ'์ ๋ด์ฉ ๋ฐ ์ด์๋ค๊ณผ ํด๊ฒฐ์ฑ ์ ๋ค๋ฃน๋๋ค. 1. EP(Entry Point) EP(Entry Point)๋ Windows ์คํ ํ์ผ (EXE, DLL, SYS๋ฑ)์ ์ฝ๋ ์์์ ์ ์๋ฏธํ๋ค. ํ๋ก๊ทธ๋จ์ด ์คํ๋ ๋ CPU์ ์ํด ๊ฐ์ฅ ๋จผ์ ์คํ๋๋ ์ฝ๋ ์์ ์์ฐจ๋ผ๊ณ ์๊ฐํ๋ฉด ๋๋ค. 2. ๋๋ฒ๊ฑฐ ๋ช ๋ น์ด ๋ช ๋ น์ด |๋จ์ถํค |์ค๋ช |:------|:-------|:------| Go to | [Ctrl+G] | ์ํ๋ ์ฃผ์๋ก ์ด๋(์ฝ๋/๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ์ธํ ๋ ์ฌ์ฉ. ์คํ๋๋ ๊ฒ์ ์๋) Execute till Cursor | [F4] | cursor ์์น๊น์ง ์คํ (๋๋ฒ๊น ํ๊ณ ์ถ์ ์ฃผ์๊น์ง ๋ฐ๋ก ๊ฐ ์ ์์) Set/Reset Breakpoint | [F2] | BP ์ค์ / ํด์ Run | [F9..

'๋ฆฌ๋ฒ์ค ์์ง๋์ด๋ง ๋ฐ์ด๋ธ'์ ํต์ฌ ๋ด์ฉ ๋ฐ ์ด์๋ค๊ณผ ํด๊ฒฐ์ฑ ์ ๋ค๋ฃน๋๋ค. Windows programming ๋ง๋ณด๊ธฐ #include #include #include void RunPorcess() { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); //start the child process. if (!CreateProcess(NULL, "MyChildProcess", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) ) { printf("CreateProcess failed.\n"); return; } // Wa..

C ์ธ์ด๋ก ์ด์ ๋ธ๋ฆฌ ์ฌ์ฉํด ๋ณด๊ธฐ! ์ด์ ๋ธ๋ฆฌ๋ก ๋ ๋ณ์์ ๊ฐ์ ๋ํ๋ ์ฝ๋๋ฅผ ์ง ๋ณด์! #include #include int Plus(int a, int b) { return a +b; } _declspec(naked) PlusAsm(int a, int b) { _asm { mov ebx, dword ptr ss:[esp+8] mov edx, dword ptr ss:[esp+4] add edx, ebx mov eax, edx retn }; } void main(int argc, char *argv[]) { int value = Plus(3, 4); printf("value: %d\n", value); int value2 = PlusAsm(3,4); printf("value2: %d\n", value2);..

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala์ Abstract class์ ๋ํด ์์๋ณด์ Abstract Class: Specification Abstract Classes can be used to abstract away the implementation details. In short, abstract classes is used for specfication, and concrete sub-classes for implementation. Example: Abstract case for specification abstract class Iter[A] { def getValue: Option[A] def getNext: Iter[A] } def sumElements[A](f: A=>Int)(xs: Iter[A])..

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala์ class์ ๋ํด ์์๋ณด์ Class: Parameterized Record object gee { val a : Int = 10 def b : Int = a + 20 def f(z: Int) : Int = b + 20 + z } type gee_type = {val a:Int; def b: Int; def f(z:Int): Int} class foo_type(x: Int, y: Int) { val a : Int = x def b : Int = a + y def f(z: Int) : Int = b + y + z } val foo : foo_type = new foo_type(10,20) If you define class, new type is made. The name r..

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala์ sub types์ ๋ํด ์์๋ณด์ Sub Type Polymorphism (Concept) Let's assume that we want this: object tom { val name = "Tom" val home = "02-880-1234" } object bob { val name = "Bob" val home = "02-123-1234" } def greeting(r: ???) = "Hi " + r.name + ", How are you?" greeting(tom) greeting(bob) // Note that we have tom: {val name: String; val home: String} bob: {val name: String; val mobile: ..

์ค์นผ๋ผ ํํ ๋ฆฌ์ผ, scala์ parametric polymophism์ ๋ํด ์์๋ณด์ Parametric Polymorphism: Functions Problem def id1(x: Int): Int = x def id2(x: Double): Double = x Can we avoid DRY(Do not Reapeat Yourself)? Parametric Polymorphism(a.k.a. For-all Types) def id[A](x: A): A = x // type for definition val f = (x:Int) => x // type for value The type of id is [A](x: A)A. id is a parametric expression. Only definition..