summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-14 09:59:30 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-14 09:59:30 +0200
commitdd6d72026ac1c96bb85d5f108fa8ddfa2758f02b (patch)
treef83d0626b2ffe1edb4bfa18d07ca0e44cb159895
parent3b2bc6741a6f0cc7a6790167e42c915d2ae9d4de (diff)
asm: check for invalid opcode.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--Sources/64asm.cc14
-rw-r--r--Sources/i64asm.cc9
-rw-r--r--Sources/ppcasm.cc30
3 files changed, 28 insertions, 25 deletions
diff --git a/Sources/64asm.cc b/Sources/64asm.cc
index efcfd66..58e02b4 100644
--- a/Sources/64asm.cc
+++ b/Sources/64asm.cc
@@ -301,14 +301,14 @@ asm_fail_exit:
static bool asm_read_attributes(std::string &line) {
// import is the opposite of export, it signals to the ld
// that we need this symbol.
- if (ParserKit::find_word(line, "import ")) {
+ if (ParserKit::find_word(line, "import")) {
if (kOutputAsBinary) {
detail::print_error("Invalid import directive in flat binary mode.",
"64asm");
throw std::runtime_error("invalid_import_bin");
}
- auto name = line.substr(line.find("import ") + strlen("import "));
+ auto name = line.substr(line.find("import") + strlen("import"));
std::string result = std::to_string(name.size());
result += kUndefinedSymbol;
@@ -326,7 +326,7 @@ static bool asm_read_attributes(std::string &line) {
} else if (name.find(".data64") != std::string::npos) {
// no code will be executed from here.
kCurrentRecord.fKind = CompilerKit::kPefData;
- } else if (name.find(".page_zero") != std::string::npos) {
+ } else if (name.find(".zero64") != std::string::npos) {
// this is a bss section.
kCurrentRecord.fKind = CompilerKit::kPefZero;
}
@@ -356,14 +356,14 @@ static bool asm_read_attributes(std::string &line) {
// export is a special keyword used by 64asm to tell the AE output stage to
// mark this section as a header. it currently supports .code64, .data64.,
// page_zero
- else if (ParserKit::find_word(line, "export ")) {
+ else if (ParserKit::find_word(line, "export")) {
if (kOutputAsBinary) {
detail::print_error("Invalid export directive in flat binary mode.",
"64asm");
throw std::runtime_error("invalid_export_bin");
}
- auto name = line.substr(line.find("export ") + strlen("export "));
+ auto name = line.substr(line.find("export") + strlen("export"));
std::string name_copy = name;
@@ -381,10 +381,10 @@ static bool asm_read_attributes(std::string &line) {
name_copy.erase(name_copy.find(".data64"), strlen(".data64"));
kCurrentRecord.fKind = CompilerKit::kPefData;
- } else if (name.find(".page_zero") != std::string::npos) {
+ } else if (name.find(".zero64") != std::string::npos) {
// this is a bss section.
- name_copy.erase(name_copy.find(".page_zero"), strlen(".page_zero"));
+ name_copy.erase(name_copy.find(".zero64"), strlen(".zero64"));
kCurrentRecord.fKind = CompilerKit::kPefZero;
}
diff --git a/Sources/i64asm.cc b/Sources/i64asm.cc
index 199a785..b85b6b3 100644
--- a/Sources/i64asm.cc
+++ b/Sources/i64asm.cc
@@ -382,7 +382,7 @@ static bool asm_read_attributes(std::string &line) {
} else if (name.find(".data64") != std::string::npos) {
// no code will be executed from here.
kCurrentRecord.fKind = CompilerKit::kPefData;
- } else if (name.find(".page_zero") != std::string::npos) {
+ } else if (name.find(".zero64") != std::string::npos) {
// this is a bss section.
kCurrentRecord.fKind = CompilerKit::kPefZero;
}
@@ -411,8 +411,7 @@ static bool asm_read_attributes(std::string &line) {
return true;
}
// export is a special keyword used by i64asm to tell the AE output stage to
- // mark this section as a header. it currently supports .code64, .data64.,
- // page_zero
+ // mark this section as a header. it currently supports .code64, .data64 and .zero64.
else if (ParserKit::find_word(line, "export")) {
if (kOutputAsBinary) {
detail::print_error("Invalid directive in flat binary mode.", "i64asm");
@@ -445,10 +444,10 @@ static bool asm_read_attributes(std::string &line) {
name_copy.erase(name_copy.find(".data64"), strlen(".data64"));
kCurrentRecord.fKind = CompilerKit::kPefData;
- } else if (name.find(".page_zero") != std::string::npos) {
+ } else if (name.find(".zero64") != std::string::npos) {
// this is a bss section.
- name_copy.erase(name_copy.find(".page_zero"), strlen(".page_zero"));
+ name_copy.erase(name_copy.find(".zero64"), strlen(".zero64"));
kCurrentRecord.fKind = CompilerKit::kPefZero;
}
diff --git a/Sources/ppcasm.cc b/Sources/ppcasm.cc
index ebc9e9e..69627bb 100644
--- a/Sources/ppcasm.cc
+++ b/Sources/ppcasm.cc
@@ -306,14 +306,14 @@ asm_fail_exit:
static bool asm_read_attributes(std::string &line) {
// import is the opposite of export, it signals to the li
// that we need this symbol.
- if (ParserKit::find_word(line, "import ")) {
+ if (ParserKit::find_word(line, "import")) {
if (kOutputAsBinary) {
detail::print_error("Invalid import directive in flat binary mode.",
"ppcasm");
throw std::runtime_error("invalid_import_bin");
}
- auto name = line.substr(line.find("import ") + strlen("import "));
+ auto name = line.substr(line.find("import") + strlen("import" + 1));
std::string result = std::to_string(name.size());
result += kUndefinedSymbol;
@@ -331,7 +331,7 @@ static bool asm_read_attributes(std::string &line) {
} else if (name.find(".data64") != std::string::npos) {
// no code will be executed from here.
kCurrentRecord.fKind = CompilerKit::kPefData;
- } else if (name.find(".page_zero") != std::string::npos) {
+ } else if (name.find(".zero64") != std::string::npos) {
// this is a bss section.
kCurrentRecord.fKind = CompilerKit::kPefZero;
}
@@ -360,15 +360,15 @@ static bool asm_read_attributes(std::string &line) {
}
// export is a special keyword used by ppcasm to tell the AE output stage to
// mark this section as a header. it currently supports .code64, .data64.,
- // page_zero
- else if (ParserKit::find_word(line, "export ")) {
+ // .zero64
+ else if (ParserKit::find_word(line, "export")) {
if (kOutputAsBinary) {
detail::print_error("Invalid export directive in flat binary mode.",
"ppcasm");
throw std::runtime_error("invalid_export_bin");
}
- auto name = line.substr(line.find("export ") + strlen("export "));
+ auto name = line.substr(line.find("export") + strlen("export"));
std::string name_copy = name;
@@ -386,10 +386,10 @@ static bool asm_read_attributes(std::string &line) {
name_copy.erase(name_copy.find(".data64"), strlen(".data64"));
kCurrentRecord.fKind = CompilerKit::kPefData;
- } else if (name.find(".page_zero") != std::string::npos) {
+ } else if (name.find(".zero64") != std::string::npos) {
// this is a bss section.
- name_copy.erase(name_copy.find(".page_zero"), strlen(".page_zero"));
+ name_copy.erase(name_copy.find(".zero64"), strlen(".zero64"));
kCurrentRecord.fKind = CompilerKit::kPefZero;
}
@@ -459,7 +459,7 @@ std::string CompilerKit::EncoderPowerPC::CheckLine(std::string &line,
} else if (line.find(';') != std::string::npos) {
line.erase(line.find(';'));
} else {
- // now check the line for validity
+ /// does the line contains valid input?
if (!detail::algorithm::is_valid(line)) {
err_str = "Line contains non alphanumeric characters.\nhere -> ";
err_str += line;
@@ -663,7 +663,7 @@ bool CompilerKit::EncoderPowerPC::WriteNumber(const std::size_t &pos,
bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line,
const std::string &file) {
- if (ParserKit::find_word(line, "export ")) return true;
+ if (ParserKit::find_word(line, "export")) return true;
for (auto &opcodePPC : kOpcodesPowerPC) {
// strict check here
@@ -912,9 +912,13 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line,
}
kOrigin += 0x04;
-
- break;
- }
+ } else {
+ /// check if we got a valid sequence of characters.
+ if (!isalnum(line[0])) {
+ detail::print_error("syntax error", file);
+ throw std::runtime_error("syntax_error");
+ }
+ }
}
return true;