惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
D
Docker
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
美团技术团队
V
V2EX
Last Week in AI
Last Week in AI
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
B
Blog RSS Feed
博客园_首页
B
Blog
博客园 - 叶小钗
I
InfoQ
WordPress大学
WordPress大学
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Latest news
Latest news
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
S
Secure Thoughts
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News

博客园 - Jason.NET

请不要为了自己的商业目地不择手段 DOTNET 32位下的程序在64位下真的可以运行吗? - Jason.NET - 博客园 加密狗保护的VFP软件破解 (朋友之作,代发) 使 Framework 2.0 的程序集不用安装 Framework 就可以运行的工具免费发布了 谁不需要赚钱 -- 想,还要敢想 - Jason.NET 发布一个武汉的.net程序员招骋信息 中国软件业的混乱,观总价值2亿项目后的感叹 - Jason.NET - 博客园 刚刚收到来至 Reliasoft Corporation 的一封版权申明信 我想列出一个保护类软件的黑名单 排名和积分都大大降低了?怎么回事? Thinstall 包装 Dotnet 程序分析 一款非混淆软件 for .net 保护 各种Web脚本下,日历的实现方法 为什么浏览器有这么多标准??? 由浅至深,谈谈.NET混淆原理 -- 五(MaxtoCode原理),六(其它保护方法) QQ有漏洞??? 由浅至深 谈谈.NET混淆原理 (四) -- 反混淆(原理 + 工具篇) WEB程序员,界面美化是你心中永远的痛吗? 由浅至深 谈谈.NET混淆原理(三)-- 流程混淆(续)
怎样给没有源代码的.net程序添加修改功能
Jason.NET · 2006-04-14 · via 博客园 - Jason.NET

今天要修改一段代码,可是找不到源代码了,怎么办呢?
具体情况如下:

某个.NET小网站,在做数据库的查询修改删除操作的时候,没有验证输入参数的合法性,没有做错误处理,导致页面异常.

代码如下:

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      iClass.Verify(Me)
      Me.DirId = Me.Request.QueryString.Item("DirId")
      Me.InfoId = Me.Request.QueryString.Item("InfoId")
      If Not IsNumber(Me.DirId) Then
            Me.DirId = ""
      End If
      Dim adapter1 As New OleDbDataAdapter(("Select * from Directory where Dirid = " & Me.DirId), Me.mCn)
      Dim table1 As New DataTable
      adapter1.Fill(table1)
      Me.DirPath = StringType.FromObject(table1.Rows.Item(0).Item("DirPath"))
      If (StringType.StrCmp(FileSystem.Dir(Me.Server.MapPath(Me.DirPath), FileAttribute.Directory), "", False) = 0) Then
            FileSystem.MkDir(Me.Server.MapPath(Me.DirPath))
      End If
      If Not Me.Page.IsPostBack Then
            Dim adapter2 As New OleDbDataAdapter(("Select * from info where InfoId=" & Me.InfoId & "and dirid=" & Me.DirId), Me.mCn)
            Dim table2 As New DataTable
            adapter2.Fill(table2)
            Me.txtTitle.Text = table2.Rows.Item(0).Item("Infotitle").ToString.Trim
            Me.txtMain.set_Text(table2.Rows.Item(0).Item("Infomain").ToString.Trim)
            Me.txtMain.set_Text(iClass.unchangestr(Me.txtMain.get_Text).ToString.Trim)
            Me.txtMaker.Text = table2.Rows.Item(0).Item("Infomaker").ToString.Trim
            Me.txtReship.Text = table2.Rows.Item(0).Item("Inforeship").ToString.Trim
      End If
End Sub

其中如果参数DirId和InfoId不为数字型的话,会造成
 "Select * from Directory where Dirid = " & Me.DirId
以及
 "Select * from info where InfoId=" & Me.InfoId & "and dirid=" & Me.DirId
的SQL语句查询出错

解决方法:
If Not IsNumber(Me.DirId) Then
    Me.DirId = ""
End If
改成
If Not IsNumber(DirId) Or Not IsNumeric(InfoId) Then
   DirId = ""
   Return
End If

新建一WEB项目,在Page_Load事件中加入以下代码

Verify(Me)
DirId = Request.QueryString("DirId")
InfoId = Request.QueryString("InfoId")
If Not IsNumber(DirId) Or Not IsNumeric(InfoId) Then
   DirId = ""
   Return
End If
Dim objApt As New OleDbDataAdapter("Select * from Directory where Dirid = " & DirId, mCn)
Dim objDt1 As New DataTable
objApt.Fill(objDt1)
DirPath = objDt1.Rows(0)("DirPath")
If Dir(Me.Server.MapPath(DirPath), FileAttribute.Directory) = "" Then
    MkDir(Me.Server.MapPath(DirPath))
End If
If Not Page.IsPostBack Then
    Dim objApt1 As New OleDbDataAdapter("Select * from info where InfoId=" & InfoId & " and dirid=" & DirId, mCn)
    Dim objDt As New DataTable
    objApt1.Fill(objDt)
    txtTitle.Text = objDt.Rows(0)("Infotitle").ToString.Trim
    txtMain.Text = objDt.Rows(0)("Infomain").ToString.Trim
    txtMain.Text = unchangestr(txtMain.Text).ToString.Trim
    txtMaker.Text = objDt.Rows(0)("Infomaker").ToString.Trim
    txtReship.Text = objDt.Rows(0)("Inforeship").ToString.Trim
End If

(注意,控件中要用到的一些控件要手动添加,函数根据.NET Reflector反编译出源代码加入到项目中.)

将新建项目编译成DLL

接着,用VS自带的ILDASM将原始DLL反编译成IL,用文本编辑器打开IL文件,用查找功能定位到
 "Select * from info where InfoId="
这一行
往下走来到函数结尾
 } // end of method Admin_FileEdit::Page_Load
往上走来到函数开头
 .method private instance void  Page_Load(object sender,
                                             class [mscorlib]System.EventArgs e) cil managed
中间部分就是要修改的代码了

再接着,用VS自带的ILDASM打开刚才生成的项目的DLL,打开IL的树形结构,找到改正后的函数,双击,可以打开一个详细的代码文件
将里面的所有代码复制到刚才打开的IL代码,替换IL文件中的原始函数
即下面的部分
 .method private instance void  Page_Load(object sender,
                                             class [mscorlib]System.EventArgs e) cil managed
  ...................................
  ...................................
  ...................................
 } // end of method Admin_FileEdit::Page_Load

重新编译修改过的IL,"ilasm filename.il /dll"  (filename指你开始用ILDASM导出的IL文件名)


将生成的DLL拷贝到BIN目录,覆盖旧的DLL

至此,修改工作告一段落