Skip to content

Commit ecbae78

Browse files
author
Alex Levinson
committed
new functionsss woot
1 parent 3ca58d1 commit ecbae78

File tree

7 files changed

+701
-42
lines changed

7 files changed

+701
-42
lines changed

FUNCTIONS.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@ Retrieves a packed asset from the VM embedded file store.
133133

134134

135135

136+
## `Chmod(path, perms)`
137+
138+
Change the permissions on a path.
139+
140+
### Argument List
141+
142+
* **path** *string*
143+
* **perms** *int64*
144+
145+
### Returned Object Fields
146+
147+
* **osError** *error*
148+
149+
---
150+
151+
152+
136153
## `CreateDir(path)`
137154

138155
Creates a directory at a given path or return an error
@@ -367,6 +384,41 @@ Perform an MD5() hash on data.
367384

368385

369386

387+
## `ModTime(path)`
388+
389+
Retrieves the last modified time of a path.
390+
391+
### Argument List
392+
393+
* **path** *string*
394+
395+
### Returned Object Fields
396+
397+
* **modTime** *int64*
398+
* **fileError** *error*
399+
400+
---
401+
402+
403+
404+
## `ModifyTimestamp(path, accessTime, modifyTime)`
405+
406+
Change the access and modified time of a file.
407+
408+
### Argument List
409+
410+
* **path** *string*
411+
* **accessTime** *int64*
412+
* **modifyTime** *int64*
413+
414+
### Returned Object Fields
415+
416+
* **fileError** *error*
417+
418+
---
419+
420+
421+
370422
## `ObfuscateString(str)`
371423

372424
Basic string obfuscator function.
@@ -499,6 +551,22 @@ Returns an array of int's representing active PIDs currently running
499551

500552

501553

554+
## `SelfPath()`
555+
556+
Retrieves the path to the currently running executable.
557+
558+
### Argument List
559+
560+
561+
### Returned Object Fields
562+
563+
* **path** *string*
564+
* **osError** *error*
565+
566+
---
567+
568+
569+
502570
## `Signal(signal, pid)`
503571

504572
Sends a signal to a target proccess

engine/lib_os.go

Lines changed: 160 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package engine
33
import (
44
"errors"
55
"os"
6-
"path/filepath"
76
"strings"
87
"syscall"
8+
"time"
99

1010
services "github.com/gen0cide/service-go"
1111
"github.com/mitchellh/go-ps"
@@ -103,7 +103,7 @@ func (e *Engine) FindProcByName(procName string) (int, error) {
103103
//
104104
func (e *Engine) InstallSystemService(path, name, displayName, description string) error {
105105
c := &services.Config{
106-
Path: filepath.Clean(path),
106+
Path: path,
107107
Name: name,
108108
DisplayName: displayName,
109109
Description: description,
@@ -470,3 +470,161 @@ func (e *Engine) EnvVars() map[string]string {
470470
func (e *Engine) GetEnvVar(eVar string) string {
471471
return os.Getenv(eVar)
472472
}
473+
474+
// SelfPath - Retrieves the path to the currently running executable.
475+
//
476+
// Package
477+
//
478+
// os
479+
//
480+
// Author
481+
//
482+
// - gen0cide (https://github.com/gen0cide)
483+
//
484+
// Javascript
485+
//
486+
// Here is the Javascript method signature:
487+
// SelfPath()
488+
//
489+
// Arguments
490+
//
491+
// Here is a list of the arguments for the Javascript function:
492+
//
493+
// Returns
494+
//
495+
// Here is a list of fields in the return object:
496+
// * obj.path (string)
497+
// * obj.osError (error)
498+
//
499+
// Example
500+
//
501+
// Here is an example of how to use this function in gscript:
502+
// var obj = SelfPath();
503+
// // obj.path
504+
// // obj.osError
505+
//
506+
func (e *Engine) SelfPath() (string, error) {
507+
return os.Executable()
508+
}
509+
510+
// Chmod - Change the permissions on a path.
511+
//
512+
// Package
513+
//
514+
// os
515+
//
516+
// Author
517+
//
518+
// - gen0cide (https://github.com/gen0cide)
519+
//
520+
// Javascript
521+
//
522+
// Here is the Javascript method signature:
523+
// Chmod(path, perms)
524+
//
525+
// Arguments
526+
//
527+
// Here is a list of the arguments for the Javascript function:
528+
// * path (string)
529+
// * perms (int64)
530+
//
531+
// Returns
532+
//
533+
// Here is a list of fields in the return object:
534+
// * obj.osError (error)
535+
//
536+
// Example
537+
//
538+
// Here is an example of how to use this function in gscript:
539+
// var obj = Chmod(path, perms);
540+
// // obj.osError
541+
//
542+
func (e *Engine) Chmod(path string, perms int64) error {
543+
if err := os.Chmod(path, os.FileMode(uint32(perms))); err != nil {
544+
return err
545+
}
546+
return nil
547+
}
548+
549+
// ModTime - Retrieves the last modified time of a path.
550+
//
551+
// Package
552+
//
553+
// os
554+
//
555+
// Author
556+
//
557+
// - gen0cide (https://github.com/gen0cide)
558+
//
559+
// Javascript
560+
//
561+
// Here is the Javascript method signature:
562+
// ModTime(path)
563+
//
564+
// Arguments
565+
//
566+
// Here is a list of the arguments for the Javascript function:
567+
// * path (string)
568+
//
569+
// Returns
570+
//
571+
// Here is a list of fields in the return object:
572+
// * obj.modTime (int64)
573+
// * obj.fileError (error)
574+
//
575+
// Example
576+
//
577+
// Here is an example of how to use this function in gscript:
578+
// var obj = ModTime(path);
579+
// // obj.modTime
580+
// // obj.fileError
581+
//
582+
func (e *Engine) ModTime(path string) (int64, error) {
583+
f, err := os.Stat(path)
584+
if err != nil {
585+
return 0, err
586+
}
587+
return f.ModTime().Unix(), nil
588+
}
589+
590+
// ModifyTimestamp - Change the access and modified time of a file.
591+
//
592+
// Package
593+
//
594+
// os
595+
//
596+
// Author
597+
//
598+
// - gen0cide (https://github.com/gen0cide)
599+
//
600+
// Javascript
601+
//
602+
// Here is the Javascript method signature:
603+
// ModifyTimestamp(path, accessTime, modifyTime)
604+
//
605+
// Arguments
606+
//
607+
// Here is a list of the arguments for the Javascript function:
608+
// * path (string)
609+
// * accessTime (int64)
610+
// * modifyTime (int64)
611+
//
612+
// Returns
613+
//
614+
// Here is a list of fields in the return object:
615+
// * obj.fileError (error)
616+
//
617+
// Example
618+
//
619+
// Here is an example of how to use this function in gscript:
620+
// var obj = ModifyTimestamp(path, accessTime, modifyTime);
621+
// // obj.fileError
622+
//
623+
func (e *Engine) ModifyTimestamp(path string, accessTime, modifyTime int64) error {
624+
aTime := time.Unix(accessTime, 0)
625+
mTime := time.Unix(modifyTime, 0)
626+
if err := os.Chtimes(path, aTime, mTime); err != nil {
627+
return err
628+
}
629+
return nil
630+
}

0 commit comments

Comments
 (0)