You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, i manage to use your library to get the CPU id with the following code :
public class Asm
{
[SuppressUnmanagedCodeSecurity] // disable security checks for better performance
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] // cdecl - let caller (.NET) clean the stack
private delegate IntPtr AssemblyReadRegistersFunction();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate CpuIdResult CpuIDDelegate(int level);
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct CpuIdResult
{
public int Eax;
public int Ebx;
public int Ecx;
public int Edx;
}
internal static string CPUIdAsm()
{
using (var currentProcess = new ProcessSharp(System.Diagnostics.Process.GetCurrentProcess(), MemoryType.Local))
{
FasmNet fasmNet = new FasmNet();
fasmNet.AddLine("use32"); //Tell FASM.Net to use x86 (32bit) mode
fasmNet.AddLine("PUSH EBX");
fasmNet.AddLine("PUSH EDI");
fasmNet.AddLine("MOV EDI, EAX");
fasmNet.AddLine("MOV EAX, 1");
fasmNet.AddLine("DW $A20F");
fasmNet.AddLine("STOSD");
fasmNet.AddLine("MOV EAX, EBX");
fasmNet.AddLine("STOSD");
fasmNet.AddLine("MOV EAX, ECX");
fasmNet.AddLine("STOSD");
fasmNet.AddLine("MOV EAX, EDX");
fasmNet.AddLine("STOSD");
fasmNet.AddLine("POP EDI");
fasmNet.AddLine("POP EBX");
fasmNet.AddLine("RET"); // in cdecl calling convention, return value is stored in EAX; so this will return both params added up
byte[] assembledCode = fasmNet.Assemble();
var allocatedCodeMemory = currentProcess.MemoryFactory.Allocate(
name: "Example3", // only used for debugging; not really needed
size: assembledCode.Length,
protection: MemoryProtectionFlags.ExecuteReadWrite /* It is important to mark the memory as executeable or we will get exceptions from DEP */
);
allocatedCodeMemory.Write(0, assembledCode);
var myAssemblyFunction = Marshal.GetDelegateForFunctionPointer<CpuIDDelegate>(allocatedCodeMemory.BaseAddress);
CpuIdResult result = myAssemblyFunction(1);
var returnValue = result;
// Warning: Potential memory leak!
// Do not forget to dispose the allocated code memory after usage.
allocatedCodeMemory.Dispose();
int cpuid1 = returnValue.Eax;
int cpuidpluscomplement = cpuid1 & 0x0FFF7FFF;
string converted = cpuidpluscomplement.ToString("X8");
return converted;
}
}
}
this work like a charm but only if i execute it "alone".
If i first call
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
The text was updated successfully, but these errors were encountered: