|
|
|
|
# Note that it doesn't really matter if the assembly below is badly written.
|
|
|
|
|
# We just care enough to see that it obfuscates and keeps the same behavior.
|
|
|
|
|
# TODO: support arm64, at least
|
|
|
|
|
[!amd64] skip 'the assembly is only written for amd64'
|
|
|
|
|
|
|
|
|
|
exec garble build
|
|
|
|
|
exec ./main
|
|
|
|
|
cmp stderr main.stderr
|
|
|
|
|
! binsubstr main$exe 'test/main' 'addJmp' 'AddImpl' 'garble_'
|
|
|
|
|
|
|
|
|
|
# We used to panic on broken packages with assembly.
|
|
|
|
|
! exec garble build ./broken/...
|
|
|
|
|
stderr -count=1 'broken[/\\]asm[/\\].*MissingType'
|
|
|
|
|
stderr -count=1 'broken[/\\]syntax[/\\].*unexpected newline'
|
|
|
|
|
|
|
|
|
|
[short] stop # no need to verify this with -short
|
|
|
|
|
|
|
|
|
|
# Ensure that reversing doesn't error with assembly files.
|
|
|
|
|
# It should fail, as there is nothing to reverse, but without any parse error.
|
|
|
|
|
stdin empty-reverse.txt
|
|
|
|
|
! exec garble reverse .
|
|
|
|
|
! stderr .
|
|
|
|
|
|
|
|
|
|
exec garble -tiny build
|
|
|
|
|
exec ./main
|
|
|
|
|
cmp stderr main.stderr
|
|
|
|
|
! binsubstr main$exe 'addJmp' 'AddImpl'
|
|
|
|
|
|
|
|
|
|
go build
|
|
|
|
|
exec ./main
|
|
|
|
|
cmp stderr main.stderr
|
|
|
|
|
binsubstr main$exe 'addJmp' 'AddImpl'
|
|
|
|
|
-- go.mod --
|
|
|
|
|
module test/with.many.dots/main
|
|
|
|
|
|
|
|
|
|
go 1.23
|
|
|
|
|
-- main.go --
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"test/with.many.dots/main/imported"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func addJmpPkgPath(x, y int32) int32
|
|
|
|
|
func addJmpPkgName(x, y int32) int32
|
|
|
|
|
|
|
|
|
|
// goData is used from both assembly and header files.
|
|
|
|
|
var goData = [4]uint64{1, 2, 3, 4}
|
|
|
|
|
|
|
|
|
|
func modifyGoData()
|
|
|
|
|
func modifyGoData2()
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
println(addJmpPkgPath(1, 2))
|
|
|
|
|
println(addJmpPkgName(1, 2))
|
|
|
|
|
|
|
|
|
|
println(goData[0], goData[1])
|
|
|
|
|
modifyGoData()
|
|
|
|
|
println(goData[0], goData[1])
|
|
|
|
|
modifyGoData2()
|
|
|
|
|
println(goData[0], goData[1])
|
|
|
|
|
|
|
|
|
|
println(imported.AddImpl(3, 4))
|
|
|
|
|
}
|
|
|
|
|
-- garble_main_amd64.s --
|
|
|
|
|
#include "garble_define_amd64.h"
|
|
|
|
|
|
|
|
|
|
#include "extra/garble_define2_amd64.h" // Inline: many·special∕asm·runes.
|
|
|
|
|
|
skip over comments when obfuscating assembly
github.com/bytedance/sonic has many comments in its assembly files,
and one in particular caused us trouble:
internal/rt/asm_amd64.s:2:// Code generated by asm2asm, DO NOT EDIT·
Since we looked for "middle dot" characters anywhere,
we would try to load the package "EDIT", which clearly does not exist.
To fix that, start skipping over comments. Thankfully,
Go's assembly syntax only supports "//" line comments,
so it's enough to read one line at a time and skip them quickly.
We also longer need a regular expression to find #include lines.
While here, two other minor bits of cleanup.
First, rename transformGo to transformGoFile, for clarity.
Second, use ".s" extensions for obfuscated assembly filenames,
just like we do with the comiler and ".go" files.
Updates #621.
2 years ago
|
|
|
|
// A comment may include many·special∕asm·runes and it's okay.
|
|
|
|
|
//No space: many·special∕asm·runes.
|
|
|
|
|
// Indented: many·special∕asm·runes.
|
|
|
|
|
DATA bar+0(SB)/8, $0 // Inline: many·special∕asm·runes.
|
skip over comments when obfuscating assembly
github.com/bytedance/sonic has many comments in its assembly files,
and one in particular caused us trouble:
internal/rt/asm_amd64.s:2:// Code generated by asm2asm, DO NOT EDIT·
Since we looked for "middle dot" characters anywhere,
we would try to load the package "EDIT", which clearly does not exist.
To fix that, start skipping over comments. Thankfully,
Go's assembly syntax only supports "//" line comments,
so it's enough to read one line at a time and skip them quickly.
We also longer need a regular expression to find #include lines.
While here, two other minor bits of cleanup.
First, rename transformGo to transformGoFile, for clarity.
Second, use ".s" extensions for obfuscated assembly filenames,
just like we do with the comiler and ".go" files.
Updates #621.
2 years ago
|
|
|
|
|
|
|
|
|
// Reference an imported package by its package path.
|
|
|
|
|
TEXT ·addJmpPkgPath(SB),$0-16
|
|
|
|
|
JMP test∕with·many·dots∕main∕imported·AddImpl(SB)
|
|
|
|
|
|
|
|
|
|
// Reference the current package by its package name.
|
|
|
|
|
TEXT ·addJmpPkgName(SB),$0-16
|
|
|
|
|
JMP main·addJmpPkgPath(SB)
|
|
|
|
|
|
|
|
|
|
TEXT ·modifyGoData(SB),$0-16
|
|
|
|
|
addGoDataTo($12)
|
|
|
|
|
ADDL $34, ·goData+8(SB)
|
|
|
|
|
RET
|
|
|
|
|
|
|
|
|
|
TEXT ·modifyGoData2(SB),$0-16
|
|
|
|
|
addGoDataTo2($12)
|
|
|
|
|
ADDL $34,·goData+8(SB) // note the lack of a space
|
|
|
|
|
RET
|
|
|
|
|
|
|
|
|
|
-- garble_define_amd64.h --
|
|
|
|
|
#define addGoDataTo(arg) \
|
|
|
|
|
ADDL arg, ·goData+0(SB)
|
|
|
|
|
|
|
|
|
|
-- extra/garble_define2_amd64.h --
|
|
|
|
|
#define addGoDataTo2(arg) \
|
|
|
|
|
ADDL arg, ·goData+0(SB)
|
|
|
|
|
|
|
|
|
|
-- imported/imported.go --
|
|
|
|
|
package imported
|
|
|
|
|
|
|
|
|
|
func AddImpl(x, y int32) int32
|
|
|
|
|
|
|
|
|
|
// Reference the current package by its package path.
|
|
|
|
|
func addJmpPkgPath(x, y int32) int32
|
|
|
|
|
|
|
|
|
|
// Reference the current package by its package path.
|
|
|
|
|
func addJmpPkgName(x, y int32) int32
|
|
|
|
|
|
|
|
|
|
-- imported/imported_amd64.s --
|
|
|
|
|
TEXT ·AddImpl(SB),$0-16
|
|
|
|
|
MOVL x+0(FP), BX
|
|
|
|
|
MOVL y+4(FP), BP
|
|
|
|
|
ADDL BP, BX
|
|
|
|
|
MOVL BX, ret+8(FP)
|
|
|
|
|
RET
|
|
|
|
|
|
|
|
|
|
TEXT ·addJmpPkgPath(SB),$0-16
|
|
|
|
|
JMP test∕with·many·dots∕main∕imported·AddImpl(SB)
|
|
|
|
|
|
|
|
|
|
TEXT ·addJmpPkgName(SB),$0-16
|
|
|
|
|
JMP imported·AddImpl(SB)
|
|
|
|
|
-- broken/syntax/broken.go --
|
|
|
|
|
package broken
|
|
|
|
|
|
|
|
|
|
func AddImpl
|
|
|
|
|
|
|
|
|
|
-- broken/asm/imported_amd64.s --
|
|
|
|
|
TEXT ·AddImpl(SB),$0-16
|
|
|
|
|
MOVL x+0(FP), BX
|
|
|
|
|
MOVL y+4(FP), BP
|
|
|
|
|
ADDL BP, BX
|
|
|
|
|
MOVL BX, ret+8(FP)
|
|
|
|
|
RET
|
|
|
|
|
-- broken/asm/broken.go --
|
|
|
|
|
package broken
|
|
|
|
|
|
|
|
|
|
func AddImpl(x, y int32) MissingType
|
|
|
|
|
|
|
|
|
|
-- broken/imported_amd64.s --
|
|
|
|
|
TEXT ·AddImpl(SB),$0-16
|
|
|
|
|
MOVL x+0(FP), BX
|
|
|
|
|
MOVL y+4(FP), BP
|
|
|
|
|
ADDL BP, BX
|
|
|
|
|
MOVL BX, ret+8(FP)
|
|
|
|
|
RET
|
|
|
|
|
-- main.stderr --
|
|
|
|
|
3
|
|
|
|
|
3
|
|
|
|
|
1 2
|
|
|
|
|
13 36
|
|
|
|
|
25 70
|
|
|
|
|
7
|
|
|
|
|
-- empty-reverse.txt --
|