Skip to content

Commit 0a03821

Browse files
Add CI/CD pipeline with MSBuild and Loader exe artifact
1 parent 00c9be2 commit 0a03821

5 files changed

Lines changed: 219 additions & 7 deletions

File tree

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: Build Pe Library with Visual Studio
1+
name: Build Windows PE Loader
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ master, dev ]
66
pull_request:
77
branches: [ master ]
88

@@ -12,11 +12,16 @@ jobs:
1212

1313
steps:
1414
- name: Checkout code
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
1616

17-
- name: Setup MSBuild path
18-
uses: microsoft/setup-msbuild@v1.1
17+
- name: Setup MSBuild
18+
uses: microsoft/setup-msbuild@v2
1919

2020
- name: Build solution
21-
run: msbuild PeLibrary/PeLibrary.vcxproj /p:Configuration=Release
21+
run: msbuild WindowsPeLoader.sln /p:Configuration=Release /p:Platform=Win32
2222

23+
- name: Upload Loader artifact
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: Loader
27+
path: Release/Loader.exe

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,4 @@ Release
5757
*.user
5858
.vs
5959
.vscode
60-
*.sln
6160
*.filters

Loader/Loader.vcxproj

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<ClCompile Include="main.c" />
15+
</ItemGroup>
16+
<ItemGroup>
17+
<ProjectReference Include="..\PeLibrary\PeLibrary.vcxproj">
18+
<Project>{2a1a2c9d-82b7-428c-af11-432808dfeff4}</Project>
19+
</ProjectReference>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>17.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{b5a7f4e1-9c3d-4f2a-8e6b-1d5a3c7e9f0b}</ProjectGuid>
25+
<RootNamespace>Loader</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<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>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
43+
<ImportGroup Label="ExtensionSettings">
44+
</ImportGroup>
45+
<ImportGroup Label="Shared">
46+
</ImportGroup>
47+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
48+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
49+
</ImportGroup>
50+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
51+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
52+
</ImportGroup>
53+
<PropertyGroup Label="UserMacros" />
54+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
55+
<ClCompile>
56+
<WarningLevel>Level4</WarningLevel>
57+
<SDLCheck>true</SDLCheck>
58+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
59+
<ConformanceMode>true</ConformanceMode>
60+
<LanguageStandard>stdcpp17</LanguageStandard>
61+
<TreatWarningAsError>true</TreatWarningAsError>
62+
<AdditionalIncludeDirectories>..\PeLibrary;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
63+
</ClCompile>
64+
<Link>
65+
<SubSystem>Console</SubSystem>
66+
<GenerateDebugInformation>true</GenerateDebugInformation>
67+
</Link>
68+
</ItemDefinitionGroup>
69+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
70+
<ClCompile>
71+
<WarningLevel>Level4</WarningLevel>
72+
<FunctionLevelLinking>true</FunctionLevelLinking>
73+
<IntrinsicFunctions>true</IntrinsicFunctions>
74+
<SDLCheck>true</SDLCheck>
75+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
76+
<ConformanceMode>true</ConformanceMode>
77+
<LanguageStandard>stdcpp17</LanguageStandard>
78+
<TreatWarningAsError>true</TreatWarningAsError>
79+
<AdditionalIncludeDirectories>..\PeLibrary;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
80+
</ClCompile>
81+
<Link>
82+
<SubSystem>Console</SubSystem>
83+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
84+
<OptimizeReferences>true</OptimizeReferences>
85+
<GenerateDebugInformation>true</GenerateDebugInformation>
86+
</Link>
87+
</ItemDefinitionGroup>
88+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
89+
<ImportGroup Label="ExtensionTargets">
90+
</ImportGroup>
91+
</Project>

