Skip to content

Instantly share code, notes, and snippets.

@rsc
Created February 19, 2015 21:15
Show Gist options
  • Select an option

  • Save rsc/d7c930d6543c9b9238ea to your computer and use it in GitHub Desktop.

Select an option

Save rsc/d7c930d6543c9b9238ea to your computer and use it in GitHub Desktop.
go vet -> sam commands
#!/usr/bin/perl
while(<>) {
chomp;
if(/^(\S+):(\d+): [^:]+: (.+) should be (.+)/) {
print "B $1\n";
$old = $3;
$new = $4;
$line = $2;
$old =~ s/([()+])/\\$1/g;
$new =~ s/([()+])/\\$1/g;
print "${line}s/$old/$new/\n";
print "w\n";
next;
}
if(/^(\S+):(\d+): [^:]+: unknown variable (\S+); offset \d+ is ([^+]+)\+/) {
print "B $1\n";
$line = $2;
$old = $3;
$new = $4;
print "${line}s/$old\\+/$new+/\n";
print "w\n";
next;
}
if(/^(\S+):(\d+): [^:]+: wrong argument size (\d+); expected \$\.\.\.-(\d+)$/) {
print "B $1\n";
$line = $2;
$old = $3;
$new = $4;
print "${line}s/-$old/-$new/\n";
print "w\n";
next;
}
if(/^(\S+):(\d+): \[([^\[\]]+)\] [^:]+: RET without writing to (\d+)-byte ret\+(\d+)\(FP\)/) {
print "B $1\n";
$line = $2;
$arch = $3;
$size = $4;
$off = $5;
$mov = "?MOV$size?";
if($size eq "1") {
$mov = "MOVB";
} elsif($size eq "2" && $arch =~ /386|amd64/) {
$mov = "MOVW";
} elsif($size eq "2" && $arch =~ /arm/) {
$mov = "MOVH";
} elsif($size eq "4" && $arch =~ /386|amd64/) {
$mov = "MOVL";
} elsif($size eq "4" && $arch =~ /arm/) {
$mov = "MOVW";
} elsif($size eq "8" && $arch =~ /amd64/) {
$mov = "MOVQ";
}
$reg = "?REG?";
if($arch =~ /386|amd64/) {
$reg = "AX";
} elsif($arch =~ /arm/) {
$reg = "R0";
}
print "${line}s/RET/$mov\t$reg, ret+$off(FP); RET/\n";
print "w\n";
next;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment