├── .gitignore
├── Boot
├── boot.asm
├── boot.vcxproj
└── main.cpp
├── GuestOS
├── GuestOS.vcxproj
├── GuestOS.vcxproj.filters
├── Shellcode.cpp
├── Shellcode.h
├── boot.asm
├── cpu.cpp
├── cpu.h
├── gdt.cpp
├── gdt.h
├── idt.cpp
├── idt.h
├── kernel.cpp
├── msr-index.h
├── os.h
├── paging.cpp
├── paging.h
├── trap.cpp
├── trap.h
├── tss.cpp
├── tss.h
├── video.cpp
└── video.h
├── README.md
├── ShellcodeVM.VC.db
├── ShellcodeVM.sln
├── ShellcodeVM
├── HAXM.h
├── HAXM_CPU.h
├── HAXM_VM.h
├── HaxVM.cpp
├── HaxVM.h
├── HaxmTest.cpp
├── HaxmTest.vcxproj
├── HaxmTest.vcxproj.filters
├── ShellcodeVM.vcxproj
├── ShellcodeVM.vcxproj.filters
├── VM.cpp
├── VM.h
├── VM
│ ├── page_frame.cpp
│ ├── page_frame.h
│ ├── paging.cpp
│ └── paging.h
├── VMCS.h
├── VirtualCPU.cpp
├── VirtualCPU.h
├── VirtualContext.cpp
├── VirtualContext.h
├── VirtualIO.cpp
├── WinMiniDump.cpp
├── WinMiniDump.h
├── config.h
├── hax-all.h
├── hax-i386.h
├── hax-interface.h
├── hax-windows.c
├── hax-windows.h
├── main.cpp
├── msr.h
├── stdafx.cpp
├── stdafx.h
├── target-i386
│ ├── TODO
│ ├── cc_helper.c
│ ├── cc_helper_template.h
│ ├── cpu-qom.h
│ ├── cpu.h
│ ├── excp_helper.c
│ ├── fpu_helper.c
│ ├── hax-all.c
│ ├── hax-darwin.c
│ ├── hax-darwin.h
│ ├── hax-i386.h
│ ├── hax-interface.h
│ ├── hax-windows.c
│ ├── hax-windows.h
│ ├── helper.c
│ ├── helper.h
│ ├── int_helper.c
│ ├── kvm-gs-restore.c
│ ├── kvm-gs-restore.h
│ ├── kvm.c
│ ├── machine.c
│ ├── mem_helper.c
│ ├── misc_helper.c
│ ├── ops_sse.h
│ ├── ops_sse_header.h
│ ├── seg_helper.c
│ ├── shift_helper_template.h
│ ├── smm_helper.c
│ ├── svm.h
│ ├── svm_helper.c
│ └── translate.c
└── vcpu.h
├── nasm
├── nasm.exe
└── ndisasm.exe
└── 同步文档.docx
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studo 2015 cache/options directory
26 | .vs/
27 |
28 | # MSTest test Results
29 | [Tt]est[Rr]esult*/
30 | [Bb]uild[Ll]og.*
31 |
32 | # NUNIT
33 | *.VisualState.xml
34 | TestResult.xml
35 |
36 | # Build Results of an ATL Project
37 | [Dd]ebugPS/
38 | [Rr]eleasePS/
39 | dlldata.c
40 |
41 | *_i.c
42 | *_p.c
43 | *_i.h
44 | *.ilk
45 | *.meta
46 | *.obj
47 | *.pch
48 | *.pdb
49 | *.pgc
50 | *.pgd
51 | *.rsp
52 | *.sbr
53 | *.tlb
54 | *.tli
55 | *.tlh
56 | *.tmp
57 | *.tmp_proj
58 | *.log
59 | *.vspscc
60 | *.vssscc
61 | .builds
62 | *.pidb
63 | *.svclog
64 | *.scc
65 |
66 | # Chutzpah Test files
67 | _Chutzpah*
68 |
69 | # Visual C++ cache files
70 | ipch/
71 | *.aps
72 | *.ncb
73 | *.opensdf
74 | *.sdf
75 | *.cachefile
76 |
77 | # Visual Studio profiler
78 | *.psess
79 | *.vsp
80 | *.vspx
81 |
82 | # TFS 2012 Local Workspace
83 | $tf/
84 |
85 | # Guidance Automation Toolkit
86 | *.gpState
87 |
88 | # ReSharper is a .NET coding add-in
89 | _ReSharper*/
90 | *.[Rr]e[Ss]harper
91 | *.DotSettings.user
92 |
93 | # JustCode is a .NET coding addin-in
94 | .JustCode
95 |
96 | # TeamCity is a build add-in
97 | _TeamCity*
98 |
99 | # DotCover is a Code Coverage Tool
100 | *.dotCover
101 |
102 | # NCrunch
103 | _NCrunch_*
104 | .*crunch*.local.xml
105 |
106 | # MightyMoose
107 | *.mm.*
108 | AutoTest.Net/
109 |
110 | # Web workbench (sass)
111 | .sass-cache/
112 |
113 | # Installshield output folder
114 | [Ee]xpress/
115 |
116 | # DocProject is a documentation generator add-in
117 | DocProject/buildhelp/
118 | DocProject/Help/*.HxT
119 | DocProject/Help/*.HxC
120 | DocProject/Help/*.hhc
121 | DocProject/Help/*.hhk
122 | DocProject/Help/*.hhp
123 | DocProject/Help/Html2
124 | DocProject/Help/html
125 |
126 | # Click-Once directory
127 | publish/
128 |
129 | # Publish Web Output
130 | *.[Pp]ublish.xml
131 | *.azurePubxml
132 | # TODO: Comment the next line if you want to checkin your web deploy settings
133 | # but database connection strings (with potential passwords) will be unencrypted
134 | *.pubxml
135 | *.publishproj
136 |
137 | # NuGet Packages
138 | *.nupkg
139 | # The packages folder can be ignored because of Package Restore
140 | **/packages/*
141 | # except build/, which is used as an MSBuild target.
142 | !**/packages/build/
143 | # Uncomment if necessary however generally it will be regenerated when needed
144 | #!**/packages/repositories.config
145 |
146 | # Windows Azure Build Output
147 | csx/
148 | *.build.csdef
149 |
150 | # Windows Store app package directory
151 | AppPackages/
152 |
153 | # Others
154 | *.[Cc]ache
155 | ClientBin/
156 | [Ss]tyle[Cc]op.*
157 | ~$*
158 | *~
159 | *.dbmdl
160 | *.dbproj.schemaview
161 | *.pfx
162 | *.publishsettings
163 | node_modules/
164 | bower_components/
165 |
166 | # RIA/Silverlight projects
167 | Generated_Code/
168 |
169 | # Backup & report files from converting an old project file
170 | # to a newer Visual Studio version. Backup files are not needed,
171 | # because we have git ;-)
172 | _UpgradeReport_Files/
173 | Backup*/
174 | UpgradeLog*.XML
175 | UpgradeLog*.htm
176 |
177 | # SQL Server files
178 | *.mdf
179 | *.ldf
180 |
181 | # Business Intelligence projects
182 | *.rdl.data
183 | *.bim.layout
184 | *.bim_*.settings
185 |
186 | # Microsoft Fakes
187 | FakesAssemblies/
188 |
189 | # Node.js Tools for Visual Studio
190 | .ntvs_analysis.dat
191 |
192 | # Visual Studio 6 build log
193 | *.plg
194 |
195 | # Visual Studio 6 workspace options file
196 | *.opt
197 | /ShellcodeVM/MiniDump.Dmp
198 |
--------------------------------------------------------------------------------
/Boot/boot.asm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/Boot/boot.asm
--------------------------------------------------------------------------------
/Boot/boot.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {77EB0E19-AA23-415C-B34B-8BDCD4CD495D}
23 | GuestOS
24 | 8.1
25 |
26 |
27 |
28 | Application
29 | true
30 | v140
31 | MultiByte
32 |
33 |
34 | Application
35 | false
36 | v140
37 | true
38 | MultiByte
39 |
40 |
41 | Application
42 | true
43 | v140
44 | MultiByte
45 |
46 |
47 | Application
48 | false
49 | v140
50 | true
51 | MultiByte
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | false
73 |
74 |
75 | false
76 |
77 |
78 |
79 | Level3
80 | Disabled
81 | true
82 | false
83 | false
84 | false
85 | NoExtensions
86 | Default
87 | E:\GitHub\ShellcodeOS\libc;E:\GitHub\ShellcodeVM\GuestOS;
88 |
89 |
90 | true
91 | Native
92 | boot_code16
93 | 0x0010000
94 | true
95 | Driver
96 | E:\GitHub\ShellcodeOS\Release\oslibc.lib
97 | true
98 | /filealign:0x1000 %(AdditionalOptions)
99 |
100 |
101 |
102 |
103 | Level3
104 | Disabled
105 | true
106 |
107 |
108 | true
109 |
110 |
111 |
112 |
113 | Level3
114 | MaxSpeed
115 | true
116 | true
117 | true
118 | false
119 | false
120 | E:\GitHub\ShellcodeOS\libc;E:\GitHub\ShellcodeVM\GuestOS;
121 | NoExtensions
122 |
123 |
124 | true
125 | true
126 | true
127 | E:\GitHub\ShellcodeOS\Release\oslibc.lib
128 | true
129 | boot_code16
130 | 0x0010000
131 | true
132 | false
133 | Native
134 | Driver
135 | /filealign:0x1000 %(AdditionalOptions)
136 |
137 |
138 |
139 |
140 | Level3
141 | MaxSpeed
142 | true
143 | true
144 | true
145 |
146 |
147 | true
148 | true
149 | true
150 |
151 |
152 |
153 |
154 | Document
155 | ..\nasm\nasm.exe -f win32 ./boot.asm -o $(Configuration)\boot.obj
156 | $(Configuration)\boot.obj
157 | ..\nasm\nasm.exe -f win64 ./boot.asm -o $(Configuration)\boot.obj
158 | $(Configuration)\boot.obj
159 | $(Configuration)\boot.obj
160 | ..\nasm\nasm.exe -f win64 ./boot.asm -o $(Configuration)\boot.obj
161 | $(Configuration)\boot.obj
162 | ..\nasm\nasm.exe -f win32 ./boot.asm -o $(Configuration)\boot.obj
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
--------------------------------------------------------------------------------
/Boot/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/Boot/main.cpp
--------------------------------------------------------------------------------
/GuestOS/GuestOS.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {70B6C809-92DB-4C09-8E45-C6ED3256412B}
23 | GuestOS
24 | 8.1
25 |
26 |
27 |
28 | Application
29 | true
30 | v140
31 | MultiByte
32 |
33 |
34 | Application
35 | false
36 | v140
37 | true
38 | MultiByte
39 |
40 |
41 | Application
42 | true
43 | v140
44 | MultiByte
45 |
46 |
47 | Application
48 | false
49 | v140
50 | true
51 | MultiByte
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | false
73 |
74 |
75 | false
76 |
77 |
78 |
79 | Level3
80 | Disabled
81 | true
82 | false
83 | false
84 | false
85 | NoExtensions
86 | Default
87 | E:\GitHub\ShellcodeOS\libc;E:\GitHub\ShellcodeVM\GuestOS;
88 |
89 |
90 | true
91 | Native
92 | main
93 | 0x80000000
94 | true
95 | Driver
96 | E:\GitHub\ShellcodeOS\Release\oslibc.lib
97 | true
98 | /filealign:0x1000 %(AdditionalOptions)
99 |
100 |
101 |
102 |
103 | Level3
104 | Disabled
105 | true
106 |
107 |
108 | true
109 |
110 |
111 |
112 |
113 | Level3
114 | MaxSpeed
115 | true
116 | true
117 | true
118 | false
119 | false
120 | E:\GitHub\ShellcodeOS\libc;E:\GitHub\ShellcodeVM\GuestOS;
121 |
122 |
123 | true
124 | true
125 | true
126 | E:\GitHub\ShellcodeOS\Release\oslibc.lib
127 | true
128 | main
129 | 0x80000000
130 | true
131 | false
132 | Native
133 | Driver
134 | /filealign:0x1000 %(AdditionalOptions)
135 | false
136 | true
137 |
138 |
139 |
140 |
141 | Level3
142 | MaxSpeed
143 | true
144 | true
145 | true
146 |
147 |
148 | true
149 | true
150 | true
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
--------------------------------------------------------------------------------
/GuestOS/GuestOS.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | 源文件
20 |
21 |
22 | 源文件
23 |
24 |
25 | 源文件
26 |
27 |
28 | 源文件
29 |
30 |
31 | 源文件
32 |
33 |
34 | 源文件
35 |
36 |
37 | 源文件
38 |
39 |
40 | 源文件
41 |
42 |
43 |
44 |
45 | 头文件
46 |
47 |
48 | 头文件
49 |
50 |
51 | 头文件
52 |
53 |
54 | 头文件
55 |
56 |
57 | 头文件
58 |
59 |
60 | 头文件
61 |
62 |
63 | 头文件
64 |
65 |
66 | 头文件
67 |
68 |
69 |
--------------------------------------------------------------------------------
/GuestOS/Shellcode.cpp:
--------------------------------------------------------------------------------
1 | #include "Shellcode.h"
2 |
3 | Shellcode::Shellcode()
4 | {
5 | }
6 |
7 | Shellcode::~Shellcode()
8 | {
9 | }
10 |
--------------------------------------------------------------------------------
/GuestOS/Shellcode.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/Shellcode.h
--------------------------------------------------------------------------------
/GuestOS/boot.asm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/boot.asm
--------------------------------------------------------------------------------
/GuestOS/cpu.cpp:
--------------------------------------------------------------------------------
1 | #include "cpu.h"
2 | #include "vga.h"
3 | #include "stdio.h"
4 | #include
5 |
6 | char *CPU::table_lookup_model()
7 | {
8 | struct cpu_model_info
9 | {
10 | int vendor;
11 | int family;
12 | char *model_names[16];
13 | };
14 |
15 | static struct cpu_model_info cpu_models[] =
16 | {
17 | { CPU_VENDOR_INTEL, 4,{ "486 DX-25/33", "486 DX-50", "486 SX", "486 DX/2", "486 SL", "486 SX/2", NULL, "486 DX/2-WB", "486 DX/4", "486 DX/4-WB", NULL, NULL, NULL, NULL, NULL, NULL } },
18 | { CPU_VENDOR_INTEL, 5,{ "Pentium 60/66 A-step", "Pentium 60/66", "Pentium 75 - 200", "OverDrive PODP5V83", "Pentium MMX", NULL, NULL, "Mobile Pentium 75 - 200", "Mobile Pentium MMX", NULL, NULL, NULL, NULL, NULL, NULL, NULL } },
19 | { CPU_VENDOR_INTEL, 6,{ "Pentium Pro A-step", "Pentium Pro", NULL, "Pentium II (Klamath)", NULL, "Pentium II (Deschutes)", "Mobile Pentium II", "Pentium III (Katmai)", "Pentium III (Coppermine)", NULL, "Pentium III (Cascades)", NULL, NULL, NULL, NULL } },
20 | { CPU_VENDOR_AMD, 4,{ NULL, NULL, NULL, "486 DX/2", NULL, NULL, NULL, "486 DX/2-WB", "486 DX/4", "486 DX/4-WB", NULL, NULL, NULL, NULL, "Am5x86-WT", "Am5x86-WB" } },
21 | { CPU_VENDOR_AMD, 5,{ "K5/SSA5", "K5", "K5", "K5", NULL, NULL, "K6", "K6", "K6-2", "K6-3", NULL, NULL, NULL, NULL, NULL, NULL } },
22 | { CPU_VENDOR_AMD, 6,{ "Athlon", "Athlon", "Athlon", NULL, "Athlon", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } },
23 | { CPU_VENDOR_UMC, 4,{ NULL, "U5D", "U5S", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } },
24 | { CPU_VENDOR_NEXGEN, 5,{ "Nx586", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } },
25 | { CPU_VENDOR_RISE, 5,{ "iDragon", NULL, "iDragon", NULL, NULL, NULL, NULL, NULL, "iDragon II", "iDragon II", NULL, NULL, NULL, NULL, NULL, NULL } }
26 | };
27 | struct cpu_model_info *info = cpu_models;
28 |
29 | if (m_model >= 16) return NULL;
30 |
31 | for (int i = 0; i < sizeof(cpu_models) / sizeof(struct cpu_model_info); i++)
32 | {
33 | if (info->vendor == m_vendor && info->family == m_family)
34 | {
35 | return info->model_names[m_model];
36 | }
37 | info++;
38 | }
39 |
40 | return NULL;
41 | }
42 |
43 | CPU::CPU()
44 | {
45 | CPUID_INFO cpuid_info;
46 | // Get vendor ID
47 |
48 | cpuid(0x00000000, &cpuid_info);
49 |
50 | m_cpuid_level = cpuid_info.eax;
51 | *(uint32*)(m_vendorid + 0)= cpuid_info.ebx;
52 | *(uint32*)(m_vendorid + 4)= cpuid_info.edx;
53 | *(uint32*)(m_vendorid + 8)= cpuid_info.ecx;
54 | *(uint32*)(m_vendorid + 12) = 0;
55 |
56 | if (strcmp(m_vendorid, "GenuineIntel") == 0)
57 | {
58 | m_vendor = CPU_VENDOR_INTEL;
59 | strcpy(m_vendorname,"Intel");
60 | }
61 | else if (strcmp(m_vendorid, "AuthenticAMD") == 0)
62 | {
63 | m_vendor = CPU_VENDOR_AMD;
64 | strcpy(m_vendorname , "AMD");
65 | }
66 | else if (strcmp(m_vendorid, "CyrixInstead") == 0)
67 | {
68 | m_vendor = CPU_VENDOR_CYRIX;
69 | strcpy(m_vendorname , "Cyrix");
70 | }
71 | else if (strcmp(m_vendorid, "UMC UMC UMC ") == 0)
72 | {
73 | m_vendor = CPU_VENDOR_UMC;
74 | strcpy(m_vendorname , "UMC");
75 | }
76 | else if (strcmp(m_vendorid, "CentaurHauls") == 0)
77 | {
78 | m_vendor = CPU_VENDOR_CENTAUR;
79 | strcpy(m_vendorname , "Centaur");
80 | }
81 | else if (strcmp(m_vendorid, "NexGenDriven") == 0)
82 | {
83 | m_vendor = CPU_VENDOR_NEXGEN;
84 | strcpy(m_vendorname , "NexGen");
85 | }
86 | else if (strcmp(m_vendorid, "GenuineTMx86") == 0 || strcmp(m_vendorid, "TransmetaCPU") == 0)
87 | {
88 | m_vendor = CPU_VENDOR_TRANSMETA;
89 | strcpy(m_vendorname , "Transmeta");
90 | }
91 | else
92 | {
93 | m_vendor = CPU_VENDOR_UNKNOWN;
94 | strcpy(m_vendorname , m_vendorid);
95 | }
96 |
97 | // Get model and features
98 | if (m_cpuid_level >= 0x00000001)
99 | {
100 | cpuid(0x00000001, &cpuid_info);
101 | m_family = (cpuid_info.eax >> 8) & 15;
102 | m_model = (cpuid_info.eax >> 4) & 15;
103 | m_stepping = cpuid_info.eax & 15;
104 | m_features = cpuid_info.edx;
105 | }
106 |
107 | // SEP CPUID bug: Pentium Pro reports SEP but doesn't have it
108 | if (m_family == 6 && m_model < 3 && m_stepping < 3) m_features &= ~CPU_FEATURE_SEP;
109 |
110 | // Get brand string
111 | cpuid(0x80000000, &cpuid_info);
112 | if (cpuid_info.eax > 0x80000000)
113 | {
114 | char model[64];
115 | char *p, *q;
116 | int space;
117 |
118 | memset(model, 0, 64);
119 | cpuid(0x80000002, (CPUID_INFO*)model);
120 | cpuid(0x80000003, (CPUID_INFO*)(model + 16));
121 | cpuid(0x80000004, (CPUID_INFO*)(model + 32));
122 |
123 | // Trim brand string
124 | p = model;
125 | q = m_modelid;
126 | space = 0;
127 | while (*p == ' ') p++;
128 | while (*p)
129 | {
130 | if (*p == ' ')
131 | {
132 | space = 1;
133 | }
134 | else
135 | {
136 | if (space) *q++ = ' ';
137 | space = 0;
138 | *q++ = *p;
139 | }
140 | p++;
141 | }
142 | *q = 0;
143 | }
144 | else
145 | {
146 | char *modelid = table_lookup_model();
147 | if (modelid)
148 | {
149 | sprintf(m_modelid, "%s %s", m_vendorname, modelid);
150 | }
151 | else
152 | {
153 | sprintf(m_modelid, "%s %d86", m_vendorname, m_family);
154 | }
155 | }
156 | printf("cpu: %s family %d model %d stepping %d\n", m_modelid, m_family, m_model, m_stepping);
157 | }
158 |
159 |
160 | CPU::~CPU()
161 | {
162 | }
163 |
164 |
165 | void CPU::cpuid(uint32 id, CPUID_INFO* cpuid_info)
166 | {
167 | __asm
168 | {
169 | mov eax, id
170 | cpuid
171 | push esi
172 | mov esi, [cpuid_info]
173 | mov [esi]CPUID_INFO.eax, eax
174 | mov [esi]CPUID_INFO.ebx, ebx
175 | mov [esi]CPUID_INFO.ecx, ecx
176 | mov [esi]CPUID_INFO.edx, edx
177 | pop esi
178 | }
179 | }
--------------------------------------------------------------------------------
/GuestOS/cpu.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "typedef.h"
3 | //
4 | // ASM instructions
5 | //
6 |
7 | #define sysenter __asm _emit 0x0F __asm _emit 0x34
8 | #define sysexit __asm _emit 0x0F __asm _emit 0x35
9 |
10 | //
11 | // x86 EFLAGS
12 | //
13 |
14 | #define EFLAG_CF 0x00000001 // Carry
15 | #define EFLAG_PF 0x00000004 // Parity
16 | #define EFLAG_AF 0x00000010 // BCD stuff
17 | #define EFLAG_ZF 0x00000040 // Zero
18 | #define EFLAG_SF 0x00000080 // Sign
19 | #define EFLAG_TF 0x00000100 // Single step
20 | #define EFLAG_IF 0x00000200 // Interrupts
21 | #define EFLAG_DF 0x00000400 // Direction
22 | #define EFLAG_OF 0x00000800 // Overflow
23 | #define EFLAG_IOPL 0x00003000 // I/O privilege level
24 | #define EFLAG_NT 0x00004000 // Nested task
25 | #define EFLAG_RF 0x00010000 // Resume flag
26 | #define EFLAG_VM 0x00020000 // Virtual 8086
27 | #define EFLAGS_AC 0x00040000 // Alignment Check
28 | #define EFLAGS_VIF 0x00080000 // Virtual Interrupt Flag
29 | #define EFLAGS_VIP 0x00100000 // Virtual Interrupt Pending
30 | #define EFLAGS_ID 0x00200000 // CPUID detection flag
31 |
32 | //
33 | // x86 CR0 flags
34 | //
35 |
36 | #define CR0_PE (1 << 0) // Protection enable
37 | #define CR0_MP (1 << 1) // Math processor present
38 | #define CR0_EM (1 << 2) // Emulate FP - trap on FP instruction
39 | #define CR0_TS (1 << 3) // Task switched flag
40 | #define CR0_ET (1 << 4) // Extension type - 387 DX presence
41 | #define CR0_NE (1 << 5) // Numeric Error - allow traps on numeric errors
42 | #define CR0_WP (1 << 16) // Write protect - ring 0 honors RO PTE's
43 | #define CR0_AM (1 << 18) // Alignment - trap on unaligned refs
44 | #define CR0_NW (1 << 29) // Not write-through - inhibit write-through
45 | #define CR0_CD (1 << 30) // Cache disable
46 | #define CR0_PG (1 << 31) // Paging - use PTEs/CR3
47 |
48 | //
49 | // x86 CR4 feature flags
50 | //
51 | #define CR4_VME 0x0001 // Enable vm86 extensions
52 | #define CR4_PVI 0x0002 // Virtual interrupts flag enable
53 | #define CR4_TSD 0x0004 // Disable time stamp at ipl 3
54 | #define CR4_DE 0x0008 // Enable debugging extensions
55 | #define CR4_PSE 0x0010 // Enable page size extensions
56 | #define CR4_PAE 0x0020 // Enable physical address extensions
57 | #define CR4_MCE 0x0040 // Machine check enable
58 | #define CR4_PGE 0x0080 // Enable global pages
59 | #define CR4_PCE 0x0100 // Enable performance counters at ipl 3
60 | #define CR4_OSFXSR 0x0200 // Enable fast FPU save and restore
61 | #define CR4_OSXMMEXCPT 0x0400 // Enable unmasked SSE exceptions
62 |
63 | //
64 | // CPU feature flags (CPUID level 0x00000001, edx)
65 | //
66 |
67 | #define CPU_FEATURE_FPU (1 << 0) // Onboard FPU
68 | #define CPU_FEATURE_VME (1 << 1) // Virtual Mode Extensions
69 | #define CPU_FEATURE_DE (1 << 2) // Debugging Extensions
70 | #define CPU_FEATURE_PSE (1 << 3) // Page Size Extensions
71 | #define CPU_FEATURE_TSC (1 << 4) // Time Stamp Counter
72 | #define CPU_FEATURE_MSR (1 << 5) // Model-Specific Registers, RDMSR, WRMSR
73 | #define CPU_FEATURE_PAE (1 << 6) // Physical Address Extensions
74 | #define CPU_FEATURE_MCE (1 << 7) // Machine Check Architecture
75 | #define CPU_FEATURE_CX8 (1 << 8) // CMPXCHG8 instruction
76 | #define CPU_FEATURE_APIC (1 << 9) // Onboard APIC
77 | #define CPU_FEATURE_SEP (1 << 11) // SYSENTER/SYSEXIT
78 | #define CPU_FEATURE_MTRR (1 << 12) // Memory Type Range Registers
79 | #define CPU_FEATURE_PGE (1 << 13) // Page Global Enable
80 | #define CPU_FEATURE_MCA (1 << 14) // Machine Check Architecture
81 | #define CPU_FEATURE_CMOV (1 << 15) // CMOV instruction
82 | #define CPU_FEATURE_PAT (1 << 16) // Page Attribute Table
83 | #define CPU_FEATURE_PSE36 (1 << 17) // 36-bit PSEs
84 | #define CPU_FEATURE_PN (1 << 18) // Processor serial number
85 | #define CPU_FEATURE_CLFLSH (1 << 19) // Supports the CLFLUSH instruction
86 | #define CPU_FEATURE_DTES (1 << 21) // Debug Trace Store
87 | #define CPU_FEATURE_ACPI (1 << 22) // ACPI via MSR
88 | #define CPU_FEATURE_MMX (1 << 23) // Multimedia Extensions
89 | #define CPU_FEATURE_FXSR (1 << 24) // FXSAVE and FXRSTOR instructions
90 | #define CPU_FEATURE_XMM (1 << 25) // Streaming SIMD Extensions
91 | #define CPU_FEATURE_XMM2 (1 << 26) // Streaming SIMD Extensions-2
92 | #define CPU_FEATURE_SELFSNOOP (1 << 27) // CPU self snoop
93 | #define CPU_FEATURE_ACC (1 << 29) // Automatic clock control
94 | #define CPU_FEATURE_IA64 (1 << 30) // IA-64 processor
95 |
96 | //
97 | // Model Specific Registers
98 | //
99 |
100 | #define MSR_SYSENTER_CS 0x174 // CS register target for CPL 0 code
101 | #define MSR_SYSENTER_ESP 0x175 // Stack pointer for CPL 0 code
102 | #define MSR_SYSENTER_EIP 0x176 // CPL 0 code entry point
103 |
104 | //
105 | // CPU vendors
106 | //
107 |
108 | #define CPU_VENDOR_UNKNOWN 0
109 | #define CPU_VENDOR_INTEL 1
110 | #define CPU_VENDOR_CYRIX 2
111 | #define CPU_VENDOR_AMD 3
112 | #define CPU_VENDOR_UMC 4
113 | #define CPU_VENDOR_NEXGEN 5
114 | #define CPU_VENDOR_CENTAUR 6
115 | #define CPU_VENDOR_RISE 7
116 | #define CPU_VENDOR_TRANSMETA 8
117 |
118 | // CPU family
119 |
120 | #define CPU_FAMILY_386 3
121 | #define CPU_FAMILY_486 4
122 | #define CPU_FAMILY_P5 5
123 | #define CPU_FAMILY_P6 6
124 |
125 | //
126 | // CPU information
127 | //
128 |
129 | struct CPUID_INFO
130 | {
131 | uint32 eax;
132 | uint32 ebx;
133 | uint32 ecx;
134 | uint32 edx;
135 | };
136 |
137 | class CPU
138 | {
139 | private:
140 | int m_family;
141 | int m_vendor;
142 | int m_model;
143 | int m_stepping;
144 | int m_mhz;
145 | unsigned long m_features;
146 | unsigned long m_cpuid_level;
147 | char m_vendorid[16];
148 | char m_modelid[64];
149 | char m_vendorname[16];
150 | //PROCESS
151 | //GDT
152 | //IDT
153 | //TSS
154 | public:
155 | CPU();
156 | ~CPU();
157 | char *table_lookup_model();
158 | void cpuid(uint32 id, CPUID_INFO* cpuid_info);
159 | };
160 |
161 |
--------------------------------------------------------------------------------
/GuestOS/gdt.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/gdt.cpp
--------------------------------------------------------------------------------
/GuestOS/gdt.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/gdt.h
--------------------------------------------------------------------------------
/GuestOS/idt.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/idt.cpp
--------------------------------------------------------------------------------
/GuestOS/idt.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/idt.h
--------------------------------------------------------------------------------
/GuestOS/kernel.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "c++.h"
4 | #include "os.h"
5 | #include "gdt.h"
6 | #include "idt.h"
7 | #include "tss.h"
8 | #include "trap.h"
9 | #include "paging.h"
10 | #include "video.h"
11 | #include "Shellcode.h"
12 | #include "msr-index.h"
13 |
14 | GDT gdt;
15 | IDT idt;
16 | TSS tss;
17 | VIDEO video;
18 | PAGER pager;
19 | Shellcode shellcode;
20 |
21 | extern "C" int liballoc_lock() { return 0; }
22 | extern "C" int liballoc_unlock() { return 0; }
23 | extern "C" void* liballoc_alloc(int pages) { return 0; }
24 | extern "C" int liballoc_free(void*ptr, int size) { return 0; }
25 |
26 | void return_to_user_mode()
27 | {
28 | __asm cli
29 | __asm xor eax,eax
30 | __asm mov ax, SEL_USER_DATA
31 | __asm mov ds, ax
32 | __asm mov es, ax
33 | __asm mov gs, ax
34 |
35 | __asm mov ax, SEL_USER_FS
36 | __asm mov fs, ax
37 |
38 | __asm push SEL_USER_DATA //Ring3_SS
39 | __asm push SHELLCODE_STACK_VIRTUAL_ADDR//Ring3_ESP
40 | __asm pushfd
41 | __asm push SEL_USER_CODE //Ring3_CS
42 | __asm push SHELLCODE_BUF_VIRTUAL_ADDR//Ring3_EIP
43 | __asm iretd
44 | }
45 |
46 | int main()
47 | {
48 | CppInit();
49 | video.Init(VIDEO_BUF_VIRTUAL_ADDR, MB(2), 100, 100);
50 | gdt.Init();
51 | idt.Init();
52 | tss.Init(&gdt);
53 | TRAP::Init(&idt);
54 | tss.active();
55 | __asm mov esp, KERNEL_STACK_TOP_VIRTUAL_ADDR
56 | pager.unmap_pages(0, FRAME_DB_PHYSICAL_ADDR);
57 | //pager.map_pages(SHELLCODE_TEB_PHYSICAL_ADDR, SHELLCODE_TEB_VIRTUAL_ADDR, SHELLCODE_TEB_SIZE, PT_READONLY | PT_USER);
58 | //pager.map_pages(DUMMY_PEB_PHYSICAL_ADDR, DUMMY_PEB_VIRTUAL_ADDR, DUMMY_PEB_SIZE,PT_READONLY | PT_USER);
59 | //pager.map_pages(KERNEL32_PHYSICAL_ADDR, KERNEL32_VIRTUAL_ADDR, KERNEL32_SIZE, PT_READONLY | PT_USER);
60 | pager.map_pages(SHELLCODE_BUF_PHYSICAL_ADDR, SHELLCODE_BUF_VIRTUAL_ADDR, SHELLCODE_BUF_SIZE, PT_PRESENT | PT_READONLY | PT_USER);
61 |
62 | UINT32 test_code_buf = 0;
63 | UINT32 test_code_len = 0;
64 | __asm jmp test_code_end
65 | {
66 | __asm test_code_start:
67 | {
68 | __asm MOV EAX, 0x11111111
69 | __asm MOV EBX, 0x22222222
70 | __asm MOV ECX, 0x33333333
71 | __asm MOV EDX, 0x44444444
72 | __asm INT 0
73 | __asm MOV EDI, SHELLCODE_BUF_VIRTUAL_ADDR
74 | __asm MOV [EDI],EDI
75 | __asm MOV EDI, 0x12345678
76 | __asm MOV EDX, [EDI]
77 | __asm hlt
78 | }
79 | __asm test_code_end:
80 | }
81 | __asm mov eax, test_code_start
82 | __asm mov test_code_buf, eax
83 | __asm mov eax, test_code_end
84 | __asm SUB eax, test_code_start
85 | __asm mov test_code_len, eax
86 |
87 | memcpy((byte*)SHELLCODE_BUF_VIRTUAL_ADDR, (void*)test_code_buf, test_code_len);
88 |
89 | __asm MOV ECX, IA32_DEBUGCTL
90 | __asm rdmsr
91 | __asm OR EAX, 0x02
92 | __asm wrmsr
93 | __asm XOR EAX,EAX
94 | __asm rdmsr
95 | return_to_user_mode();
96 | __asm hlt
97 | //video.puts("Hello world\n");
98 | __asm mov edx,0x44444444
99 | __asm mov ecx,0
100 | __asm div ecx
101 |
102 | __asm jmp $
103 | return 0;
104 | }
--------------------------------------------------------------------------------
/GuestOS/os.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/os.h
--------------------------------------------------------------------------------
/GuestOS/paging.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/paging.cpp
--------------------------------------------------------------------------------
/GuestOS/paging.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | #define PAGE_SIZE 0x1000
5 | #define PAGE_SIZE_BITS 12
6 | #define PDE_INDEX(virtual_addr) ((virtual_addr>>22))
7 | #define PTE_INDEX(virtual_addr) ((virtual_addr>>12)&0x3FF)
8 |
9 | #define KERNEL_BASE 0x80000000
10 | #define PAGE_DIR_BASE 0xC0300000
11 | #define PAGE_TABLE_BASE 0xC0000000
12 | #define PAGE_FRAME_BASE 0xC0400000
13 |
14 | #define GET_PDE(addr) ((uint32_t*)PAGE_DIR_BASE)[(uint32_t)(addr)>>22]
15 | #define GET_PTE(addr) ((uint32_t*)PAGE_TABLE_BASE)[(uint32_t)(addr)>>12]
16 | #define GET_PAGE_TABLE(addr) (PAGE_TABLE_BASE + ((uint32_t)(addr)>>22)* PAGE_SIZE)
17 |
18 | #define SET_PDE(addr, val) ((uint32_t*)PAGE_DIR_BASE)[(uint32_t)(addr)>>22] = val;
19 | #define SET_PTE(addr, val) ((uint32_t*)PAGE_TABLE_BASE)[(uint32_t)(addr)>>12]=val;
20 |
21 | #define PAGE_ALGINED(addr) ((((uint32_t)addr) & 0x00000FFF) ==0)
22 | #define CHECK_PAGE_ALGINED(addr) //if ((((uint32_t)addr) & 0x00000FFF) !=0) panic("CHECK_PAGE_ALGINED(%08X)",addr);
23 |
24 | #define PT_PRESENT 0x001
25 |
26 | #define PT_WRITABLE 0x002
27 | #define PT_READONLY 0x000
28 |
29 | #define PT_USER 0x004
30 | #define PT_KERNEL 0x000
31 |
32 | #define PT_ACCESSED 0x020
33 | #define PT_DIRTY 0x040
34 |
35 | #define PAGE_FREE 0x00
36 | #define PAGE_USED 0x01
37 | #define PAGE_RESERVED 0xff
38 |
39 |
40 | #define KB(x) ((uint32_t)x<<10)
41 | #define MB(x) ((uint32_t)x<<20)
42 | #define GB(x) ((uint32_t)x<<30)
43 |
44 | #define USER_SPACE(addr) (((uint32_t)addr) < KERNEL_BASE)
45 | #define KERNEL_SPACE(addr) (((uint32_t)addr) >= KERNEL_BASE)
46 |
47 | #define PAGES_TO_SIZE(pages) ((uint32_t)(pages)<<12)
48 | #define SIZE_TO_PAGES(size) (((uint32_t)(size) + PAGE_SIZE -1)>>12)
49 | #define PAGE_ALGIN_SIZE(size) ((uint32_t)(size + 4095)&0xFFFFF000)
50 |
51 | class PAGER
52 | {
53 | private:
54 | uint32_t m_page_dir;
55 | uint32_t m_page_table_base;
56 |
57 | uint32_t m_page_frame_min;
58 | uint32_t m_page_frame_max;
59 | uint32_t m_next_free_page_frame;
60 | uint8_t* m_page_frame_database;
61 | bool m_database_usable;
62 |
63 | public:
64 | PAGER();
65 | ~PAGER();
66 | public:
67 | bool Init(uint32_t page_frame_min, uint32_t page_frame_max);
68 |
69 | void map_pages(uint32_t physical_address, uint32_t virtual_address, uint32_t size, uint32_t protect = (PT_PRESENT | PT_WRITABLE));
70 | void unmap_pages(uint32_t virtual_address, uint32_t size);
71 |
72 | bool create_database();
73 | uint32_t alloc_physical_page();
74 | uint32_t alloc_physical_pages(uint32_t pages);
75 | void free_physical_page(uint32_t page);
76 | void free_physical_pages(uint32_t start_page, uint32_t pages);
77 |
78 | private:
79 | void startup_page_mode();
80 | uint32_t new_page_dir();
81 | uint32_t new_page_table(uint32_t virtual_address);
82 | bool identity_paging_lowest_4M();
83 | };
84 |
85 |
--------------------------------------------------------------------------------
/GuestOS/trap.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/trap.cpp
--------------------------------------------------------------------------------
/GuestOS/trap.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "typedef.h"
3 | #include "idt.h"
4 | #include "gdt.h"
5 |
6 |
7 | #pragma pack(push, 1)
8 | struct TRAP_CONTEXT
9 | {
10 | uint32 gs, fs, es, ds;
11 | uint32 edi, esi, ebp, tmp, ebx, edx, ecx, eax;
12 | uint32 irq_no, err_code;
13 | uint32 eip, cs, eflags, esp, ss;
14 | }; //19*4=76 Bytes
15 | #pragma pack(pop)
16 |
17 | #define MAX_TRAP_ENTRIES 19
18 |
19 | typedef void (*TRAP_HANDLER)(TRAP_CONTEXT* context);
20 |
21 | class TRAP
22 | {
23 | private:
24 | static TRAP_HANDLER m_handlers[MAX_TRAP_ENTRIES];
25 | public:
26 | static void Init(IDT* idt);
27 | static void register_handler(int irq_no, TRAP_HANDLER handler);
28 | static void dispatch(TRAP_CONTEXT* context);
29 | static void handler0(TRAP_CONTEXT* context);
30 | static void handler1(TRAP_CONTEXT* context);
31 | static void handler2(TRAP_CONTEXT* context);
32 | static void handler3(TRAP_CONTEXT* context);
33 | static void handler4(TRAP_CONTEXT* context);
34 | static void handler5(TRAP_CONTEXT* context);
35 | static void handler6(TRAP_CONTEXT* context);
36 | static void handler7(TRAP_CONTEXT* context);
37 | static void handler8(TRAP_CONTEXT* context);
38 | static void handler9(TRAP_CONTEXT* context);
39 | static void handler10(TRAP_CONTEXT* context);
40 | static void handler11(TRAP_CONTEXT* context);
41 | static void handler12(TRAP_CONTEXT* context);
42 | static void handler13(TRAP_CONTEXT* context);
43 | static void handler14(TRAP_CONTEXT* context);
44 | static void handler15(TRAP_CONTEXT* context);
45 | static void handler16(TRAP_CONTEXT* context);
46 | static void handler17(TRAP_CONTEXT* context);
47 | static void handler18(TRAP_CONTEXT* context);
48 | static void handler19(TRAP_CONTEXT* context);
49 | };
50 |
51 |
--------------------------------------------------------------------------------
/GuestOS/tss.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/tss.cpp
--------------------------------------------------------------------------------
/GuestOS/tss.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/GuestOS/tss.h
--------------------------------------------------------------------------------
/GuestOS/video.cpp:
--------------------------------------------------------------------------------
1 | #include "VIDEO.h"
2 | #include
3 |
4 | VIDEO::VIDEO()
5 | {
6 | m_video_buf=0;
7 | m_video_buf_size = 0;
8 | m_screen_width = 25;
9 | m_screen_height = 80;
10 | m_cursor_x = 0;
11 | m_cursor_y = 0;
12 | }
13 |
14 | VIDEO::~VIDEO()
15 | {
16 | }
17 |
18 | bool VIDEO::Init(uint32_t video_buf, uint32_t buf_size, uint32_t width, uint32_t height)
19 | {
20 | m_video_buf = video_buf;
21 | m_video_buf_size = buf_size;
22 | m_screen_width = width <= MAX_SCREEN_WIDTH ? width-1 : MAX_SCREEN_WIDTH;
23 | m_screen_height = height<= MAX_SCREEN_HEIGHT? height-1: MAX_SCREEN_HEIGHT;
24 | m_cursor_x = 0;
25 | m_cursor_y = 0;
26 |
27 | return true;
28 | }
29 |
30 | void VIDEO::putc(char ch)
31 | {
32 | if (ch == '\r')
33 | {
34 | m_cursor_x = 0;
35 | return;
36 | }
37 | if (ch == '\n')
38 | {
39 | if (m_cursor_y < m_screen_height) m_cursor_y++;
40 | else scroll(1);
41 | return;
42 | }
43 | if (m_cursor_x >= m_screen_width)
44 | {
45 | m_cursor_x = 0;
46 | if (m_cursor_y < m_screen_height) m_cursor_y++;
47 | else scroll(1);
48 | }
49 | char* addr = (char*)(m_video_buf + m_cursor_y*LINE_BUF_WIDTH + m_cursor_x++);
50 | *addr++ = ch;
51 | *addr = 0;
52 | }
53 |
54 | void VIDEO::puts(char* str)
55 | {
56 | int len = strlen(str);
57 | for (int i = 0; i < len; i++) putc(str[i]);
58 | }
59 |
60 |
61 | void VIDEO::clear()
62 | {
63 | char* line_buf = (char*)m_video_buf;
64 | for (int i = 0; i <= m_screen_height;i++)
65 | {
66 | line_buf[0] = 0;
67 | line_buf += LINE_BUF_WIDTH;
68 | }
69 | }
70 |
71 | void VIDEO::scroll(int lines)
72 | {
73 | char* line_buf = (char*)m_video_buf;
74 | memcpy(line_buf, line_buf + lines*LINE_BUF_WIDTH, (m_screen_height - lines)*LINE_BUF_WIDTH);
75 | }
76 |
77 | void VIDEO::gotoxy(int x, int y)
78 | {
79 | m_cursor_x = x;
80 | m_cursor_y = y;
81 | }
82 |
83 | int VIDEO::getx()
84 | {
85 | return m_cursor_x;
86 | }
87 |
88 | int VIDEO::gety()
89 | {
90 | return m_cursor_y;
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/GuestOS/video.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | #define MAX_VIDEO_BUF_SIZE 0x10000
5 | #define MAX_SCREEN_WIDTH 255
6 | #define MAX_SCREEN_HEIGHT 255
7 | #define LINE_BUF_WIDTH 256
8 |
9 | class VIDEO
10 | {
11 | private:
12 | uint32_t m_video_buf;
13 | uint32_t m_video_buf_size;
14 | uint32_t m_screen_width;
15 | uint32_t m_screen_height;
16 | uint32_t m_cursor_x;
17 | uint32_t m_cursor_y;
18 | public:
19 | VIDEO();
20 | ~VIDEO();
21 | bool Init(uint32_t video_buf, uint32_t buf_size, uint32_t width, uint32_t height);
22 | void putc(char ch);
23 | void puts(char* str);
24 | void clear();
25 | void scroll(int lines);
26 | void gotoxy(int x, int y);
27 | int getx();
28 | int gety();
29 | };
30 |
31 | extern VIDEO video;
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ShellcodeVM
2 | ShellcodeVM
3 |
--------------------------------------------------------------------------------
/ShellcodeVM.VC.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imgits/ShellcodeVM/9a16b806bc18fb6da45907a1c1a3337cf3a9fce2/ShellcodeVM.VC.db
--------------------------------------------------------------------------------
/ShellcodeVM.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShellcodeVM", "ShellcodeVM\ShellcodeVM.vcxproj", "{C27C6721-3007-443E-B095-51024C1B8236}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GuestOS", "GuestOS\GuestOS.vcxproj", "{70B6C809-92DB-4C09-8E45-C6ED3256412B}"
9 | EndProject
10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Boot", "Boot\Boot.vcxproj", "{77EB0E19-AA23-415C-B34B-8BDCD4CD495D}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|x64 = Debug|x64
15 | Debug|x86 = Debug|x86
16 | Release|x64 = Release|x64
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {C27C6721-3007-443E-B095-51024C1B8236}.Debug|x64.ActiveCfg = Debug|x64
21 | {C27C6721-3007-443E-B095-51024C1B8236}.Debug|x64.Build.0 = Debug|x64
22 | {C27C6721-3007-443E-B095-51024C1B8236}.Debug|x86.ActiveCfg = Debug|Win32
23 | {C27C6721-3007-443E-B095-51024C1B8236}.Debug|x86.Build.0 = Debug|Win32
24 | {C27C6721-3007-443E-B095-51024C1B8236}.Release|x64.ActiveCfg = Release|x64
25 | {C27C6721-3007-443E-B095-51024C1B8236}.Release|x64.Build.0 = Release|x64
26 | {C27C6721-3007-443E-B095-51024C1B8236}.Release|x86.ActiveCfg = Release|Win32
27 | {C27C6721-3007-443E-B095-51024C1B8236}.Release|x86.Build.0 = Release|Win32
28 | {70B6C809-92DB-4C09-8E45-C6ED3256412B}.Debug|x64.ActiveCfg = Debug|x64
29 | {70B6C809-92DB-4C09-8E45-C6ED3256412B}.Debug|x64.Build.0 = Debug|x64
30 | {70B6C809-92DB-4C09-8E45-C6ED3256412B}.Debug|x86.ActiveCfg = Debug|Win32
31 | {70B6C809-92DB-4C09-8E45-C6ED3256412B}.Debug|x86.Build.0 = Debug|Win32
32 | {70B6C809-92DB-4C09-8E45-C6ED3256412B}.Release|x64.ActiveCfg = Release|x64
33 | {70B6C809-92DB-4C09-8E45-C6ED3256412B}.Release|x64.Build.0 = Release|x64
34 | {70B6C809-92DB-4C09-8E45-C6ED3256412B}.Release|x86.ActiveCfg = Release|Win32
35 | {70B6C809-92DB-4C09-8E45-C6ED3256412B}.Release|x86.Build.0 = Release|Win32
36 | {77EB0E19-AA23-415C-B34B-8BDCD4CD495D}.Debug|x64.ActiveCfg = Debug|x64
37 | {77EB0E19-AA23-415C-B34B-8BDCD4CD495D}.Debug|x64.Build.0 = Debug|x64
38 | {77EB0E19-AA23-415C-B34B-8BDCD4CD495D}.Debug|x86.ActiveCfg = Debug|Win32
39 | {77EB0E19-AA23-415C-B34B-8BDCD4CD495D}.Debug|x86.Build.0 = Debug|Win32
40 | {77EB0E19-AA23-415C-B34B-8BDCD4CD495D}.Release|x64.ActiveCfg = Release|x64
41 | {77EB0E19-AA23-415C-B34B-8BDCD4CD495D}.Release|x64.Build.0 = Release|x64
42 | {77EB0E19-AA23-415C-B34B-8BDCD4CD495D}.Release|x86.ActiveCfg = Release|Win32
43 | {77EB0E19-AA23-415C-B34B-8BDCD4CD495D}.Release|x86.Build.0 = Release|Win32
44 | EndGlobalSection
45 | GlobalSection(SolutionProperties) = preSolution
46 | HideSolutionNode = FALSE
47 | EndGlobalSection
48 | EndGlobal
49 |
--------------------------------------------------------------------------------
/ShellcodeVM/HAXM.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "hax-interface.h"
7 | #include "hax-windows.h"
8 | #include "HAXM_VM.h"
9 | #include
10 | #include
11 | #include
12 | #include