Compilation statique !

This commit is contained in:
Horde Nicolas 2021-07-16 13:14:48 +02:00
parent 6d87ea0b61
commit 62678bdd67
5 changed files with 94 additions and 100 deletions

View File

@ -8,16 +8,15 @@ RUN echo "http://alpine.42.fr/v3.13/main" > /etc/apk/repositories
RUN echo "http://alpine.42.fr/v3.13/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
RUN apk --no-cache add bash util-linux coreutils curl make cmake gcc g++ libstdc++ libgcc \
git sed tar wget gzip indent binutils autoconf automake autoconf-archive\
libtool linux-headers ncurses-dev python3-dev
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
@ -27,6 +26,8 @@ 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
RUN MAKE_INSTALL_PREFIX=/usr CMAKE_BUILD_TYPE=Release BUILD_SHARED_LIBS=ON LLVM_TARGETS_TO_BUILD="X86" ../make-lib.sh
RUN cp /usr/src/keystone-0.9.2/build/llvm/lib64/libkeystone.a /usr/lib64/
WORKDIR /usr/src
RUN wget https://github.com/aquynh/capstone/archive/${CAPSTONE_VER}.tar.gz && tar -xzf ${CAPSTONE_VER}.tar.gz
@ -40,12 +41,17 @@ RUN mkdir build
WORKDIR /usr/src/struct_mapping/build
RUN cmake .. && cmake --build . && cmake --install .
WORKDIR /usr/src/
WORKDIR /usr/src
RUN git clone https://github.com/dahut87/finalcut.git
WORKDIR /usr/src/finalcut
RUN autoreconf --install --force && ./configure --prefix=/usr && make && make install
RUN apk --no-cache add zlib-dev
WORKDIR /usr/src
RUN git clone https://github.com/madler/zlib.git
WORKDIR /usr/src/zlib
RUN ./configure && make && make install prefix=/usr/
RUN apk --no-cache add ncurses-static
RUN adduser -D -H -u 502 utilisateur
RUN adduser -D -H -u 1000 utilisateurs

View File

@ -1,10 +1,10 @@
CC=g++ -O2
LFLAGS=-lfinal -lkeystone -lstdc++ -lm -lcapstone -lunicorn -lz
CC=g++ -O2 -static
LFLAGS=-lfinal -lkeystone -lstdc++ -lm -lcapstone -lunicorn -lz -lncursesw
OPTIONS=-std=c++17
DOCKER=docker run --name maker --rm -v $$(pwd):/data maker
START=./start.sh
all: dockerfile files copy run
all: dockerfile files run
clean: dockerclean
@ -37,32 +37,3 @@ stop:
delete:
rm -rf ./ia86
copy: libcapstone.so.4 libunicorn.so.1 libfinal.so.0.7.2 libkeystone.so.0 libc.musl-x86_64.so.1 libstdc++.so.6.0.28 libz.so.1.2.11 libgcc_s.so.1
libcapstone.so.4:
${DOCKER} cp /usr/lib/libcapstone.so.4 /data/libcapstone.so.4
libunicorn.so.1:
${DOCKER} cp /usr/lib/libunicorn.so.1 /data/libunicorn.so.1
libfinal.so.0.7.2:
${DOCKER} cp /usr/lib/libfinal.so.0.7.2 /data/libfinal.so.0.7.2
ln -s ./libfinal.so.0.7.2 ./libfinal.so.0
libkeystone.so.0:
${DOCKER} cp /usr/lib64/libkeystone.so.0 /data/libkeystone.so.0
libc.musl-x86_64.so.1:
${DOCKER} cp /lib/libc.musl-x86_64.so.1 /data/libc.musl-x86_64.so.1
libz.so.1.2.11:
${DOCKER} cp /lib/libz.so.1.2.11 /data/libz.so.1.2.11
ln -s ./libz.so.1.2.11 ./libz.so.1
libstdc++.so.6.0.28:
${DOCKER} cp /usr/lib/libstdc++.so.6.0.28 /data/libstdc++.so.6.0.28
ln -s ./libstdc++.so.6.0.28 ./libstdc++.so.6
libgcc_s.so.1:
${DOCKER} cp /usr/lib/libgcc_s.so.1 /data/libgcc_s.so.1

118
ia86.cpp
View File

