junxzm1990 / x86-sok

132 stars 20 forks source link

struct.error: unpack requires a buffer of 8 bytes in extract ground truth extractBB.py #20

Open NobinPegasus opened 2 years ago

NobinPegasus commented 2 years ago

When using the extract ground truth: python3 ../../extract_gt/extractBB.py -b test_switch -m test_switch.gt -o /tmp/gtBlock_test_switch.pb It gives the following error. How to fix it?

INFO:Found Gaps#0 in section .text, between 0x400530 - 0x4005d0, size: 160 INFO:Found Gaps#1 in section .text, between 0x400770 - 0x4007e2 INFO:Find the gap(0x400530 - 0x4005d0) behind basic block 0x400500, size is 48, padding is 5 INFO:Find the gap(0x400770 - 0x4007e2) behind basic block 0x40075d, size is 19, padding is 10 INFO:fi1: 0x400671, entry number is 14, its parent is 0x400669 INFO:Jump table base is 0x0 INFO:The begin Addr is 0x400671 INFO:Now instruction is from 0x400669 to 0x4 INFO:Now instruction is from 0x40066d to 0x8 INFO:Now instruction is from 0x400675 to 0x2 INFO:[indirect instruction] 0x400675: jmp rcx ERROR:Table base 0x0 not in fixups, please check! INFO:entry size is 0x8 Traceback (most recent call last): File "/gt_x86/x86-sok/extract_gt/extractBB.py", line 1976, in dumpGroundTruth(essInfo, module, outFile, options.binary, options.split) File "/gt_x86/x86-sok/extract_gt/extractBB.py", line 1216, in dumpGroundTruth jumpTable = scanJumpTable(essInfo, binary) File "/gt_x86/x86-sok/extract_gt/extractBB.py", line 1129, in scanJumpTable successors = readTableEntries(table_base, fi.numJTEntries, tbl_size, binary, entry_added_base) File "/gt_x86/x86-sok/extract_gt/extractBB.py", line 991, in readTableEntries entryContent = struct.unpack(unpackStr, entry) struct.error: unpack requires a buffer of 8 bytes

I was using the test_switch file. I am using the docker image provided in the repo hompage

bin2415 commented 2 years ago

Hello, I can't reproduce your problem. Could you help to share the test_switch binary?

NobinPegasus commented 2 years ago

Github don't allow to share binary file. How can I share that?

NobinPegasus commented 2 years ago

https://drive.google.com/file/d/19UVPEnetUS9xmAo7_W6QtcBDAeNwgT13/view?usp=sharing

Here's the file

bin2415 commented 2 years ago

The size of the jump table is not correct. Could you please list the steps of building the binary?

NobinPegasus commented 2 years ago

I just used the way you mentioned in the exampled guide.

Below are the given command I ran to build the binary and get the error

root@5e8606df7f20:/gt_x86/test# source ../gcc64.rc

root@5e8606df7f20:/gt_x86/test# export CFLAGS="-O0 $CFLAGS"

root@5e8606df7f20:/gt_x86/test# $CC $CFLAGS -o test_switch test_switch.c

root@5e8606df7f20:/gt_x86/test#  objcopy --dump-section .rand=test_switch.gt.gz test_switch && gzip -d test_switch.gt.gz

root@5e8606df7f20:/gt_x86/test# python3 ../../extract_gt/extractBB.py -b test_switch -m test_switch.gt -o /tmp/gtBlock_test_switch.pb