Skip to content

Instantly share code, notes, and snippets.

@bdurrani
Last active September 25, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdurrani/2ccb6e89a6156c1dac06 to your computer and use it in GitHub Desktop.
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
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