Closed smardine closed 1 year ago
Dear @smardine,
It seems you opened that issue in the wrong GitHub repository since creating an instance of MemorySharp involves playing with the class MemorySharp
(not ProcessSharp
). I will let you post on the appropriate project for further assistance.
That being said, it seems your assembly code uses some uninitialized registers (typically in the source of your MOV
instructions). You have maybe forgotten to call the CPUID
instruction beforehand.
Cheers
HI, sorry for having posting on the wrong repo. I modify my code to use MemorySharp instead. Here is the code:
internal static string CPUIIDMemorySharp()
{
var sharp = new MemorySharp(System.Diagnostics.Process.GetCurrentProcess());
using (var memory = sharp.Memory.Allocate(24))
{
AssemblyTransaction fasmNet;
using (fasmNet = sharp.Assembly.BeginTransaction(memory.BaseAddress))
{
fasmNet.AddLine("use32"); //Tell FASM.Net to use x86 (32bit) mode
fasmNet.AddLine("PUSH EBX"); //{Save affected register}
fasmNet.AddLine("PUSH EDI");
fasmNet.AddLine("MOV EDI, EAX"); //{@Resukt}
fasmNet.AddLine("MOV EAX, 1");
fasmNet.AddLine("DW $A20F"); //CPUID Command}
fasmNet.AddLine("STOSD"); //{ CPUID[1]}
fasmNet.AddLine("MOV EAX, EBX");
fasmNet.AddLine("STOSD"); //{CPUID[2]}
fasmNet.AddLine("MOV EAX, ECX");
fasmNet.AddLine("STOSD"); //{CPUID[3]}
fasmNet.AddLine("MOV EAX, EDX");
fasmNet.AddLine("STOSD"); //{CPUID[4]}
fasmNet.AddLine("POP EDI"); //{Restore registers}
fasmNet.AddLine("POP EBX");
fasmNet.AddLine("RETN"); // in cdecl calling convention, return value is stored in EAX; so this will return both params added up
}
var myAssemblyFunction = Marshal.GetDelegateForFunctionPointer<CpuIDDelegate>(memory.BaseAddress);
CpuIdResult result = myAssemblyFunction(1);
int cpuid1 = result.Eax;
int cpuidpluscomplement = cpuid1 & 0x0FFF7FFF;
string converted = cpuidpluscomplement.ToString("X8");
return converted;
}
I end with the same problem, if i execute this code first, i have a value in
CpuIdResult result = myAssemblyFunction(1);
int cpuid1 = result.Eax;
If i made a call to a P/Invoke method first, the struct CpuIdResult has all this properties to 0. When i first call MemorySharp
When i call a P/Invoke method before calling MemorySharp:
Here is the modified example /repro project. ConsoleApp1.zip
I'm pretty sure i'm missing something but what... I hope you will have the time to take a look, and maybe a lead for me
Hi, i manage to use your library to get the CPU id with the following code :
this work like a charm but only if i execute it "alone". If i first call
where VolumeSerialNumber is
the Asm.CPUIdAsm() method return 0 for all value in the struct
i put a sample test in attachment.
I hope you can help me ConsoleApp1.zip