Skip to content

Commit 0063960

Browse files
committed
Update README and Config.py for dune-built CodeHawk
1 parent 12b16c3 commit 0063960

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ requires a Java runtime environment.
2525

2626
Build instructions for the CodeHawk Binary Analyzer are available
2727
[here](https://github.com/static-analysis-engineering/codehawk/tree/master/CodeHawk).
28-
Upon completion copy the analyzer, `chx86_analyze`, from the `CodeHawk/CHB/bchcmdline`
29-
directory to the appropriate directory in `chb/bin/binaries`, or point the Config.py
30-
(or ConfigLocal.py) in `chb/util/` to its location. You can check the configuration
31-
with
28+
29+
If this repository is placed within, or next to, the `codehawk` checkout,
30+
you should be ready to proceed. Otherwise, copy
31+
`chb/util/ConfigLocal.template` to `chb/util/ConfigLocal.py` in this
32+
repository, and edit the latter file to set `config.codehawkdir` to
33+
the location of the `codehawk` checkout.
34+
35+
You can check the configuration with
3236
```
3337
> chkx info
3438
Analyzer configuration:
3539
-----------------------
36-
analyzer : /home/myname/codehawk/CodeHawk/CHB/bchcmdline/chx86_analyze (found)
40+
analyzer : /home/myname/codehawk/CodeHawk/_build/default/CHB/bchcmdline/bCHXBinaryAnalyzer.exe (found)
3741
summaries: /home/myname/codehawk/CodeHawk/CHB/bchsummaries/bchsummaries.jar (found)
3842
```
3943

chb/util/Config.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import os
3232

33-
from typing import Any, Dict, List
33+
from typing import Any, Dict, List, Optional
3434

3535
localconfig = False
3636

@@ -43,6 +43,12 @@
4343
class Config():
4444

4545
def __init__(self) -> None:
46+
self.codehawkdir: Optional[str] = None
47+
48+
# initial personalization, in particular for self.codehawkdir
49+
if localconfig:
50+
ConfigLocal.getLocals(self)
51+
4652
# platform settings
4753
if os.uname()[0] == 'Linux':
4854
self.platform = 'linux'
@@ -55,21 +61,34 @@ def __init__(self) -> None:
5561
self.rootdir = os.path.dirname(self.chbdir)
5662
self.testsdir = os.path.join(self.rootdir, "tests")
5763
self.projects = os.path.join(self.testsdir, "projects.json")
58-
self.bindir = os.path.join(self.chbdir, "bin")
59-
self.binariesdir = os.path.join(self.bindir, "binaries")
6064
self.summariesdir = os.path.join(self.chbdir, "summaries")
6165
self.summaries = os.path.join(self.summariesdir, "bchsummaries.jar")
6266
self.stdchheader = os.path.join(self.summariesdir, "bch_header.c")
6367

64-
# analyzer location
65-
if self.platform == 'linux':
66-
self.linuxdir = os.path.join(self.binariesdir, "linux")
67-
self.chx86_analyze = os.path.join(self.linuxdir, "chx86_analyze")
68-
self.cparser = os.path.join(self.linuxdir, "parseFile")
69-
70-
elif self.platform == "macOS":
71-
self.macOSdir = os.path.join(self.binariesdir, "macOS")
72-
self.chx86_analyze = os.path.join(self.macOSdir, "chx86_analyze")
68+
if self.codehawkdir is None:
69+
# CodeHawk directory -- assumption is it will be either the
70+
# parent directory of the rootdir, or a sibling in the parent.
71+
def looks_like_codehawk(path: str) -> bool:
72+
chb = os.path.join(path, "CodeHawk", "CHB")
73+
chc = os.path.join(path, "CodeHawk", "CHC")
74+
return os.path.isdir(chb) and os.path.isdir(chc)
75+
topparent = os.path.dirname(self.rootdir)
76+
alts = [topparent,
77+
os.path.join(topparent, "codehawk"),
78+
os.path.join(topparent, "CodeHawk")]
79+
viable_alts = [alt for alt in alts if looks_like_codehawk(alt)]
80+
self.codehawkdir = (viable_alts + [None])[0]
81+
82+
## analyzer executables
83+
if self.codehawkdir is not None:
84+
# Look for non-installed binaries by default
85+
self.cparser = os.path.join(self.codehawkdir, "CodeHawk",
86+
"_build", "default", "CHC", "cchcil", "cCHXParseFile.exe")
87+
self.chx86_analyze = os.path.join(self.codehawkdir, "CodeHawk",
88+
"_build", "default", "CHB", "bchcmdline", "bCHXBinaryAnalyzer.exe")
89+
else:
90+
self.cparser = "<no codehawkdir!>"
91+
self.chx86_analyze = "<no codehawkdir!>"
7392

7493
# instruction support
7594
self.armdir = os.path.join(self.chbdir, "arm")

chb/util/ConfigLocal.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def getLocals(config: 'Config') -> None:
4545
'''Set local configuration variables here if they differ from the defaults in Config.py
4646

4747
# Example :
48-
config.chx86_analyze = '/home/username/my-analyzer/chx86_analyze'
49-
config.chx86_gui = '/home/username/my-analyzer/chx86_gui
48+
config.codehawkdir = '/home/username/codehawk'
49+
config.chx86_gui = '/home/username/my-analyzer/chx86_gui'
5050
config.summaries = '/home/username/my-analyzer/bchsummaries.jar'
5151

5252
# Set locations of analysis targets

0 commit comments

Comments
 (0)