Skip to content

Commit cee8bf5

Browse files
committed
Initial
1 parent 67e5808 commit cee8bf5

File tree

12 files changed

+950
-1
lines changed

12 files changed

+950
-1
lines changed

.clang-format

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
# BasedOnStyle: WebKit
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: AlwaysBreak
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignEscapedNewlines: Right
8+
AlignOperands: false
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: true
11+
AllowShortBlocksOnASingleLine: false
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortFunctionsOnASingleLine: None
14+
AllowShortIfStatementsOnASingleLine: false
15+
AllowShortLoopsOnASingleLine: false
16+
AlwaysBreakAfterDefinitionReturnType: None
17+
AlwaysBreakAfterReturnType: None
18+
AlwaysBreakBeforeMultilineStrings: false
19+
AlwaysBreakTemplateDeclarations: false
20+
BinPackArguments: true
21+
BinPackParameters: true
22+
BraceWrapping:
23+
AfterCaseLabel: true
24+
AfterClass: true
25+
AfterControlStatement: true
26+
AfterEnum: true
27+
AfterFunction: true
28+
AfterNamespace: true
29+
AfterStruct: true
30+
AfterUnion: true
31+
BeforeCatch: true
32+
BeforeElse: true
33+
IndentBraces: false
34+
SplitEmptyFunction: true
35+
SplitEmptyRecord: true
36+
SplitEmptyNamespace: true
37+
BreakBeforeBinaryOperators: All
38+
BreakBeforeBraces: Custom
39+
BreakBeforeInheritanceComma: false
40+
BreakBeforeTernaryOperators: true
41+
BreakConstructorInitializersBeforeComma: false
42+
BreakConstructorInitializers: BeforeComma
43+
BreakStringLiterals: true
44+
ColumnLimit: 128
45+
CompactNamespaces: false
46+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
47+
ConstructorInitializerIndentWidth: 4
48+
ContinuationIndentWidth: 4
49+
Cpp11BracedListStyle: false
50+
DerivePointerAlignment: false
51+
DisableFormat: false
52+
ExperimentalAutoDetectBinPacking: false
53+
FixNamespaceComments: true
54+
IncludeBlocks: 'Regroup'
55+
IncludeCategories:
56+
- Regex: '^"'
57+
Priority: 1
58+
- Regex: '^<'
59+
Priority: 2
60+
IndentCaseLabels: true
61+
IndentPPDirectives: AfterHash
62+
IndentWidth: 4
63+
IndentWrappedFunctionNames: true
64+
KeepEmptyLinesAtTheStartOfBlocks: false
65+
MacroBlockBegin: ''
66+
MacroBlockEnd: ''
67+
MaxEmptyLinesToKeep: 1
68+
NamespaceIndentation: All
69+
PenaltyBreakAssignment: 1000
70+
PenaltyBreakBeforeFirstCallParameter: 19
71+
PenaltyBreakComment: 300
72+
PenaltyBreakFirstLessLess: 120
73+
PenaltyBreakString: 1000
74+
PenaltyExcessCharacter: 1000000
75+
PenaltyReturnTypeOnItsOwnLine: 1000
76+
PointerAlignment: Left
77+
ReflowComments: true
78+
SortIncludes: true
79+
SortUsingDeclarations: true
80+
SpaceAfterCStyleCast: false
81+
SpaceAfterTemplateKeyword: false
82+
SpaceBeforeAssignmentOperators: true
83+
SpaceBeforeParens: ControlStatements
84+
SpaceInEmptyParentheses: false
85+
SpacesBeforeTrailingComments: 1
86+
SpacesInAngles: false
87+
SpacesInContainerLiterals: true
88+
SpacesInCStyleCastParentheses: false
89+
SpacesInParentheses: false
90+
SpacesInSquareBrackets: false
91+
Standard: Cpp11
92+
UseTab: Never
93+
...

