{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/binskim/pulls/comments/47421716","id":47421716,"diff_hunk":"@@ -0,0 +1,741 @@\n+﻿// Copyright (c) Microsoft. All rights reserved.\n+// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n+\n+using System;\n+using System.Collections.Generic;\n+using System.Collections.Immutable;\n+using System.Diagnostics;\n+using System.Reflection.Metadata;\n+\n+using Microsoft.CodeAnalysis.Semantics;\n+\n+using ILExceptionRegion = System.Reflection.Metadata.ExceptionRegion;\n+\n+namespace Microsoft.CodeAnalysis.IL\n+{\n+    internal partial class ILImporter\n+    {\n+        private Compilation _compilation;\n+        private IMethodSymbol _method;\n+        private byte[] _ilBytes;\n+        private ExceptionRegion[] _exceptionRegions;\n+        private List<IStatement> _statements;\n+        private int _labelCount;\n+\n+        public ILImporter(Compilation compilation, IMethodSymbol method, MethodBodyBlock body)\n+        {\n+            if (body.ExceptionRegions.Length != 0)\n+            {\n+                throw new NotImplementedException();\n+            }\n+\n+            _compilation = compilation;\n+            _method = method;\n+            _ilBytes = body.GetILBytes();\n+            _exceptionRegions = new ExceptionRegion[0];\n+            _statements = new List<IStatement>();\n+        }\n+\n+        public IBlockStatement Import()\n+        {\n+            FindBasicBlocks();\n+            ImportBasicBlocks();\n+\n+            var statements = ImmutableArray.CreateBuilder<IStatement>(_statements.Count + _labelCount);\n+\n+            foreach (var block in _basicBlocks)\n+            {\n+                if (block != null)\n+                {\n+                    if (block.Label != null)\n+                    {\n+                        statements.Add(new LabelStatement(block.Label));\n+                    }\n+\n+                    for (int i = block.FirstStatementOffset; i <= block.LastStatementOffset; i++)\n+                    {\n+                        statements.Add(_statements[i]);\n+                    }\n+                }\n+            }\n+\n+            return new BlockStatement(ImmutableArray<ILocalSymbol>.Empty, statements.MoveToImmutable());\n+        }\n+\n+        private void Push(StackValue value)\n+        {\n+            if (_stackTop >= _stack.Length)\n+            {\n+                Array.Resize(ref _stack, 2 * _stackTop + 3);\n+            }\n+\n+            _stack[_stackTop++] = value;\n+        }\n+\n+        private void Push(StackValueKind kind, IExpression expression)\n+        {\n+            Push(new StackValue(kind, expression));\n+        }\n+\n+        private StackValue Pop()\n+        {\n+            if (_stackTop == 0)\n+            {\n+                throw new BadImageFormatException();\n+            }\n+\n+            return _stack[--_stackTop];\n+        }\n+\n+        private void Append(IStatement statement)\n+        {\n+            ReqireEmptyStackForNow();\n+            _statements.Add(statement);\n+        }\n+\n+        private void ReqireEmptyStackForNow()\n+        {\n+            if (_stackTop != 0)\n+            {\n+                // TODO: We don't yet have the machinery to (1) move between basic\n+                // blocks or (2) append statements when the operand stack isn't empty. \n+                // We'll have to create temporaries to deal with those cases.\n+                //\n+                // (2) might not be as obviously problematic, but if we leave \n+                // expressions on the stack and emit a statement, we'd create\n+                // a tree that does not preserve execution order semantics.\n+                throw new NotImplementedException();\n+            }\n+        }\n+\n+        private ITypeSymbol GetWellKnownType(WellKnownType wellKnownType)\n+        {\n+            return _compilation.GetSpecialType((SpecialType)wellKnownType);\n+        }\n+\n+        private void MarkInstructionBoundary()\n+        {\n+        }\n+\n+        private void StartImportingInstruction()\n+        {\n+        }\n+\n+        private void EndImportingInstruction()\n+        {\n+        }\n+\n+        private void StartImportingBasicBlock(BasicBlock basicBlock)\n+        {\n+            basicBlock.FirstStatementOffset = _statements.Count;\n+        }\n+\n+        private void EndImportingBasicBlock(BasicBlock basicBlock)\n+        {\n+            basicBlock.LastStatementOffset = _statements.Count - 1;\n+        }\n+\n+        private void ImportNop()\n+        {\n+        }\n+\n+        private void ImportBreak()\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportLoadVar(int index, bool argument)\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportStoreVar(int index, bool argument)\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportAddressOfVar(int index, bool argument)\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportDup()\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportPop()\n+        {\n+            Append(new ExpressionStatement(Pop().Expression));\n+        }\n+\n+        private void ImportJmp(int token)\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportCasting(ILOpcode opcode, int token)\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportCall(ILOpcode opcode, int token)\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportLdFtn(int token, ILOpcode opCode)\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportLoadInt(long value, StackValueKind kind)\n+        {\n+            object boxedValue;\n+            ITypeSymbol type;\n+\n+            if (kind == StackValueKind.Int32)\n+            {\n+                boxedValue = (int)value;\n+                type = Int32Type;\n+            }\n+            else\n+            {\n+                Debug.Assert(kind == StackValueKind.Int64);\n+                boxedValue = value;\n+                type = Int64Type;\n+            }\n+\n+            Push(kind, new LiteralExpression(boxedValue, type));\n+        }\n+\n+        private void ImportLoadFloat(double value)\n+        {\n+            Push(StackValueKind.Float, new LiteralExpression(value, DoubleType));\n+        }\n+\n+        private void ImportLoadNull()\n+        {\n+            Push(StackValueKind.ObjRef, new LiteralExpression(null, ObjectType));\n+        }\n+\n+        private void ImportReturn()\n+        {\n+            Append(new ReturnStatement(_method.ReturnsVoid ? null : Pop().Expression));\n+        }\n+\n+        private void ImportFallthrough(BasicBlock next)\n+        {\n+            ReqireEmptyStackForNow();\n+            MarkBasicBlock(next);\n+        }\n+\n+        private void ImportSwitchJump(int jmpBase, int[] jmpDelta, BasicBlock fallthrough)\n+        {\n+            throw new NotImplementedException();\n+        }\n+\n+        private void ImportBranch(ILOpcode opcode, BasicBlock target, BasicBlock fallthrough)\n+        {\n+            StackValue left, right;\n+\n+            if (opcode == ILOpcode.brtrue || opcode == ILOpcode.brfalse)\n+            {\n+                left = Pop();","path":"src/BinSkim.Driver/RoslynAnalyzer/ILImporter.cs","position":244,"original_position":244,"commit_id":"b72b5d5f86e02af1bb03a1fbe816783081bb030e","original_commit_id":"b72b5d5f86e02af1bb03a1fbe816783081bb030e","user":{"login":"michaelcfanning","id":13526455,"avatar_url":"https://avatars.githubusercontent.com/u/13526455?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelcfanning","html_url":"https://github.com/michaelcfanning","followers_url":"https://api.github.com/users/michaelcfanning/followers","following_url":"https://api.github.com/users/michaelcfanning/following{/other_user}","gists_url":"https://api.github.com/users/michaelcfanning/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelcfanning/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelcfanning/subscriptions","organizations_url":"https://api.github.com/users/michaelcfanning/orgs","repos_url":"https://api.github.com/users/michaelcfanning/repos","events_url":"https://api.github.com/users/michaelcfanning/events{/privacy}","received_events_url":"https://api.github.com/users/michaelcfanning/received_events","type":"User","site_admin":false},"body":"ok, I get this code. I think I would have authored this to conditionally create a one or a zero literal based on input opcode, and then change opcode for both cases to ILOpcode.beq. :P","created_at":"2015-12-12T00:30:41Z","updated_at":"2015-12-12T00:30:41Z","html_url":"https://github.com/Microsoft/binskim/pull/10#discussion_r47421716","pull_request_url":"https://api.github.com/repos/Microsoft/binskim/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/binskim/pulls/comments/47421716"},"html":{"href":"https://github.com/Microsoft/binskim/pull/10#discussion_r47421716"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/binskim/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/binskim/pulls/10","id":53458371,"html_url":"https://github.com/Microsoft/binskim/pull/10","diff_url":"https://github.com/Microsoft/binskim/pull/10.diff","patch_url":"https://github.com/Microsoft/binskim/pull/10.patch","issue_url":"https://api.github.com/repos/Microsoft/binskim/issues/10","number":10,"state":"open","locked":false,"title":"[WIP] IL -> IOperation","user":{"login":"nguerrera","id":75470,"avatar_url":"https://avatars.githubusercontent.com/u/75470?v=3","gravatar_id":"","url":"https://api.github.com/users/nguerrera","html_url":"https://github.com/nguerrera","followers_url":"https://api.github.com/users/nguerrera/followers","following_url":"https://api.github.com/users/nguerrera/following{/other_user}","gists_url":"https://api.github.com/users/nguerrera/gists{/gist_id}","starred_url":"https://api.github.com/users/nguerrera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nguerrera/subscriptions","organizations_url":"https://api.github.com/users/nguerrera/orgs","repos_url":"https://api.github.com/users/nguerrera/repos","events_url":"https://api.github.com/users/nguerrera/events{/privacy}","received_events_url":"https://api.github.com/users/nguerrera/received_events","type":"User","site_admin":false},"body":"@JohnHamby @michaelcfanning @srivatsn @tmat \r\n\r\nBaby steps towards raising IL to IOperation...\r\n\r\nThis isn't a traditional PR  -- it's just a live snapshot of where I'm at for those who might be interested in following progress. I'll continue to commit to this branch regularly as I bring more things online.\r\n\r\nThere's a lot that's not implemented at all yet, and I'm sure there are still embarrassing bugs in what is done, but do feel free to comment any time. \r\n\r\n@JohnHamby: I'm putting `// FEEDBACK` comments for questions around the IOperation API.\r\n\r\n\r\n","created_at":"2015-12-11T23:42:16Z","updated_at":"2015-12-12T00:30:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cdd19a57e6f77f59b50c1abeda302e9db8e18899","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/binskim/pulls/10/commits","review_comments_url":"https://api.github.com/repos/Microsoft/binskim/pulls/10/comments","review_comment_url":"https://api.github.com/repos/Microsoft/binskim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/binskim/issues/10/comments","statuses_url":"https://api.github.com/repos/Microsoft/binskim/statuses/b72b5d5f86e02af1bb03a1fbe816783081bb030e","head":{"label":"Microsoft:il-to-ioperation-dev","ref":"il-to-ioperation-dev","sha":"b72b5d5f86e02af1bb03a1fbe816783081bb030e","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":43526494,"name":"binskim","full_name":"Microsoft/binskim","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/binskim","description":"A binary static analysis tool that provides security and correctness results for Windows portable executables.","fork":false,"url":"https://api.github.com/repos/Microsoft/binskim","forks_url":"https://api.github.com/repos/Microsoft/binskim/forks","keys_url":"https://api.github.com/repos/Microsoft/binskim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/binskim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/binskim/teams","hooks_url":"https://api.github.com/repos/Microsoft/binskim/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/binskim/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/binskim/events","assignees_url":"https://api.github.com/repos/Microsoft/binskim/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/binskim/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/binskim/tags","blobs_url":"https://api.github.com/repos/Microsoft/binskim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/binskim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/binskim/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/binskim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/binskim/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/binskim/languages","stargazers_url":"https://api.github.com/repos/Microsoft/binskim/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/binskim/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/binskim/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/binskim/subscription","commits_url":"https://api.github.com/repos/Microsoft/binskim/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/binskim/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/binskim/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/binskim/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/binskim/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/binskim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/binskim/merges","archive_url":"https://api.github.com/repos/Microsoft/binskim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/binskim/downloads","issues_url":"https://api.github.com/repos/Microsoft/binskim/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/binskim/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/binskim/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/binskim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/binskim/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/binskim/releases{/id}","created_at":"2015-10-01T23:25:39Z","updated_at":"2015-12-02T00:56:32Z","pushed_at":"2015-12-11T23:46:57Z","git_url":"git://github.com/Microsoft/binskim.git","ssh_url":"git@github.com:Microsoft/binskim.git","clone_url":"https://github.com/Microsoft/binskim.git","svn_url":"https://github.com/Microsoft/binskim","homepage":null,"size":17822,"stargazers_count":6,"watchers_count":6,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":6,"default_branch":"master"}},"base":{"label":"Microsoft:il-to-ioperation","ref":"il-to-ioperation","sha":"c1d07c2fc09cc611827b99b7225286a79bdbcb14","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":43526494,"name":"binskim","full_name":"Microsoft/binskim","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/binskim","description":"A binary static analysis tool that provides security and correctness results for Windows portable executables.","fork":false,"url":"https://api.github.com/repos/Microsoft/binskim","forks_url":"https://api.github.com/repos/Microsoft/binskim/forks","keys_url":"https://api.github.com/repos/Microsoft/binskim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/binskim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/binskim/teams","hooks_url":"https://api.github.com/repos/Microsoft/binskim/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/binskim/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/binskim/events","assignees_url":"https://api.github.com/repos/Microsoft/binskim/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/binskim/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/binskim/tags","blobs_url":"https://api.github.com/repos/Microsoft/binskim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/binskim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/binskim/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/binskim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/binskim/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/binskim/languages","stargazers_url":"https://api.github.com/repos/Microsoft/binskim/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/binskim/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/binskim/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/binskim/subscription","commits_url":"https://api.github.com/repos/Microsoft/binskim/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/binskim/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/binskim/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/binskim/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/binskim/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/binskim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/binskim/merges","archive_url":"https://api.github.com/repos/Microsoft/binskim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/binskim/downloads","issues_url":"https://api.github.com/repos/Microsoft/binskim/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/binskim/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/binskim/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/binskim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/binskim/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/binskim/releases{/id}","created_at":"2015-10-01T23:25:39Z","updated_at":"2015-12-02T00:56:32Z","pushed_at":"2015-12-11T23:46:57Z","git_url":"git://github.com/Microsoft/binskim.git","ssh_url":"git@github.com:Microsoft/binskim.git","clone_url":"https://github.com/Microsoft/binskim.git","svn_url":"https://github.com/Microsoft/binskim","homepage":null,"size":17822,"stargazers_count":6,"watchers_count":6,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/binskim/pulls/10"},"html":{"href":"https://github.com/Microsoft/binskim/pull/10"},"issue":{"href":"https://api.github.com/repos/Microsoft/binskim/issues/10"},"comments":{"href":"https://api.github.com/repos/Microsoft/binskim/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/binskim/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/binskim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/binskim/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/binskim/statuses/b72b5d5f86e02af1bb03a1fbe816783081bb030e"}}}}