-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.rb
More file actions
47 lines (36 loc) · 1.1 KB
/
main.rb
File metadata and controls
47 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'sinatra'
require 'hexdump'
require 'shellwords'
include FileUtils::Verbose
get '/upload' do
erb :upload
end
post '/upload' do
ida_path = '/home/user/.wine/drive_c/Program\ Files\ \(x86\)/IDA\ 6.6/idaw.exe'
if params[:file].nil?
return "You must specificy the file to process"
end
# Copy the uploaded file for analysis
tmp_name = SecureRandom.hex
tmp_file = "/tmp/#{tmp_name}"
if params[:file][:filename] =~ /\.idb$/
tmp_file = "#{tmp_file}.idb"
end
cp(params[:file][:tempfile].path, tmp_file)
# Make sure the file type is supported
mime = `file #{tmp_file}`
functions = Shellwords.escape(params[:functions])
res = system("wine #{ida_path} -Ohexrays:-nosave:#{tmp_name}:#{functions} -A #{tmp_file}")
if res
if File.exists?("#{tmp_name}.c")
content_type 'text/x-c'
return IO.binread("#{tmp_name}.c").gsub(/\r\n/, "\n")
else
content_type 'text/plain'
return "ERROR: decompilation finished successfully but no output file was created"
end
else
content_type 'text/plain'
return "ERROR: decompilation failed"
end
end