Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
sj6219 authored and lucasg committed May 25, 2020
1 parent 00ddfcf commit 27fbfee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
3 changes: 3 additions & 0 deletions ClrPhlib/include/ClrPhlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ namespace Dependencies {
// Check if the PE is 32-bit
bool IsArm32Dll();

// return the processorArchiture of PE
String^ GetProcessor();

// Return the ApiSetSchema
ApiSetSchema^ GetApiSetSchema();

Expand Down
11 changes: 11 additions & 0 deletions ClrPhlib/src/managed/PE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,14 @@ bool PE::IsArm32Dll()
return ((Properties->Machine & 0xffff) == IMAGE_FILE_MACHINE_ARMNT);
}

String^ PE::GetProcessor()
{
if ((Properties->Machine & 0xffff) == IMAGE_FILE_MACHINE_I386)
return gcnew String("x86");
if ((Properties->Machine & 0xffff) == IMAGE_FILE_MACHINE_ARMNT)
return gcnew String("arm");
if ((Properties->Machine & 0xffff) == IMAGE_FILE_MACHINE_ARM64)
return gcnew String("arm64");
return gcnew String("amd64");
}

24 changes: 12 additions & 12 deletions DependenciesLib/SxsManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static SxsEntries SxsFindTargetDll(string AssemblyName, string Folder)
return EntriesFromElement;
}

public static SxsEntries ExtractDependenciesFromSxsElement(XElement SxsAssembly, string Folder, string ExecutableName = "", bool Wow64Pe = false)
public static SxsEntries ExtractDependenciesFromSxsElement(XElement SxsAssembly, string Folder, string ExecutableName = "", string ProcessorArch = "")
{
// Private assembly search sequence : https://msdn.microsoft.com/en-us/library/windows/desktop/aa374224(v=vs.85).aspx
//
Expand Down Expand Up @@ -167,7 +167,7 @@ public static SxsEntries ExtractDependenciesFromSxsElement(XElement SxsAssembly,
{
case "$(build.arch)":
case "*":
ProcessArch = (Wow64Pe) ? "x86" : "amd64";
ProcessArch = ProcessorArch;
break;
case "amd64":
case "x86":
Expand Down Expand Up @@ -265,7 +265,7 @@ public static SxsEntries ExtractDependenciesFromSxsElement(XElement SxsAssembly,
}


return ExtractDependenciesFromSxsManifestFile(MatchSxsManifestPath, FullPathMatchSxsManifestDir, ExecutableName, Wow64Pe);
return ExtractDependenciesFromSxsManifestFile(MatchSxsManifestPath, FullPathMatchSxsManifestDir, ExecutableName, ProcessorArch);
}
}
}
Expand All @@ -284,7 +284,7 @@ public static SxsEntries ExtractDependenciesFromSxsElement(XElement SxsAssembly,
TargetSxsManifestPath = Path.Combine(Folder, String.Format("{0:s}.manifest", SxsManifestName));
if (File.Exists(TargetSxsManifestPath))
{
return ExtractDependenciesFromSxsManifestFile(TargetSxsManifestPath, Folder, ExecutableName, Wow64Pe);
return ExtractDependenciesFromSxsManifestFile(TargetSxsManifestPath, Folder, ExecutableName, ProcessorArch);
}


Expand All @@ -301,7 +301,7 @@ public static SxsEntries ExtractDependenciesFromSxsElement(XElement SxsAssembly,
TargetSxsManifestPath = Path.Combine(SxsManifestDir, String.Format("{0:s}.manifest", SxsManifestName));
if (Directory.Exists(SxsManifestDir) && File.Exists(TargetSxsManifestPath))
{
return ExtractDependenciesFromSxsManifestFile(TargetSxsManifestPath, SxsManifestDir, ExecutableName, Wow64Pe);
return ExtractDependenciesFromSxsManifestFile(TargetSxsManifestPath, SxsManifestDir, ExecutableName, ProcessorArch);
}

// TODO : do the same thing for localization
Expand All @@ -323,18 +323,18 @@ public static SxsEntries ExtractDependenciesFromSxsElement(XElement SxsAssembly,
}
}

public static SxsEntries ExtractDependenciesFromSxsManifestFile(string ManifestFile, string Folder, string ExecutableName = "", bool Wow64Pe = false)
public static SxsEntries ExtractDependenciesFromSxsManifestFile(string ManifestFile, string Folder, string ExecutableName = "", string ProcessorArch = "")
{
// Console.WriteLine("Extracting deps from file {0:s}", ManifestFile);

using (FileStream fs = new FileStream(ManifestFile, FileMode.Open, FileAccess.Read))
{
return ExtractDependenciesFromSxsManifest(fs, Folder, ExecutableName, Wow64Pe);
return ExtractDependenciesFromSxsManifest(fs, Folder, ExecutableName, ProcessorArch);
}
}


public static SxsEntries ExtractDependenciesFromSxsManifest(System.IO.Stream ManifestStream, string Folder, string ExecutableName = "", bool Wow64Pe = false)
public static SxsEntries ExtractDependenciesFromSxsManifest(System.IO.Stream ManifestStream, string Folder, string ExecutableName = "", string ProcessorArch = "")
{
SxsEntries AdditionnalDependencies = new SxsEntries();

Expand Down Expand Up @@ -372,7 +372,7 @@ public static SxsEntries ExtractDependenciesFromSxsManifest(System.IO.Stream Man
)
{
// find target PE
AdditionnalDependencies.AddRange(ExtractDependenciesFromSxsElement(SxsAssembly, Folder, ExecutableName, Wow64Pe));
AdditionnalDependencies.AddRange(ExtractDependenciesFromSxsElement(SxsAssembly, Folder, ExecutableName, ProcessorArch));
}

return AdditionnalDependencies;
Expand Down Expand Up @@ -431,7 +431,7 @@ public static SxsEntries GetSxsEntries(PE Pe)
OverridingManifest,
RootPeFolder,
RootPeFilename,
Pe.IsWow64Dll()
Pe.GetProcessor()
);
}

Expand All @@ -448,8 +448,8 @@ public static SxsEntries GetSxsEntries(PE Pe)
ManifestStream,
RootPeFolder,
RootPeFilename,
Pe.IsWow64Dll()
);
Pe.GetProcessor()
);
return Entries;
}
}
Expand Down

0 comments on commit 27fbfee

Please sign in to comment.