Skip to content

Commit 64de958

Browse files
river-lizznop
authored andcommitted
Change type for TPIDR_EL0 and run the plugin automatically
1 parent 63536b5 commit 64de958

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

platform/efi/platform_efi.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ class EFIX86Platform : public Platform
6060
{
6161
if (!m_idtrtype)
6262
m_idtrtype = Type::NamedType(QualifiedName("IDTR32"), GetTypeByName(QualifiedName("IDTR32")));
63+
64+
auto ctx = PluginCommandContext();
65+
ctx.binaryView = view;
66+
auto commandList = PluginCommand::GetValidList(ctx);
67+
for (auto command : commandList)
68+
{
69+
if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols")
70+
{
71+
command.Execute(ctx);
72+
}
73+
}
6374
}
6475

6576
virtual Ref<Type> GetGlobalRegisterType(uint32_t reg) override
@@ -124,6 +135,17 @@ class EFIX86WindowsPlatform : public Platform
124135
{
125136
if (!m_idtrtype)
126137
m_idtrtype = Type::NamedType(QualifiedName("IDTR32"), GetTypeByName(QualifiedName("IDTR32")));
138+
139+
auto ctx = PluginCommandContext();
140+
ctx.binaryView = view;
141+
auto commandList = PluginCommand::GetValidList(ctx);
142+
for (auto command : commandList)
143+
{
144+
if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols")
145+
{
146+
command.Execute(ctx);
147+
}
148+
}
127149
}
128150

129151
virtual Ref<Type> GetGlobalRegisterType(uint32_t reg) override
@@ -171,6 +193,17 @@ class EFIX64Platform : public Platform
171193
{
172194
if (!m_idtrtype)
173195
m_idtrtype = Type::NamedType(QualifiedName("IDTR64"), GetTypeByName(QualifiedName("IDTR64")));
196+
197+
auto ctx = PluginCommandContext();
198+
ctx.binaryView = view;
199+
auto commandList = PluginCommand::GetValidList(ctx);
200+
for (auto command : commandList)
201+
{
202+
if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols")
203+
{
204+
command.Execute(ctx);
205+
}
206+
}
174207
}
175208

176209
virtual Ref<Type> GetGlobalRegisterType(uint32_t reg) override
@@ -218,6 +251,17 @@ class EFIX64WindowsPlatform : public Platform
218251
{
219252
if (!m_idtrtype)
220253
m_idtrtype = Type::NamedType(QualifiedName("IDTR64"), GetTypeByName(QualifiedName("IDTR64")));
254+
255+
auto ctx = PluginCommandContext();
256+
ctx.binaryView = view;
257+
auto commandList = PluginCommand::GetValidList(ctx);
258+
for (auto command : commandList)
259+
{
260+
if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols")
261+
{
262+
command.Execute(ctx);
263+
}
264+
}
221265
}
222266

223267
virtual Ref<Type> GetGlobalRegisterType(uint32_t reg) override
@@ -261,11 +305,15 @@ class EFIArmv7Platform : public Platform
261305

262306
class EFIArm64Platform : public Platform
263307
{
308+
uint32_t m_tpidrel0;
309+
Ref<Type> m_tpidrel0type;
310+
264311
public:
265312
EFIArm64Platform(Architecture* arch) : Platform(arch, "efi-aarch64")
266313
{
267314
Ref<CallingConvention> cc;
268315

316+
m_tpidrel0 = arch->GetRegisterByName("tpidr_el0");
269317
cc = arch->GetCallingConventionByName("cdecl");
270318
if (cc)
271319
{
@@ -276,6 +324,26 @@ class EFIArm64Platform : public Platform
276324
}
277325
}
278326

327+
virtual void BinaryViewInit(BinaryView* view) override
328+
{
329+
if (!m_tpidrel0type)
330+
m_tpidrel0type = Type::NamedType(QualifiedName("EFI_PEI_SERVICES"),
331+
Type::PointerType(view->GetDefaultArchitecture(),
332+
Type::PointerType(
333+
view->GetDefaultArchitecture(), GetTypeByName(QualifiedName("EFI_PEI_SERVICES")))));
334+
335+
auto ctx = PluginCommandContext();
336+
ctx.binaryView = view;
337+
auto commandList = PluginCommand::GetValidList(ctx);
338+
for (auto command : commandList)
339+
{
340+
if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols")
341+
{
342+
command.Execute(ctx);
343+
}
344+
}
345+
}
346+
279347
static Ref<Platform> Recognize(BinaryView* view, Metadata* metadata)
280348
{
281349
Ref<Metadata> subsystem = metadata->Get("Subsystem");
@@ -285,16 +353,27 @@ class EFIArm64Platform : public Platform
285353
return g_efiArm64;
286354
return nullptr;
287355
}
356+
357+
virtual Ref<Type> GetGlobalRegisterType(uint32_t reg) override
358+
{
359+
if (reg == m_tpidrel0)
360+
return m_tpidrel0type;
361+
362+
return nullptr;
363+
}
288364
};
289365

290366

291367
class EFIArm64WindowsPlatform : public Platform
292368
{
369+
uint32_t m_tpidrel0;
370+
Ref<Type> m_tpidrel0type;
293371
public:
294372
EFIArm64WindowsPlatform(Architecture* arch) : Platform(arch, "efi-windows-aarch64")
295373
{
296374
Ref<CallingConvention> cc;
297375

376+
m_tpidrel0 = arch->GetRegisterByName("tpidr_el0");
298377
cc = arch->GetCallingConventionByName("cdecl");
299378
if (cc)
300379
{
@@ -305,6 +384,26 @@ class EFIArm64WindowsPlatform : public Platform
305384
}
306385
}
307386

387+
virtual void BinaryViewInit(BinaryView* view) override
388+
{
389+
if (!m_tpidrel0type)
390+
m_tpidrel0type = Type::NamedType(QualifiedName("EFI_PEI_SERVICES"),
391+
Type::PointerType(view->GetDefaultArchitecture(),
392+
Type::PointerType(
393+
view->GetDefaultArchitecture(), GetTypeByName(QualifiedName("EFI_PEI_SERVICES")))));
394+
395+
auto ctx = PluginCommandContext();
396+
ctx.binaryView = view;
397+
auto commandList = PluginCommand::GetValidList(ctx);
398+
for (auto command : commandList)
399+
{
400+
if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols")
401+
{
402+
command.Execute(ctx);
403+
}
404+
}
405+
}
406+
308407
static Ref<Platform> Recognize(BinaryView* view, Metadata* metadata)
309408
{
310409
Ref<Metadata> subsystem = metadata->Get("Subsystem");
@@ -314,6 +413,14 @@ class EFIArm64WindowsPlatform : public Platform
314413
return g_efiArm64Windows;
315414
return nullptr;
316415
}
416+
417+
virtual Ref<Type> GetGlobalRegisterType(uint32_t reg) override
418+
{
419+
if (reg == m_tpidrel0)
420+
return m_tpidrel0type;
421+
422+
return nullptr;
423+
}
317424
};
318425

319426
extern "C"

0 commit comments

Comments
 (0)