Skip to content

Commit cc9e073

Browse files
committed
Implemented file inputs.
1 parent c7aea20 commit cc9e073

File tree

5 files changed

+57
-254
lines changed

5 files changed

+57
-254
lines changed

ActualConsole/ActualConsole.vcxproj

+1-58
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup Label="ProjectConfigurations">
4-
<ProjectConfiguration Include="Debug|Win32">
5-
<Configuration>Debug</Configuration>
6-
<Platform>Win32</Platform>
7-
</ProjectConfiguration>
84
<ProjectConfiguration Include="Release|Win32">
95
<Configuration>Release</Configuration>
106
<Platform>Win32</Platform>
117
</ProjectConfiguration>
12-
<ProjectConfiguration Include="Debug|x64">
13-
<Configuration>Debug</Configuration>
14-
<Platform>x64</Platform>
15-
</ProjectConfiguration>
168
<ProjectConfiguration Include="Release|x64">
179
<Configuration>Release</Configuration>
1810
<Platform>x64</Platform>
@@ -26,25 +18,13 @@
2618
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2719
</PropertyGroup>
2820
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30-
<ConfigurationType>Application</ConfigurationType>
31-
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v142</PlatformToolset>
33-
<CharacterSet>Unicode</CharacterSet>
34-
</PropertyGroup>
3521
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3622
<ConfigurationType>Application</ConfigurationType>
3723
<UseDebugLibraries>false</UseDebugLibraries>
3824
<PlatformToolset>v142</PlatformToolset>
3925
<WholeProgramOptimization>true</WholeProgramOptimization>
4026
<CharacterSet>Unicode</CharacterSet>
4127
</PropertyGroup>
42-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43-
<ConfigurationType>Application</ConfigurationType>
44-
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v142</PlatformToolset>
46-
<CharacterSet>Unicode</CharacterSet>
47-
</PropertyGroup>
4828
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4929
<ConfigurationType>Application</ConfigurationType>
5030
<UseDebugLibraries>false</UseDebugLibraries>
@@ -57,43 +37,20 @@
5737
</ImportGroup>
5838
<ImportGroup Label="Shared">
5939
</ImportGroup>
60-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62-
</ImportGroup>
6340
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
6441
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
6542
</ImportGroup>
66-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68-
</ImportGroup>
6943
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
7044
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
7145
</ImportGroup>
7246
<PropertyGroup Label="UserMacros" />
73-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74-
<LinkIncremental>true</LinkIncremental>
75-
</PropertyGroup>
7647
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
7748
<LinkIncremental>false</LinkIncremental>
7849
</PropertyGroup>
79-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
80-
<LinkIncremental>true</LinkIncremental>
81-
</PropertyGroup>
8250
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
8351
<LinkIncremental>false</LinkIncremental>
52+
<TargetName>ntlua</TargetName>
8453
</PropertyGroup>
85-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86-
<ClCompile>
87-
<WarningLevel>Level3</WarningLevel>
88-
<SDLCheck>true</SDLCheck>
89-
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
90-
<ConformanceMode>true</ConformanceMode>
91-
</ClCompile>
92-
<Link>
93-
<SubSystem>Console</SubSystem>
94-
<GenerateDebugInformation>true</GenerateDebugInformation>
95-
</Link>
96-
</ItemDefinitionGroup>
9754
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
9855
<ClCompile>
9956
<WarningLevel>Level3</WarningLevel>
@@ -110,20 +67,6 @@
11067
<GenerateDebugInformation>true</GenerateDebugInformation>
11168
</Link>
11269
</ItemDefinitionGroup>
113-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
114-
<ClCompile>
115-
<WarningLevel>Level3</WarningLevel>
116-
<SDLCheck>true</SDLCheck>
117-
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118-
<ConformanceMode>true</ConformanceMode>
119-
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
120-
<LanguageStandard>stdcpplatest</LanguageStandard>
121-
</ClCompile>
122-
<Link>
123-
<SubSystem>Console</SubSystem>
124-
<GenerateDebugInformation>true</GenerateDebugInformation>
125-
</Link>
126-
</ItemDefinitionGroup>
12770
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
12871
<ClCompile>
12972
<WarningLevel>Level3</WarningLevel>

ActualConsole/main.cpp