CMakeLists.txt

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# This file is automatically generated from cmake.toml - DO NOT EDIT
2+
# See https://github.com/build-cpp/cmkr for more information
3+
4+
cmake_minimum_required(VERSION 3.15)
5+
6+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
7+
message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build")
8+
endif()
9+
10+
# Regenerate CMakeLists.txt automatically in the root project
11+
set(CMKR_ROOT_PROJECT OFF)
12+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
13+
set(CMKR_ROOT_PROJECT ON)
14+
15+
# Bootstrap cmkr
16+
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
17+
if(CMKR_INCLUDE_RESULT)
18+
cmkr()
19+
endif()
20+
21+
# Enable folder support
22+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
23+
endif()
24+
25+
# Create a configure-time dependency on cmake.toml to improve IDE support
26+
if(CMKR_ROOT_PROJECT)
27+
configure_file(cmake.toml cmake.toml COPYONLY)
28+
endif()
29+
30+
project(zasm-modules
31+
LANGUAGES
32+
CXX
33+
)
34+
35+
# thirdparty
36+
set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER})
37+
if(CMAKE_FOLDER)
38+
set(CMAKE_FOLDER "${CMAKE_FOLDER}/thirdparty")
39+
else()
40+
set(CMAKE_FOLDER thirdparty)
41+
endif()
42+
add_subdirectory(thirdparty)
43+
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})
44+
45+
# Target zasm-modules
46+
set(CMKR_TARGET zasm-modules)
47+
set(zasm-modules_SOURCES "")
48+
49+
list(APPEND zasm-modules_SOURCES
50+
"src/zasm-modules/module.cpp"
51+
"src/zasm-modules/module.pe.cpp"
52+
"src/zasm-modules/module.pe.hpp"
53+
"include/zasm/modules/module.hpp"
54+
)
55+
56+
list(APPEND zasm-modules_SOURCES
57+
cmake.toml
58+
)
59+
60+
set(CMKR_SOURCES ${zasm-modules_SOURCES})
61+
add_library(zasm-modules STATIC)
62+
63+
if(zasm-modules_SOURCES)
64+
target_sources(zasm-modules PRIVATE ${zasm-modules_SOURCES})
65+
endif()
66+
67+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${zasm-modules_SOURCES})
68+
69+
add_library(zasm::modules ALIAS zasm-modules)
70+
target_compile_features(zasm-modules PUBLIC
71+
cxx_std_17
72+
)
73+
74+
target_include_directories(zasm-modules PUBLIC
75+
include
76+
)
77+
78+
target_link_libraries(zasm-modules PUBLIC
79+
zasm::common
80+
zasm::zasm
81+
LIEF::LIEF
82+
)
83+
84+
unset(CMKR_TARGET)
85+
unset(CMKR_SOURCES)
86+
87+
# Target example
88+
set(CMKR_TARGET example)
89+
set(example_SOURCES "")
90+
91+
list(APPEND example_SOURCES
92+
"src/example/main.cpp"
93+
)
94+
95+
list(APPEND example_SOURCES
96+
cmake.toml
97+
)
98+
99+
set(CMKR_SOURCES ${example_SOURCES})
100+
add_executable(example)
101+
102+
if(example_SOURCES)
103+
target_sources(example PRIVATE ${example_SOURCES})
104+
endif()
105+
106+
get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
107+
if(NOT CMKR_VS_STARTUP_PROJECT)
108+
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT example)
109+
endif()
110+
111+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${example_SOURCES})
112+
113+
target_compile_features(example PRIVATE
114+
cxx_std_17
115+
)
116+
117+
target_link_libraries(example PRIVATE
118+
zasm::common
119+
zasm::modules
120+
)
121+
122+
unset(CMKR_TARGET)
123+
unset(CMKR_SOURCES)
124+

README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
# zasm-modules
2-
Generating binary modules with zasm
2+
Generating binary modules with zasm and [LIEF](https://github.com/lief-project/LIEF).
3+
4+
### Project
5+
This project is currently more of a demonstration for how zasm could be used to generate binary modules,
6+
zasm provides enough information to have imports/externals/relocations/entrypoints.
7+
8+
### LIEF
9+
This project builds upon [LIEF](https://github.com/lief-project/LIEF) to generate the binary modules, the interface was built to hide this and
10+
may or may not change in the future. LIEF can currently only generate PE files from scratch which, this depends if and when LIEF might add support for generating more binaries from scratch. LIEF is a wonderful
11+
library and we do hope to be able to make more use of it.
12+
13+
### Goals
14+
Add more support for modules like COFF and potentially be fully independent from LIEF, this is not set in stone.
15+
16+
### Compiling
17+
This library ships with an example project and uses CMake. Following should be able to build the
18+
project:
19+
```
20+
cmake . -B build
21+
cmake --build .
22+
```

cmake.toml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Reference: https://build-cpp.github.io/cmkr/cmake-toml
2+
[project]
3+
name = "zasm-modules"
4+
languages = ["CXX"]
5+
6+
[subdir.thirdparty]
7+
8+
[target.zasm-modules]
9+
alias = "zasm::modules"
10+
type = "static"
11+
sources = ["src/zasm-modules/**.cpp"]
12+
headers = ["src/zasm-modules/*.hpp", "include/zasm/modules/*.hpp"]
13+
include-directories = ["include"]
14+
compile-features = ["cxx_std_17"]
15+
link-libraries = [
16+
"zasm::common",
17+
"zasm::zasm",
18+
"LIEF::LIEF",
19+
]
20+
21+
[target.example]
22+
type = "executable"
23+
sources = ["src/example/**.cpp"]
24+
headers = ["src/example/**.hpp"]
25+
compile-features = ["cxx_std_17"]
26+
link-libraries = [
27+
"zasm::common",
28+
"zasm::modules",
29+
]

0 commit comments

Comments
 (0)