zig+ollvm跨平台编译的crackme
# crackme说明程序为zig编写,固定注册码。难度主要有
1. 字符串通过comptime(编译时计算)全部加密
2. 通过llvm启动以下功能的pass
1. ibr:间接分支
2. icall:间接调用 (call 寄存器)
3. igv:间接全局变量
4. junk:花之令
5. split:基本块分割
6. sub:指令替换(add/and/sub/or/xor)
## 跨平台
zig支持交叉编译,大家根据自己电脑自行选择,见附件*crackme.zip*
### windows
crackme-x86_64-windows-gnu.exe
crackme-aarch64-windows-gnu.exe
crackme-x86-windows-gnu.exe
### linux
crackme-aarch64-linux-gnu
crackme-x86_64-linux-gnu
crackme-x86-linux-gnu
### macos
crackme-aarch64-macos-none
crackme-x86_64-macos-none
## 源码
见附件*src.zip*,注册码为解压密码
公布答案
const std = @import("std");
const os = std.os;
const posix = std.posix;
const key = @import("option").key;
const string = []const u8;
fn encrypt(comptime str: string) u8 {
comptime var enstr: u8 = undefined;
@setEvalBranchQuota(1024 * 1024);
for (0..str.len) |i| {
enstr = str ^ key;
}
return enstr;
}
inline fn x(comptime str: string) []u8 {
comptime var e = encrypt(str);
var buf = (&e).*;
for (0..buf.len) |i| {
buf ^= key;
}
return buf;
}
inline fn println(str: string) void {
const writer = std.io.getStdOut().writer();
_ = writer.write(str) catch unreachable;
writer.writeByte('\n') catch unreachable;
}
pub fn main() void {
const reader = std.io.getStdIn().reader();
println(x("input your flag"));
var buf: u8 = std.mem.zeroes(u8);
const line = reader.readUntilDelimiter(&buf, '\n') catch {
println(x("input error 1"));
return;
};
if (line.len != 17) {
println(x("input error 2"));
return;
}
if (!std.mem.eql(u8, line, x("d9Be6f0e833709fe"))) {
println(x("input error 3"));
return;
}
println(x("input ok"));
}
页:
[1]