encode id64 for modules,libraries

This commit is contained in:
georgemoralis 2023-06-14 07:47:44 +03:00
parent bcc6288e9e
commit cae39ccf23
2 changed files with 30 additions and 0 deletions

View File

@ -38,6 +38,30 @@ static u64 calculate_base_size(const elf_header* ehdr, const elf_program_header*
return base_size; return base_size;
} }
static std::string encodeId(u64 nVal)
{
std::string enc;
const char pCodes[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
if (nVal < 0x40u)
{
enc += pCodes[nVal];
}
else
{
if (nVal < 0x1000u)
{
enc += pCodes[static_cast<u16>(nVal >> 6u) & 0x3fu];
enc += pCodes[nVal & 0x3fu];
}
else
{
enc += pCodes[static_cast<u16>(nVal >> 12u) & 0x3fu];
enc += pCodes[static_cast<u16>(nVal >> 6u) & 0x3fu];
enc += pCodes[nVal & 0x3fu];
}
}
return enc;
}
Module* Linker::LoadModule(const std::string& elf_name) Module* Linker::LoadModule(const std::string& elf_name)
{ {
auto* m = new Module; auto* m = new Module;
@ -275,6 +299,7 @@ void Linker::LoadDynamicInfo(Module* m)
ModuleInfo info{}; ModuleInfo info{};
info.value = dyn->d_un.d_val; info.value = dyn->d_un.d_val;
info.name = m->dynamic_info->str_table + info.name_offset; info.name = m->dynamic_info->str_table + info.name_offset;
info.enc_id = encodeId(info.id);
m->dynamic_info->import_modules.push_back(info); m->dynamic_info->import_modules.push_back(info);
} }
break; break;
@ -283,6 +308,7 @@ void Linker::LoadDynamicInfo(Module* m)
LibraryInfo info{}; LibraryInfo info{};
info.value = dyn->d_un.d_val; info.value = dyn->d_un.d_val;
info.name = m->dynamic_info->str_table + info.name_offset; info.name = m->dynamic_info->str_table + info.name_offset;
info.enc_id = encodeId(info.id);
m->dynamic_info->import_libs.push_back(info); m->dynamic_info->import_libs.push_back(info);
} }
break; break;
@ -304,6 +330,7 @@ void Linker::LoadDynamicInfo(Module* m)
ModuleInfo info{}; ModuleInfo info{};
info.value = dyn->d_un.d_val; info.value = dyn->d_un.d_val;
info.name = m->dynamic_info->str_table + info.name_offset; info.name = m->dynamic_info->str_table + info.name_offset;
info.enc_id = encodeId(info.id);
m->dynamic_info->export_modules.push_back(info); m->dynamic_info->export_modules.push_back(info);
} }
break; break;
@ -316,6 +343,7 @@ void Linker::LoadDynamicInfo(Module* m)
LibraryInfo info{}; LibraryInfo info{};
info.value = dyn->d_un.d_val; info.value = dyn->d_un.d_val;
info.name = m->dynamic_info->str_table + info.name_offset; info.name = m->dynamic_info->str_table + info.name_offset;
info.enc_id = encodeId(info.id);
m->dynamic_info->export_libs.push_back(info); m->dynamic_info->export_libs.push_back(info);
} }
break; break;

View File

@ -30,6 +30,7 @@ struct ModuleInfo
u16 id; u16 id;
}; };
}; };
std::string enc_id;
}; };
struct LibraryInfo struct LibraryInfo
@ -45,6 +46,7 @@ struct LibraryInfo
u16 id; u16 id;
}; };
}; };
std::string enc_id;
}; };
struct DynamicModuleInfo struct DynamicModuleInfo