Skip to content

Commit

Permalink
Fix urlencode bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackINT3 committed Nov 19, 2020
1 parent ebe07eb commit cf0aebd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
21 changes: 18 additions & 3 deletions src/OpenArk/coderkit/coderkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,15 @@ void CoderKit::UpdateAlgorithmText(bool crypt)
} else if (alg_idx_ == IDX.rc4) {
cipher = Cryptor::GetSHA1ByData(plain);
} else if (alg_idx_ == IDX.urlencode) {
cipher = UrlEncode(plain);
std::vector<char> pass;
std::vector<std::string> headers = { "http", "https", "ftp" };
for (auto h : headers) {
if (UNONE::StrIndexIA(plain, h) == 0) {
pass = { ':', '&', '/', '?', '=' };
break;
}
}
cipher = UrlEncode(plain, pass);
} else if (alg_idx_ == IDX.urldecode) {
cipher = UrlDecode(plain);
} else if (alg_idx_ == IDX.urlencodeURL) {
Expand Down Expand Up @@ -562,15 +570,22 @@ void CoderKit::SolveCodeTextFormat(std::string &text, std::string &format, int i
static const char* kUrlReservedCharset = "!*'();:@&=+$,/?#[]";
static const char* kUrlNonReservedCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~";

std::string CoderKit::UrlEncode(const std::string &buf)
std::string CoderKit::UrlEncode(const std::string &buf, std::vector<char> pass)
{
std::string str;
try {
std::string CharSet = kUrlNonReservedCharset;
for (size_t i = 0; i < buf.size(); i++) {
unsigned char temp[4] = {0};
unsigned char ch = static_cast<unsigned char>(buf[i]);
if (CharSet.find(ch) != std::string::npos) {
bool found = false;
for (auto p : pass) {
if (p == ch) {
found = true;
break;
}
}
if (found || CharSet.find(ch) != std::string::npos) {
temp[0] = ch;
} else {
temp[0] = '%';
Expand Down
2 changes: 1 addition & 1 deletion src/OpenArk/coderkit/coderkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private slots:
QString NasmAsm(std::string data, int bits, const std::string &format);
QString NasmDisasm(const std::string &data, int bits);
void SolveCodeTextFormat(std::string &text, std::string &format, int interval, int id);
std::string UrlEncode(const std::string &buf);
std::string UrlEncode(const std::string &buf, std::vector<char> pass);
std::string UrlDecode(const std::string &buf);
std::string UrlEncodeURL(const std::string &buf);

Expand Down
Binary file modified src/OpenArk/res/OpenArk.rc
Binary file not shown.
8 changes: 4 additions & 4 deletions src/OpenArk/ui/coderkit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1131</width>
<height>797</height>
<width>654</width>
<height>566</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -572,14 +572,14 @@
<item>
<widget class="QRadioButton" name="urlencodeRadio">
<property name="text">
<string>urlencode</string>
<string>URL-Encode</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="urldecodeRadio">
<property name="text">
<string>urldecode</string>
<string>URL-Decode</string>
</property>
</widget>
</item>
Expand Down
Binary file modified src/OpenArkDrv/OpenArkDrv.rc
Binary file not shown.

0 comments on commit cf0aebd

Please sign in to comment.