Skip to content

Help! How to aply the obf to my code. For the sake of learning. #58

@Dagdelo

Description

@Dagdelo

Hi! I'm trying to apply the same obfuscation in the obftest.cpp in this simple Fibonacci Recursive with Memoisation.

#include <iostream>
#include <map>
#include "../../kscope/test/lest.hpp"
#include "../src/obf.h"

#ifdef ITHARE_OBF_TEST_NO_NAMESPACE
using namespace ithare::obf;
using namespace ithare::obf::tls;
#else
#define ITOBF ithare::obf::
#endif

class MyException {
public:
  MyException(std::string msg)
    : message(msg) {
  }
  virtual const char* what() const {
    return message.c_str();
  }

private:
  std::string message;
};

ITHARE_OBF_NOINLINE OBFI6(int) fibonacci(OBFI6(int) num)
{
  static std::map<OBFI6(int), OBFI6(int)> cache{{0, 0}, {1, 1}};

  auto found = cache.find(num);
  if (found != std::end(cache)) {
    // For debugging purposes, to check that the cache is doing something
    std::cout << OBF5S("Found in cache: ") << num << OBF5S(" -> ") << found->second << '\n';
    return found->second;
  }

  OBFI6(int) result = fibonacci(num - 1) + fibonacci(num - 2);
  cache[num] = result;
  return result;
}

int main()
{
  OBFI6(int) num;
  do{
    std::cout << "i: ";
    std::cin >> num;
  }while(num < 3);

  OBFI6(int) res = fibonacci(num);
  std::cout << num << OBF5S("th fibonacci number: ") << res << std::endl;
}

I stoped here... Rly don't know how to finish the code for trying compiling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions