Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1171)

Side by Side Diff: syzygy/experimental/protect/protect_lib/equation_gen.cc

Issue 2535563002: Added all code for integrity check transform (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #include <string.h>
2 #include <algorithm>
3 #include <iostream>
4 #include <vector>
5 #include <type_traits>
6 #include <iterator>
7
8 #include "syzygy/core/disassembler_util.h"
9 #include "syzygy/assm/assembler.h"
10 #include "syzygy/assm/assembler_base.h"
11 #include "syzygy/block_graph/basic_block_subgraph.h"
12 #include "syzygy/block_graph/basic_block_assembler.h"
13 #include "syzygy/block_graph/basic_block_decomposer.h"
14
15 #include "syzygy/experimental/protect/protect_lib/equation_gen.h"
16
17 void GenerateMonomial(block_graph::BasicBlockAssembler &assm,
18 assm::Register32 &temp,
19 assm::Register32 source,
20 int exp,
21 int coef)
22 {
23 // Result will be stored in temp
24 if (exp == 0) {
25 assm.mov(temp, block_graph::Immediate(coef, assm::ValueSize::kSize32Bit));
26 return;
27 }
28
29 assm.mov(temp, source);
30 exp--;
31
32 while (exp > 0) {
33 assm.imul(temp, source);
34 exp--;
35 }
36 }
37
38 void GenerateSingleVarPolinomial(block_graph::BasicBlockAssembler &assm,
39 std::vector<assm::Register32>::iterator temp_regs_start,
40 std::vector<assm::Register32>::iterator temp_regs_stop,
41 assm::Register32 &acc, assm::Register32 source,
42 std::vector<int> &source_exp, std::vector<int> &source_coef)
43 {
44 if (temp_regs_start == temp_regs_stop) {
45 assm.nop(4);
46 return;
47 }
48
49 assm::Register32 monomial_temp = *temp_regs_start;
50
51 GenerateMonomial(assm, acc, source, source_exp[0], source_coef[0]);
52
53 for (int i = 1; i < (int)source_exp.size(); ++i) {
54 GenerateMonomial(assm, monomial_temp, source, source_exp[i],
55 source_coef[i]);
56 assm.add(acc, monomial_temp);
57 }
58 }
59
60 assm::ConditionCode Equation::Generate(
61 block_graph::BasicBlockAssembler &assm,
62 std::vector<assm::Register32> &temp_regs,
63 std::vector<assm::Register32> &source_regs)
64 {
65 assm::Register32 acc = temp_regs[0];
66 assm::Register32 temp = acc;
67 assm::Register32 source_x = source_regs[0];
68 assm::Register32 source_y = source_regs[0];
69 assm::ConditionCode ret = assm::ConditionCode::kNotEqual;
70
71 GenerateSingleVarPolinomial(assm, temp_regs.begin() + 1, temp_regs.end(),
72 temp, source_x, this->x_exp, this->x_coef);
73
74 if (source_regs.size() > 1) {
75 temp = temp_regs[1];
76 source_y = source_regs[1];
77
78 GenerateSingleVarPolinomial(assm, temp_regs.begin() + 2, temp_regs.end(),
79 temp, source_y, this->y_exp, this->y_coef);
80
81 assm.add(acc, temp);
82 }
83
84 // Generate condition
85 assm.cmp(acc, block_graph::Immediate(0, assm::ValueSize::kSize8Bit));
86
87 return ret;
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698