Skip to content

Commit

Permalink
scripts: fix issue with selection
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAppSec committed Sep 8, 2024
1 parent 7ea62f4 commit 34c214a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lua/hacker-helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -286,35 +286,39 @@ vim.keymap.set("v", M.config.prefix .. M.config.keys.hash_prefix .. M.config.key
end, { noremap = true, silent = true, desc = "Scrypt Hash" })

-- Scripts/snippets are under <leader>rs

-- HTTP Burp to Python Requests (body)
vim.keymap.set(
"v",
M.config.prefix .. M.config.keys.scripts_prefix .. M.config.keys.script_http_to_python_body,
function()
selection_util.transform_selection(function(selection)
http_to_python.capture_http_selection(function(selection)
local request = http_to_python.parse_http_request(selection)
return http_to_python.generate_python_requests_script(request, "raw")
end)
end,
{ noremap = true, silent = true, desc = "HTTP Burp to Python Requests (body)" }
)

-- HTTP Burp to Python Requests (json)
vim.keymap.set(
"v",
M.config.prefix .. M.config.keys.scripts_prefix .. M.config.keys.script_http_to_python_json,
function()
selection_util.transform_selection(function(selection)
http_to_python.capture_http_selection(function(selection)
local request = http_to_python.parse_http_request(selection)
return http_to_python.generate_python_requests_script(request, "json")
end)
end,
{ noremap = true, silent = true, desc = "HTTP Burp to Python Requests (json)" }
)

-- HTTP Burp to Python Requests (form-data)
vim.keymap.set(
"v",
M.config.prefix .. M.config.keys.scripts_prefix .. M.config.keys.script_http_to_python_form,
function()
selection_util.transform_selection(function(selection)
http_to_python.capture_http_selection(function(selection)
local request = http_to_python.parse_http_request(selection)
return http_to_python.generate_python_requests_script(request, "form-data")
end)
Expand Down
11 changes: 8 additions & 3 deletions lua/hacker-helper/http_to_python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ M.convert_to_form_data = function(body)

return table.concat(encoded_data, "&")
end
-- Custom function to capture the visual selection for HTTP to Python conversion
M.capture_http_selection = function()

-- Custom function to capture the visual selection for HTTP to Python conversion and replace it with the generated script
M.capture_http_selection = function(transform_func)
-- Reselect the current visual block to ensure the latest selection is active
vim.cmd("normal! gv")

Expand All @@ -47,7 +48,11 @@ M.capture_http_selection = function()
selection[i] = line:gsub("\r$", "") -- Handle ^M
end

return selection
-- Apply the transform function to the selection (HTTP to Python)
local transformed = transform_func(selection)

-- Replace the selected lines with the transformed script
vim.fn.setline(start_line, transformed)
end

-- Function to parse the HTTP request from the selected lines
Expand Down

0 comments on commit 34c214a

Please sign in to comment.