Last active
September 25, 2015 14:26
-
-
Save bdurrani/2ccb6e89a6156c1dac06 to your computer and use it in GitHub Desktop.
Parse the output of objdump -d -M intel and print out the byte code as an array of hex bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.Diagnostics | |
open System.Globalization | |
let inline flip f x y = f y x | |
let parseLine(input:string) = | |
let trimmed = input.Trim() | |
if String.IsNullOrWhiteSpace trimmed || (trimmed.Contains("\t") |> not) then | |
Array.create 0 "" | |
else | |
let temp = trimmed.Split[|'\t'|] | |
|> Array.filter (String.IsNullOrWhiteSpace >> not) | |
|> flip Array.get 1 | |
temp.Trim().Split[|' ';'\t'|] | |
|> Array.filter (String.IsNullOrWhiteSpace >> not) | |
|> Array.filter (fun x-> x.Length = 2 ) | |
|> Array.filter ( fun x -> | |
let x,_ = Byte.TryParse (x ,NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture) | |
x | |
) | |
[<EntryPoint>] | |
let main argv = | |
let lines = | |
argv.[0] | |
|> IO.File.ReadAllLines | |
|> Seq.skipWhile(fun x -> (x.Contains(@"<main>") |> not) ) | |
|> Seq.skip 1 | |
|> Seq.skipWhile( String.IsNullOrEmpty) | |
|> Seq.collect parseLine | |
|> Seq.map (fun x -> @"0x" + x + @",") | |
|> Seq.fold (fun acc curr -> acc + curr) "" | |
Debug.WriteLine(lines) | |
0 // return an integer exit code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment