Skip to content

Commit 0f92450

Browse files
author
Alex Levinson
committed
implementing more core functions
1 parent 6945add commit 0f92450

8 files changed

Lines changed: 212 additions & 2 deletions

File tree

FUNCTIONS.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,52 @@ Basic string deobfuscator function.
133133

134134

135135

136+
## `MD5(data)`
137+
138+
Perform an MD5() hash on data.
139+
140+
### Argument List
141+
142+
* **data** *[]byte*
143+
144+
### Returned Object Fields
145+
146+
* **value** *string*
147+
148+
---
149+
150+
151+
152+
## `Timestamp()`
153+
154+
Get the system's current timestamp in epoch format.
155+
156+
### Argument List
157+
158+
159+
### Returned Object Fields
160+
161+
* **value** *int64*
162+
163+
---
164+
165+
166+
167+
## `Halt()`
168+
169+
Stop the current VM from continuing execution.
170+
171+
### Argument List
172+
173+
174+
### Returned Object Fields
175+
176+
* **value** *bool*
177+
178+
---
179+
180+
181+
136182
## `ExecuteCommand(baseCmd, cmdArgs)`
137183

138184
Executes system commands.

engine/lib_core.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package engine
22

33
import (
4+
"crypto/md5"
45
"crypto/rand"
6+
"encoding/hex"
57
"errors"
68
"math/big"
79
"strings"
10+
"time"
811
"unicode"
912
)
1013

@@ -86,3 +89,21 @@ func (e *Engine) Asset(filename string) ([]byte, error) {
8689
err := errors.New("Asset not found: " + filename)
8790
return []byte{}, err
8891
}
92+
93+
func (e *Engine) Timestamp() int64 {
94+
return time.Now().Unix()
95+
}
96+
97+
func (e *Engine) Halt() bool {
98+
e.Halted = true
99+
e.VM.Interrupt <- func() {
100+
panic(errTimeout)
101+
}
102+
return true
103+
}
104+
105+
func (e *Engine) MD5(data []byte) string {
106+
hasher := md5.New()
107+
hasher.Write(data)
108+
return hex.EncodeToString(hasher.Sum(nil))
109+
}

engine/util.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"net"
88

9-
"github.com/davecgh/go-spew/spew"
109
"github.com/robertkrimen/otto"
1110
)
1211

@@ -97,7 +96,6 @@ func (e *Engine) ValueToByteSlice(v otto.Value) []byte {
9796
}
9897
} else {
9998
e.Logger.WithField("trace", "true").Errorf("Unknown class to cast to byte slice")
100-
spew.Dump(v)
10199
}
102100

103101
return valueBytes

engine/vm_functions.go

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,35 @@
9898
- label: value
9999
gotype: string
100100
return: true
101+
- name: MD5
102+
description: Perform an MD5() hash on data.
103+
author: Alex
104+
package: core
105+
args:
106+
- label: data
107+
gotype: '[]byte'
108+
returns:
109+
- label: value
110+
gotype: string
111+
return: true
112+
- name: Timestamp
113+
description: Get the system's current timestamp in epoch format.
114+
author: Alex
115+
package: core
116+
args: []
117+
returns:
118+
- label: value
119+
gotype: int64
120+
return: true
121+
- name: Halt
122+
description: Stop the current VM from continuing execution.
123+
author: Alex
124+
package: core
125+
args: []
126+
returns:
127+
- label: value
128+
gotype: bool
129+
return: true
101130
#####################################################################
102131
#
103132
# exec package

spec/halt.gs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ function BeforeDeploy() {
55
}
66

77
function Deploy() {
8+
LogInfo("Deploy()");
89
return true;
910
}
1011

1112
function AfterDeploy() {
13+
LogInfo("AfterDeploy()");
1214
return true;
1315
}
1416

spec/md5.gs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//import:/Users/flint/Downloads/tater.jpg
2+
3+
function BeforeDeploy() {
4+
LogInfo("BeforeDeploy()");
5+
return true;
6+
}
7+
8+
function Deploy() {
9+
var firstHash = MD5("helloworld");
10+
var secondHash = MD5(Asset("tater.jpg").fileData);
11+
DebugConsole();
12+
return true;
13+
}
14+
15+
function AfterDeploy() {
16+
LogInfo("AfterDeploy()");
17+
return true;
18+
}

spec/timestamp.gs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function BeforeDeploy() {
2+
LogInfo("BeforeDeploy()");
3+
return true;
4+
}
5+
6+
function Deploy() {
7+
ts = Timestamp();
8+
LogInfo("Deploy()");
9+
LogDebug("Timestamp: " + ts.value);
10+
return true;
11+
}
12+
13+
function AfterDeploy() {
14+
LogInfo("AfterDeploy()");
15+
return true;
16+
}

0 commit comments

Comments
 (0)