Reprise du code car erreur de segmentation régulières
This commit is contained in:
parent
bbb96f6381
commit
0f4754939f
10
Makefile
10
Makefile
|
@ -8,22 +8,28 @@ all: dockerfile files run
|
||||||
|
|
||||||
clean: dockerclean
|
clean: dockerclean
|
||||||
|
|
||||||
|
clear:
|
||||||
|
clear
|
||||||
|
|
||||||
dockerclean:
|
dockerclean:
|
||||||
(docker rmi $$(docker images | grep "^<none>" | awk '{print $$3}') --force;true)
|
(docker rmi $$(docker images | grep "^<none>" | awk '{print $$3}') --force;true)
|
||||||
|
(docker rmi maker;true)
|
||||||
docker image ls
|
docker image ls
|
||||||
|
|
||||||
dockerfile:
|
dockerfile:
|
||||||
docker build . -t maker
|
docker build . -t maker
|
||||||
|
|
||||||
|
dockerfile_force: dockerclean dockerfile
|
||||||
|
|
||||||
files: ./ia86
|
files: ./ia86
|
||||||
|
|
||||||
ia86: ./ia86.cpp
|
ia86: ./ia86.cpp
|
||||||
$(DOCKER) $(CC) $(OPTIONS) -o $@ $^ $(LFLAGS)
|
$(DOCKER) $(CC) $(OPTIONS) -o $@ $^ $(LFLAGS)
|
||||||
|
|
||||||
run:
|
rerun:
|
||||||
$(XTERM) '$(DOCKER) bash -c "sleep 0.4;./ia86"'
|
$(XTERM) '$(DOCKER) bash -c "sleep 0.4;./ia86"'
|
||||||
|
|
||||||
rerun: delete files run
|
run: clear delete files rerun
|
||||||
|
|
||||||
stop:
|
stop:
|
||||||
docker stop maker
|
docker stop maker
|
||||||
|
|
348
ia86.cpp
348
ia86.cpp
|
@ -63,20 +63,8 @@ void mapping()
|
||||||
struct_mapping::reg(&i386_regs::eip, "eip");
|
struct_mapping::reg(&i386_regs::eip, "eip");
|
||||||
}
|
}
|
||||||
|
|
||||||
Scenario readscenario(std::string filename) {
|
|
||||||
|
|
||||||
std::ifstream inFile;
|
|
||||||
inFile.open(filename);
|
|
||||||
std::stringstream strStream;
|
|
||||||
strStream << inFile.rdbuf();
|
|
||||||
std::string json=strStream.str();
|
|
||||||
std::istringstream json_data(json);
|
|
||||||
Scenario scenar;
|
|
||||||
struct_mapping::map_json_to_struct(scenar, json_data);
|
|
||||||
return scenar;
|
|
||||||
}
|
|
||||||
|
|
||||||
Scenario scenario;
|
Scenario scenario;
|
||||||
|
Level level;
|
||||||
Unasm unasm;
|
Unasm unasm;
|
||||||
int marker;
|
int marker;
|
||||||
bool debug=true;
|
bool debug=true;
|
||||||
|
@ -110,36 +98,23 @@ ScenarioWindow::ScenarioWindow (finalcut::FWidget* parent)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScenarioWindow::load(std::string file)
|
|
||||||
{
|
|
||||||
scenario=readscenario(file);
|
|
||||||
if (scenario.levels.size()>0)
|
|
||||||
{
|
|
||||||
std::vector<std::string> items;
|
|
||||||
for(size_t i=0; i < scenario.levels.size(); i++)
|
|
||||||
{
|
|
||||||
//((Menu*)this->getParent())->log.append(".");
|
|
||||||
items.clear();
|
|
||||||
items.push_back(to_string(i));
|
|
||||||
items.push_back(scenario.levels[i].title);
|
|
||||||
const finalcut::FStringList line (items.begin(), items.end());
|
|
||||||
listview.insert (line);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScenarioWindow::click()
|
void ScenarioWindow::click()
|
||||||
{
|
{
|
||||||
selected=listview.getindex();
|
((Menu*)this->getParent())->loadLevel(listview.getindex());
|
||||||
((Menu*)this->getParent())->loadLevel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScenarioWindow::getselected()
|
void ScenarioWindow::Load(std::vector<Level> levels)
|
||||||
{
|
{
|
||||||
return selected;
|
vector<std::string> items;
|
||||||
|
for(size_t i=0; i < levels.size(); i++)
|
||||||
|
{
|
||||||
|
//((Menu*)this->getParent())->tolog(".");
|
||||||
|
items.clear();
|
||||||
|
items.push_back(to_string(i));
|
||||||
|
items.push_back(levels[i].title);
|
||||||
|
const finalcut::FStringList line (items.begin(), items.end());
|
||||||
|
listview.insert(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScenarioWindow::initLayout()
|
void ScenarioWindow::initLayout()
|
||||||
|
@ -309,7 +284,6 @@ void TextWindow::clear()
|
||||||
scrolltext.clear();
|
scrolltext.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TextWindow::initLayout()
|
void TextWindow::initLayout()
|
||||||
{
|
{
|
||||||
scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
|
scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
|
||||||
|
@ -333,11 +307,11 @@ Desassembler::Desassembler(Menu *widget) : widget(widget)
|
||||||
err = cs_open(CS_ARCH_X86, CS_MODE_16, &handle);
|
err = cs_open(CS_ARCH_X86, CS_MODE_16, &handle);
|
||||||
if (err != CS_ERR_OK)
|
if (err != CS_ERR_OK)
|
||||||
throw Error("Désassembleur - initialisation....................[ERREUR]");
|
throw Error("Désassembleur - initialisation....................[ERREUR]");
|
||||||
widget->log.append("Désassembleur - initialisation....................[ OK ]");
|
widget->tolog("Désassembleur - initialisation....................[ OK ]");
|
||||||
}
|
}
|
||||||
catch(exception const& e)
|
catch(exception const& e)
|
||||||
{
|
{
|
||||||
widget->log.append(e.what());
|
widget->tolog(e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +325,7 @@ void Desassembler::Desassemble(uint8_t *content, uint32_t address,uint32_t size,
|
||||||
throw Error("Désassembleur - désassemblage.....................[ERREUR]");
|
throw Error("Désassembleur - désassemblage.....................[ERREUR]");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (debug) widget->log.append("Désassemblage - désassemblage.....................[ "+to_string(srcsize)+"l ]");
|
if (debug) widget->tolog("Désassemblage - désassemblage.....................[ "+to_string(srcsize)+"l ]");
|
||||||
unasm->src.clear();
|
unasm->src.clear();
|
||||||
unasm->pos.clear();
|
unasm->pos.clear();
|
||||||
for (size_t j = 0; j < srcsize; j++)
|
for (size_t j = 0; j < srcsize; j++)
|
||||||
|
@ -373,7 +347,7 @@ void Desassembler::Desassemble(uint8_t *content, uint32_t address,uint32_t size,
|
||||||
{
|
{
|
||||||
unasm->src.clear();
|
unasm->src.clear();
|
||||||
unasm->pos.clear();
|
unasm->pos.clear();
|
||||||
widget->log.append(e.what());
|
widget->tolog(e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -389,11 +363,11 @@ Assembler::Assembler(Menu *widget) : widget(widget)
|
||||||
err = ks_open(KS_ARCH_X86, KS_MODE_16, &ks);
|
err = ks_open(KS_ARCH_X86, KS_MODE_16, &ks);
|
||||||
if (err != KS_ERR_OK)
|
if (err != KS_ERR_OK)
|
||||||
throw Error("Assembleur - initialisation.......................[ERREUR]");
|
throw Error("Assembleur - initialisation.......................[ERREUR]");
|
||||||
widget->log.append("Assembleur - initialisation.......................[ OK ]");
|
widget->tolog("Assembleur - initialisation.......................[ OK ]");
|
||||||
}
|
}
|
||||||
catch(exception const& e)
|
catch(exception const& e)
|
||||||
{
|
{
|
||||||
widget->log.append(e.what());
|
widget->tolog(e.what());
|
||||||
}
|
}
|
||||||
ks_option(ks, KS_OPT_SYNTAX, KS_OPT_SYNTAX_NASM);
|
ks_option(ks, KS_OPT_SYNTAX, KS_OPT_SYNTAX_NASM);
|
||||||
}
|
}
|
||||||
|
@ -436,13 +410,13 @@ std::vector<Code> Assembler::MultiAssemble(std::string source,uint32_t address)
|
||||||
mcode.push_back(*code);
|
mcode.push_back(*code);
|
||||||
for(size_t i=0;i<mcode.size();i++)
|
for(size_t i=0;i<mcode.size();i++)
|
||||||
this->Assemble(&mcode[i]);
|
this->Assemble(&mcode[i]);
|
||||||
widget->log.append("Assembleur - assemblage...........................[ OK ]");
|
widget->tolog("Assembleur - assemblage...........................[ OK ]");
|
||||||
return mcode;
|
return mcode;
|
||||||
}
|
}
|
||||||
catch(exception const& e)
|
catch(exception const& e)
|
||||||
{
|
{
|
||||||
std::vector<Code> mcode;
|
std::vector<Code> mcode;
|
||||||
widget->log.append(e.what());
|
widget->tolog(e.what());
|
||||||
return mcode;
|
return mcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,11 +611,11 @@ void VMEngine::Init()
|
||||||
err = uc_open(UC_ARCH_X86, UC_MODE_16, &uc);
|
err = uc_open(UC_ARCH_X86, UC_MODE_16, &uc);
|
||||||
if (err != UC_ERR_OK)
|
if (err != UC_ERR_OK)
|
||||||
throw Error("VM IA86 - initilisation...........................[ERREUR]");
|
throw Error("VM IA86 - initilisation...........................[ERREUR]");
|
||||||
widget->log.append("VM IA86 - initilisation...........................[ OK ]");
|
widget->tolog("VM IA86 - initilisation...........................[ OK ]");
|
||||||
}
|
}
|
||||||
catch(exception const& e)
|
catch(exception const& e)
|
||||||
{
|
{
|
||||||
widget->log.append(e.what());
|
widget->tolog(e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,7 +637,7 @@ void VMEngine::Close()
|
||||||
void VMEngine::Halt()
|
void VMEngine::Halt()
|
||||||
{
|
{
|
||||||
if (executed)
|
if (executed)
|
||||||
widget->log.append("VM IA86 - arret...................................[ INFO ]");
|
widget->tolog("VM IA86 - arret...................................[ INFO ]");
|
||||||
executed=false;
|
executed=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -671,7 +645,7 @@ void VMEngine::Unconfigure()
|
||||||
{
|
{
|
||||||
this->Halt();
|
this->Halt();
|
||||||
if (initialized)
|
if (initialized)
|
||||||
widget->log.append("VM IA86 - déconfiguration.........................[ INFO ]");
|
widget->tolog("VM IA86 - déconfiguration.........................[ INFO ]");
|
||||||
initialized=false;
|
initialized=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,6 +730,38 @@ int VMEngine::getLine()
|
||||||
return marker;
|
return marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMEngine::clearbreakpoints()
|
||||||
|
{
|
||||||
|
breakpoints.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VMEngine::addbreakpoint(int address)
|
||||||
|
{
|
||||||
|
for(int item: breakpoints)
|
||||||
|
if (item==address) return;
|
||||||
|
breakpoints.push_back(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VMEngine::removebreakpoint(int address)
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
for(int item: breakpoints)
|
||||||
|
if (item==address)
|
||||||
|
{
|
||||||
|
breakpoints.erase(breakpoints.begin()+i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int> VMEngine::getBreapoints()
|
||||||
|
{
|
||||||
|
std::vector<int> list;
|
||||||
|
for(int item: breakpoints)
|
||||||
|
widget->tolog(to_string(item));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Hook
|
// Hook
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -824,10 +830,11 @@ void VMEngine::Configure(State *init, std::string code)
|
||||||
return;
|
return;
|
||||||
Close();
|
Close();
|
||||||
Init();
|
Init();
|
||||||
bufferaddress=-666;
|
bufferaddress=-1;
|
||||||
initialized=false;
|
initialized=false;
|
||||||
executed=false;
|
executed=false;
|
||||||
//widget->log.append("Mappage de la mémoire virtuelle");
|
hadcall=0x0;
|
||||||
|
//widget->tolog("Mappage de la mémoire virtuelle");
|
||||||
uc_mem_map(uc, 0, 1 * 1024 * 1024, UC_PROT_ALL);
|
uc_mem_map(uc, 0, 1 * 1024 * 1024, UC_PROT_ALL);
|
||||||
uc_hook_add(uc, &uh_call, UC_HOOK_INSN, (void*)hook_call, (void*)widget, 1, 0, UC_X86_INS_SYSCALL);
|
uc_hook_add(uc, &uh_call, UC_HOOK_INSN, (void*)hook_call, (void*)widget, 1, 0, UC_X86_INS_SYSCALL);
|
||||||
uc_hook_add(uc, &uh_mem, UC_HOOK_MEM_WRITE, (void*)hook_memory_write, (void*)widget, 1, 0);
|
uc_hook_add(uc, &uh_mem, UC_HOOK_MEM_WRITE, (void*)hook_memory_write, (void*)widget, 1, 0);
|
||||||
|
@ -839,7 +846,7 @@ void VMEngine::Configure(State *init, std::string code)
|
||||||
SetMem(&mcode[i]);
|
SetMem(&mcode[i]);
|
||||||
else
|
else
|
||||||
throw Error("VM IA86 - code non assemblé...................[ERREUR]");
|
throw Error("VM IA86 - code non assemblé...................[ERREUR]");
|
||||||
if (debug) widget->log.append("Section N°"+std::to_string(i)+" : "+intToHexString(mcode[i].address,8)+" -> "+to_string(mcode[i].size)+" octets");
|
if (debug) widget->tolog("Section N°"+std::to_string(i)+" : "+intToHexString(mcode[i].address,8)+" -> "+to_string(mcode[i].size)+" octets");
|
||||||
}
|
}
|
||||||
status=verify();
|
status=verify();
|
||||||
if (status==0)
|
if (status==0)
|
||||||
|
@ -852,7 +859,7 @@ void VMEngine::Configure(State *init, std::string code)
|
||||||
}
|
}
|
||||||
catch(exception const& e)
|
catch(exception const& e)
|
||||||
{
|
{
|
||||||
widget->log.append(e.what());
|
widget->tolog(e.what());
|
||||||
initialized=false;
|
initialized=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1022,7 +1029,7 @@ void VMEngine::SetRegs(State *init)
|
||||||
out << " AX=" << std::uppercase << std::setfill('0') << std::setw(4) << std::hex << init->dump.regs.ax << " ";
|
out << " AX=" << std::uppercase << std::setfill('0') << std::setw(4) << std::hex << init->dump.regs.ax << " ";
|
||||||
else
|
else
|
||||||
out << "EAX=" << std::uppercase << std::setfill('0') << std::setw(8) << std::hex << init->dump.regs.eax << " ";
|
out << "EAX=" << std::uppercase << std::setfill('0') << std::setw(8) << std::hex << init->dump.regs.eax << " ";
|
||||||
widget->log.append(out.str());
|
widget->tolog(out.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMEngine::Run(bool astep, bool acall, uint64_t timeout)
|
void VMEngine::Run(bool astep, bool acall, uint64_t timeout)
|
||||||
|
@ -1046,7 +1053,7 @@ void VMEngine::Run(bool astep, bool acall, uint64_t timeout)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!executed)
|
if (!executed)
|
||||||
widget->log.append("VM IA86 - execution...............................[ INFO ]");
|
widget->tolog("VM IA86 - execution...............................[ INFO ]");
|
||||||
executed="true";
|
executed="true";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1054,7 +1061,7 @@ void VMEngine::Run(bool astep, bool acall, uint64_t timeout)
|
||||||
catch(exception const& e)
|
catch(exception const& e)
|
||||||
{
|
{
|
||||||
this->Halt();
|
this->Halt();
|
||||||
widget->log.append(e.what());
|
widget->tolog(e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1064,71 +1071,22 @@ void VMEngine::Run(bool astep, bool acall, uint64_t timeout)
|
||||||
|
|
||||||
Menu::Menu (finalcut::FWidget* parent)
|
Menu::Menu (finalcut::FWidget* parent)
|
||||||
: finalcut::FDialog{parent}
|
: finalcut::FDialog{parent}
|
||||||
{
|
|
||||||
initNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::initNow()
|
|
||||||
{
|
{
|
||||||
initWindows();
|
initWindows();
|
||||||
initMisc();
|
initMisc();
|
||||||
initMenus();
|
initMenus();
|
||||||
initMenusCallBack();
|
initMenusCallBack();
|
||||||
initCore();
|
loadScenario("./scenarios.json");
|
||||||
}
|
addTimer(50);
|
||||||
|
|
||||||
void Menu::initCore()
|
|
||||||
{
|
|
||||||
addTimer (50);
|
|
||||||
if (scenar.load("./scenarios.json"))
|
|
||||||
{
|
|
||||||
log.append("Application - charge scénarios....................[ OK ]");
|
|
||||||
log.append("-={ "+ scenario.title+" }=-");
|
|
||||||
if (scenario.levels.size()>0)
|
|
||||||
loadLevel();
|
|
||||||
maxi();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vm.Unconfigure();
|
|
||||||
log.append("Application - charge scénarios....................[ERREUR]");
|
|
||||||
mini();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::mini()
|
|
||||||
{
|
|
||||||
this->hide();
|
|
||||||
flags.hide();
|
|
||||||
stack.hide();
|
|
||||||
mem.hide();
|
|
||||||
screen.hide();
|
|
||||||
log.show();
|
|
||||||
edit.hide();
|
|
||||||
view.hide();
|
|
||||||
regs.hide();
|
|
||||||
tuto.hide();
|
|
||||||
debug.hide();
|
|
||||||
scenar.hide();
|
|
||||||
Options.hide();
|
|
||||||
Tools.hide();
|
|
||||||
Window.hide();
|
|
||||||
Debug.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::maxi()
|
|
||||||
{
|
|
||||||
Options.show();
|
|
||||||
Tools.show();
|
|
||||||
Window.show();
|
|
||||||
Debug.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::initWindows()
|
void Menu::initWindows()
|
||||||
{
|
{
|
||||||
log.setText ("Journaux");
|
this->setText ("Journaux");
|
||||||
log.setResizeable();
|
this->show();
|
||||||
log.show();
|
info.setText ("Informations");
|
||||||
|
info.setResizeable();
|
||||||
|
info.show();
|
||||||
edit.setText ("Code source");
|
edit.setText ("Code source");
|
||||||
edit.setResizeable();
|
edit.setResizeable();
|
||||||
edit.show();
|
edit.show();
|
||||||
|
@ -1148,7 +1106,6 @@ void Menu::initWindows()
|
||||||
debug.setResizeable();
|
debug.setResizeable();
|
||||||
debug.show();
|
debug.show();
|
||||||
scenar.setText ("Scénarios");
|
scenar.setText ("Scénarios");
|
||||||
scenar.setResizeable();
|
|
||||||
scenar.show();
|
scenar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1167,7 +1124,7 @@ void Menu::initWindows()
|
||||||
|
|
||||||
void Menu::AdjustWindows()
|
void Menu::AdjustWindows()
|
||||||
{
|
{
|
||||||
log.setGeometry ( FPoint { 63, 45 }, FSize{60, 11} );
|
this->setGeometry ( FPoint { 63, 45 }, FSize{60, 11} );
|
||||||
edit.setGeometry ( FPoint { 01, 17 }, FSize{39, 27} );
|
edit.setGeometry ( FPoint { 01, 17 }, FSize{39, 27} );
|
||||||
view.setGeometry ( FPoint { 01, 45 }, FSize{60, 11} );
|
view.setGeometry ( FPoint { 01, 45 }, FSize{60, 11} );
|
||||||
regs.setGeometry ( FPoint { 01, 01 }, FSize{40, 15} );
|
regs.setGeometry ( FPoint { 01, 01 }, FSize{40, 15} );
|
||||||
|
@ -1178,26 +1135,50 @@ void Menu::AdjustWindows()
|
||||||
screen.setGeometry ( FPoint { 103, 16 }, FSize{82, 28} );
|
screen.setGeometry ( FPoint { 103, 16 }, FSize{82, 28} );
|
||||||
debug.setGeometry ( FPoint { 42, 17 }, FSize{60, 27} );
|
debug.setGeometry ( FPoint { 42, 17 }, FSize{60, 27} );
|
||||||
scenar.setGeometry ( FPoint { 187, 01 }, FSize{25, 55} );
|
scenar.setGeometry ( FPoint { 187, 01 }, FSize{25, 55} );
|
||||||
this->hide();
|
info.setGeometry (FPoint { 55, 25 }, FSize{50, 14});
|
||||||
|
this->show();
|
||||||
|
info.hide();
|
||||||
flags.hide();
|
flags.hide();
|
||||||
stack.hide();
|
stack.hide();
|
||||||
mem.hide();
|
mem.hide();
|
||||||
screen.hide();
|
screen.hide();
|
||||||
log.show();
|
if (scenario.loaded)
|
||||||
edit.show();
|
{
|
||||||
view.show();
|
info.show();
|
||||||
regs.show();
|
edit.show();
|
||||||
tuto.show();
|
view.show();
|
||||||
debug.show();
|
regs.show();
|
||||||
scenar.show();
|
tuto.show();
|
||||||
if (scenario.levels[scenar.getselected()].rights > 3)
|
debug.show();
|
||||||
flags.show();
|
scenar.show();
|
||||||
if (scenario.levels[scenar.getselected()].rights > 5)
|
if (level.rights > 3)
|
||||||
stack.show();
|
flags.show();
|
||||||
if (scenario.levels[scenar.getselected()].rights > 2)
|
if (level.rights > 5)
|
||||||
mem.show();
|
stack.show();
|
||||||
if (scenario.levels[scenar.getselected()].rights > 6)
|
if (level.rights > 2)
|
||||||
screen.show();
|
mem.show();
|
||||||
|
if (level.rights > 6)
|
||||||
|
screen.show();
|
||||||
|
Options.setEnable();
|
||||||
|
Tools.setEnable();
|
||||||
|
Window.setEnable();
|
||||||
|
Debug.setEnable();
|
||||||
|
Breakpoint.setEnable();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
edit.hide();
|
||||||
|
view.hide();
|
||||||
|
regs.hide();
|
||||||
|
tuto.hide();
|
||||||
|
debug.hide();
|
||||||
|
scenar.hide();
|
||||||
|
Options.setDisable();
|
||||||
|
Tools.setDisable();
|
||||||
|
Window.setDisable();
|
||||||
|
Debug.setDisable();
|
||||||
|
Breakpoint.setDisable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::initMenus()
|
void Menu::initMenus()
|
||||||
|
@ -1310,33 +1291,31 @@ void Menu::initMenusCallBack()
|
||||||
|
|
||||||
void Menu::initMisc()
|
void Menu::initMisc()
|
||||||
{
|
{
|
||||||
Info << " █████ █████████ ████████ ████████ \n"
|
info.set("\
|
||||||
<< "░░███ ███░░░░░███ ███░░░░███ ███░░░░███\n"
|
█████ █████████ ████████ ████████ \n\
|
||||||
<< " ░███ ░███ ░███ ░███ ░███ ░███ ░░░ \n"
|
░░███ ███░░░░░███ ███░░░░███ ███░░░░███\n\
|
||||||
<< " ░███ ░███████████ ░░████████ ░█████████ \n"
|
░███ ░███ ░███ ░███ ░███ ░███ ░░░ \n\
|
||||||
<< " ░███ ░███░░░░░███ ███░░░░███ ░███░░░░███\n"
|
░███ ░███████████ ░░████████ ░█████████ \n\
|
||||||
<< " ░███ ░███ ░███ ░███ ░███ ░███ ░███\n"
|
░███ ░███░░░░░███ ███░░░░███ ░███░░░░███\n\
|
||||||
<< " █████ █████ █████░░████████ ░░████████ \n"
|
░███ ░███ ░███ ░███ ░███ ░███ ░███\n\
|
||||||
<< "░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░░░░ \n"
|
█████ █████ █████░░████████ ░░████████ \n\
|
||||||
<< "THE EVEN MORE PEDAGOGICAL SYSTEM !!\n"
|
░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░░░░ \n\
|
||||||
<< "\n"
|
THE EVEN MORE PEDAGOGICAL SYSTEM !!\n\
|
||||||
<< "Episode 1 : Apprendre l'assembleur X86";
|
\n\
|
||||||
|
Episode 1 : Apprendre l'assembleur X86");
|
||||||
Statusbar.setMessage("THE EVEN MORE PEDAGOGICAL SYSTEM !!");
|
Statusbar.setMessage("THE EVEN MORE PEDAGOGICAL SYSTEM !!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::initLayout()
|
void Menu::initLayout()
|
||||||
{
|
{
|
||||||
Info.setGeometry(FPoint{2, 1}, FSize{43, 12});
|
Log.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
|
||||||
FDialog::initLayout();
|
FDialog::initLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::adjustSize()
|
void Menu::adjustSize()
|
||||||
{
|
{
|
||||||
const auto pw = int(getDesktopWidth());
|
|
||||||
const auto ph = int(getDesktopHeight());
|
|
||||||
setX (1 + (pw - int(getWidth())) / 2, false);
|
|
||||||
setY (1 + (ph - int(getHeight())) / 4, false);
|
|
||||||
finalcut::FDialog::adjustSize();
|
finalcut::FDialog::adjustSize();
|
||||||
|
Log.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::onClose (finalcut::FCloseEvent* ev)
|
void Menu::onClose (finalcut::FCloseEvent* ev)
|
||||||
|
@ -1344,18 +1323,51 @@ void Menu::onClose (finalcut::FCloseEvent* ev)
|
||||||
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::loadLevel()
|
void Menu::closeLevel()
|
||||||
{
|
{
|
||||||
vm.Unconfigure();
|
vm.Unconfigure();
|
||||||
log.append("Application - charge niveau.......................[ INFO ]");
|
AdjustWindows();
|
||||||
view.setText("Objectif: "+scenario.levels[scenar.getselected()].title);
|
}
|
||||||
|
|
||||||
|
void Menu::loadScenario(std::string file)
|
||||||
|
{
|
||||||
|
|
||||||
|
scenario.loaded=false;
|
||||||
|
std::ifstream inFile;
|
||||||
|
inFile.open(file);
|
||||||
|
std::stringstream strStream;
|
||||||
|
strStream << inFile.rdbuf();
|
||||||
|
std::string json=strStream.str();
|
||||||
|
std::istringstream json_data(json);
|
||||||
|
struct_mapping::map_json_to_struct(scenario, json_data);
|
||||||
|
if (scenario.levels.size()>0)
|
||||||
|
{
|
||||||
|
scenar.Load(scenario.levels);
|
||||||
|
scenario.loaded=true;
|
||||||
|
tolog("Application - charge scénarios....................[ OK ]");
|
||||||
|
tolog("-={ "+ scenario.title+" }=-");
|
||||||
|
loadLevel(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tolog("Application - charge scénarios....................[ERREUR]");
|
||||||
|
closeLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::loadLevel(int alevel)
|
||||||
|
{
|
||||||
|
vm.Unconfigure();
|
||||||
|
level=scenario.levels[alevel];
|
||||||
|
tolog("Application - charge niveau.......................[ INFO ]");
|
||||||
|
view.setText("Objectif: "+level.title);
|
||||||
view.clear();
|
view.clear();
|
||||||
view.append(scenario.levels[scenar.getselected()].description);
|
view.append(level.description);
|
||||||
tuto.clear();
|
tuto.clear();
|
||||||
tuto.append(scenario.levels[scenar.getselected()].tutorial);
|
tuto.append(level.tutorial);
|
||||||
edit.set(scenario.levels[scenar.getselected()].code);
|
edit.set(level.code);
|
||||||
debug.clear();
|
debug.clear();
|
||||||
vm.setRights(scenario.levels[scenar.getselected()].rights);
|
vm.setRights(level.rights);
|
||||||
AdjustWindows();
|
AdjustWindows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1366,19 +1378,19 @@ void Menu::end()
|
||||||
|
|
||||||
void Menu::compile()
|
void Menu::compile()
|
||||||
{
|
{
|
||||||
vm.Configure(&scenario.levels[scenar.getselected()].init,edit.get());
|
vm.Configure(&level.init,edit.get());
|
||||||
ClearScreen();
|
ClearScreen();
|
||||||
showInstr();
|
showInstr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::tolog(std::string str)
|
void Menu::tolog(std::string str)
|
||||||
{
|
{
|
||||||
log.append(str);
|
this->Log.append(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::about()
|
void Menu::about()
|
||||||
{
|
{
|
||||||
log.hide();
|
this->hide();
|
||||||
edit.hide();
|
edit.hide();
|
||||||
view.hide();
|
view.hide();
|
||||||
regs.hide();
|
regs.hide();
|
||||||
|
@ -1389,9 +1401,8 @@ void Menu::about()
|
||||||
screen.hide();
|
screen.hide();
|
||||||
debug.hide();
|
debug.hide();
|
||||||
scenar.hide();
|
scenar.hide();
|
||||||
this->show();
|
info.show();
|
||||||
this->redraw();
|
info.redraw();
|
||||||
this->Info.redraw();
|
|
||||||
//((finalcut::FApplication*)this->getParent())->sendQueuedEvents();
|
//((finalcut::FApplication*)this->getParent())->sendQueuedEvents();
|
||||||
sleep(3);
|
sleep(3);
|
||||||
AdjustWindows();
|
AdjustWindows();
|
||||||
|
@ -1410,7 +1421,7 @@ void Menu::showInstr()
|
||||||
}
|
}
|
||||||
catch(exception const& e)
|
catch(exception const& e)
|
||||||
{
|
{
|
||||||
log.append(e.what());
|
tolog(e.what());
|
||||||
vm.Halt();
|
vm.Halt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1423,6 +1434,7 @@ void Menu::refresh()
|
||||||
flags.set("Attente...");
|
flags.set("Attente...");
|
||||||
stack.set("Attente...");
|
stack.set("Attente...");
|
||||||
mem.set("En attente d'initialisation...");
|
mem.set("En attente d'initialisation...");
|
||||||
|
screen.set("En attente d'initialisation...");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1433,7 +1445,7 @@ void Menu::refresh()
|
||||||
}
|
}
|
||||||
catch(exception const& e)
|
catch(exception const& e)
|
||||||
{
|
{
|
||||||
log.append(e.what());
|
tolog(e.what());
|
||||||
vm.Halt();
|
vm.Halt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1483,13 +1495,9 @@ int main (int argc, char* argv[])
|
||||||
mapping();
|
mapping();
|
||||||
finalcut::FApplication app {argc, argv};
|
finalcut::FApplication app {argc, argv};
|
||||||
Menu main_dlg {&app};
|
Menu main_dlg {&app};
|
||||||
main_dlg.setText ("IA86");
|
/*main_dlg.setText ("Journaux");
|
||||||
main_dlg.setSize ({50, 14});
|
main_dlg.setGeometry ( FPoint { 63, 45 }, FSize{60, 11} );
|
||||||
main_dlg.setShadow();
|
main_dlg.show();*/
|
||||||
main_dlg.show();
|
|
||||||
finalcut::FApplication::setDarkTheme();
|
|
||||||
finalcut::FWidget::setMainWidget (&main_dlg);
|
finalcut::FWidget::setMainWidget (&main_dlg);
|
||||||
//usleep(5 * 1000000);
|
|
||||||
main_dlg.hide();
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
40
ia86.h
40
ia86.h
|
@ -125,6 +125,7 @@ struct Level {
|
||||||
struct Scenario {
|
struct Scenario {
|
||||||
std::string title;
|
std::string title;
|
||||||
std::vector<Level> levels;
|
std::vector<Level> levels;
|
||||||
|
bool loaded;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Code
|
struct Code
|
||||||
|
@ -175,11 +176,9 @@ class ScenarioWindow final : public finalcut::FDialog
|
||||||
// Disable copy assignment operator (=)
|
// Disable copy assignment operator (=)
|
||||||
ScenarioWindow& operator = (const ScenarioWindow&) = delete;
|
ScenarioWindow& operator = (const ScenarioWindow&) = delete;
|
||||||
// Method
|
// Method
|
||||||
int getselected();
|
void Load(std::vector<Level> items);
|
||||||
bool load(std::string file);
|
|
||||||
private:
|
private:
|
||||||
// Method
|
// Method
|
||||||
int selected;
|
|
||||||
void click();
|
void click();
|
||||||
void initLayout() override;
|
void initLayout() override;
|
||||||
void adjustSize() override;
|
void adjustSize() override;
|
||||||
|
@ -315,7 +314,10 @@ class VMEngine
|
||||||
bool isExecuted();
|
bool isExecuted();
|
||||||
bool isInitialized();
|
bool isInitialized();
|
||||||
void setRights(int rights);
|
void setRights(int rights);
|
||||||
void ClearScreen();
|
void clearbreakpoints();
|
||||||
|
void addbreakpoint(int address);
|
||||||
|
void removebreakpoint(int address);
|
||||||
|
std::vector<int> getBreapoints();
|
||||||
int getLine();
|
int getLine();
|
||||||
uint32_t getEIP();
|
uint32_t getEIP();
|
||||||
uint16_t getCS();
|
uint16_t getCS();
|
||||||
|
@ -323,6 +325,7 @@ class VMEngine
|
||||||
uint16_t getES();
|
uint16_t getES();
|
||||||
uint16_t getSS();
|
uint16_t getSS();
|
||||||
private:
|
private:
|
||||||
|
std::vector<int> breakpoints;
|
||||||
int rights;
|
int rights;
|
||||||
void Init();
|
void Init();
|
||||||
void Close();
|
void Close();
|
||||||
|
@ -350,10 +353,10 @@ class Menu final : public finalcut::FDialog
|
||||||
// Disable copy assignment operator (=)
|
// Disable copy assignment operator (=)
|
||||||
Menu& operator = (const Menu&) = delete;
|
Menu& operator = (const Menu&) = delete;
|
||||||
// Methods
|
// Methods
|
||||||
void loadLevel();
|
void loadLevel(int alevel);
|
||||||
|
void closeLevel();
|
||||||
void tolog(std::string str);
|
void tolog(std::string str);
|
||||||
void SetScreen(uint16_t x, uint16_t y, char value);
|
void SetScreen(uint16_t x, uint16_t y, char value);
|
||||||
TextWindow log{this};
|
|
||||||
private:
|
private:
|
||||||
void onTimer (finalcut::FTimerEvent*) override;
|
void onTimer (finalcut::FTimerEvent*) override;
|
||||||
void refresh();
|
void refresh();
|
||||||
|
@ -361,17 +364,14 @@ class Menu final : public finalcut::FDialog
|
||||||
void initMenusCallBack ();
|
void initMenusCallBack ();
|
||||||
void initMenus();
|
void initMenus();
|
||||||
void initMisc();
|
void initMisc();
|
||||||
void initNow();
|
|
||||||
void initCore();
|
|
||||||
void compile();
|
void compile();
|
||||||
void end();
|
void end();
|
||||||
|
void loadScenario(std::string file);
|
||||||
void showInstr();
|
void showInstr();
|
||||||
void exec();
|
void exec();
|
||||||
void trace();
|
void trace();
|
||||||
void step();
|
void step();
|
||||||
void about();
|
void about();
|
||||||
void mini();
|
|
||||||
void maxi();
|
|
||||||
void ClearScreen();
|
void ClearScreen();
|
||||||
void AdjustWindows();
|
void AdjustWindows();
|
||||||
void initWindows();
|
void initWindows();
|
||||||
|
@ -389,11 +389,11 @@ class Menu final : public finalcut::FDialog
|
||||||
finalcut::FMenuItem Line2{&Game};
|
finalcut::FMenuItem Line2{&Game};
|
||||||
finalcut::FMenuItem Quit{"&Quitter", &Game};
|
finalcut::FMenuItem Quit{"&Quitter", &Game};
|
||||||
finalcut::FMenu Options{"&Options", &Menubar};
|
finalcut::FMenu Options{"&Options", &Menubar};
|
||||||
//finalcut::FMenu Memory{"&Mémoire", &Options};
|
finalcut::FMenu Memory{"&Mémoire", &Options};
|
||||||
//finalcut::FRadioMenuItem Ds_esi{"DS:ESI", &Memory};
|
finalcut::FRadioMenuItem Ds_esi{"DS:ESI", &Memory};
|
||||||
//finalcut::FRadioMenuItem Es_edi{"ES:EDI", &Memory};
|
finalcut::FRadioMenuItem Es_edi{"ES:EDI", &Memory};
|
||||||
//finalcut::FRadioMenuItem Cs_eip{"CS:EIP", &Memory};
|
finalcut::FRadioMenuItem Cs_eip{"CS:EIP", &Memory};
|
||||||
//finalcut::FRadioMenuItem Ss_sp{"SS:SP", &Memory};
|
finalcut::FRadioMenuItem Ss_sp{"SS:SP", &Memory};
|
||||||
finalcut::FMenu Tools{"&Outils", &Menubar};
|
finalcut::FMenu Tools{"&Outils", &Menubar};
|
||||||
finalcut::FMenuItem Assemble{"&Compilation", &Tools};
|
finalcut::FMenuItem Assemble{"&Compilation", &Tools};
|
||||||
finalcut::FMenuItem Rearange{"&Ordonne les fenêtres", &Tools};
|
finalcut::FMenuItem Rearange{"&Ordonne les fenêtres", &Tools};
|
||||||
|
@ -402,12 +402,16 @@ class Menu final : public finalcut::FDialog
|
||||||
finalcut::FMenuItem End{"&Terminer", &Debug};
|
finalcut::FMenuItem End{"&Terminer", &Debug};
|
||||||
finalcut::FMenuItem TraceInto{"Pas à pas &détaillé", &Debug};
|
finalcut::FMenuItem TraceInto{"Pas à pas &détaillé", &Debug};
|
||||||
finalcut::FMenuItem StepOver{"&Pas à pas", &Debug};
|
finalcut::FMenuItem StepOver{"&Pas à pas", &Debug};
|
||||||
finalcut::FMenuItem Breakpoint{"&Point d'arrêt", &Debug};
|
finalcut::FMenu Breakpoint{"&Point d'arrêt", &Menubar};
|
||||||
|
finalcut::FMenuItem AddBp{"&Ajouter", &Breakpoint};
|
||||||
|
finalcut::FMenuItem DelBp{"&Supprimer", &Breakpoint};
|
||||||
|
finalcut::FMenuItem ClearBp{"&Tout supprimer", &Breakpoint};
|
||||||
finalcut::FDialogListMenu Window{"&Fenêtres", &Menubar};
|
finalcut::FDialogListMenu Window{"&Fenêtres", &Menubar};
|
||||||
finalcut::FMenu Help{"&Aide", &Menubar};
|
finalcut::FMenu Help{"&Aide", &Menubar};
|
||||||
finalcut::FMenuItem About{"&A propos", &Help};
|
finalcut::FMenuItem About{"&A propos", &Help};
|
||||||
finalcut::FLabel Info{this};
|
finalcut::FTextView Log{this};
|
||||||
finalcut::FStatusBar Statusbar{this};
|
finalcut::FStatusBar Statusbar{this};
|
||||||
|
TextWindow info{this};
|
||||||
TextWindow view{this};
|
TextWindow view{this};
|
||||||
InstructionWindow debug{this};
|
InstructionWindow debug{this};
|
||||||
TextWindow regs{this};
|
TextWindow regs{this};
|
||||||
|
@ -420,5 +424,3 @@ class Menu final : public finalcut::FDialog
|
||||||
ScenarioWindow scenar{this};
|
ScenarioWindow scenar{this};
|
||||||
VMEngine vm{this};
|
VMEngine vm{this};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue