-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the method of packing function code into zip
- Loading branch information
Showing
6 changed files
with
69 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,79 @@ | ||
package function | ||
|
||
import _ "embed" | ||
import ( | ||
"archive/zip" | ||
"bytes" | ||
_ "embed" | ||
"encoding/base64" | ||
|
||
// compile socks code with `GOOS=linux GOARCH=amd64 go build main.go` | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type File struct { | ||
Name string | ||
Content []byte | ||
HighPriv bool | ||
} | ||
|
||
// compile socks code with `GOOS=linux GOARCH=amd64 go build main.go` | ||
var ( | ||
//go:embed http/tencent.py | ||
TencentHttpCode []byte | ||
tencentHttpCode []byte | ||
TencentHttpCodeZip = CreateZipBase64([]File{{Name: "index.py", Content: tencentHttpCode}}) | ||
|
||
//go:embed http/alibaba.py | ||
AlibabaHttpCode []byte | ||
alibabaHttpCode []byte | ||
AlibabaHttpCodeZip = CreateZipBase64([]File{{Name: "index.py", Content: alibabaHttpCode}}) | ||
|
||
//go:embed http/huawei.py | ||
HuaweiHttpCode []byte | ||
huaweiHttpCode []byte | ||
HuaweiHttpCodeZip =CreateZipBase64([]File{{Name: "index.py", Content: huaweiHttpCode}}) | ||
|
||
//go:embed socks/tencent | ||
TencentSocksCode []byte | ||
tencentSocksCode []byte | ||
TencentSocksCodeZip = CreateZipBase64([]File{{Name: "index.py", Content: tencentSocksCode, HighPriv: true}}) | ||
|
||
//go:embed socks/alibaba | ||
AlibabaSocksCode []byte | ||
alibabaSocksCode []byte | ||
AlibabaSocksCodeZip = CreateZipBase64([]File{{Name: "index.py", Content: alibabaSocksCode, HighPriv: true}}) | ||
) | ||
|
||
|
||
|
||
func CreateZipBase64(files []File) string { | ||
buf := new(bytes.Buffer) | ||
|
||
zw := zip.NewWriter(buf) | ||
|
||
for _, f := range files{ | ||
if f.HighPriv { | ||
fw, err := zw.CreateHeader(&zip.FileHeader{ | ||
CreatorVersion: 3 << 8, // indicates Unix | ||
ExternalAttrs: 0777 << 16, // -rwxrwxrwx file permissions | ||
Name: f.Name, | ||
Method: zip.Deflate, | ||
}) | ||
if err != nil { | ||
logrus.Error(err) | ||
} | ||
|
||
_, err = fw.Write(f.Content) | ||
if err != nil { | ||
logrus.Error(err) | ||
} | ||
} else { | ||
fw, err := zw.Create(f.Name) | ||
if err != nil { | ||
logrus.Error(err) | ||
} | ||
_, err = fw.Write(f.Content) | ||
if err != nil { | ||
logrus.Error(err) | ||
} | ||
} | ||
} | ||
|
||
zw.Close() | ||
return base64.StdEncoding.EncodeToString(buf.Bytes()) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters