Giter Site home page Giter Site logo

sparkyparrot / tritonastllvmirtranslator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fvrmatteo/tritonastllvmirtranslator

0.0 1.0 0.0 31 KB

A simple pluggable tool to convert an unrolled TritonAST to LLVM-IR, optimize it and get back to TritonAST.

C++ 75.43% CMake 4.51% Python 20.06%

tritonastllvmirtranslator's Introduction

TritonAST to LLVM-IR and back

This code has been developed as a quick test in a weekend to evaluate how feasible it would have been to use LLVM-IR optimizations to simplify a TritonAST.

Sample output

> Original Triton AST

(bvadd (bvsub (bvadd (bvnot (bvneg (bvmul SymVar_0 SymVar_1))) (bvnot (bvneg (bvmul SymVar_0 SymVar_1)))) (bvadd (bvnot (bvneg (bvmul SymVar_0 SymVar_1))) (bvnot (bvneg (bvmul SymVar_0 SymVar_1))))) (bvsub (bvadd (bvnot (bvneg (bvmul SymVar_0 SymVar_1))) (bvnot (bvneg (bvmul SymVar_0 SymVar_1)))) (bvadd (bvnot (bvneg (bvmul SymVar_0 SymVar_1))) (bvnot (bvneg (bvmul SymVar_0 SymVar_1))))))

> Unoptimized LLVM-IR Module

; ModuleID = 'TritonAstModule'
source_filename = "TritonAstModule"

@FakeVar_64_0 = common global i64

; Function Attrs: alwaysinline
define common i64 @TritonAstFunction() #0 {
TritonAstEntry:
  %0 = load i64, i64* @FakeVar_64_0
  %1 = add i64 %0, %0
  %2 = add i64 %0, %0
  %3 = sub i64 %1, %2
  %4 = add i64 %0, %0
  %5 = add i64 %0, %0
  %6 = sub i64 %4, %5
  %7 = add i64 %3, %6
  ret i64 %7
}

attributes #0 = { alwaysinline }

> Optimized LLVM-IR Module

; ModuleID = 'TritonAstModule'
source_filename = "TritonAstModule"

; Function Attrs: alwaysinline
define common i64 @TritonAstFunction() local_unnamed_addr #0 {
TritonAstEntry:
  ret i64 0
}

attributes #0 = { alwaysinline }

> Optimized Triton AST

(_ bv0 64)

Inspiration

It's important to note that this is just an experiment to take the Triton + Arybo efforts in converting TritonAST to LLVM-IR a step further. Optimizing an AST is quite useful sometime, especially when attacking obfuscation or opaque predicates.

tritonastllvmirtranslator's People

Contributors

fvrmatteo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.