-
Notifications
You must be signed in to change notification settings - Fork 1.7k
WIP: Update Java bindings and add cstest_java implementation #2904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
peace-maker
wants to merge
4
commits into
capstone-engine:next
Choose a base branch
from
peace-maker:java_bindings
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| name: Java Module CI | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
|
|
||
| # Stop previous runs on the same branch on new push | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-24.04] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - uses: actions/setup-java@v5 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '21' | ||
|
|
||
| # - name: Setup MSVC | ||
| # if: runner.os == 'Windows' | ||
| # uses: ilammy/msvc-dev-cmd@v1 | ||
|
|
||
| - name: Install JNA | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y libjna-java | ||
|
|
||
| - name: Build and install capstone | ||
| run: | | ||
| mkdir build && cd build | ||
| cmake -DCAPSTONE_INSTALL=1 -DCAPSTONE_BUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX=/usr -DCAPSTONE_BUILD_CSTEST=ON .. | ||
| sudo cmake --build . --config Debug --target install | ||
|
|
||
| - name: Build java bindings | ||
| working-directory: bindings/java | ||
| run: make capstone | ||
|
|
||
| - name: Build cstest_java | ||
| working-directory: bindings/java/cstest_java | ||
| run: ./gradlew build installDist | ||
|
|
||
| - name: cstest_java integration tests | ||
| working-directory: suite/cstest/test | ||
| run: | | ||
| python3 ./integration_tests.py '../../../bindings/java/cstest_java/app/build/install/app/bin/app' | ||
|
|
||
| - name: cstest_java negative | ||
| run: | | ||
| for test_file in \ | ||
| tests/negative/should_fail_I.yaml \ | ||
| tests/negative/should_fail_II.yaml \ | ||
| tests/negative/should_fail_III.yaml \ | ||
| tests/negative/should_fail_IV.yaml \ | ||
| tests/negative/should_fail_V.yaml \ | ||
| tests/negative/should_fail_VI.yaml; do | ||
| if ./bindings/java/cstest_java/app/build/install/app/bin/app "$test_file"; then | ||
| echo "Expected failure but test passed: $test_file" | ||
| exit 1 | ||
| else | ||
| echo "Correctly failed: $test_file" | ||
| fi | ||
| done | ||
|
|
||
| - name: cstest_java MC | ||
| run: | | ||
| ./bindings/java/cstest_java/app/build/install/app/bin/app tests/MC/ | ||
|
|
||
| - name: cstest_java details | ||
| run: | | ||
| ./bindings/java/cstest_java/app/build/install/app/bin/app tests/details/ | ||
|
|
||
| - name: cstest_java issues | ||
| run: | | ||
| ./bindings/java/cstest_java/app/build/install/app/bin/app tests/issues/ | ||
|
|
||
| - name: cstest_java features | ||
| run: | | ||
| ./bindings/java/cstest_java/app/build/install/app/bin/app tests/features/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| files_to_format.txt | ||
| .DS_Store | ||
|
|
||
| venv | ||
| .gradle | ||
| # Object files | ||
| *.o | ||
| *.ko | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| *.class | ||
| tags | ||
| *.jar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,11 +2,11 @@ | |||||||||
| // By Nguyen Anh Quynh & Dang Hoang Vu, 2013 | ||||||||||
|
|
||||||||||
| import capstone.Capstone; | ||||||||||
| import capstone.Arm64; | ||||||||||
| import capstone.AArch64; | ||||||||||
|
|
||||||||||
| import static capstone.Arm64_const.*; | ||||||||||
| import static capstone.AArch64_const.*; | ||||||||||
|
|
||||||||||
| public class TestArm64 { | ||||||||||
| public class TestAArch64 { | ||||||||||
|
|
||||||||||
| static byte[] hexString2Byte(String s) { | ||||||||||
| // from http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java | ||||||||||
|
|
@@ -34,68 +34,66 @@ private static String hex(long i) { | |||||||||
| public static void print_ins_detail(Capstone.CsInsn ins) { | ||||||||||
| System.out.printf("0x%x:\t%s\t%s\n", ins.address, ins.mnemonic, ins.opStr); | ||||||||||
|
|
||||||||||
| Arm64.OpInfo operands = (Arm64.OpInfo) ins.operands; | ||||||||||
| AArch64.OpInfo operands = (AArch64.OpInfo) ins.operands; | ||||||||||
|
|
||||||||||
| if (operands.op.length != 0) { | ||||||||||
| System.out.printf("\top_count: %d\n", operands.op.length); | ||||||||||
| for (int c=0; c<operands.op.length; c++) { | ||||||||||
| Arm64.Operand i = (Arm64.Operand) operands.op[c]; | ||||||||||
| if (operands.operands.length != 0) { | ||||||||||
| System.out.printf("\top_count: %d\n", operands.operands.length); | ||||||||||
| for (int c=0; c<operands.operands.length; c++) { | ||||||||||
| AArch64.Operand i = (AArch64.Operand) operands.operands[c]; | ||||||||||
| String imm = hex(i.value.imm); | ||||||||||
| if (i.type == ARM64_OP_REG) | ||||||||||
| if (i.type == AARCH64_OP_REG) | ||||||||||
| System.out.printf("\t\toperands[%d].type: REG = %s\n", c, ins.regName(i.value.reg)); | ||||||||||
| if (i.type == ARM64_OP_REG_MRS) | ||||||||||
| if (i.type == AARCH64_OP_REG_MRS) | ||||||||||
| System.out.printf("\t\toperands[%d].type: REG_MRS = 0x%x\n", c, i.value.reg); | ||||||||||
| if (i.type == ARM64_OP_REG_MSR) | ||||||||||
| if (i.type == AARCH64_OP_REG_MSR) | ||||||||||
| System.out.printf("\t\toperands[%d].type: REG_MSR = 0x%x\n", c, i.value.reg); | ||||||||||
| if (i.type == ARM64_OP_PSTATE) | ||||||||||
| System.out.printf("\t\toperands[%d].type: PSTATE = 0x%x\n", c, i.value.imm); | ||||||||||
| if (i.type == ARM64_OP_BARRIER) | ||||||||||
| System.out.printf("\t\toperands[%d].type: BARRIER = 0x%x\n", c, i.value.imm); | ||||||||||
| // if (i.type == AARCH64_OP_PSTATE) | ||||||||||
| // System.out.printf("\t\toperands[%d].type: PSTATE = 0x%x\n", c, i.value.imm); | ||||||||||
| // if (i.type == AARCH64_OP_BARRIER) | ||||||||||
| // System.out.printf("\t\toperands[%d].type: BARRIER = 0x%x\n", c, i.value.imm); | ||||||||||
|
Comment on lines
+50
to
+53
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| if (i.type == ARM64_OP_IMM) | ||||||||||
| if (i.type == AARCH64_OP_IMM) | ||||||||||
| System.out.printf("\t\toperands[%d].type: IMM = 0x%x\n", c, i.value.imm); | ||||||||||
| if (i.type == ARM64_OP_CIMM) | ||||||||||
| if (i.type == AARCH64_OP_CIMM) | ||||||||||
| System.out.printf("\t\toperands[%d].type: C-IMM = %d\n", c, i.value.imm); | ||||||||||
| if (i.type == ARM64_OP_FP) | ||||||||||
| if (i.type == AARCH64_OP_FP) | ||||||||||
| System.out.printf("\t\toperands[%d].type: FP = %f\n", c, i.value.fp); | ||||||||||
| if (i.type == ARM64_OP_MEM) { | ||||||||||
| if (i.type == AARCH64_OP_MEM) { | ||||||||||
| System.out.printf("\t\toperands[%d].type: MEM\n",c); | ||||||||||
| String base = ins.regName(i.value.mem.base); | ||||||||||
| String index = ins.regName(i.value.mem.index); | ||||||||||
| if (base != null) | ||||||||||
| System.out.printf("\t\t\toperands[%d].mem.base: REG = %s\n", c, base); | ||||||||||
| if (index != null) | ||||||||||
| System.out.printf("\t\t\toperands[%d].mem.index: REG = %s\n", c, index); | ||||||||||
| if (i.value.mem.base != AARCH64_REG_INVALID) | ||||||||||
| System.out.printf("\t\t\toperands[%d].mem.base: REG = %s\n", c, ins.regName(i.value.mem.base)); | ||||||||||
| if (i.value.mem.index != AARCH64_REG_INVALID) | ||||||||||
| System.out.printf("\t\t\toperands[%d].mem.index: REG = %s\n", c, ins.regName(i.value.mem.index)); | ||||||||||
| if (i.value.mem.disp != 0) | ||||||||||
| System.out.printf("\t\t\toperands[%d].mem.disp: 0x%x\n", c, i.value.mem.disp); | ||||||||||
| } | ||||||||||
| if (i.shift.type != ARM64_SFT_INVALID && i.shift.value > 0) | ||||||||||
| if (i.shift.type != AARCH64_SFT_INVALID && i.shift.value > 0) | ||||||||||
| System.out.printf("\t\t\tShift: type = %d, value = %d\n", i.shift.type, i.shift.value); | ||||||||||
| if (i.ext != ARM64_EXT_INVALID) | ||||||||||
| if (i.ext != AARCH64_EXT_INVALID) | ||||||||||
| System.out.printf("\t\t\tExt: %d\n", i.ext); | ||||||||||
| if (i.vas != ARM64_VAS_INVALID) | ||||||||||
| if (i.vas != AARCH64LAYOUT_INVALID) | ||||||||||
| System.out.printf("\t\t\tVector Arrangement Specifier: 0x%x\n", i.vas); | ||||||||||
| if (i.vector_index != -1) | ||||||||||
| System.out.printf("\t\t\tVector Index: %d\n", i.vector_index); | ||||||||||
|
|
||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (operands.writeback) | ||||||||||
| System.out.println("\tWrite-back: True"); | ||||||||||
| // if (operands.writeback) | ||||||||||
| // System.out.println("\tWrite-back: True"); | ||||||||||
|
Comment on lines
+82
to
+83
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| if (operands.updateFlags) | ||||||||||
| System.out.println("\tUpdate-flags: True"); | ||||||||||
|
|
||||||||||
| if (operands.cc != ARM64_CC_AL && operands.cc != ARM64_CC_INVALID) | ||||||||||
| if (operands.cc != AArch64CC_Invalid) | ||||||||||
| System.out.printf("\tCode-condition: %d\n", operands.cc); | ||||||||||
|
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| public static void main(String argv[]) { | ||||||||||
|
|
||||||||||
| final TestBasic.platform[] all_tests = { | ||||||||||
| new TestBasic.platform(Capstone.CS_ARCH_ARM64, Capstone.CS_MODE_ARM, hexString2Byte(ARM64_CODE), "ARM-64"), | ||||||||||
| new TestBasic.platform(Capstone.CS_ARCH_AARCH64, Capstone.CS_MODE_ARM, hexString2Byte(ARM64_CODE), "ARM-64"), | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| for (int i=0; i<all_tests.length; i++) { | ||||||||||
|
|
||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -39,10 +39,10 @@ public static void print_ins_detail(Capstone.CsInsn ins) { | |||||
|
|
||||||
| Arm.OpInfo operands = (Arm.OpInfo) ins.operands; | ||||||
|
|
||||||
| if (operands.op.length != 0) { | ||||||
| System.out.printf("\top_count: %d\n", operands.op.length); | ||||||
| for (int c=0; c<operands.op.length; c++) { | ||||||
| Arm.Operand i = (Arm.Operand) operands.op[c]; | ||||||
| if (operands.operands.length != 0) { | ||||||
| System.out.printf("\top_count: %d\n", operands.operands.length); | ||||||
| for (int c=0; c<operands.operands.length; c++) { | ||||||
| Arm.Operand i = (Arm.Operand) operands.operands[c]; | ||||||
| String imm = hex(i.value.imm); | ||||||
| if (i.type == ARM_OP_SYSREG) | ||||||
| System.out.printf("\t\toperands[%d].type: SYSREG = %d\n", c, i.value.reg); | ||||||
|
|
@@ -70,24 +70,24 @@ public static void print_ins_detail(Capstone.CsInsn ins) { | |||||
| System.out.printf("\t\t\toperands[%d].mem.scale: %d\n", c, (i.value.mem.scale)); | ||||||
| if (i.value.mem.disp != 0) | ||||||
| System.out.printf("\t\t\toperands[%d].mem.disp: 0x%x\n", c, (i.value.mem.disp)); | ||||||
| if (i.value.mem.lshift != 0) | ||||||
| System.out.printf("\t\t\toperands[%d].mem.lshift: 0x%x\n", c, (i.value.mem.lshift)); | ||||||
| if (i.value.mem.align != 0) | ||||||
| System.out.printf("\t\t\toperands[%d].mem.align: 0x%x\n", c, (i.value.mem.align)); | ||||||
| } | ||||||
| if (i.vector_index > 0) | ||||||
| System.out.printf("\t\t\toperands[%d].vector_index = %d\n", c, (i.vector_index)); | ||||||
| if (i.shift.type != ARM_SFT_INVALID && i.shift.value > 0) | ||||||
| System.out.printf("\t\t\tShift: %d = %d\n", i.shift.type, i.shift.value); | ||||||
| if (i.subtracted) | ||||||
| if (i.subtracted != 0) | ||||||
| System.out.printf("\t\t\toperands[%d].subtracted = True\n", c); | ||||||
| } | ||||||
| } | ||||||
| if (operands.writeback) | ||||||
| System.out.println("\tWrite-back: True"); | ||||||
| // if (operands.writeback) | ||||||
| // System.out.println("\tWrite-back: True"); | ||||||
|
Comment on lines
+84
to
+85
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| if (operands.updateFlags) | ||||||
| System.out.println("\tUpdate-flags: True"); | ||||||
|
|
||||||
| if (operands.cc != ARM_CC_AL && operands.cc != ARM_CC_INVALID) | ||||||
| if (operands.cc != ARMCC_AL && operands.cc != ARMCC_UNDEF) | ||||||
| System.out.printf("\tCode condition: %d\n", operands.cc); | ||||||
|
|
||||||
| if (operands.cpsMode > 0) | ||||||
|
|
||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.