You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

1

Sunday, June 14th 2009, 11:56am

How to use Opcodes with Jabaco

Hello community,
opcodes are the operation codes and each code represents an instruction of a CPU, look here for further explanation. With this way it is possible to use each CPU, FPU, SIMD, MMX instruction you want. Here is a small example, how to use opcodes with Jabaco.

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Private WinAPI Function CallProc Lib "user32.dll" _
  Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
  ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, _
  ByVal lParam As Long) As Long

Dim VarPtr As New VarPtr()

Public Sub Command1_Click()
  VarPtr.Init

  Dim ProcAddr As Long
  ProcAddr = VarPtr.CreateVar("Proc", "Array", 15)
  
  VarPtr.SetArrayByte    ("Proc", &H00,   &H55) 'push ebp
  VarPtr.SetArrayByte    ("Proc", &H01,   &H8B) 'mov ebp,esp
  VarPtr.SetArrayByte    ("Proc", &H02,   &HEC)
  VarPtr.SetArrayByte    ("Proc", &H03,   &H8B) 'mov eax, Par1
  VarPtr.SetArrayByte    ("Proc", &H04,   &H45)
  VarPtr.SetArrayByte    ("Proc", &H05,   &H08)
  VarPtr.SetArrayByte    ("Proc", &H06,   &H03) 'add eax, Par2
  VarPtr.SetArrayByte    ("Proc", &H07,   &H45)
  VarPtr.SetArrayByte    ("Proc", &H08,   &H0C)
  VarPtr.SetArrayByte    ("Proc", &H09,   &H8B) 'mov esp,ebp
  VarPtr.SetArrayByte    ("Proc", &H0A,   &HE5)
  VarPtr.SetArrayByte    ("Proc", &H0B,   &H5D) 'pop ebp
  VarPtr.SetArrayByte    ("Proc", &H0C,   &HC2) 'ret 16
  VarPtr.SetArrayInteger ("Proc", &H0D, &H0010)

  Dim res As Long
  res = CallProc(ProcAddr, 6, 5, 0 , 0)
  
  java#lang#System.out.println(Str(res))

  VarPtr.DestroyVar("Proc")
  VarPtr.UnInit 
   
End Sub


We need the WinAPI function CallWindowProc to execute the procedure. It is necessary with VarPtr to create an array and set each byte of this array with the opcode of the assembler mnemonics. Now, call the proc and get the result. In the example I show an addition of the two arguments 6 and 5, the result is 11.

Lets have a look at the assembler source:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;-Begin-----------------------------------------------------------------
  ;-Direktiven----------------------------------------------------------
    .386
    .model flat, stdcall
    option casemap : none 
    
  ;-Konstanten----------------------------------------------------------
    Par1  EQU  <[ebp+ 8]>
    Par2  EQU  <[ebp+12]>
    Par3  EQU  <[ebp+16]>
    Par4  EQU  <[ebp+20]>
  ;-Daten---------------------------------------------------------------
    .data
    
  ;-Code----------------------------------------------------------------
    .code
      start:
        push ebp
        mov ebp,esp
        
        mov eax, Par1
        add eax, Par2
        mov esp,ebp
        pop ebp
        ret 16
      end start
;-End-------------------------------------------------------------------


Compile it with Microsoft Macro Assembler, with this command:
ML /c /coff /Fl FileName.asm
and look at the lst-file. Here you find the opcodes.

Source code

1
2
3
4
5
6
7
8
9
00000000 .code 
00000000 start: 
00000000 55 push ebp 
00000001 8B EC mov ebp,esp 
00000003 8B 45 08 mov eax, Par1 
00000006 03 45 0C add eax, Par2 
00000009 8B E5 mov esp,ebp 
0000000B 5D pop ebp 
0000000C C2 0010 ret 16


You find the MASM here.

Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

This post has been edited 2 times, last edit by "StefanSchnell" (Jun 14th 2009, 6:03pm)


  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

2

Sunday, June 14th 2009, 5:56pm

Another source of MASM download

Hello community,
you can download an older version of MASM here.
Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

Rate this thread
WoltLab Burning Board