2023-10-23

C에서 C++ 함수 호출하는법

class MyClass {
public:
    void myMethod() {
        // C++ 메소드 내용
    }
}

extern "C" {
    void callMyMethod() {
        MyClass obj;
        obj.myMethod();
    }
}

// 외부에서 선언된 C++ 함수를 호출
extern void callMyMethod();

int main() {
    callMyMethod(); // C 함수를 호출하여 C++ 메소드 실행
    return 0;
}


2023-10-19

iso8601 time string

#include <chrono>

int main() {
  // 현재 시간을 가져옵니다.
  auto now = std::chrono::system_clock::now();

  // ISO 8601 포맷으로 시간을 만듭니다.
  std::string iso8601Time = std::to_string(now);

  // 시간을 출력합니다.
  std::cout << iso8601Time << std::endl;

  return 0;
}

2023-10-18

cmake binary file add.

cmake_minimum_required(VERSION 3.21)

project(example)

add_executable(main main.c)

add_executable(firmware firmware.bin)

target_link_libraries(main firmware)

# 대상의 크기를 바이트로 가져오는 함수 정의
function(get_size_of_data target)
  get_target_property(size ${target} SIZE)
  return(${size})
endfunction()

# 'firmware' 대상의 크기를 가져오고 'CMAKE_SIZE_OF_DATA' 변수에 저장
get_size_of_data(firmware)
set(CMAKE_SIZE_OF_DATA ${size})

# 'FIRMWARE_SIZE'를 킬로바이트(KB)로 변환
math(EXPR FIRMWARE_SIZE "${CMAKE_SIZE_OF_DATA} / 1024")

message("FIRMWARE_SIZE in KB: ${FIRMWARE_SIZE}")


사용법은....................................................................................
#include <stdio.h>

int main() {
  // 펌웨어 데이터를 가져옵니다.
  void *data = ((void(*)())firmware)();

  // 펌웨어 크기를 가져옵니다.
  int size = FIRMWARE_SIZE;

  // 펌웨어 데이터를 처리합니다.
  // ...

  return 0;
}

암호화 + base64 하고 쉘스크립트.

 #!/bin/bash # IV와 UserKey를 설정합니다 (아스키 문자열을 그대로 사용). IV="0123456789abcdef"  UserKey="0123456789abcdef" # IV와 UserKey를 16...