@ -405,17 +405,19 @@ std::vector<Code> Assembler::MultiAssemble(std::string source,uint32_t address)
std::vector<Code> mcode;
std::istringstream stream(source);
std::string line;
std::regex regex("^ *.org 0x([0-F]+)$");
std::regex regex_org("^ *.org 0x([0-F]+)$");
std::regex regex_name("^ *.title ([a-zA-Z0-9_]+)$");
Code *code=new Code;
bool begin=true;
int org=address;
std::string name="/";
code->address=org;
while (std::getline(stream, line))
{
if (line.find(".org") != std::string::npos)
{
std::smatch match;
if(std::regex_search(line, match, regex))
if(std::regex_search(line, match, regex_org))
{
org=std::stoul(match.str(1), nullptr, 16);
}
@ -424,6 +426,16 @@ std::vector<Code> Assembler::MultiAssemble(std::string source,uint32_t address)
mcode.push_back(*code);
code=new Code;
code->address=org;
code->name=name;
name="/";
}
}
else if (line.find(".title") != std::string::npos)
{
std::smatch match;
if(std::regex_search(line, match, regex_name))
{
name=match.str(1);
}
}
else
@ -734,6 +746,30 @@ std::string VMEngine::getRam(int segment, int address,int lines, int linesize)
return result;
}
std::vector<std::array<std::string, 7>> VMEngine::getCode()
{
int line=0;
std::vector<std::array<std::string, 7>> result;
for(Code code: mcode)
{
std::string *linestr = new std::string(to_string(line++));
std::string *name = new std::string(code.name);
std::string *address = new std::string(intToHexString(code.address,8));
std::string *size = new std::string(to_string(code.size));
std::string *srcsize = new std::string(to_string(code.src.size()));
std::string *assembled = new std::string;
if (code.assembled)
*assembled="X";
std::string *loaded = new std::string;
if (code.loaded)
*loaded="X";
std::array<std::string, 7> *array = new std::array<std::string, 7>{*linestr,*name,*address,*size,*srcsize,*assembled,*loaded};
result.push_back(*array);
}
return result;
}
std::vector<std::array<std::string, 4>> VMEngine::getInstr(int segment, int address,int size)
{
uint32_t realaddress=segment*16+address;
@ -1593,21 +1629,41 @@ void Menu::showInstr()
{
if (vm.isInitialized())
{
debug.set(vm.getInstr(vm.getCS(),vm.getEIP(),debug.getHeight()-3));
debug.setmark(vm.getLine());
debug.setmultimark(vm.getBreapoints());
if (Ds_000.isChecked())
mem.set(vm.getRam(vm.getDS(), 0x000000000, mem.getHeight(),mem.getWidth()));
else if (Ds_esi.isChecked())
mem.set(vm.getRam(vm.getDS(), vm.getESI(), mem.getHeight(),mem.getWidth()));
else if (Es_edi.isChecked())
mem.set(vm.getRam(vm.getES(), vm.getEDI(), mem.getHeight(),mem.getWidth()));
else if (Cs_eip.isChecked())
mem.set(vm.getRam(vm.getCS(), vm.getEIP(), mem.getHeight(),mem.getWidth()));
else if (Ss_esp.isChecked())
mem.set(vm.getRam(vm.getSS(), vm.getESP(), mem.getHeight(),mem.getWidth()));
else if (Ss_FFF.isChecked())
mem.set(vm.getRam(vm.getSS(), 0x0000FF20, mem.getHeight(),mem.getWidth()));
try
{
debug.set(vm.getInstr(vm.getCS(),vm.getEIP(),debug.getHeight()-3));
debug.setmark(vm.getLine());
debug.setmultimark(vm.getBreapoints());
regs.set(vm.getRegs());
flags.set(vm.getFlags());
stack.set(vm.getStack());
if (Ds_000.isChecked())
mem.set(vm.getRam(vm.getDS(), 0x000000000, mem.getHeight(),mem.getWidth()));
else if (Ds_esi.isChecked())
mem.set(vm.getRam(vm.getDS(), vm.getESI(), mem.getHeight(),mem.getWidth()));
else if (Es_edi.isChecked())
mem.set(vm.getRam(vm.getES(), vm.getEDI(), mem.getHeight(),mem.getWidth()));
else if (Cs_eip.isChecked())
mem.set(vm.getRam(vm.getCS(), vm.getEIP(), mem.getHeight(),mem.getWidth()));
else if (Ss_esp.isChecked())
mem.set(vm.getRam(vm.getSS(), vm.getESP(), mem.getHeight(),mem.getWidth()));
else if (Ss_FFF.isChecked())
mem.set(vm.getRam(vm.getSS(), 0x0000FF20, mem.getHeight(),mem.getWidth()));
}
catch(exception const& e)
{
tolog(e.what());
vm.Halt();
vm.Unconfigure();
}
}
else
{
regs.set("En attente d'initialisation...");
flags.set("Attente...");
stack.set("Attente...");
mem.set("En attente d'initialisation...");
screen.set("En attente d'initialisation...");
}
}
catch(exception const& e)
@ -1619,29 +1675,6 @@ void Menu::showInstr()
void Menu::refresh()
{
if (!vm.isInitialized())
{
regs.set("En attente d'initialisation...");
flags.set("Attente...");
stack.set("Attente...");
mem.set("En attente d'initialisation...");
screen.set("En attente d'initialisation...");
}
else
{
try
{
regs.set(vm.getRegs());
flags.set(vm.getFlags());
stack.set(vm.getStack());
}
catch(exception const& e)
{
tolog(e.what());
vm.Halt();
vm.Unconfigure();
}
}
if (!vm.isExecuted())
{
finalcut::FApplication::setDarkTheme();
@ -1650,10 +1683,9 @@ void Menu::refresh()
{
finalcut::FApplication::setDefaultTheme();
}
auto root_widget = getRootWidget();
/*auto root_widget = getRootWidget();
root_widget->resetColors();
root_widget->redraw();
root_widget->redraw();*/
}
void Menu::exec()

2
ia86.h
View File

@ -132,6 +132,7 @@ struct Code
{
uint32_t address;
size_t size;
std::string name;
uint8_t *content;
bool assembled;
bool loaded;
@ -314,6 +315,7 @@ class VMEngine
std::string getRegs();
std::string getStack();
std::vector<std::array<std::string, 4>> getInstr(int segment, int address,int size);
std::vector<std::array<std::string, 7>> getCode();
void SetMem(Code *code);
void SetRegs(State *init);
std::string getRam(int segment, int address,int lines, int linesize);

17
start
View File

@ -1,17 +0,0 @@
#!/bin/bash
X=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1)
Y=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2)
if [ ${X} -ge 1920 ]; then
SIZE=11
elif [ ${X} -ge 1680 ]; then
SIZE=10
elif [ ${X} -ge 1440 ]; then
SIZE=9
elif [ ${X} -ge 1368 ]; then
SIZE=8
elif [ ${X} -ge 1280 ]; then
SIZE=7
else
SIZE=6
fi
xterm -fullscreen -fa monaco -fs ${SIZE} -bg black -fg green -e bash -c "docker run -it -e COLUMNS=213 -e LINES=58 --name maker --rm -v $(pwd):/data maker ./ia86"