Compare commits
No commits in common. "669b6d66a3bad931b6ab2188568e92e907b0168c" and "81b3d6a08d274d0386aed9d33989e4c83026048b" have entirely different histories.
669b6d66a3
...
81b3d6a08d
@ -27,13 +27,11 @@ endif ()
|
|||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
add_executable(Compiler
|
add_executable(Compiler
|
||||||
src/ELF64_Section.cpp include/ELF64_Section.h
|
src/ELF.cpp include/ELF.h
|
||||||
src/ELF64_Program.cpp include/ELF64_Program.h
|
|
||||||
src/ELF64.cpp include/ELF64.h
|
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(Compiler PRIVATE "${PROJECT_SOURCE_DIR}/include")
|
target_include_directories(Compiler PRIVATE "include")
|
||||||
|
|
||||||
if (IS_OS_LINUX)
|
if (IS_OS_LINUX)
|
||||||
add_compile_definitions(LWE_WS_XCB)
|
add_compile_definitions(LWE_WS_XCB)
|
||||||
|
@ -0,0 +1,156 @@
|
|||||||
|
{
|
||||||
|
"inputs" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"path" : "CMakeLists.txt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isGenerated" : true,
|
||||||
|
"path" : "cmake-build-debug/CMakeFiles/3.27.8/CMakeSystem.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeSystemSpecificInitialize.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Platform/Linux-Initialize.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isGenerated" : true,
|
||||||
|
"path" : "cmake-build-debug/CMakeFiles/3.27.8/CMakeCCompiler.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isGenerated" : true,
|
||||||
|
"path" : "cmake-build-debug/CMakeFiles/3.27.8/CMakeCXXCompiler.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeSystemSpecificInformation.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeGenericSystem.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeInitializeConfigs.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Platform/Linux.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Platform/UnixPaths.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeCInformation.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeLanguageInformation.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Compiler/GNU-C.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Compiler/GNU.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Compiler/CMakeCommonCompilerMacros.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Platform/Linux-GNU-C.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Platform/Linux-GNU.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeCommonLanguageInclude.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeCXXInformation.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeLanguageInformation.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Compiler/GNU-CXX.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Compiler/GNU.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Platform/Linux-GNU-CXX.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/Platform/Linux-GNU.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/CMakeCommonLanguageInclude.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/FindVulkan.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isCMake" : true,
|
||||||
|
"isExternal" : true,
|
||||||
|
"path" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27/Modules/FindPackageMessage.cmake"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"kind" : "cmakeFiles",
|
||||||
|
"paths" :
|
||||||
|
{
|
||||||
|
"build" : "/home/karutoh/CLionProjects/Compiler/cmake-build-debug",
|
||||||
|
"source" : "/home/karutoh/CLionProjects/Compiler"
|
||||||
|
},
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 1,
|
||||||
|
"minor" : 0
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
{
|
||||||
|
"configurations" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"directories" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"build" : ".",
|
||||||
|
"jsonFile" : "directory-.-Debug-f5ebdc15457944623624.json",
|
||||||
|
"minimumCMakeVersion" :
|
||||||
|
{
|
||||||
|
"string" : "3.18.4"
|
||||||
|
},
|
||||||
|
"projectIndex" : 0,
|
||||||
|
"source" : ".",
|
||||||
|
"targetIndexes" :
|
||||||
|
[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name" : "Debug",
|
||||||
|
"projects" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"directoryIndexes" :
|
||||||
|
[
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"name" : "Compiler",
|
||||||
|
"targetIndexes" :
|
||||||
|
[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"targets" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"directoryIndex" : 0,
|
||||||
|
"id" : "Compiler::@6890427a1f51a3e7e1df",
|
||||||
|
"jsonFile" : "target-Compiler-Debug-b504b707cc3938b58fc6.json",
|
||||||
|
"name" : "Compiler",
|
||||||
|
"projectIndex" : 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"kind" : "codemodel",
|
||||||
|
"paths" :
|
||||||
|
{
|
||||||
|
"build" : "/home/karutoh/CLionProjects/Compiler/cmake-build-debug",
|
||||||
|
"source" : "/home/karutoh/CLionProjects/Compiler"
|
||||||
|
},
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 2,
|
||||||
|
"minor" : 6
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
{
|
||||||
|
"cmake" :
|
||||||
|
{
|
||||||
|
"generator" :
|
||||||
|
{
|
||||||
|
"multiConfig" : false,
|
||||||
|
"name" : "Ninja"
|
||||||
|
},
|
||||||
|
"paths" :
|
||||||
|
{
|
||||||
|
"cmake" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/bin/cmake",
|
||||||
|
"cpack" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/bin/cpack",
|
||||||
|
"ctest" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/bin/ctest",
|
||||||
|
"root" : "/home/karutoh/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.27"
|
||||||
|
},
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"isDirty" : false,
|
||||||
|
"major" : 3,
|
||||||
|
"minor" : 27,
|
||||||
|
"patch" : 8,
|
||||||
|
"string" : "3.27.8",
|
||||||
|
"suffix" : ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"objects" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"jsonFile" : "codemodel-v2-7763de202a4897ee489a.json",
|
||||||
|
"kind" : "codemodel",
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 2,
|
||||||
|
"minor" : 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"jsonFile" : "cache-v2-525bf0c12142f71983da.json",
|
||||||
|
"kind" : "cache",
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 2,
|
||||||
|
"minor" : 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"jsonFile" : "cmakeFiles-v1-c002049034cb93e91036.json",
|
||||||
|
"kind" : "cmakeFiles",
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 1,
|
||||||
|
"minor" : 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"jsonFile" : "toolchains-v1-17c20dde199508adeef8.json",
|
||||||
|
"kind" : "toolchains",
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 1,
|
||||||
|
"minor" : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"reply" :
|
||||||
|
{
|
||||||
|
"cache-v2" :
|
||||||
|
{
|
||||||
|
"jsonFile" : "cache-v2-525bf0c12142f71983da.json",
|
||||||
|
"kind" : "cache",
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 2,
|
||||||
|
"minor" : 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cmakeFiles-v1" :
|
||||||
|
{
|
||||||
|
"jsonFile" : "cmakeFiles-v1-c002049034cb93e91036.json",
|
||||||
|
"kind" : "cmakeFiles",
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 1,
|
||||||
|
"minor" : 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"codemodel-v2" :
|
||||||
|
{
|
||||||
|
"jsonFile" : "codemodel-v2-7763de202a4897ee489a.json",
|
||||||
|
"kind" : "codemodel",
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 2,
|
||||||
|
"minor" : 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"toolchains-v1" :
|
||||||
|
{
|
||||||
|
"jsonFile" : "toolchains-v1-17c20dde199508adeef8.json",
|
||||||
|
"kind" : "toolchains",
|
||||||
|
"version" :
|
||||||
|
{
|
||||||
|
"major" : 1,
|
||||||
|
"minor" : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,186 @@
|
|||||||
|
{
|
||||||
|
"artifacts" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"path" : "Compiler"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"backtrace" : 1,
|
||||||
|
"backtraceGraph" :
|
||||||
|
{
|
||||||
|
"commands" :
|
||||||
|
[
|
||||||
|
"add_executable",
|
||||||
|
"target_link_directories",
|
||||||
|
"target_link_libraries",
|
||||||
|
"add_compile_options",
|
||||||
|
"add_compile_definitions"
|
||||||
|
],
|
||||||
|
"files" :
|
||||||
|
[
|
||||||
|
"CMakeLists.txt"
|
||||||
|
],
|
||||||
|
"nodes" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"file" : 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command" : 0,
|
||||||
|
"file" : 0,
|
||||||
|
"line" : 29,
|
||||||
|
"parent" : 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command" : 1,
|
||||||
|
"file" : 0,
|
||||||
|
"line" : 39,
|
||||||
|
"parent" : 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command" : 2,
|
||||||
|
"file" : 0,
|
||||||
|
"line" : 44,
|
||||||
|
"parent" : 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command" : 3,
|
||||||
|
"file" : 0,
|
||||||
|
"line" : 11,
|
||||||
|
"parent" : 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command" : 4,
|
||||||
|
"file" : 0,
|
||||||
|
"line" : 36,
|
||||||
|
"parent" : 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"compileGroups" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"compileCommandFragments" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"fragment" : " -fPIC -g -std=gnu++20 -fdiagnostics-color=always"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 4,
|
||||||
|
"fragment" : "-Wno-stringop-overflow"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"defines" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"backtrace" : 5,
|
||||||
|
"define" : "LWE_WS_XCB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 5,
|
||||||
|
"define" : "VK_USE_PLATFORM_XCB_KHR"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"language" : "CXX",
|
||||||
|
"languageStandard" :
|
||||||
|
{
|
||||||
|
"backtraces" :
|
||||||
|
[
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"standard" : "20"
|
||||||
|
},
|
||||||
|
"sourceIndexes" :
|
||||||
|
[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id" : "Compiler::@6890427a1f51a3e7e1df",
|
||||||
|
"link" :
|
||||||
|
{
|
||||||
|
"commandFragments" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"fragment" : "-fPIC -g",
|
||||||
|
"role" : "flags"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fragment" : "",
|
||||||
|
"role" : "flags"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 2,
|
||||||
|
"fragment" : "-L/home/karutoh/.local/lib",
|
||||||
|
"role" : "libraryPath"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fragment" : "-Wl,-rpath,/home/karutoh/.local/lib",
|
||||||
|
"role" : "libraries"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 3,
|
||||||
|
"fragment" : "-lxcb",
|
||||||
|
"role" : "libraries"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 3,
|
||||||
|
"fragment" : "-lxcb-cursor",
|
||||||
|
"role" : "libraries"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 3,
|
||||||
|
"fragment" : "-lxcb-xfixes",
|
||||||
|
"role" : "libraries"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 3,
|
||||||
|
"fragment" : "-lxcb-xinput",
|
||||||
|
"role" : "libraries"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 3,
|
||||||
|
"fragment" : "-lz",
|
||||||
|
"role" : "libraries"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 3,
|
||||||
|
"fragment" : "-lasound",
|
||||||
|
"role" : "libraries"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"backtrace" : 3,
|
||||||
|
"fragment" : "-lEHS",
|
||||||
|
"role" : "libraries"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"language" : "CXX"
|
||||||
|
},
|
||||||
|
"name" : "Compiler",
|
||||||
|
"nameOnDisk" : "Compiler",
|
||||||
|
"paths" :
|
||||||
|
{
|
||||||
|
"build" : ".",
|
||||||
|
"source" : "."
|
||||||
|
},
|
||||||
|
"sourceGroups" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name" : "Source Files",
|
||||||
|
"sourceIndexes" :
|
||||||
|
[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"sources" :
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"backtrace" : 1,
|
||||||
|
"compileGroupIndex" : 0,
|
||||||
|
"path" : "main.cpp",
|
||||||
|
"sourceGroupIndex" : 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type" : "EXECUTABLE"
|
||||||
|
}
|
Binary file not shown.
@ -1,18 +1,7 @@
|
|||||||
# ninja log v5
|
# ninja log v5
|
||||||
0 222 1707982539439184710 CMakeFiles/Compiler.dir/src/ELF64.cpp.o 7203a7b7f92d3a
|
167 224 1707921734641901585 Compiler 415d67d1a4aaa864
|
||||||
0 161 1707978871138561402 CMakeFiles/Compiler.dir/src/ELF64_Program.cpp.o 6531657353b15e1e
|
0 57 1707955165530194762 build.ninja 8efbe7f6ed9511af
|
||||||
1 171 1707981742781983377 CMakeFiles/Compiler.dir/src/ELF64_Section.cpp.o 886965ebb1584f45
|
0 167 1707921734585234642 CMakeFiles/Compiler.dir/main.cpp.o de3174f74a65d11b
|
||||||
222 286 1707982539502518597 Compiler ed968931e95b249c
|
0 3 0 clean aa1517684869203c
|
||||||
0 57 1707982626129941948 build.ninja 8efbe7f6ed9511af
|
|
||||||
1 166 1707955167336856399 CMakeFiles/Compiler.dir/main.cpp.o 7e18d66cc0ec0bf7
|
1 166 1707955167336856399 CMakeFiles/Compiler.dir/main.cpp.o 7e18d66cc0ec0bf7
|
||||||
0 167 1707980675233295598 CMakeFiles/Compiler.dir/src/main.cpp.o d6e32444f822aba9
|
166 250 1707955167420189502 Compiler 9828d719de1a93e2
|
||||||
0 151 1707965004973740575 CMakeFiles/Compiler.dir/src/ELF.cpp.o bd59b885017e2e72
|
|
||||||
0 4 0 clean aa1517684869203c
|
|
||||||
0 163 1707982629519971506 CMakeFiles/Compiler.dir/src/main.cpp.o d6e32444f822aba9
|
|
||||||
163 223 1707982629579972029 Compiler 6d7a3ac418bcbfae
|
|
||||||
0 4 0 clean aa1517684869203c
|
|
||||||
1 155 1707982632830000361 CMakeFiles/Compiler.dir/src/ELF64_Program.cpp.o 6531657353b15e1e
|
|
||||||
1 168 1707982632843333811 CMakeFiles/Compiler.dir/src/ELF64_Section.cpp.o 886965ebb1584f45
|
|
||||||
1 176 1707982632850000536 CMakeFiles/Compiler.dir/src/main.cpp.o d6e32444f822aba9
|
|
||||||
1 230 1707982632903334334 CMakeFiles/Compiler.dir/src/ELF64.cpp.o 7203a7b7f92d3a
|
|
||||||
230 290 1707982632963334857 Compiler 6d7a3ac418bcbfae
|
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -1,3 +1,3 @@
|
|||||||
Start testing: Feb 14 23:37 PST
|
Start testing: Feb 14 06:42 PST
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
End testing: Feb 14 23:37 PST
|
End testing: Feb 14 06:42 PST
|
||||||
|
@ -49,37 +49,12 @@ cmake_ninja_workdir = /home/karutoh/CLionProjects/Compiler/cmake-build-debug/
|
|||||||
|
|
||||||
build cmake_object_order_depends_target_Compiler: phony || CMakeFiles/Compiler.dir
|
build cmake_object_order_depends_target_Compiler: phony || CMakeFiles/Compiler.dir
|
||||||
|
|
||||||
build CMakeFiles/Compiler.dir/src/ELF64_Section.cpp.o: CXX_COMPILER__Compiler_unscanned_Debug /home/karutoh/CLionProjects/Compiler/src/ELF64_Section.cpp || cmake_object_order_depends_target_Compiler
|
build CMakeFiles/Compiler.dir/main.cpp.o: CXX_COMPILER__Compiler_unscanned_Debug /home/karutoh/CLionProjects/Compiler/main.cpp || cmake_object_order_depends_target_Compiler
|
||||||
DEFINES = -DLWE_WS_XCB
|
DEFINES = -DLWE_WS_XCB
|
||||||
DEP_FILE = CMakeFiles/Compiler.dir/src/ELF64_Section.cpp.o.d
|
DEP_FILE = CMakeFiles/Compiler.dir/main.cpp.o.d
|
||||||
FLAGS = -g -std=gnu++20 -fdiagnostics-color=always -Wno-stringop-overflow
|
FLAGS = -g -std=gnu++20 -fdiagnostics-color=always -Wno-stringop-overflow
|
||||||
INCLUDES = -I/home/karutoh/CLionProjects/Compiler/include
|
|
||||||
OBJECT_DIR = CMakeFiles/Compiler.dir
|
OBJECT_DIR = CMakeFiles/Compiler.dir
|
||||||
OBJECT_FILE_DIR = CMakeFiles/Compiler.dir/src
|
OBJECT_FILE_DIR = CMakeFiles/Compiler.dir
|
||||||
|
|
||||||
build CMakeFiles/Compiler.dir/src/ELF64_Program.cpp.o: CXX_COMPILER__Compiler_unscanned_Debug /home/karutoh/CLionProjects/Compiler/src/ELF64_Program.cpp || cmake_object_order_depends_target_Compiler
|
|
||||||
DEFINES = -DLWE_WS_XCB
|
|
||||||
DEP_FILE = CMakeFiles/Compiler.dir/src/ELF64_Program.cpp.o.d
|
|
||||||
FLAGS = -g -std=gnu++20 -fdiagnostics-color=always -Wno-stringop-overflow
|
|
||||||
INCLUDES = -I/home/karutoh/CLionProjects/Compiler/include
|
|
||||||
OBJECT_DIR = CMakeFiles/Compiler.dir
|
|
||||||
OBJECT_FILE_DIR = CMakeFiles/Compiler.dir/src
|
|
||||||
|
|
||||||
build CMakeFiles/Compiler.dir/src/ELF64.cpp.o: CXX_COMPILER__Compiler_unscanned_Debug /home/karutoh/CLionProjects/Compiler/src/ELF64.cpp || cmake_object_order_depends_target_Compiler
|
|
||||||
DEFINES = -DLWE_WS_XCB
|
|
||||||
DEP_FILE = CMakeFiles/Compiler.dir/src/ELF64.cpp.o.d
|
|
||||||
FLAGS = -g -std=gnu++20 -fdiagnostics-color=always -Wno-stringop-overflow
|
|
||||||
INCLUDES = -I/home/karutoh/CLionProjects/Compiler/include
|
|
||||||
OBJECT_DIR = CMakeFiles/Compiler.dir
|
|
||||||
OBJECT_FILE_DIR = CMakeFiles/Compiler.dir/src
|
|
||||||
|
|
||||||
build CMakeFiles/Compiler.dir/src/main.cpp.o: CXX_COMPILER__Compiler_unscanned_Debug /home/karutoh/CLionProjects/Compiler/src/main.cpp || cmake_object_order_depends_target_Compiler
|
|
||||||
DEFINES = -DLWE_WS_XCB
|
|
||||||
DEP_FILE = CMakeFiles/Compiler.dir/src/main.cpp.o.d
|
|
||||||
FLAGS = -g -std=gnu++20 -fdiagnostics-color=always -Wno-stringop-overflow
|
|
||||||
INCLUDES = -I/home/karutoh/CLionProjects/Compiler/include
|
|
||||||
OBJECT_DIR = CMakeFiles/Compiler.dir
|
|
||||||
OBJECT_FILE_DIR = CMakeFiles/Compiler.dir/src
|
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
@ -89,7 +64,7 @@ build CMakeFiles/Compiler.dir/src/main.cpp.o: CXX_COMPILER__Compiler_unscanned_D
|
|||||||
#############################################
|
#############################################
|
||||||
# Link the executable Compiler
|
# Link the executable Compiler
|
||||||
|
|
||||||
build Compiler: CXX_EXECUTABLE_LINKER__Compiler_Debug CMakeFiles/Compiler.dir/src/ELF64_Section.cpp.o CMakeFiles/Compiler.dir/src/ELF64_Program.cpp.o CMakeFiles/Compiler.dir/src/ELF64.cpp.o CMakeFiles/Compiler.dir/src/main.cpp.o
|
build Compiler: CXX_EXECUTABLE_LINKER__Compiler_Debug CMakeFiles/Compiler.dir/main.cpp.o
|
||||||
FLAGS = -g
|
FLAGS = -g
|
||||||
LINK_LIBRARIES = -Wl,-rpath,/home/karutoh/.local/lib -lxcb -lxcb-cursor -lxcb-xfixes -lxcb-xinput -lz -lasound -lEHS
|
LINK_LIBRARIES = -Wl,-rpath,/home/karutoh/.local/lib -lxcb -lxcb-cursor -lxcb-xfixes -lxcb-xinput -lz -lasound -lEHS
|
||||||
LINK_PATH = -L/home/karutoh/.local/lib
|
LINK_PATH = -L/home/karutoh/.local/lib
|
||||||
|
101
include/ELF.h
Normal file
101
include/ELF.h
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ehs/Serializer.h>
|
||||||
|
|
||||||
|
/// Architecture's memory bit-depth.
|
||||||
|
#define ELFH_ARCH_32 0x01
|
||||||
|
#define ELFH_ARCH_64 0x02
|
||||||
|
|
||||||
|
/// Architecture's endianness.
|
||||||
|
#define ELFH_END_LE 0x01
|
||||||
|
#define ELFH_END_BE 0x02
|
||||||
|
|
||||||
|
/// OS' ABI Types.
|
||||||
|
#define ELFH_ABI_SYSTEMV 0x00
|
||||||
|
|
||||||
|
/// ELF Binary Types.
|
||||||
|
#define ELFH_TYPE_EXEC 0x02
|
||||||
|
#define ELFH_TYPE_DYN 0x03
|
||||||
|
|
||||||
|
/// Machine architectures.
|
||||||
|
#define ELFH_MARCH_AMD_X86_64 0x003E
|
||||||
|
|
||||||
|
/// Program types.
|
||||||
|
#define PRGH_TYPE_LOAD 0x00000001
|
||||||
|
|
||||||
|
/// Program flags.
|
||||||
|
#define PRGH_FLAG_EXEC 0x00000001
|
||||||
|
#define PRGH_FLAG_WRITE 0x00000002
|
||||||
|
#define PRGH_FLAG_READ 0x00000004
|
||||||
|
|
||||||
|
/// Section types.
|
||||||
|
#define SECH_TYPE_NULL 0x00
|
||||||
|
#define SECH_TYPE_PROGBITS 0x01
|
||||||
|
#define SECH_TYPE_STRTAB 0x03
|
||||||
|
|
||||||
|
/// Section flags.
|
||||||
|
#define SECH_FLAG_ALLOC 0x02
|
||||||
|
#define SECH_FLAG_EXEC 0x04
|
||||||
|
#define SECH_FLAG_STRINGS 0x20
|
||||||
|
|
||||||
|
/// True header sizes.
|
||||||
|
#define ELFH_SIZE 64
|
||||||
|
#define PRGH_SIZE 56
|
||||||
|
#define SECH_SIZE 64
|
||||||
|
|
||||||
|
/// ELF Header
|
||||||
|
struct ElfHeader
|
||||||
|
{
|
||||||
|
ehs::UInt_8 architecture;
|
||||||
|
ehs::UInt_8 endianness;
|
||||||
|
ehs::UInt_8 elfV1;
|
||||||
|
ehs::UInt_8 targetABI;
|
||||||
|
ehs::UInt_8 abiV;
|
||||||
|
ehs::UInt_16 elfType;
|
||||||
|
ehs::UInt_16 machineArch;
|
||||||
|
ehs::UInt_32 elfV2;
|
||||||
|
ehs::UInt_64 entryAddress;
|
||||||
|
ehs::UInt_64 programsOffset;
|
||||||
|
ehs::UInt_64 sectionsOffset;
|
||||||
|
ehs::UInt_32 flags;
|
||||||
|
ehs::UInt_16 headerSize;
|
||||||
|
ehs::UInt_16 pHeaderSize;
|
||||||
|
ehs::UInt_16 pEntries;
|
||||||
|
ehs::UInt_16 sSize;
|
||||||
|
ehs::UInt_16 sEntries;
|
||||||
|
ehs::UInt_16 strTabIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// ELF Program Header
|
||||||
|
struct ElfPrgHeader
|
||||||
|
{
|
||||||
|
ehs::UInt_32 type;
|
||||||
|
ehs::UInt_32 flags;
|
||||||
|
ehs::UInt_64 offset;
|
||||||
|
ehs::UInt_64 vAddr;
|
||||||
|
ehs::UInt_64 pAddr;
|
||||||
|
ehs::UInt_64 fileSize;
|
||||||
|
ehs::UInt_64 memSize;
|
||||||
|
ehs::UInt_64 align;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// ELF Section Header
|
||||||
|
struct ElfSecHeader
|
||||||
|
{
|
||||||
|
ehs::UInt_32 index;
|
||||||
|
ehs::UInt_32 type;
|
||||||
|
ehs::UInt_64 flags;
|
||||||
|
ehs::UInt_64 vAddr;
|
||||||
|
ehs::UInt_64 offset;
|
||||||
|
ehs::UInt_64 size;
|
||||||
|
ehs::UInt_32 associatedIndex;
|
||||||
|
ehs::UInt_32 info;
|
||||||
|
ehs::UInt_64 align;
|
||||||
|
ehs::UInt_64 entrySize;
|
||||||
|
};
|
||||||
|
|
||||||
|
void WriteHeader(const ElfHeader& header, ehs::Serializer<ehs::UInt_64>& data);
|
||||||
|
|
||||||
|
void WriteHeader(const ElfPrgHeader& header, ehs::Serializer<ehs::UInt_64>& data);
|
||||||
|
|
||||||
|
void WriteHeader(const ElfSecHeader& header, ehs::Serializer<ehs::UInt_64>& data);
|
@ -1,88 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ELF64_Section.h"
|
|
||||||
#include "ELF64_Program.h"
|
|
||||||
|
|
||||||
#include <ehs/Serializer.h>
|
|
||||||
|
|
||||||
/// Architecture's memory bit-depth.
|
|
||||||
#define ELFH_ARCH_32 0x01
|
|
||||||
#define ELFH_ARCH_64 0x02
|
|
||||||
|
|
||||||
/// Architecture's endianness.
|
|
||||||
#define ELFH_END_LE 0x01
|
|
||||||
#define ELFH_END_BE 0x02
|
|
||||||
|
|
||||||
/// OS' ABI Types.
|
|
||||||
#define ELFH_ABI_SYSTEMV 0x00
|
|
||||||
|
|
||||||
/// ELF Binary Types.
|
|
||||||
#define ELFH_TYPE_EXEC 0x02
|
|
||||||
#define ELFH_TYPE_DYN 0x03
|
|
||||||
|
|
||||||
/// Machine architectures.
|
|
||||||
#define ELFH_MARCH_AMD_X86_64 0x003E
|
|
||||||
|
|
||||||
/// True header sizes.
|
|
||||||
#define ELFH_SIZE 64
|
|
||||||
|
|
||||||
class ELF64
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ehs::UInt_8 subArch;
|
|
||||||
ehs::UInt_8 endianness;
|
|
||||||
ehs::UInt_8 abi;
|
|
||||||
ehs::UInt_16 type;
|
|
||||||
ehs::UInt_16 arch;
|
|
||||||
ehs::UInt_16 entryPoint;
|
|
||||||
ehs::Vector<ELF64_Program, ehs::UInt_16> programs;
|
|
||||||
ehs::Vector<ELF64_Section, ehs::UInt_16> sections;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ELF64();
|
|
||||||
|
|
||||||
ELF64(ehs::UInt_8 subArch, ehs::UInt_8 end, ehs::UInt_8 abi, ehs::UInt_16 type, ehs::UInt_16 arch);
|
|
||||||
|
|
||||||
ELF64(ehs::Serializer<ehs::UInt_64>& data);
|
|
||||||
|
|
||||||
ELF64(ELF64&& header) noexcept;
|
|
||||||
|
|
||||||
ELF64(const ELF64& header);
|
|
||||||
|
|
||||||
ELF64& operator=(ELF64&& header) noexcept;
|
|
||||||
|
|
||||||
ELF64& operator=(const ELF64& header);
|
|
||||||
|
|
||||||
ehs::UInt_8 GetSubArchitecture() const;
|
|
||||||
|
|
||||||
ehs::UInt_8 GetEndianness() const;
|
|
||||||
|
|
||||||
ehs::UInt_8 GetABI() const;
|
|
||||||
|
|
||||||
ehs::UInt_16 GetType() const;
|
|
||||||
|
|
||||||
ehs::UInt_16 GetArchitecture() const;
|
|
||||||
|
|
||||||
void SetEntryPoint(ehs::UInt_16 programIndex);
|
|
||||||
|
|
||||||
ELF64_Program* GetEntryPoint() const;
|
|
||||||
|
|
||||||
void AddProgram(ELF64_Program newProgram);
|
|
||||||
|
|
||||||
bool HasSection(ehs::UInt_64 hashId);
|
|
||||||
|
|
||||||
bool HasSection(ehs::Str_8& id);
|
|
||||||
|
|
||||||
void AddSection(ELF64_Section newSection);
|
|
||||||
|
|
||||||
ehs::Serializer<ehs::UInt_64> Serialize() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void InitializeSections();
|
|
||||||
|
|
||||||
ehs::UInt_64 RetrieveSectionsOffset() const;
|
|
||||||
|
|
||||||
ehs::UInt_16 FindShStrTabIndex() const;
|
|
||||||
|
|
||||||
ELF64_Section* FindShStrTab() const;
|
|
||||||
};
|
|
@ -1,55 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <ehs/Serializer.h>
|
|
||||||
|
|
||||||
/// Program types.
|
|
||||||
#define PRGH_TYPE_LOAD 0x00000001
|
|
||||||
|
|
||||||
/// Program flags.
|
|
||||||
#define PRGH_FLAG_EXEC 0x00000001
|
|
||||||
#define PRGH_FLAG_WRITE 0x00000002
|
|
||||||
#define PRGH_FLAG_READ 0x00000004
|
|
||||||
|
|
||||||
#define PRGH_SIZE 56
|
|
||||||
|
|
||||||
class ELF64;
|
|
||||||
|
|
||||||
class ELF64_Program
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
friend class ELF64;
|
|
||||||
|
|
||||||
ELF64* owner;
|
|
||||||
ehs::UInt_16 sectionIndex;
|
|
||||||
ehs::UInt_32 type;
|
|
||||||
ehs::UInt_32 flags;
|
|
||||||
ehs::UInt_64 offset;
|
|
||||||
ehs::UInt_64 vAddr;
|
|
||||||
ehs::UInt_64 pAddr;
|
|
||||||
ehs::UInt_64 fileSize;
|
|
||||||
ehs::UInt_64 adjustedMemSize;
|
|
||||||
ehs::UInt_64 align;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ELF64_Program();
|
|
||||||
|
|
||||||
ELF64_Program(ehs::UInt_16 sectionIndex, ehs::UInt_32 type, ehs::UInt_32 flags, ehs::UInt_64 address, ehs::UInt_64 align);
|
|
||||||
|
|
||||||
ELF64_Program(ehs::Serializer<ehs::UInt_64>& data);
|
|
||||||
|
|
||||||
ELF64_Program(ELF64_Program&& program) noexcept;
|
|
||||||
|
|
||||||
ELF64_Program(const ELF64_Program& program);
|
|
||||||
|
|
||||||
ELF64_Program& operator=(ELF64_Program&& program) noexcept;
|
|
||||||
|
|
||||||
ELF64_Program& operator=(const ELF64_Program& program);
|
|
||||||
|
|
||||||
ehs::UInt_32 GetType() const;
|
|
||||||
|
|
||||||
ehs::UInt_32 GetFlags() const;
|
|
||||||
|
|
||||||
ehs::UInt_64 GetAlign() const;
|
|
||||||
|
|
||||||
void Serialize(ehs::Serializer<ehs::UInt_64>& inData) const;
|
|
||||||
};
|
|
@ -1,68 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <ehs/Serializer.h>
|
|
||||||
#include <ehs/Array.h>
|
|
||||||
#include <ehs/Str.h>
|
|
||||||
|
|
||||||
/// Section types.
|
|
||||||
#define SECH_TYPE_NULL 0x0000
|
|
||||||
#define SECH_TYPE_PROGBITS 0x0001
|
|
||||||
#define SECH_TYPE_STRTAB 0x0003
|
|
||||||
|
|
||||||
/// Section flags.
|
|
||||||
#define SECH_FLAG_ALLOC 0x02
|
|
||||||
#define SECH_FLAG_EXEC 0x04
|
|
||||||
#define SECH_FLAG_STRINGS 0x20
|
|
||||||
|
|
||||||
#define SECH_SIZE 64
|
|
||||||
|
|
||||||
class ELF64_Section
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
friend class ELF64;
|
|
||||||
|
|
||||||
ehs::UInt_64 hashId;
|
|
||||||
ehs::Str_8 id;
|
|
||||||
ehs::UInt_32 programIndex;
|
|
||||||
ehs::UInt_32 nameOffset;
|
|
||||||
ehs::UInt_32 type;
|
|
||||||
ehs::UInt_64 flags;
|
|
||||||
ehs::UInt_64 vAddr;
|
|
||||||
ehs::UInt_64 segmentOffset;
|
|
||||||
ehs::UInt_32 associatedIndex;
|
|
||||||
ehs::UInt_32 info;
|
|
||||||
ehs::UInt_64 align;
|
|
||||||
ehs::UInt_64 entrySize;
|
|
||||||
ehs::Serializer<ehs::UInt_64> data;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ELF64_Section();
|
|
||||||
|
|
||||||
ELF64_Section(ehs::Str_8 id, ehs::UInt_32 type, ehs::UInt_64 flags, ehs::UInt_64 align);
|
|
||||||
|
|
||||||
ELF64_Section(ELF64_Section&& sect) noexcept;
|
|
||||||
|
|
||||||
ELF64_Section(const ELF64_Section& sect);
|
|
||||||
|
|
||||||
ELF64_Section& operator=(ELF64_Section&& sect) noexcept;
|
|
||||||
|
|
||||||
ELF64_Section& operator=(const ELF64_Section& sect);
|
|
||||||
|
|
||||||
ehs::UInt_64 GetHashId() const;
|
|
||||||
|
|
||||||
ehs::Str_8 GetId() const;
|
|
||||||
|
|
||||||
ehs::UInt_32 GetType() const;
|
|
||||||
|
|
||||||
ehs::UInt_64 GetFlags() const;
|
|
||||||
|
|
||||||
ehs::UInt_64 GetVirtualAddress() const;
|
|
||||||
|
|
||||||
ehs::UInt_64 GetAlignment() const;
|
|
||||||
|
|
||||||
void SetData(ehs::Serializer<ehs::UInt_64> newData);
|
|
||||||
|
|
||||||
ehs::Serializer<ehs::UInt_64>& GetData();
|
|
||||||
|
|
||||||
void Serialize(ehs::Serializer<ehs::UInt_64>& inData) const;
|
|
||||||
};
|
|
61
src/ELF.cpp
Normal file
61
src/ELF.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "ELF.h"
|
||||||
|
|
||||||
|
constexpr ehs::Char_8 Elf_Magic[] = "\x7F" "ELF";
|
||||||
|
constexpr ehs::UInt_8 Elf_Magic_Size = sizeof(Elf_Magic) - 1;
|
||||||
|
|
||||||
|
void WriteHeader(const ElfHeader& header, ehs::Serializer<ehs::UInt_64>& data)
|
||||||
|
{
|
||||||
|
data.Resize(Elf_Magic_Size);
|
||||||
|
ehs::Util::Copy(&data[0], Elf_Magic, Elf_Magic_Size);
|
||||||
|
data.SetOffset(Elf_Magic_Size);
|
||||||
|
|
||||||
|
data.Write(header.architecture);
|
||||||
|
data.Write(header.endianness);
|
||||||
|
data.Write(header.elfV1);
|
||||||
|
data.Write(header.targetABI);
|
||||||
|
data.Write(header.abiV);
|
||||||
|
|
||||||
|
data.Resize(data.Size() + 7);
|
||||||
|
ehs::Util::Zero(&data[data.GetOffset()], 7);
|
||||||
|
data.SetOffset(data.GetOffset() + 7);
|
||||||
|
|
||||||
|
data.Write(header.elfType);
|
||||||
|
data.Write(header.machineArch);
|
||||||
|
data.Write(header.elfV2);
|
||||||
|
data.Write(header.entryAddress);
|
||||||
|
data.Write(header.programsOffset);
|
||||||
|
data.Write(header.sectionsOffset);
|
||||||
|
data.Write(header.flags);
|
||||||
|
data.Write(header.headerSize);
|
||||||
|
data.Write(header.pHeaderSize);
|
||||||
|
data.Write(header.pEntries);
|
||||||
|
data.Write(header.sSize);
|
||||||
|
data.Write(header.sEntries);
|
||||||
|
data.Write(header.strTabIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteHeader(const ElfPrgHeader& header, ehs::Serializer<ehs::UInt_64>& data)
|
||||||
|
{
|
||||||
|
data.Write(header.type);
|
||||||
|
data.Write(header.flags);
|
||||||
|
data.Write(header.offset);
|
||||||
|
data.Write(header.vAddr);
|
||||||
|
data.Write(header.pAddr);
|
||||||
|
data.Write(header.fileSize);
|
||||||
|
data.Write(header.memSize);
|
||||||
|
data.Write(header.align);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteHeader(const ElfSecHeader& header, ehs::Serializer<ehs::UInt_64>& data)
|
||||||
|
{
|
||||||
|
data.Write(header.index);
|
||||||
|
data.Write(header.type);
|
||||||
|
data.Write(header.flags);
|
||||||
|
data.Write(header.vAddr);
|
||||||
|
data.Write(header.offset);
|
||||||
|
data.Write(header.size);
|
||||||
|
data.Write(header.associatedIndex);
|
||||||
|
data.Write(header.info);
|
||||||
|
data.Write(header.align);
|
||||||
|
data.Write(header.entrySize);
|
||||||
|
}
|
317
src/ELF64.cpp
317
src/ELF64.cpp
@ -1,317 +0,0 @@
|
|||||||
#include "ELF64.h"
|
|
||||||
|
|
||||||
constexpr ehs::Char_8 Elf_Magic[] = "\x7F" "ELF";
|
|
||||||
constexpr ehs::UInt_8 Elf_Magic_Size = sizeof(Elf_Magic) - 1;
|
|
||||||
|
|
||||||
ELF64::ELF64()
|
|
||||||
: subArch(ELFH_ARCH_64), endianness(ELFH_END_LE), abi(ELFH_ABI_SYSTEMV), type(ELFH_TYPE_EXEC),
|
|
||||||
arch(ELFH_MARCH_AMD_X86_64), entryPoint(0)
|
|
||||||
{
|
|
||||||
InitializeSections();
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64::ELF64(ehs::UInt_8 subArch, ehs::UInt_8 end, ehs::UInt_8 abi, ehs::UInt_16 type, ehs::UInt_16 arch)
|
|
||||||
: subArch(subArch), endianness(end), abi(abi), type(type), arch(arch), entryPoint(0)
|
|
||||||
{
|
|
||||||
InitializeSections();
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64::ELF64(ehs::Serializer<ehs::UInt_64>& data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64::ELF64(ELF64&& header) noexcept
|
|
||||||
: subArch(header.subArch), endianness(header.endianness), abi(header.abi), type(header.type), arch(header.arch),
|
|
||||||
entryPoint(header.entryPoint), programs((ehs::Vector<ELF64_Program, ehs::UInt_16>&&)header.programs),
|
|
||||||
sections((ehs::Vector<ELF64_Section, ehs::UInt_16>&&)header.sections)
|
|
||||||
{
|
|
||||||
header.subArch = ELFH_ARCH_64;
|
|
||||||
header.endianness = ELFH_END_LE;
|
|
||||||
header.abi = ELFH_ABI_SYSTEMV;
|
|
||||||
header.type = ELFH_TYPE_EXEC;
|
|
||||||
header.arch = ELFH_MARCH_AMD_X86_64;
|
|
||||||
header.entryPoint = 0;
|
|
||||||
|
|
||||||
header.InitializeSections();
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64::ELF64(const ELF64& header)
|
|
||||||
: subArch(header.subArch), endianness(header.endianness), abi(header.abi), type(header.type), arch(header.arch),
|
|
||||||
entryPoint(header.entryPoint), programs(header.programs), sections(header.sections)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64& ELF64::operator=(ELF64&& header) noexcept
|
|
||||||
{
|
|
||||||
if (this == &header)
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
subArch = header.subArch;
|
|
||||||
endianness = header.endianness;
|
|
||||||
abi = header.abi;
|
|
||||||
type = header.type;
|
|
||||||
arch = header.arch;
|
|
||||||
entryPoint = header.entryPoint;
|
|
||||||
programs = (ehs::Vector<ELF64_Program, ehs::UInt_16>&&)header.programs;
|
|
||||||
sections = (ehs::Vector<ELF64_Section, ehs::UInt_16>&&)header.sections;
|
|
||||||
|
|
||||||
header.subArch = ELFH_ARCH_64;
|
|
||||||
header.endianness = ELFH_END_LE;
|
|
||||||
header.abi = ELFH_ABI_SYSTEMV;
|
|
||||||
header.type = ELFH_TYPE_EXEC;
|
|
||||||
header.arch = ELFH_MARCH_AMD_X86_64;
|
|
||||||
header.entryPoint = 0;
|
|
||||||
|
|
||||||
header.InitializeSections();
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64& ELF64::operator=(const ELF64& header)
|
|
||||||
{
|
|
||||||
if (this == &header)
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
subArch = header.subArch;
|
|
||||||
endianness = header.endianness;
|
|
||||||
abi = header.abi;
|
|
||||||
type = header.type;
|
|
||||||
arch = header.arch;
|
|
||||||
entryPoint = header.entryPoint;
|
|
||||||
programs = header.programs;
|
|
||||||
sections = header.sections;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_8 ELF64::GetSubArchitecture() const
|
|
||||||
{
|
|
||||||
return subArch;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_8 ELF64::GetEndianness() const
|
|
||||||
{
|
|
||||||
return endianness;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_8 ELF64::GetABI() const
|
|
||||||
{
|
|
||||||
return abi;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_16 ELF64::GetType() const
|
|
||||||
{
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_16 ELF64::GetArchitecture() const
|
|
||||||
{
|
|
||||||
return arch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ELF64::SetEntryPoint(ehs::UInt_16 programIndex)
|
|
||||||
{
|
|
||||||
if (programIndex > programs.End())
|
|
||||||
{
|
|
||||||
EHS_LOG("Warning", 0, "The given index, \"" + ehs::Str_8::FromNum(programIndex) +
|
|
||||||
"\", is outside the bounds of, \"" + ehs::Str_8::FromNum(programs.End()) + "\".");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
entryPoint = programIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Program* ELF64::GetEntryPoint() const
|
|
||||||
{
|
|
||||||
return &programs[entryPoint];
|
|
||||||
}
|
|
||||||
|
|
||||||
void ELF64::AddProgram(ELF64_Program newProgram)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
for (ehs::UInt_16 i = 0; i < programs.Size(); i++)
|
|
||||||
{
|
|
||||||
if (programs[i].fileSize < newProgram.fileSize)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
EHS_LOG("Warning", 0, "The new program file size, \"" + ehs::Str_8::FromNum(newProgram.fileSize) +
|
|
||||||
"\" must be greater than, \"" + ehs::Str_8::FromNum(programs[i].fileSize) + "\".");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
newProgram.owner = this;
|
|
||||||
|
|
||||||
if (programs.Size())
|
|
||||||
sections[newProgram.sectionIndex].programIndex = programs.End() + 1;
|
|
||||||
else
|
|
||||||
sections[newProgram.sectionIndex].programIndex = programs.End();
|
|
||||||
|
|
||||||
programs.Push((ELF64_Program&&)newProgram);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ELF64::HasSection(ehs::UInt_64 hashId)
|
|
||||||
{
|
|
||||||
for (ehs::UInt_16 i = 0; i < sections.Size(); i++)
|
|
||||||
if (sections[i].GetHashId() == hashId)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ELF64::HasSection(ehs::Str_8& id)
|
|
||||||
{
|
|
||||||
return HasSection(id.Hash_64());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ELF64::AddSection(ELF64_Section newSection)
|
|
||||||
{
|
|
||||||
if (HasSection(newSection.GetHashId()))
|
|
||||||
{
|
|
||||||
EHS_LOG("Warning", 0, "The section, \"" + newSection.GetId() + "\", already exists.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::Str_8 newId = newSection.GetId();
|
|
||||||
|
|
||||||
ELF64_Section* shStrTab = FindShStrTab();
|
|
||||||
ehs::Serializer<ehs::UInt_64>& data = shStrTab->GetData();
|
|
||||||
|
|
||||||
newSection.nameOffset = data.GetOffset();
|
|
||||||
|
|
||||||
data.Resize(data.Size() + newId.Size() + 1);
|
|
||||||
ehs::Util::Copy(&data[data.GetOffset()], &newId[0], newId.Size());
|
|
||||||
data.SetOffset(data.GetOffset() + newId.Size());
|
|
||||||
data.Write('\0');
|
|
||||||
|
|
||||||
sections.Push((ELF64_Section&&)newSection);
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::Serializer<ehs::UInt_64> ELF64::Serialize() const
|
|
||||||
{
|
|
||||||
ehs::Serializer<ehs::UInt_64> result(ehs::Endianness::LE);
|
|
||||||
result.Resize(Elf_Magic_Size);
|
|
||||||
ehs::Util::Copy(&result[0], Elf_Magic, Elf_Magic_Size);
|
|
||||||
result.SetOffset(Elf_Magic_Size);
|
|
||||||
|
|
||||||
result.Write(subArch);
|
|
||||||
result.Write(endianness);
|
|
||||||
result.Write<ehs::UInt_8>(1);
|
|
||||||
result.Write(abi);
|
|
||||||
result.Write<ehs::UInt_8>(0);
|
|
||||||
|
|
||||||
result.Resize(result.Size() + 7);
|
|
||||||
ehs::Util::Zero(&result[result.GetOffset()], 7);
|
|
||||||
result.SetOffset(result.GetOffset() + 7);
|
|
||||||
|
|
||||||
result.Write(type);
|
|
||||||
result.Write(arch);
|
|
||||||
result.Write<ehs::UInt_32>(1);
|
|
||||||
|
|
||||||
ehs::UInt_64 entryAddress = result.GetOffset();
|
|
||||||
result.Write<ehs::UInt_64>(0);
|
|
||||||
|
|
||||||
result.Write<ehs::UInt_64>(ELFH_SIZE);
|
|
||||||
result.Write(RetrieveSectionsOffset());
|
|
||||||
result.Write<ehs::UInt_32>(0);
|
|
||||||
result.Write<ehs::UInt_16>(ELFH_SIZE);
|
|
||||||
result.Write<ehs::UInt_16>(PRGH_SIZE);
|
|
||||||
result.Write(programs.Size());
|
|
||||||
result.Write<ehs::UInt_16>(SECH_SIZE);
|
|
||||||
result.Write(sections.Size());
|
|
||||||
result.Write(FindShStrTabIndex());
|
|
||||||
|
|
||||||
ehs::Array<ehs::Serializer<ehs::UInt_64>, ehs::UInt_16> segmentData(sections.Size());
|
|
||||||
ehs::UInt_64 segmentOffset = 0;
|
|
||||||
const ehs::UInt_64 programsSize = PRGH_SIZE * programs.Size();
|
|
||||||
|
|
||||||
for (ehs::UInt_16 i = 1; i < sections.Size(); i++)
|
|
||||||
{
|
|
||||||
sections[i].segmentOffset = result.GetOffset() + programsSize + segmentOffset;
|
|
||||||
segmentData[i] = sections[i].GetData();
|
|
||||||
|
|
||||||
if (sections[i].programIndex < EHS_UINT_16_MAX + 1)
|
|
||||||
{
|
|
||||||
sections[i].vAddr = programs[entryPoint].pAddr + result.GetOffset() + programsSize + segmentOffset;
|
|
||||||
programs[sections[i].programIndex].fileSize =
|
|
||||||
result.GetOffset() + programsSize + segmentOffset + segmentData[i].Size();
|
|
||||||
}
|
|
||||||
|
|
||||||
segmentOffset += segmentData[i].Size();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ehs::UInt_16 i = 0; i < programs.Size(); i++)
|
|
||||||
programs[i].Serialize(result);
|
|
||||||
|
|
||||||
for (ehs::UInt_16 i = 0; i < segmentData.Size(); i++)
|
|
||||||
result.WriteSer(segmentData[i]);
|
|
||||||
|
|
||||||
for (ehs::UInt_16 i = 0; i < sections.Size(); i++)
|
|
||||||
sections[i].Serialize(result);
|
|
||||||
|
|
||||||
*(ehs::UInt_64*)(&result[entryAddress]) = programs[entryPoint].pAddr + sections[programs[entryPoint].sectionIndex].segmentOffset;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ELF64::InitializeSections()
|
|
||||||
{
|
|
||||||
ehs::Str_8 nullName = ".NULL";
|
|
||||||
|
|
||||||
ELF64_Section null(nullName, SECH_TYPE_NULL, 0, 0);
|
|
||||||
|
|
||||||
ehs::Str_8 shStrTabName = ".shstrtab";
|
|
||||||
|
|
||||||
ELF64_Section shStrTab(shStrTabName, SECH_TYPE_STRTAB, SECH_FLAG_STRINGS, 1);
|
|
||||||
|
|
||||||
ehs::Serializer<ehs::UInt_64>& data = shStrTab.GetData();
|
|
||||||
|
|
||||||
data.Resize(nullName.Size() + shStrTabName.Size() + 2);
|
|
||||||
|
|
||||||
null.nameOffset = data.GetOffset();
|
|
||||||
ehs::Util::Copy(&data[data.GetOffset()], &nullName[0], nullName.Size());
|
|
||||||
data.SetOffset(data.GetOffset() + nullName.Size());
|
|
||||||
data.Write('\0');
|
|
||||||
|
|
||||||
shStrTab.nameOffset = data.GetOffset();
|
|
||||||
ehs::Util::Copy(&data[data.GetOffset()], &shStrTabName[0], shStrTabName.Size());
|
|
||||||
data.SetOffset(data.GetOffset() + shStrTabName.Size());
|
|
||||||
data.Write('\0');
|
|
||||||
|
|
||||||
sections.Push((ELF64_Section&&)null);
|
|
||||||
sections.Push((ELF64_Section&&)shStrTab);
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_64 ELF64::RetrieveSectionsOffset() const
|
|
||||||
{
|
|
||||||
ehs::UInt_64 result = ELFH_SIZE + PRGH_SIZE * programs.Size();
|
|
||||||
|
|
||||||
for (ehs::UInt_16 i = 0; i < sections.Size(); i++)
|
|
||||||
result += sections[i].GetData().Size();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_16 ELF64::FindShStrTabIndex() const
|
|
||||||
{
|
|
||||||
for (ehs::UInt_16 i = 0; i < sections.Size(); i++)
|
|
||||||
if (sections[i].GetHashId() == 7974729948679187860ull)
|
|
||||||
return i;
|
|
||||||
|
|
||||||
EHS_LOG("Error", 0, "Could not find the \".shstrtab\" index.");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Section* ELF64::FindShStrTab() const
|
|
||||||
{
|
|
||||||
for (ehs::UInt_16 i = 0; i < sections.Size(); i++)
|
|
||||||
if (sections[i].GetHashId() == 7974729948679187860ull)
|
|
||||||
return §ions[i];
|
|
||||||
|
|
||||||
EHS_LOG("Error", 0, "Could not find the \".shstrtab\".");
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
@ -1,119 +0,0 @@
|
|||||||
#include "ELF64_Program.h"
|
|
||||||
|
|
||||||
ELF64_Program::ELF64_Program()
|
|
||||||
: owner(nullptr), sectionIndex(0), type(PRGH_TYPE_LOAD), flags(PRGH_FLAG_EXEC | PRGH_FLAG_READ), offset(0), vAddr(0),
|
|
||||||
pAddr(0), fileSize(0), adjustedMemSize(0), align(0x200000)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Program::ELF64_Program(ehs::UInt_16 sectionIndex, ehs::UInt_32 type, ehs::UInt_32 flags, ehs::UInt_64 address, ehs::UInt_64 align)
|
|
||||||
: owner(nullptr), sectionIndex(sectionIndex), type(type), flags(flags), offset(0), vAddr(address), pAddr(address),
|
|
||||||
fileSize(0), adjustedMemSize(0), align(align)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Program::ELF64_Program(ehs::Serializer<ehs::UInt_64>& data)
|
|
||||||
: owner(nullptr), sectionIndex(0), type(PRGH_TYPE_LOAD), flags(PRGH_FLAG_EXEC | PRGH_FLAG_READ), offset(0), vAddr(0),
|
|
||||||
pAddr(0), fileSize(0), adjustedMemSize(0), align(0x200000)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Program::ELF64_Program(ELF64_Program&& program) noexcept
|
|
||||||
: owner(program.owner), sectionIndex(program.sectionIndex), type(program.type), flags(program.flags),
|
|
||||||
offset(program.offset), vAddr(program.vAddr), pAddr(program.pAddr), fileSize(program.fileSize),
|
|
||||||
adjustedMemSize(program.adjustedMemSize), align(program.align)
|
|
||||||
{
|
|
||||||
program.owner = nullptr;
|
|
||||||
program.sectionIndex = 0;
|
|
||||||
program.type = PRGH_TYPE_LOAD;
|
|
||||||
program.flags = PRGH_FLAG_EXEC | PRGH_FLAG_READ;
|
|
||||||
program.offset = 0;
|
|
||||||
program.vAddr = 0;
|
|
||||||
program.pAddr = 0;
|
|
||||||
program.fileSize = 0;
|
|
||||||
program.adjustedMemSize = 0;
|
|
||||||
program.align = 0x200000;
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Program::ELF64_Program(const ELF64_Program& program)
|
|
||||||
: owner(nullptr), sectionIndex(0), type(program.type), flags(program.flags),
|
|
||||||
offset(program.offset), vAddr(program.vAddr), pAddr(program.pAddr), fileSize(program.fileSize),
|
|
||||||
adjustedMemSize(program.adjustedMemSize), align(program.align)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Program& ELF64_Program::operator=(ELF64_Program&& program) noexcept
|
|
||||||
{
|
|
||||||
if (this == &program)
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
owner = program.owner;
|
|
||||||
sectionIndex = program.sectionIndex;
|
|
||||||
type = program.type;
|
|
||||||
flags = program.flags;
|
|
||||||
offset = program.offset;
|
|
||||||
vAddr = program.vAddr;
|
|
||||||
pAddr = program.pAddr;
|
|
||||||
fileSize = program.fileSize;
|
|
||||||
adjustedMemSize = program.adjustedMemSize;
|
|
||||||
align = program.align;
|
|
||||||
|
|
||||||
program.owner = nullptr;
|
|
||||||
program.sectionIndex = 0;
|
|
||||||
program.type = PRGH_TYPE_LOAD;
|
|
||||||
program.flags = PRGH_FLAG_EXEC | PRGH_FLAG_READ;
|
|
||||||
program.offset = 0;
|
|
||||||
program.vAddr = 0;
|
|
||||||
program.pAddr = 0;
|
|
||||||
program.fileSize = 0;
|
|
||||||
program.adjustedMemSize = 0;
|
|
||||||
program.align = 0x200000;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Program& ELF64_Program::operator=(const ELF64_Program& program)
|
|
||||||
{
|
|
||||||
if (this == &program)
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
owner = nullptr;
|
|
||||||
sectionIndex = program.sectionIndex;
|
|
||||||
type = program.type;
|
|
||||||
flags = program.flags;
|
|
||||||
offset = program.offset;
|
|
||||||
vAddr = program.vAddr;
|
|
||||||
pAddr = program.pAddr;
|
|
||||||
fileSize = program.fileSize;
|
|
||||||
adjustedMemSize = program.adjustedMemSize;
|
|
||||||
align = program.align;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_32 ELF64_Program::GetType() const
|
|
||||||
{
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_32 ELF64_Program::GetFlags() const
|
|
||||||
{
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_64 ELF64_Program::GetAlign() const
|
|
||||||
{
|
|
||||||
return align;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ELF64_Program::Serialize(ehs::Serializer<ehs::UInt_64>& inData) const
|
|
||||||
{
|
|
||||||
inData.Write(type);
|
|
||||||
inData.Write(flags);
|
|
||||||
inData.Write(offset);
|
|
||||||
inData.Write(vAddr);
|
|
||||||
inData.Write(pAddr);
|
|
||||||
inData.Write(fileSize);
|
|
||||||
inData.Write(fileSize + adjustedMemSize);
|
|
||||||
inData.Write(align);
|
|
||||||
}
|
|
@ -1,151 +0,0 @@
|
|||||||
#include "ELF64_Section.h"
|
|
||||||
|
|
||||||
ELF64_Section::ELF64_Section()
|
|
||||||
: hashId(0), programIndex(EHS_UINT_16_MAX + 1), nameOffset(0), type(0), flags(0), vAddr(0), segmentOffset(0), associatedIndex(0),
|
|
||||||
info(0), align(0), entrySize(0), data(ehs::Endianness::LE)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Section::ELF64_Section(ehs::Str_8 id, ehs::UInt_32 type, ehs::UInt_64 flags, ehs::UInt_64 align)
|
|
||||||
: hashId(id.Hash_64()), id((ehs::Str_8&&)id), programIndex(EHS_UINT_16_MAX + 1), nameOffset(0), type(type), flags(flags), vAddr(0),
|
|
||||||
segmentOffset(0), associatedIndex(0), info(0), align(align), entrySize(0), data(ehs::Endianness::LE)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Section::ELF64_Section(ELF64_Section&& sect) noexcept
|
|
||||||
: hashId(sect.hashId), id((ehs::Str_8&&)sect.id), programIndex(sect.programIndex), nameOffset(sect.nameOffset),
|
|
||||||
type(sect.type), flags(sect.flags), vAddr(sect.vAddr), segmentOffset(sect.segmentOffset),
|
|
||||||
associatedIndex(sect.associatedIndex), info(sect.info), align(sect.align), entrySize(sect.entrySize),
|
|
||||||
data((ehs::Serializer<ehs::UInt_64>&&)sect.data)
|
|
||||||
{
|
|
||||||
sect.hashId = 0;
|
|
||||||
sect.programIndex = EHS_UINT_16_MAX + 1;
|
|
||||||
sect.nameOffset = 0;
|
|
||||||
sect.type = 0;
|
|
||||||
sect.flags = 0;
|
|
||||||
sect.vAddr = 0;
|
|
||||||
sect.segmentOffset = 0;
|
|
||||||
sect.associatedIndex = 0;
|
|
||||||
sect.info = 0;
|
|
||||||
sect.align = 0;
|
|
||||||
sect.entrySize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Section::ELF64_Section(const ELF64_Section& sect)
|
|
||||||
: hashId(sect.hashId), id(sect.id), programIndex(EHS_UINT_16_MAX + 1), nameOffset(0), type(sect.type),
|
|
||||||
flags(sect.flags), vAddr(sect.vAddr), segmentOffset(sect.segmentOffset), associatedIndex(sect.associatedIndex),
|
|
||||||
info(sect.info), align(sect.align), entrySize(sect.entrySize), data(sect.data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Section& ELF64_Section::operator=(ELF64_Section&& sect) noexcept
|
|
||||||
{
|
|
||||||
if (this == §)
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
hashId = sect.hashId;
|
|
||||||
id = (ehs::Str_8&&)sect.id;
|
|
||||||
programIndex = sect.programIndex;
|
|
||||||
nameOffset = sect.nameOffset;
|
|
||||||
type = sect.type;
|
|
||||||
flags = sect.flags;
|
|
||||||
vAddr = sect.vAddr;
|
|
||||||
segmentOffset = sect.segmentOffset;
|
|
||||||
associatedIndex = sect.associatedIndex;
|
|
||||||
info = sect.info;
|
|
||||||
align = sect.align;
|
|
||||||
entrySize = sect.entrySize;
|
|
||||||
data = (ehs::Serializer<ehs::UInt_64>&&)sect.data;
|
|
||||||
|
|
||||||
sect.hashId = 0;
|
|
||||||
sect.programIndex = EHS_UINT_16_MAX + 1;
|
|
||||||
sect.nameOffset = 0;
|
|
||||||
sect.type = 0;
|
|
||||||
sect.flags = 0;
|
|
||||||
sect.vAddr = 0;
|
|
||||||
sect.segmentOffset = 0;
|
|
||||||
sect.associatedIndex = 0;
|
|
||||||
sect.info = 0;
|
|
||||||
sect.align = 0;
|
|
||||||
sect.entrySize = 0;
|
|
||||||
sect.data = {ehs::Endianness::LE};
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ELF64_Section& ELF64_Section::operator=(const ELF64_Section& sect)
|
|
||||||
{
|
|
||||||
if (this == §)
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
hashId = sect.hashId;
|
|
||||||
id = sect.id;
|
|
||||||
programIndex = EHS_UINT_16_MAX + 1;
|
|
||||||
nameOffset = 0;
|
|
||||||
type = sect.type;
|
|
||||||
flags = sect.flags;
|
|
||||||
vAddr = sect.vAddr;
|
|
||||||
segmentOffset = sect.segmentOffset;
|
|
||||||
associatedIndex = sect.associatedIndex;
|
|
||||||
info = sect.info;
|
|
||||||
align = sect.align;
|
|
||||||
entrySize = sect.entrySize;
|
|
||||||
data = sect.data;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_64 ELF64_Section::GetHashId() const
|
|
||||||
{
|
|
||||||
return hashId;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::Str_8 ELF64_Section::GetId() const
|
|
||||||
{
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_32 ELF64_Section::GetType() const
|
|
||||||
{
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_64 ELF64_Section::GetFlags() const
|
|
||||||
{
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_64 ELF64_Section::GetVirtualAddress() const
|
|
||||||
{
|
|
||||||
return vAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::UInt_64 ELF64_Section::GetAlignment() const
|
|
||||||
{
|
|
||||||
return align;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ELF64_Section::SetData(ehs::Serializer<ehs::UInt_64> newData)
|
|
||||||
{
|
|
||||||
data = (ehs::Serializer<ehs::UInt_64>&&)newData;
|
|
||||||
}
|
|
||||||
|
|
||||||
ehs::Serializer<ehs::UInt_64>& ELF64_Section::GetData()
|
|
||||||
{
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ELF64_Section::Serialize(ehs::Serializer<ehs::UInt_64>& inData) const
|
|
||||||
{
|
|
||||||
inData.Write(nameOffset);
|
|
||||||
inData.Write(type);
|
|
||||||
inData.Write(flags);
|
|
||||||
inData.Write(vAddr);
|
|
||||||
inData.Write(segmentOffset);
|
|
||||||
inData.Write(data.Size());
|
|
||||||
inData.Write(associatedIndex);
|
|
||||||
inData.Write(info);
|
|
||||||
inData.Write(align);
|
|
||||||
inData.Write(entrySize);
|
|
||||||
}
|
|
90
src/main.cpp
90
src/main.cpp
@ -1,4 +1,4 @@
|
|||||||
#include "ELF64.h"
|
#include "ELF.h"
|
||||||
|
|
||||||
#include <ehs/EHS.h>
|
#include <ehs/EHS.h>
|
||||||
#include <ehs/io/Console.h>
|
#include <ehs/io/Console.h>
|
||||||
@ -23,16 +23,92 @@ ehs::SInt_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVe
|
|||||||
ehs::Serializer<ehs::UInt_64> code = codeFile.ReadSerializer_64(ehs::Endianness::LE, codeFile.Size());
|
ehs::Serializer<ehs::UInt_64> code = codeFile.ReadSerializer_64(ehs::Endianness::LE, codeFile.Size());
|
||||||
codeFile.Release();
|
codeFile.Release();
|
||||||
|
|
||||||
ELF64 executable(ELFH_ARCH_64, ELFH_END_LE, ELFH_ABI_SYSTEMV, ELFH_TYPE_EXEC, ELFH_MARCH_AMD_X86_64);
|
char sections[] = "\0.text\0.shstrtab\0";
|
||||||
|
|
||||||
ELF64_Section text(".text", SECH_TYPE_PROGBITS, SECH_FLAG_ALLOC | SECH_FLAG_EXEC, 16);
|
ElfHeader elfHeader = {};
|
||||||
text.SetData(code);
|
elfHeader.architecture = ELFH_ARCH_64;
|
||||||
executable.AddSection(text);
|
elfHeader.endianness = ELFH_END_LE;
|
||||||
|
elfHeader.elfV1 = 1;
|
||||||
|
elfHeader.targetABI = ELFH_ABI_SYSTEMV;
|
||||||
|
elfHeader.abiV = 0;
|
||||||
|
elfHeader.elfType = ELFH_TYPE_EXEC;
|
||||||
|
elfHeader.machineArch = ELFH_MARCH_AMD_X86_64;
|
||||||
|
elfHeader.elfV2 = 1;
|
||||||
|
elfHeader.entryAddress = 0x400000 + ELFH_SIZE + PRGH_SIZE;
|
||||||
|
elfHeader.programsOffset = ELFH_SIZE;
|
||||||
|
elfHeader.sectionsOffset = ELFH_SIZE + PRGH_SIZE + code.Size() + sizeof(sections);
|
||||||
|
elfHeader.flags = 0;
|
||||||
|
elfHeader.headerSize = ELFH_SIZE;
|
||||||
|
elfHeader.pHeaderSize = PRGH_SIZE;
|
||||||
|
elfHeader.pEntries = 1;
|
||||||
|
elfHeader.sSize = SECH_SIZE;
|
||||||
|
elfHeader.sEntries = 3;
|
||||||
|
elfHeader.strTabIndex = 2;
|
||||||
|
|
||||||
executable.AddProgram({2, PRGH_TYPE_LOAD, PRGH_FLAG_EXEC | PRGH_FLAG_READ, 0x400000, 0x200000});
|
ElfPrgHeader programHeader = {};
|
||||||
|
programHeader.type = PRGH_TYPE_LOAD;
|
||||||
|
programHeader.flags = PRGH_FLAG_EXEC | PRGH_FLAG_READ;
|
||||||
|
programHeader.offset = 0;
|
||||||
|
programHeader.vAddr = 0x400000;
|
||||||
|
programHeader.pAddr = 0x400000;
|
||||||
|
programHeader.fileSize = ELFH_SIZE + PRGH_SIZE + code.Size();
|
||||||
|
programHeader.memSize = ELFH_SIZE + PRGH_SIZE + code.Size();
|
||||||
|
programHeader.align = 0x200000;
|
||||||
|
|
||||||
|
ElfSecHeader null = {};
|
||||||
|
null.index = 0;
|
||||||
|
null.type = SECH_TYPE_NULL;
|
||||||
|
null.flags = 0;
|
||||||
|
null.vAddr = 0;
|
||||||
|
null.offset = 0;
|
||||||
|
null.size = 0;
|
||||||
|
null.associatedIndex = 0;
|
||||||
|
null.info = 0;
|
||||||
|
null.align = 0;
|
||||||
|
null.entrySize = 0;
|
||||||
|
|
||||||
|
ElfSecHeader text = {};
|
||||||
|
text.index = 1;
|
||||||
|
text.type = SECH_TYPE_PROGBITS;
|
||||||
|
text.flags = SECH_FLAG_ALLOC | SECH_FLAG_EXEC;
|
||||||
|
text.vAddr = 0x400000 + ELFH_SIZE + PRGH_SIZE;
|
||||||
|
text.offset = ELFH_SIZE + PRGH_SIZE;
|
||||||
|
text.size = sizeof(code.Size());
|
||||||
|
text.associatedIndex = 0;
|
||||||
|
text.info = 0;
|
||||||
|
text.align = 16;
|
||||||
|
text.entrySize = 0;
|
||||||
|
|
||||||
|
ElfSecHeader strTbl = {};
|
||||||
|
strTbl.index = 7;
|
||||||
|
strTbl.type = SECH_TYPE_STRTAB;
|
||||||
|
strTbl.flags = SECH_FLAG_STRINGS;
|
||||||
|
strTbl.vAddr = 0;
|
||||||
|
strTbl.offset = ELFH_SIZE + PRGH_SIZE + code.Size();
|
||||||
|
strTbl.size = sizeof(sections);
|
||||||
|
strTbl.associatedIndex = 0;
|
||||||
|
strTbl.info = 0;
|
||||||
|
strTbl.align = 0;
|
||||||
|
strTbl.entrySize = 0;
|
||||||
|
|
||||||
|
ehs::Serializer<ehs::UInt_64> data(ehs::Endianness::LE);
|
||||||
|
WriteHeader(elfHeader, data);
|
||||||
|
WriteHeader(programHeader, data);
|
||||||
|
|
||||||
|
data.Resize(data.Size() + code.Size());
|
||||||
|
ehs::Util::Copy(&data[data.GetOffset()], code, code.Size());
|
||||||
|
data.SetOffset(data.GetOffset() + code.Size());
|
||||||
|
|
||||||
|
data.Resize(data.Size() + sizeof(sections));
|
||||||
|
ehs::Util::Copy(&data[data.GetOffset()], sections, sizeof(sections));
|
||||||
|
data.SetOffset(data.GetOffset() + sizeof(sections));
|
||||||
|
|
||||||
|
WriteHeader(null, data);
|
||||||
|
WriteHeader(text, data);
|
||||||
|
WriteHeader(strTbl, data);
|
||||||
|
|
||||||
ehs::File file(args[2].RemoveAll("\""), ehs::Mode::WRITE, ehs::Disposition::CREATE_PERSISTENT);
|
ehs::File file(args[2].RemoveAll("\""), ehs::Mode::WRITE, ehs::Disposition::CREATE_PERSISTENT);
|
||||||
file.WriteSerializer_64(executable.Serialize());
|
file.WriteSerializer_64(data);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user