{"id":18175083,"url":"https://github.com/sailro/dexer","last_synced_at":"2025-04-04T07:07:21.151Z","repository":{"id":9979645,"uuid":"12007326","full_name":"sailro/Dexer","owner":"sailro","description":"Dexer is an open source framework, written in C#, that reads and writes .DEX files (Dalvik Executable Format) used by the Android Open Source Project.","archived":false,"fork":false,"pushed_at":"2024-11-14T07:34:29.000Z","size":3448,"stargazers_count":92,"open_issues_count":2,"forks_count":27,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-27T12:17:22.243Z","etag":null,"topics":["android","dalvik","dex"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sailro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sailro","patreon":"sailro"}},"created_at":"2013-08-09T18:01:09.000Z","updated_at":"2024-11-20T02:15:30.000Z","dependencies_parsed_at":"2024-04-29T11:24:43.393Z","dependency_job_id":"dcd7aec7-9133-497b-a8e3-9bf543eeba9e","html_url":"https://github.com/sailro/Dexer","commit_stats":{"total_commits":120,"total_committers":3,"mean_commits":40.0,"dds":"0.050000000000000044","last_synced_commit":"ebaa0b239e20345c11c9e21245bda7820dfb3eea"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sailro%2FDexer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sailro%2FDexer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sailro%2FDexer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sailro%2FDexer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sailro","download_url":"https://codeload.github.com/sailro/Dexer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135144,"owners_count":20889421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","dalvik","dex"],"created_at":"2024-11-02T16:08:44.569Z","updated_at":"2025-04-04T07:07:21.119Z","avatar_url":"https://github.com/sailro.png","language":"C#","funding_links":["https://github.com/sponsors/sailro","https://patreon.com/sailro"],"categories":[],"sub_categories":[],"readme":"# Dexer\n[![Build status](https://github.com/sailro/Dexer/workflows/CI/badge.svg)](https://github.com/sailro/Dexer/actions?query=workflow%3ACI)\n[![NuGet](https://img.shields.io/nuget/v/Dexer.svg)](https://www.nuget.org/packages/Dexer/)\n\nDexer is an open source framework, written in C#, that reads and writes .DEX files (Dalvik Executable Format) used by the Android Open Source Project.\n\nUsage:\n\nLet's work on the following Android application:\n```java\npackage dexer.poc;\n \nimport android.app.Activity;\nimport android.os.Bundle;\n \npublic class MainActivity extends Activity {\n \n        @Override\n        public void onCreate(Bundle savedInstanceState) {\n                super.onCreate(savedInstanceState);\n                setContentView(R.layout.main);\n       \n                int a = 4;\n                int b = 5;\n                int result = a*b;\n       \n                setTitle(\"This demo rocks: \" + result);\n        }\n}\n```\n![image](https://user-images.githubusercontent.com/638167/71027080-5c716880-20bf-11ea-8974-489d6ee43469.png)\n\nAnd here is the code of the main method using the Dexer object model:\n![image](https://user-images.githubusercontent.com/638167/71027156-8b87da00-20bf-11ea-8d9e-723fb9bc99a0.png)\n\nNow let’s go back to C# to play a little with this application by changing a string constant and an opcode (adding instead of multiplying):\n```csharp\nusing System;\nusing Dexer.Core;\nusing Dexer.Instructions;\n \nnamespace Dexer.Debug\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            Dex dex = Dex.Load(\"classes.dex\");\n            MethodDefinition method = dex.GetClass(\"dexer.poc.MainActivity\").GetMethod(\"onCreate\");\n \n            method.Body.Instructions[5].OpCode = OpCodes.Add_int;\n            method.Body.Instructions[7].Operand = \"Dexer rocks! \";\n \n            dex.Write(\"output.dex\");\n            Console.ReadLine();\n        }\n    }\n}\n```\n\n![image](https://user-images.githubusercontent.com/638167/71033470-31d9dc80-20cc-11ea-928a-7533bfb3a1a3.png)\n\nHere is the result:\n\n![image](https://user-images.githubusercontent.com/638167/71033535-533ac880-20cc-11ea-872f-6359760e5895.png)\n\nNow let’s call a method to change the title color:\n```csharp\nusing System;\nusing Dexer.Core;\nusing Dexer.Instructions;\n \nnamespace Dexer.Debug\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            Dex dex = Dex.Load(\"classes.dex\");\n            MethodDefinition method = dex.GetClass(\"dexer.poc.MainActivity\").GetMethod(\"onCreate\");\n \n            method.Body.Instructions[5].OpCode = OpCodes.Add_int;\n            method.Body.Instructions[7].Operand = \"Dexer rocks! \";\n \n            int color; unchecked { color = (int)0xFFFF00FF; }\n \n            // Declare a new method reference with prototype\n            Prototype prototype = new Prototype(PrimitiveType.Void, new Parameter(PrimitiveType.Int));\n            MethodReference setTitleColor = dex.Import(new MethodReference(method.Owner, \"setTitleColor\", prototype));\n \n            // Load the color in a register (n°1) then invoke the method (register n°5 is 'this' in our case)\n            var regs = method.Body.Registers;\n            Instruction iconst = new Instruction(OpCodes.Const, color, regs[1]);\n            method.Body.Instructions.Insert(14, iconst);\n \n            Instruction iinvoke = new Instruction(OpCodes.Invoke_virtual, setTitleColor, regs[5], regs[1]);\n            method.Body.Instructions.Insert(15, iinvoke);\n \n            dex.Write(\"output.dex\");\n            Console.ReadLine();\n        }\n    }\n}\n```\n![image](https://user-images.githubusercontent.com/638167/71033577-6cdc1000-20cc-11ea-8e7c-05ef8e544eae.png)\n\nHere is the result:\n\n![image](https://user-images.githubusercontent.com/638167/71033606-7c5b5900-20cc-11ea-8a96-c86ba3bfbc07.png)\n\nAs you can see, altering DEX files is quite easy with Dexer. In order to rebuild APK packages, I’ve used ApkTool and JarSigner (with the default debug key generated by the Android SDK).\n\n```batch\napktool d -s -f DexerPOC.apk output\nI: Copying raw classes.dex file...\nI: Loading resource table...\nI: Decoding resources...\nI: Copying assets and libs...\n\napktool b output DexerPOC.new.apk\nI: Copying classes.dex file...\nI: Checking whether resources has changed...\nI: Building resources...\nI: Building apk file...\n\njarsigner -keystore .\\.android\\debug.keystore -storepass android -keypass android DexerPOC.new.apk androiddebugkey\n\nadb install DexerPOC.new.apk\n586 KB/s (12609 bytes in 0.021s)\n        pkg: /data/local/tmp/DexerPOC.new.apk\nSuccess.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsailro%2Fdexer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsailro%2Fdexer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsailro%2Fdexer/lists"}