Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
800
Spec-Driven Development with AI Agents (Workshop, May 2026)
antonarhipov
4
610
Spec-Driven Development with AI Agents. Java Day Istanbul 2026
antonarhipov
3
170
Spec-Driven Development with AI Agents: From High-Level Requirements to Working Software
antonarhipov
3
200
Strengthening Immutability in Kotlin. A Glimpse into Valhalla
antonarhipov
3
130
Kotlin—the New and Noteworthy in 2.2
antonarhipov
1
62
Levels of AI-assisted programming
antonarhipov
0
190
Devoxx France 2024. Kotlin - the new and noteworthy
antonarhipov
2
130
Harnessing the power of AI in IntelliJ IDEA
antonarhipov
1
280
Other Decks in Technology
See All in Technology
LocalStack を使ったサーバーレスアプリケーション開発 / Serverless Development with LocalStack
kakakakakku
1
290
freeeらしさをAIとともに作る / Creating the freee Experience with AI
ymrl
0
210
ログラスのマルチプロダクトを 支える認証基盤 〜テナントごとに異なる統制とどう向き合うか〜
dada4386
3
410
予測不能な実行エージェントを安全にサクッと試せるサンドボックス環境の話
sansantech
PRO
0
130
FactoryBotアンチパターン / factory_bot anti-patterns
toshimaru
0
140
Essential architectural thinking (revised edition)
ufried
0
100
継続的なAIコスト最適化
bgpat
1
230
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
520
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
5
1.4k
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
150
形式手法を使って仕様をコーディングしよう
mikanichinose
0
190
オンラインゲームのシステム全体像 - コロプラ 2026年度 新卒研修
colopl
0
920
Featured
See All Featured
sira's awesome portfolio website redesign presentation
elsirapls
0
440
Discover your Explorer Soul
emna__ayadi
2
1.3k
Abbi's Birthday
coloredviolet
4
10k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
400
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
Skip the Path - Find Your Career Trail
mkilby
1
250
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
350
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
210
Building Applications with DynamoDB
mza
96
7.2k
WCS-LA-2024
lcolladotor
0
850
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