Giter Site home page Giter Site logo

unicorn.cr's Introduction

unicorn.cr

Crystal bindings for Unicorn Engine.

Installation

Add this to your application's shard.yml:

dependencies:
  unicorn:
    github: becojo/unicorn.cr

Usage

require "unicorn/all"

# Create a new instance of unicorn engine to emulate X86-32
mu = Uc.new(UC_ARCH_X86, UC_MODE_32)

code = "\x83\xc0{" # add eax, 123

# Map 1 mb of memory at address 0
mu.mem_map(0, 1024 * 1024)

# Write the code
mu.mem_write(0, code)

# Set eax = 54
mu.reg_write(UC_X86_REG_EAX, 54)

# Tracing all instructions with customized callback
mu.hook_code do |address, size|
  puts ">>> Tracing instruction at 0x%x, instruction size = 0x%x" % {address, size}
end

# Tracing all memory READ & WRITE access
mu.hook_mem(UC_HOOK_MEM_READ | UC_HOOK_MEM_WRITE) { |access, address, size, value|
  if access == UC_MEM_WRITE
    puts ">>> Memory is being WRITE at 0x%x, data size = %d, data value = 0x%x" % {address, size, value}
  else
    puts ">>> Memory is being READ at 0x%x, data size = %d" % {address, size}
  end
}

mu.hook_block do |address, size|
  puts ">>> Tracing basic block at 0x%x, block size = 0x%x" % {address, size}
end

# Run the code
mu.emu_start(0, code.size)

# Inspect resulting context
r_eax = mu.reg_read(UC_X86_REG_EAX)

puts "123 + 54 = #{r_eax}"

Output:

$ crystal samples/readme.cr
>>> Tracing basic block at 0x0, block size = 0x3
>>> Tracing instruction at 0x0, instruction size = 0x3
123 + 54 = 177

Contributing

  1. Fork it (https://github.com/becojo/unicorn/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

unicorn.cr's People

Contributors

becojo avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

unicorn.cr's Issues

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.