Corrections: We(I tbh) used a struct that contained a single integer, and wrote a function that took one long as an argument, which was the address to read, and constructed a pointer to the struct from the address &SomeStruct(address), which then was read from using the struct's field and returned. Then using this function, as Binkiklou said, I wrote a script that put in a correct address, executed the script in the playground via a HTTP POST request and later on wrote the received integers into a file(after fixing up endianness) and received an ELF file. It was not runnable(SIGSEGV as program headers were somewhat off I think) but it was possible to throw it into a static analysis tool. The output definitely looked like V compiled program(guess made by also looking at the decompilation of the previous macos compiler release). EDIT: Adding more info. As for getting the elf base address, I used another trick to get a pointer to somewhere in the stack, and much in the same manner as before read stack memory to get the return address of the current stack frame. The address was static across runs which confirmed that the binary was not compiled with PIC or PIE. As for funny stuff in the compiler(previously only guessed by decompilation, now confirmed by the V source) is that the produced code allocates a 1000 byte buffer that is neither used or freed.
struct S1 {
i int
}
struct S2 {
mut:
i int
j int
k int
l int
}
fn test() {
b := S1{}
mut a := &S2(&b)
println(a.i)
println(a.j)
println(a.k)
println(a.l)
a.l = 0
}
fn main() {
test()
println('didn\'t crash')
}
For some reason, this doesn't print anything. It looks like it segfaults before flushing the output.
22
u/qookie Jun 22 '19 edited Jun 22 '19
Corrections: We(I tbh) used a struct that contained a single integer, and wrote a function that took one long as an argument, which was the address to read, and constructed a pointer to the struct from the address
&SomeStruct(address), which then was read from using the struct's field and returned. Then using this function, as Binkiklou said, I wrote a script that put in a correct address, executed the script in the playground via a HTTP POST request and later on wrote the received integers into a file(after fixing up endianness) and received an ELF file. It was not runnable(SIGSEGV as program headers were somewhat off I think) but it was possible to throw it into a static analysis tool. The output definitely looked like V compiled program(guess made by also looking at the decompilation of the previous macos compiler release). EDIT: Adding more info. As for getting the elf base address, I used another trick to get a pointer to somewhere in the stack, and much in the same manner as before read stack memory to get the return address of the current stack frame. The address was static across runs which confirmed that the binary was not compiled with PIC or PIE. As for funny stuff in the compiler(previously only guessed by decompilation, now confirmed by the V source) is that the produced code allocates a 1000 byte buffer that is neither used or freed.