-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Context Structure to Affect State Dependent Liftings (#617)
* add empty contexts * add include * make function const * add helper for uniform mappings * expose cache clearing for operand lifter * decoding context documentation: * move virtual inheritance down * remove unused var names * add type alias * remove underscores * make sure we have poetry * check version in CI * try specify python3 * newer poetry install script * fail fast * try use pythons pip * upgrade pip? * install directly * update in linux too
- Loading branch information
Showing
20 changed files
with
221 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2022 Trail of Bits, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
|
||
#include <functional> | ||
#include <string_view> | ||
#include <unordered_map> | ||
|
||
namespace remill { | ||
|
||
/// A decoding context is contextual information about the state of the program that affects decoding, ie. the thumb mode register on ARM | ||
/// We allow clients to interpose on a context for resolution | ||
|
||
/// We return a function of successor -> DecodingContext. The decoder defines a relation on the | ||
/// previous context and the successor address that produces a new decoding. | ||
/// This definition of returned contexts allows us to cleanly handle situations like indirect jumps in arm | ||
class DecodingContext { | ||
|
||
private: | ||
std::unordered_map<std::string, uint64_t> context_value; | ||
|
||
public: | ||
using ContextMap = std::function<DecodingContext(uint64_t)>; | ||
|
||
DecodingContext() = default; | ||
|
||
DecodingContext(std::unordered_map<std::string, uint64_t> context_value); | ||
|
||
|
||
uint64_t GetContextValue(const std::string &context_reg) const; | ||
DecodingContext PutContextReg(std::string creg, uint64_t value) const; | ||
|
||
static ContextMap UniformContextMapping(DecodingContext cst); | ||
}; | ||
|
||
} // namespace remill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
#include <glog/logging.h> | ||
#include <remill/Arch/Context.h> | ||
|
||
namespace remill { | ||
|
||
DecodingContext::DecodingContext( | ||
std::unordered_map<std::string, uint64_t> context_value) | ||
: context_value(std::move(context_value)) {} | ||
|
||
|
||
uint64_t | ||
DecodingContext::GetContextValue(const std::string &context_reg) const { | ||
|
||
if (auto res = this->context_value.find(context_reg); | ||
res != this->context_value.end()) { | ||
return res->second; | ||
} | ||
|
||
LOG(FATAL) << "No context value for " << context_reg | ||
<< " but it is required for decoding"; | ||
} | ||
DecodingContext DecodingContext::PutContextReg(std::string creg, | ||
uint64_t value) const { | ||
std::unordered_map<std::string, uint64_t> new_value(this->context_value); | ||
new_value.emplace(creg, value); | ||
return DecodingContext(std::move(new_value)); | ||
} | ||
|
||
DecodingContext::ContextMap | ||
DecodingContext::UniformContextMapping(DecodingContext cst) { | ||
return [cst = std::move(cst)](uint64_t) -> DecodingContext { return cst; }; | ||
} | ||
|
||
|
||
} // namespace remill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.