Author Topic: Oracle.ManagedDataAccess.dll from C or asm  (Read 1123 times)

TimoVJL

  • Member
  • *****
  • Posts: 1223
Oracle.ManagedDataAccess.dll from C or asm
« on: August 27, 2021, 07:18:07 PM »
How to use an Oracle.ManagedDataAccess.dll from C or asm ?
« Last Edit: September 01, 2021, 03:21:53 PM by TimoVJL »
May the source be with you

LiaoMi

  • Member
  • *****
  • Posts: 1038
Re: Oracle.ManagedDataAccess.dll from C or asm
« Reply #1 on: August 27, 2021, 08:45:00 PM »
Hi TimoVJL,

Oracle.ManagedDataAccess 21.3.0
ODP.NET, Managed Driver is a 100% native code .NET Framework driver for Oracle Database. No additional Oracle Client software is required to be installed to connect to Oracle Database.
C# + https://docs.microsoft.com/en-us/windows/win32/ipc/interprocess-communications

https://docs.oracle.com/en/database/oracle/oracle-database/21/books.html

Oracle C++ Call Interface Programmer's Guide
https://docs.oracle.com/en/database/oracle/oracle-database/21/lncpp/oracle-c-call-interface-programmers-guide.pdf

Oracle Call Interface Programmer's Guide
https://docs.oracle.com/en/database/oracle/oracle-database/21/lnoci/oracle-call-interface-programmers-guide.pdf


LiaoMi

  • Member
  • *****
  • Posts: 1038
Re: Oracle.ManagedDataAccess.dll from C or asm
« Reply #2 on: August 29, 2021, 08:11:31 AM »
x86_64 assembly language application that hosts the CLR runtime for .NET applications -

