Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Binary patching for fun and profit
Search
Anton Arhipov
February 26, 2012
Technology
91
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Binary patching for fun and profit
Anton Arhipov
February 26, 2012
More Decks by Anton Arhipov
See All by Anton Arhipov
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
650
Spec-Driven Development with AI Agents (Workshop, May 2026)
antonarhipov
4
570
Spec-Driven Development with AI Agents. Java Day Istanbul 2026
antonarhipov
3
150
Spec-Driven Development with AI Agents: From High-Level Requirements to Working Software
antonarhipov
3
180
Strengthening Immutability in Kotlin. A Glimpse into Valhalla
antonarhipov
3
120
Kotlin—the New and Noteworthy in 2.2
antonarhipov
1
58
Levels of AI-assisted programming
antonarhipov
0
180
Devoxx France 2024. Kotlin - the new and noteworthy
antonarhipov
2
120
Harnessing the power of AI in IntelliJ IDEA
antonarhipov
1
270
Other Decks in Technology
See All in Technology
Sigmaユーザーのための有用リソース一挙公開 & Sigmaで使えるMCP #sigma_ucj /useful-resources-for-sigma-computing-users-and-mcps-with-sigma
shinyaa31
0
140
Benchmarking Vector Databases: pgvector vs. LanceDB
tsho
0
150
データエンジニアの困りごとをDevinと一緒に解消する
10xinc
2
840
AI時代のAPI品質を支えるガードレール / API Guardrails for API quality in the AI era
yokawasa
1
130
Amazon S3 Tablesに全部任せてみた結果——コンパクション/スナップショット管理は本当に手放せるか
shigeruoda
0
410
Azure App Service / Container Apps の組み込み認証
kuniteru
0
210
enechainの内製セルフサービスプラットフォーム
hiyosi
0
120
推論の観測、できていますか? 〜 Google Cloud Gemini Enterprise Agent Platformで 3つの Gemini モデルを実測して踏んだ、評価の罠 〜
shukob
PRO
0
160
多層防御と最⼩権限で実現する、安全なAIエージェント設計パターン
lycorptech_jp
PRO
0
210
Bet AI Day 2026丨Production-Ready AI Agents — エンタープライズの実務を任せるための設計と運用
layerx
PRO
3
2.5k
Where Is JetBrains AI Heading- — Central CLI, Air Alpha, and the Agentic Development Stack
x5gtrn
PRO
0
140
GuardDuty 検知対応を DevOps Agent で効率化しようとしている話 / GuardDuty Investigations with DevOps Agent
masahirokawahara
1
320
Featured
See All Featured
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
Exploring anti-patterns in Rails
aemeredith
3
490
Why Our Code Smells
bkeepers
PRO
340
58k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Statistics for Hackers
jakevdp
799
230k
Technical Leadership for Architectural Decision Making
baasie
3
550
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
420
How GitHub (no longer) Works
holman
316
150k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
A Soul's Torment
seathinner
7
3.5k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
320
Transcript
Binary Patching for Fun and Profit with
JRebel SDK
Binary Patching 10101010101 11000101010 10101010001 00010001110 11011101011 10101010101 11100001010
10101010001 00010001110 11011101110 Ninja.class Ninja.class’ a.k.a instrumenta9on
Binary Patching MyClass.class New code: 1001010010010 0101011001010 ClassLoader MyObject
Transformer Application
Why? • Programming model (AOP, ORM) • Tooling
(profilers, coverage) • Legacy integraFon … or maybe you’re just bored? J
How? • Add –javaagent to hook into class loading
process • Implement ClassFileTransformer • Use bytecode manipulaFon libraries (Javassist, cglib, asm) to add any custom logic java.lang.instrument
java.lang.instrument import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumenta9on; public
class Agent { public sta9c void premain(String args, Instrumenta9on inst) throws Excep9on { inst.addTransformer(new ClassFileTransformer { … }); } }
java.lang.instrument import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumenta9on; public
class Agent { public sta9c void premain(String args, Instrumenta9on inst) throws Excep9on { inst.addTransformer(new ClassFileTransformer { … }); } }
java.lang.instrument import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumenta9on; public
class Agent { public sta9c void premain(String args, Instrumenta9on inst) throws Excep9on { inst.addTransformer(new ClassFileTransformer { … }); } } META-INF/MANIFEST.MF Premain-Class: Agent java –javaagent:agent.jar …
j.l.instrument.ClassFileTransformer new ClassFileTransformer() { public byte[] transform(ClassLoader loader, String
className, Class<?>classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer){ ClassPool cp = ClassPool.getDefault(); CtClass ct = cp.makeClass(new ByteArrayInputStream(classfileBuffer)); transformClass(ct, cp); return ct.toBytecode(); } }
j.l.instrument.ClassFileTransformer new ClassFileTransformer() { public byte[] transform(ClassLoader loader, String
className, Class<?>classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer){ ClassPool cp = ClassPool.getDefault(); CtClass ct = cp.makeClass(new ByteArrayInputStream(classfileBuffer)); transformClass(ct, cp); return ct.toBytecode(); } }
j.l.instrument.ClassFileTransformer new ClassFileTransformer() { public byte[] transform(ClassLoader loader, String
className, Class<?>classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer){ ClassPool cp = ClassPool.getDefault(); CtClass ct = cp.makeClass(new ByteArrayInputStream(classfileBuffer)); transformClass(ct, cp); return ct.toBytecode(); } }
j.l.instrument.ClassFileTransformer new ClassFileTransformer() { public byte[] transform(ClassLoader loader, String
className, Class<?>classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer){ ClassPool cp = ClassPool.getDefault(); CtClass ct = cp.makeClass(new ByteArrayInputStream(classfileBuffer)); transformClass(ct, cp); return ct.toBytecode(); } }
Javassist 1-‐2-‐3
Javassist • Bytecode manipulaFon made easy • Source-‐level
and bytecode-‐level API • Uses the vocabulary of Java language • On-‐the-‐fly compilaFon of the injected code • hVp://www.jboss.org/javassist
Adding Interfaces ClassPool cp = ClassPool.getDefault(); CtClass
ct = cp.get("org.geecon.Alarm"); ct.addInterface(cp.get(Listener.class.getName())); ct.addMethod(CtNewMethod.make("public void fire(){ alert(); }", ct)); public interface Listener { void fire(); } public class Alarm { void alert() {} }
Adding Interfaces ClassPool cp = ClassPool.getDefault(); CtClass
ct = cp.get("org.geecon.Alarm"); ct.addInterface(cp.get(Listener.class.getName())); ct.addMethod(CtNewMethod.make("public void fire(){ alert(); }", ct)); public interface Listener { void fire(); } public class Alarm { void alert() {} }
Adding Interfaces ClassPool cp = ClassPool.getDefault(); CtClass
ct = cp.get("org.geecon.Alarm"); ct.addInterface(cp.get(Listener.class.getName())); ct.addMethod(CtNewMethod.make("public void fire(){ alert(); }", ct)); public interface Listener { void fire(); } public class Alarm { void alert() {} }
Adding Interfaces ClassPool cp = ClassPool.getDefault(); CtClass
ct = cp.get("org.geecon.Alarm"); ct.addInterface(cp.get(Listener.class.getName())); ct.addMethod(CtNewMethod.make("public void fire(){ alert(); }", ct)); public interface Listener { void fire(); } public class Alarm { void alert() {} }
Simple AOP ProxyFactory pf = new ProxyFactory();
pf.setSuperclass(No9fier.class); pf.setFilter(new MethodFilter() { … }); No9fier no9fier = (No9fier) pf.createClass().newInstance(); ((ProxyObject) no9fier).setHandler(new MethodHandler() { … }); System.out.println("calling on()"); no9fier.on(); System.out.println("calling off()"); no9fier.off(); public class No9fier { public void on(){ } @Pointcut public void off(){} }
Intercept Statements ClassPool pool = ClassPool.getDefault();
CtClass ct = pool.get("org.geecon.PaymentMachine"); ct.getDeclaredMethod("process") .instrument(new ExprEditor() { public void edit(NewExpr e) throws CannotCompileExcep9on { e.replace("$_ = $proceed($$);"); } });
JRebel SDK Ö_õ
IDEs Containers Frameworks Build Tools More at h^p://www.jrebel.com/features
None