+56-42
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <Windows.h>
22
#include <string>
33
#include <iostream>
4+
#include <fstream>
45
#include <sstream>
56
#include <tuple>
67
#include <mutex>
@@ -16,40 +17,76 @@ HANDLE device = CreateFileA
1617
FILE_ATTRIBUTE_NORMAL,
1718
NULL
1819
);
20+
bool execute( const char* str, bool silent )
21+
{
22+
// Issue the IOCTL.
23+
//
24+
DWORD discarded = 0;
25+
ntlua_result result = { nullptr, nullptr };
26+
DeviceIoControl( device, NTLUA_RUN, ( void* ) str, strlen( str ) + 1, &result, sizeof( result ), &discarded, nullptr );
27+
bool had_result = result.outputs != nullptr;
28+
29+
// If silent, free result and return.
30+
//
31+
if ( silent )
32+
{
33+
if ( result.outputs ) VirtualFree( result.outputs, 0, MEM_RELEASE );
34+
if ( result.errors ) VirtualFree( result.errors, 0, MEM_RELEASE );
35+
}
36+
// Print each buffer to the console.
37+
//
38+
else
39+
{
40+
for ( auto& [buffer, color] : { std::pair{ result.errors, 12 },
41+
std::pair{ result.outputs, 15 } } )
42+
{
43+
if ( !buffer ) continue;
44+
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), color );
45+
puts( buffer );
46+
VirtualFree( buffer, 0, MEM_RELEASE );
47+
}
48+
}
49+
return had_result;
50+
}
1951

2052
void worker_thread()
2153
{
2254
bool prev_success = false;
2355
while ( 1 )
2456
{
2557
Sleep( prev_success ? 100 : 5000 );
26-
27-
ntlua_result result = { nullptr, nullptr };
28-
char worker_script[] = R"(
58+
static constexpr char worker_script[] = R"(
2959
if worker then
3060
worker()
3161
print("-")
3262
end
3363
)";
34-
35-
DWORD discarded = 0;
36-
DeviceIoControl(
37-
device,
38-
NTLUA_RUN,
39-
worker_script, sizeof( worker_script ),
40-
&result, sizeof( result ),
41-
&discarded, nullptr
42-
);
43-
44-
if ( result.outputs ) VirtualFree( result.outputs, 0, MEM_RELEASE );
45-
if ( result.errors ) VirtualFree( result.errors, 0, MEM_RELEASE );
46-
prev_success = !result.outputs;
64+
prev_success = execute( worker_script, true );
4765
}
4866
}
4967

50-
int main()
68+
69+
int main( int argc, const char** argv )
5170
{
5271
if ( device == INVALID_HANDLE_VALUE ) return 1;
72+
73+
// If any arguments are given, assume they're lua files and execute them.
74+
//
75+
if ( argc >= 2 )
76+
{
77+
for ( size_t n = 1; n != argc; n++ )
78+
{
79+
printf( "Running '%s'...\n", argv[ n ] );
80+
81+
std::ifstream fs( argv[ n ] );
82+
std::string buffer{ std::istreambuf_iterator<char>( fs ), {} };
83+
execute( buffer.data(), false );
84+
}
85+
return 0;
86+
}
87+
88+
// Start the worker thread.
89+
//
5390
std::thread thr( &worker_thread );
5491

5592
// Enter REPL:
@@ -73,14 +110,11 @@ int main()
73110
buffer += "\n" + buffer2;
74111
}
75112

76-
77-
78113
// Handle special commands:
79114
//
80115
if ( buffer == "clear" )
81116
{
82117
system( "cls" );
83-
continue;
84118
}
85119
else if ( buffer == "cmd" )
86120
return system( "cmd" );
@@ -96,30 +130,10 @@ int main()
96130
&discarded, sizeof( discarded ),
97131
&discarded, nullptr
98132
);
99-
continue;
100133
}
101-
102-
// Send IOCTL.
103-
//
104-
ntlua_result result = { nullptr, nullptr };
105-
DWORD discarded = 0;
106-
DeviceIoControl(
107-
device,
108-
NTLUA_RUN,
109-
&buffer[0], buffer.size() + 1,
110-
&result, sizeof( result ),
111-
&discarded, nullptr
112-
);
113-
114-
// Print each buffer if relevant.
115-
//
116-
for ( auto& [buffer, color] : { std::pair{ result.errors, 12 },
117-
std::pair{ result.outputs, 15 } } )
134+
else
118135
{
119-
if ( !buffer ) continue;
120-
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), color );
121-
puts( buffer );
122-
VirtualFree( buffer, 0, MEM_RELEASE );
136+
execute( buffer.data(), false );
123137
}
124138
}
125139
}

KernelLuaVm/KernelLuaVm.vcxproj

