SkyLine
  • SkyLine | Introduction
    • Module Overview
    • SkyLine's Development
    • Skyline's Reason
    • SkyLine Syntax
    • SkyLine Concepts
      • Concepts | Modes
  • SkyLine | Technologies
    • Module Overview
    • REPL
      • REPL - Basic usage
      • REPL - Console Design
      • REPL - Commands
    • SLC
      • SLC - What is it
      • SLC - Use cases
      • SLC - Lexical Analysis
      • SLC - Intro To Development
      • SLC - Error System
  • SkyLine | Theory
    • Module Overview
    • Theory | Type Systems
      • Objects | Strings
      • Objects | Integers & Floats
  • SkyLine | Development
    • Module Overview
    • Development | Hello Integers?
  • SL | Hybrid Development
    • Module Overview
    • Hybrid Projects | Advancing
    • Hybrid Projects | Wrapping
    • Hybrid Projects | Using SLC
  • SkyLine | For Abusers
    • SL Abuser | Security Research
    • SL Abuser | Module Overview
    • SL Abuser | Abusing Helps
  • SkyLine Experiments
    • Introduction To Module
      • Caster - IoT Manipulation With SkyLine
        • Caster In Real World Scenarios
          • Cracking The Grounds
        • Caster: Setting Up
        • Caster - Running Caster
        • Caster - Dev Manipulation
          • Caster - Console
          • Caster - Apple Devs
          • Caster - Amazon Devs
          • Caster - Google Devs
          • Caster - Roku Devs
      • SkyNeXt - Hacking The Skies
      • SkyLine - PwnLib
Powered by GitBook
On this page
  1. SL | Hybrid Development

Hybrid Projects | Wrapping

Before we get started into the actual programming and using the engine to understand project development, we need to actually understand our goal. So all we need to do right now is ensure we can build a wrapper that can call C++ code within C code and be able to execute it in Go by calling the SkyLine programming language to load the compiled plugin program.

The idea of having wrappers is to be able to create large projects and easily load them into SkyLine and call the function one after another with them directly. The best part about it will be the factor that your code might not even have to output anything but only return data

Building the C++ Wrapper

In order to build the C code we need to actually build the C++ wrapper which will work like so.

cpp_wrapper.hpp

#ifndef CPP_WRAPPER_H
#define CPP_WRAPPER_H
#ifdef __cplusplus
extern "C" {
#endif
int callCPPFunction();
#ifdef __cplusplus
}
#endif
#endif  // CPP_WRAPPER_H

This may seem like ugly code and horrible for management but right now it is just fine!

Now we have to build our file cpp_wrapper.cpp

#include <iostream>

extern "C" {
    // C interface functions
    int callCPPFunction();
}
// Example
int cppFunction() {
    return 20 - 100;
}

int callCPPFunction() {
    return cppFunction();
}

Our final step for programming will need to actually now create a .go file that will import the C code and call it using CGO.

package main

import (
	SkyEnv "SkyLine/Modules/Backend/SkyEnvironment"
)

//#include "cpp_wrapper.h"
import "C"

func GenerateCall(*SkyEnv.SkyLineEnvironment, ...SkyEnv.SL_Object) SkyEnv.SL_Object {
	res := C.callCPPFunction()
	return &SkyEnv.SL_Integer{Value: int(res)}
}

Note that we are actually calling the SkyEnvironment or SkyLine Virtual Environment backend code and module file in order to create a function. We do this because the FFI requires the desired function type and exactly what it needs to execute before it can be called and it also needs to return an object when called.

Now we can build a simple makefile called Makefile

all:
    g++ -c -fPIC cpp_wrapper.cpp -o cpp_wrapper.o
    g++ -shared cpp_wrapper.o -o cpp_wrapper.so
    go build --buildmode=plugin -o project

Finally we can open the SkyLine REPL and call the function or in a raw script open the code.

And now we have sucessfully written a project that not only used C/C++ but also used Go and could be easily programmed within SkyLine. Loading Plugins may also be easier in the future but for now they will remain like this. It is also important to note that if the function is thrown on a thread then the program and thread will continue to run in the background, this is because before even printing the variable, the backend of SkyLine loads and executes the foreign function interface which in this case would be a function rather than a variable.

PreviousHybrid Projects | AdvancingNextHybrid Projects | Using SLC

Last updated 1 year ago

Page cover image