Premiers fichiers

This commit is contained in:
Horde Nicolas 2021-07-03 15:29:13 +02:00
parent 4032f995a9
commit c0a4639643
5 changed files with 173 additions and 0 deletions

46
Dockerfile Normal file
View File

@ -0,0 +1,46 @@
FROM alpine:3.12.0
ENV UNICORN_VER 1.0.3
ENV CAPSTONE_VER 4.0.2
ENV KEYSTONE_VER 0.9.2
RUN echo "http://alpine.42.fr/v3.12/main" > /etc/apk/repositories
RUN echo "http://alpine.42.fr/v3.12/community" >> /etc/apk/repositories
RUN apk --no-cache update
RUN apk --no-cache upgrade
RUN apk --no-cache add bash util-linux coreutils curl make cmake gcc g++ libstdc++ libgcc zlib-dev \
git sed tar wget gzip indent binutils hexdump dos2unix xxd autoconf automake autoconf-archive\
libtool linux-headers ncurses-dev
WORKDIR /usr/src/
RUN git clone git://github.com/gansm/finalcut.git
WORKDIR /usr/src/finalcut
RUN autoreconf --install --force && ./configure --prefix=/usr && make && make install
WORKDIR /usr/src
RUN wget https://github.com/unicorn-engine/unicorn/archive/${UNICORN_VER}.tar.gz && tar -xzf ${UNICORN_VER}.tar.gz
WORKDIR /usr/src/unicorn-${UNICORN_VER}
RUN UNICORN_ARCHS="x86" ./make.sh && UNICORN_ARCHS="x86" ./make.sh install
RUN apk --no-cache add python3-dev
WORKDIR /usr/src
RUN wget https://github.com/keystone-engine/keystone/archive/${KEYSTONE_VER}.tar.gz && tar -xzf ${KEYSTONE_VER}.tar.gz
RUN ls
WORKDIR /usr/src/keystone-${KEYSTONE_VER}
RUN mkdir build
WORKDIR /usr/src/keystone-${KEYSTONE_VER}/build
RUN cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DLLVM_TARGETS_TO_BUILD="X86" -G "Unix Makefiles" ..
RUN make -j8
RUN make install
WORKDIR /usr/src
RUN wget https://github.com/aquynh/capstone/archive/${CAPSTONE_VER}.tar.gz && tar -xzf ${CAPSTONE_VER}.tar.gz
WORKDIR /usr/src/capstone-${CAPSTONE_VER}
RUN CAPSTONE_ARCHS="x86" CAPTONE_X86_REDUCE="yes" ./make.sh && CAPSTONE_ARCHS="x86" CAPTONE_X86_REDUCE="yes" ./make.sh install
RUN adduser -D -H -u 502 utilisateur
RUN adduser -D -H -u 1000 utilisateurs
RUN mkdir /data
WORKDIR /data
ENV LD_LIBRARY_PATH /usr/lib64

21
Makefile Normal file
View File

@ -0,0 +1,21 @@
CC=g++ -O2
LFLAGS=-lfinal -lkeystone -lstdc++ -lm -lcapstone -lunicorn
DOCKER=docker run -it --name maker --rm -v $$(pwd):/data maker
all: dockerfile files run
dockerfile:
docker build . -t maker
files: ./test
test: ./test.cpp
$(DOCKER) $(CC) -o $@ $^ $(LFLAGS)
run:
$(DOCKER) ./test
rerun: delete files run
delete:
rm -rf ./test

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# IA86, The even more pedagogical system
Logiciel pour apprendre à utiliser l'assembleur

BIN
test Executable file

Binary file not shown.

103
test.cpp Normal file
View File

@ -0,0 +1,103 @@
#include <final/final.h>
#include <keystone/keystone.h>
#include <unicorn/unicorn.h>
#include <capstone/capstone.h>
#include <stdio.h>
#define CODE "INC cx; DEC dx"
#define ADDRESS 0x1000
int main (int argc, char* argv[])
{
ks_engine *ks;
ks_err err;
size_t count;
unsigned char *encode;
size_t sizecode;
err = ks_open(KS_ARCH_X86, KS_MODE_16, &ks);
if (err != KS_ERR_OK) {
printf("ERROR: failed on ks_open(), quit\n");
return -1;
}
if (ks_asm(ks, CODE, 0, &encode, &sizecode, &count) != KS_ERR_OK) {
printf("ERROR: ks_asm() failed & count = %lu, error = %u\n",
count, ks_errno(ks));
} else {
size_t i;
printf("%s = ", CODE);
for (i = 0; i < sizecode; i++) {
printf("%02x ", encode[i]);
}
printf("\n");
printf("Compiled: %lu bytes, statements: %lu\n", sizecode, count);
}
ks_free(encode);
ks_close(ks);
csh handle;
cs_insn *insn;
if (cs_open(CS_ARCH_X86, CS_MODE_16, &handle) != CS_ERR_OK)
return -1;
count = cs_disasm(handle, encode, sizecode, ADDRESS, 0, &insn);
if (count > 0) {
size_t j;
for (j = 0; j < count; j++) {
printf("0x%"PRIx64":\t%s\t\t%s\n", insn[j].address, insn[j].mnemonic,
insn[j].op_str);
}
cs_free(insn, count);
} else
printf("ERROR: Failed to disassemble given code!\n");
cs_close(&handle);
uc_engine *uc;
uc_err error;
int r_cx = 0x1234;
int r_dx = 0x7890;
int r_ip = 0x0000;
printf("Emulate i386 code\n");
error = uc_open(UC_ARCH_X86, UC_MODE_16, &uc);
if (error != UC_ERR_OK) {
printf("Failed on uc_open() with error returned: %u\n", error);
return -1;
}
uc_mem_map(uc, ADDRESS, 1 * 1024 * 1024, UC_PROT_ALL);
if (uc_mem_write(uc, ADDRESS, encode, sizecode)) {
printf("Failed to write emulation code to memory, quit!\n");
return -1;
}
uc_reg_write(uc, UC_X86_REG_CX, &r_cx);
uc_reg_write(uc, UC_X86_REG_DX, &r_dx);
uc_reg_read(uc, UC_X86_REG_IP, &r_ip);
printf(">>> CX = 0x%x\n", r_cx);
printf(">>> DX = 0x%x\n", r_dx);
printf(">>> IP = 0x%x\n", r_ip);
error=uc_emu_start(uc, ADDRESS, ADDRESS + sizecode, 0, 0);
if (error) {
printf("Failed on uc_emu_start() with error returned %u: %s\n",
error, uc_strerror(error));
}
printf("Emulation done. Below is the CPU context\n");
uc_reg_read(uc, UC_X86_REG_CX, &r_cx);
uc_reg_read(uc, UC_X86_REG_DX, &r_dx);
uc_reg_read(uc, UC_X86_REG_IP, &r_ip);
printf(">>> CX = 0x%x\n", r_cx);
printf(">>> DX = 0x%x\n", r_dx);
printf(">>> IP = 0x%x\n", r_ip);
uc_close(uc);
finalcut::FApplication app(argc, argv);
finalcut::FDialog dialog(&app);
dialog.setText ("A dialog");
const finalcut::FPoint position{25, 5};
const finalcut::FSize size{30, 10};
dialog.setGeometry (position, size);
finalcut::FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}