Skip to content

Instantly share code, notes, and snippets.

@mvanotti

mvanotti/foo.c Secret

Created October 10, 2014 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvanotti/7fcbe9d83758e532d197 to your computer and use it in GitHub Desktop.
Save mvanotti/7fcbe9d83758e532d197 to your computer and use it in GitHub Desktop.
When running foo.go on windows 8 64 bits it panics.
#include "foo.h"
void bar(process_handle_t handle, bool *b, memory_region_t *region) {
region->start_address = 100;
*b = true;
}
void open_process(process_handle_t *handle) {
*handle = 0x201;
}
package main
// #include "foo.h"
// #cgo CFLAGS: -std=c99
import "C"
import "runtime"
import "fmt"
type process struct {
handle C.process_handle_t
pid int
}
func main() {
var b int = 3
var p process
C.open_process(&(p.handle))
foo(p, b)
}
func foo(p process, a int) {
fmt.Println(a)
var isAvailable C.bool
var region C.memory_region_t
runtime.GC()
//fmt.Println(isAvailable, region)
C.bar(p.handle, &isAvailable, &region)
}
#ifndef __FOO__
#define __FOO__
#include <windows.h>
#include <stdbool.h>
#include <stdlib.h>
typedef unsigned long long memory_address_t;
typedef HANDLE process_handle_t;
typedef struct {
memory_address_t start_address;
size_t length;
} memory_region_t;
void bar(process_handle_t handle, bool *b, memory_region_t *region);
void open_process(process_handle_t *handle);
#endif // __FOO__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment