/// <summary> /// Creates a new instance of the FASM assembler. /// </summary> /// <param name="textSize"> /// The minimum size of the buffer to be used for passing the /// text to be assembled to FASM Assembler. /// </param> /// <param name="resultSize"> /// The minimum size of the buffer to be used for FASM to return the /// text to be assembled. /// </param> public Assembler(int textSize = 0x10000, int resultSize = 0x8000) { // Attempt allocation of memory X times. AllocateText(textSize, 3); AllocateResult(resultSize, 3); IntPtr fasmDllHandle; // Get path of FASM dll string fasmDllPath = GetFasmDLLPath(); fasmDllHandle = LoadLibraryW(fasmDllPath); // Throw exception if dll not loaded. if (fasmDllHandle == null) { throw new FasmWrapperException("Failed to load FASM dll. The FASM dll pointer from LoadLibraryW is null."); } // Obtain delegates to FASM functions. IntPtr assembleAddress = GetProcAddress(fasmDllHandle, "fasm_Assemble"); IntPtr getVersionAddress = GetProcAddress(fasmDllHandle, "fasm_GetVersion"); _assembleFunction = Marshal.GetDelegateForFunctionPointer <FasmDelegates.fasm_Assemble>(assembleAddress); _getVersionFunction = Marshal.GetDelegateForFunctionPointer <FasmDelegates.fasm_GetVersion>(getVersionAddress); }
/// <summary> /// Creates a new instance of the FASM assembler. /// </summary> /// <param name="textSize"> /// The minimum size of the buffer to be used for passing the /// text to be assembled to FASM Assembler. /// </param> /// <param name="resultSize"> /// The minimum size of the buffer to be used for FASM to return the /// text to be assembled. /// </param> public Assembler(int textSize = 0x10000, int resultSize = 0x8000) { // Attempt allocation of memory X times. AllocateText(textSize, 3, _bufferHelper); AllocateResult(resultSize, 3, _bufferHelper); IntPtr fasmDllHandle; // Set functions if (IntPtr.Size == 4) { fasmDllHandle = LoadLibraryW("FASM.dll"); } else if (IntPtr.Size == 8) { fasmDllHandle = LoadLibraryW("FASMX64.dll"); } else { // Does not actually check OS or architecture but it should be good enough for our purposes. // Users should know that this is a Windows lib for x86/x64 throw new FasmWrapperException("Only 32bit and 64bit desktop architectures are supported (X86 and X86_64)."); } // Obtain delegates to FASM functions. IntPtr assembleAddress = GetProcAddress(fasmDllHandle, "fasm_Assemble"); IntPtr getVersionAddress = GetProcAddress(fasmDllHandle, "fasm_GetVersion"); _assembleFunction = Marshal.GetDelegateForFunctionPointer <FasmDelegates.fasm_Assemble>(assembleAddress); _getVersionFunction = Marshal.GetDelegateForFunctionPointer <FasmDelegates.fasm_GetVersion>(getVersionAddress); }