usrbin
컴퓨터 일기
usrbin
전체 방문자
오늘
어제

공지사항

  • whoami
  • 분류 전체보기 (127)
    • 깔짝할짝 (61)
    • 잡지식 (30)
    • Network (7)
      • Programming (3)
      • Study (4)
    • Mobile (13)
    • Reversing (5)
      • Win API (2)
      • 분석 (0)
    • Kernel (4)
      • linux (1)
      • Windows (3)
    • Programming (5)

블로그 메뉴

  • 홈
  • 방명록

인기 글

태그

  • xcz.kr
  • x64dbg
  • sql injection
  • libpcap
  • HEVD
  • ftz
  • PWN
  • Packet
  • Scapy
  • Reversing
  • Hive Ransomware
  • pcapng
  • Pwnable
  • BOF
  • HackCTF
  • qt
  • pwnable.kr
  • pwntools
  • monitor mode
  • Android
  • System
  • suninatas
  • network
  • Digital Forensics
  • Network Programming
  • pcap
  • nethunter
  • forensics
  • Follina
  • System Hacking

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
usrbin

컴퓨터 일기

[json-c] android cross-compile
Mobile

[json-c] android cross-compile

2020. 5. 18. 01:02

1. json-c download


https://github.com/json-c/json-c

위 링크에서 Download Zip

cd Download
unzip json-c-master.zip
mv json-c-master json-c
mv json-c ~/android

이전 libpcap과 경로를 맞추기 위해 android 디렉토리로 옮겨준다.

2. cmake cross-compile 준비


mkdir json-c-build
cd json-c-build
vi toolchain.android.cmake
SET(CMAKE_C_COMPILER /root/android/ndk/toolchains/llvm/prebuild/linux-x86_64/bin/clang)
SET(CMAKE_CXX_COMPILER /root/android/ndk/toolchains/llvm/prebuild/linux-x86_64/bin/clang++)
SET(CMAKE_C_FLAGS "-target armv7a-linux-androideabi21")
SET(CMAKE_CXX_FLAGS "-target armv7a-linux-androideabi21")
SET(CMAKE_LD_FLAGS "-target armv7a-linux-androideabi21")

cmake로 크로스컴파일을 하기 위해 파일을 작성한다.

3. json-c compile


cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.android.cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=$PWD/../sysroot-json ../json-c
make
make install

위 명령은 ~/android/json-c-build 디렉토리에서 진행한다.

명령어가 성공적으로 수행되면 상위 디렉토리에 sysroot-json 디렉토리가 생성되고, 그 밑에 lib와 include가 성공적으로 생성된다. 이를 이용하여 안드로이드에서 json-c를 사용할 수 있다.

4. example


mkdir json-test
cd json-test
vi json.c
#include <stdio.h>
#include <string.h>
#include <json-c/json.h>

int main()
{
    enum json_type type;

    char *string = "{\
            \"name\"            : \"Yubin Sim\",\
            \"student\"         : true,\
            \"age\"             : 23,\
            \"heigh\"           : 170,\
            \"interestings\"    : [ \"c\" , \"c++\", \"python\", \"food\" ],\
            \"author-details\"  : { \"name\" : \"Yubin Sim\", \"Number of Posts\" : 10 }\
      }";

    // string type is converted to json object type
    json_object *jobj = json_tokener_parse(string);

    // parse each json object paired with key and val
    json_object_object_foreach(jobj, key, val)
    {
        // get current json object type
        type = json_object_get_type(val);
        printf("type = ");

        switch(type)
        {
            case json_type_null:
                printf("json_type_null\n");
                break;
            case json_type_boolean:
                printf("json_type_boolean\n");
                printf("key = %-15s : value = %s\n", key, json_object_get_boolean(val) ? "true" : "false");
                break;
            case json_type_double:
                printf("json_type_double\n");
                printf("key = %-15s : value = %lf\n", key, json_object_get_double(val));
                break;
            case json_type_int:
                printf("json_type_int\n");
                printf("key = %-15s : value = %d\n", key, json_object_get_int(val));
                break;
            case json_type_object:
                printf("json_type_object\n");
                printf("key = %-15s : value = \n", key);
                break;
            case json_type_array:
                printf("json_type_array\n");
                printf("key = %-15s : value = \n", key);
                break;
            case json_type_string:
                printf("json_type_string\n");
                printf("key = %-15s : value = %s\n", key, json_object_get_string(val));
                break;
        }
    }

    printf("\n");

    return 0;
}
vi makefile
TARGET=json
OBJS = json.o
CFLAGS+=-I../android/sysroot-json/include
LDFLAGS+=-L../android/sysroot-json/lib
LDFLAGS+=-pie
LIBS+=-ljson-c

all : $(TARGET)

$(TARGET) : $(OBJS)
    $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
json.o : json.c

clean:
    rm -f $(TARGET)
    rm -f *.o
make
adb push json /data/local/tmp
adb shell
su
cd /data/lcoal/tmp
./json

 

저작자표시 비영리 변경금지 (새창열림)

'Mobile' 카테고리의 다른 글

[Nexmon] nexus5 monitor mode(bcm4339)  (0) 2020.05.11
Android screen mirroring in Kali linux  (0) 2020.04.18
libpcap Android build(Newest version)  (0) 2020.04.03
[안드로이드 모바일 앱 모의해킹] 환경설정(drozer)  (0) 2020.03.19
libpcap Android build(arm cross compile)  (0) 2020.03.13
    usrbin
    usrbin
    컴퓨터 할거야

    티스토리툴바