aboutsummaryrefslogtreecommitdiff
path: root/element_detection.cc
diff options
context:
space:
mode:
authorCalder Kitagawa <ckitagawa@google.com>2018-05-23 17:30:51 +0000
committerEdward Lesmes <ehmaldonado@google.com>2021-07-23 22:37:13 +0000
commit0d7a2511be3754c2e4860e16ddbf7610e07ffe68 (patch)
tree292a85ec3d60366bc409d3839145e3541c7da25a /element_detection.cc
parent1bed19c017ffd98c6448e352d564b8583b4862b1 (diff)
downloadzucchini-0d7a2511be3754c2e4860e16ddbf7610e07ffe68.tar.gz
[Zucchini] ZTF (text) disassembler
A Zucchini text format (ZTF) disassembler for validating and debugging Zucchini using special text files. This is intended to be primarily used for easier validation of the core Zucchini algorithm. It is also useful for fuzzing reference projection as it is a lighter weight disassembler than other executable formats. References are encoded in an ASCII plain-text format to be human-readable and easier to debug. See the disassembler_ztf.h file for a complete outline of the file format. Which is referred to as Zucchini Text Format (ZTF) throughout the code. The design is meant to be highly flexible and non-redundant so a fair amount of templating/overloading is used. The overall design is: Shared: - ZtfConfig: To handle metadata for different types of references. - ZtfTranslator: Translate text references into offsets and back. Read: - ZtfParser: Find references in the file. - ZtfReferenceReader: Drive ZtfParser through the file and use it with ZtfTranslator to translate between offsets and references. Write: - ZtfWriter: The counterpart to parser for writing a reference to a location. - ZtfReferenceWriter: Compose ZtfWriter and ZtfTranslator together and write references to an image. Bug: 834904 Change-Id: Iec62c67eab6bd3e7e95b79798417035a4873360a Reviewed-on: https://chromium-review.googlesource.com/1056147 Commit-Queue: Calder Kitagawa <ckitagawa@google.com> Reviewed-by: Samuel Huang <huangs@chromium.org> Reviewed-by: Greg Thompson <grt@chromium.org> Cr-Commit-Position: refs/heads/master@{#561140} NOKEYCHECK=True GitOrigin-RevId: d2c5be5844c12d2585bde53ba891154ffed2ca62
Diffstat (limited to 'element_detection.cc')
-rw-r--r--element_detection.cc25
1 files changed, 24 insertions, 1 deletions
diff --git a/element_detection.cc b/element_detection.cc
index a826f54..6b31f61 100644
--- a/element_detection.cc
+++ b/element_detection.cc
@@ -9,9 +9,19 @@
#include "base/logging.h"
#include "components/zucchini/buildflags.h"
#include "components/zucchini/disassembler.h"
-#include "components/zucchini/disassembler_dex.h"
#include "components/zucchini/disassembler_no_op.h"
+
+#if BUILDFLAG(ENABLE_DEX)
+#include "components/zucchini/disassembler_dex.h"
+#endif // BUILDFLAG(ENABLE_DEX)
+
+#if BUILDFLAG(ENABLE_WIN)
#include "components/zucchini/disassembler_win32.h"
+#endif // BUILDFLAG(ENABLE_WIN)
+
+#if BUILDFLAG(ENABLE_ZTF)
+#include "components/zucchini/disassembler_ztf.h"
+#endif // BUILDFLAG(ENABLE_ZTF)
namespace zucchini {
@@ -48,6 +58,15 @@ std::unique_ptr<Disassembler> MakeDisassemblerWithoutFallback(
}
#endif // BUILDFLAG(ENABLE_DEX)
+#if BUILDFLAG(ENABLE_ZTF)
+ if (DisassemblerZtf::QuickDetect(image)) {
+ // This disallows very short examples like "ZTxtxtZ\n" in ensemble patching.
+ auto disasm = Disassembler::Make<DisassemblerZtf>(image);
+ if (disasm && disasm->size() >= kMinProgramSize)
+ return disasm;
+ }
+#endif // BUILDFLAG(ENABLE_ZTF)
+
return nullptr;
}
@@ -64,6 +83,10 @@ std::unique_ptr<Disassembler> MakeDisassemblerOfType(ConstBufferView image,
case kExeTypeDex:
return Disassembler::Make<DisassemblerDex>(image);
#endif // BUILDFLAG(ENABLE_DEX)
+#if BUILDFLAG(ENABLE_ZTF)
+ case kExeTypeZtf:
+ return Disassembler::Make<DisassemblerZtf>(image);
+#endif // BUILDFLAG(ENABLE_ZTF)
case kExeTypeNoOp:
return Disassembler::Make<DisassemblerNoOp>(image);
default: