Skip to content

Commit 17a5025

Browse files
committed
Colored opcodes in a loop in a different way
1 parent 2670b3f commit 17a5025

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/api/bytecode/Operation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export interface Operation {
66
argument: any
77
begin?: number
88
end?: number
9+
repeated?: number
910
}

src/api/cfg/GraphVizService.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import { DebugTrace } from '../symbolic/evm/DebugTrace'
77
@injectable()
88
export class GraphVizService {
99
createDotFromBlocks(blocks: CFGBlocks, trace: DebugTrace): string {
10-
return `digraph " " {
10+
let graph = `digraph " " {
1111
graph [splines=ortho ranksep="2" nodesep="2"]
1212
rankdir=LR
13-
node [shape=plain fillcolor="#2A2A2A" style=filled fontname="Courier"]
14-
${this.createLegend()}
15-
${this.buildBody(blocks, trace)}
16-
}`
13+
node [shape=plain fillcolor="#2A2A2A" style=filled fontname="Courier"]`
14+
if (trace) {
15+
graph += `${this.createLegend()}`
16+
}
17+
graph += `${this.buildBody(blocks, trace)}
18+
}`
19+
return graph
1720
}
1821

1922
private createLegend() {
@@ -46,6 +49,9 @@ export class GraphVizService {
4649
if (trace && this.isOperationInTrace(op, trace)) {
4750
fontColor = '#ff1020'
4851
}
52+
if (op.repeated > 1) {
53+
fontColor = '#CD950C'
54+
}
4955
ops += `<TR>`
5056
ops += `<TD ID="${op.offset.toString(16)}" HREF=" "><font color="${fontColor}">0x${op.offset.toString(
5157
16

src/api/cfg/OperationBlock.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ export interface OperationBlock {
44
offset: number
55
operations: Operation[]
66
childA?: number
7-
childB?: number,
8-
repeated?: number
7+
childB?: number
98
}

src/api/service/service/CFGService.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ export class CFGService {
5151
checkTraceLoops(blocks: CFGBlocks, trace: DebugTrace) {
5252
const logs = trace.result.structLogs
5353
const count = this.count(logs.map(l => l.pc))
54-
const repeated: any = Object.keys(count).filter(key => count[key] > 1).map( key=> { return {offset: key, repeated: count[key]}})
54+
const repeated: any = Object.keys(count).filter(key => count[key] > 1).map( key=> { return {offset: parseInt(key), repeated: parseInt(count[key])}})
5555
for (const repeatedOffset of repeated) {
56-
console.log(`trying to find block ${repeatedOffset.offset}`)
5756
const block = blocks.get(repeatedOffset.offset)
5857
if (block) {
59-
console.log('block found')
60-
block.repeated = repeatedOffset.repeated
58+
const operation = block.operations.find(op => op.offset === parseInt(repeatedOffset.offset))
59+
if (operation) {
60+
operation.repeated = repeatedOffset.repeated
61+
}
6162
}
6263
}
6364
}

0 commit comments

Comments
 (0)