It's really quite hard to guess what is 29th line of emulator.cpp
, but I think your compilec can't locate the rest of libemu headers.
Try to restore paths to emu_instruction to original and add into compiler line key like -I/home/user/libemu/libemu/include
to point place with headers.
Trying to use emu_instruction in libemu gives forward declaration error
-
19-10-2022 - |
문제
I'm writing a code obfuscation tool as a part of my master thesis and I have run in to some problems.
I use libemu for emulating x86 instructions and I would like to read an input file containing hexcode and store the instructions in a vector. In libemu the instructions are represented by the struct emu_instruction
and I would like to use this struct in my program also since libemu also provides a parser. This is how I would like to use it:
emulator.cpp
std::vector<struct emu_instruction*> Emulator::getInstructionVector()
{
std::vector<struct emu_instruction*> v;
//e is my struct emu*
while(emu_cpu_parse(emu_cpu_get(e))) {
v.push_back(&emu_cpu_get(e)->instr);
}
return v;
}
emulator.h (I changed the import paths)
#ifndef EMULATOR_H
#define EMULATOR_H
#include <vector>
extern "C" {
#include "~/libemu/libemu/include/emu/emu.h"
#include "~/libemu/libemu/include/emu/emu_memory.h"
#include "~/libemu/libemu/include/emu/emu_cpu.h"
#include "~/libemu/libemu/include/emu/emu_log.h"
#include "~/libemu/libemu/include/emu/emu_instruction.h"
}
class Emulator {
public:
Emulator();
~Emulator();
void loadProgramInMemory(unsigned char instructionBytes[], int instructionBytesLen);
std::vector<struct emu_instruction*> getInstructionVector();
int runAndGetEFlags();
void printDebug();
private:
struct emu *e;
struct emu_memory *mem;
int static_offset;
};
#endif
I had to change the import paths in emu_instruction to make it compile.
The error I'm getting when trying to run this code is
emulator.cpp: In member function ‘std::vector<emu_instruction*> Emulator::getInstructionVector()’:
emulator.cpp:29:29: error: invalid use of incomplete type ‘struct emu_cpu’
~/libemu/libemu/include/emu/emu.h:45:8: error: forward declaration of ‘struct emu_cpu’
At this point I don't know what to do since I don't fully understand the error. Any help would be appreciated.
Adding the makefile.
Makefile:
CXX = g++
CC = g++
SRC = $(wildcard *.cpp)
OBJ = $(SRC:.cpp=.o)
# Executables
PROGS = program
all: $(PROGS)
program: program.o parser.o instruction.o emulator.o /home/user/libemu/libemu/src/.libs/libemu.a
$(CXX) $(CXXFLAGS) program.o parser.o instruction.o emulator.o /home/user/libemu/libemu/src/.libs/libemu.a -ludis86 -o program.out
parser: parser.o instruction.o
$(CXX) $(CXXFLAGS) parser.o instruction.o -ludis86
clean:
rm -f *.o
cleaner: clean
rm -f $(PROGS) *.out
%.d: %.cpp
@set -e; rm -f $@; \
$(CXX) -MM $(CXXFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
해결책
다른 팁
You must include emu_cpu_data.h
that is where emu_cpu
is actually defined.