Skip to content

Commit 18e6326

Browse files
committed
Add elf2rel
1 parent d42b935 commit 18e6326

17 files changed

+5308
-1
lines changed

ttyd-tools/elf2rel/elf2rel.cpp

Lines changed: 442 additions & 0 deletions
Large diffs are not rendered by default.

ttyd-tools/elf2rel/elf2rel.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include <vector>
4+
5+
enum RelRelocationType
6+
{
7+
R_PPC_NONE = 0,
8+
R_PPC_ADDR32,
9+
R_PPC_ADDR24,
10+
R_PPC_ADDR16,
11+
R_PPC_ADDR16_LO,
12+
R_PPC_ADDR16_HI,
13+
R_PPC_ADDR16_HA,
14+
R_PPC_ADDR14,
15+
R_PPC_ADDR14_BRTAKEN,
16+
R_PPC_ADDR14_BRNKTAKEN,
17+
R_PPC_REL24,
18+
R_PPC_REL14,
19+
20+
R_DOLPHIN_NOP = 201,
21+
R_DOLPHIN_SECTION,
22+
R_DOLPHIN_END,
23+
};
24+
25+
template<typename T>
26+
void save(std::vector<uint8_t> &buffer, const T &value)
27+
{
28+
for (size_t i = sizeof(T); i > 0; --i)
29+
{
30+
buffer.emplace_back(static_cast<uint8_t>((value >> (i - 1) * 8) & 0xFF));
31+
}
32+
}

ttyd-tools/elf2rel/elf2rel.vcxproj

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" 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+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ClInclude Include="elf2rel.h" />
23+
<ClInclude Include="elfio\elfio.hpp" />
24+
<ClInclude Include="elfio\elfio_dump.hpp" />
25+
<ClInclude Include="elfio\elfio_dynamic.hpp" />
26+
<ClInclude Include="elfio\elfio_header.hpp" />
27+
<ClInclude Include="elfio\elfio_note.hpp" />
28+
<ClInclude Include="elfio\elfio_relocation.hpp" />
29+
<ClInclude Include="elfio\elfio_section.hpp" />
30+
<ClInclude Include="elfio\elfio_segment.hpp" />
31+
<ClInclude Include="elfio\elfio_strings.hpp" />
32+
<ClInclude Include="elfio\elfio_symbols.hpp" />
33+
<ClInclude Include="elfio\elfio_utils.hpp" />
34+
<ClInclude Include="elfio\elf_types.hpp" />
35+
</ItemGroup>
36+
<ItemGroup>
37+
<ClCompile Include="elf2rel.cpp" />
38+
</ItemGroup>
39+
<PropertyGroup Label="Globals">
40+
<VCProjectVersion>15.0</VCProjectVersion>
41+
<ProjectGuid>{B5BB1531-4352-4B38-837C-C0139A45BDBA}</ProjectGuid>
42+
<RootNamespace>elf2rel</RootNamespace>
43+
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
44+
</PropertyGroup>
45+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
47+
<ConfigurationType>Application</ConfigurationType>
48+
<UseDebugLibraries>true</UseDebugLibraries>
49+
<PlatformToolset>v141</PlatformToolset>
50+
<CharacterSet>MultiByte</CharacterSet>
51+
</PropertyGroup>
52+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
53+
<ConfigurationType>Application</ConfigurationType>
54+
<UseDebugLibraries>false</UseDebugLibraries>
55+
<PlatformToolset>v141</PlatformToolset>
56+
<WholeProgramOptimization>true</WholeProgramOptimization>
57+
<CharacterSet>MultiByte</CharacterSet>
58+
</PropertyGroup>
59+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
60+
<ConfigurationType>Application</ConfigurationType>
61+
<UseDebugLibraries>true</UseDebugLibraries>
62+
<PlatformToolset>v141</PlatformToolset>
63+
<CharacterSet>MultiByte</CharacterSet>
64+
</PropertyGroup>
65+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
66+
<ConfigurationType>Application</ConfigurationType>
67+
<UseDebugLibraries>false</UseDebugLibraries>
68+
<PlatformToolset>v141</PlatformToolset>
69+
<WholeProgramOptimization>true</WholeProgramOptimization>
70+
<CharacterSet>MultiByte</CharacterSet>
71+
</PropertyGroup>
72+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
73+
<ImportGroup Label="ExtensionSettings">
74+
</ImportGroup>
75+
<ImportGroup Label="Shared">
76+
</ImportGroup>
77+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
78+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
79+
</ImportGroup>
80+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
81+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
82+
</ImportGroup>
83+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
84+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
85+
</ImportGroup>
86+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
87+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
88+
</ImportGroup>
89+
<PropertyGroup Label="UserMacros" />
90+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
91+
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
92+
</PropertyGroup>
93+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
94+
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
95+
</PropertyGroup>
96+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
97+
<ClCompile>
98+
<WarningLevel>Level3</WarningLevel>
99+
<Optimization>MaxSpeed</Optimization>
100+
<FunctionLevelLinking>true</FunctionLevelLinking>
101+
<IntrinsicFunctions>true</IntrinsicFunctions>
102+
<SDLCheck>true</SDLCheck>
103+
<ConformanceMode>true</ConformanceMode>
104+
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
105+
</ClCompile>
106+
<Link>
107+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
108+
<OptimizeReferences>true</OptimizeReferences>
109+
<SubSystem>Console</SubSystem>
110+
</Link>
111+
</ItemDefinitionGroup>
112+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
113+
<ClCompile>
114+
<WarningLevel>Level3</WarningLevel>
115+
<Optimization>Disabled</Optimization>
116+
<SDLCheck>true</SDLCheck>
117+
<ConformanceMode>true</ConformanceMode>
118+
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
119+
</ClCompile>
120+
<Link>
121+
<SubSystem>Console</SubSystem>
122+
</Link>
123+
</ItemDefinitionGroup>
124+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
125+
<ClCompile>
126+
<WarningLevel>Level3</WarningLevel>
127+
<Optimization>Disabled</Optimization>
128+
<SDLCheck>true</SDLCheck>
129+
<ConformanceMode>true</ConformanceMode>
130+
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
131+
</ClCompile>
132+
<Link>
133+
<SubSystem>Console</SubSystem>
134+
</Link>
135+
</ItemDefinitionGroup>
136+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
137+
<ClCompile>
138+
<WarningLevel>Level3</WarningLevel>
139+
<Optimization>MaxSpeed</Optimization>
140+
<FunctionLevelLinking>true</FunctionLevelLinking>
141+
<IntrinsicFunctions>true</IntrinsicFunctions>
142+
<SDLCheck>true</SDLCheck>
143+
<ConformanceMode>true</ConformanceMode>
144+
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
145+
</ClCompile>
146+
<Link>
147+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
148+
<OptimizeReferences>true</OptimizeReferences>
149+
<SubSystem>Console</SubSystem>
150+
</Link>
151+
</ItemDefinitionGroup>
152+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
153+
<ImportGroup Label="ExtensionTargets">
154+
</ImportGroup>
155+
</Project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="elfio\elf_types.hpp">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
<ClInclude Include="elfio\elfio.hpp">
22+
<Filter>Header Files</Filter>
23+
</ClInclude>
24+
<ClInclude Include="elfio\elfio_dump.hpp">
25+
<Filter>Header Files</Filter>
26+
</ClInclude>
27+
<ClInclude Include="elfio\elfio_dynamic.hpp">
28+
<Filter>Header Files</Filter>
29+
</ClInclude>
30+
<ClInclude Include="elfio\elfio_header.hpp">
31+
<Filter>Header Files</Filter>
32+
</ClInclude>
33+
<ClInclude Include="elfio\elfio_note.hpp">
34+
<Filter>Header Files</Filter>
35+
</ClInclude>
36+
<ClInclude Include="elfio\elfio_relocation.hpp">
37+
<Filter>Header Files</Filter>
38+
</ClInclude>
39+
<ClInclude Include="elfio\elfio_section.hpp">
40+
<Filter>Header Files</Filter>
41+
</ClInclude>
42+
<ClInclude Include="elfio\elfio_segment.hpp">
43+
<Filter>Header Files</Filter>
44+
</ClInclude>
45+
<ClInclude Include="elfio\elfio_strings.hpp">
46+
<Filter>Header Files</Filter>
47+
</ClInclude>
48+
<ClInclude Include="elfio\elfio_symbols.hpp">
49+
<Filter>Header Files</Filter>
50+
</ClInclude>
51+
<ClInclude Include="elfio\elfio_utils.hpp">
52+
<Filter>Header Files</Filter>
53+
</ClInclude>
54+
<ClInclude Include="elf2rel.h">
55+
<Filter>Header Files</Filter>
56+
</ClInclude>
57+
</ItemGroup>
58+
<ItemGroup>
59+
<ClCompile Include="elf2rel.cpp">
60+
<Filter>Source Files</Filter>
61+
</ClCompile>
62+
</ItemGroup>
63+
</Project>

0 commit comments

Comments
 (0)