-62
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup Label="ProjectConfigurations">
4-
<ProjectConfiguration Include="Debug|Win32">
5-
<Configuration>Debug</Configuration>
6-
<Platform>Win32</Platform>
7-
</ProjectConfiguration>
84
<ProjectConfiguration Include="Release|Win32">
95
<Configuration>Release</Configuration>
106
<Platform>Win32</Platform>
117
</ProjectConfiguration>
12-
<ProjectConfiguration Include="Debug|x64">
13-
<Configuration>Debug</Configuration>
14-
<Platform>x64</Platform>
15-
</ProjectConfiguration>
168
<ProjectConfiguration Include="Release|x64">
179
<Configuration>Release</Configuration>
1810
<Platform>x64</Platform>
@@ -29,14 +21,6 @@
2921
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
3022
</PropertyGroup>
3123
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
32-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
33-
<TargetVersion>Windows10</TargetVersion>
34-
<UseDebugLibraries>true</UseDebugLibraries>
35-
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
36-
<ConfigurationType>Driver</ConfigurationType>
37-
<DriverType>KMDF</DriverType>
38-
<DriverTargetPlatform>Universal</DriverTargetPlatform>
39-
</PropertyGroup>
4024
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
4125
<TargetVersion>Windows10</TargetVersion>
4226
<UseDebugLibraries>false</UseDebugLibraries>
@@ -45,14 +29,6 @@
4529
<DriverType>KMDF</DriverType>
4630
<DriverTargetPlatform>Universal</DriverTargetPlatform>
4731
</PropertyGroup>
48-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
49-
<TargetVersion>Windows10</TargetVersion>
50-
<UseDebugLibraries>true</UseDebugLibraries>
51-
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
52-
<ConfigurationType>Driver</ConfigurationType>
53-
<DriverType>KMDF</DriverType>
54-
<DriverTargetPlatform>Universal</DriverTargetPlatform>
55-
</PropertyGroup>
5632
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
5733
<TargetVersion>Windows10</TargetVersion>
5834
<UseDebugLibraries>false</UseDebugLibraries>
@@ -71,19 +47,10 @@
7147
</ImportGroup>
7248
<PropertyGroup Label="UserMacros" />
7349
<PropertyGroup />
74-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
75-
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
76-
<IncludePath>$(SolutionDir)..\LuaLib;$(IncludePath);$(KMDF_INC_PATH)$(KMDF_VER_PATH)</IncludePath>
77-
</PropertyGroup>
7850
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
7951
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
8052
<IncludePath>$(SolutionDir)..\LuaLib;$(IncludePath);$(KMDF_INC_PATH)$(KMDF_VER_PATH)</IncludePath>
8153
</PropertyGroup>
82-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
83-
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
84-
<IncludePath>$(SolutionDir)LuaLib;$(IncludePath);$(KMDF_INC_PATH)$(KMDF_VER_PATH)</IncludePath>
85-
<TimeStampServer>http://timestamp.verisign.com/scripts/timstamp.dll</TimeStampServer>
86-
</PropertyGroup>
8754
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
8855
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
8956
<IncludePath>$(SolutionDir)LuaLib;$(IncludePath);$(KMDF_INC_PATH)$(KMDF_VER_PATH)</IncludePath>
@@ -92,20 +59,6 @@
9259
</TimeStampServer>
9360
<EnableInf2cat>false</EnableInf2cat>
9461
</PropertyGroup>
95-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
96-
<ClCompile>
97-
<TreatWarningAsError>false</TreatWarningAsError>
98-
<CompileAs>CompileAsCpp</CompileAs>
99-
<IntrinsicFunctions>false</IntrinsicFunctions>
100-
<BufferSecurityCheck>false</BufferSecurityCheck>
101-
<ControlFlowGuard>false</ControlFlowGuard>
102-
<LanguageStandard>stdcpp17</LanguageStandard>
103-
<PreprocessorDefinitions>_DEBUG;_X86_=1;i386=1;STD_CALL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
104-
</ClCompile>
105-
<Link>
106-
<TreatLinkerWarningAsErrors>false</TreatLinkerWarningAsErrors>
107-
</Link>
108-
</ItemDefinitionGroup>
10962
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
11063
<ClCompile>
11164
<TreatWarningAsError>false</TreatWarningAsError>
@@ -118,21 +71,6 @@
11871
<TreatLinkerWarningAsErrors>false</TreatLinkerWarningAsErrors>
11972
</Link>
12073
</ItemDefinitionGroup>
121-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
122-
<ClCompile>
123-
<TreatWarningAsError>false</TreatWarningAsError>
124-
<CompileAs>CompileAsCpp</CompileAs>
125-
<IntrinsicFunctions>false</IntrinsicFunctions>
126-
<ControlFlowGuard>false</ControlFlowGuard>
127-
<BufferSecurityCheck>false</BufferSecurityCheck>
128-
<LanguageStandard>stdcpp17</LanguageStandard>
129-
<PreprocessorDefinitions>_DEBUG;_WIN64;_AMD64_;AMD64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
130-
</ClCompile>
131-
<Link>
132-
<TreatLinkerWarningAsErrors>false</TreatLinkerWarningAsErrors>
133-
<EntryPointSymbol>DriverEntry</EntryPointSymbol>
134-
</Link>
135-
</ItemDefinitionGroup>
13674
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
13775
<ClCompile>
13876
<TreatWarningAsError>false</TreatWarningAsError>

0 commit comments

Comments
 (0)