Loader/main.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <stdint.h>
4+
#include <Windows.h>
5+
6+
#include "pe_library.h"
7+
8+
static BOOL read_file(const wchar_t* path, uint8_t** out_buffer, DWORD* out_size)
9+
{
10+
HANDLE file = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL,
11+
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
12+
13+
if (file == INVALID_HANDLE_VALUE)
14+
{
15+
wprintf(L"Failed to open file: %s (error: %lu)\n", path, GetLastError());
16+
return FALSE;
17+
}
18+
19+
DWORD file_size = GetFileSize(file, NULL);
20+
if (file_size == INVALID_FILE_SIZE)
21+
{
22+
wprintf(L"Failed to get file size (error: %lu)\n", GetLastError());
23+
CloseHandle(file);
24+
return FALSE;
25+
}
26+
27+
uint8_t* buffer = (uint8_t*)malloc(file_size);
28+
if (buffer == NULL)
29+
{
30+
wprintf(L"Failed to allocate %lu bytes\n", file_size);
31+
CloseHandle(file);
32+
return FALSE;
33+
}
34+
35+
DWORD bytes_read = 0;
36+
if (!ReadFile(file, buffer, file_size, &bytes_read, NULL) || bytes_read != file_size)
37+
{
38+
wprintf(L"Failed to read file (error: %lu)\n", GetLastError());
39+
free(buffer);
40+
CloseHandle(file);
41+
return FALSE;
42+
}
43+
44+
CloseHandle(file);
45+
*out_buffer = buffer;
46+
*out_size = file_size;
47+
return TRUE;
48+
}
49+
50+
int wmain(int argc, wchar_t* argv[])
51+
{
52+
if (argc < 2)
53+
{
54+
wprintf(L"Usage: %s <path_to_dll>\n", argv[0]);
55+
return 1;
56+
}
57+
58+
uint8_t* pe_buffer = NULL;
59+
DWORD pe_size = 0;
60+
61+
if (!read_file(argv[1], &pe_buffer, &pe_size))
62+
{
63+
return 1;
64+
}
65+
66+
wprintf(L"Loading DLL: %s (%lu bytes)\n", argv[1], pe_size);
67+
68+
HMODULE module = Library__load_library(pe_buffer, pe_size);
69+
free(pe_buffer);
70+
71+
if (module == NULL)
72+
{
73+
wprintf(L"Failed to load library\n");
74+
return 1;
75+
}
76+
77+
wprintf(L"Library loaded at 0x%p\n", (void*)module);
78+
wprintf(L"Press Enter to unload and exit...\n");
79+
getwchar();
80+
81+
if (!Library__FreeLibrary(module))
82+
{
83+
wprintf(L"Failed to free library\n");
84+
return 1;
85+
}
86+
87+
wprintf(L"Library unloaded successfully\n");
88+
return 0;
89+
}

WindowsPeLoader.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.0.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PeLibrary", "PeLibrary\PeLibrary.vcxproj", "{2A1A2C9D-82B7-428C-AF11-432808DFEFF4}"
7+
EndProject
8+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Loader", "Loader\Loader.vcxproj", "{B5A7F4E1-9C3D-4F2A-8E6B-1D5A3C7E9F0B}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Win32 = Debug|Win32
13+
Release|Win32 = Release|Win32
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{2A1A2C9D-82B7-428C-AF11-432808DFEFF4}.Debug|Win32.ActiveCfg = Debug|Win32
17+
{2A1A2C9D-82B7-428C-AF11-432808DFEFF4}.Debug|Win32.Build.0 = Debug|Win32
18+
{2A1A2C9D-82B7-428C-AF11-432808DFEFF4}.Release|Win32.ActiveCfg = Release|Win32
19+
{2A1A2C9D-82B7-428C-AF11-432808DFEFF4}.Release|Win32.Build.0 = Release|Win32
20+
{B5A7F4E1-9C3D-4F2A-8E6B-1D5A3C7E9F0B}.Debug|Win32.ActiveCfg = Debug|Win32
21+
{B5A7F4E1-9C3D-4F2A-8E6B-1D5A3C7E9F0B}.Debug|Win32.Build.0 = Debug|Win32
22+
{B5A7F4E1-9C3D-4F2A-8E6B-1D5A3C7E9F0B}.Release|Win32.ActiveCfg = Release|Win32
23+
{B5A7F4E1-9C3D-4F2A-8E6B-1D5A3C7E9F0B}.Release|Win32.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

0 commit comments

Comments
 (0)