Skip to content

Commit

Permalink
GenerateGarbageAssembly function adjusted for better stability.
Browse files Browse the repository at this point in the history
  • Loading branch information
EgeBalci committed Feb 22, 2024
1 parent 012c110 commit f54fa65
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func main() {
color.Blue("\n" + hex.Dump(payload) + "\n")
}

utils.PrintVerbose("Total Garbage Size: %d", encoder.ObfuscationLimit)
utils.PrintSuccess("Final size: %d", outputSize)
utils.PrintSuccess("All done \(^O^)/")
}
Expand Down
31 changes: 2 additions & 29 deletions pkg/obfuscate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,16 @@ import (
// GenerateGarbageAssembly generates random garbage instruction(s) assemblies
// based on the subject encoder architecture
func (encoder *Encoder) GenerateGarbageAssembly() string {

switch rand.Intn(4) {
case 1:
if CoinFlip() {
randomGarbageAssembly := GetRandomSafeAssembly()
register := encoder.GetRandomRegister(encoder.architecture)
randomGarbageAssembly = strings.ReplaceAll(randomGarbageAssembly, "{R}", register)
randomGarbageAssembly = strings.ReplaceAll(randomGarbageAssembly, "{K}", fmt.Sprintf("0x%x", GetRandomByte()))
randomGarbageAssembly = strings.ReplaceAll(randomGarbageAssembly, "{L}", RandomLabel())
randomGarbageAssembly = strings.ReplaceAll(randomGarbageAssembly, "{G}", encoder.GenerateGarbageAssembly())
return randomGarbageAssembly + ";"
case 2:
return encoder.GetRandomFunctionAssembly()
case 3:
randRegister, _ := encoder.GetSafeRandomRegister(encoder.architecture, encoder.GetStackPointer()) // we can safely ignore the error
// Save the destination register
// After saving the target register to stack we can munipulate the register unlimited times
unsafeGarbageAssembly := fmt.Sprintf("PUSH %s;", randRegister)
if CoinFlip() {
unsafeGarbageAssembly += encoder.GenerateGarbageAssembly()
}
unsafeGarbageAssembly += encoder.GetRandomUnsafeAssembly(randRegister)
// Keep adding unsafe garbage by chance
for {
if CoinFlip() {
unsafeGarbageAssembly += encoder.GetRandomUnsafeAssembly(randRegister)
} else {
break
}
}
if CoinFlip() {
unsafeGarbageAssembly += encoder.GenerateGarbageAssembly()
}
unsafeGarbageAssembly += fmt.Sprintf("POP %s;", randRegister)
return unsafeGarbageAssembly
default:
return ";"
}
return ";"
}

// GenerateGarbageInstructions generates random garbage instruction(s)
Expand Down

0 comments on commit f54fa65

Please sign in to comment.