Requirements
GoAsm 0.61.0.1 (http://www.godevtool.com/)
EasyCode IDE (https://www.easycode.cat/English/index.htm)
C# compiler

Building
Assembling and linking the host
C:\goasm\bin\goasm.exe /x64 /ni clrhost.obj clrhost.asm
C:\goasm\bin\golink /no /debug coff /console /fo clrhost.exe clrhost.obj kernel32.dll user32.dll mscoree.dll

Compiling the hosted application
C:\windows\microsoft.net\Framework64\v4.0.30319\csc.exe /out:Hostedapp.exe program.cs

Copy the executables
Copy both of the executables you just created (CLRHost.exe & HostedApp.exe) and put them into the same directory.

Code: [Select]
;EasyCodeName=CLRHost,1
;===================================
; CLRHost.asm
; Demonstrates how to host the CLR
; in an x86 assembly language application.
;
; Kevin Voell
; 02-17-2021
;===================================
#Include "clrhost.inc"
.Const
S_OK                        equ     0
FORMAT_MESSAGE_FROM_SYSTEM  equ     00001000h
STD_OUTPUT_HANDLE           equ     -11
STD_INPUT_HANDLE            equ     -10
RUNTIMEVERSION              equ      L"v4.0.30319"

.Data
hInst                       DQ      0                       ;handle to the module instance
hout                        DQ      0                       ;handle to console output
hin                         DQ      0                       ;handle to console input
hResult                     DD      0                       ;result of the operation
bout                        DD      0                       ;byte output
bin                         DD      0                       ;byte input
inputBuff                   DD      3 DUP 0                 ;input buffer
pMetaHost                   DD      0                       ;pointer to the ICLRMetaHost struct
retVal                      DW      0                       ;return value from CLR method invocation
pInterface                  DQ      0                       ;pointer to the ICLRInterface struct
pRuntimeInfo                DQ      0                       ;pointer to the ICLRRuntimeInfo struct
pRuntimeHost                DQ      0                       ;pointer to the ICLRRuntimeHost struct
pEnumerator                 DQ      0                       ;pointer to the ICLRXXX enumerator

errorMsg                    DB      "Error occurred",0Ah,0Dh
errorMsgLen                 DD      $-errorMsg
errBuff                     DB      512 DUP 0               ;char buffer used to hold error message from WinApi
exitMsg                     DB      "Process complete",0Ah,0Dh
exitMsgLen                  DD      $-exitMsg

CLSID_CLRMetaHost           GUID    <9280188dh, 0e8eh, 4867h, <0b3h, 0ch, 07fh, 0a8h, 38h, 84h, 0e8h, 0deh>>
IID_ICLRMetaHost            GUID    <0D332DB9Eh, 0B9B3h, 4125h, <82h, 07h, 0A1h, 48h, 84h, 0F5h, 32h, 16h>>
IID_ICLRRuntimeInfo         GUID    <0BD39D1D2h, 0BA2Fh, 486ah, <89h, 0B0h, 0B4h, 0B0h, 0CBh, 46h, 68h, 91h>>
CLSID_CLRRuntimeHost        GUID    <90F1A06Eh, 7712h, 4762h, <86h, 0B5h, 7Ah, 5Eh, 0BAh, 06Bh, 0DBh, 02h>>
IID_ICLRRuntimeHost         GUID    <90F1A06Ch, 7712h, 4762h, <86h, 0B5h, 7Ah, 5Eh, 0BAh, 6Bh, 0DBh, 02h>>

.Code
start:
    Invoke GetModuleHandleA, 0
    Mov [hInst], Rax
   
    arg STD_OUTPUT_HANDLE   
    invoke GetStdHandle   
    mov [hout],eax         
   
    arg STD_INPUT_HANDLE
    invoke GetStdHandle
    mov [hin],eax
   
    Invoke Main

    invoke WriteFile,[hout],addr exitMsg,[exitMsgLen], addr bout,0
   
    invoke CloseHandle, [hout]
    invoke CloseHandle, [hInst]

    Invoke ExitProcess, 0



Main Frame   
    ;===================================
    ;Create the CLR Instance
    ;===================================
    lea r8,[pInterface]                         
    lea rdx,[IID_ICLRMetaHost]
    lea rcx,[CLSID_CLRMetaHost]
    invoke CLRCreateInstance                             ;Create the CLR instance
    cmp RAX,S_OK
    jne >displayError
   
    ;===================================
    ;Get the runtime
    ;===================================
    mov RAX, [pInterface]
    mov RAX, [RAX]
    mov RSI, ICLRMetaHostVtable.GetRuntime
    invoke [RAX+RSI],[pInterface], RUNTIMEVERSION, addr IID_ICLRRuntimeInfo, addr pRuntimeInfo
    cmp RAX,S_OK
    jne >displayError
   
    ;===================================
    ;Get the interface
    ;===================================
    mov RAX, [pRuntimeInfo]
    mov RAX, [RAX]
    mov RSI, ICLRRuntimeInfo.GetInterface
    invoke [RAX+RSI],[pRuntimeInfo],addr CLSID_CLRRuntimeHost,addr IID_ICLRRuntimeHost,addr pRuntimeHost
    cmp RAX,S_OK
    jne >displayError
   
    ;===================================
    ;Start the runtime
    ;===================================
    mov RAX,[pRuntimeHost]
    mov RAX,[RAX]
    mov RSI,ICLRRuntimeHost.Start
    invoke [RAX+18h],[pRuntimeHost]
    cmp RAX,S_OK
    jne >displayError
   
    ;===================================
    ;Call .NET assembly
    ;===================================
    mov RAX, [pRuntimeHost]
    mov RAX, [RAX]
    mov RSI, ICLRRuntimeHost.ExecuteInDefaultAppDomain
    invoke [RAX+RSI], \
        [pRuntimeHost], \   
        L"HostedApp.exe", \                             ;.NET assembly name
        L"HostedApp.Program", \                         ;namespace containing method to invoke
        L"Test", \                                      ;name of method to invoke
        L"Hello World!", \                              ;parameter to method
        addr retVal                                     ;pointer to return value
    cmp RAX,S_OK
    jne >displayError
   
    jmp >done
   
displayError:
    invoke FormatMessageA,FORMAT_MESSAGE_FROM_SYSTEM,0,RAX,0,addr errBuff,512,0
    invoke WriteFile,[hout],addr errorMsg,[errorMsgLen], addr bout,0
    ;invoke WriteFile,[hout],RAX,8, addr bout,0
    invoke WriteFile,[hout],addr errBuff,sizeof errBuff, addr bout,0
   
done:
    ret

EndF

Raistlin

  • Member
  • ****
  • Posts: 548
Re: Oracle.ManagedDataAccess.dll from C or asm
« Reply #3 on: August 30, 2021, 03:03:14 PM »
Nice one Liaomi  :biggrin:
Was looking for an example myself incidentally for
Oracle DBMS with REST services.
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...