{"action":"created","comment":{"url":"https://api.github.com/repos/binjitsu/binjitsu/pulls/comments/32184844","id":32184844,"diff_hunk":"@@ -855,3 +953,185 @@ def call(*args):\n             return self.call(attr, args)\n \n         return call\n+\n+    def build_graph(self):\n+        '''Build gadgets graph, gadget as vertex, reg as edge.\n+        '''\n+        gadget_graph = {}\n+        for gad_1 in self.gadgets.values():\n+            gadget_graph[gad_1] = set()\n+            outputs = []\n+            for i in gad_1.regs.keys():\n+                if isinstance(i, str) and \"[\" not in i:\n+                    outputs.append(i[-2:])\n+\n+            for gad_2 in self.gadgets.values():\n+                if gad_1 == gad_2:\n+                    continue\n+                inputs=[]\n+                for i in gad_2.regs.values():\n+                    if isinstance(i, str) and \"[\" not in i:\n+                        inputs.append(i[-2:])\n+                    if isinstance(i, list):\n+                        for j in i:\n+                            if isinstance(j, str) and \"[\" not in i:\n+                                inputs.append(j[-2:])\n+\n+                inter = set(inputs) & set(outputs)\n+                if len(inter) > 0:\n+                    gadget_graph[gad_1].add(gad_2)\n+\n+        return gadget_graph\n+\n+    def __build_top_sort(self, graph):\n+        \"\"\"\n+        Topological sort a graph.\n+\n+        Arguments:\n+            \n+            graph(dict):\n+                A simple example : graph = {'eax': ['ebx'], 'ebx': ['eax'], 'edx': ['eax']}\n+                May be cycles in graph. we need to handle it.\n+\n+        Return Value:\n+            top_sorted(list):\n+                such as: [\"edx\", \"eax\", \"ebx\"]\n+        \"\"\"\n+        top_sorted = []\n+        indegree_zero = []\n+\n+        #Inital indegree list will zero.\n+        indegree = {}\n+        for k, v in graph.items():\n+            indegree[k] = 0\n+            for l in v:\n+                indegree[l] = 0\n+\n+        #Caculate indegree, for gadget graph.\n+        for g, glist in graph.items():\n+            for gadget in glist:\n+                indegree[gadget] += 1\n+\n+        #inital indegree_zero list.\n+        for g, indeg in indegree.items():\n+            if indeg == 0:\n+                indegree_zero.append(g)\n+        \n+        # TOP sort\n+        while len(indegree_zero) > 0:\n+            n = indegree_zero.pop()\n+            top_sorted.append(n)\n+\n+            if n not in graph.keys():\n+                continue\n+\n+            for m in graph[n]:\n+                indegree[m] -= 1\n+                if indegree[m] == 0:\n+                    indegree_zero.append(m)\n+            del(graph[n])\n+        \n+        if len(graph) == 0:\n+            return top_sorted\n+\n+        # Recursive top sort.\n+        for g, indeg in indegree.items():\n+            if indeg > 1:\n+                for k, glist in graph.items():\n+                    for h in glist:\n+                        if h == g:\n+                            #delete the edge of a cirle.\n+                            graph[k].remove(h)\n+\n+                            #record the deleted edge of cirles.\n+                            if k not in self._global_delete_gadget.keys():\n+                                self._global_delete_gadget[k] = set()\n+                            self._global_delete_gadget[k].add(h)\n+                            \n+                            # Recurisve top sorting.\n+                            last_result = self.__build_top_sort(graph)\n+                            if not last_result:\n+                                last_result = []\n+\n+                            return top_sorted + last_result\n+\n+\n+    def search_path(self, src, regs):\n+        '''Search paths, from src to regs.\n+        Example: search(\"rsp\", [\"rdi\"]), such as gadget \"pop rdi; ret\" will be return to us.","path":"pwnlib/rop/rop.py","position":639,"original_position":288,"commit_id":"79db8b3f4d0ae559c5ab0f86be877ecaa3ddd70a","original_commit_id":"5833cd6273678a263f4308ff115c2687aef78515","user":{"login":"zachriggle","id":111640,"avatar_url":"https://avatars.githubusercontent.com/u/111640?v=3","gravatar_id":"","url":"https://api.github.com/users/zachriggle","html_url":"https://github.com/zachriggle","followers_url":"https://api.github.com/users/zachriggle/followers","following_url":"https://api.github.com/users/zachriggle/following{/other_user}","gists_url":"https://api.github.com/users/zachriggle/gists{/gist_id}","starred_url":"https://api.github.com/users/zachriggle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zachriggle/subscriptions","organizations_url":"https://api.github.com/users/zachriggle/orgs","repos_url":"https://api.github.com/users/zachriggle/repos","events_url":"https://api.github.com/users/zachriggle/events{/privacy}","received_events_url":"https://api.github.com/users/zachriggle/received_events","type":"User","site_admin":false},"body":"Please? :smiley: \r\n\r\nAlso, I'm not sure about the usage of `src`.  What other values could it ever be?  Presumably using `rsp` treats it as the stack, versus other registers are just used as their register value.  I'm not sure how this is actually implemented, though.","created_at":"2015-06-11T02:07:57Z","updated_at":"2015-06-11T02:07:57Z","html_url":"https://github.com/binjitsu/binjitsu/pull/24#discussion_r32184844","pull_request_url":"https://api.github.com/repos/binjitsu/binjitsu/pulls/24","_links":{"self":{"href":"https://api.github.com/repos/binjitsu/binjitsu/pulls/comments/32184844"},"html":{"href":"https://github.com/binjitsu/binjitsu/pull/24#discussion_r32184844"},"pull_request":{"href":"https://api.github.com/repos/binjitsu/binjitsu/pulls/24"}}},"pull_request":{"url":"https://api.github.com/repos/binjitsu/binjitsu/pulls/24","id":36229153,"html_url":"https://github.com/binjitsu/binjitsu/pull/24","diff_url":"https://github.com/binjitsu/binjitsu/pull/24.diff","patch_url":"https://github.com/binjitsu/binjitsu/pull/24.patch","issue_url":"https://api.github.com/repos/binjitsu/binjitsu/issues/24","number":24,"state":"open","locked":false,"title":"Multi arch  ROP module using amoco project","user":{"login":"lieanu","id":3104641,"avatar_url":"https://avatars.githubusercontent.com/u/3104641?v=3","gravatar_id":"","url":"https://api.github.com/users/lieanu","html_url":"https://github.com/lieanu","followers_url":"https://api.github.com/users/lieanu/followers","following_url":"https://api.github.com/users/lieanu/following{/other_user}","gists_url":"https://api.github.com/users/lieanu/gists{/gist_id}","starred_url":"https://api.github.com/users/lieanu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lieanu/subscriptions","organizations_url":"https://api.github.com/users/lieanu/orgs","repos_url":"https://api.github.com/users/lieanu/repos","events_url":"https://api.github.com/users/lieanu/events{/privacy}","received_events_url":"https://api.github.com/users/lieanu/received_events","type":"User","site_admin":false},"body":"Hi, Zach\r\n\r\nI rewrited the automate rop module using [amoco](https://github.com/bdcht/amoco), It's much faster than when using BARF project, about 2 seconds average. \r\n\r\nThe tests in [https://github.com/lieanu/test_for_multiarch_rop](https://github.com/lieanu/test_for_multiarch_rop) passed.\r\n\r\nRegards,","created_at":"2015-05-26T18:04:10Z","updated_at":"2015-06-11T02:07:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b743d2b4d0a367d430aecfa0e848c5dcf9002bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/binjitsu/binjitsu/pulls/24/commits","review_comments_url":"https://api.github.com/repos/binjitsu/binjitsu/pulls/24/comments","review_comment_url":"https://api.github.com/repos/binjitsu/binjitsu/pulls/comments{/number}","comments_url":"https://api.github.com/repos/binjitsu/binjitsu/issues/24/comments","statuses_url":"https://api.github.com/repos/binjitsu/binjitsu/statuses/79db8b3f4d0ae559c5ab0f86be877ecaa3ddd70a","head":{"label":"lieanu:automate_rop","ref":"automate_rop","sha":"79db8b3f4d0ae559c5ab0f86be877ecaa3ddd70a","user":{"login":"lieanu","id":3104641,"avatar_url":"https://avatars.githubusercontent.com/u/3104641?v=3","gravatar_id":"","url":"https://api.github.com/users/lieanu","html_url":"https://github.com/lieanu","followers_url":"https://api.github.com/users/lieanu/followers","following_url":"https://api.github.com/users/lieanu/following{/other_user}","gists_url":"https://api.github.com/users/lieanu/gists{/gist_id}","starred_url":"https://api.github.com/users/lieanu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lieanu/subscriptions","organizations_url":"https://api.github.com/users/lieanu/orgs","repos_url":"https://api.github.com/users/lieanu/repos","events_url":"https://api.github.com/users/lieanu/events{/privacy}","received_events_url":"https://api.github.com/users/lieanu/received_events","type":"User","site_admin":false},"repo":{"id":32589108,"name":"binjitsu","full_name":"lieanu/binjitsu","owner":{"login":"lieanu","id":3104641,"avatar_url":"https://avatars.githubusercontent.com/u/3104641?v=3","gravatar_id":"","url":"https://api.github.com/users/lieanu","html_url":"https://github.com/lieanu","followers_url":"https://api.github.com/users/lieanu/followers","following_url":"https://api.github.com/users/lieanu/following{/other_user}","gists_url":"https://api.github.com/users/lieanu/gists{/gist_id}","starred_url":"https://api.github.com/users/lieanu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lieanu/subscriptions","organizations_url":"https://api.github.com/users/lieanu/orgs","repos_url":"https://api.github.com/users/lieanu/repos","events_url":"https://api.github.com/users/lieanu/events{/privacy}","received_events_url":"https://api.github.com/users/lieanu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lieanu/binjitsu","description":"CTF framework and exploit development library","fork":true,"url":"https://api.github.com/repos/lieanu/binjitsu","forks_url":"https://api.github.com/repos/lieanu/binjitsu/forks","keys_url":"https://api.github.com/repos/lieanu/binjitsu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lieanu/binjitsu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lieanu/binjitsu/teams","hooks_url":"https://api.github.com/repos/lieanu/binjitsu/hooks","issue_events_url":"https://api.github.com/repos/lieanu/binjitsu/issues/events{/number}","events_url":"https://api.github.com/repos/lieanu/binjitsu/events","assignees_url":"https://api.github.com/repos/lieanu/binjitsu/assignees{/user}","branches_url":"https://api.github.com/repos/lieanu/binjitsu/branches{/branch}","tags_url":"https://api.github.com/repos/lieanu/binjitsu/tags","blobs_url":"https://api.github.com/repos/lieanu/binjitsu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lieanu/binjitsu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lieanu/binjitsu/git/refs{/sha}","trees_url":"https://api.github.com/repos/lieanu/binjitsu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lieanu/binjitsu/statuses/{sha}","languages_url":"https://api.github.com/repos/lieanu/binjitsu/languages","stargazers_url":"https://api.github.com/repos/lieanu/binjitsu/stargazers","contributors_url":"https://api.github.com/repos/lieanu/binjitsu/contributors","subscribers_url":"https://api.github.com/repos/lieanu/binjitsu/subscribers","subscription_url":"https://api.github.com/repos/lieanu/binjitsu/subscription","commits_url":"https://api.github.com/repos/lieanu/binjitsu/commits{/sha}","git_commits_url":"https://api.github.com/repos/lieanu/binjitsu/git/commits{/sha}","comments_url":"https://api.github.com/repos/lieanu/binjitsu/comments{/number}","issue_comment_url":"https://api.github.com/repos/lieanu/binjitsu/issues/comments{/number}","contents_url":"https://api.github.com/repos/lieanu/binjitsu/contents/{+path}","compare_url":"https://api.github.com/repos/lieanu/binjitsu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lieanu/binjitsu/merges","archive_url":"https://api.github.com/repos/lieanu/binjitsu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lieanu/binjitsu/downloads","issues_url":"https://api.github.com/repos/lieanu/binjitsu/issues{/number}","pulls_url":"https://api.github.com/repos/lieanu/binjitsu/pulls{/number}","milestones_url":"https://api.github.com/repos/lieanu/binjitsu/milestones{/number}","notifications_url":"https://api.github.com/repos/lieanu/binjitsu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lieanu/binjitsu/labels{/name}","releases_url":"https://api.github.com/repos/lieanu/binjitsu/releases{/id}","created_at":"2015-03-20T14:42:12Z","updated_at":"2015-05-22T03:48:47Z","pushed_at":"2015-06-11T01:40:24Z","git_url":"git://github.com/lieanu/binjitsu.git","ssh_url":"git@github.com:lieanu/binjitsu.git","clone_url":"https://github.com/lieanu/binjitsu.git","svn_url":"https://github.com/lieanu/binjitsu","homepage":"https://binjit.su","size":18880,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"binjitsu:master","ref":"master","sha":"c3b006ef5089a8da91037a6284c5a35d7ae6bf4c","user":{"login":"binjitsu","id":6656233,"avatar_url":"https://avatars.githubusercontent.com/u/6656233?v=3","gravatar_id":"","url":"https://api.github.com/users/binjitsu","html_url":"https://github.com/binjitsu","followers_url":"https://api.github.com/users/binjitsu/followers","following_url":"https://api.github.com/users/binjitsu/following{/other_user}","gists_url":"https://api.github.com/users/binjitsu/gists{/gist_id}","starred_url":"https://api.github.com/users/binjitsu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binjitsu/subscriptions","organizations_url":"https://api.github.com/users/binjitsu/orgs","repos_url":"https://api.github.com/users/binjitsu/repos","events_url":"https://api.github.com/users/binjitsu/events{/privacy}","received_events_url":"https://api.github.com/users/binjitsu/received_events","type":"Organization","site_admin":false},"repo":{"id":29157870,"name":"binjitsu","full_name":"binjitsu/binjitsu","owner":{"login":"binjitsu","id":6656233,"avatar_url":"https://avatars.githubusercontent.com/u/6656233?v=3","gravatar_id":"","url":"https://api.github.com/users/binjitsu","html_url":"https://github.com/binjitsu","followers_url":"https://api.github.com/users/binjitsu/followers","following_url":"https://api.github.com/users/binjitsu/following{/other_user}","gists_url":"https://api.github.com/users/binjitsu/gists{/gist_id}","starred_url":"https://api.github.com/users/binjitsu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binjitsu/subscriptions","organizations_url":"https://api.github.com/users/binjitsu/orgs","repos_url":"https://api.github.com/users/binjitsu/repos","events_url":"https://api.github.com/users/binjitsu/events{/privacy}","received_events_url":"https://api.github.com/users/binjitsu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/binjitsu/binjitsu","description":"CTF framework and exploit development library","fork":true,"url":"https://api.github.com/repos/binjitsu/binjitsu","forks_url":"https://api.github.com/repos/binjitsu/binjitsu/forks","keys_url":"https://api.github.com/repos/binjitsu/binjitsu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/binjitsu/binjitsu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/binjitsu/binjitsu/teams","hooks_url":"https://api.github.com/repos/binjitsu/binjitsu/hooks","issue_events_url":"https://api.github.com/repos/binjitsu/binjitsu/issues/events{/number}","events_url":"https://api.github.com/repos/binjitsu/binjitsu/events","assignees_url":"https://api.github.com/repos/binjitsu/binjitsu/assignees{/user}","branches_url":"https://api.github.com/repos/binjitsu/binjitsu/branches{/branch}","tags_url":"https://api.github.com/repos/binjitsu/binjitsu/tags","blobs_url":"https://api.github.com/repos/binjitsu/binjitsu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/binjitsu/binjitsu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/binjitsu/binjitsu/git/refs{/sha}","trees_url":"https://api.github.com/repos/binjitsu/binjitsu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/binjitsu/binjitsu/statuses/{sha}","languages_url":"https://api.github.com/repos/binjitsu/binjitsu/languages","stargazers_url":"https://api.github.com/repos/binjitsu/binjitsu/stargazers","contributors_url":"https://api.github.com/repos/binjitsu/binjitsu/contributors","subscribers_url":"https://api.github.com/repos/binjitsu/binjitsu/subscribers","subscription_url":"https://api.github.com/repos/binjitsu/binjitsu/subscription","commits_url":"https://api.github.com/repos/binjitsu/binjitsu/commits{/sha}","git_commits_url":"https://api.github.com/repos/binjitsu/binjitsu/git/commits{/sha}","comments_url":"https://api.github.com/repos/binjitsu/binjitsu/comments{/number}","issue_comment_url":"https://api.github.com/repos/binjitsu/binjitsu/issues/comments{/number}","contents_url":"https://api.github.com/repos/binjitsu/binjitsu/contents/{+path}","compare_url":"https://api.github.com/repos/binjitsu/binjitsu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/binjitsu/binjitsu/merges","archive_url":"https://api.github.com/repos/binjitsu/binjitsu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/binjitsu/binjitsu/downloads","issues_url":"https://api.github.com/repos/binjitsu/binjitsu/issues{/number}","pulls_url":"https://api.github.com/repos/binjitsu/binjitsu/pulls{/number}","milestones_url":"https://api.github.com/repos/binjitsu/binjitsu/milestones{/number}","notifications_url":"https://api.github.com/repos/binjitsu/binjitsu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/binjitsu/binjitsu/labels{/name}","releases_url":"https://api.github.com/repos/binjitsu/binjitsu/releases{/id}","created_at":"2015-01-12T21:28:40Z","updated_at":"2015-06-08T09:00:55Z","pushed_at":"2015-06-11T01:40:24Z","git_url":"git://github.com/binjitsu/binjitsu.git","ssh_url":"git@github.com:binjitsu/binjitsu.git","clone_url":"https://github.com/binjitsu/binjitsu.git","svn_url":"https://github.com/binjitsu/binjitsu","homepage":"https://binjit.su","size":21584,"stargazers_count":74,"watchers_count":74,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":11,"mirror_url":null,"open_issues_count":9,"forks":11,"open_issues":9,"watchers":74,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/binjitsu/binjitsu/pulls/24"},"html":{"href":"https://github.com/binjitsu/binjitsu/pull/24"},"issue":{"href":"https://api.github.com/repos/binjitsu/binjitsu/issues/24"},"comments":{"href":"https://api.github.com/repos/binjitsu/binjitsu/issues/24/comments"},"review_comments":{"href":"https://api.github.com/repos/binjitsu/binjitsu/pulls/24/comments"},"review_comment":{"href":"https://api.github.com/repos/binjitsu/binjitsu/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/binjitsu/binjitsu/pulls/24/commits"},"statuses":{"href":"https://api.github.com/repos/binjitsu/binjitsu/statuses/79db8b3f4d0ae559c5ab0f86be877ecaa3ddd70a"}}}}