├── .gitignore
├── Bin
├── OSX64
│ └── libBeaEngine.dylib
├── OSXARM64
│ └── libBeaEngine.dylib
├── Win32
│ └── BeaEngine.dll
└── Win64
│ └── BeaEngine.dll
├── Dcu
└── .gitignore
├── Delphinus.Info.json
├── Delphinus.Install.json
├── Demos
├── Delphi
│ ├── Demo.dpr
│ ├── Demo.dproj
│ └── Demo.res
└── FreePascal
│ ├── Demo.lpi
│ └── Demo.lpr
├── LICENSE
├── Lib
├── aarch64-darwin
│ └── libBeaEngine.dylib
├── i386-win32
│ └── BeaEngine.dll
├── x86_64-darwin
│ └── libBeaEngine.dylib
└── x86_64-win64
│ └── BeaEngine.dll
├── README.md
├── Ref
├── beaengine-5.3.0
│ ├── abi
│ │ └── BeaEngineLib.md
│ ├── cb
│ │ └── BeaEngineLib.cbp
│ └── include
│ │ └── beaengine
│ │ ├── BeaEngine.h
│ │ ├── basic_types.h
│ │ ├── export.h
│ │ └── macros.h
└── doc
│ └── logo.png
├── Source
├── BeaEngineDelphi.pas
├── aarch64-android
│ └── BeaEngine.o
├── aarch64-darwin
│ └── BeaEngine.o
├── aarch64-linux
│ └── BeaEngine.o
├── arm-android
│ └── BeaEngine.o
├── arm-linux
│ └── BeaEngine.o
├── i386-linux
│ └── BeaEngine.o
├── i386-win32
│ ├── BeaEngine.o
│ └── BeaEngine.obj
├── loongarch64-linux
│ └── BeaEngine.o
├── x86_64-darwin
│ └── BeaEngine.o
├── x86_64-linux
│ └── BeaEngine.o
└── x86_64-win64
│ ├── BeaEngine.o
│ └── BeaEngine.obj
└── Tests
├── test_block.dpr
├── test_block.dproj
└── test_block.res
/.gitignore:
--------------------------------------------------------------------------------
1 | # Uncomment these types if you want even more clean repository. But be careful.
2 | # It can make harm to an existing project source. Read explanations below.
3 | #
4 | # Resource files are binaries containing manifest, project icon and version info.
5 | # They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files.
6 | #*.res
7 | #
8 | # Type library file (binary). In old Delphi versions it should be stored.
9 | # Since Delphi 2009 it is produced from .ridl file and can safely be ignored.
10 | #*.tlb
11 | #
12 | # Diagram Portfolio file. Used by the diagram editor up to Delphi 7.
13 | # Uncomment this if you are not using diagrams or use newer Delphi version.
14 | #*.ddp
15 | #
16 | # Visual LiveBindings file. Added in Delphi XE2.
17 | # Uncomment this if you are not using LiveBindings Designer.
18 | #*.vlb
19 | #
20 | # Deployment Manager configuration file for your project. Added in Delphi XE2.
21 | # Uncomment this if it is not mobile development and you do not use remote debug feature.
22 | #*.deployproj
23 | #
24 | # C++ object files produced when C/C++ Output file generation is configured.
25 | # Uncomment this if you are not using external objects (zlib library for example).
26 | #*.obj
27 | #
28 |
29 | # Delphi compiler-generated binaries (safe to delete)
30 | *.exe
31 | *.dll
32 | *.bpl
33 | *.bpi
34 | *.dcp
35 | *.so
36 | *.apk
37 | *.drc
38 | *.map
39 | *.dres
40 | *.rsm
41 | *.tds
42 | *.dcu
43 | *.lib
44 | *.a
45 | *.o
46 | *.ocx
47 |
48 | # Delphi autogenerated files (duplicated info)
49 | *.cfg
50 | *.hpp
51 | *Resource.rc
52 |
53 | # Delphi local files (user-specific info)
54 | *.local
55 | *.identcache
56 | *.projdata
57 | *.tvsconfig
58 | *.dsk
59 |
60 | # Delphi history and backups
61 | __history/
62 | __recovery/
63 | *.~*
64 |
65 | # Castalia statistics file (since XE7 Castalia is distributed with Delphi)
66 | *.stat
67 |
68 | # Boss dependency manager vendor folder https://github.com/HashLoad/boss
69 | modules/
70 |
--------------------------------------------------------------------------------
/Bin/OSX64/libBeaEngine.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Bin/OSX64/libBeaEngine.dylib
--------------------------------------------------------------------------------
/Bin/OSXARM64/libBeaEngine.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Bin/OSXARM64/libBeaEngine.dylib
--------------------------------------------------------------------------------
/Bin/Win32/BeaEngine.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Bin/Win32/BeaEngine.dll
--------------------------------------------------------------------------------
/Bin/Win64/BeaEngine.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Bin/Win64/BeaEngine.dll
--------------------------------------------------------------------------------
/Dcu/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Dcu/.gitignore
--------------------------------------------------------------------------------
/Delphinus.Info.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "{BEA58FDC-88C7-42D1-AE3D-78231ADC231E}",
3 | "name": "BeaEngineDelphi",
4 | "picture": "Ref\\Doc\\Logo.png",
5 | "license_type": "MPL-2.0",
6 | "license_file": "License",
7 | "platforms": "Win32;Win64;OSX64;OSXARM64;Android;Android64;Linux64",
8 | "first_version": "5.3.0",
9 | "package_compiler_min": 23,
10 | "compiler_min": 23
11 | }
--------------------------------------------------------------------------------
/Delphinus.Install.json:
--------------------------------------------------------------------------------
1 | {
2 | "search_pathes": [
3 | {
4 | "pathes": "Source",
5 | "platforms": "Win32;Win64;OSX64;OSXARM64;Android;Android64;Linux64"
6 | }
7 | ],
8 | "browsing_pathes": [
9 | {
10 | "pathes": "Source",
11 | "platforms": "Win32;Win64;OSX64;OSXARM64;Android;Android64;Linux64"
12 | }
13 | ],
14 | "source_folders": [
15 | {
16 | "folder": "Source",
17 | "base": "",
18 | "recursive": true,
19 | "filter": "*;*.*"
20 | }
21 | ],
22 | "projects": [
23 | {
24 | "project": "Demos\\Delphi\\Demo.dproj",
25 | "compiler_min": 23
26 | }
27 | ]
28 | }
--------------------------------------------------------------------------------
/Demos/Delphi/Demo.dpr:
--------------------------------------------------------------------------------
1 | { ***************************************************** }
2 | { }
3 | { Pascal language binding for the BeaEngine }
4 | { }
5 | { Unit Name: Demo }
6 | { Author: Lsuper 2024.06.01 }
7 | { Purpose: Demo }
8 | { License: Mozilla Public License 2.0 }
9 | { }
10 | { Copyright (c) 1998-2024 Super Studio }
11 | { }
12 | { ***************************************************** }
13 |
14 | program Demo;
15 |
16 | {$IF CompilerVersion >= 21.0}
17 | {$WEAKLINKRTTI ON}
18 | {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
19 | {$IFEND}
20 |
21 | {$APPTYPE CONSOLE}
22 |
23 | {$R *.res}
24 |
25 | uses
26 | SysUtils, BeaEngineDelphi;
27 |
28 | const
29 | DelphiExpandFileNameCaseCode32: array[0..562] of Byte = (
30 | $55, $8B, $EC, $81, $C4, $6C, $FD, $FF, $FF, $53, $56, $57, $33, $DB, $89, $9D,
31 | $6C, $FD, $FF, $FF, $89, $9D, $70, $FD, $FF, $FF, $89, $9D, $74, $FD, $FF, $FF,
32 | $89, $9D, $78, $FD, $FF, $FF, $89, $9D, $7C, $FD, $FF, $FF, $89, $9D, $84, $FD,
33 | $FF, $FF, $89, $9D, $80, $FD, $FF, $FF, $89, $5D, $FC, $89, $5D, $F8, $8B, $D9,
34 | $8B, $F2, $8B, $F8, $8D, $85, $88, $FD, $FF, $FF, $8B, $15, $84, $3B, $82, $00,
35 | $E8, $6F, $10, $FF, $FF, $33, $C0, $55, $68, $45, $70, $82, $00, $64, $FF, $30,
36 | $64, $89, $20, $8B, $D3, $8B, $C7, $E8, $10, $FF, $FF, $FF, $C6, $06, $00, $85,
37 | $FF, $0F, $84, $70, $01, $00, $00, $8D, $55, $FC, $8B, $03, $E8, $A7, $FD, $FF,
38 | $FF, $8D, $55, $F8, $8B, $03, $E8, $95, $FE, $FF, $FF, $8D, $95, $80, $FD, $FF,
39 | $FF, $8B, $45, $FC, $E8, $57, $FE, $FF, $FF, $8B, $85, $80, $FD, $FF, $FF, $8D,
40 | $95, $84, $FD, $FF, $FF, $E8, $8E, $3F, $00, $00, $8B, $95, $84, $FD, $FF, $FF,
41 | $8B, $45, $FC, $E8, $E4, $43, $00, $00, $84, $C0, $0F, $85, $94, $00, $00, $00,
42 | $8D, $95, $7C, $FD, $FF, $FF, $8B, $45, $FC, $E8, $AE, $3F, $00, $00, $8B, $85,
43 | $7C, $FD, $FF, $FF, $8D, $8D, $88, $FD, $FF, $FF, $BA, $FF, $01, $00, $00, $E8,
44 | $D8, $FC, $FF, $FF, $8B, $F8, $8D, $85, $88, $FD, $FF, $FF, $E8, $1B, $FD, $FF,
45 | $FF, $85, $FF, $74, $5F, $8D, $95, $78, $FD, $FF, $FF, $8B, $45, $FC, $E8, $79,
46 | $3F, $00, $00, $8B, $95, $78, $FD, $FF, $FF, $8D, $45, $FC, $E8, $0F, $07, $FF,
47 | $FF, $8D, $8D, $74, $FD, $FF, $FF, $8B, $D6, $8B, $45, $FC, $E8, $DF, $FE, $FF,
48 | $FF, $8B, $95, $74, $FD, $FF, $FF, $8D, $45, $FC, $E8, $F1, $06, $FF, $FF, $80,
49 | $3E, $00, $0F, $84, $AF, $00, $00, $00, $8D, $95, $70, $FD, $FF, $FF, $8B, $45,
50 | $FC, $E8, $F2, $3E, $00, $00, $8B, $95, $70, $FD, $FF, $FF, $8D, $45, $FC, $E8,
51 | $CC, $06, $FF, $FF, $33, $C0, $55, $68, $00, $70, $82, $00, $64, $FF, $30, $64,
52 | $89, $20, $8D, $85, $6C, $FD, $FF, $FF, $8B, $4D, $F8, $8B, $55, $FC, $E8, $71,
53 | $0B, $FF, $FF, $8B, $85, $6C, $FD, $FF, $FF, $8D, $8D, $88, $FD, $FF, $FF, $BA,
54 | $FF, $01, $00, $00, $E8, $33, $FC, $FF, $FF, $85, $C0, $75, $38, $0F, $B6, $06,
55 | $04, $FE, $2C, $02, $72, $18, $8B, $45, $F8, $8B, $95, $9C, $FD, $FF, $FF, $E8,
56 | $78, $0C, $FF, $FF, $75, $05, $C6, $06, $01, $EB, $03, $C6, $06, $02, $8B, $C3,
57 | $8B, $8D, $9C, $FD, $FF, $FF, $8B, $55, $FC, $E8, $26, $0B, $FF, $FF, $E8, $0D,
58 | $FC, $FE, $FF, $EB, $22, $33, $C0, $5A, $59, $59, $64, $89, $10, $68, $07, $70,
59 | $82, $00, $8D, $85, $88, $FD, $FF, $FF, $E8, $2F, $FC, $FF, $FF, $58, $FF, $E0,
60 | $E9, $17, $FA, $FE, $FF, $EB, $EB, $33, $C0, $5A, $59, $59, $64, $89, $10, $68,
61 | $4C, $70, $82, $00, $8D, $85, $6C, $FD, $FF, $FF, $BA, $07, $00, $00, $00, $E8,
62 | $6C, $03, $FF, $FF, $8D, $85, $88, $FD, $FF, $FF, $8B, $15, $84, $3B, $82, $00,
63 | $E8, $93, $12, $FF, $FF, $8D, $45, $F8, $BA, $02, $00, $00, $00, $E8, $4E, $03,
64 | $FF, $FF, $58, $FF, $E0, $E9, $D2, $F9, $FE, $FF, $EB, $C8, $5F, $5E, $5B, $8B,
65 | $E5, $5D, $C3
66 | );
67 | DelphiExpandFileNameCaseCode64: array[0..654] of Byte = (
68 | $55, $48, $81, $EC, $00, $03, $00, $00, $48, $8B, $EC, $48, $C7, $45, $20, $00,
69 | $00, $00, $00, $48, $C7, $45, $28, $00, $00, $00, $00, $48, $C7, $45, $30, $00,
70 | $00, $00, $00, $48, $C7, $45, $38, $00, $00, $00, $00, $48, $C7, $45, $40, $00,
71 | $00, $00, $00, $48, $C7, $45, $50, $00, $00, $00, $00, $48, $C7, $45, $48, $00,
72 | $00, $00, $00, $48, $C7, $45, $78, $00, $00, $00, $00, $48, $C7, $45, $70, $00,
73 | $00, $00, $00, $48, $89, $6D, $58, $48, $89, $8D, $10, $03, $00, $00, $48, $89,
74 | $95, $18, $03, $00, $00, $4C, $89, $85, $20, $03, $00, $00, $48, $8D, $8D, $80,
75 | $00, $00, $00, $48, $8B, $15, $F6, $B1, $FF, $FF, $E8, $91, $C1, $FE, $FF, $90,
76 | $48, $8B, $8D, $10, $03, $00, $00, $48, $8B, $95, $18, $03, $00, $00, $E8, $BD,
77 | $FE, $FF, $FF, $48, $8B, $85, $20, $03, $00, $00, $C6, $00, $00, $48, $83, $BD,
78 | $18, $03, $00, $00, $00, $0F, $84, $A5, $01, $00, $00, $48, $8D, $4D, $78, $48,
79 | $8B, $85, $10, $03, $00, $00, $48, $8B, $10, $E8, $C2, $FC, $FF, $FF, $48, $8D,
80 | $4D, $70, $48, $8B, $85, $10, $03, $00, $00, $48, $8B, $10, $E8, $FF, $FD, $FF,
81 | $FF, $48, $8D, $4D, $48, $48, $8B, $55, $78, $E8, $B2, $FD, $FF, $FF, $48, $8D,
82 | $4D, $50, $48, $8B, $55, $48, $E8, $65, $67, $00, $00, $48, $8B, $4D, $78, $48,
83 | $8B, $55, $50, $E8, $08, $6D, $00, $00, $84, $C0, $0F, $85, $9C, $00, $00, $00,
84 | $48, $8D, $4D, $40, $48, $8B, $55, $78, $E8, $A3, $67, $00, $00, $48, $8B, $4D,
85 | $40, $BA, $FF, $01, $00, $00, $4C, $8D, $85, $80, $00, $00, $00, $E8, $CE, $FB,
86 | $FF, $FF, $89, $45, $6C, $48, $8D, $8D, $80, $00, $00, $00, $E8, $1F, $FC, $FF,
87 | $FF, $83, $7D, $6C, $00, $74, $65, $48, $8D, $4D, $38, $48, $8B, $55, $78, $E8,
88 | $6C, $67, $00, $00, $48, $8D, $4D, $78, $48, $8B, $55, $38, $E8, $8F, $B2, $FE,
89 | $FF, $48, $8D, $4D, $30, $48, $8B, $55, $78, $4C, $8B, $85, $20, $03, $00, $00,
90 | $E8, $9B, $FE, $FF, $FF, $48, $8D, $4D, $78, $48, $8B, $55, $30, $E8, $6E, $B2,
91 | $FE, $FF, $48, $8B, $85, $20, $03, $00, $00, $80, $38, $00, $0F, $84, $CE, $00,
92 | $00, $00, $48, $8D, $4D, $28, $48, $8B, $55, $78, $E8, $C1, $66, $00, $00, $48,
93 | $8D, $4D, $78, $48, $8B, $55, $28, $E8, $44, $B2, $FE, $FF, $90, $48, $8D, $4D,
94 | $20, $48, $8B, $55, $78, $4C, $8B, $45, $70, $E8, $82, $BB, $FE, $FF, $48, $8B,
95 | $4D, $20, $BA, $FF, $01, $00, $00, $4C, $8D, $85, $80, $00, $00, $00, $E8, $2D,
96 | $FB, $FF, $FF, $85, $C0, $75, $6C, $48, $8B, $85, $20, $03, $00, $00, $48, $0F,
97 | $B6, $08, $80, $F9, $07, $77, $13, $B0, $01, $D3, $E0, $48, $0F, $B6, $0D, $11,
98 | $01, $00, $00, $84, $C8, $0F, $95, $C0, $EB, $02, $33, $C0, $84, $C0, $75, $2A,
99 | $48, $8B, $4D, $70, $48, $8B, $95, $98, $00, $00, $00, $E8, $A0, $BC, $FE, $FF,
100 | $85, $C0, $75, $0C, $48, $8B, $85, $20, $03, $00, $00, $C6, $00, $01, $EB, $0A,
101 | $48, $8B, $85, $20, $03, $00, $00, $C6, $00, $02, $48, $8B, $8D, $10, $03, $00,
102 | $00, $48, $8B, $55, $78, $4C, $8B, $85, $98, $00, $00, $00, $E8, $FF, $BA, $FE,
103 | $FF, $EB, $0F, $90, $48, $8D, $8D, $80, $00, $00, $00, $E8, $10, $FB, $FF, $FF,
104 | $EB, $0D, $33, $C9, $48, $8B, $55, $58, $E8, $43, $00, $00, $00, $EB, $01, $90,
105 | $48, $8D, $4D, $20, $BA, $07, $00, $00, $00, $E8, $12, $AD, $FE, $FF, $48, $8D,
106 | $4D, $70, $BA, $02, $00, $00, $00, $E8, $04, $AD, $FE, $FF, $48, $8D, $8D, $80,
107 | $00, $00, $00, $48, $8B, $15, $F6, $AF, $FF, $FF, $E8, $A1, $C5, $FE, $FF, $48,
108 | $8B, $85, $10, $03, $00, $00, $48, $8D, $A5, $00, $03, $00, $00, $5D, $C3
109 | );
110 |
111 | procedure DisAsmFunctionCode(const AFunc: Pointer; Archi: Integer);
112 | var
113 | aDisasm: TDisasm;
114 | nLen: LongWord;
115 | pData: PByte;
116 | B, S: string;
117 | begin
118 | FillChar(aDisasm, SizeOf(aDisasm), 0);
119 | aDisasm.Archi := Archi;
120 | aDisasm.EIP := UIntPtr(AFunc);
121 | aDisasm.Options := NoTabulation + MasmSyntax;
122 | pData := PByte(AFunc);
123 | repeat
124 | nLen := Disasm(aDisasm);
125 | B := BufferToHex(pData, nLen);
126 | S := Format('%.8x %-16s %s', [aDisasm.EIP, B, aDisasm.CompleteInstr]);
127 | Writeln(S);
128 | aDisasm.EIP := aDisasm.EIP + nLen;
129 | Inc(pData, nLen);
130 | until (aDisasm.Instruction.Opcode = OPCODE_RET) or (nLen <= 0);
131 | end;
132 |
133 | begin
134 | ReportMemoryLeaksOnShutdown := True;
135 | try
136 | WriteLn('BeaEngine: ', BeaEngineVersionInfo);
137 | WriteLn('');
138 | WriteLn('DisAsm ExpandFileNameCase32:', sLineBreak);
139 | DisAsmFunctionCode(@DelphiExpandFileNameCaseCode32, ARCHI_X32);
140 | WriteLn('');
141 | WriteLn('DisAsm ExpandFileNameCase64:', sLineBreak);
142 | DisAsmFunctionCode(@DelphiExpandFileNameCaseCode64, ARCHI_X64);
143 | WriteLn('');
144 | WriteLn('Done.');
145 | except
146 | on E: Exception do
147 | WriteLn('Error Decompiler: ', E.Message);
148 | end;
149 | ReadLn;
150 | end.
151 |
--------------------------------------------------------------------------------
/Demos/Delphi/Demo.dproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {A1346F3C-0C48-4A8C-BFF0-65CEA5270BC6}
4 | 13.4
5 | None
6 | Demo.dpr
7 | True
8 | Debug
9 | Win32
10 | 3
11 | Console
12 |
13 |
14 | true
15 |
16 |
17 | true
18 | Base
19 | true
20 |
21 |
22 | true
23 | Base
24 | true
25 |
26 |
27 | true
28 | Base
29 | true
30 |
31 |
32 | true
33 | Cfg_1
34 | true
35 | true
36 |
37 |
38 | true
39 | Base
40 | true
41 |
42 |
43 | ..\..\Dcu\$(Platform)
44 | ..\..\Bin\$(Platform)
45 | System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)
46 | dsnap;rtl;dbrtl;xmlrtl;DbxCommonDriver;soaprtl;$(DCC_UsePackage)
47 | ..\..\Source;$(DCC_UnitSearchPath)
48 | None
49 | 1033
50 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=
51 |
52 |
53 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)
54 |
55 |
56 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)
57 |
58 |
59 | DEBUG;$(DCC_Define)
60 | false
61 | true
62 | true
63 | true
64 |
65 |
66 | false
67 |
68 |
69 | false
70 | RELEASE;$(DCC_Define)
71 | 0
72 | false
73 |
74 |
75 |
76 | MainSource
77 |
78 |
79 | Cfg_2
80 | Base
81 |
82 |
83 | Base
84 |
85 |
86 | Cfg_1
87 | Base
88 |
89 |
90 |
91 | Delphi.Personality.12
92 |
93 |
94 |
95 |
96 | Demo.dpr
97 |
98 |
99 | False
100 | False
101 | 1
102 | 0
103 | 0
104 | 0
105 | False
106 | False
107 | False
108 | False
109 | False
110 | 2052
111 | 936
112 |
113 |
114 |
115 |
116 | 1.0.0.0
117 |
118 |
119 |
120 |
121 |
122 | 1.0.0.0
123 |
124 |
125 |
126 |
127 | True
128 | True
129 |
130 |
131 | 12
132 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/Demos/Delphi/Demo.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Demos/Delphi/Demo.res
--------------------------------------------------------------------------------
/Demos/FreePascal/Demo.lpi:
--------------------------------------------------------------------------------
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 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | -
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | -
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | -
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 | -
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | -
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 | -
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | -
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 | -
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 | -
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 | -
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 | -
423 |
424 |
425 | -
426 |
427 |
428 | -
429 |
430 |
431 |
432 |
433 |
434 |
--------------------------------------------------------------------------------
/Demos/FreePascal/Demo.lpr:
--------------------------------------------------------------------------------
1 | { ***************************************************** }
2 | { }
3 | { Pascal language binding for the BeaEngine }
4 | { }
5 | { Unit Name: Demo }
6 | { Author: Lsuper 2024.06.01 }
7 | { Purpose: Demo }
8 | { License: Mozilla Public License 2.0 }
9 | { }
10 | { Copyright (c) 1998-2024 Super Studio }
11 | { }
12 | { ***************************************************** }
13 |
14 | program Demo;
15 |
16 | {$mode objfpc}{$H+}
17 |
18 | uses
19 | SysUtils, BeaEngineDelphi;
20 |
21 | const
22 | DelphiExpandFileNameCaseCode32: array[0..562] of Byte = (
23 | $55, $8B, $EC, $81, $C4, $6C, $FD, $FF, $FF, $53, $56, $57, $33, $DB, $89, $9D,
24 | $6C, $FD, $FF, $FF, $89, $9D, $70, $FD, $FF, $FF, $89, $9D, $74, $FD, $FF, $FF,
25 | $89, $9D, $78, $FD, $FF, $FF, $89, $9D, $7C, $FD, $FF, $FF, $89, $9D, $84, $FD,
26 | $FF, $FF, $89, $9D, $80, $FD, $FF, $FF, $89, $5D, $FC, $89, $5D, $F8, $8B, $D9,
27 | $8B, $F2, $8B, $F8, $8D, $85, $88, $FD, $FF, $FF, $8B, $15, $84, $3B, $82, $00,
28 | $E8, $6F, $10, $FF, $FF, $33, $C0, $55, $68, $45, $70, $82, $00, $64, $FF, $30,
29 | $64, $89, $20, $8B, $D3, $8B, $C7, $E8, $10, $FF, $FF, $FF, $C6, $06, $00, $85,
30 | $FF, $0F, $84, $70, $01, $00, $00, $8D, $55, $FC, $8B, $03, $E8, $A7, $FD, $FF,
31 | $FF, $8D, $55, $F8, $8B, $03, $E8, $95, $FE, $FF, $FF, $8D, $95, $80, $FD, $FF,
32 | $FF, $8B, $45, $FC, $E8, $57, $FE, $FF, $FF, $8B, $85, $80, $FD, $FF, $FF, $8D,
33 | $95, $84, $FD, $FF, $FF, $E8, $8E, $3F, $00, $00, $8B, $95, $84, $FD, $FF, $FF,
34 | $8B, $45, $FC, $E8, $E4, $43, $00, $00, $84, $C0, $0F, $85, $94, $00, $00, $00,
35 | $8D, $95, $7C, $FD, $FF, $FF, $8B, $45, $FC, $E8, $AE, $3F, $00, $00, $8B, $85,
36 | $7C, $FD, $FF, $FF, $8D, $8D, $88, $FD, $FF, $FF, $BA, $FF, $01, $00, $00, $E8,
37 | $D8, $FC, $FF, $FF, $8B, $F8, $8D, $85, $88, $FD, $FF, $FF, $E8, $1B, $FD, $FF,
38 | $FF, $85, $FF, $74, $5F, $8D, $95, $78, $FD, $FF, $FF, $8B, $45, $FC, $E8, $79,
39 | $3F, $00, $00, $8B, $95, $78, $FD, $FF, $FF, $8D, $45, $FC, $E8, $0F, $07, $FF,
40 | $FF, $8D, $8D, $74, $FD, $FF, $FF, $8B, $D6, $8B, $45, $FC, $E8, $DF, $FE, $FF,
41 | $FF, $8B, $95, $74, $FD, $FF, $FF, $8D, $45, $FC, $E8, $F1, $06, $FF, $FF, $80,
42 | $3E, $00, $0F, $84, $AF, $00, $00, $00, $8D, $95, $70, $FD, $FF, $FF, $8B, $45,
43 | $FC, $E8, $F2, $3E, $00, $00, $8B, $95, $70, $FD, $FF, $FF, $8D, $45, $FC, $E8,
44 | $CC, $06, $FF, $FF, $33, $C0, $55, $68, $00, $70, $82, $00, $64, $FF, $30, $64,
45 | $89, $20, $8D, $85, $6C, $FD, $FF, $FF, $8B, $4D, $F8, $8B, $55, $FC, $E8, $71,
46 | $0B, $FF, $FF, $8B, $85, $6C, $FD, $FF, $FF, $8D, $8D, $88, $FD, $FF, $FF, $BA,
47 | $FF, $01, $00, $00, $E8, $33, $FC, $FF, $FF, $85, $C0, $75, $38, $0F, $B6, $06,
48 | $04, $FE, $2C, $02, $72, $18, $8B, $45, $F8, $8B, $95, $9C, $FD, $FF, $FF, $E8,
49 | $78, $0C, $FF, $FF, $75, $05, $C6, $06, $01, $EB, $03, $C6, $06, $02, $8B, $C3,
50 | $8B, $8D, $9C, $FD, $FF, $FF, $8B, $55, $FC, $E8, $26, $0B, $FF, $FF, $E8, $0D,
51 | $FC, $FE, $FF, $EB, $22, $33, $C0, $5A, $59, $59, $64, $89, $10, $68, $07, $70,
52 | $82, $00, $8D, $85, $88, $FD, $FF, $FF, $E8, $2F, $FC, $FF, $FF, $58, $FF, $E0,
53 | $E9, $17, $FA, $FE, $FF, $EB, $EB, $33, $C0, $5A, $59, $59, $64, $89, $10, $68,
54 | $4C, $70, $82, $00, $8D, $85, $6C, $FD, $FF, $FF, $BA, $07, $00, $00, $00, $E8,
55 | $6C, $03, $FF, $FF, $8D, $85, $88, $FD, $FF, $FF, $8B, $15, $84, $3B, $82, $00,
56 | $E8, $93, $12, $FF, $FF, $8D, $45, $F8, $BA, $02, $00, $00, $00, $E8, $4E, $03,
57 | $FF, $FF, $58, $FF, $E0, $E9, $D2, $F9, $FE, $FF, $EB, $C8, $5F, $5E, $5B, $8B,
58 | $E5, $5D, $C3
59 | );
60 | DelphiExpandFileNameCaseCode64: array[0..654] of Byte = (
61 | $55, $48, $81, $EC, $00, $03, $00, $00, $48, $8B, $EC, $48, $C7, $45, $20, $00,
62 | $00, $00, $00, $48, $C7, $45, $28, $00, $00, $00, $00, $48, $C7, $45, $30, $00,
63 | $00, $00, $00, $48, $C7, $45, $38, $00, $00, $00, $00, $48, $C7, $45, $40, $00,
64 | $00, $00, $00, $48, $C7, $45, $50, $00, $00, $00, $00, $48, $C7, $45, $48, $00,
65 | $00, $00, $00, $48, $C7, $45, $78, $00, $00, $00, $00, $48, $C7, $45, $70, $00,
66 | $00, $00, $00, $48, $89, $6D, $58, $48, $89, $8D, $10, $03, $00, $00, $48, $89,
67 | $95, $18, $03, $00, $00, $4C, $89, $85, $20, $03, $00, $00, $48, $8D, $8D, $80,
68 | $00, $00, $00, $48, $8B, $15, $F6, $B1, $FF, $FF, $E8, $91, $C1, $FE, $FF, $90,
69 | $48, $8B, $8D, $10, $03, $00, $00, $48, $8B, $95, $18, $03, $00, $00, $E8, $BD,
70 | $FE, $FF, $FF, $48, $8B, $85, $20, $03, $00, $00, $C6, $00, $00, $48, $83, $BD,
71 | $18, $03, $00, $00, $00, $0F, $84, $A5, $01, $00, $00, $48, $8D, $4D, $78, $48,
72 | $8B, $85, $10, $03, $00, $00, $48, $8B, $10, $E8, $C2, $FC, $FF, $FF, $48, $8D,
73 | $4D, $70, $48, $8B, $85, $10, $03, $00, $00, $48, $8B, $10, $E8, $FF, $FD, $FF,
74 | $FF, $48, $8D, $4D, $48, $48, $8B, $55, $78, $E8, $B2, $FD, $FF, $FF, $48, $8D,
75 | $4D, $50, $48, $8B, $55, $48, $E8, $65, $67, $00, $00, $48, $8B, $4D, $78, $48,
76 | $8B, $55, $50, $E8, $08, $6D, $00, $00, $84, $C0, $0F, $85, $9C, $00, $00, $00,
77 | $48, $8D, $4D, $40, $48, $8B, $55, $78, $E8, $A3, $67, $00, $00, $48, $8B, $4D,
78 | $40, $BA, $FF, $01, $00, $00, $4C, $8D, $85, $80, $00, $00, $00, $E8, $CE, $FB,
79 | $FF, $FF, $89, $45, $6C, $48, $8D, $8D, $80, $00, $00, $00, $E8, $1F, $FC, $FF,
80 | $FF, $83, $7D, $6C, $00, $74, $65, $48, $8D, $4D, $38, $48, $8B, $55, $78, $E8,
81 | $6C, $67, $00, $00, $48, $8D, $4D, $78, $48, $8B, $55, $38, $E8, $8F, $B2, $FE,
82 | $FF, $48, $8D, $4D, $30, $48, $8B, $55, $78, $4C, $8B, $85, $20, $03, $00, $00,
83 | $E8, $9B, $FE, $FF, $FF, $48, $8D, $4D, $78, $48, $8B, $55, $30, $E8, $6E, $B2,
84 | $FE, $FF, $48, $8B, $85, $20, $03, $00, $00, $80, $38, $00, $0F, $84, $CE, $00,
85 | $00, $00, $48, $8D, $4D, $28, $48, $8B, $55, $78, $E8, $C1, $66, $00, $00, $48,
86 | $8D, $4D, $78, $48, $8B, $55, $28, $E8, $44, $B2, $FE, $FF, $90, $48, $8D, $4D,
87 | $20, $48, $8B, $55, $78, $4C, $8B, $45, $70, $E8, $82, $BB, $FE, $FF, $48, $8B,
88 | $4D, $20, $BA, $FF, $01, $00, $00, $4C, $8D, $85, $80, $00, $00, $00, $E8, $2D,
89 | $FB, $FF, $FF, $85, $C0, $75, $6C, $48, $8B, $85, $20, $03, $00, $00, $48, $0F,
90 | $B6, $08, $80, $F9, $07, $77, $13, $B0, $01, $D3, $E0, $48, $0F, $B6, $0D, $11,
91 | $01, $00, $00, $84, $C8, $0F, $95, $C0, $EB, $02, $33, $C0, $84, $C0, $75, $2A,
92 | $48, $8B, $4D, $70, $48, $8B, $95, $98, $00, $00, $00, $E8, $A0, $BC, $FE, $FF,
93 | $85, $C0, $75, $0C, $48, $8B, $85, $20, $03, $00, $00, $C6, $00, $01, $EB, $0A,
94 | $48, $8B, $85, $20, $03, $00, $00, $C6, $00, $02, $48, $8B, $8D, $10, $03, $00,
95 | $00, $48, $8B, $55, $78, $4C, $8B, $85, $98, $00, $00, $00, $E8, $FF, $BA, $FE,
96 | $FF, $EB, $0F, $90, $48, $8D, $8D, $80, $00, $00, $00, $E8, $10, $FB, $FF, $FF,
97 | $EB, $0D, $33, $C9, $48, $8B, $55, $58, $E8, $43, $00, $00, $00, $EB, $01, $90,
98 | $48, $8D, $4D, $20, $BA, $07, $00, $00, $00, $E8, $12, $AD, $FE, $FF, $48, $8D,
99 | $4D, $70, $BA, $02, $00, $00, $00, $E8, $04, $AD, $FE, $FF, $48, $8D, $8D, $80,
100 | $00, $00, $00, $48, $8B, $15, $F6, $AF, $FF, $FF, $E8, $A1, $C5, $FE, $FF, $48,
101 | $8B, $85, $10, $03, $00, $00, $48, $8D, $A5, $00, $03, $00, $00, $5D, $C3
102 | );
103 |
104 | procedure DisAsmFunctionCode(const AFunc: Pointer; Archi: Integer);
105 | var
106 | aDisasm: TDisasm;
107 | nLen: LongWord;
108 | pData: PByte;
109 | B, S: string;
110 | begin
111 | FillChar(aDisasm, SizeOf(aDisasm), 0);
112 | aDisasm.Archi := Archi;
113 | aDisasm.EIP := UIntPtr(AFunc);
114 | aDisasm.Options := NoTabulation + MasmSyntax;
115 | pData := PByte(AFunc);
116 | repeat
117 | nLen := Disasm(aDisasm);
118 | B := BufferToHex(pData, nLen);
119 | S := Format('%.8x %-16s %s', [aDisasm.EIP, B, aDisasm.CompleteInstr]);
120 | Writeln(S);
121 | aDisasm.EIP := aDisasm.EIP + nLen;
122 | Inc(pData, nLen);
123 | until (aDisasm.Instruction.Opcode = OPCODE_RET) or (nLen <= 0);
124 | end;
125 |
126 | begin
127 | try
128 | WriteLn('BeaEngine: ', BeaEngineVersionInfo);
129 | WriteLn('');
130 | WriteLn('DisAsm ExpandFileNameCase32:', sLineBreak);
131 | DisAsmFunctionCode(@DelphiExpandFileNameCaseCode32, ARCHI_X32);
132 | WriteLn('');
133 | WriteLn('DisAsm ExpandFileNameCase64:', sLineBreak);
134 | DisAsmFunctionCode(@DelphiExpandFileNameCaseCode64, ARCHI_X64);
135 | WriteLn('');
136 | WriteLn('Done.');
137 | except
138 | on E: Exception do
139 | WriteLn('Error Decompiler: ', E.Message);
140 | end;
141 | ReadLn;
142 | end.
143 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Mozilla Public License Version 2.0
2 | ==================================
3 |
4 | 1. Definitions
5 | --------------
6 |
7 | 1.1. "Contributor"
8 | means each individual or legal entity that creates, contributes to
9 | the creation of, or owns Covered Software.
10 |
11 | 1.2. "Contributor Version"
12 | means the combination of the Contributions of others (if any) used
13 | by a Contributor and that particular Contributor's Contribution.
14 |
15 | 1.3. "Contribution"
16 | means Covered Software of a particular Contributor.
17 |
18 | 1.4. "Covered Software"
19 | means Source Code Form to which the initial Contributor has attached
20 | the notice in Exhibit A, the Executable Form of such Source Code
21 | Form, and Modifications of such Source Code Form, in each case
22 | including portions thereof.
23 |
24 | 1.5. "Incompatible With Secondary Licenses"
25 | means
26 |
27 | (a) that the initial Contributor has attached the notice described
28 | in Exhibit B to the Covered Software; or
29 |
30 | (b) that the Covered Software was made available under the terms of
31 | version 1.1 or earlier of the License, but not also under the
32 | terms of a Secondary License.
33 |
34 | 1.6. "Executable Form"
35 | means any form of the work other than Source Code Form.
36 |
37 | 1.7. "Larger Work"
38 | means a work that combines Covered Software with other material, in
39 | a separate file or files, that is not Covered Software.
40 |
41 | 1.8. "License"
42 | means this document.
43 |
44 | 1.9. "Licensable"
45 | means having the right to grant, to the maximum extent possible,
46 | whether at the time of the initial grant or subsequently, any and
47 | all of the rights conveyed by this License.
48 |
49 | 1.10. "Modifications"
50 | means any of the following:
51 |
52 | (a) any file in Source Code Form that results from an addition to,
53 | deletion from, or modification of the contents of Covered
54 | Software; or
55 |
56 | (b) any new file in Source Code Form that contains any Covered
57 | Software.
58 |
59 | 1.11. "Patent Claims" of a Contributor
60 | means any patent claim(s), including without limitation, method,
61 | process, and apparatus claims, in any patent Licensable by such
62 | Contributor that would be infringed, but for the grant of the
63 | License, by the making, using, selling, offering for sale, having
64 | made, import, or transfer of either its Contributions or its
65 | Contributor Version.
66 |
67 | 1.12. "Secondary License"
68 | means either the GNU General Public License, Version 2.0, the GNU
69 | Lesser General Public License, Version 2.1, the GNU Affero General
70 | Public License, Version 3.0, or any later versions of those
71 | licenses.
72 |
73 | 1.13. "Source Code Form"
74 | means the form of the work preferred for making modifications.
75 |
76 | 1.14. "You" (or "Your")
77 | means an individual or a legal entity exercising rights under this
78 | License. For legal entities, "You" includes any entity that
79 | controls, is controlled by, or is under common control with You. For
80 | purposes of this definition, "control" means (a) the power, direct
81 | or indirect, to cause the direction or management of such entity,
82 | whether by contract or otherwise, or (b) ownership of more than
83 | fifty percent (50%) of the outstanding shares or beneficial
84 | ownership of such entity.
85 |
86 | 2. License Grants and Conditions
87 | --------------------------------
88 |
89 | 2.1. Grants
90 |
91 | Each Contributor hereby grants You a world-wide, royalty-free,
92 | non-exclusive license:
93 |
94 | (a) under intellectual property rights (other than patent or trademark)
95 | Licensable by such Contributor to use, reproduce, make available,
96 | modify, display, perform, distribute, and otherwise exploit its
97 | Contributions, either on an unmodified basis, with Modifications, or
98 | as part of a Larger Work; and
99 |
100 | (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | for sale, have made, import, and otherwise transfer either its
102 | Contributions or its Contributor Version.
103 |
104 | 2.2. Effective Date
105 |
106 | The licenses granted in Section 2.1 with respect to any Contribution
107 | become effective for each Contribution on the date the Contributor first
108 | distributes such Contribution.
109 |
110 | 2.3. Limitations on Grant Scope
111 |
112 | The licenses granted in this Section 2 are the only rights granted under
113 | this License. No additional rights or licenses will be implied from the
114 | distribution or licensing of Covered Software under this License.
115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | Contributor:
117 |
118 | (a) for any code that a Contributor has removed from Covered Software;
119 | or
120 |
121 | (b) for infringements caused by: (i) Your and any other third party's
122 | modifications of Covered Software, or (ii) the combination of its
123 | Contributions with other software (except as part of its Contributor
124 | Version); or
125 |
126 | (c) under Patent Claims infringed by Covered Software in the absence of
127 | its Contributions.
128 |
129 | This License does not grant any rights in the trademarks, service marks,
130 | or logos of any Contributor (except as may be necessary to comply with
131 | the notice requirements in Section 3.4).
132 |
133 | 2.4. Subsequent Licenses
134 |
135 | No Contributor makes additional grants as a result of Your choice to
136 | distribute the Covered Software under a subsequent version of this
137 | License (see Section 10.2) or under the terms of a Secondary License (if
138 | permitted under the terms of Section 3.3).
139 |
140 | 2.5. Representation
141 |
142 | Each Contributor represents that the Contributor believes its
143 | Contributions are its original creation(s) or it has sufficient rights
144 | to grant the rights to its Contributions conveyed by this License.
145 |
146 | 2.6. Fair Use
147 |
148 | This License is not intended to limit any rights You have under
149 | applicable copyright doctrines of fair use, fair dealing, or other
150 | equivalents.
151 |
152 | 2.7. Conditions
153 |
154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | in Section 2.1.
156 |
157 | 3. Responsibilities
158 | -------------------
159 |
160 | 3.1. Distribution of Source Form
161 |
162 | All distribution of Covered Software in Source Code Form, including any
163 | Modifications that You create or to which You contribute, must be under
164 | the terms of this License. You must inform recipients that the Source
165 | Code Form of the Covered Software is governed by the terms of this
166 | License, and how they can obtain a copy of this License. You may not
167 | attempt to alter or restrict the recipients' rights in the Source Code
168 | Form.
169 |
170 | 3.2. Distribution of Executable Form
171 |
172 | If You distribute Covered Software in Executable Form then:
173 |
174 | (a) such Covered Software must also be made available in Source Code
175 | Form, as described in Section 3.1, and You must inform recipients of
176 | the Executable Form how they can obtain a copy of such Source Code
177 | Form by reasonable means in a timely manner, at a charge no more
178 | than the cost of distribution to the recipient; and
179 |
180 | (b) You may distribute such Executable Form under the terms of this
181 | License, or sublicense it under different terms, provided that the
182 | license for the Executable Form does not attempt to limit or alter
183 | the recipients' rights in the Source Code Form under this License.
184 |
185 | 3.3. Distribution of a Larger Work
186 |
187 | You may create and distribute a Larger Work under terms of Your choice,
188 | provided that You also comply with the requirements of this License for
189 | the Covered Software. If the Larger Work is a combination of Covered
190 | Software with a work governed by one or more Secondary Licenses, and the
191 | Covered Software is not Incompatible With Secondary Licenses, this
192 | License permits You to additionally distribute such Covered Software
193 | under the terms of such Secondary License(s), so that the recipient of
194 | the Larger Work may, at their option, further distribute the Covered
195 | Software under the terms of either this License or such Secondary
196 | License(s).
197 |
198 | 3.4. Notices
199 |
200 | You may not remove or alter the substance of any license notices
201 | (including copyright notices, patent notices, disclaimers of warranty,
202 | or limitations of liability) contained within the Source Code Form of
203 | the Covered Software, except that You may alter any license notices to
204 | the extent required to remedy known factual inaccuracies.
205 |
206 | 3.5. Application of Additional Terms
207 |
208 | You may choose to offer, and to charge a fee for, warranty, support,
209 | indemnity or liability obligations to one or more recipients of Covered
210 | Software. However, You may do so only on Your own behalf, and not on
211 | behalf of any Contributor. You must make it absolutely clear that any
212 | such warranty, support, indemnity, or liability obligation is offered by
213 | You alone, and You hereby agree to indemnify every Contributor for any
214 | liability incurred by such Contributor as a result of warranty, support,
215 | indemnity or liability terms You offer. You may include additional
216 | disclaimers of warranty and limitations of liability specific to any
217 | jurisdiction.
218 |
219 | 4. Inability to Comply Due to Statute or Regulation
220 | ---------------------------------------------------
221 |
222 | If it is impossible for You to comply with any of the terms of this
223 | License with respect to some or all of the Covered Software due to
224 | statute, judicial order, or regulation then You must: (a) comply with
225 | the terms of this License to the maximum extent possible; and (b)
226 | describe the limitations and the code they affect. Such description must
227 | be placed in a text file included with all distributions of the Covered
228 | Software under this License. Except to the extent prohibited by statute
229 | or regulation, such description must be sufficiently detailed for a
230 | recipient of ordinary skill to be able to understand it.
231 |
232 | 5. Termination
233 | --------------
234 |
235 | 5.1. The rights granted under this License will terminate automatically
236 | if You fail to comply with any of its terms. However, if You become
237 | compliant, then the rights granted under this License from a particular
238 | Contributor are reinstated (a) provisionally, unless and until such
239 | Contributor explicitly and finally terminates Your grants, and (b) on an
240 | ongoing basis, if such Contributor fails to notify You of the
241 | non-compliance by some reasonable means prior to 60 days after You have
242 | come back into compliance. Moreover, Your grants from a particular
243 | Contributor are reinstated on an ongoing basis if such Contributor
244 | notifies You of the non-compliance by some reasonable means, this is the
245 | first time You have received notice of non-compliance with this License
246 | from such Contributor, and You become compliant prior to 30 days after
247 | Your receipt of the notice.
248 |
249 | 5.2. If You initiate litigation against any entity by asserting a patent
250 | infringement claim (excluding declaratory judgment actions,
251 | counter-claims, and cross-claims) alleging that a Contributor Version
252 | directly or indirectly infringes any patent, then the rights granted to
253 | You by any and all Contributors for the Covered Software under Section
254 | 2.1 of this License shall terminate.
255 |
256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | end user license agreements (excluding distributors and resellers) which
258 | have been validly granted by You or Your distributors under this License
259 | prior to termination shall survive termination.
260 |
261 | ************************************************************************
262 | * *
263 | * 6. Disclaimer of Warranty *
264 | * ------------------------- *
265 | * *
266 | * Covered Software is provided under this License on an "as is" *
267 | * basis, without warranty of any kind, either expressed, implied, or *
268 | * statutory, including, without limitation, warranties that the *
269 | * Covered Software is free of defects, merchantable, fit for a *
270 | * particular purpose or non-infringing. The entire risk as to the *
271 | * quality and performance of the Covered Software is with You. *
272 | * Should any Covered Software prove defective in any respect, You *
273 | * (not any Contributor) assume the cost of any necessary servicing, *
274 | * repair, or correction. This disclaimer of warranty constitutes an *
275 | * essential part of this License. No use of any Covered Software is *
276 | * authorized under this License except under this disclaimer. *
277 | * *
278 | ************************************************************************
279 |
280 | ************************************************************************
281 | * *
282 | * 7. Limitation of Liability *
283 | * -------------------------- *
284 | * *
285 | * Under no circumstances and under no legal theory, whether tort *
286 | * (including negligence), contract, or otherwise, shall any *
287 | * Contributor, or anyone who distributes Covered Software as *
288 | * permitted above, be liable to You for any direct, indirect, *
289 | * special, incidental, or consequential damages of any character *
290 | * including, without limitation, damages for lost profits, loss of *
291 | * goodwill, work stoppage, computer failure or malfunction, or any *
292 | * and all other commercial damages or losses, even if such party *
293 | * shall have been informed of the possibility of such damages. This *
294 | * limitation of liability shall not apply to liability for death or *
295 | * personal injury resulting from such party's negligence to the *
296 | * extent applicable law prohibits such limitation. Some *
297 | * jurisdictions do not allow the exclusion or limitation of *
298 | * incidental or consequential damages, so this exclusion and *
299 | * limitation may not apply to You. *
300 | * *
301 | ************************************************************************
302 |
303 | 8. Litigation
304 | -------------
305 |
306 | Any litigation relating to this License may be brought only in the
307 | courts of a jurisdiction where the defendant maintains its principal
308 | place of business and such litigation shall be governed by laws of that
309 | jurisdiction, without reference to its conflict-of-law provisions.
310 | Nothing in this Section shall prevent a party's ability to bring
311 | cross-claims or counter-claims.
312 |
313 | 9. Miscellaneous
314 | ----------------
315 |
316 | This License represents the complete agreement concerning the subject
317 | matter hereof. If any provision of this License is held to be
318 | unenforceable, such provision shall be reformed only to the extent
319 | necessary to make it enforceable. Any law or regulation which provides
320 | that the language of a contract shall be construed against the drafter
321 | shall not be used to construe this License against a Contributor.
322 |
323 | 10. Versions of the License
324 | ---------------------------
325 |
326 | 10.1. New Versions
327 |
328 | Mozilla Foundation is the license steward. Except as provided in Section
329 | 10.3, no one other than the license steward has the right to modify or
330 | publish new versions of this License. Each version will be given a
331 | distinguishing version number.
332 |
333 | 10.2. Effect of New Versions
334 |
335 | You may distribute the Covered Software under the terms of the version
336 | of the License under which You originally received the Covered Software,
337 | or under the terms of any subsequent version published by the license
338 | steward.
339 |
340 | 10.3. Modified Versions
341 |
342 | If you create software not governed by this License, and you want to
343 | create a new license for such software, you may create and use a
344 | modified version of this License if you rename the license and remove
345 | any references to the name of the license steward (except to note that
346 | such modified license differs from this License).
347 |
348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | Licenses
350 |
351 | If You choose to distribute Source Code Form that is Incompatible With
352 | Secondary Licenses under the terms of this version of the License, the
353 | notice described in Exhibit B of this License must be attached.
354 |
355 | Exhibit A - Source Code Form License Notice
356 | -------------------------------------------
357 |
358 | This Source Code Form is subject to the terms of the Mozilla Public
359 | License, v. 2.0. If a copy of the MPL was not distributed with this
360 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
361 |
362 | If it is not possible or desirable to put the notice in a particular
363 | file, then You may include the notice in a location (such as a LICENSE
364 | file in a relevant directory) where a recipient would be likely to look
365 | for such a notice.
366 |
367 | You may add additional accurate notices of copyright ownership.
368 |
369 | Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ---------------------------------------------------------
371 |
372 | This Source Code Form is "Incompatible With Secondary Licenses", as
373 | defined by the Mozilla Public License, v. 2.0.
374 |
--------------------------------------------------------------------------------
/Lib/aarch64-darwin/libBeaEngine.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Lib/aarch64-darwin/libBeaEngine.dylib
--------------------------------------------------------------------------------
/Lib/i386-win32/BeaEngine.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Lib/i386-win32/BeaEngine.dll
--------------------------------------------------------------------------------
/Lib/x86_64-darwin/libBeaEngine.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Lib/x86_64-darwin/libBeaEngine.dylib
--------------------------------------------------------------------------------
/Lib/x86_64-win64/BeaEngine.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Lib/x86_64-win64/BeaEngine.dll
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BeaEngineDelphi
2 | 
3 | 
4 | 
5 | 
6 |
7 | BeaEngineDelphi is a [Delphi](http://www.embarcadero.com/products/delphi) and [Free Pascal](https://www.freepascal.org/) binding for the [BeaEngine](https://github.com/BeaEngine/beaengine/). It supports BeaEngine and provides a friendly and simple type-safe API that is ridiculously easy to learn and quick to pick up.
8 |
9 | BeaEngine is a C library designed to decode instructions from 16 bits, 32 bits and 64 bits intel architectures. It includes standard instructions set and instructions set from FPU, MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, VMX, CLMUL, AES, MPX, AVX, AVX2, AVX512 (VEX & EVEX prefixes), CET, BMI1, BMI2, SGX, UINTR, KL, TDX and AMX extensions. If you want to analyze malicious codes and more generally obfuscated codes, BeaEngine sends back a complex structure that describes precisely the analyzed instructions.
10 |
11 | ## Features
12 | * **Supports** BeaEngine 5, x16 bits, x32 bits and x64 bits intel architectures.
13 | * **Supports** Delphi XE2 and greater, and FPC 3 and greater.
14 | * **Supports** Static libraries: i386-win32, x86_64-win64, i386-linux, x86_64-linux, arm-linux, aarch64-linux, x86_64-darwin, aarch64-darwin, arm-android, aarch64-android, loongarch64-linux.
15 | * **Supports** Dynamic libraries: i386-win32, x86_64-win64, x86_64-darwin, aarch64-darwin.
16 |
17 | ## Installation: Manual
18 | To install the BeaEngineDelphi binding, follow these steps:
19 |
20 | 1. Clone the repository:
21 | ```sh
22 | git clone https://github.com/delphilite/BeaEngineDelphi.git
23 | ```
24 |
25 | 2. Add the BeaEngineDelphi\Source directory to the project or IDE's search path.
26 |
27 | ## Installation: Delphinus-Support
28 | BeaEngineDelphi should now be listed in Delphinus package manager.
29 |
30 | Be sure to restart Delphi after installing via Delphinus otherwise the units may not be found in your test projects.
31 |
32 | ## Usage
33 | Included is the wrapper record `TDisasm` in `BeaEngineDelphi.pas`. The example bellow is incomplete, but it may give you an impression how to use it.
34 |
35 | ```pas
36 | uses
37 | SysUtils, BeaEngineDelphi;
38 |
39 | procedure DisAsmFunctionCode(const AFunc: Pointer);
40 | var
41 | aDisasm: TDisasm;
42 | nLen: LongWord;
43 | pData: PByte;
44 | B, S: string;
45 | begin
46 | FillChar(aDisasm, SizeOf(TDISASM), 0);
47 | aDisasm.EIP := UIntPtr(AFunc);
48 | {$IFDEF CPUX64}
49 | aDisasm.Archi := ARCHI_X64;
50 | {$ELSE}
51 | aDisasm.Archi := ARCHI_X32;
52 | {$ENDIF}
53 | aDisasm.Options := NoTabulation + MasmSyntax;
54 | pData := PByte(AFunc);
55 | repeat
56 | nLen := Disasm(aDisasm);
57 | B := BufferToHex(pData, nLen);
58 | S := Format('%.8x %-16s %s', [aDisasm.EIP, B, aDisasm.CompleteInstr]);
59 | Writeln(S);
60 | aDisasm.EIP := aDisasm.EIP + nLen;
61 | Inc(pData, nLen);
62 | until (aDisasm.Instruction.Opcode = OPCODE_RET) or (nLen <= 0);
63 | end;
64 |
65 | begin
66 | try
67 | WriteLn('BeaEngine: ', BeaEngineVersionInfo, ', DisAsm ExpandFileNameCase ...');
68 | WriteLn('');
69 | DisAsmFunctionCode(@SysUtils.ExpandFileNameCase);
70 | WriteLn('');
71 | WriteLn('Done.');
72 | except
73 | on E: Exception do
74 | WriteLn('Error Decompiler: ', E.Message);
75 | end;
76 | ReadLn;
77 | end.
78 | ```
79 |
80 | For more examples based on low-level API, refer to the test cases under the demos directory.
81 |
82 | ## Documentation
83 | For more detailed information, refer to the [BeaEngine documentation](https://github.com/BeaEngine/beaengine/blob/master/doc/beaengine.md).
84 |
85 | ## Contributing
86 | Contributions are welcome! Please fork this repository and submit pull requests with your improvements.
87 |
88 | ## License
89 | This project is licensed under the Mozilla Public License 2.0. See the [LICENSE](LICENSE) file for details.
90 |
91 | ## Acknowledgements
92 | Special thanks to the BeaEngine development team for creating and maintaining the BeaEngine.
93 |
--------------------------------------------------------------------------------
/Ref/beaengine-5.3.0/abi/BeaEngineLib.md:
--------------------------------------------------------------------------------
1 | | | | | | | | | |
2 | |-|-|-|-|-|-|-|-|
3 | |编译器|使用|平台|库名称|格式|导入|导出|调用|
4 | |gcc aarch64-linux-android|否|aarch64-android|BeaEngine.o|elf64 for arm64|sprintf stpcpy strcmp strcpy strlen memcpy memset|BeaEngineRevision BeaEngineVersion Disasm|fastcall|
5 | |xcode14|是|aarch64-darwin|BeaEngine.o|macho for arm64|_sprintf _strcmp _strcpy _strlen _memcpy ___sprintf_chk ___stack_chk_fail ___stack_chk_guard ___strcpy_chk|_BeaEngineRevision _BeaEngineVersion _Disasm|fastcall|
6 | |gcc aarch64-linux-gnu|是|aarch64-linux|BeaEngine.o|elf64 for arm64|sprintf stpcpy strcmp strcpy strlen memcpy memset|BeaEngineRevision BeaEngineVersion Disasm|fastcall|
7 | |gcc arm-linux-androideabi|否|arm-android|BeaEngine.o|elf for arm|sprintf stpcpy strcmp strcpy strlen memcpy memset|BeaEngineRevision BeaEngineVersion Disasm|fastcall|
8 | |gcc x86_64-pc-linux-gnu|是|i386-linux|BeaEngine.o|elf|sprintf stpcpy strcmp strcpy strlen|BeaEngineRevision BeaEngineVersion Disasm|cdecl|
9 | |bcb12|否|i386-win32|BeaEngine.obj|omf|_sprintf _strcmp _strcpy _strlen _memcpy _memset|BeaEngineRevision BeaEngineVersion Disasm|stdcall|
10 | |bcb12 -STDCALL|是|i386-win32|BeaEngine.obj|omf|_sprintf _strcmp _strcpy _strlen _memcpy _memset|_BeaEngineRevision _BeaEngineVersion _Disasm|cdecl|
11 | |gcc tdm64|否|i386-win32|BeaEngine.o|coff|_sprintf _strcpy _strlen|_BeaEngineRevision@0 _BeaEngineVersion@0 _Disasm@4|stdcall|
12 | |gcc tdm64 -STDCALL|是|i386-win32|BeaEngine.o|coff|_sprintf _strcpy _strlen|_BeaEngineRevision _BeaEngineVersion _Disasm|cdecl|
13 | |msvc|否|i386-win32|BeaEngine.dll|pe|-|_BeaEngineRevision@0 _BeaEngineVersion@0 _Disasm@4|stdcall|
14 | |msvc -STDCALL|否|i386-win32|BeaEngine.dll|pe|-|BeaEngineRevision BeaEngineVersion Disasm|cdecl|
15 | |xcode14|是|x86_64-darwin|BeaEngine.o|macho for amd64|_sprintf _strcmp _strcpy _strlen _memcpy ___bzero ___sprintf_chk ___stack_chk_fail ___stack_chk_guard ___strcpy_chk|_BeaEngineRevision _BeaEngineVersion _Disasm|fastcall|
16 | |gcc x86_64-pc-linux-gnu|是|x86_64-linux|BeaEngine.o|elf64 for x86-64|sprintf stpcpy strcmp strcpy strlen|BeaEngineRevision BeaEngineVersion Disasm|fastcall|
17 | |pelles c|是|x86_64-win64|BeaEngine.obj|coff for amd64|sprintf strcmp strcpy strlen memset|BeaEngineRevision BeaEngineVersion Disasm|fastcall|
18 | |pelles c|否|x86_64-win64|BeaEngine.dll|pe64|-|BeaEngineRevision BeaEngineVersion Disasm|fastcall|
19 | |gcc tdm64|是|x86_64-win64|BeaEngine.o|coff for amd64|sprintf strcpy strlen|BeaEngineRevision BeaEngineVersion Disasm|fastcall|
20 |
--------------------------------------------------------------------------------
/Ref/beaengine-5.3.0/cb/BeaEngineLib.cbp:
--------------------------------------------------------------------------------
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 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
--------------------------------------------------------------------------------
/Ref/beaengine-5.3.0/include/beaengine/BeaEngine.h:
--------------------------------------------------------------------------------
1 | #ifndef _BEA_ENGINE_
2 | #define _BEA_ENGINE_
3 | #if defined(__cplusplus) && defined(__BORLANDC__)
4 | namespace BeaEngine {
5 | #endif
6 |
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | #if !defined(BEA_ENGINE_STATIC)
13 | #if defined(BUILD_BEA_ENGINE_DLL)
14 | #define BEA_API bea__api_export__
15 | #else
16 | #define BEA_API bea__api_import__
17 | #endif
18 | #else
19 | #define BEA_API
20 | #endif
21 |
22 |
23 | #define INSTRUCT_LENGTH 80
24 |
25 | #pragma pack(1)
26 | typedef struct {
27 | UInt8 P0;
28 | UInt8 P1;
29 | UInt8 P2;
30 | UInt8 mm;
31 | UInt8 pp;
32 | UInt8 R;
33 | UInt8 X;
34 | UInt8 B;
35 | UInt8 R1;
36 | UInt8 vvvv;
37 | UInt8 V;
38 | UInt8 aaa;
39 | UInt8 W;
40 | UInt8 z;
41 | UInt8 b;
42 | UInt8 LL;
43 | UInt8 state;
44 | UInt8 masking;
45 | UInt8 tupletype;
46 | } EVEX_Struct ;
47 | #pragma pack()
48 |
49 | #pragma pack(1)
50 | typedef struct {
51 | UInt8 L;
52 | UInt8 vvvv;
53 | UInt8 mmmmm;
54 | UInt8 pp;
55 | UInt8 state;
56 | UInt8 opcode;
57 | } VEX_Struct ;
58 | #pragma pack()
59 |
60 | #pragma pack(1)
61 | typedef struct {
62 | UInt8 W_;
63 | UInt8 R_;
64 | UInt8 X_;
65 | UInt8 B_;
66 | UInt8 state;
67 | } REX_Struct ;
68 | #pragma pack()
69 |
70 | #pragma pack(1)
71 | typedef struct {
72 | int Number;
73 | int NbUndefined;
74 | UInt8 LockPrefix;
75 | UInt8 OperandSize;
76 | UInt8 AddressSize;
77 | UInt8 RepnePrefix;
78 | UInt8 RepPrefix;
79 | UInt8 FSPrefix;
80 | UInt8 SSPrefix;
81 | UInt8 GSPrefix;
82 | UInt8 ESPrefix;
83 | UInt8 CSPrefix;
84 | UInt8 DSPrefix;
85 | UInt8 BranchTaken;
86 | UInt8 BranchNotTaken;
87 | REX_Struct REX;
88 | char alignment[2];
89 | } PREFIXINFO ;
90 | #pragma pack()
91 |
92 | #pragma pack(1)
93 | typedef struct {
94 | UInt8 OF_;
95 | UInt8 SF_;
96 | UInt8 ZF_;
97 | UInt8 AF_;
98 | UInt8 PF_;
99 | UInt8 CF_;
100 | UInt8 TF_;
101 | UInt8 IF_;
102 | UInt8 DF_;
103 | UInt8 NT_;
104 | UInt8 RF_;
105 | UInt8 alignment;
106 | } EFLStruct ;
107 | #pragma pack()
108 |
109 | #pragma pack(4)
110 | typedef struct {
111 | Int64 BaseRegister;
112 | Int64 IndexRegister;
113 | Int32 Scale;
114 | Int64 Displacement;
115 | } MEMORYTYPE ;
116 | #pragma pack()
117 |
118 | #pragma pack(4)
119 | typedef struct {
120 | Int64 type;
121 | Int64 gpr;
122 | Int64 mmx;
123 | Int64 xmm;
124 | Int64 ymm;
125 | Int64 zmm;
126 | Int64 special;
127 | Int64 cr;
128 | Int64 dr;
129 | Int64 mem_management;
130 | Int64 mpx;
131 | Int64 opmask;
132 | Int64 segment;
133 | Int64 fpu;
134 | Int64 tmm;
135 | } REGISTERTYPE ;
136 | #pragma pack()
137 |
138 | #pragma pack(1)
139 | typedef struct {
140 | Int32 Category;
141 | Int32 Opcode;
142 | char Mnemonic[24];
143 | Int32 BranchType;
144 | EFLStruct Flags;
145 | UInt64 AddrValue;
146 | Int64 Immediat;
147 | REGISTERTYPE ImplicitModifiedRegs;
148 | REGISTERTYPE ImplicitUsedRegs;
149 | } INSTRTYPE;
150 | #pragma pack()
151 |
152 | #pragma pack(1)
153 | typedef struct {
154 | char OpMnemonic[24];
155 | Int64 OpType;
156 | Int32 OpSize;
157 | Int32 OpPosition;
158 | UInt32 AccessMode;
159 | MEMORYTYPE Memory;
160 | REGISTERTYPE Registers;
161 | UInt32 SegmentReg;
162 | } OPTYPE;
163 | #pragma pack()
164 |
165 | /* reserved structure used for thread-safety */
166 | /* unusable by customer */
167 | #pragma pack(1)
168 | typedef struct {
169 | UIntPtr EIP_;
170 | UInt64 EIP_VA;
171 | UIntPtr EIP_REAL;
172 | Int32 OriginalOperandSize;
173 | Int32 OperandSize;
174 | Int32 MemDecoration;
175 | Int32 AddressSize;
176 | Int32 MOD_;
177 | Int32 RM_;
178 | Int32 INDEX_;
179 | Int32 SCALE_;
180 | Int32 BASE_;
181 | Int32 REGOPCODE;
182 | UInt32 DECALAGE_EIP;
183 | Int32 FORMATNUMBER;
184 | Int32 SYNTAX_;
185 | UInt64 EndOfBlock;
186 | Int32 RelativeAddress;
187 | UInt32 Architecture;
188 | Int32 ImmediatSize;
189 | Int32 NB_PREFIX;
190 | Int32 PrefRepe;
191 | Int32 PrefRepne;
192 | UInt32 SEGMENTREGS;
193 | UInt32 SEGMENTFS;
194 | Int32 third_arg;
195 | UInt64 OPTIONS;
196 | Int32 ERROR_OPCODE;
197 | REX_Struct REX;
198 | Int32 OutOfBlock;
199 | VEX_Struct VEX;
200 | EVEX_Struct EVEX;
201 | Int32 VSIB_;
202 | Int32 Register_;
203 | } InternalDatas;
204 | #pragma pack()
205 |
206 | /* ************** main structure ************ */
207 | #pragma pack(1)
208 | typedef struct _Disasm {
209 | UIntPtr EIP;
210 | UInt64 VirtualAddr;
211 | UInt32 SecurityBlock;
212 | char CompleteInstr[INSTRUCT_LENGTH];
213 | UInt32 Archi;
214 | UInt64 Options;
215 | INSTRTYPE Instruction;
216 | OPTYPE Operand1;
217 | OPTYPE Operand2;
218 | OPTYPE Operand3;
219 | OPTYPE Operand4;
220 | OPTYPE Operand5;
221 | OPTYPE Operand6;
222 | OPTYPE Operand7;
223 | OPTYPE Operand8;
224 | OPTYPE Operand9;
225 | PREFIXINFO Prefix;
226 | Int32 Error;
227 | InternalDatas Reserved_;
228 | } DISASM, *PDISASM, *LPDISASM;
229 | #pragma pack()
230 |
231 | /* #UD exception */
232 | #define UD_ 2
233 | #define DE__ 3
234 |
235 | #define ESReg 0x1
236 | #define DSReg 0x2
237 | #define FSReg 0x4
238 | #define GSReg 0x8
239 | #define CSReg 0x10
240 | #define SSReg 0x20
241 |
242 | #define InvalidPrefix 4
243 | #define SuperfluousPrefix 2
244 | #define NotUsedPrefix 0
245 | #define MandatoryPrefix 8
246 | #define InUsePrefix 1
247 |
248 | #define LowPosition 0
249 | #define HighPosition 1
250 |
251 | /* EVEX Masking */
252 |
253 | #define NO_MASK 0
254 | #define MERGING 1
255 | #define MERGING_ZEROING 2
256 |
257 | /* EVEX Compressed Displacement */
258 |
259 | #define FULL 1
260 | #define HALF 2
261 | #define FULL_MEM 3
262 | #define TUPLE1_SCALAR__8 4
263 | #define TUPLE1_SCALAR__16 5
264 | #define TUPLE1_SCALAR 6
265 | #define TUPLE1_FIXED__32 7
266 | #define TUPLE1_FIXED__64 8
267 | #define TUPLE2 9
268 | #define TUPLE4 10
269 | #define TUPLE8 11
270 | #define HALF_MEM 12
271 | #define QUARTER_MEM 13
272 | #define EIGHTH_MEM 14
273 | #define MEM128 15
274 | #define MOVDDUP 16
275 |
276 | enum INSTRUCTION_TYPE
277 | {
278 | GENERAL_PURPOSE_INSTRUCTION = 0x10000,
279 | FPU_INSTRUCTION = 0x20000,
280 | MMX_INSTRUCTION = 0x30000,
281 | SSE_INSTRUCTION = 0x40000,
282 | SSE2_INSTRUCTION = 0x50000,
283 | SSE3_INSTRUCTION = 0x60000,
284 | SSSE3_INSTRUCTION = 0x70000,
285 | SSE41_INSTRUCTION = 0x80000,
286 | SSE42_INSTRUCTION = 0x90000,
287 | SYSTEM_INSTRUCTION = 0xa0000,
288 | VM_INSTRUCTION = 0xb0000,
289 | UNDOCUMENTED_INSTRUCTION = 0xc0000,
290 | AMD_INSTRUCTION = 0xd0000,
291 | ILLEGAL_INSTRUCTION = 0xe0000,
292 | AES_INSTRUCTION = 0xf0000,
293 | CLMUL_INSTRUCTION = 0x100000,
294 | AVX_INSTRUCTION = 0x110000,
295 | AVX2_INSTRUCTION = 0x120000,
296 | MPX_INSTRUCTION = 0x130000,
297 | AVX512_INSTRUCTION = 0x140000,
298 | SHA_INSTRUCTION = 0x150000,
299 | BMI2_INSTRUCTION = 0x160000,
300 | CET_INSTRUCTION = 0x170000,
301 | BMI1_INSTRUCTION = 0x180000,
302 | XSAVEOPT_INSTRUCTION = 0x190000,
303 | FSGSBASE_INSTRUCTION = 0x1a0000,
304 | CLWB_INSTRUCTION = 0x1b0000,
305 | CLFLUSHOPT_INSTRUCTION = 0x1c0000,
306 | FXSR_INSTRUCTION = 0x1d0000,
307 | XSAVE_INSTRUCTION = 0x1e0000,
308 | SGX_INSTRUCTION = 0x1f0000,
309 | PCONFIG_INSTRUCTION = 0x200000,
310 | UINTR_INSTRUCTION = 0x210000,
311 | KL_INSTRUCTION = 0x220000,
312 | AMX_INSTRUCTION = 0x230000,
313 |
314 | DATA_TRANSFER = 0x1,
315 | ARITHMETIC_INSTRUCTION,
316 | LOGICAL_INSTRUCTION,
317 | SHIFT_ROTATE,
318 | BIT_UInt8,
319 | CONTROL_TRANSFER,
320 | STRING_INSTRUCTION,
321 | InOutINSTRUCTION,
322 | ENTER_LEAVE_INSTRUCTION,
323 | FLAG_CONTROL_INSTRUCTION,
324 | SEGMENT_REGISTER,
325 | MISCELLANEOUS_INSTRUCTION,
326 | COMPARISON_INSTRUCTION,
327 | LOGARITHMIC_INSTRUCTION,
328 | TRIGONOMETRIC_INSTRUCTION,
329 | UNSUPPORTED_INSTRUCTION,
330 | LOAD_CONSTANTS,
331 | FPUCONTROL,
332 | STATE_MANAGEMENT,
333 | CONVERSION_INSTRUCTION,
334 | SHUFFLE_UNPACK,
335 | PACKED_SINGLE_PRECISION,
336 | SIMD128bits,
337 | SIMD64bits,
338 | CACHEABILITY_CONTROL,
339 | FP_INTEGER_CONVERSION,
340 | SPECIALIZED_128bits,
341 | SIMD_FP_PACKED,
342 | SIMD_FP_HORIZONTAL ,
343 | AGENT_SYNCHRONISATION,
344 | PACKED_ALIGN_RIGHT ,
345 | PACKED_SIGN,
346 | PACKED_BLENDING_INSTRUCTION,
347 | PACKED_TEST,
348 | PACKED_MINMAX,
349 | HORIZONTAL_SEARCH,
350 | PACKED_EQUALITY,
351 | STREAMING_LOAD,
352 | INSERTION_EXTRACTION,
353 | DOT_PRODUCT,
354 | SAD_INSTRUCTION,
355 | ACCELERATOR_INSTRUCTION, /* crc32, popcnt (sse4.2) */
356 | ROUND_INSTRUCTION
357 |
358 | };
359 |
360 | enum EFLAGS_STATES
361 | {
362 | TE_ = 1,
363 | MO_ = 2,
364 | RE_ = 4,
365 | SE_ = 8,
366 | UN_ = 0x10,
367 | PR_ = 0x20
368 | };
369 |
370 | enum BRANCH_TYPE
371 | {
372 | JO = 1,
373 | JC = 2,
374 | JE = 3,
375 | JA = 4,
376 | JS = 5,
377 | JP = 6,
378 | JL = 7,
379 | JG = 8,
380 | JB = 2, /* JC == JB */
381 | JECXZ = 10,
382 | JmpType = 11,
383 | CallType = 12,
384 | RetType = 13,
385 | JNO = -1,
386 | JNC = -2,
387 | JNE = -3,
388 | JNA = -4,
389 | JNS = -5,
390 | JNP = -6,
391 | JNL = -7,
392 | JNG = -8,
393 | JNB = -2 /* JNC == JNB */
394 | };
395 |
396 | enum ARGUMENTS_TYPE
397 | {
398 | NO_ARGUMENT = 0x10000,
399 | REGISTER_TYPE = 0x20000,
400 | MEMORY_TYPE = 0x30000,
401 | CONSTANT_TYPE = 0x40000,
402 |
403 | GENERAL_REG = 0x1,
404 | MMX_REG = 0x2,
405 | SSE_REG = 0x4,
406 | AVX_REG = 0x8,
407 | AVX512_REG = 0x10,
408 | SPECIAL_REG = 0x20,
409 | CR_REG = 0x40,
410 | DR_REG = 0x80,
411 | MEMORY_MANAGEMENT_REG = 0x100,
412 | MPX_REG = 0x200,
413 | OPMASK_REG = 0x400,
414 | SEGMENT_REG = 0x800,
415 | FPU_REG = 0x1000,
416 | TMM_REG = 0x2000,
417 |
418 | RELATIVE_ = 0x4000000,
419 | ABSOLUTE_ = 0x8000000,
420 |
421 | READ = 0x1,
422 | WRITE = 0x2,
423 |
424 | REG0 = 0x1,
425 | REG1 = 0x2,
426 | REG2 = 0x4,
427 | REG3 = 0x8,
428 | REG4 = 0x10,
429 | REG5 = 0x20,
430 | REG6 = 0x40,
431 | REG7 = 0x80,
432 | REG8 = 0x100,
433 | REG9 = 0x200,
434 | REG10 = 0x400,
435 | REG11 = 0x800,
436 | REG12 = 0x1000,
437 | REG13 = 0x2000,
438 | REG14 = 0x4000,
439 | REG15 = 0x8000,
440 | REG16 = 0x10000,
441 | REG17 = 0x20000,
442 | REG18 = 0x40000,
443 | REG19 = 0x80000,
444 | REG20 = 0x100000,
445 | REG21 = 0x200000,
446 | REG22 = 0x400000,
447 | REG23 = 0x800000,
448 | REG24 = 0x1000000,
449 | REG25 = 0x2000000,
450 | REG26 = 0x4000000,
451 | REG27 = 0x8000000,
452 | REG28 = 0x10000000,
453 | REG29 = 0x20000000,
454 | REG30 = 0x40000000,
455 | REG31 = 0x80000000
456 | };
457 |
458 | enum SPECIAL_INFO
459 | {
460 | UNKNOWN_OPCODE = -1,
461 | OUT_OF_BLOCK = -2,
462 |
463 | /* === mask = 0xff */
464 | NoTabulation = 0x00000000,
465 | Tabulation = 0x00000001,
466 |
467 | /* === mask = 0xff00 */
468 | MasmSyntax = 0x00000000,
469 | GoAsmSyntax = 0x00000100,
470 | NasmSyntax = 0x00000200,
471 | ATSyntax = 0x00000400,
472 | IntrinsicMemSyntax= 0x00000800,
473 |
474 | /* === mask = 0xff0000 */
475 | PrefixedNumeral = 0x00010000,
476 | SuffixedNumeral = 0x00000000,
477 |
478 | /* === mask = 0xff000000 */
479 | ShowSegmentRegs = 0x01000000,
480 | ShowEVEXMasking = 0x02000000
481 | };
482 |
483 |
484 | #ifdef __cplusplus
485 | extern "C" {
486 | #endif
487 |
488 | BEA_API int __bea_callspec__ Disasm (LPDISASM pDisAsm);
489 | BEA_API const__ char* __bea_callspec__ BeaEngineVersion (void);
490 | BEA_API const__ char* __bea_callspec__ BeaEngineRevision (void);
491 |
492 | #ifdef __cplusplus
493 | }
494 | #endif
495 |
496 |
497 | #if defined(__cplusplus) && defined(__BORLANDC__)
498 | };
499 | using namespace BeaEngine;
500 | #endif
501 | #endif
502 |
--------------------------------------------------------------------------------
/Ref/beaengine-5.3.0/include/beaengine/basic_types.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file basic_types.h
3 | * @author
4 | * @date Thu Dec 24 19:31:22 2009
5 | *
6 | * @brief Definitions of fixed-size integer types for various platforms
7 | *
8 | * This file is part of BeaEngine.
9 | *
10 | * BeaEngine is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU Lesser General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * BeaEngine is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU Lesser General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU Lesser General Public License
21 | * along with BeaEngine. If not, see . */
22 |
23 | #ifndef __BEA_BASIC_TYPES_HPP__
24 | #define __BEA_BASIC_TYPES_HPP__
25 |
26 | #include
27 |
28 | #if defined(__GNUC__) || defined (__INTEL_COMPILER) || defined(__LCC__) || defined(__POCC__)
29 | #include
30 | #endif
31 |
32 | #if defined(_MSC_VER) && !defined(__BORLANDC__)
33 | /*
34 | * Windows/Visual C++
35 | */
36 | typedef signed char Int8;
37 | typedef unsigned char UInt8;
38 | typedef signed short Int16;
39 | typedef unsigned short UInt16;
40 | typedef signed int Int32;
41 | typedef unsigned int UInt32;
42 | typedef signed __int64 Int64;
43 | typedef unsigned __int64 UInt64;
44 | #if defined(_WIN64)
45 | #define BEA_PTR_IS_64_BIT 1
46 | typedef signed __int64 IntPtr;
47 | typedef unsigned __int64 UIntPtr;
48 | #else
49 | typedef signed long IntPtr;
50 | typedef size_t UIntPtr;
51 | #endif
52 | #define BEA_HAVE_INT64 1
53 | #elif defined(__POCC__)
54 | /*
55 | * PellesC
56 | */
57 | typedef signed char Int8;
58 | typedef unsigned char UInt8;
59 | typedef signed short Int16;
60 | typedef unsigned short UInt16;
61 | typedef signed int Int32;
62 | typedef unsigned int UInt32;
63 | typedef signed long long Int64;
64 | typedef unsigned long long UInt64;
65 | #if defined(_WIN64)
66 | #define BEA_PTR_IS_64_BIT 1
67 | typedef signed long long IntPtr;
68 | typedef unsigned long long UIntPtr;
69 | #else
70 | typedef signed long IntPtr;
71 | typedef size_t UIntPtr;
72 | #endif
73 | #define BEA_HAVE_INT64 1
74 | #elif defined(__GNUC__) || defined(__LCC__)
75 | /*
76 | * Unix/GCC
77 | */
78 | typedef signed char Int8;
79 | typedef unsigned char UInt8;
80 | typedef signed short Int16;
81 | typedef unsigned short UInt16;
82 | typedef signed int Int32;
83 | typedef unsigned int UInt32;
84 | typedef intptr_t IntPtr;
85 | typedef uintptr_t UIntPtr;
86 | #if defined(__LP64__)
87 | #define BEA_PTR_IS_64_BIT 1
88 | #define BEA_LONG_IS_64_BIT 1
89 | typedef signed long Int64;
90 | typedef unsigned long UInt64;
91 | #else
92 | #if defined (__INTEL_COMPILER) || defined (__ICC) || defined (_ICC)
93 | typedef __int64 Int64;
94 | typedef unsigned __int64 UInt64;
95 | #else
96 | typedef signed long long Int64;
97 | typedef unsigned long long UInt64;
98 | #endif
99 | #endif
100 | #define BEA_HAVE_INT64 1
101 | #elif defined(__DECCXX)
102 | /*
103 | * Compaq C++
104 | */
105 | typedef signed char Int8;
106 | typedef unsigned char UInt8;
107 | typedef signed short Int16;
108 | typedef unsigned short UInt16;
109 | typedef signed int Int32;
110 | typedef unsigned int UInt32;
111 | typedef signed __int64 Int64;
112 | typedef unsigned __int64 UInt64;
113 | #if defined(__VMS)
114 | #if defined(__32BITS)
115 | typedef signed long IntPtr;
116 | typedef unsigned long UIntPtr;
117 | #else
118 | typedef Int64 IntPtr;
119 | typedef UInt64 UIntPtr;
120 | #define BEA_PTR_IS_64_BIT 1
121 | #endif
122 | #else
123 | typedef signed long IntPtr;
124 | typedef unsigned long UIntPtr;
125 | #define BEA_PTR_IS_64_BIT 1
126 | #define BEA_LONG_IS_64_BIT 1
127 | #endif
128 | #define BEA_HAVE_INT64 1
129 | #elif defined(__HP_aCC)
130 | /*
131 | * HP Ansi C++
132 | */
133 | typedef signed char Int8;
134 | typedef unsigned char UInt8;
135 | typedef signed short Int16;
136 | typedef unsigned short UInt16;
137 | typedef signed int Int32;
138 | typedef unsigned int UInt32;
139 | typedef signed long IntPtr;
140 | typedef unsigned long UIntPtr;
141 | #if defined(__LP64__)
142 | #define BEA_PTR_IS_64_BIT 1
143 | #define BEA_LONG_IS_64_BIT 1
144 | typedef signed long Int64;
145 | typedef unsigned long UInt64;
146 | #else
147 | typedef signed long long Int64;
148 | typedef unsigned long long UInt64;
149 | #endif
150 | #define BEA_HAVE_INT64 1
151 | #elif defined(__SUNPRO_CC) || defined(__SUNPRO_C)
152 | /*
153 | * SUN Forte C++
154 | */
155 | typedef signed char Int8;
156 | typedef unsigned char UInt8;
157 | typedef signed short Int16;
158 | typedef unsigned short UInt16;
159 | typedef signed int Int32;
160 | typedef unsigned int UInt32;
161 | typedef signed long IntPtr;
162 | typedef unsigned long UIntPtr;
163 | #if defined(__sparcv9)
164 | #define BEA_PTR_IS_64_BIT 1
165 | #define BEA_LONG_IS_64_BIT 1
166 | typedef signed long Int64;
167 | typedef unsigned long UInt64;
168 | #else
169 | typedef signed long long Int64;
170 | typedef unsigned long long UInt64;
171 | #endif
172 | #define BEA_HAVE_INT64 1
173 | #elif defined(__IBMCPP__)
174 | /*
175 | * IBM XL C++
176 | */
177 | typedef signed char Int8;
178 | typedef unsigned char UInt8;
179 | typedef signed short Int16;
180 | typedef unsigned short UInt16;
181 | typedef signed int Int32;
182 | typedef unsigned int UInt32;
183 | typedef signed long IntPtr;
184 | typedef unsigned long UIntPtr;
185 | #if defined(__64BIT__)
186 | #define BEA_PTR_IS_64_BIT 1
187 | #define BEA_LONG_IS_64_BIT 1
188 | typedef signed long Int64;
189 | typedef unsigned long UInt64;
190 | #else
191 | typedef signed long long Int64;
192 | typedef unsigned long long UInt64;
193 | #endif
194 | #define BEA_HAVE_INT64 1
195 | #elif defined(__BORLANDC__)
196 | /*
197 | * Borland C/C++
198 | */
199 | typedef signed char Int8;
200 | typedef unsigned char UInt8;
201 | typedef signed short Int16;
202 | typedef unsigned short UInt16;
203 | typedef signed int Int32;
204 | typedef unsigned int UInt32;
205 | typedef unsigned __int64 Int64;
206 | typedef signed __int64 UInt64;
207 | typedef signed long IntPtr;
208 | typedef unsigned long UIntPtr;
209 | #define BEA_HAVE_INT64 1
210 | #elif defined(__WATCOMC__)
211 | /*
212 | * Watcom C/C++
213 | */
214 | typedef signed char Int8;
215 | typedef unsigned char UInt8;
216 | typedef signed short Int16;
217 | typedef unsigned short UInt16;
218 | typedef signed int Int32;
219 | typedef unsigned int UInt32;
220 | typedef unsigned __int64 Int64;
221 | typedef signed __int64 UInt64;
222 | #define BEA_HAVE_INT64 1
223 | typedef size_t UIntPtr;
224 | #elif defined(__sgi)
225 | /*
226 | * MIPSpro C++
227 | */
228 | typedef signed char Int8;
229 | typedef unsigned char UInt8;
230 | typedef signed short Int16;
231 | typedef unsigned short UInt16;
232 | typedef signed int Int32;
233 | typedef unsigned int UInt32;
234 | typedef signed long IntPtr;
235 | typedef unsigned long UIntPtr;
236 | #if _MIPS_SZLONG == 64
237 | #define BEA_PTR_IS_64_BIT 1
238 | #define BEA_LONG_IS_64_BIT 1
239 | typedef signed long Int64;
240 | typedef unsigned long UInt64;
241 | #else
242 | typedef signed long long Int64;
243 | typedef unsigned long long UInt64;
244 | #endif
245 | #define BEA_HAVE_INT64 1
246 | #endif
247 |
248 | #if defined(_MSC_VER) || defined(__BORLANDC__)
249 | #define W64LIT(x) x##ui64
250 | #else
251 | #define W64LIT(x) x##ULL
252 | #endif
253 |
254 |
255 | #ifndef C_STATIC_ASSERT
256 | #define C_STATIC_ASSERT(tag_name, x) \
257 | typedef int cache_static_assert_ ## tag_name[(x) * 2-1]
258 | #endif
259 |
260 | C_STATIC_ASSERT(sizeof_Int8 , (sizeof(Int8) == 1));
261 | C_STATIC_ASSERT(sizeof_UInt8, (sizeof(UInt8) == 1));
262 |
263 | C_STATIC_ASSERT(sizeof_Int16 , (sizeof(Int16) == 2));
264 | C_STATIC_ASSERT(sizeof_UInt16, (sizeof(UInt16) == 2));
265 |
266 | C_STATIC_ASSERT(sizeof_Int32 , (sizeof(Int32) == 4));
267 | C_STATIC_ASSERT(sizeof_UInt32, (sizeof(UInt32) == 4));
268 |
269 | C_STATIC_ASSERT(sizeof_Int64 , (sizeof(Int64) == 8));
270 | C_STATIC_ASSERT(sizeof_UInt64, (sizeof(UInt64) == 8));
271 |
272 | #endif
273 |
--------------------------------------------------------------------------------
/Ref/beaengine-5.3.0/include/beaengine/export.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file export.h
3 | * @author igor.gutnik@gmail.com
4 | * @date Mon Sep 22 09:28:54 2008
5 | *
6 | * @brief This file sets things up for C dynamic library function definitions and
7 | * static inlined functions
8 | *
9 | * This file is part of BeaEngine.
10 | *
11 | * BeaEngine is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU Lesser General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * BeaEngine is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU Lesser General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU Lesser General Public License
22 | * along with BeaEngine. If not, see . */
23 |
24 | #ifndef __BEA_EXPORT_H__
25 | #define __BEA_EXPORT_H__
26 |
27 |
28 | /* Set up for C function definitions, even when using C++ */
29 |
30 | #ifdef __cplusplus
31 | #define CPP_VISIBLE_BEGIN extern "C" {
32 | #define CPP_VISIBLE_END }
33 | #else
34 | #define CPP_VISIBLE_BEGIN
35 | #define CPP_VISIBLE_END
36 | #endif
37 |
38 | #if defined(_MSC_VER)
39 | #pragma warning( disable: 4251 )
40 | #endif
41 |
42 | /* Some compilers use a special export keyword */
43 | #ifndef bea__api_export__
44 | # if defined(__BEOS__)
45 | # if defined(__GNUC__)
46 | # define bea__api_export__ __declspec(dllexport)
47 | # else
48 | # define bea__api_export__ __declspec(export)
49 | # endif
50 | # elif defined(_WIN32) || defined(_WIN64)
51 | # ifdef __BORLANDC__
52 | # define bea__api_export__ __declspec(dllexport)
53 | # define bea__api_import__ __declspec(dllimport)
54 | # elif defined(__WATCOMC__)
55 | # define bea__api_export__ __declspec(dllexport)
56 | # define bea__api_import__
57 | # else
58 | # define bea__api_export__ __declspec(dllexport)
59 | # define bea__api_import__ __declspec(dllimport)
60 | # endif
61 | # elif defined(__OS2__)
62 | # ifdef __WATCOMC__
63 | # define bea__api_export__ __declspec(dllexport)
64 | # define bea__api_import__
65 | # else
66 | # define bea__api_export__
67 | # define bea__api_import__
68 | # endif
69 | # else
70 | # if defined(_WIN32) && defined(__GNUC__) && __GNUC__ >= 4
71 | # define bea__api_export__ __attribubea__ ((visibility("default")))
72 | # define bea__api_import__ __attribubea__ ((visibility("default")))
73 | # else
74 | # define bea__api_export__
75 | # define bea__api_import__
76 | # endif
77 | # endif
78 | #endif
79 |
80 | /* Use C calling convention by default*/
81 |
82 | #ifndef __bea_callspec__
83 | #if defined(BEA_USE_STDCALL)
84 | #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(_WIN64)
85 | #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) || defined(__POCC__)
86 | #define __bea_callspec__ __stdcall
87 | #else
88 | #define __bea_callspec__
89 | #endif
90 | #else
91 | #ifdef __OS2__
92 | #define __bea_callspec__ _System
93 | #else
94 | #define __bea_callspec__
95 | #endif
96 | #endif
97 | #else
98 | #define __bea_callspec__
99 | #endif
100 | #endif
101 |
102 | #ifdef __SYMBIAN32__
103 | # ifndef EKA2
104 | # undef bea__api_export__
105 | # undef bea__api_import__
106 | # define bea__api_export__
107 | # define bea__api_import__
108 | # elif !defined(__WINS__)
109 | # undef bea__api_export__
110 | # undef bea__api_import__
111 | # define bea__api_export__ __declspec(dllexport)
112 | # define bea__api_import__ __declspec(dllexport)
113 | # endif /* !EKA2 */
114 | #endif /* __SYMBIAN32__ */
115 |
116 |
117 | #if defined(__GNUC__) && (__GNUC__ > 2)
118 | #define BEA_EXPECT_CONDITIONAL(c) (__builtin_expect((c), 1))
119 | #define BEA_UNEXPECT_CONDITIONAL(c) (__builtin_expect((c), 0))
120 | #else
121 | #define BEA_EXPECT_CONDITIONAL(c) (c)
122 | #define BEA_UNEXPECT_CONDITIONAL(c) (c)
123 | #endif
124 |
125 |
126 | /* Set up compiler-specific options for inlining functions */
127 | #ifndef BEA_HAS_INLINE
128 | #if defined(__GNUC__) || defined(__POCC__) || defined(__WATCOMC__) || defined(__SUNPRO_C)
129 | #define BEA_HAS_INLINE
130 | #else
131 | /* Add any special compiler-specific cases here */
132 | #if defined(_MSC_VER) || defined(__BORLANDC__) || \
133 | defined(__DMC__) || defined(__SC__) || \
134 | defined(__WATCOMC__) || defined(__LCC__) || \
135 | defined(__DECC) || defined(__EABI__)
136 | #ifndef __inline__
137 | #define __inline__ __inline
138 | #endif
139 | #define BEA_HAS_INLINE
140 | #else
141 | #if !defined(__MRC__) && !defined(_SGI_SOURCE)
142 | #ifndef __inline__
143 | #define __inline__ inline
144 | #endif
145 | #define BEA_HAS_INLINE
146 | #endif /* Not a funky compiler */
147 | #endif /* Visual C++ */
148 | #endif /* GNU C */
149 | #endif /* CACHE_HAS_INLINE */
150 |
151 | /* If inlining isn't supported, remove "__inline__", turning static
152 | inlined functions into static functions (resulting in code bloat
153 | in all files which include the offending header files)
154 | */
155 | #ifndef BEA_HAS_INLINE
156 | #define __inline__
157 | #endif
158 |
159 | /* fix a bug with gcc under windows */
160 |
161 | #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(_WIN64)
162 | #if defined(__MINGW32__)
163 | #define const__
164 | #else
165 | #define const__ const
166 | #endif
167 | #else
168 | #define const__ const
169 | #endif
170 |
171 |
172 |
173 | #endif
174 |
--------------------------------------------------------------------------------
/Ref/beaengine-5.3.0/include/beaengine/macros.h:
--------------------------------------------------------------------------------
1 | #ifndef __BEAENGINE_MACROS_H__
2 | #define __BEAENGINE_MACROS_H__
3 | /*
4 | ============================================================================
5 | Compiler Silencing macros
6 |
7 | Some compilers complain about parameters that are not used. This macro
8 | should keep them quiet.
9 | ============================================================================
10 | */
11 |
12 | # if defined (__GNUC__) && ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)))
13 | # define BEA_UNUSED_ARG(a) (void) (a)
14 | #elif defined (ghs) || defined (__GNUC__) || defined (__hpux) || defined (__sgi) || defined (__DECCXX) || defined (__rational__) || defined (__USLC__) || defined (BEA__RM544) || defined (__DCC__) || defined (__PGI) || defined (__TANDEM) || defined(__BORLANDC__)
15 | /*
16 | Some compilers complain about "statement with no effect" with (a).
17 | This eliminates the warnings, and no code is generated for the null
18 | conditional statement. Note, that may only be true if -O is enabled,
19 | such as with GreenHills (ghs) 1.8.8.
20 | */
21 |
22 | # define BEA_UNUSED_ARG(a) do {/* null */} while (&a == 0)
23 | #elif defined (__DMC__)
24 | #if defined(__cplusplus)
25 | #define BEA_UNUSED_ID(identifier)
26 | template
27 | inline void BEA_UNUSED_ARG(const T& BEA_UNUSED_ID(t)) { }
28 | #else
29 | #define BEA_UNUSED_ARG(a)
30 | #endif
31 | #else /* ghs || __GNUC__ || ..... */
32 | # define BEA_UNUSED_ARG(a) (a)
33 | #endif /* ghs || __GNUC__ || ..... */
34 |
35 | #if defined (_MSC_VER) || defined(__sgi) || defined (ghs) || defined (__DECCXX) || defined(__BORLANDC__) || defined (BEA_RM544) || defined (__USLC__) || defined (__DCC__) || defined (__PGI) || defined (__TANDEM) || (defined (__HP_aCC) && (__HP_aCC >= 60500))
36 | # define BEA_NOTREACHED(a)
37 | #else /* __sgi || ghs || ..... */
38 | # define BEA_NOTREACHED(a) a
39 | #endif /* __sgi || ghs || ..... */
40 |
41 | #endif /* __BEAENGINE_MACROS_H__ */
42 |
--------------------------------------------------------------------------------
/Ref/doc/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Ref/doc/logo.png
--------------------------------------------------------------------------------
/Source/BeaEngineDelphi.pas:
--------------------------------------------------------------------------------
1 | { ***************************************************** }
2 | { }
3 | { Pascal language binding for the BeaEngine }
4 | { }
5 | { Unit Name: BeaEngine Api Header }
6 | { Author: Lsuper 2024.06.01 }
7 | { Purpose: }
8 | { License: Mozilla Public License 2.0 }
9 | { }
10 | { Copyright (c) 1998-2024 Super Studio }
11 | { }
12 | { ***************************************************** }
13 |
14 | {$IFDEF FPC}
15 | {$MODE DELPHI}
16 | {$WARNINGS OFF}
17 | {$HINTS OFF}
18 | {$ENDIF FPC}
19 |
20 | {$ALIGN ON}
21 | {$MINENUMSIZE 4}
22 | {$WEAKPACKAGEUNIT}
23 |
24 | unit BeaEngineDelphi;
25 |
26 | // Define BE_STATICLINK enable static library support, otherwise use dynamic link libraries.
27 | // Support platforms such as Windows, Linux, MacOSX, Android, etc.
28 | {$DEFINE BE_STATICLINK}
29 |
30 | interface
31 |
32 | const
33 | INSTRUCT_LENGTH = 80;
34 |
35 | type
36 | EVEX_Struct = packed record
37 | P0: UInt8;
38 | P1: UInt8;
39 | P2: UInt8;
40 | mm: UInt8;
41 | pp: UInt8;
42 | R: UInt8;
43 | X: UInt8;
44 | B: UInt8;
45 | R1: UInt8;
46 | vvvv: UInt8;
47 | V: UInt8;
48 | aaa: UInt8;
49 | W: UInt8;
50 | z: UInt8;
51 | b_: UInt8;
52 | LL: UInt8;
53 | state: UInt8;
54 | masking: UInt8;
55 | tupletype: UInt8;
56 | end;
57 |
58 | VEX_Struct = packed record
59 | L: UInt8;
60 | vvvv: UInt8;
61 | mmmmm: UInt8;
62 | pp: UInt8;
63 | state: UInt8;
64 | opcode: UInt8;
65 | end;
66 |
67 | REX_Struct = packed record
68 | W_: UInt8;
69 | R_: UInt8;
70 | X_: UInt8;
71 | B_: UInt8;
72 | state: UInt8;
73 | end;
74 |
75 | // This structure gives informations on used prefixes. When can know if some prefixes
76 | // are used properly or not.
77 | PREFIXINFO = packed record
78 | Number: Integer;
79 | NbUndefined: Integer;
80 | LockPrefix: UInt8;
81 | OperandSize: UInt8;
82 | AddressSize: UInt8;
83 | RepnePrefix: UInt8;
84 | RepPrefix: UInt8;
85 | FSPrefix: UInt8;
86 | SSPrefix: UInt8;
87 | GSPrefix: UInt8;
88 | ESPrefix: UInt8;
89 | CSPrefix: UInt8;
90 | DSPrefix: UInt8;
91 | BranchTaken: UInt8;
92 | BranchNotTaken: UInt8;
93 | REX: REX_Struct;
94 | alignment: array [0..1] of AnsiChar;
95 | end;
96 |
97 | // This structure gives informations on the register EFLAGS.
98 | EFLStruct = packed record
99 | OF_: UInt8;
100 | SF_: UInt8;
101 | ZF_: UInt8;
102 | AF_: UInt8;
103 | PF_: UInt8;
104 | CF_: UInt8;
105 | TF_: UInt8;
106 | IF_: UInt8;
107 | DF_: UInt8;
108 | NT_: UInt8;
109 | RF_: UInt8;
110 | alignment: UInt8;
111 | end;
112 |
113 | // This structure gives informations if infos.Operandxx.OpType == MEMORY_TYPE.
114 | MEMORYTYPE = packed record
115 | BaseRegister: Int64;
116 | IndexRegister: Int64;
117 | Scale: Int32;
118 | Displacement: Int64;
119 | end;
120 |
121 | // This structure gives informations on operands if: infos.Operandxx.OpType ==
122 | // REGISTER_TYPE or if infos.Instruction.ImplicitModifiedRegs is filled
123 | REGISTERTYPE = packed record
124 | type_: Int64;
125 | gpr: Int64;
126 | mmx: Int64;
127 | xmm: Int64;
128 | ymm: Int64;
129 | zmm: Int64;
130 | special: Int64;
131 | cr: Int64;
132 | dr: Int64;
133 | mem_management: Int64;
134 | mpx: Int64;
135 | opmask: Int64;
136 | segment: Int64;
137 | fpu: Int64;
138 | tmm: Int64;
139 | end;
140 |
141 | // This structure gives informations on the analyzed instruction.
142 | INSTRTYPE = packed record
143 | // [out] Specify the family instruction . More precisely, (infos.Instruction.Category
144 | // & 0xFFFF0000) is used to know if the instruction is a standard one or comes
145 | // from one of the following technologies: MMX, FPU, SSE, SSE2, SSE3, SSSE3, SSE4.1,
146 | // SSE4.2, VMX or SYSTEM.LOWORD(infos.Instruction.Category) is used to know if
147 | // the instruction is an arithmetic instruction, a logical one, a data transfer
148 | // one ... To see the complete list of constants used by BeaEngine, go HERE .
149 | Category: Int32;
150 | // [out] This field contains the opcode on 1, 2 or 3 bytes. If the instruction
151 | // uses a mandatory prefix, this last one is not present here. For that,
152 | // you have to use the structure infos.Prefix.
153 | Opcode: Int32;
154 | // [out] This field sends back the instruction mnemonic with an ASCII format.
155 | // You must know that all mnemonics are followed by a space (0x20). For example ,
156 | // the instruction "add" is written "add ".
157 | Mnemonic: array [0..23] of AnsiChar;
158 | // [out] If the decoded instruction is a branch instruction, this field is set to
159 | // indicate what kind of jump it is (call, ret, unconditional jump, conditional jump).
160 | // To get a complete list of constants used by BeaEngine, go HERE
161 | BranchType: Int32;
162 | // [out] Structure EFLStruct that specifies the used flags.
163 | Flags: EFLStruct;
164 | // [out] If the decoded instruction is a branch instruction and if the destination
165 | // address can be calculated, the result is stored in that field. A "jmp eax" or
166 | // a "jmp [eax]" will set this field to 0 .
167 | AddrValue: UInt64;
168 | // [out] If the instruction uses a constant, this immediat value is stored here.
169 | Immediat: Int64;
170 | // [out] Some instructions modify registers implicitly. For example, "push 0" modifies
171 | // the register RSP. In that case, infos.Instruction.ImplicitModifiedRegs.gpr == REG4.
172 | // Find more useful informations on that field looking at the Structure REGISTERTYPE
173 | ImplicitModifiedRegs: REGISTERTYPE;
174 | // [out] Some instructions use registers implicitly. Find more useful informations
175 | // on that field looking at the Structure REGISTERTYPE
176 | ImplicitUsedRegs: REGISTERTYPE;
177 | end;
178 |
179 | // This structure gives informations about the operand analyzed.
180 | OPTYPE = packed record
181 | // [out] This field sends back, when it is possible, the operand in ASCII format.
182 | OpMnemonic: array [0..23] of AnsiChar;
183 | // [out] This field specifies the operand type. infos.Operandxx.OpType indicates
184 | // if it is one of the following :
185 | // * REGISTER_TYPE
186 | // * MEMORY_TYPE
187 | // * CONSTANT_TYPE+ABSOLUTE_
188 | // * CONSTANT_TYPE+RELATIVE_
189 | OpType: Int64;
190 | // [out] This field sends back the size of the operand.
191 | OpSize: Int32;
192 | OpPosition: Int32;
193 | // [out] This field indicates if the operand is modified or not (READ=0x1) or (WRITE=0x2).
194 | AccessMode: UInt32;
195 | // [out] Structure MEMORYTYPE , filled only if infos.Operandxx.OpType == MEMORY_TYPE.
196 | Memory: MEMORYTYPE;
197 | // [out] Structure REGISTERTYPE , filled only if infos.Operandxx.OpType == REGISTER_TYPE.
198 | Registers: REGISTERTYPE;
199 | // [out] This field indicates, in the case of memory addressing mode, the segment
200 | // register used : ESReg, DSReg, FSReg, GSReg, CSReg, SSReg
201 | SegmentReg: UInt32;
202 | end;
203 |
204 | // Reserved structure used for thread-safety.
205 | // Unusable by customer.
206 | InternalDatas = packed record
207 | EIP_: UIntPtr;
208 | EIP_VA: UInt64;
209 | EIP_REAL: UIntPtr;
210 | OriginalOperandSize: Int32;
211 | OperandSize: Int32;
212 | MemDecoration: Int32;
213 | AddressSize: Int32;
214 | MOD_: Int32;
215 | RM_: Int32;
216 | INDEX_: Int32;
217 | SCALE_: Int32;
218 | BASE_: Int32;
219 | REGOPCODE: Int32;
220 | DECALAGE_EIP: UInt32;
221 | FORMATNUMBER: Int32;
222 | SYNTAX_: Int32;
223 | EndOfBlock: UInt64;
224 | RelativeAddress: Int32;
225 | Architecture: UInt32;
226 | ImmediatSize: Int32;
227 | NB_PREFIX: Int32;
228 | PrefRepe: Int32;
229 | PrefRepne: Int32;
230 | SEGMENTREGS: UInt32;
231 | SEGMENTFS: UInt32;
232 | third_arg: Int32;
233 | OPTIONS: UInt64;
234 | ERROR_OPCODE: Int32;
235 | REX: REX_Struct;
236 | OutOfBlock: Int32;
237 | VEX: VEX_Struct;
238 | EVEX: EVEX_Struct;
239 | VSIB_: Int32;
240 | Register_: Int32;
241 | end;
242 |
243 | //* ************** main structure ************ */
244 |
245 | // This structure is used to store the mnemonic, source and destination operands.
246 | // You just have to specify the address where the engine has to make the analysis.
247 | _Disasm = packed record
248 | // [in] Offset of bytes sequence we want to disassemble
249 | EIP: UIntPtr;
250 | // [in] optional - (For instructions CALL - JMP - conditional JMP - LOOP) By default,
251 | // this value is 0 (disable). The disassembler calculates the destination address of
252 | // the branch instruction using VirtualAddr (not EIP). This address can be 64 bits long.
253 | // This option allows us to decode instructions located anywhere in memory even
254 | // if they are not at their original place
255 | VirtualAddr: UInt64;
256 | // [in] By default, this value is 0. (disabled option). In other cases, this number
257 | // is the number of bytes the engine is allowed to read since EIP. Thus,
258 | // we can make a read block to avoid some Access violation. On INTEL processors,
259 | // (in IA-32 or intel 64 modes) , instruction never exceeds 15 bytes.
260 | // A SecurityBlock value outside this range is useless.
261 | SecurityBlock: UInt32;
262 | // [out] String used to store the instruction representation
263 | CompleteInstr: array [0..79] of AnsiChar;
264 | // [in] This field is used to specify the architecture used for the decoding.
265 | // If it is set to 0 or 64 (0x20), the architecture used is 64 bits. If it is
266 | // set to 32 (0x20), the architecture used is IA-32. If set to 16 (0x10),
267 | // architecture is 16 bits.
268 | Archi: UInt32;
269 | // [in] This field allows to define some display options. You can specify the
270 | // syntax: masm, nasm ,goasm. You can specify the number format you want to use:
271 | // prefixed numbers or suffixed ones. You can even add a tabulation between the
272 | // mnemonic and the first operand or display the segment registers used by the
273 | // memory addressing. Constants used are the following :
274 | // * Tabulation: add a tabulation between mnemonic and first operand (default has no tabulation)
275 | // * GoAsmSyntax / NasmSyntax: change the intel syntax (default is Masm syntax)
276 | // * PrefixedNumeral: 200h is written 0x200 (default is suffixed numeral)
277 | // * ShowSegmentRegs: show segment registers used (default is hidden)
278 | // * ShowEVEXMasking: show opmask and merging/zeroing applyed on first operand for AVX512 instructions (default is hidden)
279 | Options: UInt64;
280 | // [out] Structure INSTRTYPE.
281 | Instruction: INSTRTYPE;
282 | // [out] Structure OPTYPE that concerns the first operand.
283 | Operand1: OPTYPE;
284 | // [out] Structure OPTYPE that concerns the second operand.
285 | Operand2: OPTYPE;
286 | // [out] Structure OPTYPE that concerns the third operand.
287 | Operand3: OPTYPE;
288 | // [out] Structure OPTYPE that concerns the fourth operand.
289 | Operand4: OPTYPE;
290 | // [out] Structure OPTYPE that concerns the fifth operand.
291 | Operand5: OPTYPE;
292 | // [out] Structure OPTYPE that concerns the sixth operand.
293 | Operand6: OPTYPE;
294 | // [out] Structure OPTYPE that concerns the seventh operand.
295 | Operand7: OPTYPE;
296 | // [out] Structure OPTYPE that concerns the eighth operand.
297 | Operand8: OPTYPE;
298 | // [out] Structure OPTYPE that concerns the ninth operand.
299 | Operand9: OPTYPE;
300 | // [out] Structure PREFIXINFO containing an exhaustive list of used prefixes.
301 | Prefix: PREFIXINFO;
302 | // [out] This field returns the status of the disassemble process :
303 | // * Success: (0) instruction has been recognized by the engine
304 | // * Out of block: (-2) instruction length is out of SecurityBlock
305 | // * Unknown opcode: (-1) instruction is not recognized by the engine
306 | // * Exception #UD: (2) instruction has been decoded properly but sends #UD exception if executed.
307 | // * Exception #DE: (3) instruction has been decoded properly but sends #DE exception if executed
308 | Error: Int32;
309 | // reserved structure used for thread-safety, unusable by customer
310 | Reserved_: InternalDatas;
311 | end;
312 | TDisasm = _Disasm;
313 | PDisasm = ^TDisasm;
314 |
315 | const
316 | //* #UD exception */
317 | UD_ = 2;
318 | DE__ = 3;
319 |
320 | const
321 | // Values taken by infos.Operandxx.SegmentReg
322 | ESReg = $01;
323 | DSReg = $02;
324 | FSReg = $04;
325 | GSReg = $08;
326 | CSReg = $10;
327 | SSReg = $20;
328 |
329 | const
330 | // Concerns the LOCK prefix
331 | InvalidPrefix = 4;
332 | SuperfluousPrefix = 2;
333 | NotUsedPrefix = 0;
334 | MandatoryPrefix = 8;
335 | InUsePrefix = 1;
336 |
337 | LowPosition = 0;
338 | HighPosition = 1;
339 |
340 | //* EVEX Masking */
341 | NO_MASK = 0;
342 | MERGING = 1;
343 | MERGING_ZEROING = 2;
344 |
345 | //* EVEX Compressed Displacement */
346 | FULL = 1;
347 | HALF = 2;
348 | FULL_MEM = 3;
349 | TUPLE1_SCALAR__8 = 4;
350 | TUPLE1_SCALAR__16 = 5;
351 | TUPLE1_SCALAR = 6;
352 | TUPLE1_FIXED__32 = 7;
353 | TUPLE1_FIXED__64 = 8;
354 | TUPLE2 = 9;
355 | TUPLE4 = 10;
356 | TUPLE8 = 11;
357 | HALF_MEM = 12;
358 | QUARTER_MEM = 13;
359 | EIGHTH_MEM = 14;
360 | MEM128 = 15;
361 | MOVDDUP = 16;
362 |
363 | type
364 | INSTRUCTION_TYPE = Integer;
365 | const
366 | // Here is an exhaustive list of constants used by fields sends back by BeaEngine.
367 | // Values taken by (infos.Instruction.Category & 0xFFFF0000)
368 | GENERAL_PURPOSE_INSTRUCTION = $10000;
369 | FPU_INSTRUCTION = $20000;
370 | MMX_INSTRUCTION = $30000;
371 | SSE_INSTRUCTION = $40000;
372 | SSE2_INSTRUCTION = $50000;
373 | SSE3_INSTRUCTION = $60000;
374 | SSSE3_INSTRUCTION = $70000;
375 | SSE41_INSTRUCTION = $80000;
376 | SSE42_INSTRUCTION = $90000;
377 | SYSTEM_INSTRUCTION = $A0000;
378 | VM_INSTRUCTION = $B0000;
379 | UNDOCUMENTED_INSTRUCTION = $C0000;
380 | AMD_INSTRUCTION = $D0000;
381 | ILLEGAL_INSTRUCTION = $E0000;
382 | AES_INSTRUCTION = $F0000;
383 | CLMUL_INSTRUCTION = $100000;
384 | AVX_INSTRUCTION = $110000;
385 | AVX2_INSTRUCTION = $120000;
386 | MPX_INSTRUCTION = $130000;
387 | AVX512_INSTRUCTION = $140000;
388 | SHA_INSTRUCTION = $150000;
389 | BMI2_INSTRUCTION = $160000;
390 | CET_INSTRUCTION = $170000;
391 | BMI1_INSTRUCTION = $180000;
392 | XSAVEOPT_INSTRUCTION = $190000;
393 | FSGSBASE_INSTRUCTION = $1A0000;
394 | CLWB_INSTRUCTION = $1B0000;
395 | CLFLUSHOPT_INSTRUCTION = $1C0000;
396 | FXSR_INSTRUCTION = $1D0000;
397 | XSAVE_INSTRUCTION = $1E0000;
398 | SGX_INSTRUCTION = $1F0000;
399 | PCONFIG_INSTRUCTION = $200000;
400 | UINTR_INSTRUCTION = $210000;
401 | KL_INSTRUCTION = $220000;
402 | AMX_INSTRUCTION = $230000;
403 |
404 | const
405 | // Values taken by LOWORD(infos.Instruction.Category)
406 | DATA_TRANSFER = 1;
407 | ARITHMETIC_INSTRUCTION = 2;
408 | LOGICAL_INSTRUCTION = 3;
409 | SHIFT_ROTATE = 4;
410 | BIT_UInt8 = 5;
411 | CONTROL_TRANSFER = 6;
412 | STRING_INSTRUCTION = 7;
413 | InOutINSTRUCTION = 8;
414 | ENTER_LEAVE_INSTRUCTION = 9;
415 | FLAG_CONTROL_INSTRUCTION = 10;
416 | SEGMENT_REGISTER = 11;
417 | MISCELLANEOUS_INSTRUCTION = 12;
418 | COMPARISON_INSTRUCTION = 13;
419 | LOGARITHMIC_INSTRUCTION = 14;
420 | TRIGONOMETRIC_INSTRUCTION = 15;
421 | UNSUPPORTED_INSTRUCTION = 16;
422 | LOAD_CONSTANTS = 17;
423 | FPUCONTROL = 18;
424 | STATE_MANAGEMENT = 19;
425 | CONVERSION_INSTRUCTION = 20;
426 | SHUFFLE_UNPACK = 21;
427 | PACKED_SINGLE_PRECISION = 22;
428 | SIMD128bits = 23;
429 | SIMD64bits = 24;
430 | CACHEABILITY_CONTROL = 25;
431 | FP_INTEGER_CONVERSION = 26;
432 | SPECIALIZED_128bits = 27;
433 | SIMD_FP_PACKED = 28;
434 | SIMD_FP_HORIZONTAL = 29;
435 | AGENT_SYNCHRONISATION = 30;
436 | PACKED_ALIGN_RIGHT = 31;
437 | PACKED_SIGN = 32;
438 | PACKED_BLENDING_INSTRUCTION = 33;
439 | PACKED_TEST = 34;
440 | PACKED_MINMAX = 35;
441 | HORIZONTAL_SEARCH = 36;
442 | PACKED_EQUALITY = 37;
443 | STREAMING_LOAD = 38;
444 | INSERTION_EXTRACTION = 39;
445 | DOT_PRODUCT = 40;
446 | SAD_INSTRUCTION = 41;
447 | ACCELERATOR_INSTRUCTION = 42; //* crc32; popcnt (sse4.2) */
448 | ROUND_INSTRUCTION = 43;
449 |
450 | type
451 | EFLAGS_STATES = Integer;
452 | const
453 | // Values taken by infos.Instruction.Flags.OF_ , .SF_ ...
454 | TE_ = $01;
455 | MO_ = $02;
456 | RE_ = $04;
457 | SE_ = $08;
458 | UN_ = $10;
459 | PR_ = $20;
460 |
461 | type
462 | BRANCH_TYPE = Integer;
463 | const
464 | // Values taken by infos.Instruction.BranchType
465 | JO = 1;
466 | JC = 2;
467 | JE = 3;
468 | JA = 4;
469 | JS = 5;
470 | JP = 6;
471 | JL = 7;
472 | JG = 8;
473 | JB = 2; //* JC == JB */
474 | JECXZ = 10;
475 | JmpType = 11;
476 | CallType = 12;
477 | RetType = 13;
478 | JNO = -1;
479 | JNC = -2;
480 | JNE = -3;
481 | JNA = -4;
482 | JNS = -5;
483 | JNP = -6;
484 | JNL = -7;
485 | JNG = -8;
486 | JNB = -2; //* JNC == JNB */
487 |
488 | type
489 | ARGUMENTS_TYPE = Integer;
490 | const
491 | // Values taken by infos.Operandxx.OpType
492 | NO_ARGUMENT = $10000;
493 | REGISTER_TYPE = $20000;
494 | MEMORY_TYPE = $30000;
495 | CONSTANT_TYPE = $40000;
496 |
497 | GENERAL_REG = $1;
498 | MMX_REG = $2;
499 | SSE_REG = $4;
500 | AVX_REG = $8;
501 | AVX512_REG = $10;
502 | SPECIAL_REG = $20;
503 | CR_REG = $40;
504 | DR_REG = $80;
505 | MEMORY_MANAGEMENT_REG = $100;
506 | MPX_REG = $200;
507 | OPMASK_REG = $400;
508 | SEGMENT_REG = $800;
509 | FPU_REG = $1000;
510 | TMM_REG = $2000;
511 |
512 | RELATIVE_ = $4000000;
513 | ABSOLUTE_ = $8000000;
514 |
515 | // OPTYPE.AccessMode, indicates if the operand is modified or not
516 | READ = $1;
517 | WRITE = $2;
518 |
519 | REG0 = $1;
520 | REG1 = $2;
521 | REG2 = $4;
522 | REG3 = $8;
523 | REG4 = $10;
524 | REG5 = $20;
525 | REG6 = $40;
526 | REG7 = $80;
527 | REG8 = $100;
528 | REG9 = $200;
529 | REG10 = $400;
530 | REG11 = $800;
531 | REG12 = $1000;
532 | REG13 = $2000;
533 | REG14 = $4000;
534 | REG15 = $8000;
535 | REG16 = $10000;
536 | REG17 = $20000;
537 | REG18 = $40000;
538 | REG19 = $80000;
539 | REG20 = $100000;
540 | REG21 = $200000;
541 | REG22 = $400000;
542 | REG23 = $800000;
543 | REG24 = $1000000;
544 | REG25 = $2000000;
545 | REG26 = $4000000;
546 | REG27 = $8000000;
547 | REG28 = $10000000;
548 | REG29 = $20000000;
549 | REG30 = $40000000;
550 | REG31 = $80000000;
551 |
552 | type
553 | SPECIAL_INFO = Integer;
554 | const
555 | UNKNOWN_OPCODE = -1;
556 | OUT_OF_BLOCK = -2;
557 |
558 | // Values taken by infos.Options
559 |
560 | //* === mask = 0xff */
561 | NoTabulation = $00000000;
562 | Tabulation = $00000001;
563 |
564 | //* === mask = 0xff00 */
565 | MasmSyntax = $00000000;
566 | GoAsmSyntax = $00000100;
567 | NasmSyntax = $00000200;
568 | ATSyntax = $00000400;
569 | IntrinsicMemSyntax = $00000800;
570 |
571 | //* === mask = 0xff0000 */
572 | PrefixedNumeral = $00010000;
573 | SuffixedNumeral = $00000000;
574 |
575 | //* === mask = 0xff000000 */
576 | ShowSegmentRegs = $01000000;
577 | ShowEVEXMasking = $02000000;
578 |
579 | const
580 | // _Disasm.Archi
581 | ARCHI_X16 = $10;
582 | ARCHI_X32 = $20;
583 | ARCHI_X64 = $40;
584 |
585 | const
586 | OPCODE_RET = $C3;
587 |
588 | // The Disasm function disassembles one instruction from the Intel ISA. It makes a precise
589 | // analysis of the focused instruction and sends back a complete structure that is usable
590 | // to make data-flow and control-flow studies.
591 | // Parameters
592 | // aDisAsm: Pointer to a structure PDISASM
593 | // Return
594 | // The function may sends you back 3 values. if the analyzed bytes sequence is an invalid
595 | // opcode, it sends back UNKNOWN_OPCODE (-1). If it tried to read a byte located outside
596 | // the Security Block, it sends back OUT_OF_BLOCK (-2). In others cases, it sends back
597 | // the instruction length. Thus, you can use it as a LDE. To have a detailed status,
598 | // use infos.Error field.
599 | function Disasm(var aDisAsm: TDisasm): LongInt; cdecl;
600 |
601 | // The BeaEngineVersion function retrieves the version information of the BeaEngine library.
602 | // Return
603 | // The function returns a pointer to an AnsiChar string containing the version information of the BeaEngine library.
604 | function BeaEngineVersion: PAnsiChar; cdecl;
605 |
606 | // The BeaEngineRevision function retrieves the revision information of the BeaEngine library.
607 | // Return
608 | // The function returns a pointer to an AnsiChar string containing the revision information of the BeaEngine library.
609 | function BeaEngineRevision: PAnsiChar; cdecl;
610 |
611 | // The BeaEngineVersionInfo function retrieves the full version information of the BeaEngine library,
612 | // including the version number, revision, and CPU architecture.
613 | // Return
614 | // The function returns a string containing the full version information of the BeaEngine library.
615 | // The format is "v (Rev,)", where is x64 or x32
616 | // depending on the CPU architecture.
617 | function BeaEngineVersionInfo: string;
618 |
619 | // The BufferToHex function converts a buffer of binary data into its hexadecimal string representation.
620 | // Parameters
621 | // AData: Pointer to the binary data buffer.
622 | // ALen: Integer specifying the length of the binary data buffer.
623 | // Return
624 | // The function returns a string that represents the hexadecimal equivalent of the binary data.
625 | function BufferToHex(const AData: Pointer; ALen: Integer): string;
626 |
627 | implementation
628 |
629 | // Define import and export function behavior.
630 | {$IFDEF BE_STATICLINK}
631 | {$IFDEF MSWINDOWS}
632 | {$DEFINE BE_USE_EXTNAME}
633 | {$ENDIF MSWINDOWS}
634 | {$IF DEFINED(DCC) and (DEFINED(LINUX) or DEFINED(MACOS64) or DEFINED(ANDROID))}
635 | {$DEFINE BE_USE_EXTLIB}
636 | {$DEFINE BE_USE_EXTNAME}
637 | {$IFEND}
638 | {$IFDEF WIN32}
639 | {$DEFINE BE_IMP_UNDERSCORE}
640 | {$ENDIF WIN32}
641 | {$IF DEFINED(DCC) and DEFINED(WIN32)}
642 | {$DEFINE BE_EXP_UNDERSCORE}
643 | {$IFEND}
644 | {.$MESSAGE ERROR 'staticlink not supported'}
645 | {$ELSE BE_STATICLINK}
646 | {$DEFINE BE_USE_EXTLIB}
647 | {$DEFINE BE_USE_EXTNAME}
648 | {$ENDIF BE_STATICLINK}
649 |
650 | {$IFDEF BE_STATICLINK}
651 |
652 | // Link static libraries.
653 | {$IFDEF FPC}
654 | {$IFDEF MSWINDOWS} {$IFDEF CPUX64}
655 | // Win64 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + TDM-GCC-64 9.2.0 x86_64-win64
656 | {$L 'x86_64-win64\BeaEngine.o'}
657 | {$ENDIF} {$IFDEF CPUX86}
658 | // Win32 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + TDM-GCC-64 9.2.0 i386-win32
659 | {$L 'i386-win32\BeaEngine.o'}
660 | {$ENDIF} {$ENDIF}
661 | {$IFDEF LINUX} {$IFDEF CPUX64}
662 | // Linux64 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 14.0 x86_64-pc-linux-gnu
663 | {$L 'x86_64-linux\BeaEngine.o'}
664 | {$ENDIF} {$IFDEF CPUX86}
665 | // Linux32 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 14.0 x86_64-pc-linux-gnu
666 | {$L 'i386-linux\BeaEngine.o'}
667 | {$ENDIF} {$IFDEF CPUAARCH64}
668 | // Linux ARM64 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 13.0 aarch64-linux-gnu
669 | {$L 'aarch64-linux\BeaEngine.o'}
670 | {$ENDIF} {$IFDEF CPUARM}
671 | // Linux ARM32 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 4.9 arm-linux-gnueabihf-gcc, Using hard floating-point (VFP), -mfloat-abi=hard -mfpu=vfpv3-d16
672 | {$L 'arm-linux\BeaEngine.o'}
673 | {$ENDIF} {$IFDEF CPULOONGARCH64}
674 | // Linux LoongArch64 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 8.3 loongarch64-newlib-elf
675 | {$L 'loongarch64-linux\BeaEngine.o'}
676 | {$ENDIF} {$ENDIF}
677 | {$IFDEF DARWIN} {$IFDEF CPUX64}
678 | // MacOS AMD64 from Ref\beaengine-5.3.0\xcode\BeaEngine.xcodeproj + XCode 14 $(ARCHS_STANDARD)
679 | {$L 'x86_64-darwin\BeaEngine.o'}
680 | {$ENDIF} {$IFDEF CPUAARCH64}
681 | // MacOS ARM64 from Ref\beaengine-5.3.0\xcode\BeaEngine.xcodeproj + XCode 14 $(ARCHS_STANDARD)
682 | {$L 'aarch64-darwin\BeaEngine.o'}
683 | {$ENDIF} {$ENDIF}
684 | {$IFDEF ANDROID} {$IFDEF CPUAARCH64}
685 | // Android ARM64 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 12.0 aarch64-linux-android
686 | {$L 'aarch64-android\BeaEngine.o'}
687 | {$ENDIF} {$IFDEF CPUARM}
688 | // Android ARM32 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 11.0 arm-linux-androideabi
689 | {$L 'arm-android\BeaEngine.o'}
690 | {$ENDIF} {$ENDIF}
691 | {$ELSE FPC}
692 | {$IFDEF MSWINDOWS} {$IFDEF CPUX64}
693 | // Win64 from Ref\beaengine-5.3.0\lib_static_x64\BeaEngine.lib, PellesC x64
694 | {$L 'x86_64-win64\BeaEngine.obj'}
695 | {$ENDIF} {$IFDEF CPUX86}
696 | // Win32 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + BCC 10.2 bcb-win32
697 | {$L 'i386-win32\BeaEngine.obj'}
698 | {$ENDIF} {$ENDIF}
699 | {$ENDIF FPC}
700 |
701 | // Link static library dependency functions.
702 | const
703 | {$IFDEF MSWINDOWS}
704 | libc = 'msvcrt.dll';
705 | {$ENDIF MSWINDOWS}
706 | {$IF DEFINED(ANDROID) or DEFINED(LINUX)}
707 | libc = 'libc.so';
708 | {$IFEND}
709 | {$IF DEFINED(DARWIN) or DEFINED(MACOS)}
710 | libc = '/usr/lib/libc.dylib';
711 | {$IFEND}
712 |
713 | procedure {$IFDEF BE_IMP_UNDERSCORE}_memcpy{$ELSE}memcpy{$ENDIF}; cdecl;
714 | external libc name 'memcpy';
715 |
716 | procedure {$IFDEF BE_IMP_UNDERSCORE}_memset{$ELSE}memset{$ENDIF}; cdecl;
717 | external libc name 'memset';
718 |
719 | procedure {$IFDEF BE_IMP_UNDERSCORE}_sprintf{$ELSE}sprintf{$ENDIF}; cdecl;
720 | external libc name 'sprintf';
721 |
722 | procedure {$IFDEF BE_IMP_UNDERSCORE}_strcmp{$ELSE}strcmp{$ENDIF}; cdecl;
723 | external libc name 'strcmp';
724 |
725 | function {$IFDEF BE_IMP_UNDERSCORE}_strcpy{$ELSE}strcpy{$ENDIF}(dest, src: PAnsiChar): PAnsiChar; cdecl;
726 | external libc name 'strcpy';
727 |
728 | function {$IFDEF BE_IMP_UNDERSCORE}_strlen{$ELSE}strlen{$ENDIF}(s: PAnsiChar): NativeUInt; cdecl;
729 | external libc name 'strlen';
730 |
731 | function {$IFDEF BE_IMP_UNDERSCORE}_stpcpy{$ELSE}stpcpy{$ENDIF}(dest, src: PAnsiChar): PAnsiChar; cdecl;
732 | external libc name 'stpcpy';
733 |
734 | {$IFDEF FPC}
735 |
736 | const
737 | {$IFDEF BE_IMP_UNDERSCORE}
738 | _PREFIX = '_';
739 | {$ELSE}
740 | _PREFIX = '';
741 | {$ENDIF}
742 |
743 | {$IF (DEFINED(CPUX86) or DEFINED(CPUX64))}
744 | procedure impl_sprintf; assembler; nostackframe; public name _PREFIX + 'sprintf';
745 | asm
746 | jmp {$IFDEF BE_IMP_UNDERSCORE}_sprintf{$ELSE}sprintf{$ENDIF}
747 | end;
748 | {$IFEND}
749 |
750 | function impl_strcpy(dest, src: PAnsiChar): PAnsiChar; cdecl; public name _PREFIX + 'strcpy';
751 | begin
752 | Result := {$IFDEF BE_IMP_UNDERSCORE}_strcpy{$ELSE}strcpy{$ENDIF}(dest, src);
753 | end;
754 |
755 | function impl_strlen(s: PAnsiChar): NativeUInt; cdecl; public name _PREFIX + 'strlen';
756 | begin
757 | Result := {$IFDEF BE_IMP_UNDERSCORE}_strlen{$ELSE}strlen{$ENDIF}(s);
758 | end;
759 |
760 | function impl_stpcpy(dest, src: PAnsiChar): PAnsiChar; cdecl; public name _PREFIX + 'stpcpy';
761 | begin
762 | Result := {$IFDEF BE_IMP_UNDERSCORE}_stpcpy{$ELSE}stpcpy{$ENDIF}(dest, src);
763 | end;
764 |
765 | {$ENDIF}
766 |
767 | {$ENDIF BE_STATICLINK}
768 |
769 | // Link static or dynamic libraries.
770 | const
771 | {$IFDEF BE_STATICLINK}
772 | {$IFDEF LINUX} {$IFDEF CPUX64}
773 | // Linux AMD64 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 14.0 x86_64-pc-linux-gnu
774 | BeaEngineLib = 'x86_64-linux\BeaEngine.o';
775 | {$ENDIF} {$IFDEF CPUAARCH64}
776 | // Linux ARM64 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 13.0 aarch64-linux-gnu
777 | BeaEngineLib = 'aarch64-linux\BeaEngine.o';
778 | {$ENDIF} {$ENDIF}
779 | {$IFDEF MACOS} {$IFDEF CPUX64}
780 | // MacOS AMD64 from Ref\beaengine-5.3.0\xcode\BeaEngine.xcodeproj + XCode 14 $(ARCHS_STANDARD)
781 | BeaEngineLib = 'x86_64-darwin\BeaEngine.o';
782 | {$ENDIF} {$IFDEF CPUARM64}
783 | // MacOS ARM64 from Ref\beaengine-5.3.0\xcode\BeaEngine.xcodeproj + XCode 14 $(ARCHS_STANDARD)
784 | BeaEngineLib = 'aarch64-darwin\BeaEngine.o';
785 | {$ENDIF} {$ENDIF}
786 | {$IFDEF ANDROID} {$IFDEF CPUARM64}
787 | // Android ARM64 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 12.0 aarch64-linux-android
788 | BeaEngineLib = 'aarch64-android\BeaEngine.o';
789 | {$ENDIF} {$IFDEF CPUARM32}
790 | // Android ARM32 from Ref\beaengine-5.3.0\cb\BeaEngineLib.cbp + GCC-CROSS 11.0 arm-linux-androideabi
791 | BeaEngineLib = 'arm-android\BeaEngine.o';
792 | {$ENDIF} {$ENDIF}
793 | {$ELSE BE_STATICLINK}
794 | {$IFDEF MSWINDOWS}
795 | // Win32 from Ref\beaengine-5.3.0\msvc\BeaEngine.sln + VS19 + VC-LTL 5
796 | // Win64 from Ref\beaengine-5.3.0\dll_x64\BeaEngine.dll
797 | BeaEngineLib = 'BeaEngine.dll';
798 | {$ENDIF}
799 | {$IF DEFINED(LINUX) or DEFINED(ANDROID)}
800 | // Linux, Android from Ref\beaengine-5.3.0\CMakeLists.txt + make
801 | BeaEngineLib = 'libBeaEngine.so';
802 | {$IFEND}
803 | {$IF DEFINED(MACOS) or DEFINED(DARWIN)}
804 | // MacOSX from Ref\beaengine-5.3.0\darwin\BeaEngine.xcodeproj + XCode 14
805 | {$IF DEFINED(IOS) or DEFINED(MACOS64)}
806 | BeaEngineLib = '/usr/lib/libBeaEngine.dylib';
807 | {$ELSE}
808 | BeaEngineLib = 'libBeaEngine.dylib';
809 | {$IFEND}
810 | {$IFEND}
811 | {$ENDIF BE_STATICLINK}
812 |
813 | {$IFDEF BE_EXP_UNDERSCORE}
814 | BeaEngineRevisionName = '_BeaEngineRevision';
815 | BeaEngineVersionName = '_BeaEngineVersion';
816 | DisasmName = '_Disasm';
817 | {$ELSE BE_EXP_UNDERSCORE}
818 | BeaEngineRevisionName = 'BeaEngineRevision';
819 | BeaEngineVersionName = 'BeaEngineVersion';
820 | DisasmName = 'Disasm';
821 | {$ENDIF BE_EXP_UNDERSCORE}
822 |
823 | function Disasm; external {$IFDEF BE_USE_EXTLIB}BeaEngineLib{$ENDIF} {$IFDEF BE_USE_EXTNAME}name DisasmName{$ENDIF};
824 |
825 | function BeaEngineVersion; external {$IFDEF BE_USE_EXTLIB}BeaEngineLib{$ENDIF} {$IFDEF BE_USE_EXTNAME}name BeaEngineVersionName{$ENDIF};
826 |
827 | function BeaEngineRevision; external {$IFDEF BE_USE_EXTLIB}BeaEngineLib{$ENDIF} {$IFDEF BE_USE_EXTNAME}name BeaEngineRevisionName{$ENDIF};
828 |
829 | function BeaEngineVersionInfo: string;
830 | begin
831 | {$IFDEF CPUX64}
832 | Result := 'v' + string(BeaEngineVersion) + ' (Rev' + string(BeaEngineRevision) + ',x64)';
833 | {$ELSE}
834 | Result := 'v' + string(BeaEngineVersion) + ' (Rev' + string(BeaEngineRevision) + ',x32)';
835 | {$ENDIF}
836 | end;
837 |
838 | function BufferToHex(const AData: Pointer; ALen: Integer): string;
839 | const
840 | defCharConvertTable: array[0..15] of Char = (
841 | '0', '1', '2', '3', '4', '5', '6', '7',
842 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
843 | );
844 | var
845 | pData: PByte;
846 | pRet: PChar;
847 | begin
848 | pData := AData;
849 | SetLength(Result, 2 * ALen);
850 | pRet := PChar(Result);
851 | while ALen > 0 do
852 | begin
853 | pRet^ := defCharConvertTable[(pData^ and $F0) shr 4];
854 | Inc(pRet);
855 | pRet^ := defCharConvertTable[pData^ and $0F];
856 | Inc(pRet);
857 | Dec(ALen);
858 | Inc(pData);
859 | end;
860 | end;
861 |
862 | end.
863 |
--------------------------------------------------------------------------------
/Source/aarch64-android/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/aarch64-android/BeaEngine.o
--------------------------------------------------------------------------------
/Source/aarch64-darwin/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/aarch64-darwin/BeaEngine.o
--------------------------------------------------------------------------------
/Source/aarch64-linux/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/aarch64-linux/BeaEngine.o
--------------------------------------------------------------------------------
/Source/arm-android/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/arm-android/BeaEngine.o
--------------------------------------------------------------------------------
/Source/arm-linux/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/arm-linux/BeaEngine.o
--------------------------------------------------------------------------------
/Source/i386-linux/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/i386-linux/BeaEngine.o
--------------------------------------------------------------------------------
/Source/i386-win32/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/i386-win32/BeaEngine.o
--------------------------------------------------------------------------------
/Source/i386-win32/BeaEngine.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/i386-win32/BeaEngine.obj
--------------------------------------------------------------------------------
/Source/loongarch64-linux/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/loongarch64-linux/BeaEngine.o
--------------------------------------------------------------------------------
/Source/x86_64-darwin/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/x86_64-darwin/BeaEngine.o
--------------------------------------------------------------------------------
/Source/x86_64-linux/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/x86_64-linux/BeaEngine.o
--------------------------------------------------------------------------------
/Source/x86_64-win64/BeaEngine.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/x86_64-win64/BeaEngine.o
--------------------------------------------------------------------------------
/Source/x86_64-win64/BeaEngine.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Source/x86_64-win64/BeaEngine.obj
--------------------------------------------------------------------------------
/Tests/test_block.dpr:
--------------------------------------------------------------------------------
1 | { ***************************************************** }
2 | { }
3 | { Pascal language binding for the BeaEngine }
4 | { }
5 | { Unit Name: test_block }
6 | { Author: Lsuper 2024.06.01 }
7 | { Purpose: tests\test_block.c }
8 | { License: Mozilla Public License 2.0 }
9 | { }
10 | { Copyright (c) 1998-2024 Super Studio }
11 | { }
12 | { ***************************************************** }
13 |
14 | program test_block;
15 |
16 | {$APPTYPE CONSOLE}
17 |
18 | uses
19 | SysUtils, BeaEngineDelphi;
20 |
21 | type
22 | TPlatform = record
23 | Archi: Integer;
24 | Code: PByte;
25 | Size: Integer;
26 | Comment: string;
27 | end;
28 |
29 | procedure DisassembleCode(const APlatform: TPlatform; const AVirtualAddr: UInt64);
30 |
31 | function FormatBuffer(ACode: PByte; ASize: Integer): string;
32 | var
33 | I: Integer;
34 | L: string;
35 | P: PByte;
36 | begin
37 | Result := '';
38 | P := PByte(ACode);
39 | for I := 0 to ASize - 1 do
40 | begin
41 | L := '0x' + LowerCase(IntToHex(P[I], 2)) + ' ';
42 | Result := Result + L;
43 | end;
44 | end;
45 | var
46 | aDisasm: TDisasm;
47 | nLen: Integer;
48 | pData, pEnd: PByte;
49 | S: string;
50 | begin
51 | WriteLn('Platform: ', APlatform.Comment);
52 | WriteLn('Archi: ', APlatform.Archi);
53 | S := FormatBuffer(APlatform.Code, APlatform.Size);
54 | WriteLn('Code: ', LowerCase(S));
55 | WriteLn('Disasm:');
56 |
57 | FillChar(aDisasm, SizeOf(aDisasm), 0);
58 | aDisasm.Archi := APlatform.Archi;
59 | aDisasm.EIP := UIntPtr(APlatform.Code);
60 | aDisasm.Options := NoTabulation + MasmSyntax;
61 | aDisasm.VirtualAddr := AVirtualAddr;
62 |
63 | pData := APlatform.Code;
64 | pEnd := APlatform.Code + APlatform.Size;
65 |
66 | while aDisasm.Error = 0 do
67 | begin
68 | aDisasm.SecurityBlock := UInt32(pEnd - PByte(aDisasm.EIP));
69 | if aDisasm.SecurityBlock <= 0 then
70 | Break;
71 | nLen := Disasm(aDisasm);
72 | case aDisasm.Error of
73 | OUT_OF_BLOCK:
74 | WriteLn('disasm engine is not allowed to read more memory');
75 | UNKNOWN_OPCODE:
76 | begin
77 | S := BufferToHex(pData, 1);
78 | S := Format('%.8x %-16s %s', [aDisasm.EIP, S, aDisasm.CompleteInstr]);
79 | Writeln(S);
80 | aDisasm.EIP := aDisasm.EIP + 1;
81 | aDisasm.Error := 0;
82 | Inc(pData, 1);
83 | end;
84 | else
85 | begin
86 | S := BufferToHex(pData, nLen);
87 | S := Format('%.8x %-16s %s', [aDisasm.EIP, S, aDisasm.CompleteInstr]);
88 | Writeln(S);
89 | aDisasm.EIP := aDisasm.EIP + nLen;
90 | Inc(pData, nLen);
91 | end;
92 | end;
93 | end;
94 |
95 | WriteLn('');
96 | end;
97 |
98 | procedure Test;
99 | const
100 | X86_CODE16: array[0..61] of Byte = (
101 | $8D, $4C, $32, $08, $01, $D8, $81, $C6, $34, $12, $00, $00, $05, $23, $01, $00,
102 | $00, $36, $8B, $84, $91, $23, $01, $00, $00, $41, $8D, $84, $39, $89, $67, $00,
103 | $00, $8D, $87, $89, $67, $00, $00, $B4, $C6, $66, $E9, $B8, $00, $00, $00, $67,
104 | $FF, $A0, $23, $01, $00, $00, $66, $E8, $CB, $00, $00, $00, $74, $FC
105 | );
106 | X86_CODE32: array[0..58] of Byte = (
107 | $8D, $4C, $32, $08, $01, $D8, $81, $C6, $34, $12, $00, $00, $05, $23, $01, $00,
108 | $00, $36, $8B, $84, $91, $23, $01, $00, $00, $41, $8D, $84, $39, $89, $67, $00,
109 | $00, $8D, $87, $89, $67, $00, $00, $B4, $C6, $E9, $EA, $BE, $AD, $DE, $FF, $A0,
110 | $23, $01, $00, $00, $E8, $DF, $BE, $AD, $DE, $74, $FF
111 | );
112 | X86_CODE64: array[0..25] of Byte = (
113 | $55, $48, $8B, $05, $B8, $13, $00, $00, $E9, $EA, $BE, $AD, $DE, $FF, $25, $23,
114 | $01, $00, $00, $E8, $DF, $BE, $AD, $DE, $74, $FF
115 | );
116 | const
117 | Platforms: array[0..3] of TPlatform = (
118 | (Archi: ARCHI_X16; Code: @X86_CODE16; Size: SizeOf(X86_CODE16); Comment: 'X86 16bit (Intel syntax)'),
119 | (Archi: ARCHI_X32; Code: @X86_CODE32; Size: SizeOf(X86_CODE32); Comment: 'X86 32 (AT&T syntax)'),
120 | (Archi: ARCHI_X64; Code: @X86_CODE32; Size: SizeOf(X86_CODE32); Comment: 'X86 32 (Intel syntax)'),
121 | (Archi: ARCHI_X64; Code: @X86_CODE64; Size: SizeOf(X86_CODE64); Comment: 'X86 64 (Intel syntax)')
122 | );
123 | var
124 | P: TPlatform;
125 | begin
126 | for P in Platforms do
127 | begin
128 | DisassembleCode(P, $1000);
129 | end;
130 | end;
131 |
132 | begin
133 | try
134 | Test;
135 | except
136 | on E: Exception do
137 | Writeln(E.ClassName, ': ', E.Message);
138 | end;
139 | Readln;
140 | end.
141 |
--------------------------------------------------------------------------------
/Tests/test_block.dproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {0572A026-CFC8-4571-A3B9-4826C7B27A77}
4 | test_block.dpr
5 | True
6 | Debug
7 | 3
8 | Console
9 | None
10 | 13.4
11 | Win32
12 |
13 |
14 | true
15 |
16 |
17 | true
18 | Base
19 | true
20 |
21 |
22 | true
23 | Base
24 | true
25 |
26 |
27 | true
28 | Base
29 | true
30 |
31 |
32 | true
33 | Base
34 | true
35 |
36 |
37 | true
38 | Cfg_2
39 | true
40 | true
41 |
42 |
43 | xCS_STATICLINK;$(DCC_Define)
44 | 00400000
45 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=
46 | None
47 | System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace)
48 | ..\Source;$(DCC_UnitSearchPath)
49 | ..\Bin\$(Platform)
50 | 2052
51 | false
52 | false
53 | false
54 | ..\Dcu\$(Platform)
55 | false
56 | false
57 |
58 |
59 | System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)
60 | 1033
61 |
62 |
63 | System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)
64 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=
65 | 1033
66 |
67 |
68 | false
69 | false
70 | 0
71 | RELEASE;$(DCC_Define)
72 |
73 |
74 | DEBUG;$(DCC_Define)
75 | false
76 | true
77 |
78 |
79 | 1033
80 |
81 |
82 |
83 | MainSource
84 |
85 |
86 | Cfg_2
87 | Base
88 |
89 |
90 | Base
91 |
92 |
93 | Cfg_1
94 | Base
95 |
96 |
97 |
98 | Delphi.Personality.12
99 |
100 |
101 |
102 |
103 | test_block.dpr
104 |
105 |
106 | False
107 | False
108 | 1
109 | 0
110 | 0
111 | 0
112 | False
113 | False
114 | False
115 | False
116 | False
117 | 2052
118 | 936
119 |
120 |
121 |
122 |
123 | 1.0.0.0
124 |
125 |
126 |
127 |
128 |
129 | 1.0.0.0
130 |
131 |
132 |
133 |
134 | True
135 | False
136 | True
137 |
138 |
139 | 12
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/Tests/test_block.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/delphilite/BeaEngineDelphi/47f964bc3c29228feef4e2c5efed56db22eb7c4f/Tests/test_block.res
--------------------------------------------------------------------------------